Convert profiles vertical coordinate from Hybrid-Pressure to pressure

[1]:
%matplotlib inline
# for figures in notebook

# import & initialize epygram
import epygram
epygram.init_env()

import os
INPUTS_DIR = os.path.join('..', 'inputs')
[2]:
r = epygram.resources.meta_resource(os.path.join(INPUTS_DIR, 'ICMSHAROM+0022'), 'r', 'CL')  # CL = CombineLevels
# in a "CL" meta-resource, fields are to be grabbed through a GRIB2 nomenclature
t_as_grib2 = dict(discipline=0, parameterCategory=0, parameterNumber=0,  # this is temperature
                  typeOfFirstFixedSurface=119)  # hybrid-pressure levels
[3]:
# read as 3D
t3d = r.readfield(t_as_grib2)
t3d.sp2gp()
[4]:
# extract profiles
profiles = []
for position in [(6.1,46.2), (6.8,45.8), (6,46.5)]:
    profgeo = t3d.geometry.make_profile_geometry(*position)  # make a V1D geometry at that position
    profiles.append(t3d.extract_subdomain(profgeo))  # extract subdomain corresponding to the geometry of the profile
[5]:
# plot with level as vertical coord
fig = ax = None
for p in profiles:
    fig, ax = p.plotfield(labels='Temperature @ ({}, {})'.format(p.geometry.grid['longitudes'][0],
                                                                 p.geometry.grid['latitudes'][0]),
                          over=(fig, ax))  # superpose profiles
../../_images/gallery_D.2-vertical_geometry_02.profiles_vertical_coords_2pressure_5_0.png

and now on a Pressure z-axis

[6]:
# for the conversion, we need Surface pressure
ps = epygram.formats.resource(r.resource.container.abspath, 'r').readfield('SURFPRESSION')
# Ps is spectral and ln(Ps)
ps.sp2gp()
ps.operation('exp')
[7]:
from epygram.geometries.VGeometry import hybridP2pressure

for p in profiles:
    ps_local = ps.getvalue_ll(p.geometry.grid['longitudes'][0],
                              p.geometry.grid['latitudes'][0])
    # create the P vertical coordinate
    p.geometry.vcoordinate = hybridP2pressure(p.geometry.vcoordinate,
                                              ps_local,
                                              vertical_mean='geometric')
[8]:
fig = ax = None
for p in profiles:
    fig, ax = p.plotfield(labels='Temperature @ ({}, {})'.format(p.geometry.grid['longitudes'][0],
                                                                 p.geometry.grid['latitudes'][0]),
                          over=(fig, ax))  # superpose profiles
../../_images/gallery_D.2-vertical_geometry_02.profiles_vertical_coords_2pressure_9_0.png
[ ]: