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 (CACHE_NODE_OUTPUT_DEFAULT for general Nodes, and CACHE_DATASOURCE_OUTPUT_DEFAULT for DataSource nodes). If True, outputs will be cached and retrieved from cache. If False, outputs will not be cached OR retrieved from cache (even if they exist in cache).

Type

bool

force_eval

Default is False. Should the node’s cached output be updated from the source data? If True it ignores the cache when computing outputs but puts results into the cache (thereby updating the cache)

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

outputs

For multiple-output nodes, the names of the outputs. Default is None for standard nodes.

Type

list

output

For multiple-output nodes only, specifies a particular output to evaluate, if desired. Must be one of outputs.

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

  • _from_cache: whether the most recent call to eval used the cache

  • _multi_threaded: whether the most recent call to eval was executed using multiple threads

Alternative Constructors

from_definition(definition)

Create podpac Node from a dictionary definition.

from_json(s)

Create podpac Node from a JSON definition.

Methods

__init__(**kwargs)

Do not overwrite me

create_output_array(coords[, data, attrs])

Initialize an output data array

eval(coordinates, **kwargs)

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 coordinates for the Node.

from_url(url)

Create podpac Node from a WMS/WCS request.

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.

load(path)

Create podpac Node from file.

put_cache(data, key[, coordinates, expires, …])

Cache data for this node.

rem_cache(key[, coordinates, mode])

Clear cached data for this node.

save(path)

Write node to file.

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_is_defined(name)

trait_values(**metadata)

A dict of trait names and their values.

Attributes

attrs

List of node attributes

base_ref

Default reference/name in node definitions

cache_ctrl

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

cache_output

A boolean (True, False) trait.

definition

dtype

A trait which allows any value.

force_eval

A boolean (True, False) trait.

hash

hash for this node, used in caching and to determine equality.

json

Definition for this node in JSON format.

json_pretty

Definition for this node in JSON format, with indentation suitable for display.

output

A trait for unicode strings.

outputs

An instance of a Python list.

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

property attrs

List of node attributes

property base_ref

Default reference/name in node definitions

Returns

Name of the node in node 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.

create_output_array(coords, data=nan, attrs=None, **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

property definition
dtype

A trait which allows any value.

eval(coordinates, **kwargs)[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.

  • **kwargs (**dict) – Additional key-word arguments passed down the node pipelines, used internally

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 coordinates for the Node. Implemented in child classes.

Returns

coord_list – list of available coordinates (Coordinates objects)

Return type

list

force_eval

A boolean (True, False) trait.

classmethod from_definition(definition)[source]

Create podpac Node from a dictionary definition.

Parameters

d (dict) – node definition

Returns

podpac Node

Return type

Node

See also

definition()

node definition as a dictionary

from_json()

create podpac node from a JSON definition

load()

create a node from file

classmethod from_json(s)[source]

Create podpac Node from a JSON definition.

Parameters

s (str) – JSON-formatted node definition

Returns

podpac Node

Return type

Node

See also

json()

node definition as a JSON string

load()

create a node from file

classmethod from_url(url)[source]

Create podpac Node from a WMS/WCS request.

Parameters

url (str, dict) – The raw WMS/WCS request url, or a dictionary of query parameters

Returns

A full Node with sub-nodes based on the definition of the node from the URL

Return type

Node

Notes

The request can specify the PODPAC node by four different mechanism:

  • Direct node name: PODPAC will look for an appropriate node in podpac.datalib

  • JSON definition passed using the ‘PARAMS’ query string: Need to specify the special LAYER/COVERAGE value of “%PARAMS%”

  • By pointing at the JSON definition retrievable with a http GET request: e.g. by setting LAYER/COVERAGE value to https://my-site.org/pipeline_definition.json

  • By pointing at the JSON definition retrievable from an S3 bucket that the user has access to: e.g by setting LAYER/COVERAGE value to s3://my-bucket-name/pipeline_definition.json

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

property hash

hash for this node, used in caching and to determine equality.

init()[source]

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

property json

Definition for this node in JSON format.

property json_pretty

Definition for this node in JSON format, with indentation suitable for display.

classmethod load(path)[source]

Create podpac Node from file.

Parameters

path (str) – path to text file containing a JSON-formatted node definition

Returns

podpac Node

Return type

Node

See also

save()

save a node to file

output

A trait for unicode strings.

outputs

An instance of a Python list.

put_cache(data, key, coordinates=None, expires=None, overwrite=True)[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.

  • expires (float, datetime, timedelta) – Expiration date. If a timedelta is supplied, the expiration date will be calculated from the current time.

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

Raises

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

rem_cache(key, coordinates=None, mode='all')[source]

Clear cached data for this node.

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

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

  • mode (str, optional) – Specify which cache stores are affected. Default ‘all’.

See also

None()

save(path)[source]

Write node to file.

Parameters

path (str) – path to write to

See also

load()

load podpac Node from file.

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

trait_is_defined(name)[source]
units

A trait for unicode strings.