"We define a function to calculate the __global and yearly mean__ of the variable. <br>\n",
"We assume that the grid is _rectangular_ . That implies that grid cell area is proportional to the cosinus of the latitude.\n",
"We assume that the grid is _rectangular_ (Not valid for other sources). That implies that grid cell area is proportional to the cosinus of the latitude and we can use these cosinuses as the _weights_ for the global mean.\n",
"\n",
"With these weights we can calculate a global mean.\n",
"The yearly mean is calculated with a groupby."
...
...
@@ -242,7 +242,7 @@
" xlabel=\"Year\",\n",
" ylabel=label,\n",
" value_label=label,\n",
" legend=\"bottom_right\",\n",
" legend=\"top_left\",\n",
" ncol=3,\n",
" title=\"Global and yearly mean anomaly in comparison with\" \"1851-1880 \",\n",
" grid=True,\n",
...
...
@@ -261,9 +261,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "test_env",
"display_name": "Python [conda env:root] *",
"language": "python",
"name": "test_env"
"name": "conda-root-py"
},
"language_info": {
"codemirror_mode": {
...
...
@@ -275,7 +275,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.7.3"
}
},
"nbformat": 4,
...
...
%% Cell type:markdown id: tags:
## Plot the time series of a simulated variable from CMIP6 data for 1850-2100
We will plot the __anomaly__ of a variable with respect to a reference period __1851-1880__ from the historical simulation.
For understanding the code we recoomend to be familiar with
- intake-esm <br>
check the notebook `tutorial_find-data_catalogs_intake-esm.ipynb`
- pandas
- xarray
We use three different experiments from the CMIP6 data pool:
We define a query and specify values for some columns.
In the following case, we look for the specified variable in monthly resolution for the 3 different experiments.
_Search for the ESMs by `source_id` and not for its corresponding institutions by `institution_id` because some experiments may be conducted by other institutions._
%% Cell type:code id: tags:
``` python
query = dict(
variable_id=variable_id,
table_id="Amon",
experiment_id=["historical", "ssp245", "ssp585"],
source_id=["MPI-ESM1-2-HR", "AWI-CM-1-1-MR"],
)
# piControl = pre-industrial control, simulation to represent a stable climate from 1850 for >100 years.
# historical = historical Simulation, 1850-2014
# ssp370 = Shared Socioeconomic Pathways (SSPs) are scenarios of projected socioeconomic global changes. Simulation covers 2015-2100
cat = col.search(**query)
```
%% Cell type:markdown id: tags:
### Accessing the data
The catalog can give us a dictionary of xarray datasets. They are aggregated over time and member. The keys of the dictionary are concatenated directory names.
%% Cell type:code id: tags:
``` python
xrdsetdict = cat.to_dataset_dict()
'''Keys of the dataset dictionary are concatinations of 6 column labels:'''
for key in xrdsetdict.keys():
print(key)
```
%% Cell type:markdown id: tags:
### Post-process the data
We define a function to calculate the __global and yearly mean__ of the variable. <br>
We assume that the grid is _rectangular_ . That implies that grid cell area is proportional to the cosinus of the latitude.
We assume that the grid is _rectangular_ (Not valid for other sources). That implies that grid cell area is proportional to the cosinus of the latitude and we can use these cosinuses as the _weights_ for the global mean.
With these weights we can calculate a global mean.
The plot is generated by a function on top of a __pandas dataframe__.
We define one and write the results of each global yearly mean into that dataframe. We use parts of the keys of the dataset dictionary as column names of the dataframe.
%% Cell type:code id: tags:
``` python
lxr = list(xrdsetdict.keys())
columns = [".".join(elem.split(".")[1:4]) for elem in lxr]