podpac.Node

class podpac.Node(**kwargs)[source]

Bases: traitlets.traitlets.HasTraits

The base class for all Nodes, which defines the common interface for everything.

cache_output

Should the node’s output be cached? If not provided or None, uses default based on settings.

Type

bool

cache_update

Default is False. Should the node’s cached output be updated from the source data?

Type

bool

cache_ctrl

Class that controls caching. If not provided, uses default based on settings.

Type

podpac.core.cache.cache.CacheCtrl

dtype

The numpy datatype of the output. Currently only float is supported.

Type

type

style

Object discribing how the output of a node should be displayed. This attribute is planned for deprecation in the future.

Type

podpac.Style

units

The units of the output data. Must be pint compatible.

Type

str

Notes

Additional attributes are available for debugging after evaluation, including:
  • _requested_coordinates: the requested coordinates of the most recent call to eval

  • _output: the output of the most recent call to eval

Methods

__init__(**kwargs)

Do not overwrite me

create_output_array(coords[, data])

Initialize an output data array

eval(coordinates[, output])

Evaluate the node at the given coordinates.

eval_group(group)

Evaluate the node for each of the coordinates in the group.

find_coordinates()

Get all available native coordinates for the Node.

get_cache(key[, coordinates])

Get cached data for this node.

has_cache(key[, coordinates])

Check for cached data for this node.

init()

Overwrite this method if a node needs to do any additional initialization after the standard initialization.

put_cache(data, key[, coordinates, overwrite])

Cache data for this node.

rem_cache(key[, coordinates, mode, all_cache])

Clear cached data for this node.

Attributes

base_definition

Pipeline node definition.

base_ref

Default pipeline node reference/name in pipeline node definitions

cache_ctrl

A trait whose value must be an instance of a specified class.

cache_output

A boolean (True, False) trait.

cache_update

A boolean (True, False) trait.

definition

Full pipeline definition for this node.

dtype

A trait which allows any value.

hash

json

definition for this node in json format

json_pretty

pipeline

Create a pipeline node from this node

style

A trait whose value must be an instance of a specified class.

units

A trait for unicode strings.

Members

__init__(**kwargs)[source]

Do not overwrite me

base_definition

Pipeline node definition.

This property is implemented in the primary base nodes (DataSource, Algorithm, and Compositor). Node subclasses with additional attrs will need to extend this property.

Returns

Return type

{definition_return}

base_ref

Default pipeline node reference/name in pipeline node definitions

Returns

Name of the node in pipeline definitions

Return type

str

cache_ctrl

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

cache_output

A boolean (True, False) trait.

cache_update

A boolean (True, False) trait.

create_output_array(coords, data=nan, **kwargs)[source]

Initialize an output data array

Parameters
  • coords (podpac.Coordinates) – Input to UnitsDataArray (i.e. an xarray coords dictionary/list)

  • data (None, number, or array-like (optional)) –

    How to initialize the array. Options are:

    nan: uses np.full(…, np.nan) (Default option) empty: uses np.empty zeros: uses np.zeros() ones: uses np.ones full: uses np.full(…, fillval) data: uses the fillval as the input array

  • **kwargs – Dictioary of any additional keyword arguments that will be passed to UnitsDataArray.

Returns

Unit-aware xarray DataArray of the desired size initialized using the method specified.

Return type

podpac.UnitsDataArray

definition

Full pipeline definition for this node.

Returns

Dictionary-formatted definition of a PODPAC pipeline.

Return type

OrderedDict

dtype

A trait which allows any value.

eval(coordinates, output=None)[source]

Evaluate the node at the given coordinates.

Parameters
  • coordinates (podpac.Coordinates) – The set of coordinates requested by a user. The Node will be evaluated using these coordinates.

  • output (podpac.UnitsDataArray, optional) – Default is None. Optional input array used to store the output data. When supplied, the node will not allocate its own memory for the output array. This array needs to have the correct dimensions, coordinates, and coordinate reference system.

Returns

  • output

  • podpac.UnitsDataArray – Unit-aware xarray DataArray containing the results of the node evaluation.

eval_group(group)[source]

Evaluate the node for each of the coordinates in the group.

Parameters

group (podpac.CoordinatesGroup) – Group of coordinates to evaluate.

Returns

outputs – evaluation output, list of UnitsDataArray objects

Return type

list

find_coordinates()[source]

Get all available native coordinates for the Node. Implemented in child classes.

Returns

coord_list – list of available coordinates (Coordinates objects)

Return type

list

get_cache(key, coordinates=None)[source]

Get cached data for this node.

Parameters
  • key (str) – Key for the cached data, e.g. ‘output’

  • coordinates (podpac.Coordinates, optional) – Coordinates for which the cached data should be retrieved. Omit for coordinate-independent data.

Returns

data – The cached data.

Return type

any

Raises

NodeException – Cached data not found.

has_cache(key, coordinates=None)[source]

Check for cached data for this node.

Parameters
  • key (str) – Key for the cached data, e.g. ‘output’

  • coordinates (podpac.Coordinates, optional) – Coordinates for which the cached data should be retrieved. Omit for coordinate-independent data.

Returns

True if there is cached data for this node, key, and coordinates.

Return type

bool

hash
init()[source]

Overwrite this method if a node needs to do any additional initialization after the standard initialization.

json

definition for this node in json format

Returns

JSON-formatted definition of a PODPAC pipeline.

Return type

str

Notes

This definition can be used to create Pipeline Nodes. It also serves as a light-weight transport mechanism to share algorithms and pipelines, or run code on cloud services.

json_pretty
pipeline

Create a pipeline node from this node

Returns

A pipeline node that wraps this node

Return type

podpac.Pipeline

put_cache(data, key, coordinates=None, overwrite=False)[source]

Cache data for this node.

Parameters
  • data (any) – The data to cache.

  • key (str) – Unique key for the data, e.g. ‘output’

  • coordinates (podpac.Coordinates, optional) – Coordinates that the cached data depends on. Omit for coordinate-independent data.

  • overwrite (bool, optional) – Overwrite existing data, default False

Raises

NodeException – Cached data already exists (and overwrite is False)

rem_cache(key, coordinates=None, mode=None, all_cache=False)[source]

Clear cached data for this node.

Parameters
  • key (str, optional) – Delete cached objects with this key. If ‘*’, cached data is deleted for all keys.

  • coordinates (podpac.Coordinates, str, optional) – Delete cached objects for these coordinates. If ‘*’, cached data is deleted for all coordinates, including coordinate-independent data.

  • mode (str, optional) – Specify which cache stores are affected.

  • all_cache (bool, optional) – Default is False. If True, deletes all of the cache.

See also

None()

style

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

units

A trait for unicode strings.