geocat.comp.triple_to_grid#
- geocat.comp.triple_to_grid(data, x_in, y_in, x_out, y_out, method=1, domain=1.0, distmx=None, missing_value=None, meta=False)#
Places unstructured (randomly-spaced) data onto the nearest locations of a rectilinear grid.
This function puts unstructured data (randomly-spaced) onto the nearest locations of a rectilinear grid. A default value of
domain
option is now set to 1.0 instead of 0.0.This function does not perform interpolation; rather, each individual data point is assigned to the nearest grid point. It is possible that upon return, grid will contain grid points set to missing value if no
x_in(n)
,y_in(n)
are nearby.- Parameters:
data (
xarray.DataArray
,numpy.ndarray
) – A multi-dimensional array, whose rightmost dimension is the same length asx_in
andy_in
, containing the values associated with the “x” and “y” coordinates. Missing values may be present but will be ignored.x_in (
xarray.DataArray
,numpy.ndarray
) – A one-dimensional array that specifies the x-coordinate associated with the input (data
).y_in (
xarray.DataArray
,numpy.ndarray
) – A one-dimensional array that specifies the y-coordinate associated with the input (data
).x_out (
xarray.DataArray
,numpy.ndarray
) – A one-dimensional array of lengthM
containing the x-coordinates associated with the returned two-dimensional grid. The coordinate values must be monotonically increasing.y_out (
xarray.DataArray
ornumpy.ndarray
) – A one-dimensional array of lengthN
containing the y-coordinates associated with the returned two-dimensional grid. The coordinate values must be monotonically increasing.method (
int
, optional) – An integer value that can be 0 or 1. The default value is 1. A value of 1 means to use the great circle distance formula for distance calculations. Warning:method = 0
, together withdomain = 1.0
, could result in many of the target grid points to be set to the missing value if the number of grid points is large (ie: a high resolution grid) and the number of observations relatively small.domain (
float
, optional) – A float value that should be set to a value>= 0
. The default value is 1.0. If present, the larger this factor, the wider the spatial domain allowed to influence grid boundary points. Typically,domain
is 1.0 or 2.0. Ifdomain <= 0.0
, then values located outside the grid domain specified byx_out
andy_out
arguments will not be used.distmx (
float
, optional) – Settingdistmx
allows the user to specify a search radius (km) beyond which observations are not considered for nearest neighbor. Only applicable whenmethod = 1
. The defaultdistmx=1e20 (km)
means that every grid point will have a nearest neighbor. It is suggested that users specify a reasonable value fordistmx
.missing_value (
numpy.number
, optional) – A numpy scalar value that represent a missing value indata
. The default value isnp.nan
. If specified explicitly, this argument allows the user to use a missing value scheme other than NaN or masked arrays.meta (
bool
, optional) – If set to True and the input array is an Xarray, the metadata from the input array will be copied to the output array; default is False. Warning: This option is not yet supported for this function.
- Returns:
grid (
xarray.DataArray
,numpy.ndarray
) – The returned array will beK
xN
xM
, whereK
represents the leftmost dimensions ofdata
, N represent the size ofy_out
, and M represent the size ofx_out
coordinate vectors.
Examples
Example 1: Using triple_to_grid with
xarray.DataArray
inputimport numpy as np import xarray as xr import geocat.comp # Open a netCDF data file using xarray default engine and load the data stream ds = xr.open_dataset("./ruc.nc") # [INPUT] Grid & data info on the source curvilinear data = ds.DIST_236_CBL[:] x_in = ds.gridlat_236[:] y_in = ds.gridlon_236[:] x_out = ds.gridlat_236[:] y_out = ds.gridlon_236[:] # [OUTPUT] Grid on destination points grid (or read the 1D lat and lon from # another .nc file. newlat1D_points=np.linspace(lat2D_curv.min(), lat2D_curv.max(), 100) newlon1D_points=np.linspace(lon2D_curv.min(), lon2D_curv.max(), 100) output = geocat.comp.triple_to_grid(data, x_in, y_in, x_out, y_out)