podpac.coordinates.StackedCoordinates

class podpac.coordinates.StackedCoordinates(coords, name=None, dims=None, ctype=None)[source]

Bases: podpac.core.coordinates.base_coordinates.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], ctype['midpoint']
    lat_lon[lon]: ArrayCoordinates1d(lon): Bounds[10.0, 30.0], N[3], ctype['midpoint']
    time: ArrayCoordinates1d(time): Bounds[2018-01-01, 2018-01-02], N[2], ctype['midpoint']

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], ctype['midpoint']
    lat_lon[lon]: ArrayCoordinates1d(lon): Bounds[10.0, 30.0], N[3], ctype['midpoint']
    time: ArrayCoordinates1d(time): Bounds[2018-01-01, 2018-01-02], N[2], ctype['midpoint']
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(xcoords[, ctype])

Convert an xarray coord to StackedCoordinates

Methods

__init__(coords[, name, dims, ctype])

Initialize a multidimensional coords object.

copy()

Make a copy of the stacked coordinates.

select(bounds[, return_indices, outer])

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

Attributes

area_bounds

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

bounds

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

coordinates

MultiIndex of stacked coordinates values.

coords

xarray coordinates (container of coordinate arrays)

definition

Serializable stacked coordinates definition.

dims

Tuple of dimension names.

full_definition

Serializable stacked coordinates definition, containing all properties.

idims

Tuple of indexing dimensions.

name

Stacked dimension name.

shape

Shape of the stacked coordinates.

size

Number of stacked coordinates.

udims

Tuple of unstacked dimension names, for compatibility.

values

MultiIndex of stacked coordinates values.

Members

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

Initialize a multidimensional coords object.

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

  • ctype (str, optional) – Default coordinates type.

See also

clinspace(), crange()

area_bounds

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

Type

dict

bounds

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

Type

dict

coordinates

MultiIndex of stacked coordinates values.

Type

pandas.MultiIndex

coords

xarray coordinates (container of coordinate arrays)

Type

dict-like

copy()[source]

Make a copy of the stacked coordinates.

Returns

Copy of the stacked coordinates.

Return type

StackedCoordinates

definition

Serializable stacked coordinates definition.

Type

list

dims

Tuple of dimension names.

Type

tuple

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(xcoords, ctype=None)[source]

Convert an xarray coord to StackedCoordinates

Parameters
  • xcoords (DataArrayCoordinates) – xarray coords attribute to convert

  • ctype (str, optional) – Default coordinates type.

Returns

coord – stacked coordinates object

Return type

StackedCoordinates

full_definition

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

Type

list

idims

Tuple of indexing dimensions.

For stacked coordinates, this is a singleton of the stacked coordinates name (self.name,).

Type

tuple

name

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

Type

str

select(bounds, return_indices=False, outer=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_indices (bool, optional) – If True, return slice or indices for the selections in addition to coordinates. Default False.

Returns

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

  • I (slice or list) – Slice or index for the selected coordinates, only if return_indices is True.

shape

Shape of the stacked coordinates.

Type

tuple

size

Number of stacked coordinates.

Type

int

udims

Tuple of unstacked dimension names, for compatibility. This is the same as the dims.

Type

tuple

values

MultiIndex of stacked coordinates values.

Type

pandas.MultiIndex