podpac.coordinates.StackedCoordinates

class podpac.coordinates.StackedCoordinates(**kwargs: Any)[source]

Bases: BaseCoordinates

Stacked coordinates.

StackedCoordinates contain coordinates from two or more different dimensions that are stacked together to form a list of points (rather than a grid). The underlying coordinates values are Coordinates1d objects of equal size. The name for the stacked coordinates combines the underlying dimensions with underscores, e.g. 'lat_lon' or 'lat_lon_time'.

When creating Coordinates, podpac automatically detects StackedCoordinates. The following Coordinates contain 3 stacked lat-lon coordinates and 2 time coordinates in a 3 x 2 grid:

>>> lat = [0, 1, 2]
>>> lon = [10, 20, 30]
>>> time = ['2018-01-01', '2018-01-02']
>>> podpac.Coordinates([[lat, lon], time], dims=['lat_lon', 'time'])
Coordinates
    lat_lon[lat]: ArrayCoordinates1d(lat): Bounds[0.0, 2.0], N[3]
    lat_lon[lon]: ArrayCoordinates1d(lon): Bounds[10.0, 30.0], N[3]
    time: ArrayCoordinates1d(time): Bounds[2018-01-01, 2018-01-02], N[2]

For convenience, you can also create uniformly-spaced stacked coordinates using clinspace:

>>> lat_lon = podpac.clinspace((0, 10), (2, 30), 3)
>>> time = ['2018-01-01', '2018-01-02']
>>> podpac.Coordinates([lat_lon, time], dims=['lat_lon', 'time'])
Coordinates
    lat_lon[lat]: ArrayCoordinates1d(lat): Bounds[0.0, 2.0], N[3]
    lat_lon[lon]: ArrayCoordinates1d(lon): Bounds[10.0, 30.0], N[3]
    time: ArrayCoordinates1d(time): Bounds[2018-01-01, 2018-01-02], N[2]
Parameters:
  • dims (tuple) – Tuple of dimension names.

  • name (str) – Stacked dimension name.

  • coords (dict-like) – xarray coordinates (container of coordinate arrays)

  • coordinates (pandas.MultiIndex) – MultiIndex of stacked coordinates values.

Alternative Constructors

from_definition(d)

Create StackedCoordinates from a stacked coordinates definition.

from_xarray(x, **kwargs)

Create 1d Coordinates from named xarray coordinates.

Methods

__init__(coords[, name, dims])

Initialize a multidimensional coords bject.

copy()

Make a copy of the stacked coordinates.

flatten()

get_area_bounds(boundary)

Get coordinate area bounds, including boundary information, for each unstacked dimension.

issubset(other)

Report whether other coordinates contains these coordinates.

reshape(newshape)

select(bounds[, outer, return_index])

Get the coordinate values that are within the given bounds in all dimensions.

simplify()

trait_defaults(*names, **metadata)

Return a trait's default value or a dictionary of them

trait_has_value(name)

Returns True if the specified trait has a value.

trait_values(**metadata)

A dict of trait names and their values.

transpose(*dims, **kwargs)

Transpose (re-order) the dimensions of the StackedCoordinates.

unique([return_index])

Remove duplicate stacked coordinate values.

Attributes

bounds

Dictionary of (low, high) coordinates bounds in each dimension

coordinates

definition

Serializable stacked coordinates definition.

dims

Tuple of dimension names.

full_definition

Serializable stacked coordinates definition, containing all properties.

is_affine

name

Stacked dimension name.

ndim

coordinates array ndim.

shape

Shape of the stacked coordinates.

size

Number of stacked coordinates.

udims

Tuple of unstacked dimension names, for compatibility.

xcoords

xarray coordinates (container of coordinate arrays)

xdims

Tuple of indexing dimensions used to create xarray DataArray.

Members:

__init__(coords, name=None, dims=None)[source]

Initialize a multidimensional coords bject.

Parameters:

coords (list, StackedCoordinates) – Coordinate values in a list, or a StackedCoordinates object to copy.

See also

clinspace, crange

property bounds

Dictionary of (low, high) coordinates bounds in each dimension

Type:

dict

property coordinates
copy()[source]

Make a copy of the stacked coordinates.

Returns:

Copy of the stacked coordinates.

Return type:

StackedCoordinates

property definition

Serializable stacked coordinates definition.

Type:

list

property dims

Tuple of dimension names.

Type:

tuple

flatten()[source]
classmethod from_definition(d)[source]

Create StackedCoordinates from a stacked coordinates definition.

Parameters:

d (list) – stacked coordinates definition

Returns:

stacked coordinates object

Return type:

StackedCoordinates

See also

definition

classmethod from_xarray(x, **kwargs)[source]

Create 1d Coordinates from named xarray coordinates.

Parameters:

x (xarray.DataArray) – Nade DataArray of the coordinate values

Returns:

1d coordinates

Return type:

ArrayCoordinates1d

property full_definition

Serializable stacked coordinates definition, containing all properties. For internal use.

Type:

list

get_area_bounds(boundary)[source]

Get coordinate area bounds, including boundary information, for each unstacked dimension.

Parameters:

boundary (dict) – dictionary of boundary offsets for each unstacked dimension. Point dimensions can be omitted.

Returns:

area_bounds – Dictionary of (low, high) coordinates area_bounds in each unstacked dimension

Return type:

dict

property is_affine
issubset(other)[source]

Report whether other coordinates contains these coordinates.

Parameters:

other (Coordinates, StackedCoordinates) – Other coordinates to check

Returns:

issubset – True if these coordinates are a subset of the other coordinates.

Return type:

bool

property name

Stacked dimension name. Stacked dimension names are the individual dims joined by an underscore.

Type:

str

property ndim

coordinates array ndim.

Type:

int

reshape(newshape)[source]
select(bounds, outer=False, return_index=False)[source]

Get the coordinate values that are within the given bounds in all dimensions.

Note: you should not generally need to call this method directly.

Parameters:
  • bounds (dict) – dictionary of dim -> (low, high) selection bounds

  • outer (bool, optional) – If True, do outer selections. Default False.

  • return_index (bool, optional) – If True, return index for the selections in addition to coordinates. Default False.

Returns:

  • selection (StackedCoordinates) – StackedCoordinates object consisting of the selection in all dimensions.

  • selection_index (slice, boolean array) – Slice or index for the selected coordinates, only if return_index is True.

property shape

Shape of the stacked coordinates.

Type:

tuple

simplify()[source]
property size

Number of stacked coordinates.

Type:

int

transpose(*dims, **kwargs)[source]

Transpose (re-order) the dimensions of the StackedCoordinates.

Parameters:
  • dim_1 (str, optional) – Reorder dims to this order. By default, reverse the dims.

  • dim_2 (str, optional) – Reorder dims to this order. By default, reverse the dims.

  • ... (str, optional) – Reorder dims to this order. By default, reverse the dims.

  • in_place (boolean, optional) – If True, transpose the dimensions in-place. Otherwise (default), return a new, transposed Coordinates object.

Returns:

transposed – The transposed StackedCoordinates object.

Return type:

StackedCoordinates

unique(return_index=False)[source]

Remove duplicate stacked coordinate values.

Parameters:

return_index (bool, optional) – If True, return index for the unique coordinates in addition to the coordinates. Default False.

Returns:

  • unique (StackedCoordinates) – New StackedCoordinates object with unique, sorted, flattened coordinate values.

  • unique_index (list of indices) – index

property xcoords

xarray coordinates (container of coordinate arrays)

Type:

dict-like