fre.cmor.cmor_helpers module

file holding helper functions for the cmor_mixer in this submodule

fre.cmor.cmor_helpers.check_dataset_for_ocean_grid(ds)

checks netCDF4.Dataset ds for ocean grid origin, and throws an error if it finds one. accepts one argument. this function has no return.

ds: netCDF4.Dataset object containing variables with associated dimensional information.

fre.cmor.cmor_helpers.create_lev_bnds(bound_these=None, with_these=None)

creates a (2, len(bound_these)) shaped array with values assigned from with_these and returns that array

fre.cmor.cmor_helpers.create_tmp_dir(outdir, json_exp_config=None)

creates a tmp_dir based on targeted output directory root. returns the name of the tmp dir. accepts one argument:

outdir: string, representing the final output directory root for the cmor modules netcdf

file output. tmp_dir will be slightly different depending on the output directory targeted

fre.cmor.cmor_helpers.find_statics_file(bronx_file_path)

given a FRE-bronx-style file path, attempt to find the corresponding statics file based on the dir structure

fre.cmor.cmor_helpers.from_dis_gimme_dis(from_dis, gimme_dis)
gives you gimme_dis from from_dis. accepts two arguments, both mandatory.

from_dis: the target netCDF4.Dataset object to try reading from gimme_dis: what from_dis is hopefully gonna have and you’re gonna get

fre.cmor.cmor_helpers.get_iso_datetime_ranges(var_filenames, iso_daterange_arr=None, start=None, stop=None)
appends iso datetime strings found amongst filenames to iso_datetime_arr.
var_filenames: non-empty list of strings representing filenames. some of which presumably

contain ranges of datetimes as strings, hopefully like ????????-????????

iso_daterange_arr: list of strings, empty or non-empty, representing datetime ranges found in

var_filenames entries. the object pointed to by the reference iso_dateramge_arr is manipulated directly, and so need-not be returned.

start: string of four integers representing a year in any calendar. only YYYY format supported.

if the starting year of the data is before this, the datetime range is excluded from var_filenames

start: string of four integers representing a year in any calendar. only YYYY format supported.

fre.cmor.cmor_helpers.get_json_file_data(json_file_path=None)

returns loaded data from a json file pointed to by arg json_file_path (string, required)

fre.cmor.cmor_helpers.get_vertical_dimension(ds, target_var)

determines the vertical dimensionality of target_var within netCDF4 Dataset ds. accepts two arguments and returns an object representing the vertical dimensions assoc with the target_var.

ds: netCDF4.Dataset object containing variables with associated dimensional information. target_var: string, representing a variable contained within the netCDF4.Dataset ds

fre.cmor.cmor_helpers.print_data_minmax(ds_variable=None, desc=None)

outputs the the min/max of numpy.ma.core.MaskedArray (ds_variable) and the name/description (desc) of the data to the screen if there’s a verbose flag, and just to logger otherwise

fre.cmor.cmor_helpers.update_grid_and_label(json_file_path, new_grid_label, new_grid, new_nom_res, output_file_path=None)

Updates the “grid_label” and “grid” fields in a specified JSON file housing exp-specific configuration information req’d by CMOR for re-writing data compliantly

Args:

json_file_path (str): Path to the input JSON file. new_grid_label (str): New value for the “grid_label” field. new_grid (str): New value for the “grid” field. new_nom_res (str): New value for the “nominal_resolution” field output_file_path (str, optional): Path to save the updated JSON file. If None, overwrites the original file.

Raises:

FileNotFoundError: If the input JSON file does not exist. KeyError: If the “grid_label” or “grid” fields are not found in the JSON file. json.JSONDecodeError: If the JSON file cannot be decoded.