libera_utils.io.netcdf.VariableMetadata#
- class libera_utils.io.netcdf.VariableMetadata(*, long_name: str, dimensions: dict[str, LiberaDimension], valid_range: list, missing_value: int | float, units: str | None, dtype: str | None)#
Bases:
BaseModel
Pydantic model for variable-level metadata for NetCDF-4 files.
- available_dimensions#
A class variable listing all available dimensions that can be used in the variable metadata.
- Type:
ClassVar[list[LiberaDimension]]
- long_name#
A long name for the variable, providing a human-readable description of what the variable represents.
- Type:
- dimensions#
A list of dimensions that the variable’s data array will have. These should be instances of LiberaDimension.
- Type:
- valid_range#
A list specifying the valid range of values for the variable’s data, excluding missing values.
- Type:
- missing_value#
The value used to represent missing data in the variable’s data array. This should be the same type as the data.
- units#
The units of the variable’s data, if applicable. This can be None if the variable does not have units.
- Type:
str | None
- dtype#
The data type of the variable’s data, if applicable. This can be None if the variable does not have a specific data type.
- Type:
str | None
Notes
These derive from the CF conventions. More information at: https://cfconventions.org/cf-conventions/cf-conventions.html
- Attributes:
dimensions_name_list
A computed property tuple of the string names of the dimensions
dimensions_shape
A tuple of the shape of the dimensions for this variable
model_extra
Get extra fields set during validation.
model_fields_set
Returns the set of fields that have been explicitly set on this model instance.
Methods
copy
(*[, include, exclude, update, deep])Returns a copy of the model.
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, include, ...])!!! 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, ...])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.
set_dimensions
(input_dimensions)Class method validating the list of input dimensions when they are provided.
set_dynamic_dimension
(selected_dimension, ...)Internal method to set a dynamic dimension length
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
set_dimensions
(input_dimensions)Class method validating the list of input dimensions when they are provided.
set_dynamic_dimension
(selected_dimension, ...)Internal method to set a dynamic dimension length
Attributes
A computed property tuple of the string names of the dimensions
A tuple of the shape of the dimensions for this variable
model_computed_fields
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Get extra fields set during validation.
model_fields
Returns the set of fields that have been explicitly set on this model instance.
- property dimensions_name_list: tuple#
A computed property tuple of the string names of the dimensions
- Returns:
A tuple of dimension names as strings.
- Return type:
Notes
This property returns a tuple of the names of the dimensions in the order they are defined in the metadata.
- property dimensions_shape: tuple#
A tuple of the shape of the dimensions for this variable
- Returns:
A tuple of dimension sizes, where dynamic dimensions are represented as “dynamic”.
- Return type:
Notes
This property returns a tuple of the sizes of the dimensions in the order they are defined in the metadata.
- model_config: ClassVar[ConfigDict] = {}#
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.
- classmethod set_dimensions(input_dimensions: list[str] | list[LiberaDimension])#
Class method validating the list of input dimensions when they are provided.
- Parameters:
input_dimensions (list[str] | list[LiberaDimension]) – A list of dimension names as strings or LiberaDimension instances.
- Returns:
A list of LiberaDimension instances corresponding to the input dimensions.
- Return type:
- Raises:
TypeError – If the input dimensions are not a list or if the items in the list are not of type str or LiberaDimension.
Notes
This method ensures that the dimensions are either strings that match the available dimensions or instances of the LiberaDimension class. It converts string dimensions to LiberaDimension instances.
- set_dynamic_dimension(selected_dimension: LiberaDimension, data_length: int)#
Internal method to set a dynamic dimension length
- Parameters:
selected_dimension (LiberaDimension) – The dimension that has a dynamic dimension to be set.
data_length (int) – The length of the dimension that will replace the dynamic size.
- Raises:
ValueError – If the selected dimension is not dynamic or if the size is already set.
Notes
This method is used to set the size of a dimension that has been defined as dynamic in the metadata.