pycmor.data_request package

Contents

pycmor.data_request package#

Submodules#

pycmor.data_request.collection module#

class pycmor.data_request.collection.CMIP6DataRequest(tables: Dict[str, CMIP6DataRequestTable], flattable_variables: bool = True, include_table_headers_in_variables: bool = True)[source]#

Bases: DataRequest

GIT_URL = 'https://github.com/PCMDI/cmip6-cmor-tables/'#

The URL of the CMIP6 data request repository.

Type:

str

_IGNORE_TABLE_FILES = ['CMIP6_CV_test.json', 'CMIP6_coordinate.json', 'CMIP6_CV.json', 'CMIP6_formula_terms.json', 'CMIP6_grids.json', 'CMIP6_input_example.json']#

Table files to ignore when reading from a directory.

Type:

List[str]

_registry = {}#
classmethod from_directory(directory: str) CMIP6DataRequest[source]#

Create a DataRequest from a directory of tables.

classmethod from_git(url: str = None, branch: str = 'main') CMIP6DataRequest[source]#

Create a DataRequest from a git repository.

classmethod from_tables(tables: Dict[str, DataRequestTable]) CMIP6DataRequest[source]#

Create a DataRequest from a dictionary of tables.

classmethod from_tables_dir(directory: str) CMIP6DataRequest[source]#

Deprecated since version Use: from_directory instead.

classmethod from_variables(variables: Dict[str, Dict[str, str]]) CMIP6DataRequest[source]#
class pycmor.data_request.collection.CMIP6IgnoreTableFiles(*values)[source]#

Bases: Enum

Table files to ignore when reading from a directory.

COORDINATE = 'CMIP6_coordinate.json'#
CV = 'CMIP6_CV.json'#
CV_TEST = 'CMIP6_CV_test.json'#
FORMULA_TERMS = 'CMIP6_formula_terms.json'#
GRIDS = 'CMIP6_grids.json'#
INPUT_EXAMPLE = 'CMIP6_input_example.json'#
classmethod values()[source]#
class pycmor.data_request.collection.CMIP7DataRequest(tables: Dict[str, DataRequestTable], variables: Dict[str, CMIP7DataRequestVariable] = None)[source]#

Bases: DataRequest

GIT_URL = 'https://github.com/CMIP-Data-Request/CMIP7_DReq_Software/'#

The URL of the CMIP7 data request repository.

Type:

str

_registry = {}#
classmethod from_all_var_info(data)[source]#
classmethod from_directory(directory: str) CMIP7DataRequest[source]#

Creates the CMIP7 data request from a directory

classmethod from_json_file(jfile: str) CMIP7DataRequest[source]#

Creates a CMIP7DataRequest instance from a single JSON file

classmethod from_tables(tables: Dict[str, DataRequestTable]) CMIP7DataRequest[source]#

Create a DataRequest from a dictionary of tables.

classmethod from_tables_dir(directory: str) CMIP7DataRequest[source]#

Deprecated since version Use: from_directory instead.

classmethod from_vendored_json()[source]#
class pycmor.data_request.collection.DataRequest[source]#

Bases: object

_registry = {'CMIP6': <class 'pycmor.data_request.collection.CMIP6DataRequest'>, 'CMIP7': <class 'pycmor.data_request.collection.CMIP7DataRequest'>}#
abstractmethod classmethod from_directory(directory: str) DataRequest[source]#

Create a DataRequest from a directory of tables.

abstractmethod classmethod from_git(url: str, branch: str = 'master') DataRequest[source]#

Create a DataRequest from a git repository.

abstractmethod classmethod from_tables(tables: Dict[str, DataRequestTable]) DataRequest[source]#

Create a DataRequest from a dictionary of tables.

abstractmethod classmethod from_tables_dir(directory: str) DataRequest[source]#

Create a DataRequest from a directory of tables.

Deprecated since version Use: from_directory instead.

pycmor.data_request.table module#

class pycmor.data_request.table.CMIP6DataRequestTable(header: CMIP6DataRequestTableHeader, variables: List[DataRequestVariable])[source]#

Bases: DataRequestTable

DataRequestTable for CMIP6.

_registry = {}#
classmethod from_dict(data: dict) CMIP6DataRequestTable[source]#

Create a DataRequestTable from a dictionary.

classmethod from_json_file(jfile) CMIP6DataRequestTable[source]#
get_variable(name: str, find_by='name') DataRequestVariable[source]#

Returns the first variable with the matching name.

Parameters:

name (str)

Return type:

DataRequestVariable

property header: CMIP6DataRequestTableHeader#

Header of the table.

classmethod table_dict_from_directory(path) dict[source]#

Create a dictionary of tables from a directory.

property table_name: str#

Name of the table.

property variables: List[str]#

List of variables in the table.

class pycmor.data_request.table.CMIP6DataRequestTableHeader(_table_id: str, _realm: List[str], _table_date: pendulum.date.Date, _approx_interval: float, _generic_levels: List[str], _data_specs_version: semver.version.Version = Version(major=1, minor=0, patch=33, prerelease=None, build=None), _cmor_version: semver.version.Version = Version(major=3, minor=5, patch=0, prerelease=None, build=None), _mip_era: str = 'CMIP6', _Conventions: str = 'CF-1.7 CMIP-6.2', _missing_value: float = 1e+20, _int_missing_value: int = -999, _product: str = 'model-output')[source]#

Bases: DataRequestTableHeader

property Conventions: str#
_Conventions: str = 'CF-1.7 CMIP-6.2'#
_HARD_CODED_DATA_SPECS_REPLACEMENTS = {'01.00.27': '1.0.27', '01.00.33': '1.0.33'}#
_approx_interval: float#
_cmor_version: Version = Version(major=3, minor=5, patch=0, prerelease=None, build=None)#
_data_specs_version: Version = Version(major=1, minor=0, patch=33, prerelease=None, build=None)#
_generic_levels: List[str]#
_int_missing_value: int = -999#
_mip_era: str = 'CMIP6'#
_missing_value: float = 1e+20#
_product: str = 'model-output'#
_realm: List[str]#
_registry = {'CMIP6JSONDataRequestTableHeader': <class 'pycmor.data_request.table.CMIP6JSONDataRequestTableHeader'>}#
_table_date: Date#
_table_id: str#
property approx_interval: float#

Approximate interval (time in days)

property cmor_version: Version#

CMOR version.

property data_specs_version: Version#

Data specifications version.

classmethod from_dict(data: dict) CMIP6DataRequestTableHeader[source]#

Create a DataRequestTableHeader from a dictionary.

property generic_levels: List[str]#

Generic levels

property int_missing_value: int#

Integer missing value

property mip_era: str#

MIP era

property missing_value: float#

Missing Value

property product: str#

Product

property realm: List[str]#

Realm of the table.

property table_date: Date#

Date of the table.

property table_id: str#

Name of the table.

class pycmor.data_request.table.CMIP6JSONDataRequestTableHeader(_table_id: str, _realm: List[str], _table_date: pendulum.date.Date, _approx_interval: float, _generic_levels: List[str], _data_specs_version: semver.version.Version = Version(major=1, minor=0, patch=33, prerelease=None, build=None), _cmor_version: semver.version.Version = Version(major=3, minor=5, patch=0, prerelease=None, build=None), _mip_era: str = 'CMIP6', _Conventions: str = 'CF-1.7 CMIP-6.2', _missing_value: float = 1e+20, _int_missing_value: int = -999, _product: str = 'model-output')[source]#

Bases: CMIP6DataRequestTableHeader

_approx_interval: float#
_generic_levels: List[str]#
_realm: List[str]#
_registry = {}#
_table_date: Date#
_table_id: str#
classmethod from_json_file(jfile) CMIP6JSONDataRequestTableHeader[source]#
class pycmor.data_request.table.CMIP7DataRequestTable(header: CMIP7DataRequestTableHeader, variables: List[DataRequestVariable])[source]#

Bases: DataRequestTable

DataRequestTable for CMIP7.

_registry = {}#
classmethod from_all_var_info(table_name: str, all_var_info: dict = None)[source]#
classmethod from_all_var_info_json(table_name: str) CMIP7DataRequestTable[source]#
classmethod from_dict(data: dict) CMIP7DataRequestTable[source]#

Create a DataRequestTable from a dictionary.

classmethod from_json_file(jfile) CMIP7DataRequestTable[source]#
get_variable(name: str, find_by='name') DataRequestVariable[source]#

Returns the first variable with the matching name.

Parameters:

name (str)

Return type:

DataRequestVariable

property header: CMIP7DataRequestTableHeader#

Header of the table.

classmethod table_dict_from_directory(path) dict[source]#

Create a dictionary of tables from a directory.

property table_id: str#

Alias for table_name.

property table_name: str#

Name of the table.

property variables: List[str]#

List of variables in the table.

class pycmor.data_request.table.CMIP7DataRequestTableHeader(_table_id: str, _realm: List[str], _approx_interval: float, _generic_levels: List[str], _data_specs_version: semver.version.Version = Version(major=1, minor=0, patch=0, prerelease=None, build=None), _cmor_version: semver.version.Version = Version(major=3, minor=5, patch=0, prerelease=None, build=None), _mip_era: str = 'CMIP7', _Conventions: str = 'CF-1.7 CMIP-7.0', _missing_value: float = 1e+20, _int_missing_value: int = -999, _product: str = 'model-output', _table_date: pendulum.date.Date = Date(2024, 11, 22))[source]#

Bases: DataRequestTableHeader

property Conventions: str#
_Conventions: str = 'CF-1.7 CMIP-7.0'#
_approx_interval: float#
static _approx_interval_from_frequency(frequency: str) float[source]#
_cmor_version: Version = Version(major=3, minor=5, patch=0, prerelease=None, build=None)#
_data_specs_version: Version = Version(major=1, minor=0, patch=0, prerelease=None, build=None)#
_generic_levels: List[str]#
_int_missing_value: int = -999#
_mip_era: str = 'CMIP7'#
_missing_value: float = 1e+20#
_product: str = 'model-output'#
_realm: List[str]#
_registry = {}#
_table_date: Date = Date(2024, 11, 22)#
_table_id: str#
property approx_interval: float#

Approximate interval (time in days)

property cmor_version: Version#

CMOR version.

property data_specs_version: Version#

Data specifications version.

classmethod from_all_var_info(table_name: str, all_var_info: dict = None) CMIP7DataRequestTableHeader[source]#
property generic_levels: List[str]#

Generic levels

property int_missing_value: int#

Integer missing value

property mip_era: str#

MIP era

property missing_value: float#

Missing Value

property product: str#

Product

property realm: List[str]#

Realm of the table.

property table_date: Date#

Date of the table.

property table_id: str#

Name of the table.

class pycmor.data_request.table.DataRequestTable[source]#

Bases: object

Abstract base class for a generic data request table.

_registry = {'CMIP6': <class 'pycmor.data_request.table.CMIP6DataRequestTable'>, 'CMIP7': <class 'pycmor.data_request.table.CMIP7DataRequestTable'>}#
abstractmethod classmethod from_dict(data: dict) DataRequestTable[source]#

Create a DataRequestTable from a dictionary.

abstractmethod get_variable(name: str) DataRequestVariable[source]#

Retrieve a variable’s details by name.

abstract property header: DataRequestTableHeader#

Header of the table.

abstractmethod classmethod table_dict_from_directory(path: str) dict[source]#

Create a dictionary of tables from a directory.

property table_id: str#

Alias for table_name.

abstract property table_name: str#

Name of the table.

abstract property variables: List[DataRequestVariable]#

List of variables in the table.

class pycmor.data_request.table.DataRequestTableHeader[source]#

Bases: object

abstract property Conventions: str#
_registry = {'CMIP6': <class 'pycmor.data_request.table.CMIP6DataRequestTableHeader'>, 'CMIP7': <class 'pycmor.data_request.table.CMIP7DataRequestTableHeader'>}#
abstract property approx_interval: float#

Approximate interval (time in days)

abstract property cmor_version: Version#

CMOR version.

abstract property data_specs_version: Version#

Data specifications version.

abstractmethod classmethod from_dict(data: dict) DataRequestTableHeader[source]#

Create a DataRequestTableHeader from a dictionary.

abstract property generic_levels: List[str]#

Generic levels

abstract property int_missing_value: int#

Integer missing value

abstract property mip_era: str#

MIP era

abstract property missing_value: float#

Missing Value

abstract property product: str#

Product

abstract property realm: str#

Realm of the table.

abstract property table_date: date#

Date of the table.

abstract property table_id: str#

Name of the table.

pycmor.data_request.variable module#

This module defines the DataRequestVariable abstract base class and its concrete implementation CMIP6DataRequestVariable.

The DataRequestVariable class outlines the necessary properties and methods that any variable class should implement. It includes properties such as frequency, modeling realm, standard name, units, cell methods, cell measures, long name, comment, dimensions, out name, type, positive direction, valid minimum and maximum values, acceptable minimum and maximum mean absolute values, and the table name.

The CMIP6DataRequestVariable class is a concrete implementation of the DataRequestVariable class, specifically for CMIP6 variables. It uses the dataclass decorator to automatically generate the __init__, __repr__, and other special methods.

The module also provides class methods for constructing DataRequestVariable instances from dictionaries and JSON files, as well as a method for converting a DataRequestVariable instance to a dictionary representation.

class pycmor.data_request.variable.CMIP6DataRequestVariable(_variable_id: str, _name: str, _frequency: str, _modeling_realm: str, _standard_name: str, _units: str, _cell_methods: str, _cell_measures: str, _long_name: str, _comment: str, _dimensions: tuple[str, ...], _out_name: str, _typ: type, _positive: str, _valid_min: float, _valid_max: float, _ok_min_mean_abs: float, _ok_max_mean_abs: float, _table_name: str | None = None)[source]#

Bases: DataRequestVariable

_cell_measures: str#
_cell_methods: str#
_comment: str#
_dimensions: tuple[str, ...]#
_frequency: str#
_long_name: str#
_modeling_realm: str#
_name: str#
_ok_max_mean_abs: float#
_ok_min_mean_abs: float#
_out_name: str#
_positive: str#
_registry = {'CMIP6JSONDataRequestVariable': <class 'pycmor.data_request.variable.CMIP6JSONDataRequestVariable'>}#
_standard_name: str#
_table_name: str | None = None#
_typ: type#
_units: str#
_valid_max: float#
_valid_min: float#
_variable_id: str#
property attrs: dict#

Attributes to update the Xarray DataArray with

property cell_measures: str#

What this cell measure

property cell_methods: str#

Methods applied to the cell

clone() CMIP6DataRequestVariable[source]#

Create a copy of this variable

property comment: str#

Comment for NetCDF attributes

property dimensions: tuple[str, ...]#

Dimensions of this variable

property frequency: str#

Frequency of this variable

classmethod from_dict(data: dict) CMIP6DataRequestVariable[source]#

Create a DataRequestVariable instance from a dictionary.

global_attrs(override_dict: dict = None) dict[source]#

Return a dictionary of global attributes for a CMIP6 variable

Parameters:

override_dict (dict) – A dictionary of attributes to override the default values

property long_name: str#

The CF long name for this variable

property modeling_realm: str#

Modeling Realm of this variable

property name: str#

Name of the variable

property ok_max_mean_abs: float#

ok maximum, mean, and absolute value

property ok_min_mean_abs: float#

ok minimum, mean, and absolute value

property out_name: str#

Short name (array name) of this variable

property positive: str#

For 3-D variables, which direction is up/down

property standard_name: str#

The CF standard name of the variable

property table_name: str | None#

The table this variable is define in

property typ: type#

int, float, str

Type:

The type of this array

property units: str#

The units of the variable

property valid_max: float#

Valid maximum

property valid_min: float#

Valid minimum

class pycmor.data_request.variable.CMIP6JSONDataRequestVariable(_variable_id: str, _name: str, _frequency: str, _modeling_realm: str, _standard_name: str, _units: str, _cell_methods: str, _cell_measures: str, _long_name: str, _comment: str, _dimensions: tuple[str, ...], _out_name: str, _typ: type, _positive: str, _valid_min: float, _valid_max: float, _ok_min_mean_abs: float, _ok_max_mean_abs: float, _table_name: str | None = None)[source]#

Bases: CMIP6DataRequestVariable

_cell_measures: str#
_cell_methods: str#
_comment: str#
_dimensions: tuple[str, ...]#
_frequency: str#
_long_name: str#
_modeling_realm: str#
_name: str#
_ok_max_mean_abs: float#
_ok_min_mean_abs: float#
_out_name: str#
_positive: str#
_registry = {}#
_standard_name: str#
_typ: type#
_units: str#
_valid_max: float#
_valid_min: float#
_variable_id: str#
classmethod from_json_file(jfile: str, varname: str) CMIP6DataRequestVariable[source]#

Create a DataRequestVariable instance from a JSON file.

class pycmor.data_request.variable.CMIP7DataRequestVariable(_frequency: str, _modeling_realm: str, _standard_name: str, _units: str, _cell_methods: str, _cell_measures: str, _long_name: str, _comment: str, _dimensions: tuple[str, ...], _out_name: str, _typ: type, _positive: str, _spatial_shape: str, _temporal_shape: str, _cmip6_cmor_table: str, _name: str, _table_name: str | None = None)[source]#

Bases: DataRequestVariable

_cell_measures: str#
_cell_methods: str#
_cmip6_cmor_table: str#
_comment: str#
_dimensions: tuple[str, ...]#
_frequency: str#
_long_name: str#
_modeling_realm: str#
_name: str#
_out_name: str#
_positive: str#
_registry = {}#
_spatial_shape: str#
_standard_name: str#
_table_name: str | None = None#
_temporal_shape: str#
_typ: type#
_units: str#
property attrs: dict#

Attributes to update the Xarray DataArray with

property cell_measures: str#

What this cell measure

property cell_methods: str#

Methods applied to the cell

clone() CMIP7DataRequestVariable[source]#

Create a copy of this variable

property comment: str#

Comment for NetCDF attributes

property dimensions: tuple[str, ...]#

Dimensions of this variable

property frequency: str#

Frequency of this variable

classmethod from_all_var_info_json(var_name: str, table_name: str)[source]#
classmethod from_dict(data)[source]#

Create a DataRequestVariable instance from a dictionary.

property global_attrs: dict#

Global attributes for this variable, used to set on the xr.Dataset

property long_name: str#

The CF long name for this variable

property modeling_realm: str#

Modeling Realm of this variable

property name: str#

Name of the variable

property ok_max_mean_abs: float#

ok maximum, mean, and absolute value

property ok_min_mean_abs: float#

ok minimum, mean, and absolute value

property out_name: str#

Short name (array name) of this variable

property positive: str#

For 3-D variables, which direction is up/down

property standard_name: str#

The CF standard name of the variable

property table_name: str | None#

The table this variable is define in

property typ: type#

int, float, str

Type:

The type of this array

property units: str#

The units of the variable

property valid_max: float#

Valid maximum

property valid_min: float#

Valid minimum

class pycmor.data_request.variable.DataRequestVariable[source]#

Bases: object

Abstract base class for a generic variable.

_registry = {'CMIP6': <class 'pycmor.data_request.variable.CMIP6DataRequestVariable'>, 'CMIP7': <class 'pycmor.data_request.variable.CMIP7DataRequestVariable'>}#
_type_strings = {'boolean': <class 'bool'>, 'char': <class 'str'>, 'character': <class 'str'>, 'double': <class 'float'>, 'float': <class 'float'>, 'int': <class 'int'>, 'integer': <class 'int'>, 'logical': <class 'bool'>, 'long': <class 'int'>, 'real': <class 'float'>, 'short': <class 'int'>, 'string': <class 'str'>}#

conversion of string names in the tables to actual Python types

Type:

dict

abstract property attrs: dict#

Attributes to update the Xarray DataArray with

abstract property cell_measures: str#

What this cell measure

abstract property cell_methods: str#

Methods applied to the cell

abstractmethod clone() DataRequestVariable[source]#

Create a copy of this variable

abstract property comment: str#

Comment for NetCDF attributes

abstract property dimensions: tuple[str, ...]#

Dimensions of this variable

abstract property frequency: str#

Frequency of this variable

classmethod from_dict(data: dict) DataRequestVariable[source]#

Create a DataRequestVariable instance from a dictionary.

classmethod from_json_file(jfile: str, varname: str) DataRequestVariable[source]#

Create a DataRequestVariable instance from a JSON file.

abstractmethod global_attrs(override_dict: dict = None) dict[source]#

Global attributes for this variable, used to set on the xr.Dataset

abstract property long_name: str#

The CF long name for this variable

abstract property modeling_realm: str#

Modeling Realm of this variable

abstract property name: str#

Name of the variable

abstract property ok_max_mean_abs: float#

ok maximum, mean, and absolute value

abstract property ok_min_mean_abs: float#

ok minimum, mean, and absolute value

abstract property out_name: str#

Short name (array name) of this variable

abstract property positive: str#

For 3-D variables, which direction is up/down

abstract property standard_name: str#

The CF standard name of the variable

abstract property table_name: str | None#

The table this variable is define in

to_dict() dict[source]#

Convert the variable to a dictionary representation

abstract property typ: type#

int, float, str

Type:

The type of this array

abstract property units: str#

The units of the variable

abstract property valid_max: float#

Valid maximum

abstract property valid_min: float#

Valid minimum

property variable_id: str#

Variable ID