wrf.xy¶
- wrf.xy(field, pivot_point=None, angle=None, start_point=None, end_point=None, meta=True)¶
Return the x,y points for a line within a two-dimensional grid.
This function is primarily used to obtain the x,y points when making a cross section.
- Parameters:
field (
xarray.DataArray
ornumpy.ndarray
) – A field with at least two dimensions.pivot_point (
tuple
orlist
, optional) – Atuple
orlist
with two entries, in the form of [x, y] (or [west_east, south_north]), which indicates the x,y location through which the plane will pass. Must also specify angle.angle (
float
, optional) – Only valid for cross sections where a plane will be plotted through a given point on the model domain. 0.0 represents a S-N cross section. 90.0 is a W-E cross section.start_point (
tuple
orlist
, optional) – Atuple
orlist
with two entries, in the form of [x, y] (or [west_east, south_north]), which indicates the start x,y location through which the plane will pass.end_point (
tuple
orlist
, optional) – Atuple
orlist
with two entries, in the form of [x, y] (or [west_east, south_north]), which indicates the end x,y location through which the plane will pass.meta (
bool
, optional) – Set to False to disable metadata and returnnumpy.ndarray
instead ofxarray.DataArray
. Default is True.
- Returns:
An array of x,y points, which has shape num_points x 2. 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: Using Pivot Point and Angle
from wrf import getvar, xy from netCDF4 import Dataset wrfnc = Dataset("wrfout_d02_2010-06-13_21:00:00") field = wrf.getvar(wrfnc, "slp") # Use the center of the grid pivot = (field.shape[-1]/2.0, field.shape[-2]/2.0) # West-East angle = 90.0 xy_points = xy(field, pivot_point=pivot, angle=angle)
Example 2: Using Start Point and End Point
from wrf import getvar, xy from netCDF4 import Dataset wrfnc = Dataset("wrfout_d02_2010-06-13_21:00:00") field = wrf.getvar(wrfnc, "slp") # Make a diagonal of lower left to upper right start = (0, 0) end = (-1, -1) xy_points = xy(field, start_point=start, end_point=end)