geocat.comp.grid_to_triple

geocat.comp.grid_to_triple(data, x_in=None, y_in=None, msg_py=None)

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)