geocat.comp.triple2grid¶
-
geocat.comp.
triple2grid
(x, y, data, xgrid, ygrid, **kwargs)¶ Places unstructured (randomly-spaced) data onto the nearest locations of a rectilinear grid.
- Parameters
x (
numpy.ndarray
) – One-dimensional arrays of the same length containing the coordinates associated with the data values. For geophysical variables, x correspond to longitude.y (
numpy.ndarray
) – One-dimensional arrays of the same length containing the coordinates associated with the data values. For geophysical variables, y correspond to latitude.data (
numpy.ndarray
) – A multi-dimensional array, whose rightmost dimension is the same length as x and y, containing the values associated with the x and y coordinates. Missing values, may be present but will be ignored.xgrid (
numpy.ndarray
) – A one-dimensional array of length M containing the x coordinates associated with the returned two-dimensional grid. For geophysical variables, these are longitudes. The coordinates’ values must be monotonically increasing.ygrid (
numpy.ndarray
) – A one-dimensional array of length N containing the y coordinates associated with the returned two-dimensional grid. For geophysical variables, these are latitudes. The coordinates’ values must be monotonically increasing.**kwargs –
extra options for the function. Currently the following are supported: -
method
: An integer value that defaults to 1 if option is True,and 0 otherwise. A value of 1 means to use the great circle distance formula for distance calculations.
domain
: A float value that should be set to a value >= 0. Thedefault 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. If domain <= 0.0, then values located outside the grid domain specified by xgrid and ygrid arguments will not be used.
distmx
: Setting option@distmx allows the user to specify a searchradius (km) beyond which observations are not considered for nearest neighbor. Only applicable when method = 1. The default `distmx`=1e20 (km) means that every grid point will have a nearest neighbor. It is suggested that users specify some reasonable value for distmx.
msg
(numpy.number
): A numpy scalar value that representa missing value in data. This argument allows a user to use a missing value scheme other than NaN or masked arrays, similar to what NCL allows.
meta
(bool
): 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 currently supported.
- Returns
The return array will be K x N x M, where K represents the leftmost dimensions of data. It will be of type double if any of the input is double, and float otherwise.
- Return type
- Description:
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(n), y(n) are nearby.
Examples
Example 1: Using triple2grid 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 = ds.gridlat_236[:] y = ds.gridlon_236[:] xgrid = ds.gridlat_236[:] ygrid = ds.gridlon_236[:] # [OUTPUT] Grid on destination points grid (or read the 1D lat and lon from # an other .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.triple2grid(x, y, data, xgrid, ygrid)