satpy.dependency_tree module

Implementation of a dependency tree.

class satpy.dependency_tree.DependencyTree(readers, compositors=None, modifiers=None, available_only=False)[source]

Bases: Tree

Structure to discover and store Dataset dependencies.

Used primarily by the Scene object to organize dependency finding. Dependencies are stored used a series of Node objects which this class is a subclass of.

Collect Dataset generating information.

Collect the objects that generate and have information about Datasets including objects that may depend on certain Datasets being generated. This includes readers, compositors, and modifiers.

Composites and modifiers are defined per-sensor. If multiple sensors are available, compositors and modifiers are searched for in sensor alphabetical order.

Parameters:
  • readers (dict) – Reader name -> Reader Object

  • compositors (dict) – Sensor name -> Composite ID -> Composite Object. Empty dictionary by default.

  • modifiers (dict) – Sensor name -> Modifier name -> (Modifier Class, modifier options). Empty dictionary by default.

  • available_only (bool) – Whether only reader’s available/loadable datasets should be used when searching for dependencies (True) or use all known/configured datasets regardless of whether the necessary files were provided to the reader (False). Note that when False loadable variations of a dataset will have priority over other known variations. Default is False.

_create_implicit_dependency_subtree(dataset_key, query)[source]
_create_optional_subtrees(parent, prereqs, query=None)[source]

Determine optional prerequisite Nodes for a composite.

Parameters:
  • parent (Node) – Compositor node to add these prerequisites under

  • prereqs (sequence) – Strings (names), floats (wavelengths), or DataQuerys to analyze.

_create_prerequisite_subtrees(parent, prereqs, query=None)[source]

Determine prerequisite Nodes for a composite.

Parameters:
  • parent (Node) – Compositor node to add these prerequisites under

  • prereqs (sequence) – Strings (names), floats (wavelengths), DataQuerys or Nodes to analyze.

_create_required_subtrees(parent, prereqs, query=None)[source]

Determine required prerequisite Nodes for a composite.

Parameters:
  • parent (Node) – Compositor node to add these prerequisites under

  • prereqs (sequence) – Strings (names), floats (wavelengths), DataQuerys or Nodes to analyze.

_create_subtree_for_key(dataset_key, query=None)[source]

Find the dependencies for dataset_key.

Parameters:
  • dataset_key (str, float, DataID, DataQuery) – Dataset identifier to locate and find any additional dependencies for.

  • query (DataQuery) – Additional filter parameters. See satpy.readers.get_key for more details.

_create_subtree_from_compositors(dataset_key, query)[source]
_create_subtree_from_reader(dataset_key, query)[source]
_find_compositor(dataset_key, query)[source]

Find the compositor object for the given dataset_key.

_find_matching_ids_in_readers(dataset_key)[source]
_find_reader_node(dataset_key, query)[source]

Attempt to find a DataID in the available readers.

Parameters:

dataset_key (str, float, DataID, DataQuery) – Dataset name, wavelength, DataID or DataQuery to use in searching for the dataset from the available readers.

_get_subtree_for_existing_key(dsq)[source]
_get_subtree_for_existing_name(dsq)[source]
static _get_unique_id_from_sorted_ids(sorted_ids, distances)[source]
_get_unique_matching_id(matching_ids, dataset_key, query)[source]

Get unique matching id from matching_ids, for a given dataset_key and some optional query.

_get_unique_reader_node_from_id(data_id, reader_name)[source]
_promote_query_to_modified_dataid(query, dep_key)[source]

Promote a query to an id based on the dataset it will modify (dep).

Typical use case is requesting a modified dataset (query). This modified dataset most likely depends on a less-modified dataset (dep_key). The less-modified dataset must come from a reader (at least for now) or will eventually depend on a reader dataset. The original request key may be limited like (wavelength=0.67, modifiers=(‘a’, ‘b’)) while the reader-based key should have all of its properties specified. This method updates the original request key so it is fully specified and should reduce the chance of Node’s not being unique.

copy()[source]

Copy this node tree.

Note all references to readers are removed. This is meant to avoid tree copies accessing readers that would return incompatible (Area) data. Theoretically it should be possible for tree copies to request compositor or modifier information as long as they don’t depend on any datasets not already existing in the dependency tree.

get_compositor(key)[source]

Get a compositor.

get_modifier(comp_id)[source]

Get a modifer.

populate_with_keys(dataset_keys: set, query=None)[source]

Populate the dependency tree.

Parameters:
  • dataset_keys (set) – Strings, DataIDs, DataQuerys to find dependencies for

  • query (DataQuery) – Additional filter parameters. See satpy.readers.get_key for more details.

Returns:

Root node of the dependency tree and a set of unknown datasets

Return type:

(Node, set)

update_compositors_and_modifiers(compositors: dict, modifiers: dict) None[source]

Add additional compositors and modifiers to the tree.

Provided dictionaries and the first sub-level dictionaries are copied to avoid modifying the input.

Parameters:
  • compositors (dict) – Sensor name -> composite ID -> Composite Object

  • modifiers (dict) – Sensor name -> Modifier name -> (Modifier Class, modifier options)

update_node_name(node, new_name)[source]

Update ‘name’ property of a node and any related metadata.

class satpy.dependency_tree.Tree[source]

Bases: object

A tree implementation.

Set up the tree.

add_child(parent, child)[source]

Add a child to the tree.

add_leaf(ds_id, parent=None)[source]

Add a leaf to the tree.

contains(item)[source]

Check contains when we know the exact DataID or DataQuery.

empty_node = <Node ('__EMPTY_LEAF_SENTINEL__')>
getitem(item)[source]

Get Node when we know the exact DataID or DataQuery.

leaves(limit_nodes_to: Iterable[DataID] | None = None, unique: bool = True) list[Node][source]

Get the leaves of the tree starting at the root.

Parameters:
  • limit_nodes_to – Limit leaves to Nodes with the names (DataIDs) specified.

  • unique – Only include individual leaf nodes once.

Returns:

list of leaf nodes

trunk(limit_nodes_to: Iterable[DataID] | None = None, unique: bool = True, limit_children_to: Container[DataID] | None = None) list[Node][source]

Get the trunk nodes of the tree starting at this root.

Parameters:
  • limit_nodes_to – Limit searching to trunk nodes with the names (DataIDs) specified and the children of these nodes.

  • unique – Only include individual trunk nodes once

  • limit_children_to – Limit searching to the children with the specified names. These child nodes will be included in the result, but not their children.

Returns:

list of trunk nodes

class satpy.dependency_tree._DataIDContainer[source]

Bases: dict

Special dictionary object that can handle dict operations based on dataset name, wavelength, or DataID.

Note: Internal dictionary keys are DataID objects.

get_key(match_key)[source]

Get multiple fully-specified keys that match the provided query.

Parameters:

match_key (DataID) – DataID or DataQuery of query parameters to use for searching. Can also be a string representing the dataset name or a number representing the dataset wavelength.

keys()[source]

Give currently contained keys.