tsdat.config.variable_definition

Module Contents

Classes

VarKeys

Class that provides a handle for keys in the variables section of the

VarInputKeys

Class that provides a handle for keys in the variable input section of

ConverterKeys

Class that provides a handle for keys in the converter section of

VarInput

Class to explicitly encode fields set by the variable’s input source

VariableDefinition

Class to encode variable definitions from the config file. Also provides

class tsdat.config.variable_definition.VarKeys

Class that provides a handle for keys in the variables section of the pipeline config file.

INPUT = input
DIMS = dims
TYPE = type
ATTRS = attrs
class tsdat.config.variable_definition.VarInputKeys

Class that provides a handle for keys in the variable input section of the pipeline config file.

NAME = name
CONVERTER = converter
UNITS = units
REQUIRED = required
class tsdat.config.variable_definition.ConverterKeys

Class that provides a handle for keys in the converter section of the pipeline config file.

CLASSNAME = classname
PARAMETERS = parameters
class tsdat.config.variable_definition.VarInput(dictionary: Dict, defaults: Union[Dict, None] = None)

Class to explicitly encode fields set by the variable’s input source defined by the yaml file.

Parameters
  • dictionary (Dict) – The dictionary entry corresponding with a variable’s input section from the config file.

  • defaults (Dict, optional) – The default input parameters, defaults to {}

is_required(self)bool
class tsdat.config.variable_definition.VariableDefinition(name: str, dictionary: Dict, available_dimensions: Dict[str, tsdat.config.dimension_definition.DimensionDefinition], defaults: Union[Dict, None] = None)

Class to encode variable definitions from the config file. Also provides a few utility methods.

Parameters
  • name (str) – The name of the variable in the output file.

  • dictionary (Dict) – The dictionary entry corresponding with this variable in the config file.

:param

available_dimensions: A mapping of dimension name to DimensionDefinition objects.

Parameters

defaults (Dict, optional) – The defaults to use when instantiating this VariableDefinition object, defaults to {}.

_parse_input(self, dictionary: Dict, defaults: Union[Dict, None] = None)VarInput

Parses the variable’s input property, if it has one, from the variable dictionary.

Parameters
  • dictionary (Dict) – The dictionary entry corresponding with this variable in the config file.

  • defaults (Dict, optional) – The defaults to use when instantiating the VariableDefinition object, defaults to {}.

Returns

A VarInput object for this VariableDefinition, or None.

Return type

VarInput

_parse_attributes(self, dictionary: Dict, defaults: Union[Dict, None] = None)Dict[str, Any]

Parses the variable’s attributes from the variable dictionary.

Parameters
  • dictionary (Dict) – The dictionary entry corresponding with this variable in the config file.

  • defaults (Dict, optional) – The defaults to use when instantiating the VariableDefinition object, defaults to {}.

Returns

A mapping of attribute name to attribute value.

Return type

Dict[str, Any]

_parse_dimensions(self, dictionary: Dict, available_dimensions: Dict[str, tsdat.config.dimension_definition.DimensionDefinition], defaults: Union[Dict, None] = None)Dict[str, tsdat.config.dimension_definition.DimensionDefinition]

Parses the variable’s dimensions from the variable dictionary.

Parameters
  • dictionary (Dict) – The dictionary entry corresponding with this variable in the config file.

  • available_dimensions – A mapping of dimension name to DimensionDefinition.

  • defaults (Dict, optional) – The defaults to use when instantiating the VariableDefinition object, defaults to {}.

Returns

A mapping of dimension name to DimensionDefinition objects.

Return type

Dict[str, DimensionDefinition]

_parse_data_type(self, dictionary: Dict, defaults: Union[Dict, None] = None)object

Parses the data_type string and returns the appropriate numpy data type (i.e. “float” -> np.float).

Parameters
  • dictionary (Dict) – The dictionary entry corresponding with this variable in the config file.

  • defaults (Dict, optional) – The defaults to use when instantiating the VariableDefinition object, defaults to {}.

Raises

KeyError – Raises KeyError if the data type in the dictionary does not match a valid data type.

Returns

The numpy data type corresponding with the type provided in the yaml file, or data_type if the provided data_type is not in the ME Data Standards list of data types.

Return type

object

add_fillvalue_if_none(self, attributes: Dict[str, Any])Dict[str, Any]

Adds the _FillValue attribute to the provided attributes dictionary if the _FillValue attribute has not already been defined and returns the modified attributes dictionary.

Parameters

attributes (Dict[str, Any]) – The dictionary containing user-defined variable attributes.

Returns

The dictionary containing user-defined variable attributes. Is guaranteed to have a _FillValue attribute.

Return type

Dict[str, Any]

is_constant(self)bool

Returns True if the variable is a constant. A variable is constant if it does not have any dimensions.

Returns

True if the variable is constant, False otherwise.

Return type

bool

is_predefined(self)bool

Returns True if the variable’s data was predefined in the config yaml file.

Returns

True if the variable is predefined, False otherwise.

Return type

bool

is_coordinate(self)bool

Returns True if the variable is a coordinate variable. A variable is defined as a coordinate variable if it is dimensioned by itself.

Returns

True if the variable is a coordinate variable, False otherwise.

Return type

bool

is_derived(self)bool

Return True if the variable is derived. A variable is derived if it does not have an input and it is not predefined.

Returns

True if the Variable is derived, False otherwise.

Return type

bool

has_converter(self)bool

Returns True if the variable has an input converter defined, False otherwise.

Returns

True if the Variable has a converter defined, False otherwise.

Return type

bool

is_required(self)bool

Returns True if the variable has the ‘required’ property defined and the ‘required’ property evaluates to True. A required variable is a variable which much be retrieved in the input dataset. If a required variable is not in the input dataset, the process should crash.

Returns

True if the variable is required, False otherwise.

Return type

bool

has_input(self)bool

Return True if the variable is copied from an input dataset, regardless of whether or not unit and/or naming conversions should be applied.

Returns

True if the Variable has an input defined, False otherwise.

Return type

bool

get_input_name(self)str

Returns the name of the variable in the input if defined, otherwise returns None.

Returns

The name of the variable in the input, or None.

Return type

str

get_input_units(self)str

If the variable has input, returns the units of the input variable or the output units if no input units are defined.

Returns

The units of the input variable data.

Return type

str

get_output_units(self)str

Returns the units of the output data or None if no units attribute has been defined.

Returns

The units of the output variable data.

Return type

str

get_coordinate_names(self)List[str]

Returns the names of the coordinate VariableDefinition(s) that this VariableDefinition is dimensioned by.

Returns

A list of dimension/coordinate variable names.

Return type

List[str]

get_shape(self)Tuple[int]

Returns the shape of the data attribute on the VariableDefinition.

Raises

KeyError – Raises a KeyError if the data attribute has not been set yet.

Returns

The shape of the VariableDefinition’s data, or None.

Return type

Tuple[int]

get_data_type(self)numpy.dtype

Retrieves the variable’s data type.

Returns

Returns the data type of the variable’s data as a numpy dtype.

Return type

np.dtype

get_FillValue(self)int

Retrieves the variable’s _FillValue attribute, using -9999 as a default if it has not been defined.

Returns

Returns the variable’s _FillValue.

Return type

int

run_converter(self, data: numpy.ndarray)numpy.ndarray

If the variable has an input converter, runs the input converter for the input/output units on the provided data.

Parameters

data (np.ndarray) – The data to be converted.

Returns

Returns the data after it has been run through the variable’s converter.

Return type

np.ndarray

to_dict(self)Dict

Returns the Variable as a dictionary to be used to intialize an empty xarray Dataset or DataArray.

Returns a dictionary like (Example is for temperature):

{
    "dims": ["time"],
    "data": [],
    "attrs": {"units": "degC"}
}
Returns

A dictionary representation of the variable.

Return type

Dict