Standardise - metadata#

These handle the assignment and standardisation of metadata and ensure the NetCDF created during standardisation has the correct attributes assigned to it.

openghg.standardise.meta.assign_attributes(data, site=None, network=None, sampling_period=None, update_metadata_mismatch=False, site_filename=None, species_filename=None)[source]#

Assign attributes to each site and species dataset. This ensures that the xarray Datasets produced are CF 1.7 compliant. Some of the attributes written to the Dataset are saved as metadata to the Datasource allowing more detailed searching of data.

If accessing underlying stored site or species definitions, this will be accessed from the openghg/supplementary_data repository by default.

Parameters:
  • data (Dict) – Dictionary containing data, metadata and attributes

  • site (Optional[str]) – Site code

  • sampling_period (Union[str, float, int, None]) – Number of seconds for which air sample is taken. Only for time variable attribute

  • network (Optional[str]) – Network name

  • update_metadata_mismatch (bool) – If current metadata does not match to attributes update metadata.

  • site_filename (Union[str, Path, None]) – Alternative site info file

  • species_filename (Union[str, Path, None]) – Alternative species info file

Returns:

Dictionary of combined data with correct attributes assigned to Datasets

Return type:

dict

openghg.standardise.meta.get_attributes(ds, species, site, network=None, global_attributes=None, units=None, scale=None, sampling_period=None, date_range=None, site_filename=None, species_filename=None)[source]#

This function writes attributes to an xarray.Dataset so that they conform with the CF Convention v1.6

Attributes of the xarray DataSet are modified, and variable names are changed

If accessing underlying stored site or species definitions, this will be accessed from the openghg/supplementary_data repository by default.

Variable naming related to species name will be defined using define_species_label() function.

Parameters:
  • ds (Dataset) – Should contain variables such as “ch4”, “ch4 repeatability”. Must have a “time” dimension.

  • species (str) – Species name. e.g. “CH4”, “HFC-134a”, “dCH4C13”

  • site (str) – Three-letter site code

  • network (Optional[str]) – Network site is associated with

  • global_attribuates – Dictionary containing any info you want to add to the file header (e.g. {“Contact”: “Contact_Name”})

  • units (Optional[str]) – This routine will try to guess the units unless this is specified. Options are in units_interpret

  • scale (Optional[str]) – Calibration scale for species.

  • sampling_period (Union[str, float, int, None]) – Number of seconds for which air sample is taken. Only for time variable attribute

  • date_range (Optional[List[str]]) – Start and end date for output If you only want an end date, just put a very early start date (e.g. [“1900-01-01”, “2010-01-01”])

  • site_filename (Union[str, Path, None]) – Alternative site info file

  • species_filename (Union[str, Path, None]) – Alternative species info file

Return type:

Dataset

openghg.standardise.meta.sync_surface_metadata(metadata, attributes, keys_to_add=None, update_mismatch=False)[source]#

Makes sure any duplicated keys between the metadata and attributes dictionaries match and that certain keys are present in the metadata.

Parameters:
  • metadata (Dict) – Dictionary of metadata

  • attributes (Dict) – Attributes

  • keys_to_add (Optional[List]) – Add these keys to the metadata, if not present, based on

  • Note (the attribute values.) – this skips any keys which can’t be

  • values. (copied from the attribute) –

  • update_mismatch (bool) – If case insensitive mismatch is found between an attribute and a metadata value, update the metadata to contain the attribute value. By default this will raise an AttrMismatchError.

Returns:

Copy of metadata updated with attributes

Return type:

dict