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

[python #KSG-176203]: Regarding sounding data pressure level interpolation



Greetings!

I'm not sure why you call it a "metpy interpolation function" since that 
function `vertical_interpolate` is not present in the MetPy library anywhere. I 
assume you found in this Python training notebook?

https://github.com/Unidata/python-training/blob/master/pages/gallery/Observational_Data_Cross_Section.ipynb

That function *can* handle irregularly spaced points to give you values at 
specific heights. However, you should be aware that function is performing 
log-based interpolation. That is, it is taking the logarithm of values before 
interpolating, then converting them back. This is traditionally only used when 
pressure is the vertical values. Whether you think this is appropriate in this 
case is obviously up to you, but if it were me I would probably just use 
numpy.interp.

Hope this helps,

Ryan

> def vertical_interpolate(vcoord_data, interp_var, interp_levels):
> """A function to interpolate sounding data from each station to
> every millibar. Assumes a log-linear relationship.
> Input    -----    vcoord_data : A 1D array of vertical level
> values (e.g., pressure from a radiosonde)    interp_var : A 1D array
> of the variable to be interpolated to all pressure levels
> vcoord_interp_levels : A 1D array containing veritcal levels to
> interpolate to
> Return    ------    interp_data : A 1D array that contains the
> interpolated variable on the interp_levels    """
> 
> # Make veritcal coordinate data and grid level log variables
> lnp = np.log
> <https://docs.scipy.org/doc/numpy/reference/generated/numpy.log.html#numpy.log>(vcoord_data)
> lnp_intervals = np.log
> <https://docs.scipy.org/doc/numpy/reference/generated/numpy.log.html#numpy.log>(interp_levels)
> 
> # Use numpy to interpolate from observed levels to grid levels
> interp_data = np.interp
> <https://docs.scipy.org/doc/numpy/reference/generated/numpy.interp.html#numpy.interp>(lnp_intervals[::-1],
> lnp[::-1], interp_var[::-1])[::-1]
> 
> # Mask for missing data (generally only near the surface)
> mask_low = interp_levels > vcoord_data[0]
> mask_high = interp_levels < vcoord_data[-1]
> interp_data[mask_low] = interp_var[0]
> interp_data[mask_high] = interp_var[-1]
> 
> return interp_data
> 
> 
> 
> 
> By this above metpy interpolation function , can we interpolate
> irregular "height" corresponding to irregular pressure to regular
> height?
> 
> Or is there any way to interpolate sounding (wyoming data) data's
> irregular height , if we have corresponding pressure and temperature?


Ticket Details
===================
Ticket ID: KSG-176203
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.