geocat.f2py.triple_to_grid_wrapper

Module Contents

Functions

_grid_to_triple(x, y, z, msg_py)

_triple_to_grid(data, x_in, y_in, x_out, y_out, shape)

_triple_to_grid_2d(x_in, y_in, data, x_out, y_out, msg_py)

grid_to_triple(→ supported_types)

Converts a two-dimensional grid with one-dimensional coordinate

triple_to_grid(→ supported_types)

Places unstructured (randomly-spaced) data onto the nearest locations of

triple_to_grid_2d(x_in, y_in, data, x_out, y_out, msg_py)

grid2triple(x_in, y_in, data, msg_py)

triple2grid(x_in, y_in, data, x_out, y_out, **kwargs)

Attributes

supported_types

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 in data, 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) is numpy.ndarray; otherwise, it should come from fi.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) is numpy.ndarray; otherwise, it should come from fi.coords.

  • msg_py (numpy.number) – A numpy scalar value that represent a 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.

Returns

out – The maximum size of the returned array will be 3 x ld, where ld <= ny x mx. If no missing values are encountered in data, then ld = ny x mx. If missing values are encountered in data, they are not returned and hence ld will be equal to ny x mx minus the number of missing values found in data.

Return type

xarray.DataArray, numpy.ndarray

Examples

Example 1: Using grid_to_triple with xarray.DataArray input

import 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 as x_in and y_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 length M containing the x-coordinates associated with the returned two-dimensional grid. The coordinate values must be monotonically increasing.

  • y_out (xarray.DataArray or numpy.ndarray) – A one-dimensional array of length N 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 with domain = 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. If domain <= 0.0, then values located outside the grid domain specified by x_out and y_out arguments will not be used.

  • distmx (float, optional) – Setting distmx allows the user to specify a search radius (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 a reasonable value for distmx.

  • missing_value (numpy.number, optional) – A numpy scalar value that represent a missing value in data. The default value is np.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 x N x M, where K represents the leftmost dimensions of data, N represent the size of y_out, and M represent the size of x_out coordinate vectors.

Return type

xarray.DataArray, numpy.ndarray

Examples

Example 1: Using triple_to_grid with xarray.DataArray input

import 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)