MetadataMapper#
- class dtcg.datacube.update_metadata.MetadataMapper(metadata_mapping_file_path=None)[source]#
Bases:
objectClass for applying CF-compliant metadata to xarray Datasets.
- Parameters:
metadata_mapping_file_path (str)
- METADATA_SCHEMA#
Validation schema for variable metadata.
- Type:
schema.Schema
- metadata_mappings#
Dictionary of metadata mappings loaded from a YAML file.
- Type:
dict
Attributes
Methods
__init__([metadata_mapping_file_path])Initialise MetadataMapper with a given or default mapping file.
Load and validate metadata mappings from a YAML file.
update_metadata(dataset, ds_name)Apply variable and shared metadata to an xarray Dataset.
- __init__(metadata_mapping_file_path=None)[source]#
Initialise MetadataMapper with a given or default mapping file.
- Parameters:
metadata_mapping_file_path (str, optional) – Path to the YAML file containing variable metadata mappings. If None, defaults to ‘metadata_mapping.yaml’ in the current directory.
self (MetadataMapper)
- read_metadata_mappings(
- metadata_mapping_file_path,
Load and validate metadata mappings from a YAML file.
- Parameters:
metadata_mapping_file_path (str) – Path to the YAML file containing metadata mappings.
self (MetadataMapper)
- Raises:
schema.SchemaError – If any of the metadata entries fail schema validation.
- Return type:
None
- update_metadata(dataset, ds_name)[source]#
Apply variable and shared metadata to an xarray Dataset.
- Parameters:
dataset (xarray.Dataset) – Dataset to which the metadata should be applied.
ds_name (str) – Name of dataset.
self (MetadataMapper)
- Returns:
The input dataset with updated metadata.
- Return type:
xarray.Dataset
- Warns:
UserWarning – If any dataset variables are missing in the metadata mapping.
Notes
This function adds both per-variable and global metadata attributes. Missing variable mappings are reported as warnings, not errors.
