src.netcdf_helper module

class src.netcdf_helper.NetcdfHelper[source]

Bases: object

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

classmethod nc_check_environ()[source]
classmethod nc_cat_chunks(chunk_list, out_file=None, cwd=None, dry_run=False)[source]
classmethod nc_crop_time_axis(time_var_name, date_range, in_file=None, out_file=None, cwd=None, dry_run=False)[source]
classmethod nc_extract_level()[source]
classmethod ncdump_h(in_file=None, cwd=None, dry_run=False)[source]
classmethod nc_get_attribute(attr_name, in_file=None, cwd=None, dry_run=False)[source]

Return dict of variables and values of a given attribute.

If the attribute is not defined for the variable (or is the empty string), it’s not included in the returned dict.

classmethod nc_get_axes_attributes(var, in_file=None, cwd=None, dry_run=False)[source]

Return variable names corresponding to an axis attribute.

src.netcdf_helper._nco_outfile_decorator(function)[source]

Wrapper handling cleanup for NCO operations that modify files. NB must come between classmethod and base function definition. See https://stackoverflow.com/a/18732038.

class src.netcdf_helper.NcoNetcdfHelper[source]

Bases: src.netcdf_helper.NetcdfHelper

static _run_command(command, env=None, cwd=None, timeout=0, dry_run=False)

Subprocess wrapper to facilitate running single command without starting a shell.

Note

We hope to save some process overhead by not running the command in a shell, but this means the command can’t use piping, quoting, environment variables, or filename globbing etc.

See documentation for the Python2 subprocess module.

Parameters
  • command (list of str) – List of commands to execute

  • env (dict, optional) – environment variables to set, passed to Popen, default None.

  • cwd (str, optional) – child processes’ working directory, passed to Popen. Default is None, which uses parent processes’ directory.

  • timeout (int, optional) – Optionally, kill the command’s subprocess and raise a CalledProcessError if the command doesn’t finish in timeout seconds.

Returns

list of str containing output that was written to stdout by each command. Note: this is split on newlines after the fact.

Raises

CalledProcessError – If any commands return with nonzero exit code. Stderr for that command is stored in output attribute.

classmethod nc_check_environ()[source]
classmethod nc_cat_chunks(chunk_list, out_file=None, cwd=None, dry_run=False)[source]
classmethod nc_crop_time_axis(*args, **kwargs)[source]
classmethod ncdump_h(in_file=None, cwd=None, dry_run=False)[source]

Return header information for all variables in a file.

classmethod nc_change_variable_units(*args, **kwargs)[source]
classmethod nc_dump_axis(ax_name, in_file=None, cwd=None, dry_run=False)[source]
class src.netcdf_helper.CdoNetcdfHelper[source]

Bases: src.netcdf_helper.NetcdfHelper