CosmoState

A high-level python module for reading GRIB1 and GRIB2 COSMO output files based on the grib_api/eccodes python module.

Grib_api : Standard library for reading/writing grib files developed at ECMWF, replaces DWDs grib library
eccodes : successor of grip_api

Why not use CosmoUtils? No support for GRIB2 (based on wgrib)...

Why not use grib_api python module directly? It is very low-level, records (=2D-slices of >=3D variables) are accessed sequentially. CosmoState allows the user to access model variables without having to deal with low-level technical details...

In [1]:
%matplotlib inline
import matplotlib
import numpy as np
import matplotlib.pyplot as plt

Getting started

In [2]:
from cosmo_state import CosmoState

Get cosmo_state.py from http://www.meteo.physik.uni-muenchen.de/~leo.scheck/cosmo_state.py and put it somewhere in your $PYTHONPATH

Requirements: grib_api or eccodes python module.

Listing file contents

In [3]:
g2=CosmoState('/home/l/Leonhard.Scheck/userdata/grib_examples/grib2_fcst/de_2016060112.grib2') # operational COSMO-DE forecast in GRIB2 format
In [4]:
g2.list_variables(narrow=True) # narrow -> do not print long variable description
short_name                            type_of_level class #times #levels           units
10u                               heightAboveGround  (Z)       1       1         m s**-1 
10v                               heightAboveGround  (Z)       1       1         m s**-1 
2d                                heightAboveGround  (Z)       1       1               K 
2t                                heightAboveGround  (Z)       1       1               K 
AEVAP_S                                     surface  (S)       1       1          kg m-2 
ALHFL_S                                     surface  (S)       1       1           W m-2 
APAB_S                                      surface  (S)       1       1           W m-2 
ASHFL_S                                     surface  (S)       1       1           W m-2 
ASOB_S                                      surface  (S)       1       1           W m-2 
ASOB_T                                   nominalTop  (L)       1       1           W m-2 
ASWDIFD_S                                   surface  (S)       1       1           W m-2 
ASWDIFU_S                                   surface  (S)       1       1           W m-2 
ASWDIR_S                                    surface  (S)       1       1           W m-2 
ATHB_S                                      surface  (S)       1       1           W m-2 
ATHB_T                                   nominalTop  (L)       1       1           W m-2 
AUMFL_S                                     surface  (S)       1       1           N m-2 
AVMFL_S                                     surface  (S)       1       1           N m-2 
CAPE_ML                                     unknown  (U)       1       1          J kg-1 
CIN_ML                                      unknown  (U)       1       1          J kg-1 
CLC                            generalVerticalLayer  (M)       1      50               % 
CLCH                                  isobaricLayer  (X)       1       1               % 
CLCH_S                                isobaricLayer  (X)       1       1               % 
CLCL                                        unknown  (U)       1       1               % 
CLCL_S                                      unknown  (U)       1       1               % 
CLCM                                  isobaricLayer  (X)       1       1               % 
CLCM_S                                isobaricLayer  (X)       1       1               % 
CLCT                                        surface  (S)       1       1               % 
CLCT_MOD                                    surface  (S)       1       1         Numeric 
CLCT_S                                      surface  (S)       1       1               % 
CLDEPTH                                     surface  (S)       1       1         Numeric 
C_T_LK                                      unknown  (U)       1       1         Numeric 
DBZ_850                                     surface  (S)       1       1              dB 
DBZ_CMAX                           entireAtmosphere  (X)       1       1              dB 
FOR_D                                       surface  (S)       1       1         Numeric 
FOR_E                                       surface  (S)       1       1         Numeric 
FRESHSNW                                    surface  (S)       1       1         Numeric 
GRAU_GSP                                    surface  (S)       1       1          kg m-2 
HBAS_SC                                     unknown  (U)       1       1               m 
HTOP_DC                                     unknown  (U)       1       1               m 
HTOP_SC                                     unknown  (U)       1       1               m 
HZEROCL                                     unknown  (U)       1       1               m 
H_ML_LK                                     unknown  (U)       1       1               m 
LPI                                         surface  (S)       1       1          J kg-1 
PRG_GSP                                     surface  (S)       1       1      kg m-2 s-1 
PRR_GSP                                     surface  (S)       1       1      kg m-2 s-1 
QI                             generalVerticalLayer  (M)       1      50         kg kg-1 
QV_S                                        surface  (S)       1       1         kg kg-1 
Q_SEDIM                        generalVerticalLayer  (M)       1      50         kg kg-1 
RAIN_GSP                                    surface  (S)       1       1          kg m-2 
RELHUM_2M                         heightAboveGround  (Z)       1       1               % 
RUNOFF_G                        depthBelowLandLayer  (Z)       1       1          kg m-2 
RUNOFF_S                        depthBelowLandLayer  (Z)       1       1          kg m-2 
SDI_1                                       surface  (S)       1       1             s-1 
SDI_2                                       surface  (S)       1       1             s-1 
SNOWLMT                                     unknown  (U)       1       1               m 
SNOW_GSP                                    surface  (S)       1       1          kg m-2 
SNOW_GSP_C                                  surface  (S)       1       1          kg m-2 
SNOW_GSP_S                                  surface  (S)       1       1          kg m-2 
SYNMSG_BT_CL_IR10.8                             TOA  (X)       1       1               K 
SYNMSG_BT_CL_IR12.1                             TOA  (X)       1       1               K 
SYNMSG_BT_CL_IR13.4                             TOA  (X)       1       1               K 
SYNMSG_BT_CL_IR3.9                              TOA  (X)       1       1               K 
SYNMSG_BT_CL_IR8.7                              TOA  (X)       1       1               K 
SYNMSG_BT_CL_IR9.7                              TOA  (X)       1       1               K 
SYNMSG_BT_CL_WV6.2                              TOA  (X)       1       1               K 
SYNMSG_BT_CL_WV7.3                              TOA  (X)       1       1               K 
SYNMSG_BT_CS_IR10.8                             TOA  (X)       1       1               K 
SYNMSG_BT_CS_IR12.1                             TOA  (X)       1       1               K 
SYNMSG_BT_CS_IR13.4                             TOA  (X)       1       1               K 
SYNMSG_BT_CS_IR3.9                              TOA  (X)       1       1               K 
SYNMSG_BT_CS_IR8.7                              TOA  (X)       1       1               K 
SYNMSG_BT_CS_IR9.7                              TOA  (X)       1       1               K 
SYNMSG_BT_CS_WV6.2                              TOA  (X)       1       1               K 
SYNMSG_BT_CS_WV7.3                              TOA  (X)       1       1               K 
SYNMSG_RAD_CL_IR10.8                            TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CL_IR12.1                            TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CL_IR13.4                            TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CL_IR3.9                             TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CL_IR8.7                             TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CL_IR9.7                             TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CL_WV6.2                             TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CL_WV7.3                             TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CS_IR10.8                            TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CS_IR12.1                            TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CS_IR13.4                            TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CS_IR3.9                             TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CS_IR8.7                             TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CS_IR9.7                             TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CS_WV6.2                             TOA  (X)       1       1      W m sr m-2 
SYNMSG_RAD_CS_WV7.3                             TOA  (X)       1       1      W m sr m-2 
TCH                                         surface  (S)       1       1         Numeric 
TDIV_HUM                                    surface  (S)       1       1          kg m-2 
TD_2M_S                           heightAboveGround  (Z)       1       1               K 
TMAX_2M                           heightAboveGround  (Z)       1       1               K 
TMAX_2M_S                         heightAboveGround  (Z)       1       1               K 
TMIN_2M                           heightAboveGround  (Z)       1       1               K 
TMIN_2M_S                         heightAboveGround  (Z)       1       1               K 
TQC                                         surface  (S)       1       1          kg m-2 
TQG                                         surface  (S)       1       1          kg m-2 
TQI                                         surface  (S)       1       1          kg m-2 
TWATER                                      surface  (S)       1       1          kg m-2 
T_2M_S                            heightAboveGround  (Z)       1       1               K 
T_BOT_LK                                    unknown  (U)       1       1               K 
T_G                                         surface  (S)       1       1               K 
T_MNW_LK                                    unknown  (U)       1       1               K 
T_S                                         surface  (S)       1       1               K 
T_SNOW                                      surface  (S)       1       1               K 
T_SO                                 depthBelowLand  (Z)       1       9               K 
T_S_S                                depthBelowLand  (Z)       1       1               K 
T_WML_LK                                    unknown  (U)       1       1               K 
U_10M_S                           heightAboveGround  (Z)       1       1           m s-1 
VMAX_10M                          heightAboveGround  (Z)       1       1           m s-1 
VMAX_10M_C                        heightAboveGround  (Z)       1       1           m s-1 
VMAX_10M_S                        heightAboveGround  (Z)       1       1           m s-1 
V_10M_S                           heightAboveGround  (Z)       1       1           m s-1 
WW                                          surface  (S)       1       1         Numeric 
W_SO                            depthBelowLandLayer  (Z)       1       8          kg m-2 
W_SO_ICE                        depthBelowLandLayer  (Z)       1       8          kg m-2 
ZHD                                         surface  (S)       1       1               m 
ZTD                                         surface  (S)       1       1               m 
ZWD                                         surface  (S)       1       1               m 
al                                          surface  (S)       1       1               % 
cd                                          surface  (S)       1       1         Numeric 
ceil                                        surface  (S)       1       1               m 
clwmr                          generalVerticalLayer  (M)       1      50       kg kg**-1 
cnwat                                       surface  (S)       1       1        kg m**-2 
grle                           generalVerticalLayer  (M)       1      50       kg kg**-1 
icetk                                       surface  (S)       1       1               m 
ist                                         surface  (S)       1       1               K 
lssrwe                                      surface  (S)       1       1  kg m**-2 s**-1 
pres                           generalVerticalLayer  (M)       1      50              Pa 
pres                                 heightAboveSea  (Z)       1       6              Pa 
prmsl                                       meanSea  (0)       1       1              Pa 
q                              generalVerticalLayer  (M)       1      50       kg kg**-1 
r                                    heightAboveSea  (Z)       1       6               % 
r                                     isobaricInhPa  (P)       1      11               % 
rsn                                         surface  (S)       1       1        kg m**-3 
rwmr                           generalVerticalLayer  (M)       1      50       kg kg**-1 
sd                                          surface  (S)       1       2        kg m**-2 
snmr                           generalVerticalLayer  (M)       1      50       kg kg**-1 
sp                                          surface  (S)       1       1              Pa 
sr                                          surface  (S)       1       1               m 
t                              generalVerticalLayer  (M)       1      50               K 
t                                    heightAboveSea  (Z)       1       6               K 
t                                     isobaricInhPa  (P)       1      11               K 
tciwv                                       surface  (S)       1       1        kg m**-2 
tcolr                                       surface  (S)       1       1        kg m**-2 
tcols                                       surface  (S)       1       1        kg m**-2 
tke                                 generalVertical  (M)       1      51        J kg**-1 
tp                                          surface  (S)       1       3        kg m**-2 
u                              generalVerticalLayer  (M)       1      50         m s**-1 
u                                    heightAboveSea  (Z)       1       6         m s**-1 
u                                     isobaricInhPa  (P)       1      11         m s**-1 
v                              generalVerticalLayer  (M)       1      50         m s**-1 
v                                    heightAboveSea  (Z)       1       6         m s**-1 
v                                     isobaricInhPa  (P)       1      11         m s**-1 
w                                     isobaricInhPa  (P)       1      11        Pa s**-1 
wz                                  generalVertical  (M)       1      51         m s**-1 
wz                                   heightAboveSea  (Z)       1       6         m s**-1 
z                                     isobaricInhPa  (P)       1      11      m**2 s**-2 

To generate this overview, cosmo_state.py can also be run directly from the command line with a grib file name as argument (like a grib_ls replacement). You may need to do "chmod +x cosmo_state.py" before...

Accessing variables and meta information

In [120]:
plt.imshow( g2['RELHUM_2M'], origin='lower' ) # variable is identified by 'short name' and read from file when you access it
Out[120]:
<matplotlib.image.AxesImage at 0x7ff34d5fc4d0>
In [121]:
g2['u'].shape # access the first variable with short name 'u' -- this happens to be u on pressure levels
Out[121]:
(461, 421, 11)
In [122]:
type(g2['u']), g2['u'].max() # variables = numpy array, remain stored in the object (will not be read every time you access it)
Out[122]:
(numpy.ndarray, 20.391532897949219)
In [123]:
g2['u:M'].shape # append ':M' to get the u on model levels
Out[123]:
(461, 421, 50)
In [124]:
g2['u:Z'].shape, g2['u:P'].shape # ':Z' means geometric height, ':P' pressure levels (see source code for all types)
Out[124]:
((461, 421, 6), (461, 421, 11))

Excerpt from cosmo_state.py source:

# level types used in Grib1 and Grib2 files + level type classes:
#                M = model levels
#                P = pressure l.
#                Z = geometrical height
#                S = surface
#                0 = mean sea level
#                L = special level, e.g. cloud top
#                X = satellite or other vertically integrating obs.
level_types = { 'M':['hybrid','hybridLayer','generalVertical','generalVerticalLayer'],
                'P':['isobaricInhPa'],
                'Z':['depthBelowLand','depthBelowLandLayer','heightAboveSea','heightAboveGround'],
                'S':['surface'],
                '0':['meanSea'],
                'L':['isothermZero','cloudTop','cloudBase','nominalTop'],
                'U':['unknown'],
                'X':['TOA','meanLayer','entireAtmosphere','isobaricLayer'] }

Different "type of level" names in GRIB1 and GRIB2, different names for levels and layers (half-levels) -> use classes M, P, Z...

In [125]:
 g2.meta['RELHUM_2M'] # meta information is stored in .meta, can be accessed once the variable has been accessed
Out[125]:
{'Ni': '421',
 'Nj': '461',
 'angleOfRotationInDegrees': '0',
 'bitmapPresent': '0',
 'centre': 'edzw',
 'dataDate': '20160601',
 'dataTime': '1200',
 'dataType': 'fc',
 'date': '20160601',
 'dimnames': ['lat', 'lon'],
 'edition': '2',
 'endStep': '3',
 'gridType': 'rotated_ll',
 'iDirectionIncrementInDegrees': '0.025',
 'iScansNegatively': '0',
 'jDirectionIncrementInDegrees': '0.025',
 'jPointsAreConsecutive': '0',
 'jScansPositively': '1',
 'latitudeOfFirstGridPointInDegrees': '-5',
 'latitudeOfLastGridPointInDegrees': '6.5',
 'latitudeOfSouthernPoleInDegrees': '-40',
 'level': '2',
 'levtype': 'sfc',
 'longitudeOfFirstGridPointInDegrees': '355',
 'longitudeOfLastGridPointInDegrees': '5.5',
 'longitudeOfSouthernPoleInDegrees': '10',
 'member_index': -1,
 'name': '2m Relative Humidity',
 'ndim': 2,
 'nens': 1,
 'nlat': 461,
 'nlevel': 1,
 'nlon': 421,
 'ntime': 1,
 'nx': 421,
 'ny': 461,
 'origin': '/home/l/Leonhard.Scheck/userdata/grib_examples/grib2_fcst/de_2016060112.grib2',
 'packingType': 'grid_simple',
 'param': '500036',
 'paramId': '500036',
 'shortName': 'RELHUM_2M',
 'startStep': '3',
 'step': 3,
 'stepRange': '3',
 'stepType': 'instant',
 'stepUnits': 'h',
 'time': '1200',
 'typeOfLevel': 'heightAboveGround',
 'units': '%',
 'validityDate': '20160601',
 'validityTime': '1500'}
In [126]:
g2.meta['u:P']['levels'] # u:P is available on which pressure levels?
Out[126]:
[200, 250, 300, 400, 500, 600, 700, 850, 950, 975, 1000]
In [127]:
s,pres,n = g2.distribution( 'pres:M', 't:M' )
plt.plot( s['mean'],              pres/1e2, 'k' )
plt.plot( s['mean']+0.5*s['std'], pres/1e2, '--r')
plt.plot( s['mean']-0.5*s['std'], pres/1e2, '--r')
plt.xlabel( g2.meta['t:M']['name'] )
plt.ylabel( g2.meta['pres:M']['name'] )
plt.ylim((1000,0))
Out[127]:
(1000, 0)

A more realistic example

Common situation: Not all grib files contain all variables, e.g. constants are stored only in first output file -> specify second grib file that will be searched for variables not found in the first file

If you know which variables you will need, specify them using the "preload" argument. This will be faster...

Please note: cosmo_state is not yet optimized for speed (work in progress), but at least with "preload" it is quite fast.

In [128]:
cs = CosmoState('/home/userdata/leo.scheck/bacy_ahutt/cosmo_letkf/data/1000.05b/20140516060000/laf20140516080000.det',
                constfile='/home/userdata/leo.scheck/bacy_ahutt/cosmo_letkf/data/1000.05b/20140516090000/lff20140516080000.det',
                preload=['QC','RLAT','RLON'],verbose=True)
CosmoState: trying to load from /home/userdata/leo.scheck/bacy_ahutt/cosmo_letkf/data/1000.05b/20140516060000/laf20140516080000.det :  ['QC', 'RLAT', 'RLON']
found 1552648 byte record for QC ( nx=421, ny=461, level=1, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=2, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=3, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=4, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=5, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=6, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=7, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=8, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=9, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=10, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=11, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=12, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=13, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=14, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=15, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=16, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=17, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=18, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=19, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=20, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=21, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=22, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=23, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=24, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=25, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=26, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=27, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=28, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=29, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=30, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=31, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=32, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=33, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=34, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=35, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=36, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=37, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=38, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=39, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=40, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=41, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=42, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=43, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=44, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=45, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=46, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=47, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=48, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=49, step=0, tol=hybridLayer)
found 1552648 byte record for QC ( nx=421, ny=461, level=50, step=0, tol=hybridLayer)
>>> QC 421 461 50 1 1
CosmoState: The following variables could not be found in /home/userdata/leo.scheck/bacy_ahutt/cosmo_letkf/data/1000.05b/20140516060000/laf20140516080000.det :  ['RLAT', 'RLON']
CosmoState: trying to load from /home/userdata/leo.scheck/bacy_ahutt/cosmo_letkf/data/1000.05b/20140516090000/lff20140516080000.det :  ['RLAT', 'RLON']
found 1552648 byte record for RLAT ( nx=421, ny=461, level=0, step=1, tol=surface)
found 1552648 byte record for RLON ( nx=421, ny=461, level=0, step=1, tol=surface)
>>> RLON 421 461 1 1 1
>>> RLAT 421 461 1 1 1
In [129]:
plt.figure(2,figsize=(8,8))
plt.gray()
plt.imshow( np.log10(np.maximum(cs['QC'].max(axis=2),1e-4)), origin='lower' )
plt.contour( cs['RLAT'], levels=np.arange(40,60,2.5), colors='#009900')
plt.contour( cs['RLON'], levels=np.arange(0,30,2.5), colors='#009900')
Out[129]:
<matplotlib.contour.QuadContourSet at 0x7ff34d41c790>

Time and ensemble dimensions

In [130]:
ens=CosmoState('/home/l/Leonhard.Scheck/userdata/grib_examples/grib2_ensemble/2016052800.grib2') # a grib2 file containing 2 variables for 20 members and 25 times
In [131]:
ens['tp'].shape # access all times and members
Out[131]:
(461, 421, 25, 20)
In [132]:
ens['tp@2'].shape # access time step 2 only (but all members)
Out[132]:
(461, 421, 20)
In [133]:
ens['tp@2#10'].shape # access time step 2 of member 10
Out[133]:
(461, 421)
In [134]:
ens['tp#10'].shape # access all time steps of member 10
Out[134]:
(461, 421, 25)
In [135]:
plt.plot( ens['tp#10'].mean(axis=(0,1)), color='#cc0033', label='member #10' )
plt.plot( ens['tp'].mean(axis=(0,1,3)),  color='#0099ff', label='ensemble mean' )
plt.ylabel( '%s [%s]'%(ens.meta['tp']['name'],ens.meta['tp']['units']))
plt.legend(loc="upper left")
Out[135]:
<matplotlib.legend.Legend at 0x7ff3cee9eed0>
In [ ]: