libera_utils.io.netcdf#
Classes
|
Pydantic model for a Libera data product configuration. |
|
Pydantic model for file specific metadata. |
|
Pydantic model for file specific spatial and temporal metadata |
|
Pydantic model for file specifics geolocation metadata. |
|
Pydantic model for any dimension used for Libera data |
|
Pydantic model for a Libera variable. |
|
Pydantic model for file-level metadata. |
|
Pydantic model for unchanging NetCDF-4 file metadata. |
|
Pydantic model for variable-level metadata for NetCDF-4 files. |
- class libera_utils.io.netcdf.DataProductConfig(*, data_product_id: ~libera_utils.aws.constants.DataProductIdentifier, static_project_metadata: ~libera_utils.io.netcdf.StaticProjectMetadata = <factory>, version: str, variable_configuration_path: ~pathlib.Path | None = None, variables: dict[str, ~libera_utils.io.netcdf.LiberaVariable] | None = None, product_metadata: ~libera_utils.io.netcdf.ProductMetadata | None = None)#
Pydantic model for a Libera data product configuration.
- data_product_id#
The identifier for the data product, which is used to generate the filename.
- Type:
- static_project_metadata#
The static metadata associated with the Libera project, loaded automatically.
- Type:
- version#
The version number of the data product in X.Y.Z format, where X is the major version, Y is the minor version, and Z is the patch version.
- Type:
- variable_configuration_path#
The path to the variable configuration file, which can be used to load variable metadata.
- Type:
Path | None
- variables#
A dictionary of variable names and their corresponding LiberaVariable objects, which contain metadata and data.
- Type:
dict[str, LiberaVariable] | None
- product_metadata#
The metadata associated with the data product, including dynamic metadata and spatio-temporal metadata.
- Type:
ProductMetadata | None
Notes
This is the primary object used to configure and write properly formatted NetCDF4 files that can be archived with the Libera SDC. It includes methods for loading variable metadata, validating the configuration, and writing the data product to a file.
- Attributes:
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
add_data_to_variable
(variable_name, ...)Adds the actual data to an existing LiberaVariable
A wrapper around the load_data_product_variables_with_metadata method.
copy
(*[, include, exclude, update, deep])Returns a copy of the model.
enforce_version_format
(version_string)Enforces the proper formatting of the version string as M.m.p.
ensure_data_product_id
(raw_data_product_id)Converts raw data product id string to DataProductIdentifier class if necessary.
from_data_config_file
(product_config_filepath)Primary means of making a data product config all at once
get_static_project_metadata
([file_path])Loads the static project metadata field of the object from a file
Method to create a properly made LiberaVariables from a config file.
If a model is instantiated with a configuration path listed then populate the variables from that file
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.
Optional validator method that allows the user to specify a path to the variable configuration file.
construct
dict
from_orm
json
parse_file
parse_obj
parse_raw
schema
schema_json
update_forward_refs
validate
- _format_version_for_filename()#
Internal method for ensuring version string is proper for file output
- Returns:
A formatted version string suitable for use in filenames, with dots replaced by dashes and prefixed with “V”.
- Return type:
Notes
This method replaces the dots in the version string with dashes and prepends a “V” to it.
- _generate_data_product_filename(utc_start_time: datetime, utc_end_time: datetime, revision: datetime | None = None) LiberaDataProductFilename #
Generate a valid data product filename using the Filenaming methods
- Parameters:
utc_start_time (datetime) – The start time of the data product, used to generate the filename.
utc_end_time (datetime) – The end time of the data product, used to generate the filename.
revision (datetime | None) – The revision date of the data product, used to generate the filename. If None, the current UTC time is used.
- Returns:
An instance of LiberaDataProductFilename representing the generated filename for the data product.
- Return type:
Notes
This method generates a filename for the data product based on its ID, version, start and end times, and revision date. It uses the LiberaDataProductFilename class to create the filename.
- add_data_to_variable(variable_name: str, variable_data: ndarray | DataArray)#
Adds the actual data to an existing LiberaVariable
- Parameters:
variable_name (str) – The name of the variable to which the data will be added.
variable_data (np.ndarray | DataArray) – The data to be added to the variable. It can be a numpy ndarray or an xarray DataArray.
- Raises:
KeyError – If the variable name does not exist in the configuration.
TypeError – If the variable data is not of type np.ndarray or DataArray.
ValueError – If the variable data does not match the expected dimensions defined in the variable’s metadata.
Notes
This method takes the name of a variable and the data to be added to that variable. It checks if the variable exists in the configuration and then sets the data for that variable.
- add_variable_metadata_from_file(variable_config_file_path)#
A wrapper around the load_data_product_variables_with_metadata method.
- Parameters:
variable_config_file_path (str | Path) – The path to the configuration file containing variable metadata.
- Raises:
ValueError – If the provided file path does not point to a valid JSON or YAML file.
Notes
This allows the model to be validated after the variables have been added.
- classmethod enforce_version_format(version_string: str)#
Enforces the proper formatting of the version string as M.m.p.
- Parameters:
version_string (str) – The version string to be validated, expected to be in the format M.m.p.
- Returns:
The validated version string in the format M.m.p.
- Return type:
- Raises:
Notes
This method checks if the version string is formatted as M.m.p, where M, m, and p are integers. If the version string does not match this format, it raises a ValueError.
- classmethod ensure_data_product_id(raw_data_product_id: str | DataProductIdentifier) DataProductIdentifier #
Converts raw data product id string to DataProductIdentifier class if necessary.
- Parameters:
raw_data_product_id (str | DataProductIdentifier) – The raw data product ID, which can be a string or an instance of DataProductIdentifier.
- Returns:
An instance of DataProductIdentifier representing the data product ID.
- Return type:
Notes
This method checks if the provided data product ID is already an instance of DataProductIdentifier. If it is, it returns it as is. If it is a string, it converts it to a DataProductIdentifier instance.
- classmethod from_data_config_file(product_config_filepath: str | AnyPath)#
Primary means of making a data product config all at once
- Parameters:
product_config_filepath (str | AnyPath) – The path to the configuration file containing the product metadata and variable definitions.
- Returns:
An instance of DataProductConfig with the loaded data product ID, version, and variables.
- Return type:
Notes
This method reads a configuration file (in YAML format) that contains the static product metadata, version, and variable metadata. It then creates an instance of DataProductConfig with the loaded data.
- classmethod get_static_project_metadata(file_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/lasp-libera-sdc-libera-utils/checkouts/latest/libera_utils/data/static_project_metadata.yml'))#
Loads the static project metadata field of the object from a file
- Parameters:
file_path (Path) – The path to the corresponding yml file.
- Returns:
An instance of StaticProjectMetadata containing the static metadata for the Libera project.
- Return type:
- classmethod load_data_product_variables_with_metadata(file_path: str | Path)#
Method to create a properly made LiberaVariables from a config file.
- Parameters:
file_path (str | Path) – The path to the configuration file containing variable metadata.
- Returns:
A dictionary where the keys are variable names and the values are LiberaVariable objects
- Return type:
Notes
This method is used as part of validator if a filepath is passed in to construct the Data ProductConfig object. It reads a JSON or YAML file containing variable metadata, and returns a dictionary of LiberaVariable objects with their metadata.
- load_variables_from_config()#
If a model is instantiated with a configuration path listed then populate the variables from that file
- Returns:
The instance of DataProductConfig with the variables loaded from the configuration file, if applicable.
- Return type:
Notes
This method is called after the model is validated. It checks if the variable_configuration_path is not None and if the variables are None. If so, it calls the add_variable_metadata_from_file method to load the variable metadata from the specified file. This allows the model to be validated after the variables have been added.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- classmethod use_variable_configuration(variable_configuration_path: str | Path)#
Optional validator method that allows the user to specify a path to the variable configuration file.
- Parameters:
variable_configuration_path (str | Path | None) – The path to the variable configuration file. It can be a string, a Path object, or None.
- Returns:
A Path object representing the variable configuration path, or None if no path is provided.
- Return type:
Path | None
Notes
This method checks if the provided variable configuration path is None or a string. If it is a string, it converts it to a Path object. If the path is None, it returns None.
- class libera_utils.io.netcdf.DynamicProductMetadata(*, GranuleID: str, input_files: list[str])#
Pydantic model for file specific metadata.
- Attributes:
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.
construct
dict
from_orm
json
parse_file
parse_obj
parse_raw
schema
schema_json
update_forward_refs
validate
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class libera_utils.io.netcdf.DynamicSpatioTemporalMetadata(*, ProductionDateTime: datetime, RangeBeginningDate: datetime, RangeBeginningTime: datetime, RangeEndingDate: datetime, RangeEndingTime: datetime, GPolygon: list[GPolygon])#
Pydantic model for file specific spatial and temporal metadata
- Attributes:
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.
construct
dict
from_orm
json
parse_file
parse_obj
parse_raw
schema
schema_json
update_forward_refs
validate
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class libera_utils.io.netcdf.GPolygon(*, latitude: Annotated[float, Ge(ge=-90), Le(le=90)], longitude: Annotated[float, Ge(ge=-180), Le(le=180)])#
Pydantic model for file specifics geolocation metadata.
- Attributes:
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.
construct
dict
from_orm
json
parse_file
parse_obj
parse_raw
schema
schema_json
update_forward_refs
validate
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class libera_utils.io.netcdf.LiberaDimension(*, name: str, size: int, long_name: str, is_set: bool = True)#
Pydantic model for any dimension used for Libera data
- name#
The name of the dimension, which should match the names defined in the available dimensions.
- Type:
- size#
The size of the dimension. If it is dynamic, it should be set to “dynamic”. If it is a fixed size, it should be an integer representing the size. If it is not set, it can be None.
- long_name#
A long name for the dimension, providing a human-readable description of what the dimension represents.
- Type:
Notes
This class defines the needed aspects of a Libera Dimension and also contains the list of known and defined dimensions that are available to be used.
- Attributes:
- is_dynamic_size
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.
get_available_dimensions_dict
([file_path])Loads the available dimensions for variables on the Libera project.
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, /)This function is meant to behave like a BaseModel method to initialise private attributes.
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.
Ensure that the dynamic size and set status are properly set after initialization.
construct
dict
from_orm
json
parse_file
parse_obj
parse_raw
schema
schema_json
update_forward_refs
validate
- static get_available_dimensions_dict(file_path: AnyPath | None = None)#
Loads the available dimensions for variables on the Libera project.
- Parameters:
file_path (Path) – The path to the corresponding yml file.
Notes
These are the only available dimensions to be used with official Libera variables.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- validate_dynamic_size_and_is_set()#
Ensure that the dynamic size and set status are properly set after initialization.
- Returns:
The instance of LiberaDimension with the dynamic size and set status updated.
- Return type:
Notes
This method is called after the model is validated. It sets the _is_dynamic and is_set attributes correctly based on the size of the dimension. If the size is -1, called DYNAMIC_SIZE, it indicates a dynamic size, and is_set is set to False.
- class libera_utils.io.netcdf.LiberaVariable(*, metadata: VariableMetadata, variable_encoding: dict | None = {'_FillValue': None, 'complevel': 4, 'zlib': True}, data: DataArray | None = None)#
Pydantic model for a Libera variable.
- metadata#
The metadata associated with the variable, including its dimensions, valid range, missing value, units, and data type.
- Type:
- variable_encoding#
A dictionary specifying how the variable’s data should be encoded when written to a NetCDF file.
- Type:
dict | None
- data#
The data associated with the variable, stored as an xarray DataArray
- Type:
DataArray | None
- Attributes:
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
Ensure the dimensions in provided data are correct on instantiation.
copy
(*[, include, exclude, update, deep])Returns a copy of the model.
copy_incoming_metadata
(input_metadata)Ensure that the metadata is copied in as a VariableMetadata object
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_data
(data)Takes the provided data into an internal DataArray with Libera defined dimensions
set_data_as_dataarray
(input_data)Ensure that the data is internally stored as a DataArray when passed in to the model.
construct
dict
from_orm
json
parse_file
parse_obj
parse_raw
schema
schema_json
update_forward_refs
validate
- _check_for_bad_dimensions(data_array: DataArray | ndarray)#
Internal method to check provided data set has dimension that match the shape expected in the metadata.
- Parameters:
data_array (DataArray | np.ndarray) – The data array whose shape will be checked against the metadata dimensions.
- Raises:
ValueError – If the provided data array does not match the expected dimensions in the metadata.
Notes
This will ignore any “dynamic” data dimensions. If the provided data does not match the expected dimensions in the metadata, it raises a ValueError.
- _set_all_dynamic_dimension_lengths(data_array: DataArray | ndarray) None #
Internal method to set any dynamic dimension lengths to match a given array
- Parameters:
data_array (DataArray | np.ndarray) – The data array whose shape will be used to set the dynamic dimensions in the metadata.
Notes
This should be run after the _check_for_bad_dimensions below. This method iterates through the dimensions of the metadata and sets the size of any dynamic dimensions to the corresponding size in the provided data array.
- _set_data_with_dimensions_to_match_metadata(data_array: DataArray | ndarray)#
Internal method to ensure the dimensions from the metadata are used in the data itself
- Parameters:
data_array (DataArray | np.ndarray) – The data array to be set for the variable. It can be a DataArray or a numpy ndarray.
- Raises:
TypeError – If the provided data is not of type DataArray or np.ndarray.
ValueError – If the provided data does not match the expected dimensions in the metadata.
Notes
This method checks the provided data array against the metadata dimensions and sets the data to a new DataArray with the correct dimensions. It also checks for bad dimensions and sets any dynamic dimension lengths.
- confirm_and_set_data_with_dimensions()#
Ensure the dimensions in provided data are correct on instantiation.
- Returns:
The instance of LiberaVariable with the data set if it was provided.
- Return type:
Notes
This method is called after the model is validated. It checks if the data is not None and sets the data using the set_data method. If the data is None, it does nothing.
- classmethod copy_incoming_metadata(input_metadata: VariableMetadata)#
Ensure that the metadata is copied in as a VariableMetadata object
- Parameters:
input_metadata (VariableMetadata) – The metadata to be copied into the variable.
- Returns:
A deep copy of the input metadata.
- Return type:
- Raises:
TypeError – If the input metadata is not of type VariableMetadata.
Notes
This method validates that the input metadata is of type VariableMetadata and returns a deep copy of it.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- set_data(data: DataArray | ndarray)#
Takes the provided data into an internal DataArray with Libera defined dimensions
- Parameters:
data (DataArray | np.ndarray) – The data to be set for the variable. It can be a DataArray or a numpy ndarray.
- Raises:
TypeError – If the provided data is not of type DataArray or np.ndarray.
ValueError – If the provided data does not match the expected dimensions in the metadata.
Notes
This method is used to set the data for the variable. It checks if the data is a DataArray or a numpy ndarray, and if so, it sets the data while ensuring that the dimensions match those defined in the metadata.
- classmethod set_data_as_dataarray(input_data: DataArray | ndarray | None)#
Ensure that the data is internally stored as a DataArray when passed in to the model.
- Parameters:
input_data (DataArray | np.ndarray | None) – The data to be set for the variable. It can be a DataArray, a numpy ndarray, or None.
- Returns:
A DataArray containing the input data, or None if the input data is None.
- Return type:
DataArray | None
- Raises:
TypeError – If the input data is not of type DataArray or np.ndarray.
Notes
This method checks if the input data is None, a numpy ndarray, or an xarray DataArray. If it is None, it returns None. If it is a numpy ndarray, it converts it to a DataArray. If it is already a DataArray, it returns it as is. If the input data is of any other type, it raises a TypeError.
- class libera_utils.io.netcdf.ProductMetadata(*, dynamic_metadata: DynamicProductMetadata | None, dynamic_spatio_temporal_metadata: DynamicSpatioTemporalMetadata | None)#
Pydantic model for file-level metadata.
- Attributes:
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.
construct
dict
from_orm
json
parse_file
parse_obj
parse_raw
schema
schema_json
update_forward_refs
validate
Notes
This data will change between files and is obtained from the science Dataset. The create_file_metadata method makes this object.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class libera_utils.io.netcdf.StaticProjectMetadata(*, Format: str, Conventions: str, ProjectLongName: str, ProjectShortName: str, PlatformLongName: str, PlatformShortName: str)#
Pydantic model for unchanging NetCDF-4 file metadata.
Notes
See more details at https://wiki.earthdata.nasa.gov/display/CMR/UMM-C+Schema+Representation
- Attributes:
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.
construct
dict
from_orm
json
parse_file
parse_obj
parse_raw
schema
schema_json
update_forward_refs
validate
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- 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)#
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
- 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].
- 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.