\documentclass{article}

\usepackage{hyperref}
\usepackage{cite}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[ruled]{algorithm2e}
\usepackage[margin=1in]{geometry}
\usepackage{appendix}
\usepackage{float}
\usepackage{verbatim}
\usepackage[normalem]{ulem}
\setcounter{section}{-1}

\title{CLimate Analysis using Digital Estimations Non-Offical Manual (CLAuDE NOM)}
\author{Sam "TechWizard" Baggen}
\date{\today}

\begin{document}

\maketitle

\tableofcontents

\section{Introduction}

The CLimate Analysis using Digital Estimations model is a simplified planetary climate model. It will be used to educate people on how climate physics works and to experiment with different 
parameters and see how much influence a tiny change can have (like for instance the rotation rate of the planet around its axis). It is built to be accessible to and runnable by everyone, 
whether they have a super computer or a dated laptop. The model is written in Python and written during the weekly streams of Dr. Simon Clark \cite{twitch}. There is a useful playlist on 
Simon's Twitch which has all the streams without ad breaks or interruptions \cite{playlist}. 

The manual itself is split up into distinct sections, each explaining one particular part of the model. Each section will be treating one topic, like radiation, advection or the control panel.
Although many concepts cannot be seen in isolation, as the wind has influence on how much temperature is distributed throughout the atmosphere, the calculations can be split up. The manual is 
cumulative, starting with the basics and slowly building up to the current form of the algorithm. All changes to the algorithms can therefore be found here. An important distinction needs to be 
made regarding the changes though. If the changes only change one part of the calculations, then it is considered an evolution, which will be added to the relevant section. However if the changes 
are significant and not based on the previous code then the old alghorithms will be relocated to \autoref{sec:history}. Though the relevant theory will remain, as that is required to gain an 
understanding of what the algorithm does. Do note that the radiation \autoref{sec:rad} is an exception for the first calculations as this forms the basis of the beginning of CLAuDE and the 
fundamentals of the theory which I deem important enough to be left in place even if the calculations end up significantly different.

This manual will provide an overview of the formulae used and will explain aspects of these formulae. For each equation each symbol will be explained what it is. In such an explanation, the units 
will be presented in SI units \cite{SI} between brackets like: $T$: The temperature of the planet ($K$). Which indicates that $T$ is the temperature of the planet in degrees Kelvin. If you need 
to relate SI units to your preferred system of units, please refer to the internet for help with that. There are great calculators online where you only need to plug in a number and select the 
right units.

Within this manual we will not concern ourselves with plotting the data, instead we focus on the physics side of things and translating formulae into code. If you are interested in how the
plotting of the data works, or how loading and saving data works, please refer to the relevant stream on Simon's Twitch page \cite{twitch}.

This manual is for the toy model, which is as of now still in development. One important thing to note is that the layout may change significantly when new sections are added. This is due to the amount of code that is added/changed. If a lot of code changes, a lot of so called
'algorithm' blocks are present which have different placement rules than just plain text. Therefore it may occur that an algorithm is referenced even though it is one or two pages later. This is 
a pain to fix and if something later on changes, the whole layout may be messed up again and is a pain to fix again. Hence I opt to let \LaTeX (the software/typeset language used to create this 
manual) figure out the placement of the algorithm blocks, which may or may not be in the right places.

The manual is now up on the Planet Factory GitHub repository\cite{claudeGit}, together with all the source code. There is also a fork \cite{nomGit} that also contains the source code. 
The fork will usually be more up to date than the version on the Planet Factory repository as Simon needs to merge pull requests into the repository. However I can update the fork freely so if a 
particular stream is missing in the version on the Planet Factory repository, check the fork/Discord whether there is a newer version. If that is not the case, you just have to be a bit more 
patient, or you can start writing a part of the manual yourself! Don't forget to ping me in the Discord to notify me of any additions (GitHub refuses to send me emails so I have no other way of 
knowing).

\input{topics/control_panel.tex}

\input{topics/util_funcs.tex}

\input{topics/radiation.tex}

\input{topics/velocity.tex}

\input{topics/advection.tex}

\input{topics/master.tex}

\newpage
\input{appendices/TTNMETAF.tex}

\input{appendices/history.tex}

\input{appendices/vars.tex}

\newpage
\bibliography{references}
\bibliographystyle{plain}

\begin{comment}
\subsection{Hydrostatic balance}
Hydrostatic balance is the relation between the pressure at the surface of the planet and the pressure higher up in the atmosphere \cite{hydrostatic}. This all works under the assumption that 
the vertical acceleration is relatively small in magnitude compared to the gravity of the planet, which it almost always is when looking at the atmosphere or the ocean. The corresponding 
formula is described in \autoref{eq:hydrostatic}. The symbols here represent:

\begin{itemize}
    \item $\delta p$: The change in the atmospheric pressure ($Pa$).
    \item $\delta z$: The change in altitude or height ($m$).
    \item $\rho$: The density of the atmosphere ($kgm^{-3}$).
    \item $g$: The gravitational acceleration, on Earth this is $9.81$ ($ms^{-2}$).
\end{itemize}

\begin{equation}
    \frac{\delta p}{\delta z} = -\rho g
    \label{eq:hydrostatic}
\end{equation}

Now we need to translate this into code, luckily this is quite easy as shown in \autoref{alg:hydrostatic}. We first calculate the difference between the current mean pressure and the mean 
pressure we get from \autoref{eq:hydrostatic}. Then we add the difference to the pressure, effectively correcting the average pressure for the current atmospheric layer to what it is supposed to 
be. By correcting it with the mean difference we still have the local variation in pressure while on average we are closer to the true value we calculate in \autoref{eq:hydrostatic}.

\begin{algorithm}
    \For{$alt \in [1, nlevels]$}{
        $correction \leftarrow mean(p[:, :, alt - 1]) - mean(\rho[:, :, alt])(heights[alt] - heights[alt - 1])g$ \;
        $p[:, :, alt] \leftarrow \rho[:, :, alt] + correction$ \;
    }
    \caption{Calculating the effects of Hydrostatic Balance on the average pressure}
    \label{alg:hydrostatic}
\end{algorithm}
\end{comment}
\end{document}