pycmor package#

pycmor - Makes CMOR Simple

Subpackages#

Submodules#

pycmor._version module#

Git implementation of _version.py.

exception pycmor._version.NotThisMethod[source]#

Bases: Exception

Exception raised if a method is not valid for the current scenario.

class pycmor._version.VersioneerConfig[source]#

Bases: object

Container for Versioneer configuration parameters.

VCS: str#
parentdir_prefix: str#
style: str#
tag_prefix: str#
verbose: bool#
versionfile_source: str#
pycmor._version.get_config() VersioneerConfig[source]#

Create, populate and return the VersioneerConfig() object.

pycmor._version.get_keywords() Dict[str, str][source]#

Get the keywords needed to look up the version information.

pycmor._version.get_versions() Dict[str, Any][source]#

Get version information or return default if unable to do so.

pycmor._version.git_get_keywords(versionfile_abs: str) Dict[str, str][source]#

Extract version information from the given file.

pycmor._version.git_pieces_from_vcs(tag_prefix: str, root: str, verbose: bool, runner: ~typing.Callable = <function run_command>) Dict[str, Any][source]#

Get version from ‘git describe’ in the root of the source tree.

This only gets called if the git-archive ‘subst’ keywords were not expanded, and _version.py hasn’t already been rewritten with a short version string, meaning we’re inside a checked out source tree.

pycmor._version.git_versions_from_keywords(keywords: Dict[str, str], tag_prefix: str, verbose: bool) Dict[str, Any][source]#

Get version information from git keywords.

pycmor._version.pep440_split_post(ver: str) Tuple[str, int | None][source]#

Split pep440 version string at the post-release segment.

Returns the release segments before the post-release and the post-release version number (or -1 if no post-release segment is present).

pycmor._version.plus_or_dot(pieces: Dict[str, Any]) str[source]#

Return a + if we don’t already have one, else return a .

pycmor._version.register_vcs_handler(vcs: str, method: str) Callable[source]#

Create decorator to mark a method as the handler of a VCS.

pycmor._version.render(pieces: Dict[str, Any], style: str) Dict[str, Any][source]#

Render the given version pieces into the requested style.

pycmor._version.render_git_describe(pieces: Dict[str, Any]) str[source]#

TAG[-DISTANCE-gHEX][-dirty].

Like ‘git describe –tags –dirty –always’.

Exceptions: 1: no tags. HEX[-dirty] (note: no ‘g’ prefix)

pycmor._version.render_git_describe_long(pieces: Dict[str, Any]) str[source]#

TAG-DISTANCE-gHEX[-dirty].

Like ‘git describe –tags –dirty –always -long’. The distance/hash is unconditional.

Exceptions: 1: no tags. HEX[-dirty] (note: no ‘g’ prefix)

pycmor._version.render_pep440(pieces: Dict[str, Any]) str[source]#

Build up version string, with post-release “local version identifier”.

Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you get a tagged build and then dirty it, you’ll get TAG+0.gHEX.dirty

Exceptions: 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]

pycmor._version.render_pep440_branch(pieces: Dict[str, Any]) str[source]#

TAG[[.dev0]+DISTANCE.gHEX[.dirty]] .

The “.dev0” means not master branch. Note that .dev0 sorts backwards (a feature branch will appear “older” than the master branch).

Exceptions: 1: no tags. 0[.dev0]+untagged.DISTANCE.gHEX[.dirty]

pycmor._version.render_pep440_old(pieces: Dict[str, Any]) str[source]#

TAG[.postDISTANCE[.dev0]] .

The “.dev0” means dirty.

Exceptions: 1: no tags. 0.postDISTANCE[.dev0]

pycmor._version.render_pep440_post(pieces: Dict[str, Any]) str[source]#

TAG[.postDISTANCE[.dev0]+gHEX] .

The “.dev0” means dirty. Note that .dev0 sorts backwards (a dirty tree will appear “older” than the corresponding clean one), but you shouldn’t be releasing software with -dirty anyways.

Exceptions: 1: no tags. 0.postDISTANCE[.dev0]

pycmor._version.render_pep440_post_branch(pieces: Dict[str, Any]) str[source]#

TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] .

The “.dev0” means not master branch.

Exceptions: 1: no tags. 0.postDISTANCE[.dev0]+gHEX[.dirty]

pycmor._version.render_pep440_pre(pieces: Dict[str, Any]) str[source]#

TAG[.postN.devDISTANCE] – No -dirty.

Exceptions: 1: no tags. 0.post0.devDISTANCE

pycmor._version.run_command(commands: List[str], args: List[str], cwd: str | None = None, verbose: bool = False, hide_stderr: bool = False, env: Dict[str, str] | None = None) Tuple[str | None, int | None][source]#

Call the given command(s).

pycmor._version.versions_from_parentdir(parentdir_prefix: str, root: str, verbose: bool) Dict[str, Any][source]#

Try to determine the version from the parent directory name.

Source tarballs conventionally unpack into a directory that includes both the project name and a version string. We will also support searching up two directory levels for an appropriately named parent directory

pycmor.cli module#

pycmor.cli.MAX_FRAMES = 3#

The maximum number of frames to show in the traceback if there is an error. Default to 3

Type:

str

pycmor.cli.find_subcommands()[source]#

Finds CLI Subcommands for installed plugins in both legacy and new groups.

pycmor.cli.main()[source]#
pycmor.cli.pymor_cli_group(func)[source]#

Decorator to add the click_loguru logging options to a click group

pycmor.webapp module#

Web Viewer for CMIP6 Data Tables#

We provide a Streamlit web application that provides an interface for interacting with CMIP6 (Coupled Model Intercomparison Project Phase 6) data tables.

Launch it from the command line with:

$ pycmor table-explorer
api/images/table-explorer.png

The application allows users to load these tables from three different sources: GitHub, a local directory, or directly from the user’s laptop. The tables are JSON files containing metadata about climate model outputs.

The main features of the application are:

  1. Table Source Selection: Users can select the source of the tables. The options are ‘github’, ‘Local’, and ‘Laptop’. Depending on the selection, the user can provide a URL (for GitHub), a directory path (for Local), or upload files (for Laptop).

  2. Table Processing: The application processes each table, extracting key information such as table ID, frequency, and variable entries. Tables that do not contain variable entries or frequency are added to an ignore list.

  3. Variable Selection and Display: Users can select a variable from the processed tables. The application then displays all tables and frequencies where this variable is found, along with additional information such as the time method (Instantaneous, Climatology, or Mean).

  4. Metrics Display: The application displays metrics about the processed tables, including the number of tables, frequencies, and variables.

  5. Ignored Tables: The application provides an expander to view all ignored tables.

The application uses multithreading to load and process tables from GitHub, improving performance when dealing with a large number of tables.

This module contains several functions:

  • `process_table(tbl_name: str, data: dict)`: Processes a single table,

    extracting key information and updating global data structures.

  • `show_selected_variable(varname)`: Displays information about

    the selected variable.

  • `load_data_from_github(f, ctx)`: Loads a single table from GitHub.

The application uses several global data structures to store information about the tables and variables, including tbls, tbl_raw_data, var_to_tbl, frequencies, tids, and ignored_table_files.

pycmor.webapp.process_table(tbl_name: str, data: dict)[source]#
pycmor.webapp.show_selected_variable(varname)[source]#