Skip to content
Snippets Groups Projects
Commit 2a368e2d authored by Fabian Wachsmann's avatar Fabian Wachsmann
Browse files

Merge branch '15-plotting-cmip6-data-on-unstructured-grids-with-psyplot' into 'develop'

Resolve "Plotting CMIP6 data on unstructured grids with psyplot"

Closes #15

See merge request mipdata/tutorials-and-use-cases!4
parents a36bfa35 82036375
No related branches found
No related tags found
1 merge request!10Develop
%% Cell type:markdown id: tags:
# Plot Earth System Model data on unstructured grids with psyplot
This notebook introduces you to the `mapplot` function of the package `psyplot`.
It is suitable to plot maps from data on unstructured grids like the ones from ICON and FESOM.
We therefore search for the corresponding data in the CMIP6 data pool with intake-esm.
Afterwards, we open a file with `xarray` and configure the opened xarray dataset as well as psyplot for a map plot.
In the end, we discuss the functions of `psyplot.project.plot.mapplot`.
%% Cell type:code id: tags:
``` python
import psyplot.project as psy
import matplotlib as mpl
import xarray as xr
import intake
```
%% Cell type:markdown id: tags:
We open a swift catalog from dkrz cloud which is accessible without authentication.
%% Cell type:code id: tags:
``` python
col_url = "https://swift.dkrz.de/v1/dkrz_a44962e3ba914c309a7421573a6949a6/intake-esm/mistral-cmip6.json"
col = intake.open_esm_datastore(col_url)
```
%% Cell type:markdown id: tags:
In this example, we aim at plotting the Sea Surface Temperature of the upper boundary of the liquid ocean, including temperatures below sea-ice and floating ice shelves from AWI.
We therefore search for `tos` in the catalog for monthly frequency. We use 1 realization of 1 experiment only.
%% Cell type:code id: tags:
``` python
tos=col.search(source_id="AWI-CM-1-1-MR",
experiment_id="ssp370",
variable_id="tos",
table_id="Omon",
member_id="r1i1p1f1")
```
%% Cell type:markdown id: tags:
We now open the file on the mistral file system.
%% Cell type:code id: tags:
``` python
dset = xr.open_dataset(tos.df["path"].to_list()[0])
#dset = xr.open_mfdataset(tos.df["path"].to_list())
```
%% Cell type:markdown id: tags:
In order to make `tos` plottable, we set the following configuration.
- The `CDI_grid_type` is a keyword for `psyplot`.
- Coordinates are not fully recognized by `xarray` so that we have to add some manually (version from Dec 2020).
%% Cell type:code id: tags:
``` python
dset["tos"]["CDI_grid_type"]="unstructured"
coordlist=["vertices_latitude", "vertices_longitude", "lat_bnds", "lon_bnds"]
dset=dset.set_coords([coord for coord in dset.data_vars if coord in coordlist])
```
%% Cell type:markdown id: tags:
This is based on the example from:
https://psyplot.readthedocs.io/projects/psy-maps/en/latest/examples/example_ugrid.html#gallery-examples-example-ugrid-ipynb
%% Cell type:code id: tags:
``` python
psy.rcParams['plotter.maps.xgrid'] = False
psy.rcParams['plotter.maps.ygrid'] = False
mpl.rcParams['figure.figsize'] = [10, 8.]
```
%% Cell type:code id: tags:
``` python
iconplot11=psy.plot.mapplot(
dset, name="tos", cmap='rainbow',
clabel=dset["tos"].description,
stock_img=True, lsm='50m')
```
%% Cell type:markdown id: tags:
We now do the same with a smaller subset to see the fine resolution of the AWI ocean model FESOM.
The subsetting is required because the plotting takes too long otherwise.
%% Cell type:code id: tags:
``` python
dset2 = dset.isel(time=slice(1,3)).where( (dset.lon > -10. ) &
(dset.lon < 50. ) &
(dset.lat > 40. ) &
(dset.lat < 70. ), drop=True)
```
%% Cell type:code id: tags:
``` python
dset2.to_netcdf("/home/dkrz/k204210/test.nc")
```
%% Cell type:code id: tags:
``` python
dset2=xr.open_dataset("/home/dkrz/k204210/test.nc")
```
%% Cell type:code id: tags:
``` python
dset2["tos"]["CDI_grid_type"]="unstructured"
coordlist=["vertices_latitude", "vertices_longitude", "lat_bnds", "lon_bnds"]
dset2=dset2.set_coords([coord for coord in dset2.data_vars if coord in coordlist])
```
%% Cell type:code id: tags:
``` python
iconplot12=psy.plot.mapplot(
dset2, name="tos", cmap='rainbow',
lonlatbox='Ireland',
clabel=dset["tos"].description,
stock_img=True,
lsm='50m',
datagrid=dict(c='b', lw=0.2))
```
%% Cell type:code id: tags:
``` python
```
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