[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[python #PHR-160601]: MetPy Help



Greetings!

Thanks for linking to the code, that helped. Looking at your current code, it 
looks like it is assembling 3D arrays of temperature and absolute vorticity out 
of individual GRIB messages using pygrib.

The first change is that potential_vorticity_baroclinic calculates some 
additional terms not in the original code, so it needs the full u and v wind 
components rather than the absolute vorticity field. I'm not sure how those are 
listed in pygrib, but you'd need to replace the code that looks for absolute 
vorticity with code to find those.

The second change is to make sure you attach unit information to your fields, 
like:

    from metpy.units import units
    pot_temp = np.array(pot_temp) * units.Kelvin
    levs = np.array(levs) * units.hPa

You could also use MetPy to calculate potential temperature from your 
temperature data with:

    import metpy.calc as mpcalc
    from metpy.units import units

    # Assume temp is list of all temperature 2D fields in Kelvin
    pot_temp = mpcalc.potential_temperature(levs, temp * units.K)

The third change is that you need some information about the lat/lon grid so 
that metpy can properly calculate horizontal derivatives:

    dx, dy = mpcalc.lat_lon_grid_deltas(longitude, latitude)

Then, the call to calculate PV would look like:

    pv = mpcalc.potential_vorticity_baroclinic(levs, pot_temp, u, v, dx=dx, 
dy=dy, latitude=latitude)

You might also consider using xarray + cfgrib rather than pygrib to open up the 
GRIB data. That would give you xarray DataArrays to work with right away--and 
MetPy can then get things like units, coordinates automatically.

Hope that helps,

Ryan

> Hi Ryan,
> 
> Thanks for getting back to me! I am trying to use the
> potential_vorticity_baroclinic. The script is I am trying to replace is
> here:
> https://github.com/dtcenter/METplus/blob/develop/parm/use_cases/model_applications/medium_range/TCStat_SeriesAnalysis_fcstGFS_obsGFS_FeatureRelative_SeriesByLead_PyEmbed_Multiple_Diagnostics/gfs_pv_fcst.py
> 
> The variables needed for this script are:
> Levels required: all pressure levels <= 100mb
> - Absolute Vorticity
> - Temperature
> 
> 
> Please let me know if you have any questions or have trouble accessing the
> link I provided.
> 


Ticket Details
===================
Ticket ID: PHR-160601
Department: Support Python
Priority: Low
Status: Closed
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.