src.cmip6 module¶
Code to parse CMIP6 controlled vocabularies and elements of the CMIP6 DRS.
Specifications for the above were taken from the planning document
http://goo.gl/v1drZl, which doesn’t seem to have a permanent link. The
CMIP6 controlled vocabularies (lists of registered MIPs, modeling centers, etc.)
are derived from data in the
PCMDI/cmip6-cmor-tables
repo, which is included as a subtree under /data.
Warning
Functionality here has been added as needed for the project and is incomplete, for example parsing subexperiments is not supported.
-
class
src.cmip6.CMIP6_CVs(*args, **kwargs)[source]¶ Bases:
src.util.basic.SingletonInterface for looking up information from the CMIP6 CV file.
Note
Lookups are implemented in an ad-hoc way with
util.MultiMap; a more robust solution would use sqlite.-
_make_cv()[source]¶ Populate the cv attribute of
CMIP6_CVswith the tables read in during __init__().Do this on-demand rather than in __init__, in case this information isn’t needed for this run of the framework.
-
is_in_cv(category, items)[source]¶ Determine if items take values that are valid for the CV category category.
- Parameters
- Returns: boolean or list of booleans, corresponding to the validity of
the entries in items.
-
get_lookup(source, dest)[source]¶ Find the appropriate lookup table to convert values in source (keys) to values in dest (values), generating it if necessary.
- Parameters
- Returns:
util.MultiMapproviding a dict-like lookup interface, ie dest_value = d[source_key].
-
lookup(source_items, source, dest)[source]¶ Lookup the corresponding dest values for source_items (keys).
- Parameters
Returns: list of dest values corresponding to each entry in source_items.
-
lookup_single(source_item, source, dest)[source]¶ The same as
lookup(), but perform lookup for a single source_item, and raise KeyError if the number of values returned is != 1.
-
table_id_from_freq(frequency)[source]¶ Specialized lookup to determine which MIP tables use data at the requested frequency.
Should really be handled as a special case of
lookup().- Parameters
frequency (
CMIP6DateFrequency) – DateFrequency
- Returns: list of MIP table
table_idnames, if any, that use data at the given frequency.
-
-
class
src.cmip6.CMIP6DateFrequency(quantity, unit=None)[source]¶ Bases:
src.util.datelabel.DateFrequencySubclass of
src.util.datelabel.DateFrequencyto parse data frequency information as encoded in MIP tables, DRS filenames, etc.Extends DateFrequency in that this records if the data is a climatological average, although this information is not currently used.
Reference: http://goo.gl/v1drZl page 16.
-
_precision_lookup= {'day': 3, 'fx': 0, 'hr': 5, 'min': 6, 'mo': 2, 'yr': 1}¶
-
_regex= re.compile('\n ^\n (?P<quantity>(1|3|6)?)\n (?P<unit>[a-z]*?)\n (?P<avg>(C|CM|Pt)?)\n $\n ', re.VERBOSE)¶
-
-
class
src.cmip6.CMIP6_VariantLabel(first_arg=None, *args, **kwargs)[source]¶ Bases:
objectDataclass which represents and parses the CMIP6 DRS variant label identifier string.
References: https://earthsystemcog.org/projects/wip/mip_table_about, although this doesn’t document all cases used in CMIP6. See also note 8 on page 9 of http://goo.gl/v1drZl.
-
_is_regex_dataclass= True¶
-
_pattern= {}¶
-
classmethod
from_string(str_, *args)¶
-
-
class
src.cmip6.CMIP6_MIPTable(first_arg=None, *args, **kwargs)[source]¶ Bases:
objectDataclass which represents and parses MIP table identifier string.
Reference: https://earthsystemcog.org/projects/wip/mip_table_about, although this doesn’t document all cases used in CMIP6.
-
table_freq: dataclasses.InitVar = ''¶
-
frequency: CMIP6DateFrequency¶
-
_is_regex_dataclass= True¶
-
_pattern= {}¶
-
classmethod
from_string(str_, *args)¶
-
-
class
src.cmip6.CMIP6_GridLabel(first_arg=None, *args, **kwargs)[source]¶ Bases:
objectDataclass which represents and parses the CMIP6 DRS grid label identifier string.
Reference: http://goo.gl/v1drZl, note 11 on page 11.
-
global_mean: dataclasses.InitVar = ''¶
-
zonal_mean: dataclasses.InitVar = ''¶
-
_is_regex_dataclass= True¶
-
_pattern= {}¶
-
classmethod
from_string(str_, *args)¶
-
-
class
src.cmip6.CMIP6_DRSDirectory(first_arg=None, *args, **kwargs)[source]¶ Bases:
src.cmip6.CMIP6_VariantLabel,src.cmip6.CMIP6_MIPTable,src.cmip6.CMIP6_GridLabelDataclass which represents and parses the DRS directory, using regex defined above.
Reference: http://goo.gl/v1drZl, page 17.
Warning
This regex will fail on paths involving subexperiments.
-
variant_label: src.cmip6.CMIP6_VariantLabel = ''¶
-
table_id: src.cmip6.CMIP6_MIPTable = ''¶
-
grid_label: src.cmip6.CMIP6_GridLabel = ''¶
-
version_date: src.util.datelabel.Date = None¶
-
_is_regex_dataclass= True¶
-
_pattern= {}¶
-
classmethod
from_string(str_, *args)¶
-
-
class
src.cmip6.CMIP6_DRSFilename(first_arg=None, *args, **kwargs)[source]¶ Bases:
src.cmip6.CMIP6_VariantLabel,src.cmip6.CMIP6_MIPTable,src.cmip6.CMIP6_GridLabelDataclass which represents and parses the DRS filename, using regex defined above.
Reference: http://goo.gl/v1drZl, page 14-15.
-
table_id: src.cmip6.CMIP6_MIPTable = ''¶
-
variant_label: src.cmip6.CMIP6_VariantLabel = ''¶
-
grid_label: src.cmip6.CMIP6_GridLabel = ''¶
-
start_date: src.util.datelabel.Date = None¶
-
end_date: src.util.datelabel.Date = None¶
-
date_range: util.DateRange¶
-
_is_regex_dataclass= True¶
-
_pattern= <src.util.dataclass.ChainedRegexPattern object>¶
-
classmethod
from_string(str_, *args)¶
-
-
class
src.cmip6.CMIP6_DRSPath(first_arg=None, *args, **kwargs)[source]¶ Bases:
src.cmip6.CMIP6_DRSDirectory,src.cmip6.CMIP6_DRSFilenameDataclass which represents and parses a full CMIP6 DRS path.
-
directory: src.cmip6.CMIP6_DRSDirectory = ''¶
-
_is_regex_dataclass= True¶
-
_pattern= {}¶
-
filename: src.cmip6.CMIP6_DRSFilename = ''¶
-
classmethod
from_string(str_, *args)¶
-