libera_utils.io.product_definition.LiberaVariableDefinition#
- class libera_utils.io.product_definition.LiberaVariableDefinition(*, dtype: str, attributes: dict[str, ~typing.Any] = {}, dimensions: list[str] = [], encoding: dict = <factory>)#
Bases:
BaseModelPydantic model for a Libera variable definition.
This model is the same for both data variables and coordinate variables
- attributes#
The attribute metadata for the variable, containing specific key value pairs for CF metadata compliance
- Type:
VariableAttributes
- dimensions#
A list of dimensions that the variable’s data array references. These should be instances of LiberaDimension.
- Type:
list[LiberaDimension]
- encoding#
A dictionary specifying how the variable’s data should be encoded when written to a NetCDF file.
- Type:
- Attributes:
dynamic_attributesReturn attributes for a variable that are dynamically defined (null values) in the data product definition
model_extraGet extra fields set during validation.
model_fields_setReturns the set of fields that have been explicitly set on this model instance.
static_attributesReturn attributes for a variable that are statically defined (have values) in the data product definition
Methods
check_data_array_conformance(data_array, ...)Validate variable data array based on product definition.
copy(*[, include, exclude, update, deep])Returns a copy of the model.
create_conforming_data_array(data, variable_name)Create a DataArray for a single variable that is valid against the data product definition.
enforce_data_array_conformance(data_array, ...)Analyze and fix a DataArray to conform to variable specifications in data product definition
model_construct([_fields_set])Creates a new instance of the Model class with validated data.
model_copy(*[, update, deep])!!! abstract "Usage Documentation"
model_dump(*[, mode, include, exclude, ...])!!! abstract "Usage Documentation"
model_dump_json(*[, indent, ensure_ascii, ...])!!! abstract "Usage Documentation"
model_json_schema([by_alias, ref_template, ...])Generates a JSON schema for a model class.
model_parametrized_name(params)Compute the class name for parametrizations of generic classes.
model_post_init(context, /)Override this method to perform additional initialization after __init__ and model_construct.
model_rebuild(*[, force, raise_errors, ...])Try to rebuild the pydantic-core schema for the model.
model_validate(obj, *[, strict, extra, ...])Validate a pydantic model instance.
model_validate_json(json_data, *[, strict, ...])!!! abstract "Usage Documentation"
model_validate_strings(obj, *[, strict, ...])Validate the given object with string data against the Pydantic model.
construct
dict
from_orm
json
parse_file
parse_obj
parse_raw
schema
schema_json
update_forward_refs
validate
- __init__(**data: Any) None#
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Methods
check_data_array_conformance(data_array, ...)Validate variable data array based on product definition.
create_conforming_data_array(data, variable_name)Create a DataArray for a single variable that is valid against the data product definition.
enforce_data_array_conformance(data_array, ...)Analyze and fix a DataArray to conform to variable specifications in data product definition
Attributes
Return attributes for a variable that are dynamically defined (null values) in the data product definition
model_computed_fieldsConfiguration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Get extra fields set during validation.
model_fieldsReturns the set of fields that have been explicitly set on this model instance.
Return attributes for a variable that are statically defined (have values) in the data product definition
- _check_data_array_attributes(data_array_attrs: dict[str, Any], variable_name: str) list[str]#
Validate the variable level attributes of a DataArray against the product definition
Attributes must match exactly
- classmethod _set_encoding(encoding: dict | None)#
Merge configured encoding with required defaults, issuing warnings on conflicts.
- check_data_array_conformance(data_array: DataArray, variable_name: str) list[str]#
Validate variable data array based on product definition.
This does not verify that all required coordinate data exists on the DataArray. Dimensions lacking coordinates are treated as index dimensions. If coordinate data is later added to a Dataset under a dimension of the same name, the dimension will reference that coordinate data.
- create_conforming_data_array(data: ndarray, variable_name: str, user_variable_attributes: dict[str, Any] | None = None) DataArray#
Create a DataArray for a single variable that is valid against the data product definition.
Coordinate data is not required. Dimensions that reference coordinate dimensions are created as index dimensions. If coordinate data is added later (e.g. to a Dataset), these dimensions will reference the coordinates.
- Parameters:
data (np.ndarray) – Data for the variable DataArray.
variable_name (str) – Name of the variable. Used for log messages and warnings.
user_variable_attributes (dict[str, Any] | None) – Algorithm developers should not need to use this kwarg. Variable level attributes defined by the user. This allows a user to specify dynamic attributes that may be required by the definition but not statically defined in yaml.
- Returns:
A valid DataArray for the specified variable
- Return type:
DataArray
- property dynamic_attributes#
Return attributes for a variable that are dynamically defined (null values) in the data product definition
These attributes are _required_ but are expected to be defined externally to the data product definition
- enforce_data_array_conformance(data_array: DataArray, variable_name: str) tuple[DataArray, list[str]]#
Analyze and fix a DataArray to conform to variable specifications in data product definition
- Parameters:
data_array (DataArray) – The variable data array to analyze and update
variable_name (str) – Name of the variable being enforced (for logging)
- Returns:
Tuple of (updated DataArray, error_messages) where error_messages contains any problems that could not be fixed. Empty list if all problems were fixed.
- Return type:
- model_config: ClassVar[ConfigDict] = {'frozen': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- property model_extra: dict[str, Any] | None#
Get extra fields set during validation.
- Returns:
A dictionary of extra fields, or None if config.extra is not set to “allow”.
- property model_fields_set: set[str]#
Returns the set of fields that have been explicitly set on this model instance.
- Returns:
- A set of strings representing the fields that have been set,
i.e. that were not filled from defaults.
- property static_attributes#
Return attributes for a variable that are statically defined (have values) in the data product definition