\documentclass[12pt]{article}
\usepackage[a4paper, bindingoffset=0.2in, %
							left=0.5in,right=0.5in,top=0.5in,bottom=0.5in,%
							footskip=.25in]{geometry}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{hyperref}

\title{PSet4 Report}
\author{Ali Abolhassanzadeh Mahani}

\begin{document}
	\maketitle
	\section{Standard Deviation}
	I proved this on a piece of paper and later, I scanned it using \emph{CamScanner} and it's available   \href{run:d:/../CompPhys4.pdf}{here}.
	\section{Random Walk}
	I made a function \texttt{rw\_next()} that takes the current postion and moves to left / right
	with a given probability.
	Then I simulate the random walk and take the data. I took the data in 100 choice intervals, from
	100 to 1000 and ran the simulation 10000 times in the \texttt{rw\_simul()} function.
	The plots are available in Fig\ref{fig:rw_sim})
	\begin{figure}[h!]
		\centering
		\includegraphics[width=0.9\linewidth]{../p2/sigmas.jpg}
		\includegraphics[width=0.9\linewidth]{../p2/x_means.jpg}
		\label{fig:rw_sim}
		\caption{The plot of $\sigma^2$ (top) and $<x>$ (bottom) over time for different probabilities. Took 10000 runs and got the mean.}
	\end{figure}

	\section{Random Walk with Trap (Random)}
	I simulated this problem using a class called \texttt{Drunk}. This is the actualization of a
	drunk person dangling around in 1-D. I set the path to be from 0 to 19 and traps at -1 and 20.
	If the drunk gets to those points, it perishes and I can then get its lifetime.
	I ran the simulation for 10000 drunk men and took the mean.
	The resulting graph is plotted in Fig\ref{fig:rw_trap}
	\begin{figure}[h!]
		\centering
		\includegraphics[width=0.9\linewidth]{../p3/drunk.jpg}
		\label{fig:rw_trap}
		\caption{mean lifetime over different indices of the path. traps at -1 and 19. Ran 10000
		instance simulations}
	\end{figure}

	\section{Random Walk with trap (Deterministic)}
	This time, I simulated and used the \texttt{profile} library in python to find the exact run time of my algorithm. The resulted graph is available in Fig\ref{fig:rw_trap_det}.
	\begin{figure}[h!]
		\centering
		\includegraphics[width=0.9\linewidth]{../p4/rw_trap.jpg}
		\label{fig:rw_trap_det}
		\caption{mean lifetime over index in path which the drunk person begins from.
			Deterministic algorithm.}
	\end{figure}

	I did the same for the random generation algorithm here we shall see the difference.
	My system has an \emph{Intel Core i5 8th gen} CPU and 8 GB of DDR4 RAM. the result are:\\
	\begin{itemize}
		\item \textbf{Deterministic:} $0.636 s$
		\item \textbf{Random:} $139.667 s$
	\end{itemize}
	This is an example where deterministic algorithms perform much faster!

	\section{2-D Random Walk}
	This time, I simulated the \texttt{Drunk} person to be a girl on a 2-D surface. Almost the same as the 1-D instance, but returns $r^2$. I ran the simulation with time intervals of 100 for 10 intervals. The plot is available in Fig\ref{fig:2d_rw}
	\begin{figure}[h!]
		\includegraphics[width=0.9\linewidth]{../p5/2d_girl.jpg}
		\label{fig:2d_rw}
		\caption{dependence of The distance squared $r^2$ over time intervals of 100 choices.}
	\end{figure}

	\section{Aggressive Layer Deposition}
	I made a \texttt{RandWalker} class that generates a particle at a random x and the highest y
	that I chose to be 199. The length of the seed is 201 for symmetry that proved to play no role
	in the simulation whatsoever :-) \\
	I chose the buffer length to be 10. If the particle exceeds that buffer, I reset the position with
	a random $x$ position again.

	I made 2000 particles and gave them room to random walk and stick to the seed. Then I
	visualized the grid using \texttt{plt.pcolor()}.

	I also tried changing colors but apparently something is wrong with it. Maybe the color code intervals.

	The plot is in Fig\ref{fig:ald}
	\begin{figure}[h!]
		\includegraphics[width=0.9\linewidth]{../p6/ald.jpg}
		\label{fig:ald}
		\caption{deposited 2000 randomly positioned particles using random walk simulation.}
	\end{figure}
\end{document}


% !TEX TS-program = xelatex
% !TEX encoding = UTF-8
% !Mode:: "TeX:UTF-8"

\documentclass[onecolumn,oneside]{SUSTechHomework}

\usepackage{indentfirst}
\setlength{\parindent}{2em}

\author{Yubin Hu}
\sid{11712121}
\title{Assignment 1}
\coursecode{CS403}
\coursename{Cryptography and Network Security}

\begin{document}
  \maketitle

  \section*{Q.1}
  Due to the shift-cipher's key is from 0 to 25, so we try all 26 keys. When the $key = 13$, we decrypt the cihertext:

  "SUSTech is a public university founded in the lush hills of Nanshan District Shenzhen It is working towards becoming a world class university excelling in interdisciplinary research nurturing innovative talents and delivering new knowledge to the world."

  \section*{Q.2}
  We prove that for every pair of plaintexts $x, x'$, the probability that Eve guesses $x_b$ after seeing the ciphertext $c=Enc_k(x_b)$ is at most 1/2, if and only if we have $E_{U_n}(x) \equiv E_{U_n}(x')$.

  \subsection*{"if" part}
  if $E_{U_n}(x) \equiv E_{U_n}(x')$, the Eve can not get any information and the probability is at most.

  \subsection*{"only if" part}
  We prove by contrapositive.
  Suppose $\exists x_1, x_2$ such that $E_{U_n}(x_1) \not\equiv E_{U_n}(x_2)$ which means that there has a $y_0$ satisfied that $Pr[Y_{x_1}=y_0]>Pr[Y_{x_2}=y_0]$. So that Eve guesses $x_1$ if the ciphertext $y=y_0$, otherwise Eve guesses randomly. Then the probability is larger than 1/2.

  \section*{Q.3}

  \subsection*{"if" part}
  Suppose that $Pr[E_{nc_k}(m)=c]=Pr[E_{nc_k}(m')=c]$, we should prove that (Gen,Enc,Dec) with message space $M$ is perfectly secure, which means:
  $$Pr[M=m|C=c]=\frac{Pr[C=c|M=m]*Pr[M=m]}{\sum_{m' \in M}Pr[C=c|M=m']*Pr[M=m']}=Pr[M=m]$$
  $$Pr[C=c|M=m]*Pr[M=m]=\sum_{m' \in M}Pr[C=c|M=m']*Pr[M=m']$$
  Since $\forall m, m' \in M$, we have $Pr[C=c|M=m]=Pr[C=c|M=m']$, so that
  $$\sum_{m' \in M}Pr[C=c|M=m']*Pr[M=m']=Pr[C=c|M=m']*\sum_{m' \in M}Pr[M=m']=Pr[C=c|M=m]$$
  Above all, we complete the proof.

  \subsection*{"only if" part}
  Suppose that (Gen,Enc,Dec) with message space $M$ is perfectly secure. Fix arbitrary messages $m, m'$ and ciphertext $c$, since it is perfectly secure,
  $$\forall m \in M,~Pr[M=m|C=c]=Pr[M=m]$$
  So we have
  $$Pr[E_{nc_k}(m)=c]=\frac{Pr[M=m|C=c]*Pr[C=c]}{Pr[M=m]}=Pr[C=c]$$
  $$Pr[E_{nc_k}(m')=c]=\frac{Pr[M=m'|C=c]*Pr[C=c]}{Pr[M=m']}=Pr[C=c]$$
  The resuly is nothing to do with $m$, $Pr[E_{nc_k}(m)=c]=Pr[E_{nc_k}(m')=c]$

  \section*{Q.4}

  \subsection*{(1)}
  Yes. For every $m \in Z_M$, we have $Pr[E_k(m)=c]=\frac{|{k \in Z_M~:~k~+~m~mod~M~=~c}|}{|Z_M|} = \frac{1}{6}$. Due to an encryption scheme (Gen,Enc,Dec) with message space $M$ is perfectly secure if and only if $Pr[E_{nc_k}(m)=c]=Pr[E_{nc_k}(m')=c]$, this encryption scheme is \emph{perfectly secure}.

  \subsection*{(2)}
  No. Let $m_1=1,~m_2=0,~c=4$, $Pr[E_{nc_k}(m_1)=c]=0$, $Pr[E_{nc_k}(m_2)=c]=\frac{1}{3}$, they go against \emph{an encryption scheme (Gen,Enc,Dec) with message space $M$ is perfectly secure if and only if $Pr[E_{nc_k}(m)=c]=Pr[E_{nc_k}(m')=c]$}, so this encryption scheme is not perfectly secure.

  \section*{Q.5}
  for any two messages $m_0,m_1$, $m_0$ and $m_1$ agree on at least $l/2$ bits.. Suppose there is a new message $m_2$, $m_2$ and $m_1$ also agree on at least $l/2$ bits.

  $m_2$ could be composed of the first half of $m_0$ and the second half of $m_1$. So that we have $E_{U_n}(m_0) \equiv E_{U_n}(m_1) \equiv E_{U_n}(m_2)$ which prove that any encryption scheme that is half-message perfectly secure must in fact also be perfectly secure.

  \section*{Q.6}
  To prove that the statistical distance $\triangle(X, Y)$ defined in Definition 2.1 of Lecture 3 is a metric. We should prove:

  (1) $\triangle(X, Y) = 0 \Leftrightarrow (X, Y)$

  since
  $$\triangle(X, Y) = max_{T\subseteq {0,1}^n}$$
  $$|Pr[X \in T]-Pr[Y |in T]| = 0$$
  which means $t \in {0,1}^n$ and $Pr[X \in T] = Pr[Y |in T]$.
  Suppose $\forall t \in {0,1}^n$
  $$Pr[X=t]=Pr[X \in {t}]=Pr[X \in {t}]=Pr[Y \in {t}]=Pr[Y=t]$$
  So that $X=Y$

  (2) $\triangle(X, Y) = \triangle(Y, X)$

  since
  $$\triangle(X, Y) = max_{T\subseteq {0,1}^n}$$
  so that
  $$|Pr[X \in T]-Pr[Y |in T]| = max_{T\subseteq {0,1}^n}$$
  $$|Pr[Y \in T]-Pr[X |in T]| = \triangle(Y, X)$$

  (3) $\triangle(X, Y) \le \triangle(X, Z) + \triangle(Z, Y)$

  $\triangle(X, Y) = \frac{1}{2}\sum_{w \in Supp(X) \cup Supp(Y)}|Pr[X=w]-Pr[Y=w]|$ So that:
  \begin{align*}
    \triangle(X, Z) &+ \triangle(Z, Y) \\
   &= \frac{1}{2}\sum_{w \in Supp(X) \cup Supp(Y)}|Pr[X=w]-Pr[Z=w]| + \frac{1}{2}\sum_{w \in Supp(X) \cup Supp(Y)}|Pr[Z=w]-Pr[Y=w]|  \\
   &= \frac{1}{2}\sum_{w \in Supp(X) \cup Supp(Y)}(|Pr[X=w]-Pr[Z=w]| + |Pr[Z=w]-Pr[Y=w]|)   \\
   &\ge \frac{1}{2}\sum_{w \in Supp(X) \cup Supp(Y)}(|Pr[X=w]-Pr[Z=w] + Pr[Z=w]-Pr[Y=w]|)   \\
   &= \frac{1}{2}\sum_{w \in Supp(X) \cup Supp(Y)}(|Pr[X=w]-Pr[Y=w]|)   \\
   &= \triangle(X, Y)
  \end{align*}

  So the statistical distance $\triangle(X, Y)$ defined in Definition 2.1 of Lecture 3 is a metric.

  \section*{Q.7}
  To prove that the computational indistinguishability $\approx$ defined above is an equivalence relation, we need to prove that $\approx$ is relexive, symmetric and transitive.
  \subsection*{reflexive}
  $X_n \approx Y_n$ for any $\epsilon$, $Pr[A(X_n)=1]-Pr[A(Y_n)=1] \le \epsilon(n)$, whith means $X_n \approx X_n$
  \subsection*{symmetric}
  If $X_n \approx Y_n$, $|Pr[A(X_n)=1]-Pr[A(Y_n)=1]|=|Pr[A(Y_n)=1]-Pr[A(X_n)=1]|$, whith means $X_n \approx X_n$
  \subsection*{transitive}
  If $X_n \approx Y_n$ and $Y_n \approx Z_n$, for any $\epsilon$, $Pr[A(X_n)=1]-Pr[A(Y_n)=1] \le \epsilon(n)$, $Pr[A(Y_n)=1]-Pr[A(Z_n)=1] \le \epsilon(n)$

  \begin{align*}
    Pr&[A(X_n)=1]-Pr[A(Y_n)=1] \\
   &= Pr[A(X_n)=1]-Pr[A(Y_n)=1] + Pr[A(Y_n)=1]-Pr[A(Z_n)=1]  \\
   &\le |Pr[A(X_n)=1]-Pr[A(Y_n)=1]| + |Pr[A(Y_n)=1]-Pr[A(Z_n)=1]|  \\
   &\le 2\epsilon(n)
  \end{align*}

\end{document}


\section{Evaluation}
\label{sec:evaluation}
%% \jrex{start with a brief roadmap of the section.}

We now evaluate \TheSystem through trace-driven simulations. We tune the
parameter of \TheSystem---the number of table stages $d$---in
\Sec{subsec:sensitivity}. We evaluate the performance of \TheSystem in isolation
in \Sec{subsec:isolatedEvaluation}, and then compare it to prior sampling and
sketching solutions in \Sec{subsec:comparisonRelated}. Then, we examine the
performance of \TheSystem in context of the idealized algorithms it is derived from
(\Sec{sec:algorithm}) in \Sec{subsec:comparisonIdeal}.

\NewPara{Experiment setup.} We compute the $k$ heaviest flows aggregated
by transport 5-tuple, using a traffic trace of a 10Gb/s ISP backbone link from
CAIDA~\cite{caida} recorded in 2016. The traffic trace is 17 minutes long, and
contains 500 million packets. We split this trace into 50 different chunks with
each being about 20 seconds long, with 10 million packets. The chunks on average
contain about 400,000 5-tuple flows each. Each chunk is one trial, and each data
point in the following graphs reports the average across these 50 trials. We
assume the switch zeroes out its tables at the end of each trial, which
corresponds to a 20 second ``table flush'' period. It is feasible to flush the
table this often in switch hardware; switches can already rewrite tables at
intervals of tens of seconds or smaller, \eg~\cite{bgp-neighbor-timer,
  netflow-timer, li2016flowradar}.

\NewPara{Metrics.} As discussed in \Sec{sec:problem}, we evaluate schemes on
false negatives (\% heavy flows that are not reported), false positives (\%
non-heavy flows that are reported), and the count estimation error (\% error for
heavy flows). Note that for the top-$k$ problem, the false positive error is
just a scaled version of the false negative.

\subsection{Tuning \TheSystem}
\label{subsec:sensitivity}

Given a total memory size $m$, \TheSystem's only tunable parameter is the number of
table stages $d$ that it uses. Once $d$ is fixed, we simply partition the
available memory equally into $d$ hash tables. As $d$ increases, the number of
table slots over which a minimum is computed increases, which can lead to higher
retention of heavier keys. However, with a fixed total memory, an increase in
the value of $d$ decreases the per-stage hash table size, increasing the
likelihood of hash collisions, and also of duplicates
(\Sec{sec:feed-forward}). Also, the switch hardware constrains the number
of table stages to a small number, \eg 6-16~\cite{intel-fm6000, RMT}.

\Fig{falseNegvsD} shows the impact of changing $d$ on the false negatives,
plotted for different sizes of memory $m$ and different number of desired heavy
hitters $k$. As expected, the false negatives reduce as $d$ increases starting
at $d=2$, but the decrease quickly tapers off in the range between 5--8. This
holds across a range of memory sizes and number of heavy-hitters estimated. The
false positives, elided here, follow the same trend.

To understand whether duplicates impact the false negative rates, we also show
the prevalence of duplicates in \TheSystem's hash tables in
\Fig{duplicates}. Overall, duplicates only take up between 5-10\% of the
available table size but, in going from $d=2$ and $d=8$, duplicates increase
from 3\% to 7\%. Further, \Fig{estimation-error-D} shows that the improvement
in count estimation error going from $d=4$ to $d=8$ is not as significant as
going from $d=2$ to $d=4$.
%
We conclude that between $d=5$ and $d=8$, the slightly increased prevalence of
duplicates and hash collisions offsets the gain from the larger number of
alternative slots available to pick the minimum.
%
%\ngs{Also, say something about dependence of estimation accuracy on $d$.}

\NewPara{Choosing $d=6$ table stages.} Given the robustness of the accuracy
metrics across varying memory sizes and heavy hitters in the range $d=5$ to
$d=8$, we use $d=6$ table stages for all further experiments with \TheSystem.

\iffalse
\begin{figure}[h]
\includegraphics[max height=11cm,max width=8cm]{WFalseNegsvsDsSingle.pdf}
\caption{Weighted fraction of Heavy Hitters Reported for Different $d$ values  with 500000 flows in total}
\label{fig:weightedNegvsD}
\end{figure}
\fi

\begin{figure}[h]
\includegraphics[max height=11cm,max width=8cm]{FalseNegvsDSingle.pdf}
\caption{Impact of the number of table stages on false negatives. Error
  decreases as $d$ grows, and then flattens out.}
\label{fig:falseNegvsD}
\end{figure}

\begin{figure}[h]
\includegraphics[max height=11cm,max width=8cm]{Duplicates.pdf}
\caption{Prevalence of duplicate keys in \TheSystem's tables.}
\label{fig:duplicates}
\end{figure}

\begin{figure}[h]
\includegraphics[max height=11cm,max width=8cm]{DsRelativeError.pdf}
\caption{Comparison of average estimation error (\%) of flows whose true counts
  are higher than the $x$-value in the graph. Error
 decreases as $d$ grows, yet, the difference is less pronounced at higher $d$}
\label{fig:estimation-error-D}
\end{figure}

%% In order to enure that the algorithm preserves the feed-forward property,
%% \TheSystem always inserts the incoming flow in stage $1$ an then computes the
%% minimum in a rolling fashion (\Sec{sec:feed-forward}). However, this could
%% induce some duplicates in the table when a flow present in a later table
%% stage is inserted afresh in the first table stage. Figure
%% \ref{fig:duplicates} shows that the fraction of the table occupied by
%% duplicates increases as the memory provisioned is increased but that this is
%% a small fraction (around $5\%$) of the total memory available for
%% heavy-hitter detection. %smaller memories, fewer %duplicates - get evicted
%% (or coalesced) for %larger flows - shows up as underestimates?

\subsection{Accuracy of \TheSystem}
\label{subsec:isolatedEvaluation}

We plot error \vs memory tradeoff curves for \TheSystem, run with $d=6$ table
stages.

\NewPara{False negatives.} \Fig{HPNegvsM} shows the false negatives as memory
increases, with curves corresponding to different numbers of reported heavy
hitters $k$. We find that error decreases with allocated memory across a range
of $k$ values, and settles to under 10\% in all cases at 80KB of memory, which
corresponds to 4500 counters.
%
For $k$=300, the error drops to about 5\% at 110KB, corresponding to 6200
($\sim20k$) counters, and for $k$=60, the error is about 2\% at the same memory
($\sim100k$).
%
%% For $k=300$, the error drops under 10\% at about 4000 counters ($\sim 13k$)
%% counters, and for $k=60$ around 2000 counters ($\sim 33k$).
%% (As memory increases beyond the range shown, false negatives continue to
%%drop.)
Recall that there are about 400,000 flows on average in any one trial,
which is two orders of magnitude higher than the number of counters used here.
We also find that the factor of $k$ required in the number of counters so as to
achieve a particular accuracy {\em reduces} as $k$ increases.

%% We also evaluate the memory-accuracy tradeoff for \TheSystem when one is
%% interested in the top-$k$ flows. Figure \ref{fig:HPNegvsM} and \Fig{HPPosvsM}
%% captures this tradeoff for different values of $k$. The trend indicates, as
%% expected, that for a given $k$ value, the accuracy improves as we provision more
%% memory. Given that the individual $20s$ traces contain around $0.5M$ flows by
%% 5-tuple on average, we are able to detect on the order of $100$ heavy flows
%% amongst the $0.5M$ with less than $10\%$ false negatives using less than $5K$
%% entries or $80 KB$ of space! This translates to needing roughly $15-20$ times
%% $k$ entries to track the top-$k$ heavy hitters to achieve a false negative rate
%% that is lower than $10\%$. At even higher memory, the false negative rate drops
%% to $5\%$. The exact factor is different across different $k$. As you increase
%% $k$, the curves start dropping faster. For example, at $k=60$, $1500$ or $25x$
%% entries are needed, while at $k=240$, less than $4500$ or $18$x entires are
%% needed.

\begin{figure}[ht]
\includegraphics[width=\columnwidth]{FalseNegsvsMsSingle.pdf} % previously [width=0.45\columnwidth]
\caption{False negatives of \TheSystem with increasing memory. Each trial trace
  contains an average of 400,000 flows, but \TheSystem achieves between 5-10\%
  false negatives for the top 60-300 heavy hitters with just 4500 flow
  counters.}
  %% Accuracy of reported Heavy hitters for Different $m$ values at $d = 6$ with
  %% $0.5M$ flows. $80KB$ translates to about 4500 key, value pairs
\label{fig:HPNegvsM}
\end{figure}

%% unsure about this figure, not turning out the way i hoped

%rephrase that it helps understand error
\NewPara{Which flows are likely to be missed?} %% We achieve a 10\% false negative
%% rate for the top 300 flows with 80KB memory, so
It is natural to ask which flows
are more likely missed by \TheSystem. \Fig{falseNegvsK} shows how the false
negatives change as the number of desired heavy hitters $k$ is varied, for three
different total memory sizes. We find that {\em the heaviest flows are least
  likely to be missed}, \eg with false negatives in the 1-2\% range for the top
20 flows, when using 3000 counters. This trend is intuitive, since \TheSystem
prioritizes the retention of larger flows in the table
(\Sec{sec:spacesaving}). Most of the higher values of false negative errors are
at larger values of $k$, meaning that the smaller of the top $k$
flows are more likely to be missed among the reported flows.

%% While the overall false
%% negative rate that we achieve for the top-$k$ flows is around $10\%$, Figure
%% \ref{fig:falseNegvsK} indicates that if we were interested in a smaller number
%% of heavy hitters, the false negative rate would be even lower.  Given that
%% \TheSystem prioritizes heavier flows over smaller ones, as $k$ increases, the
%% false negative rate in reporting the corresponding top-$k$ heavy hitters also
%% increases.  This does indicate, though, that the majority of the errors in
%% \ref{fig:HPPosvsM} (\ref{fig:HPNegvsM}) and \ref{fig:falseNegvsD} are arising
%% from the smaller flows and the heavier flows are retained with very high
%% probability.
% typical number that might be useful for applications?
%% anything more?

\begin{figure}[h]
\includegraphics[max height=11cm,max width=8cm]{FalseNegvsKSingle.pdf}
\caption{False negatives against different numbers of reported heavy flows
  $k$. The heavier a flow is, the less likely it is missed.}
\label{fig:falseNegvsK}
%plot 600 line here too
\end{figure}

\NewPara{False positives.} \Fig{HPPosvsM} shows the false positives of
\TheSystem against varying memory sizes, exhibiting the natural trend of
decreasing error with increasing memory. In particular, we find that false
positive rates are very low, partly owing to the large number of small flows. On
all curves, the false positive rate is smaller than 0.1\%, dropping to lower
than 0.01\% at a table size of 80KB.

%\ngs{Perhaps add counter estimation errors.}

\begin{figure}[ht]
\includegraphics[width=\columnwidth]{FalsePosvsMsSingle.pdf}
\caption{\TheSystem has false positive rates of 0.01\%-0.1\% across a range of
  table sizes and reported heavy hitters.}
\label{fig:HPPosvsM}
\end{figure}

%Choose parameters for good performance of our scheme. Given a K (for top K) or threshold (for threshold HH), how do you determine
%- number of table stages?
%- assymetry - wanna explore this at all?
%- memory size?

%(2) Memory/other overheads - get away with not keeping entire key if the goal isn't to report to the controller, but instead to act on hh directly in the dataplane

\subsection{\TheSystem\ \vs Existing Solutions}\label{subsec:comparisonRelated}

\NewPara{Comparison baselines.} We compare \TheSystem against two
schemes---representative of sampling and sketching---which are able to estimate
counts in the switch directly (\Sec{sec:related}). We use the same total memory
as earlier, and measure the top $k = 150$ flows, with the following baseline
schemes.

\noindent (1) Sample and Hold: We simulate sample and hold~\cite{estan2002new}
with a flow table that is implemented as a {\em list}.  As described in
\Sec{sec:related}, we liberally allow incoming packets to look up flow entries
anywhere in the list, and add new entries up to the total memory size. The
sampling probability is set according to the available flow table size,
following recommendations from \cite{estan2002new}.

\noindent (2) Count-min sketch augmented with a `heavy flow' cache: We simulate
the count-min sketch~\cite{cormode2005improved}, but use a flow cache to keep
flow keys and exact counts starting from the packet where a flow is {\em
  estimated to be heavy} from the sketch. We liberally allow the count-min
sketch to use the offline-estimated exact count of the $k$th heaviest
flow in the trace, as a threshold to identify heavy flows. The flow cache is
implemented as a hash table that retains only the pre-existing flow key on a
hash collision. We allocate half the available memory each to the sketch and the
flow cache.\footnote{This is similar to the memory splits used in \cite[page
    288]{estan2002new}.}

\begin{figure}[h]
\includegraphics[max height=11cm,max width=8cm]{CompFalseNeg.pdf}
\caption{Comparison of false negatives of \TheSystem to other
  baselines. \TheSystem outperforms sample and hold and count-min sketch over
  the entire memory range evaluated.}
\label{fig:FalseNegvsMSchemes}
\end{figure}

%% In order to evaluate our scheme against our two main competitors, we ran
%% \TheSystem, Count-Min Sketch with a cache and Sample and Hold on the same traces
%% with the same amount of memory (ranging from $5KB$ to $80KB$) and compared the
%% average rate of false negatives that each of the schemes produced across all the
%% traces in detecting the top $150$ flows. In the case of \TheSystem, the memory
%% provisioned is directly translated into a certain number of entries (flowid,
%% packet count pairs) in the hash table assuming that the flow-id is the 5-tuple
%% for an Ipv4 packet. For Sample and Hold, this translates into a similar number
%% of entries based on the same principle, but this is the maximum number of
%% entries that the flow memory can hold \cite{estan2002new}. For the count-min
%% sketch combined with cache, we allocate half of the memory to the sketch itself
%% and the other half to track the heavy-hitter flows in the cache, as suggested in
%% the analysis of the Multi-stage filter \cite{estan2002new}.

\NewPara{False negatives.} \Fig{FalseNegvsMSchemes} shows false negatives
against varying memory sizes, for the three schemes compared. We see that
\TheSystem outperforms sample and hold as well as the augmented count-min sketch
over the entire memory range. (All schemes have smaller errors as the memory
increases.) Notably, at 100KB memory, \TheSystem has 15\% smaller false negative
rate than sample and hold. The count-min sketch tracks the error rate of
\TheSystem more closely from above, staying within a 3-4\% error
difference. Next, we understand where the errors occur in the baseline schemes.

\NewPara{Where are the errors in the other baselines?} \Fig{relative-error}
shows the count estimation error (\%) averaged across flows whose {\em true
  count} is higher than the $x$-value in the graph, when running all the schemes
with 26KB memory.

Sample and hold can make two kinds of estimation errors. It can miss the first
set of packets from a heavy flow because of not sampling the flow early enough,
or (less likely) miss the flow entirely due to not sampling or the flow table
becoming full. \Fig{relative-error} shows that sample and hold makes
the former kind of error even for flows with very high true counts. For
example, there are relative errors of about 10\% even for flows of size more
than 80,000 packets. As \Fig{FalseNegvsMSchemes} shows, the errors becomes less
prominent as the memory size increases, since the sampling rate increases too.

The count-min sketch makes errors because of its inability to discriminate
between heavy and light flows during hash collisions in the sketch. This means
that a {\em light} flow colliding with heavy flows may occupy a flow cache
entry, preventing a heavier flow later on from entering the flow cache. For
instance in \Fig{relative-error}, even flows as large as 50,000 packets can have
estimation errors close to 20\%. However, as \Fig{FalseNegvsMSchemes} shows, the
effect of hash collisions becomes less significant as memory size increases.

On the other hand, \TheSystem's average error on flows larger than 20,000
packets---which is 0.2\% of the total packets in the interval---is negligible
(\Fig{relative-error}). \TheSystem has 100\% accuracy in estimating the count of
flows larger than 30,000 packets.

%% Fig \ref{fig:FalseNegvsMSchemes} suggests that all three schemes uniformly do
%% better at higher amounts of memory. \TheSystem outperforms both Sample and Hold
%% and the Count-min sketch based approach by over $10\%$ at smaller amounts of
%% memory, in terms of missing fewer of the heavy hitting flows. The reason for
%% this is that Sample and Hold only samples one among every so many flows,
%% depending on the sampling rate, which is decided once the flow memory size is
%% decided. Hence, it may lose some of the heavy-hitting flows altogether or may
%% sample a heavy-hitter so late in the measurement interval that its count is
%% underestimated significantly. A more detailed analysis of this effect is
%% illustrated in Figure \ref{fig:relative-error}.

%% Count-min sketch, on the other hand, does not discriminate between packets
%% belonging to a heavy flow vs. those belonging to a small flow, in maintaining
%% information in the sketch itself. As a consequence, in the count-min sketch
%% and cache scheme, if the smaller flows collide with a few heavy hitters, the
%% heavy hitters' counters themselves are overestimated (Figure
%% \ref{fig:relative-error}) along with the smaller flows occupying the space in
%% the cache that could have gone to true heavy hitters. This effect becomes
%% less prominent as the memory is increased, as Figure
%% \ref{fig:FalseNegvsMSchemes} shows . However, this scheme does rely on
%% setting the threshold for flagging a heavy hitter accurately in the count-min
%% sketch. A lower threshold would result in a lot of flows being added to the
%% cache at the expense of true heavy hitters. A higher threshold would prevent
%% legitimate heavy hitters from even entering the cache. Given that this
%% threshold involves the knowledge of the $k_{th}$ flow's size, this is a
%% somewhat circuitous approach to identifying the $k$ heaviest
%% flows.\vls{unsure if everything is needed}

%
%- sample and hold (currently top K)
%- count min + cache (currently threshold)
%- univmon? opensketch?
%- reversible sketch?
%- XXX: need to figure out exhaustive set of comparison schemes.

\begin{figure}[h]
\includegraphics[max height=11cm,max width=8cm]{RelativeError.pdf}
\caption{Comparison of average estimation error (\%) of flows whose true counts
  are higher than the $x$-value in the graph. Sample and hold underestimates
  heavy flows due to sampling, and count-min sketch misses heavy flows due to
  lighter flows colliding in the flow cache. \TheSystem has no estimation errors for
  flows larger than 30,000 packets.}
  %% Comparison of average relative error in the reported sizes of flows whose
  %% actual size is larger than a given actual flow size, when detecting $150$
  %% Heavy Hitters from $0.5M$ flows on average with $26KB$ ofmemory}
\label{fig:relative-error}
\end{figure}

%% Figure \ref{fig:relative-error} analyzes the average relative error in the
%% reporting of all flows larger than a certain size $x$ across all the
%% schemes. Here, the relative error for a given flow of actual size $s_i$ and
%% reported size $r_i$ computed as $|\frac{s_i - r_i}{s_i}|$. The average
%% relative error at size $s$ is then computed as the average among the relative
%% error of all flows that are as large as and larger than $s$. For example, at
%% $x = 20K$ (which is $0.2\%$ of the total number of packets seen in this
%% interval)the average error in the reported size of all flows larger than
%% $20K$ packets is almost negligible with \TheSystem, around $10\%$ of $20K$
%% \ie $2K$ packets with the Count-Min sketch and a cache, and around $20\%$ or
%% $4K$ packets with Sample and Hold. WHle all schemes report higher flows with
%% better accuracy, \TheSystem achieves the almost $100\% $accuracy for all
%% flows of size larger than $30K$, which is faster than the other two. This
%% accounts for its ability to report the heavy hitters more accurately than
%% either of the other two.

\subsection{\TheSystem\ \vs Idealized Schemes}\label{subsec:comparisonIdeal}

We now compare \TheSystem against the idealized algorithms it is derived from
(\Sec{sec:algorithm}), namely \spacesaving~\cite{metwally2005efficient} and
\Baseline.

There are two reasons why \TheSystem may do badly relative to \spacesaving: (i)
it may evict a key whose count is much higher than the table minimum, hence
missing heavy items from the table, and (ii) it may allow too many duplicate
flow keys in the table (\Sec{sec:feed-forward}), reducing the memory available
for heavy flows, and evict heavy flows whose counts are underestimated due to
the duplicates. We showed that duplicate keys are not very prevalent in
\Sec{subsec:sensitivity}; in what follows, we understand their effects on false
negatives in the reported top $k$ flows.

\NewPara{How far is the subsampled minimum from the true table minimum?}
\Fig{mindist} shows the complementary CDF of the minimum count that was chosen
by \TheSystem, obtained by sampling the algorithm's choice of minimum at every
100th packet in a 10 million packet trace. We don't show the corresponding CCDF
for the absolute minimum in the table, which only takes on two values---0 and
1---with the minimum being 1 more than 99\% likely.\footnote{Note that this is
  different from the minimum distribution of \spacesaving, which has much larger
  values in its support.}
%
We see that the chance that \TheSystem chooses a certain minimum value decreases
rapidly as that value grows, judging from the straight-line plot on log scales
in \Fig{mindist}.
%
For example, the minimum counter has a value higher than 5 less than 5\% of the
time. There are a few larger minimum values (\eg 100), but they are rarer (less
than 0.01\% of the time). This suggests that it is unlikely that \TheSystem
experiences large errors due to the choice of a larger minimum from the table,
when a smaller counter exists.
%% srinivas: we haven't discussed why the absolute minimum distribution is so
%% skewed: possibly because we always insert keys with values 1. It seems less
%% important, though.

\begin{figure}[h]
\includegraphics[max height=11cm,max width=8cm]{minDistribution.pdf}
\caption{Complementary CDF of the minimum chosen by \TheSystem on $26KB$ of
  memory, sampled every 100th packet from a trace of 10 million packets.}
\label{fig:mindist}
%plot CM, UnivMon, Reversible
\end{figure}

%% \TheSystem aims to model the Space Saving \cite{metwally2005efficient}
%% algorithm in a hardware-amenable version by sampling a few locations to
%% estimate the minimum instead of computing the global minimum. A natural
%% question to ask is how far are we in our minimum approximation fromt the
%% global minimum. We compared the minimum picked by \TheSystem with the actual
%% minimum in the table at the same-time for the hash table update corresponding
%% to every $100_{th}$ packet in the trace. Figure \ref{fig:mindist} shows the
%% complementary cumulative distribution function for the two minima. The two
%% distributions look reasonably similar indicating that the approximated
%% minimum isn't that far off from the actual minimum and it is very rarely
%% higher than $10$. Further, the true minimum of the table is almost always $1$
%% which is also expected since we insert flows with value $1$ in the first
%% table stage. Our scheme also reports $1$ as the actual minimum majority of
%% the time.

\begin{figure}[h]
\includegraphics[max height=11cm,max width=8cm]{FriendsFalseNeg.pdf}
\caption{Comparison of false negatives of \TheSystem to idealized schemes when
  detecting $k$=150 heavy hitters. In some memory regimes, \TheSystem may
  even outperform \spacesaving, while \Baseline closely tracks \spacesaving.}
%% \caption{False Negative Rate for memory sizes when detecting $150$ heavy hitters from $0.5M$ flows across $10M$ packets}
\label{fig:FalseNegvsFriendSchemes-k150}
%plot CM, UnivMon, Reversible
\end{figure}

\begin{figure}[h]
\includegraphics[max height=11cm,max width=8cm]{FriendsFalseNeg60.pdf}
\caption{Comparison of false negatives of \TheSystem to idealized schemes when
  detecting $k$=60 heavy hitters.}
%% \caption{False Negative Rate for memory sizes when detecting $60$ heavy hitters
%%   from $0.5M$ flows across $10M$ packets}
\label{fig:FalseNegvsFriendSchemes-k60}
%plot CM, UnivMon, Reversible
\end{figure}

\NewPara{Comparison against \spacesaving and \Baseline.} We compare the false
negatives of the idealized schemes and \TheSystem against varying memory sizes
in \Fig{FalseNegvsFriendSchemes-k150} and \Fig{FalseNegvsFriendSchemes-k60},
when reporting two different number of heavy hitters, $k$=150 and $k$=60
respectively. Two features stand out from the graph for both $k$ values. First,
wherever the schemes operate with low false negative error (say less than 20\%),
the performance of the three schemes is comparable (\ie within 2-3\% of each
other). Second, there are small values of memory where \TheSystem\ {\em
  outperforms} \spacesaving.

Why is \TheSystem outperforming \spacesaving? \spacesaving only guarantees that
the $k$th heaviest item is in the table when the $k$th item is larger than the
average table count (\Sec{sec:spacesaving}). In our trace, the 60th item and
150th item contribute to roughly 6000 and 4000 packets out of 10 million
(resp.), which means that they require at least\footnote{10 million / 6000
  $\approx$ 1700; 10 million / 4000 $\approx$ 2500.} 1700 counters and 2500
counters in the table (resp.). These correspond to memory sizes of 30KB and 45KB
(resp.). At those values of memory, we see that \spacesaving starts
outperforming \TheSystem on false negatives.

We also show why \spacesaving fails to capture the heavier flows when it is
allocated a number of counters smaller than the minimum number of counters
mentioned above. Note that \TheSystem attributes every packet to its flow entry
correctly (but may miss some packets entirely), since it always starts a new
flow at counter value 1. However, \spacesaving increments {\em some counter} for
every incoming packet (\Alg{spacesaving}). In contexts where the number of
active flows is much larger than the number of available counters (\eg 400,000
flows with 1200 counters), this can lead to some flows having enormously large
(and grossly overestimated) counters. In contrast, \TheSystem keeps the counter
values small for small flows by evicting the flows (and counts) entirely from
the table.

At memory sizes smaller than the thresholds mentioned above, incrementing a
counter for each packet may result in {\em several small flows} catching up to a
heavy flow, leading to significant false positives, and higher likelihood of
evicting truly heavy flows from the table. We show this effect on \spacesaving
in \Fig{SSkeysperbucket} for $k$=150 and $m$=1200 counters ($m$=2500 needed).
The distribution of the number of keys contributing to a false positive flow
counter in the table is clearly shifted to the right relative to the
corresponding distribution for a true positive flow counter.
%
%% A similar and
%% natural characterization of the distributions holds for the estimation errors
%% from the different categories of flow keys, shown in \Fig{SSdevperbucket}.

%% To quantify how we do compared to \spacesaving, we compared the performance of
%% \TheSystem against the intermediate \Baseline as well as \spacesaving in terms
%% of the false negative rate in the reporting of $150$ heavy hitters with
%% different amounts of memory. As reported in Figure
%% \ref{fig:FalseNegvsFriendSchemes}, \Baseline is almost identical to \spacesaving
%% in its performance. This is not surprising since Figure \ref{fig:mindist} shows
%% that sampling the minimum doesn't result in such a different distribution from
%% the actual minimum. However, \TheSystem has significantly lower false negative
%% rates (by almost $15\%$) than either of them at almost all memory sizes. This is
%% attributed to the fact that \TheSystem inserts a new flow with value $1$ in the
%% first table while \spacesaving and \Baseline both replace it with the current
%% minimum value incremented by $1$.

\begin{figure}[h]
\includegraphics[max height=11cm,max width=8cm]{SSKeysPerBucketDist.pdf}
\caption{CDF of the number of distinct flows contributing to a counter in
  \spacesaving's table, when identifying $k$=150 heavy flows with $m$=1200
  counters. We show three distributions according to the flow's label after the
  experiment.}
%% \caption{Chances of a given bucket having a certain number of keys contributing
%%   to it when running \spacesaving to identify $150$ heavy hitters with $1200$
%%   counters. Legend represents category that the flow found in a bucket at the
%%   end of the interval belongs to.}
\label{fig:SSkeysperbucket}
\end{figure}

%% When the number of flows and packets in a network are high (around two orders
%% of magnitude more than the number of entries in the table), the fact that
%% every packet causes at least one counter to increment by $1$
%% \cite{metwally2005efficient} without any evictions results in a large average
%% counter value.  This large average counter could be even larger than some of
%% the heavy hitter flows resulting in certain mice flows being incorrectly
%% reported while other legitimate hevay hitters are missed. To analyze this, we
%% observed the number of keys that contributed to the count in every bucket at
%% the end of the measurement interval in Space-Saving when run with $1200$
%% counters. In addition, we analyzed what the reported size of the flow in the
%% bucket was and how it compared to the actual size of the flow (relative error
%% of that flow). We then classified the flows based on whether they were True
%% Positives, False Positives or neither in the context of the top $150$ flows.

%% \begin{figure}[h]
%% \includegraphics[max height=11cm,max width=8cm]{SSDeviationPerBucketDist.pdf}
%% \caption{CDF of the count estimation error (\%) of different flows in
%%   \spacesaving's table, when identifying $k$=150 heavy flows with $m$=1200
%%   counters. We show three distributions according to the flow's label after the
%%   experiment.}
%% \label{fig:SSdevperbucket}
%% \end{figure}

%% Figure \ref{fig:SSkeysperbucket} shows that the number of keys contributing to a
%% particular bucket is over $2000$ in more than half the buckets. If each of those
%% keys contributed even two packets, that would be over the actual true count of
%% the average $150^{th}$ ranked flow. Thus even a few such buckets would start
%% competing heavily against the true heavy hitters, as illustrated in the false
%% positive line of the plot. Similarly, according to Figure
%% \ref{fig:SSdevperbucket}, the relative error with those flows in the table that
%% are not true positives is so high that it indicates the possibility that if
%% these were medium-sized in the first place, they could, once again, easily
%% replace the true-positives.

\NewPara{Impact of duplicate keys in the table.} Finally, we investigate how
duplicate keys and consequent underestimation of flow counts in the table may
affect the errors of \TheSystem. In \Fig{reportingMoreThanK-falseneg}, we show
the benefits of reporting {\em more than $k$ counters} on false negatives, when
the top $k$=300 flows are requested with a memory size of $m$=2400 counters.
While the false negative rates of \spacesaving and \Baseline improve
significantly with overreporting, the errors for \TheSystem remains flat
throughout the interval, dropping only around 1800 reported flows. We infer that
most heavy flows are retained somewhere in the table for \spacesaving and
\Baseline, while \TheSystem underestimates keys sufficiently often that they are
completely evicted---to the point where overreporting does not lower the false
negative errors. \Fig{reportingMoreThanK-falsepos} shows that overreporting
flows only increases the false positive errors slightly for all schemes, with
values staying between 0.1-0.5\% throughout.

\begin{figure}[h]
\includegraphics[max height=11cm,max width=8cm]{FriendsFalseNegWithRep.pdf}
\caption{Benefits of overreporting flows from the table on false negative errors
  with $k$=300 heavy flows and $m$=2400 counters. While \spacesaving and
  \Baseline improve significantly when reporting even as many as $2k$ flows,
  \TheSystem does not, because of evictions due to duplicate entries.}
%% \caption{
%%   Comparison of false negatives of HashPipe to \spacesaving and Hash
%%   Parallel when reporting more than $k$ candidate flows. \spacesaving and
%%   HashParallel significantly outperform HashPipe even with $2k$ reported flows}
\label{fig:reportingMoreThanK-falseneg}
\end{figure}

\begin{figure}[h]
\includegraphics[max height=11cm,max width=8cm]{FriendsFalsePosWithRep.pdf}
\caption{Impact of overreporting flows from the table on false positive errors
  with $k$=300 heavy flows and $m$=2400 flows. %%The errors stay within a small
  %%range.}
  }
\label{fig:reportingMoreThanK-falsepos}
\end{figure}

%%
%- scatter plots to show where errors arise in our scheme. Sources of error include effect of hash collisions and packet interleaving. Possibly talk about prevalence of duplicates in sequential probing as a source of error. (generate graph here)
%- impact of (i) subsampling the table (as opposed to looking at the entire table), assuming you see all $D$ probes at once (ii) partial knowledge/sequential lookup instead of seeing all $D$ locations at once.
%(the two categorizations above may lead to the same!)
%%

%%

%zoomed in only top 1000 flows
%Focusing on only the top 1000 flows
%\includegraphics[max height=11cm,max width=8cm]{image031}
%\includegraphics[max height=11cm,max width=8cm]{image033}


\chapter{Thermohaline overturning circulation}
\label{ch:thermohaline}

%\includegraphics[width=6in]{figs/WaterMasses/Schmitz96Fig91.png}
\includegraphics[width=6in]{figs/WaterMasses/HansellEtAl09.png}

The water masses we saw in the previous chapter are the result of water formation at the ocean's surface, and for those that make it to depth, sinking of water.  From the picture in \fref{fig:AnnotateSections}a it is very evocative of the idea that dense water is created in the Southern Ocean and then sinks along the bottom to the north and fills the bottom basin of the Pacific.  However, if that sinking of cold salty water happens all the time (and evidence is that it does), then there are  two choices for where that water ends up eventually.  The deep ocean could fill up with cold, salty water, or heat and fresh water can mix from above and modify it.

We sketch this here, where the $1.1^oC$ isotherm is highlighted (\fref{fig:AnnotatePacific}.  The dense water flows counter clockwise in this sketch, and must cross isotherms in order to complete the closed circuit.  If water crosses an isotherm, it must warm, and the only way for this to happen is by vertical mixing.  This chapter discusses this circulation, the evidence for it, and the mechanisms that drive it.

\begin{figure}[hbt]
  \begin{center}
    \includegraphics{figs/WaterMasses/AnnotatePacific}
    \caption{Sketch of deep overturning circulation in the Pacific.  Green contour is the 1.1 degree-C isotherm (approximately) and the purple lines are idealized paths taken by the water.}
    \label{fig:AnnotatePacific}
  \end{center}
\end{figure}

\section{Inferring the overturning circulation from other tracers}

\subsection{Bio-active tracers}

The physical tracers like temperature and salinity are \emph{conservative} in that they cannot be destroyed or consumed in the water column.  This is not the case with bio-active tracers which change as the water is exposed to biological activity.   In general, the upper ocean where sunlight can penetrate is dominated by photosynthesis, where plants, largely phytoplankton,  convert CO2 and nutrients to Oxygen.  Outside the euphotic zone, the ocean is dominated by respiration, where animals and bacteria consume oxygen and respire CO2.  This leads to the general picture in \fref{fig:P16BioActive}.  The youngest water near the surface is high in O2 and low in CO2 and nutrients like Nitrate and Silica.  The Antarctic Intermediate water is a clear plume of high-O2 water being pushed south under the subtropical gyre.  The Antarctic bottom water is seen pouring into the  Pacific and losing oxygen as it moves north and gaining CO2.  The lowest oxygen and highest CO2 are found at around 1000 m in the north Pacific. Based on this logic alone we might argue that the oldest water is where this oxygen minimum is.  That would not quite be correct - the oldest water is thought to be about 1000 m deeper (see the next section), and that is because the net respiration rate tends to decrease with depth.

Nitrate and Silica are also highest at this point, though the have maxima at slightly different depths.  Nutrients accumulate in the water column largely due to sinking of particles from the near-surface ocean. The particles that have large silica content like shells and bones tend to sink deeper than more labile material (bodies, fecal pellets) that contains significant nitrate.  So, similarly to oxygen, the minimima and maxima of the nutrients gives the correct sense of water sinking in the Southern Ocean and rising in the North Pacific, but the details depend on biological processes.

If we knew the rate of oxygen consumption, or the rate of particle fluxes in the deep ocean, we could use this information to estimate the strength of the overturning circulation.  So if  this rate were on average c umol/kg/day, and there is 200 umol/kg difference between the AABW oxygen content and the oxygen minimum in the north Pacific, we could make an estimate of how many days it would take for the water to get to that minimum.  Unfortunately, for most of the biological tracers, the consumption/production rates are poorly constrained, and understood to be spatially variable, so this approach is not typically used.

\begin{figure}[hbt]
  \begin{center}
    \includegraphics{figs/WaterMasses/P16OxygenCrop}
    \includegraphics{figs/WaterMasses/P16CO2Crop}
    \includegraphics{figs/WaterMasses/P16NitrateCrop}
    \includegraphics{figs/WaterMasses/P16SilicaCrop}
    \caption{Bio-active tracers in the Pacific ocean along P16.  From the \href{http://whp-atlas.ucsd.edu/pacific_index.html}{WOCE Atlas of the Pacific}. }
    \label{fig:P16BioActive}
  \end{center}
\end{figure}
\clearpage
\subsection{Radioactive and tracers from the crust}

The age of water can be relatively accurately determined by carbon data using the radioactive isotope $^{14}C$. This carbon isotope is produced in the atmosphere when cosmic rays impact nitrogen molecules.  As such, $^{14}C$ concentrations are highest in the surface ocean (\fref{fig:P16Radioactive}).  $^{14}C$ decays, but unlike bio-active tracers, it decays at a known steady rate, with a half-life of \href{https://en.wikipedia.org/wiki/Carbon-14}{5,730 years}.  Knowing this decay rate, and the relative abundance in the atmosphere, we can arrive at an average age for a water parcel, keeping in mind that there has necessarily been mixing with the water masses above.  From this we can see that the oldest water in the Pacific is probably at about 2500 m depth in the North Pacific.

There are some caveats to looking at $^{14}C$, tho most obvious one is that the water signal can be contaminated by organic matter raining down from above.  This organic matter will have younger $^{14}C$ in it, so the water will be deduced to be younger than it is.  There is another bias that will make the water look younger, in that if young water is mixed with old water, the age is actually a logarithm of the concentration, and logarithms cannot be added linearly.  This turns out to be a difficult problem, so that accurately estimating the age of the water requires complicated inverses of where the water has been and what water masses have mixed to produce it over its history.

Recent attempts to estimate water mass age using $^{14}C$ give estimates of water as old as 1500 y in the north Pacific, and at the north end of the Indian Ocean.  Atlantic water tends to be younger, reaching about 700 years old, because it is heavily influenced by the shallower overturning of the North Atlantic Deep Water.  These number speak to the sluggishness of the overturning circulation.  In the Pacific, the bottom water is almost 1000 years old by the time it reaches the equator, or a speed of approximately 7.7 km-per-year in the horizontal, or
$2.5\times 10^{-7}\ \mathrm{m\,s^{-1}}$

\begin{figure}[hbt]
  \begin{center}
    \includegraphics{figs/WaterMasses/P16DC14Crop}
    \includegraphics{figs/WaterMasses/P16dC13Crop}
    \includegraphics{figs/WaterMasses/P16d3HeCrop}
    \caption{Radioactive and crust tracers in the Pacific ocean along P16.  From the \href{http://whp-atlas.ucsd.edu/pacific_index.html}{WOCE Atlas of the Pacific}. }
    \label{fig:P16Radioactive}
  \end{center}
\end{figure}

\begin{figure}[hbt]
  \begin{center}
    \includegraphics{WaterMasses/GebbieHuybers12Fig8Crop}
    \caption{Average age of water in the three ocean basins as estimated from $^{14}C$ data \citep{gebbiehuybers12}.}
    \label{fig:GebbieHuybers12Fig8}
  \end{center}
\end{figure}

The isotope $^3He$ is an interesting tracer because it largely comes from ocean hydrothermal vents (\fref{fig:P16Radioactive}c).  The two large peaks in the middle of the section arise because the cruise passed close to the East Pacific Rise at these locations.

\clearpage
\subsection{Man-made tracers}

Anthropogenic tracers are also useful for tracking ocean processes.  The only problem is that most of these are modern, and hence only track the upper ocean (\fref{fig:P16Manmade}).  In fact these tracers give an idea of just how \emph{slow} the circulation is.  Tritium is largely a product of nuclear weapons testing, which was predominantly carried out in the atmosphere in the 1960s (\fref{fig:TritiumOttawa}).  This makes for a nice tracer spike that shows how far water transited in the 35 years when  the WOCE lines were run (\fref{fig:P16Manmade}).  Similarly, CFC-11 and -12 saw an exponential increase in emissions until the 1970s when the danger of CFCs to the ozone layer was realized, and dropped off after the Montreal Protocol, when they were finally banned.

\begin{figure}[hbt]
  \begin{center}
    \includegraphics[width=3in]{figs/WaterMasses/TritiumOttawa}
    \caption{Tritium time series in the atmosphere measured at Ottawa and Vienna.  Note the logarithmic vertical scale, so almost all the input was in the 1960s}
    \label{fig:TritiumOttawa}
  \end{center}
\end{figure}

\begin{figure}[hbt]
  \begin{center}
    \includegraphics[width=3in]{figs/WaterMasses/Emissions-estimates-for-CFC-11-blue-CFC-12-green-and-CFC-113-orange-based-on.png}
    \caption{Global CFC emissions, estimated from atmospheric concentrations \citep{Allin_2015}.}
    \label{fig:CFCEmmisions}
  \end{center}
\end{figure}

All three man-made tracers had relatively minimal penetration into the  deep ocean when the P16 lines were occupied, but \emph{clearly} show up in the Southern Ocean as a plume of high concentrations.  Of course the upper ocean has substantial quantities of these tracers.

\begin{figure}[hbt]
  \begin{center}
    \includegraphics[width=3.8in]{figs/WaterMasses/P16TritiumCrop}
    \includegraphics[width=3.8in]{figs/WaterMasses/P16CFC11Crop}
    \includegraphics[width=3.8in]{figs/WaterMasses/P16CFC12Crop}
    \caption{Man-made tracers along P16.  From the \href{http://whp-atlas.ucsd.edu/pacific_index.html}{WOCE Atlas of the Pacific}. Note that this section was collected in 1991.}
    \label{fig:P16Manmade}
  \end{center}
\end{figure}

The WOCE cruises along P16 spanned the years 1991-1993.  These waters were resampled again as part of the CLIVAR/GO-SHIP program in 2014-2015 (\fref{fig:P16CFCWOCECLIVAR}) and the intervening 21-24 years do show some change.  These changes are particularly pronounced in the intermediate waters with CFCs transiting substantially deeper and more equatorward.  The CFCs also appear to have mixed from the surface ocean to deeper, with the CFC-gradient descending around 200 m in most of the basin. In the deep ocean, however, there is still little evidence of CFC penetration.  Looking south of 60 S, there is some evidence that high CFC waters are trying to push over the ridge, and there are perhaps some heightened values along the bottom south of 30 S, but if so, then these values are very diluted.  Overall the manmade tracers show how old and slow the deep ocean bottom circulation is.

\begin{figure}[hbt]
  \begin{center}
    \includegraphics[width=3.8in]{figs/WaterMasses/p16_cfc11_woce.png}
    \includegraphics[width=3.8in]{figs/WaterMasses/p16_cfc11_2014_2015.png}
    \caption{CFC-11 along P16, during WOCE (1991-93) and the GO-SHIP/CLIVAR re-occupation (2015-16).  Note there are some poor-quality samples in the WOCE section deeper than 2000 m between 30S and 15 S.  Figure courtesy S. Mecking.}
    \label{fig:P16CFCWOCECLIVAR}
  \end{center}
\end{figure}

\clearpage

\section{Deep water formation processes}

The densest water in the global ocean is formed at the high latitudes.  The densest water is formed in the Wedell and Ross Seas in the southern ocean.  Deep water formation processes are notoriously hard to observe, but the mechanisms are relatively well understood.

\subsection{Antarctic Bottom Water}

\begin{marginfigure}
  \includegraphics[width=2.3in]{figs/WaterMasses/Gordon09Fig3}
    \caption{Schematic of deep water formation in the marginal seas of Antarctica \citep{gordon01}.}
    \label{fig:Gordon09Fig3}
\end{marginfigure}

In the Antarctic, dry cold continental air blows off the continent \fref{fig:Gordon09Fig3}.  These winds can be quite strong and work to push sea ice off the landmass, often opening up \emph{leads} and \emph{polynyas}, despite the cold air.  These polynyas are regions of very large heat loss, both latent and sensible.  Further, they create more ice (which is then pushed offshore), and ice creation leads to brine rejection, which makes the water very salty.

Detailed observations in the Southern ocean make this process clear \fref{fig:stewartthompson16}.  In these observations, the cold water that comes from the shallower basins to the southeast are observed hugging continental slope.  The very cold water at the bottom is colder than Antarctic Bottom Water, but mixes with the shallower as it descends the slope to make water that is between -1 and 0 C.

\begin{figure}[hbt]
  \begin{center}
  \includegraphics{figs/WaterMasses/StewartThompson16Fig1}
    \caption{bathymetry of the Wedell Sea, and a section of density  contours with temperature coloured underneath.  Note the cold dense water sinking along the continental slope. \citep{stewartthompson16}.}
    \label{fig:stewartthompson16}
  \end{center}
\end{figure}

\subsection{North Atlantic Deep Water}

North Atlantic Deep Water starts in a similar way to Antarctic Bottom Water, with an origin on the Barents Sea shelf.  Conversely to the Antarctic, this water forms largely free from ice cover, and hence brine rejection is not too important a part of the process.  This cold water flows into the Greenland Sea where it mixes with cold water experiencing convection (\fref{fig:NADWSketch}).  This water pours over the Denmark Straits just east of Greenland, and is further diluted with warm salty water from the North Atlantic.  This current is added to from convection in the Larbador Sea.

\begin{figure}[hbt]
  \begin{center}
    \includegraphics{figs/WaterMasses/NADWSketch}
    \caption{Sketch of paths taken by North Atlantic Deep Water. \citep{currymauritzen2005} }
    \label{fig:NADWSketch}
  \end{center}
\end{figure}

Deep-water convection is very easy to observe in the Labrador Sea, between Labrador and Greenland.  In the winter, convective mixing can create a mixed layer that is over 2000 m deep \fref{fig:Lazier01Fig9}.  This is caused by cooling, and mixing of relatively fresh water near the surface with warmer saltier water that comes in from the side.  This process varies each year, and sometimes the convection is not as deep in one year as in other years (\fref{fig:KiekeYashayaev15}).  In some years there is no convection at all, like 2007, whereas in others there is very deep convection, like in 2008.

\begin{figure}[hbt]
  \begin{center}
    \includegraphics{figs/WaterMasses/Lazier01Fig9}
    \caption{Evidence of convection in the Labrador Sea from a section across the Sea in June 1993.  Note the very homogeneous water in the central Labrador Sea, with mixing deeper than 2000 m.  }
    \label{fig:Lazier01Fig9}
  \end{center}
\end{figure}

\begin{figure}[hbt]
  \begin{center}
    \includegraphics{figs/WaterMasses/KiekeYashayaev15}
    \caption{Time series of convection in the Labrador Sea as measured by autonomous Argo profiling floats \citep{kiekeyashayaev15}}
    \label{fig:KiekeYashayaev15}
  \end{center}
\end{figure}

This water flows South, hugging the western boundary of the Atlantic ocean in a narrow order 100-km wide flow, that mixes as it goes (\fref{fig:DenglerEtAl06Fig1}).  The boundary current is remarkably persistent, being traced as far south as Florida (\fref{fig:StahrSanford99Fig4}), where bathymetry roughens and disperses the flow.  The flow hugs this side of the basin due to the Coriolis force, and doesn't fall down the slope for the same reason.  Bottom friction does cause it to move downslope slowly, but despite 1600 km of distance between the two sections, its clear that the current hasn't descended very much.
\begin{figure}[hbt]
  \begin{center}
    \includegraphics{figs/WaterMasses/DenglerEtAl06Fig1}
    \caption{Observations of Deep Western Boundary Current off the Grand Banks.\citep{schottetal06}}
    \label{fig:DenglerEtAl06Fig1}
  \end{center}
\end{figure}

\begin{figure}[hbt]
  \begin{center}
    \includegraphics{figs/WaterMasses/StahrSanford99Fig4}
    \caption{Observations of the Deep Western Boundary  Current off Blake Outer Ridge (32 N) \citep{stahrsanford1999}}
    \label{fig:StahrSanford99Fig4}
  \end{center}
\end{figure}

\section{Inferring the strength of the overturning circulation from data}

The strength of the overturning circulation is almost impossible to infer directly from measuring ocean velocities, and hence it is inferred from ``inversions'' of data collected on hydrographic cruises such as the WOCE and CLIVAR cruises mentioned above.  We haven't discussed geostrophic transport yet, but it will be discussed in future chapters.  However, knowing the density distribution along a section will give us an estimate \emph{within a constant} of the transport of water \emph{across} that section (\fref{fig:SketchCrossSection}.  This somewhat un-intuitive result is because the Coriolis force acting on the moving water balances the pressure gradients.

\begin{marginfigure}
    \includegraphics{figs/WaterMasses/SketchCrossSection}
    \caption{Sketch of cross section in a basin.  A hydrographic cruise that has crossed the basin making measurements will give estimates of the pressure gradients along the section, which can be used to estimate the velocity across the section.}
    \label{fig:SketchCrossSection}
\end{marginfigure}

There are unknowns in making these estimates, which can be constrained for by making mass, heat, salt, and other tracers balance in the basins.  We will discuss these results and how they are obtained briefly below.

\subsection{Inverse results}
\label{sec:inverse_results}

The large amounts of data collected during the WOCE and CLIVAR cruises have undergone substantial analysis to determine the strength of the overturning circulation.  The final result is what is described above, but quantified.
Globally, there are two overturning cells, one that sinks in the southern ocean, and the other that sinks in the North Atlantic (\fref{fig:LumpkinSpeer07Fig2}.  The Southern overturning cell is denser and flows under the North Atlantic cell on average.
(The way these flows are contoured in \fref{fig:LumpkinSpeer07Fig2} may be unfamiliar to some readers, so please see \fref{box:Streamlines}).

\begin{figure}[hbt]
  \begin{center}
  \includegraphics{figs/WaterMasses/LumpkinSpeer07Fig2}
    \caption{Estimate of the strength of the global overturning circulation plotted as a stream function.  The upper plot is the streamfunction plotted with the density of the water as the vertical axes, whereas the lower plot is the depth of the ocean \citep{lumpkinspeer07}.  The stream functions are plotted in units of $Sv$, where $1\,Sv = 10^{6}\ \mathrm{m^3\,s^{-1}}$}
    \label{fig:LumpkinSpeer07Fig2}
  \end{center}
\end{figure}

\begin{derivbox}[label={box:Streamlines}]{Quantifying flows with streamlines}

A ``streamline'' is a path followed by a parcel in a \emph{steady} flow.  These paths are plotted in 2-dimensions in \fref{fig:LumpkinSpeer07Fig2} and represent the average path of the flow averaged around the world.  This tells us qualitatively where the flow goes.

Streamlines also receive a quantity proportional to the total water transported from the point of the streamline relative to some zero.  So in the sketch below, showing an idealized river, the zero is the southward bank of the river.  The $1\ \mathrm{m^3\,s^{-1}}$ streamline denotes how far across the river you would need to go to get that much downstream (or along streamline) transport.

\begin{center}
  \includegraphics[width=3in]{figs/WaterMasses/SketchStreamline}

\end{center}

If the streamlines are drawn so that they have equal transport between them, then the spacing between streamlines is inversely proportional to the speed.  So in the above plot the streamlines get closer together as the river narrows the speed necessarily increases.

Closed streamlines, as we see above (\fref{fig:LumpkinSpeer07Fig2}) indicate that the flow is circulating around a circuit.  The more streamlines the stronger the recirculation.

\end{derivbox}

The streamlines look different in the two plots of \fref{fig:LumpkinSpeer07Fig2} because of the different averaging.  However, the absolute values are the same - $20.9 \pm 6.7 \ \mathrm{Sv}$ for the Antarctic Bottom Water cell and $17.2\pm 3.2 \ \mathrm{Sv}$ for the North Atlantic Deep Water cell (the unit $\mathrm{Sv}$ is called a \emph{Svredrup} after Harald Sverdrup and $1\,\mathrm{Sv} = 10^{6}\ \mathrm{m^3\,s^{-1}}$).

An important reason to plot \fref{fig:LumpkinSpeer07Fig2} with density on the y-axis is to note where mixing is believed to happen.  If water is going down in this reference frame, then it is getting denser, and that must be happening largely due to cooling or mixing with cold water.  If water is going up along this axis it is being warmed by mixing with warm water above.

There is a stark difference in the overturning circulation between the Atlantic ocean and the Pacific and Indian due to Atlantic Deep Water formation (\fref{fig:LumpkinSpeer07Fig3}).  We see that the deep water in the Atlantic mostly moves south and that there is very little AABW recirculating in that basin.  Conversely, in the Pacific the deep circulation is dominated by the AABW recirculating cell to quite low densities.

\begin{figure}[hbt]
  \begin{center}
  \includegraphics{figs/WaterMasses/LumpkinSpeer07Fig3}
    \caption{As in \fref{fig:LumpkinSpeer07Fig2}, but divided by ocean basin}
    \label{fig:LumpkinSpeer07Fig3}
  \end{center}
\end{figure}

The strength of the overturning, divided by basin, is shown in \fref{fig:LumpkinSpeer07Fig4}.  The Pacific and Indian each support approximately 10 Sv of upwelling of AABW, while only 5 Sv is upwelled in the Atlantic. However, 17 Sv of NADW is also upwelled in the Atlantic, albeit from a less dense water mass.   There are numerous complicated connections of the water int he upper ocean that must be tracked in order to balance the flux of water, including a very strong exchange between the Indian and Pacific oceans through Indonesia and near Australia.

\begin{figure}[hbt]
  \begin{center}
  \includegraphics{figs/WaterMasses/LumpkinSpeer07Fig4}
    \caption{Strength of overturning circulation in various basins in $\mathrm{Sv}$.  Blue is the AABW, green is ``deep water'', yellow are ``intermediate'' waters, and orange surface water. \citep{lumpkinspeer07}}.
    \label{fig:LumpkinSpeer07Fig4}
  \end{center}
\end{figure}

Similar calculations can be presented in different ways.  \fref{fig:ganachaudwunschFig2} shows the transport of various water masses through the world's oceans.   Sinking in the Southern ocean and Greenland-Icealand Norway (GIN) seas then upwells in the various basins as shown by the green or blue arrows.  Note that 15 Sv that is produced in the GIN seas eventually is transported to the Southern ocean where it either downwells again as AABW \emph{or} upwells into the surface layer via mixing.

\begin{figure}[hbt]
  \begin{center}
  \includegraphics{figs/WaterMasses/ganachaudwunsch00Fig2}
    \caption{Arrows show lateral transport (in Sv) of upper- (red), mid- (blue), and deep (green) waters through WOCE hydrographic sections.  X-symbols show flow downwards out of a layer into the next layer below.  Dot-circle symbols show flow up out of a layer into the layer above.  So the upwelling associated with AABW is shown with green dot-circle signals in the three oceans.  \citep{ganachaudwunsch00}}.
    \label{fig:ganachaudwunschFig2}
  \end{center}
\end{figure}

\subsection{How to make an inverse calculation}

The inverse calculations that go into creating the estimates above are simple in concept, but complicated in execution.  The simplicity comes from just assuming a simple mass balances as we did in previous chapters, and assuming that the ocean is broadly in steady state.

A very simple example of such an inverse calculation comes from the flow of Antarctic Bottom Water into the Brazil Basin \fref{fig:MorrisEtAl01Fig1}. Water colder than 1 deg C enters in the Vema Channel from the south, but is not observed to make it out of the Brazil Basin.    This can be seen in \fref{fig:MorrisEtAl01Fig4}, where water 1.2-degrees and colder is blocked at the north end of the basin.

Channels like the Vema Channel are nice, because the flow can be  monitored with moorings, which was done in the late 70s \citep{hoggetal82} and again late 90s \citep{morrisetal01}.  These moorings found, on average, 3.7 Sv of water flowed in the channel that was colder than 1.2 degrees \citep{morrisetal01}.  This water, on average, is 0.2 degrees-C.

\begin{figure}[hbt]
  \begin{center}
    \includegraphics[width=3in]{figs/WaterMasses/MorrisEtAl01Fig1}
    \caption{Map of the Brazil Basin \citep{morrisetal01}}
    \label{fig:MorrisEtAl01Fig1}
  \end{center}
\end{figure}
\begin{figure}[hbt]
  \begin{center}
    \includegraphics{figs/WaterMasses/MorrisEtAl01Fig4Ann}
    \caption{Hydrography along the Brazil Basin.  Note that water colder than 1.2 degrees C does not make it out the north end.   \citep{morrisetal01}}
    \label{fig:MorrisEtAl01Fig4}
  \end{center}
\end{figure}

We can apply a volume budget and a heat budget to the problem, by considering a volume bounded by the Vema channel at the south, the north end of the Brazil Basin, and the 1.2 degree isotherm at the top.  The volume budget is straight forward - if 3.7 Sv enters in Vema Channel and there is no outlet to the north, it must cross the 1.2 degree isotherm.  $Q_{in} = Q_{out}$.

The heat budget is almost the same, but we need to include the heating due to diffusion at the top of our volume:
\begin{equation}
    h_{in} + h_{diffusion}= h_{out}
\end{equation}
where $h_{in} \approx  3.7 \mathrm{Sv}\, 0.0 \mathrm{C} = 0 \mathrm{Sv\,C}$, and $h_{out} \approx 3.7 \mathrm{Sv}\, 1.2 \mathrm{C} = 4.4 \mathrm{Sv\,C}$.  This means that the residual has to come into the volume via diffusion:
\begin{equation}
    h_{diffusion} = K \frac{d\theta}{dz} A
\end{equation}
where $\frac{d\theta}{dz}$ is the average vertical temperature gradient at the top of the volume, and $A\approx 7\times10^{12}\mathrm{m^2}$ is the area of the 1.2 degree isotherm in the basin.  There were lots of hydrographic cruises made in the Brazil basin, such that the gradient was found to be
$\frac{d\theta}{dz}\approx 2.1\times10^{-3}\mathrm{C\,m^{-1}}$. This leaves us with only one unknown, $K$, the turbulent diffusivity necessary to mix the temperature gradient fast enough to counter the cold water coming into the basin from the south.  And carrying out the math, we get a final answer of $K\approx 3\times10^{-4}\ \mathrm{m^2s^{-1}}$.   \citet{morrisetal01} divide the water in the basin into more layers and determine that the turbulent diffusivity is between 2 and $3\times 10 ^{-4}\ \mathrm{m^2\,s^{-1}}$ .  Note that this is over 1000 times the molecular diffusivity of heat, so turbulence must be responsible for this inferred mixing.

The amount of turbulence required to maintain such a high turbulent diffusivity is moderately strong.  Field work was carried out there to measure the turbulence directly using instruments called \emph{shear probes}, which are 1-cm scale phonograph needles encased in a silicone tip.  The results show that there is indeed substantial mixing in the Brazil Basin, but that it is not at all homogeneous, with the strongest mixing occurring on the east side where there is substantial roughness (\fref{fig:PolzinEtAl97Fig2}).  Indirect evidence is that this heightened mixing is due to tides moving back and forth over the rough bathymetry and creating turbulence with the stratified water above.  Note that in most of the basin, even above the rough topography, the turbulence is substantially \emph{lower} than the mean inferred from the inverse calculation.  However, the mean is dominated by the few red and orange pixels in the data, and there are enough of those that the average comes out to $0.5-1.5\times10^{-4}\ \mathrm{m^2\,s^{-1}}$ \citep{polzinetal97}.  This is within a factor of two of the inverse estimate, and probably within error bounds of both.  It is also likely that the Brazil Basin is undersampled by the turbulence measurements and there is some mixing ``hot spots'' that the sampling missed.

\begin{figure}[hbt]
  \begin{center}
  \includegraphics{figs/WaterMasses/PolzinEtAl97Fig2}
    \caption{Turbulence diffusivity inferred from directly measuring turbulence.  The cross section is made west-to-east across the Brazil Basin, and the 0.8-degC isotherm is shown in white. \citep{polzinetal97} }
    \label{fig:PolzinEtAl97Fig2}
  \end{center}
\end{figure}

Extending the inverse estimate made in the Brazil Basin to the global oceans is exactly what was done in \fref{sec:inverse_results}.  Volumes of the ocean were constrained by the cross-basin cruises. However, in addition to an unknown diffusivity in the ocean, there were unknown offsets in the velocity measurements (because we do not have current meters everywhere in the ocean), and sampling errors due to temporal variability.  So, what is done for global estimates is to use substantially more data from other tracers.  These tracers have their own uncertainties; for instance silicate is used, but the accumulation of silicate in the deep ocean is an unknown.  C14 is used, but will be biased by particles raining down from the surface ocean.  These data and unknowns are all put into a large matrix, and then then the best solutions for the unknowns are inverted for by minimizing error in all the individual constraints.  This was the procedure pioneered by \citet{wunsch96}, and followed by \citet{lumpkinspeer07} in the results above.

\section{Theory of overturning circulation and Sandstrom's theorem}

From the above, we might have the idea that the overturning circulation is driven by how much cold water you make.  Thats true to an extent - the heating gradient between the poles and the equator is one part of what drives the overturning circulation, and plus or minus any net heating or cooling, the heat transport in the ocean must balance the hating differential (\fref{fig:SketchHeatingCooling}).

\begin{marginfigure}
    \includegraphics{figs/WaterMasses/SketchHeatingCooling}
    \caption{Sketch of heat input into a one-pole ocean.  The heat flux in must be balanced by the heat flux out, and the ocean must transport that heat from the equator to the poles.}
    \label{fig:SketchHeatingCooling}
\end{marginfigure}

However, just like a river pouring into an estuary, its possible for that heat flux to be carried in a very shallow current and drive a very weak volume transport that only affects the very surface ocean.  In such a world, all the deep ocean would be very cold, and a thin layer at the surface would be very warm (\fref{fig:SketchMixing}).

So for a given heat difference at the surface, what ultimately drives the strength of the overturning circulation is how strong mixing is in the ocean.  By mixing the heat down, the ocean creates lateral density gradients, and lateral gradients create lateral pressure gradients that ultimately drive circulation (\fref{fig:SketchMixing}).

\begin{marginfigure}
    \includegraphics{figs/WaterMasses/SketchWeakMix}
    \includegraphics{figs/WaterMasses/SketchStrongMix}
    \caption{Sketch of two different oceans with the same external heat differential.  The top panel shows weak mixing, and the bottom panel shows strong mixing.  The heat transports from equator to pole are the same, but the amount of circulation is much stronger in the second case.}
    \label{fig:SketchMixing}
\end{marginfigure}

The other way to think of this is to think of the \emph{potential energy} of the system.  Recall from previous chapters that the isopycnals surfaces in \fref{fig:SketchMixing} want to flatten out.  This means that tilted isopycnals have potential energy that they would not have if the isopycnals were all flat.  This idea of potential energy and the need to mix buoyancy to depth in the ocean is nicely encapsulated by \emph{Sandstrom's theorem} which states that heating and cooling at the same depth will not drive a vigorous circulation in fluid.  Essentially surface heating and cooling does not increase the potential energy of the system, and hence there is no strong circulation driven.

Conversely mixing of heat down from the equatorial regions \emph{does} increase the potential energy.  However, it is important energetically to realize that this mixing cannot arise because of the overturning circulation itself.  i.e. the 20-30 Sv of overturning noted above cannot create the turbulence that drives the overturning.  This would be the equivalent of the ocean lifting itself by its own bootstraps.  Instead the energy for the overturning circulation must come from other sources of deep ocean mixing.  This again is directly analogous with the situation in an estuary - the estuarine circulation is catalyzed by mixing in the estuary.

This dependence of the overturning circulation on the strength of the turbulence has been tested numerically.  Stronger mixing transports heat deeper in the ocean (\fref{fig:Bryan87Fig3}) making for stronger lateral gradients.  This drives a more vigorous overturning circulation (\fref{fig:Bryan87Fig7}).  The scaling of the overturning circulation with the vertical diffusivity $K$ is approximately $K^{1/3}$ (\fref{fig:Bryan87Fig8}).  These integrations were carried out many years ago, but the basic results have held up well to more sophisticated treatments.

\begin{figure}[hbt]
  \begin{center}
  \includegraphics[width=2.1in]{figs/WaterMasses/Bryan87Fig3}  \includegraphics[width=2.1in]{figs/WaterMasses/Bryan87Fig7}
      \caption{Left panels: Potential temperature cross section in a numerical ocean with different vertical diffusivities: $0.1, 0.5$ and $2.5\times10^{-4}\mathrm{m^2\,s^{-1}}$.  Right panels: Overturning streamfunctions.  \citep{bryan87}}
    \label{fig:Bryan87Fig3}
  \end{center}
\end{figure}

\begin{figure}[hbt]
  \begin{center}
  \includegraphics[width=2in]{figs/WaterMasses/Bryan87Fig8}
      \caption{Dependence of the overturning circulation strength on the vertical diffusivity used in the idealized model \citep{bryan87}.}
    \label{fig:Bryan87Fig8}
  \end{center}
\end{figure}

The tides and wind are believed to be the energy source for the mixing that drives the overturning circulation.  Because the fluid is stratified, energy is able to radiate into the interior from the boundaries as \Wikiref{internal waves}.  There are many sources and pathways of internal waves, and their importance to the overturning circulation has catalyzed a significant research into their properties (\fref{fig:MacKinnonEtAl17Fig1}).

\begin{figure}[hbt]
  \begin{center}
    \includegraphics{figs/WaterMasses/MacKinnonEtAl17Fig1}
    \caption{Schematic of the zoo of ocean mixing processes \citep{MacKinnonEtAl17}.}
    \label{fig:MacKinnonEtAl17Fig1}
  \end{center}
\end{figure}

\section{Exercises}

\paragraph{Inverse modelling}

Suppose we have a rectangular basin that runs north-south, is 3000 km long and is 1000 km wide at each end. There is an isopycnal in this basin that intersects each of the ends (and of course the side walls).  We use the open ends, the sidewalls, to constrain the sides of a volume of water, and the sea floor and the isopycnal to constrain the bottom and top of the volume.

The average temperature along the bounding isopycnal is 7 degrees C, and $dT/dz = -10^{-3}\ \mathrm{deg/m}$ at that isopycnal.

At the south end section: the thickness of the layer defined by the isopycnal is 2500 m, the average temperature in the section beneath the isopycnal is T=3.2 deg C, the average salinity, S=33 psu, and the average speed through the section is V=0.02 m/s (positive to the north)

North end section, the isopycnal layer is thinner at 2200 m, with an average temperature of T= 3.3 deg C, and average salinity of S = 33.01 psu.  The average velocity is V=0.0226 m/s, to the north.

\begin{itemize}
    \item What is the average velocity out the top of the bounding box?
    \item What is the average turbulent diffusivity of temperature along the isopycnal?
    \item What is the salinity of the top of the surface, assuming $dS/dz=0$ there (i.e. no diffusive flux in or out the top).
\end{itemize}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:


% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
  pdftitle={Using Tikz},
  pdfauthor={Dan Li},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=1in]{geometry}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\usepackage{tikz}
\usepackage{pgfplots}

\title{Using Tikz}
\author{Dan Li}
\date{2020-08-14}

\begin{document}
\maketitle

\hypertarget{tikz-picture}{%
\subsection{TikZ picture}\label{tikz-picture}}

\begin{itemize}
\tightlist
\item
  Here is a TikZ picutre
\end{itemize}

\textbackslash begin\{tikzpicture\} \textbackslash draw (0,0) circle
(2cm); \textbackslash end\{tikzpicture\}

\begin{tikzpicture}
\draw (0,0) circle (2cm);
\end{tikzpicture}

\begin{itemize}
\tightlist
\item
  Here is another TikZ picutre
\end{itemize}

\textbackslash begin\{tikzpicture\}
\textbackslash begin\{axis\}{[}xmax=9,ymax=9, samples=50{]}
\textbackslash addplot{[}blue, ultra thick{]} (x,x\emph{x);
\textbackslash addplot{[}red, ultra thick{]} (x}x,x);
\textbackslash end\{axis\} \textbackslash end\{tikzpicture\}

\begin{tikzpicture}
\begin{axis}[xmax=9,ymax=9, samples=50]
  \addplot[blue, ultra thick] (x,x*x);
  \addplot[red,  ultra thick] (x*x,x);
\end{axis}
\end{tikzpicture}

\end{document}