pywatershed.base.Process#

class pywatershed.base.Process(control, discretization, parameters, metadata_patches=None, metadata_patch_conflicts='error')[source]#

Base class for physical process representation.

The class aims to describe itself through its staticmethods and properties.

Conventions are adopted through the use of the following properties/methods:

inputs/get_inputs():

List the names of variables required from external sources. Still working on conventions if these are to be modified. For an input to be successfully inicluded, that variable must be defined in the metadata (pywatershed/static/metadata/variables.yaml). Efforts should be made to not use diagnostic variables as input as much as possible.

variables/get_variables():

List the names of internal public variables. If not necessary, to be public, variables should be made private with a single, leading underscore and not maintained in this list. For an input to be successfully inicluded, that variable must be defined in the metadata (pywatershed/static/metadata/variables.yaml). Efforts should be made not to track diagnostic variables in this public variable set, as much as possible.

parameters/get_parameters():

List the names of parameters used by the subclass.

description:

Return a dictionary of with the process subclass name and its metadata for all variables for each of inputs, variables, and parameters.

get_init_values:

Return a dictionary of initialization values for variables. Note that these may be overridden by subclass initialization routines (e.g. using parameters) or by restart values. So these are not “initial values”, they are initialization values that are set when the variable is declared from metadata in _initialize_var(). Initization values should be nan as much as possible.

_advance_variables():

This advance should exactly specify the prognostic variables in setting previous values to current values. When/if necessary to keep previous diagnostic variables, those must not appear here but in _calculate().

_calculate():

This method is to be overridden by the subclass. Near the end of the method, the subclass should calculate its changes in mass and energy storage in an obvious way. As commented for mass_budget_terms, storage changes should only be tracked for prognostic variables. (For example is snow_water_equiv = snow_ice + snow_liquid, then storage changes for snow_ice and snow_liquid should be tracked and not for snow_water_equiv).

Parameters:
  • control (Control) – A Control object

  • discretization (Parameters) – A discretization object

  • parameters (Parameters) – The parameters for this object

  • metadata_patches (Optional[dict[dict]]) – Override static metadata for any public parameter or variable – experimental.

  • metadata_patch_conflicts (Literal['ignore', 'warn', 'error']) – How to handle metadata_patches conflicts. Experimental.

__init__(control, discretization, parameters, metadata_patches=None, metadata_patch_conflicts='error')[source]#

Methods

__init__(control, discretization, parameters)

advance()

Advance the Process in time.

calculate(time_length, **kwargs)

Calculate Process terms for a time step

description()

A dictionary description of this Process.

finalize()

Finalizes the Process, including output methods.

get_dimensions()

Get a tuple of dimension names for this Process.

get_init_values()

Get a dictionary of initialization values for each public variable.

get_inputs()

Get a tuple of input variable names for this Process.

get_parameters()

Get a tuple of parameter names for this Process.

get_restart_variables()

Get a list of restart varible names.

get_variables()

Get a tuple of (public) variable names for this Process.

initialize_netcdf([output_dir, ...])

Initialize NetCDF output.

output()

Output data to previously initialized output types.

output_to_csv(pth)

Save each output variable to separate csv file in specified path

set_input_to_adapter(input_variable_name, ...)

Attributes

dimensions

A tuple of parameter names.

init_values

A dictionary of initial values for each public variable.

inputs

A tuple of input variable names.

parameters

A tuple of parameter names.

restart_variables

A tuple of restart variable names.

variables

A tuple of public variable names.

advance()[source]#

Advance the Process in time.

Returns:

None

calculate(time_length, **kwargs)[source]#

Calculate Process terms for a time step

Parameters:

simulation_time – current simulation time

Return type:

None

Returns:

None

classmethod description()[source]#

A dictionary description of this Process.

Return type:

dict

Returns:

All metadata for all variables in inputs, variables, and parameters.

property dimensions: tuple#

A tuple of parameter names.

finalize()[source]#

Finalizes the Process, including output methods. :rtype: None :returns: None

static get_dimensions()[source]#

Get a tuple of dimension names for this Process.

Return type:

tuple

static get_init_values()[source]#

Get a dictionary of initialization values for each public variable.

Return type:

dict

static get_inputs()[source]#

Get a tuple of input variable names for this Process.

Return type:

tuple

static get_parameters()[source]#

Get a tuple of parameter names for this Process.

Return type:

tuple

static get_restart_variables()[source]#

Get a list of restart varible names.

Return type:

list

classmethod get_variables()[source]#

Get a tuple of (public) variable names for this Process.

Return type:

tuple

property init_values: dict#

A dictionary of initial values for each public variable.

initialize_netcdf(output_dir=None, separate_files=None, output_vars=None)[source]#

Initialize NetCDF output.

Parameters:
  • output_dir – base directory path or NetCDF file path if separate_files is True

  • separate_files – boolean indicating if storage component output variables should be written to a separate file for each variable

  • output_vars – list of variable names to outuput.

Returns:

None

property inputs: tuple#

A tuple of input variable names.

output()[source]#

Output data to previously initialized output types. :rtype: None :returns: None

output_to_csv(pth)[source]#

Save each output variable to separate csv file in specified path

property parameters: tuple#

A tuple of parameter names.

property restart_variables: tuple#

A tuple of restart variable names.

set_input_to_adapter(input_variable_name, adapter)[source]#
property variables: tuple#

A tuple of public variable names.