wrf.interp1d

wrf.interp1d(field, z_in, z_out, missingval=9.969209968386869e+36, 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 or numpy.ndarray) – A one-dimensional field. Metadata for field is only copied to the output if field is a xarray.DataArray object.
  • z_in (xarray.DataArray or numpy.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.
  • missingval (float, optional) – The fill value to use for the output. Default is wrf.Constants.DEFAULT_FILL.
  • meta (bool, optional) – Set to False to disable metadata and return numpy.ndarray instead of xarray.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 a numpy.ndarray object with no metadata.
Return type:xarray.DataArray or numpy.ndarray

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)