pywatershed.base.Process#
- class pywatershed.base.Process(control, discretization, parameters, input_aliases=None, metadata_patches=None, metadata_patch_conflicts='error', restart_read=False, restart_write=False, restart_write_freq=False)[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).
See also
- Parameters:
control (
Control) – A Control objectdiscretization (
Parameters) – A discretization objectparameters (
Parameters) – The parameters for this objectmetadata_patches (
dict[dict]) – Override static metadata for any public parameter or variable – experimental.metadata_patch_conflicts (
Literal['left','warn','error']) – How to handle metadata_patches conflicts. Experimental.restart_read (
Union[Path,bool]) – May be boolean or a Pathlib.Path. If False, control.options will be examined for this key. If True, the working directory is searched for restart files. If a Pathlib.Path, this specifies an alternative directory to search for restart files. Files searched for are of the pattern YYYY-mm-dd-varname.nc where the date is the control.init_time. The timestamp on the file is the valid time of the states in the file with the exception of processes with sub-daily timesteps. For example, the outflow_ts variable of PRMSChannel is instantaneous and valid at the 23rd hour of the timestampped day whereas its variable seg_outflow is the daily averge value over the timestampped day.restart_write (
Union[Path,bool]) – As for restart_read but for writing. The directory in either case will be attempted to be created if it does not exist.restart_write_freq (
Literal['y','m','d','f',False]) – If False, then control.options is examined for this key. The follwing values set the frequency of restart output with “y” for yearly, “m” for monthly, “d” for daily, or “f” for final. “Final” means that restart files are written with the states at control.end_time to files timestampped with control.end_time. Yearly and monthly restart options write files with timestamps on the last day of each year or month during the run. If daily, restarts are written every day. If restart_write is not False and restart_write_freq is False, the default of “f” is used.
- __init__(control, discretization, parameters, input_aliases=None, metadata_patches=None, metadata_patch_conflicts='error', restart_read=False, restart_write=False, restart_write_freq=False)[source]#
Methods
__init__(control, discretization, parameters)advance()Advance the Process in time.
calculate(time_length, **kwargs)Calculate Process terms for a time step
A dictionary description of this Process.
finalize()Finalize the Process, output methods, and close input adapters.
Get a tuple of dimension names for this Process.
Get a dictionary of initialization values for each public variable.
Get a tuple of input variable names for this Process.
Get a tuple of parameter names for this Process.
A list of restart varible names.
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, ...)Set input variables to adapter.current and manage the adapter.
Attributes
A tuple of parameter names.
A dictionary of initial values for each public variable.
A tuple of input variable names.
A tuple of parameter names.
previous.
A tuple of public variable names.
- calculate(time_length, **kwargs)[source]#
Calculate Process terms for a time step
- Parameters:
simulation_time – current simulation time
- Return type:
- Returns:
None
- classmethod description()[source]#
A dictionary description of this Process.
- Return type:
- Returns:
All metadata for all variables in inputs, variables, and parameters.
- finalize()[source]#
Finalize the Process, output methods, and close input adapters.
- Return type:
- Returns:
None
- static get_init_values()[source]#
Get a dictionary of initialization values for each public variable.
- Return type:
- classmethod get_variables()[source]#
Get a tuple of (public) variable names for this Process.
- Return type:
- initialize_netcdf(output_dir=None, separate_files=None, output_vars=None, extra_coords=None, addtl_output_vars=None, **kwargs)[source]#
Initialize NetCDF output.
- Parameters:
output_dir ([<class ‘str’>, <class ‘pathlib.Path’>]) – base directory path or NetCDF file path if separate_files is True
separate_files (
bool) – boolean indicating if storage component output variables should be written to a separate file for each variableoutput_vars (
list) – list of variable names to output.
- Return type:
- Returns:
None