fre.cmor.cmor_finder module
fre cmor find
This module provides tools to find and print information about variables in CMIP6 JSON configuration files. It is primarily used for inspecting variable entries and generating variable lists for use in FRE CMORization workflows.
Functions
print_var_content(table_config_file, var_name)cmor_find_subtool(json_var_list, json_table_config_dir, opt_var_name)make_simple_varlist(dir_targ, output_variable_list, json_mip_table)
Notes
These utilities are intended to make it easier to inspect and extract variable information from CMIP6 JSON tables, avoiding the need for manual shell scripting and ad-hoc file inspection.
- fre.cmor.cmor_finder.cmor_find_subtool(json_var_list: str | None = None, json_table_config_dir: str | None = None, opt_var_name: str | None = None) None
Find and print information about variables in CMIP6 JSON configuration files in a specified directory.
- Parameters:
json_var_list (str or None, optional) – path to JSON file containing variable names to look up in tables.
json_table_config_dir (str) – Directory containing CMIP6 table JSON files.
opt_var_name (str or None, optional) – Name of a single variable to look up. If None, json_var_list must be provided.
- Raises:
OSError – If the specified directory does not exist or contains no JSON files.
ValueError – If neither opt_var_name nor json_var_list is provided.
- Returns:
None
- Return type:
None
Note
This function is intended as a helper tool for CLI users to quickly inspect variable definitions in CMIP6 tables. Information is printed via the logger.
- fre.cmor.cmor_finder.make_simple_varlist(dir_targ: str, output_variable_list: str | None, json_mip_table: str | None = None) Dict[str, str] | None
Generate a JSON file containing a list of variable names from NetCDF files in a specified directory. This function searches for NetCDF files in the given directory, or a subdirectory, “ts/monthly/5yr”, if not already included. It then extracts variable names from the filenames, and writes these variable names to a JSON file.
- Parameters:
dir_targ (str) – The target directory to search for NetCDF files.
output_variable_list (str) – The path to the output JSON file where the variable list will be saved.
json_mip_table (str) – target table for making the var list. found variables are included if they are in the table
- Raises:
OSError – if the outputfile cannot be written
- Returns:
Dictionary of variable names (keys == values), or None if no files are found or an error occurs
- Return type:
dict or None
Note
Assumes NetCDF filenames are of the form: <something>.<datetime>.<variable>.nc
Note
Variable name is assumed to be the second-to-last component when split by periods.
Note
Logs a warning if only one file is found.
Warning
Logs errors if no files are found in the directory or if no files match the expected pattern.
- fre.cmor.cmor_finder.print_var_content(table_config_file: IO[str], var_name: str) None
Print information about a specific variable from a given CMIP6 JSON configuration file.
- Parameters:
table_config_file (Input buffer/stream of text, usually output by the open() built-in. See python typing doc) – An open file object for a CMIP6 table JSON file. The file should be opened in text mode
var_name (str) – The name of the variable to look for in the configuration file.
- Raises:
Exception – If there is an issue reading the JSON content from the file.
- Returns:
None
- Return type:
None
Note
Outputs information to the logger at INFO level.
Note
If the variable is not found, logs a debug message and returns.
Note
Only prints selected fields, omitting any in DO_NOT_PRINT_LIST.