Skip to content
Snippets Groups Projects
Commit df21827e authored by Aiko Voigt's avatar Aiko Voigt
Browse files

Not working first example of loading data from Pangeo cloud

parent 617474fd
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# How to access and load TRACMIP data from the Pangeo cloud
1. "load" the Tracmip collection
2. get some basic info on Tracmip collection
3. load monthly mean precip for the aquaControl simulation
4. plot meridional zonal-mean time-mean profile for one model
%% Cell type:code id: tags:
``` python
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
import xarray as xr
import zarr
import gcsfs
xr.set_options(display_style='html')
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
```
%% Cell type:code id: tags:
``` python
df = pd.read_csv('https://storage.googleapis.com/cmip6/tracmip.csv')
df.head()
```
%% Cell type:code id: tags:
``` python
df_pr = df.query("frequency == 'Amon' & variable == 'pr' & experiment == 'aquaControl'")
```
%% Output
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-36bdea2f3883> in <module>
----> 1 df_pr = df.query("frequency == 'Amon' & variable == 'pr' & experiment == 'aquaControl'")
NameError: name 'df' is not defined
%% Cell type:markdown id: tags:
## 1. "Load" Tracmip collection
%% Cell type:code id: tags:
``` python
from intake import open_catalog
# get whole pangeo catalogue
cat = open_catalog("https://raw.githubusercontent.com/pangeo-data/pangeo-datastore/master/intake-catalogs/climate.yaml")
# select tracmip collection
col = cat.tracmip()
```
%% Cell type:markdown id: tags:
## 2. Basic info on the collection
%% Cell type:markdown id: tags:
print collection to screen: this shows that there is 3 output frequencies (monthly-mean, daily-mean, 3-hr snapshots),
11 experiments (6 are due to the CALTECH model with changed atmosperic opacity), and 47 variables
%% Cell type:code id: tags:
``` python
col
```
%% Cell type:markdown id: tags:
print starting and end portion of the collection
%% Cell type:code id: tags:
``` python
col.df.head()
```
%% Cell type:code id: tags:
``` python
col.df.tail()
```
%% Cell type:markdown id: tags:
print some further information on the collection (i.e., dataframe)
%% Cell type:code id: tags:
``` python
col.df.columns.unique()
```
%% Cell type:code id: tags:
``` python
col.df.model.unique()
```
%% Cell type:code id: tags:
``` python
col.df.experiment.unique()
```
%% Cell type:markdown id: tags:
## 3. Now actually load the monthly-mean precip data for the aquaControl experiment, use a dictionary for this
%% Cell type:markdown id: tags:
note: the option "zarr_kwargs={'consolidated': True}" for to_dataset_dicts does not seem necessary but is still included here
%% Cell type:code id: tags:
``` python
ds_dict = col.search(frequency="Amon", experiment="aquaControl",
variable="pr").to_dataset_dict(zarr_kwargs={'consolidated': True})
```
%% Cell type:markdown id: tags:
## 4. Plot zonal-mean time-mean precip for last 20 years for CNRM-AM5 model
%% Cell type:code id: tags:
``` python
import matplotlib.pyplot as plt
```
%% Cell type:code id: tags:
``` python
ds_dict['CNRM-AM5.aquaControl.Amon']['pr']
```
%% Cell type:code id: tags:
``` python
plt.plot(ds_dict['CNRM-AM5.aquaControl.Amon'].lat,
ds_dict['CNRM-AM5.aquaControl.Amon']['pr'].isel(time=slice(120,360)).mean(['lon', 'time'])*86400)
plt.xlabel('degree latitude')
plt.ylabel('precipitation (mm/day)')
plt.title('CNRM-AM5.aquaControl.Amon')
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment