tsdat.config.variable_definition
¶
Classes¶
Class that provides a handle for keys in the converter section of |
|
Class to explicitly encode fields set by the variable’s input source |
|
Class that provides a handle for keys in the variable input section of |
|
Class that provides a handle for keys in the variables section of the |
|
Class to encode variable definitions from the config file. Also provides |
-
class
tsdat.config.variable_definition.
ConverterKeys
[source]¶ Class that provides a handle for keys in the converter section of the pipeline config file.
-
class
tsdat.config.variable_definition.
VarInput
(dictionary: Dict, defaults: Union[Dict, None] = None)[source]¶ 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 {}
Class Methods
Method Descriptions
-
class
tsdat.config.variable_definition.
VarInputKeys
[source]¶ Class that provides a handle for keys in the variable input section of the pipeline config file.
-
class
tsdat.config.variable_definition.
VarKeys
[source]¶ Class that provides a handle for keys in the variables section of the pipeline config file.
-
class
tsdat.config.variable_definition.
VariableDefinition
(name: str, dictionary: Dict, available_dimensions: Dict[str, tsdat.config.dimension_definition.DimensionDefinition], defaults: Union[Dict, None] = None)[source]¶ 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 {}.
Class Methods
Adds the _FillValue attribute to the provided attributes dictionary
Retrieves the variable’s _FillValue attribute, using -9999 as a
Returns the names of the coordinate VariableDefinition(s) that this
Retrieves the variable’s data type.
Returns the name of the variable in the input if defined, otherwise
If the variable has input, returns the units of the input variable
Returns the units of the output data or None if no units attribute has
Returns the shape of the data attribute on the VariableDefinition.
Returns True if the variable has an input converter defined, False
Return True if the variable is copied from an input dataset,
Returns True if the variable is a constant. A variable is constant
Returns True if the variable is a coordinate variable. A variable is
Return True if the variable is derived. A variable is derived if it
Returns True if the variable’s data was predefined in the config
Returns True if the variable has the ‘required’ property defined and
If the variable has an input converter, runs the input converter for
Returns the Variable as a dictionary to be used to intialize an
Method Descriptions
-
add_fillvalue_if_none
(self, attributes: Dict[str, Any]) → Dict[str, Any][source]¶ 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]
-
get_FillValue
(self) → int[source]¶ 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
-
get_coordinate_names
(self) → List[str][source]¶ 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_data_type
(self) → numpy.dtype[source]¶ 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_input_name
(self) → str[source]¶ 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[source]¶ 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[source]¶ 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_shape
(self) → Tuple[int][source]¶ 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]
-
has_converter
(self) → bool[source]¶ 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
-
has_input
(self) → bool[source]¶ 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
-
is_constant
(self) → bool[source]¶ 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_coordinate
(self) → bool[source]¶ 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[source]¶ 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
-
is_predefined
(self) → bool[source]¶ 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_required
(self) → bool[source]¶ 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
-
run_converter
(self, data: numpy.ndarray) → numpy.ndarray[source]¶ 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[source]¶ 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