Commit f79b73fc authored by Nils Brüggemann's avatar Nils Brüggemann
Browse files

pyicon.view: Added new xarray pyicon.view compatibility to main pyicon...

pyicon.view: Added new xarray pyicon.view compatibility to main pyicon library. Updated all notebooks accordingsly. Added some small new features.
parent 371bd79c
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"!!! Disclaimer: This notebook uses the 'old' version of pyicon.view without xarray support, see pyicon_view_nextgems_xr and pyicon_view_nextgems_xr_intake for the 'new' version with xarray support."
]
},
{
"cell_type": "markdown",
"metadata": {},
%% Cell type:markdown id: tags:
 
!!! Disclaimer: This notebook uses the 'old' version of pyicon.view without xarray support, see pyicon_view_nextgems_xr and pyicon_view_nextgems_xr_intake for the 'new' version with xarray support.
%% Cell type:markdown id: tags:
# pyICON.view for R2B9 atmospheric data
 
%% Cell type:markdown id: tags:
 
Load the necessary modules:
 
%% Cell type:code id: tags:
 
``` python
# if this line is not separated from the line below this cell has to be executed twice
# Jupyter Notebook with widget matplotlib plots
%matplotlib notebook
# Jupyter Lab with widget matplotlib plots
#%matplotlib widget
# with Jupyter and Jupyter Lab but without widget matplotlib plots
#%matplotlib inline
%load_ext autoreload
%autoreload 2
```
 
%% Cell type:code id: tags:
 
``` python
#import pyicon_jupyter as jup
import pyicon as pyic
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import matplotlib
warnings.filterwarnings("ignore",category=matplotlib.cbook.mplDeprecation)
import numpy as np
```
 
%%%% Output: stream
 
-----calc
sys glob os
numpy
netcdf
Done modules calc.
-----calc_xr
sys glob os
numpy
netcdf
xarray
Done modules calc.
-----tb
sys
json
numpy
scipy
netcdf datetime
matplotlib
mybreak
pnadas
xarray
done xarray
-----IconData
-----plotting
-----view
-----calc
-----calc_xr
-----tb
-----IconData
-----plotting
-----view
-----quickplots
-----quickplots
 
%% Cell type:markdown id: tags:
 
## Specify data set
 
%% Cell type:markdown id: tags:
 
Define a dataset with giving the path to the data and information about the triangular grid and the regular grid. The regular grid needs to be created in advance (use pyic.calc_ckdtree for that).
 
%% Cell type:code id: tags:
 
``` python
run = 'dpp0016'
runname = ''
gname = 'r2b9_atm_r0015'
lev = ''
 
path_data = f'/work/mh0287/k203123/GIT/icon-aes-dyw_albW/experiments/{run}/'
path_grid = f'/mnt/lustre01/work/mh0033/m300602/icon/grids/{gname}/'
```
 
%% Cell type:code id: tags:
 
``` python
IcD = pyic.IconData(
# fname = run+'_atm_3d_w_ml_????????????????.nc',
# fname = run+'_atm_3d_2_ml_????????????????.nc',
fname = run+'_atm3_2d_ml_????????????????.nc',
path_data = path_data,
path_grid = path_grid,
gname = gname,
lev = lev,
model_type = 'atm',
do_triangulation = True,
omit_last_file = True,
calc_coeff = False,
load_triangular_grid = True,
verbose = True,
)
# Fake depth data
IcD.depthc=np.arange(77)
```
 
%%%% Output: stream
 
-v-: set paths and fnames
-v-: set global variables
-v-: find ckdtrees etc.
::: Warning: Could not find any section-npz-file in /mnt/lustre01/work/mh0033/m300602/icon/grids/r2b9_atm_r0015/ckdtree/sections/. :::
::: Warning: no section found.:::
-v-: load tgrid
-v-: load rgrid
-v-: load vgrid
-v-: do_triangulation
-v-: list of variables and time steps
-v-: load_variable_info
 
%% Cell type:markdown id: tags:
 
## Plotting on a regular grid
 
%% Cell type:code id: tags:
 
``` python
PyicV = pyic.view.hplot(IcD)
```
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%% Cell type:code id: tags:
 
``` python
lon_reg = [-85,-65]
lat_reg = [14,24]
PyicV = pyic.view.hplot(IcD, lon_reg=lon_reg, lat_reg=lat_reg, rgrid_name='global_0.1')
```
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%% Cell type:markdown id: tags:
 
## Plotting on the original grid
 
%% Cell type:markdown id: tags:
 
Select a small region. Otherwise it takes too long.
 
%% Cell type:code id: tags:
 
``` python
lon_reg = [-85,-75]
lat_reg = [19,24]
PyicV = pyic.view.hplot(IcD, grid_type='tgrid', logplot=False, verbose=False, lon_reg=lon_reg, lat_reg=lat_reg)
```
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%%%% Output: display_data
 
 
%% Cell type:code id: tags:
 
``` python
```
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
from .pyicon_view import *
from .pyicon_view_xr import *
......@@ -75,7 +75,7 @@ def my_slide(name='slider:', bnds=[0,10]):
# hplot
# (main class for horizontal plots)
# ------------------------------------------------------------
class hplot(object):
class hplot_xr(object):
output = widgets.Output()
def __init__(self,
......@@ -89,6 +89,8 @@ class hplot(object):
fpath_ckdtree='auto',
fpath_tgrid='auto',
do_mask_big_triangles=False,
title='auto',
do_mask_zeros=True,
):
"""
Parameters
......@@ -116,6 +118,12 @@ class hplot(object):
do_mask_big_triangles : bool
When plotting on the triangular grid, matplotlib can have problems with triangles
which cross the map boundary. To avoid this, set do_mask_big_triangles=False.
title: str
Set title string for plot. If 'auto' then title string is set by variable name and unit
and updated when variable is changed.
do_mask_zeros: bool
If set to 'True' then all data values which are exactly zero are masked. This is helpful for
plotting ocean data where land values are always zero.
"""
# ------------------------------------------------------------
......@@ -127,6 +135,8 @@ class hplot(object):
self.varnames = list(ds.keys())
self.ds = ds.copy()
self.var = self.varnames[0]
self.title = title
self.do_mask_zeros = do_mask_zeros
# --- location
self.iz = 0
self.step_snap = 0
......@@ -338,7 +348,8 @@ class hplot(object):
else:
self.lev_name = 'none'
# --- mask land values (necessary for ocean data)
arr = arr.where(arr!=0)
if self.do_mask_zeros:
arr = arr.where(arr!=0)
# --- get current fpath_ckdtree
self.fpath_ckdtree = self.rgrid_options[self.rgrid_name]
# --- interpolate data
......@@ -359,19 +370,22 @@ class hplot(object):
return
def get_title(self):
try:
long_name = self.arr.long_name
except:
#long_name = 'NA'
long_name = self.arr.name
try:
units = self.arr.units
except:
units = 'NA'
if self.logplot:
title = f'log_10({long_name}) [{units}]'
if self.title=='auto':
try:
long_name = self.arr.long_name
except:
#long_name = 'NA'
long_name = self.arr.name
try:
units = self.arr.units
except:
units = 'NA'
if self.logplot:
title = f'log_10({long_name}) [{units}]'
else:
title = f'{long_name} [{units}]'
else:
title = f'{long_name} [{units}]'
title = self.title
return title
def update_infotext(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment