wrf.interp1d¶
- wrf.interp1d(field, z_in, z_out, missing=<MagicMock name='mock().item()' id='140499233145616'>, meta=True)¶
Return the linear interpolation of a one-dimensional variable.
This function is typically used to interpolate a variable in a vertical column, but the coordinate system need not be a vertical coordinate system. Multiple interpolation points may be specified in the z_out parameter.
- Parameters:
field (
xarray.DataArray
ornumpy.ndarray
) – A one-dimensional field. Metadata for field is only copied to the output if field is axarray.DataArray
object.z_in (
xarray.DataArray
ornumpy.ndarray
) – The one-dimensional coordinates associated with field (usually the vertical coordinates, either height or pressure).z_out (
xarray.DataArray
,numpy.ndarray
) – A one-dimensional array of z_in coordinate points to interpolate to. Must be the same type as z_in.missing (
float
, optional) – The fill value to use for the output. Default iswrf.default_fill(np.float64)
.meta (
bool
, optional) – Set to False to disable metadata and returnnumpy.ndarray
instead ofxarray.DataArray
. Default is True.
Warning
The input arrays must not contain any missing/fill values or
numpy.nan
values.- Returns:
An array with the same dimensionality as z_out containing the interpolated values. If xarray is enabled and the meta parameter is True, then the result will be a
xarray.DataArray
object. Otherwise, the result will be anumpy.ndarray
object with no metadata.- Return type:
Examples
Example 1: Calculate the 850 hPa and 500 hPa values at location x,y = (100,200)
import numpy as np from wrf import getvar, interp1d from netCDF4 import Dataset wrfnc = Dataset("wrfout_d02_2010-06-13_21:00:00") # Get a 1D vertical column for pressure at location x,y = 100,200 p_1d = wrf.getvar(wrfnc, "pres", units="hPa")[:,200,100] # Get a 1D vertical column for height at location 100,200 ht_1d = wrf.getvar(wrfnc, "z", units="dm")[:,200,100] # Want the heights (in decameters) at 850, 500 hPa levels = np.asarray([850., 500.]) # Get the 850 hPa and 500 hPa values at location 100,200. interp_vals = interp1d(p_1d, ht_1d, levels)