geocat.f2py.triple_to_grid_wrapper
¶
Module Contents¶
Functions¶
|
|
|
|
|
|
|
Converts a two-dimensional grid with one-dimensional coordinate |
|
Places unstructured (randomly-spaced) data onto the nearest locations of |
|
|
|
|
|
Attributes¶
- geocat.f2py.triple_to_grid_wrapper.supported_types¶
- geocat.f2py.triple_to_grid_wrapper._grid_to_triple(x, y, z, msg_py)¶
- geocat.f2py.triple_to_grid_wrapper._triple_to_grid(data, x_in, y_in, x_out, y_out, shape, method=None, distmx=None, domain=None, msg_py=None)¶
- geocat.f2py.triple_to_grid_wrapper._triple_to_grid_2d(x_in, y_in, data, x_out, y_out, msg_py)¶
- geocat.f2py.triple_to_grid_wrapper.grid_to_triple(data: supported_types, x_in: supported_types = None, y_in: supported_types = None, msg_py: supported_types = None) supported_types ¶
Converts a two-dimensional grid with one-dimensional coordinate variables to an array where each grid value is associated with its coordinates.
- Parameters
data (
xarray.DataArray
,numpy.ndarray
) – Two-dimensional input array of size ny x mx containing the data values. Missing values may be present indata
, but they are ignored.x_in (
xarray.DataArray
,numpy.ndarray
) –A one-dimensional array that specifies the the right dimension coordinates of the input (
data
).Note: It should only be explicitly provided when the input (
fi
) isnumpy.ndarray
; otherwise, it should come fromfi.coords
.y_in (
xarray.DataArray
,numpy.ndarray
) –A one-dimensional array that specifies the the left dimension coordinates of the input (
data
).Note: It should only be explicitly provided when the input (
fi
) isnumpy.ndarray
; otherwise, it should come fromfi.coords
.msg_py (
numpy.number
) – A numpy scalar value that represent a missing value indata
. This argument allows a user to use a missing value scheme other than NaN or masked arrays, similar to what NCL allows.
- Returns
out – The maximum size of the returned array will be
3 x ld
, whereld <= ny x mx
. If no missing values are encountered indata
, thenld = ny x mx
. If missing values are encountered indata
, they are not returned and henceld
will be equal tony x mx
minus the number of missing values found indata
.- Return type
Examples
Example 1: Using grid_to_triple 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("./NETCDF_FILE.nc") # [INPUT] Grid & data info on the source curvilinear data = ds.DIST_236_CBL[:] x_in = ds.gridlat_236[:] y_in = ds.gridlon_236[:] output = geocat.comp.grid_to_triple(data, x_in, y_in)
- geocat.f2py.triple_to_grid_wrapper.triple_to_grid(data: supported_types, x_in: supported_types, y_in: supported_types, x_out: supported_types, y_out: supported_types, method: int = 1, domain: float = 1.0, distmx: float = None, missing_value: numpy.number = None, meta: bool = False) supported_types ¶
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 – The returned array will be
K
xN
xM
, whereK
represents the leftmost dimensions ofdata
, N represent the size ofy_out
, and M represent the size ofx_out
coordinate vectors.- Return type
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)
- geocat.f2py.triple_to_grid_wrapper.triple_to_grid_2d(x_in, y_in, data, x_out, y_out, msg_py)¶
- geocat.f2py.triple_to_grid_wrapper.grid2triple(x_in, y_in, data, msg_py)¶
- geocat.f2py.triple_to_grid_wrapper.triple2grid(x_in, y_in, data, x_out, y_out, **kwargs)¶