MetadataMapper#
- class dtcg.datacube.update_metadata.MetadataMapper(
- metadata_mapping_data='',
- metadata_mapping_coords='',
Bases:
objectClass for applying CF-compliant metadata to xarray Datasets.
- Parameters:
metadata_mapping_data (str)
metadata_mapping_coords (str)
- METADATA_SCHEMA_DATA#
Validation schema for data variable metadata.
- Type:
schema.Schema
- METADATA_SCHEMA_COORDS#
Validation schema for coordinates metadata.
- Type:
schema.Schema
- metadata_mappings_data#
Dictionary of metadata mappings for data variables loaded from a YAML file.
- Type:
dict
- metadata_mappings_coords#
Dictionary of metadata mappings for coordinates loaded from a YAML file.
- Type:
dict
Attributes
Methods
__init__([metadata_mapping_data, ...])Initialise MetadataMapper with a given or default mapping file.
read_metadata_mappings(schema, map_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_data='',
- metadata_mapping_coords='',
Initialise MetadataMapper with a given or default mapping file.
- Parameters:
metadata_mapping_data (str, optional) – Path to the YAML file containing variable metadata mappings. If empty, defaults to ‘metadata_mapping_data.yaml’ provided by the
dtcgpackage.metadata_mapping_coords (str, optional) – Path to the YAML file containing variable metadata mappings. If empty, defaults to ‘metadata_mapping_coords.yaml’ provided by the
dtcgpackage.self (MetadataMapper)
- read_metadata_mappings(schema, map_file)[source]#
Load and validate metadata mappings from a YAML file.
- Parameters:
schema (Schema) – The schema structure used for validation
map_file (str) – Path to the YAML file containing metadata mappings.
self (MetadataMapper)
- Returns:
Metadata mappings loaded from YAML file.
- Return type:
dict
- Raises:
schema.SchemaError – If any of the metadata entries fail schema validation.
- 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.
