Commit 1d8f3259 authored by Willi Rath's avatar Willi Rath
Browse files

Merge branch 'use-more-than-1000-sltac-files' into 'master'

Use all available SLTAC data and stick to ipynb

See merge request !4
parents 2428ece9 34aabde1
Loading
Loading
Loading
Loading
+16 −21

File changed.

Preview size limit exceeded, changes collapsed.

+0 −91
Original line number Diff line number Diff line

# Using git.geomar.de/data to calculate SSH variance

This example uses version v1.0.0 of <https://git.geomar.de/data/SLTAC_GLO_PHY_L4_REP/> and calculates sea-surface-height variance for the year 1993.

## Preamble

Import a few modules:

- `pyplot` is loaded by `xarray`, but we need to explicitly modify a dictionary to increase figure size
- `pathlib.Path` is good for handling paths
- `seaborn` makes plots nice
- `xarray` will do the calculations and call the plotting


```python
# suppress warnings
import warnings
warnings.filterwarnings('ignore')
```


```python
%matplotlib inline
import matplotlib.pyplot as plt
from pathlib import Path
import seaborn as sns
import xarray as xr
```


```python
plt.rcParams['figure.figsize'] = [15, 9]
sns.set_context("notebook", font_scale=1.5, rc={"lines.linewidth": 2.5})
```

## Using a local checkout

In `taurus:/data/c2/TMdata/git_geomar_de_data/`, there's a checkout of `SLTAC_GLO_PHY_L4_REP`, `v1.0.0`.  Generate a list of all files for the year 1993 and open all files as one data set and calculate temporal variance of absolute dynamic topography, `adt`.


```python
data_path = Path("/data/c2/TMdata/git_geomar_de_data/")
data_set = "SLTAC_GLO_PHY_L4_REP"
ref = "v1.0.0"
full_path = data_path / data_set / ref / "data"
file_list = [str(fp) for fp in full_path.glob("1993/*.nc")]
```


```python
xr.open_mfdataset(file_list).adt.var(dim="time").plot()
```




    <matplotlib.collections.QuadMesh at 0x7feb95eacf28>




![png](example_01_SLTAC_adt_variance_local_and_opendap_files/example_01_SLTAC_adt_variance_local_and_opendap_6_1.png)


## OPeNDAP

There is <https://data.geomar.de/thredds/tmdata/git_geomar_de_data/catalog.html>.  Clicking will bring a list of data-file urls (which, lacking a decent crawler, we'll have to improvise here).  Open all urls in one dataset and again create the variance plot with `xarray`.


```python
# wave hands and pull a list of urls from somewhere (the local file listing for now...)
base_url = "https://data.geomar.de/thredds/dodsC/tmdata/git_geomar_de_data/SLTAC_GLO_PHY_L4_REP/v1.0.0/data/1993/{file_name}"
url_list = [base_url.format(file_name=fn) for fn in [p.name for p in full_path.glob("1993/*.nc")]]
```


```python
xr.open_mfdataset(url_list).adt.var(dim="time").plot()
```




    <matplotlib.collections.QuadMesh at 0x7feb8e6582b0>




![png](example_01_SLTAC_adt_variance_local_and_opendap_files/example_01_SLTAC_adt_variance_local_and_opendap_9_1.png)