cfmeta package

Submodules

cfmeta.cmip3file module

Module to process Cmip3 file based metadata

class cfmeta.cmip3file.Cmip3File(fp=None, **kwargs)

Bases: cfmeta.cmipfile.CmipFile

Represents a Cmip3File.

Parameters:
  • fp (Optional[str]) – A file path conforming to CMIP3 spec.
  • **kwargs – Keyworded metadata (overrides any meta obtained from path args)
dirname

Generates a standard CMOR file path from object attributes

fname

Generates a CMOR filename from object attributes.

fp
get_joined_file_name(atts, optional_atts=None)

Returns a joined path populated with the supplied attribute names

cfmeta.cmip3file.get_fname_meta(fp)

Processes a CMIP3 style file name.

Filename is of pattern:

<model>-<experiment>-<variable_name>-<ensemble_member>.nc
Parameters:fp (str) – A file path/name conforming to DRS spec.
Returns:Metadata as extracted from the filename.
Return type:dict
cfmeta.cmip3file.get_fp_meta(fp)

Processes a CMIP3 style file path.

The standard CMIP3 directory structure:

<experiment>/<variable_name>/<model>/<ensemble_member>/<CMOR filename>.nc

Filename is of pattern:

<model>-<experiment>-<variable_name>-<ensemble_member>.nc
Parameters:fp (str) – A file path conforming to CMIP3 spec.
Returns:Metadata as extracted from the file path.
Return type:dict

cfmeta.cmip5file module

Module to process Cmip5 file based metadata

class cfmeta.cmip5file.Cmip5File(cmor_fp=None, datanode_fp=None, cmor_fname=None, **kwargs)

Bases: cfmeta.cmipfile.CmipFile

Represents a Cmip5File.

Metadata is parsed based on interpreting the following documentation as best as possible:

Parameters:
  • cmor_fp (Optional[str]) – A file path conforming to DRS spec.
  • datanode_fp (Optional[str]) – A file path conforming to DRS spec.
  • cmor_fname (Optional[str]) – A file path conforming to DRS spec.
  • **kwargs – Keyworded metadata (overrides any meta obtained from path args)
cmor_dirname

Generates a CMOR directory path from object attributes

cmor_fname

Generates a CMOR filename from object attributes.

cmor_fp

Generates a CMOR file path from object attributes

datanode_dirname

Generates a datanode extended CMOR directory path from object attributes

datanode_fp

Generates a datanode extended CMOR file path from object attributes

cfmeta.cmip5file.get_cmor_fname_meta(fname)

Processes a CMOR style file name.

Section 3.3 of the Data Reference Syntax details:

filename = <variable name>_<mip_table>_<model>_<experiment>_
<ensemble_member>[_<temporal_subset>][_<geographical_info>].nc

Temporal subsets are detailed in section 2.4:

Time instants or periods will be represented by a construction of the form “N1-N2”, where N1 and N2 are of the form ‘yyyy[MM[dd[hh[mm[ss]]]]][-suffix]’, where ‘yyyy’, ‘MM’, ‘dd’, ‘hh’ ‘mm’ and ‘ss’ are integer year, month, day, hour, minute, and second, respectively, and the precision with which time is expressed must unambiguously resolve the interval between timesamples contained in the file or virtual file

Geographic subsets are also detailed in section 2.4:

The DRS specification for this indicator is a string of the form g-XXXX[-YYYY]. The “g-” indicates that some spatial selection or processing has been done (i.e., selection of a sub-global region and possibly spatial averaging).
Parameters:fname (str) – A file name conforming to DRS spec.
Returns:Metadata as extracted from the filename.
Return type:dict
cfmeta.cmip5file.get_cmor_fp_meta(fp)

Processes a CMOR style file path.

Section 3.1 of the Data Reference Syntax details:

The standard CMIP5 output tool CMOR optionally writes output files to a directory structure mapping DRS components to directory names as:

<activity>/<product>/<institute>/<model>/<experiment>/<frequency>/ <modeling_realm>/<variable_name>/<ensemble_member>/<CMOR filename>.nc
Parameters:fp (str) – A file path conforming to DRS spec.
Returns:Metadata as extracted from the file path.
Return type:dict
cfmeta.cmip5file.get_datanode_fp_meta(fp)

Processes a datanode style file path.

Section 3.2 of the Data Reference Syntax details:

It is recommended that ESGF data nodes should layout datasets on disk mapping DRS components to directories as:

<activity>/<product>/<institute>/<model>/<experiment>/ <frequency>/<modeling_realm>/<mip_table>/<ensemble_member>/ <version_number>/<variable_name>/<CMOR filename>.nc
Parameters:fp (str) – A file path conforming to DRS spec.
Returns:Metadata as extracted from the file path.
Return type:dict

cfmeta.cmipfile module

class cfmeta.cmipfile.CmipFile(nc=None, **kwargs)

Bases: object

Represents a CmipFile.

Provides common functionality for children.

Parameters:
  • nc_fp (Optional[str]) – A netCDF file path to pull attributes from internal metadata.
  • **kwargs – Keyworded metadata (overrides any meta obtained from path args)
atts
delete(*args)

Delete instance metadata by attribute name.

get_joined_dir_name(atts)

Returns a joined path populated with the supplied attribute names

get_joined_file_name(atts, optional_atts=None)

Returns a joined path populated with the supplied attribute names

set_timeval(index, value)
t_end
t_start
temporal_suffix
update(**kwargs)

Updates instance attributes with supplied keyword arguments.

If a supplied value is falsey, the attribute will be deleted.

Parameters:**kwargs (dict) – keyword arguments to update instance with
Raises:SyntaxWarning – If a supplied key is not recognized as valid metadata
cfmeta.cmipfile.get_nc_attrs(nc)

Gets netCDF file metadata attributes.

Parameters:nc (netCDF4.Dataset) – an open NetCDF4 Dataset to pull attributes from.
Returns:Metadata as extracted from the netCDF file.
Return type:dict
cfmeta.cmipfile.get_var_name(nc)

Guesses the variable_name of an open NetCDF file

cfmeta.exceptions module

Module with custom exceptions for cfmeta.

exception cfmeta.exceptions.PathError(path)

Bases: exceptions.Exception

cfmeta.path module

cfmeta.path.get_dir_meta(fp, atts)

Pop path information and map to supplied atts

Module contents

A Python package to interact with Climate model metadata.

The cfmeta - Climate Model Metadata Extractor package makes it easy to extract standard CMIP metadata from CMIP3/5 NetCDF filepaths and/or the metadata contained in the NetCDF file itself. Metadata can be manipulated with a simple interface, and CMIP3/5 compliant file paths generated from a metadata collection.