### Sverdrup Balance in observations



```python
import numpy as np
import xarray as xr
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
```


```python
%matplotlib inline
```

In this assignment, we are going to compute the Sverdrup streamfunction from the wind stress. As a reminder, the Sverdrup balance is
\begin{equation}
    \beta V = \frac{\vec{\nabla} \times \vec{\tau}}{\rho}
\end{equation}

Download the zonal and meridional GODAS momentum flux (=wind stress in [N/m$^2$]) files for one year from the GODAS website at https://psl.noaa.gov/data/gridded/data.godas.html (via 'List of *.nc files'>'See list'>'Save Link as') and use their time average from here on.


```python
# loading and inspecting
data = '/Users/Andre/Downloads'
uflx = xr.open_dataset(f'{data}/uflx.2020.nc')
vflx = xr.open_dataset(f'{data}/vflx.2020.nc')
taux = uflx.uflx.mean('time')
tauv = vflx.vflx.mean('time')
uflx
```

#### (a) Determine the length (in m) of the grid cells in the x- and y-directions and plot them as a function of latitude. Also compute $\beta$ as a function of latitude and plot it in the same figure with a secondary y-axis (using e.g. `ax.twinx()`).

#### (b) Plot maps of (1) the zonal and (2) meridional wind stress components, (3) the total wind stress with streamlines (using `plt.streamplot()`), and (4) wind stress curl with its (5) zonal and (6) meridional components.

#### (c) Integrate the wind curl  to arrive at the Sverdrup streamfunction.
$$ \Psi = \frac{1}{\beta \rho} \int_{E}^{W} \left( \frac{d\tau_{wy}}{dx}-\frac{d\tau_{wx}}{dy} \right) dx$$

There are two step:
1. integrate East to West with the proper longitudinal grid size.
2. fix discontinuity at the null meridian in the Atlantic.

#### Why do you integrate East to West and not the other way around?

Hints: 
- You should arrive at a plot similar to the one on slide 19 of lecture 6.
- As always in pogramming, there are many roads to Rome. We would recommend keeping the data within the xarray DataArrays/Datasets as much as possible, but you could also use numpy arrays (and then have to keep track of your own indices).
- the following code gives an example of how you can fix the null meridian issue in the Atlantic (in this case for a single latitude, this code easily extends to 2D):
```
example = xr.DataArray(dims=['lon'],
                       coords={'lon':[1,2,3,4,256,257,258,359,360]},
                       data=[5,4,2,np.nan,1,0,np.nan,3,0])
# data representating:     (East-Atl.)..(S.Amer.)..(West-Atl.)    
example.plot()  # here the West-Atlantic starts at 0 in the null meridian
da_add = xr.zeros_like(example)
da_add[-1] = example[0]
for i in np.arange(2,10):  # fixing zero meridian
    da_add[-i] += xr.where(np.isnan(example[-i]), np.nan, da_add[-i+1])
fixed = (example+xr.where(np.isnan(da_add),0,da_add))
fixed.plot()  # now the values continue smoothly across the Atlantic null meridian from East to West 
```

#### (d) Explain the features that you see. How is the Sverdrup flow and what happens at the Western boundaries, the Aghulhas Retroflection, and in the Antarctic Circumpolar Current regions?


```python

```

7cb3b90a6a28638231cd3496af58192f02d2a31b
ipynb
Jupyter Notebook
Ch04_WesternBoundaryCurrents_OrganismDrift/Ch04_SverdrupBalance.ipynb
OceanCurrentsBook/Exercises
60a91a794edec53d333fbce8679ff68ac9aa6cf9
CC0-1.0
2020-08-28T21:59:36.000Z
2021-08-19T18:40:54.000Z
Ch04_WesternBoundaryCurrents_OrganismDrift/Ch04_SverdrupBalance.ipynb
OceanCurrentsBook/Exercises
60a91a794edec53d333fbce8679ff68ac9aa6cf9
CC0-1.0
Ch04_WesternBoundaryCurrents_OrganismDrift/Ch04_SverdrupBalance.ipynb
OceanCurrentsBook/Exercises
60a91a794edec53d333fbce8679ff68ac9aa6cf9
CC0-1.0
Qwen/Qwen-72B
1. YES
2. YES