pywatershed.PRMSAtmosphere#

class pywatershed.PRMSAtmosphere(control, discretization, parameters, prcp, tmax, tmin, soltab_potsw, soltab_horad_potsw, input_aliases=None, verbose=False, restart_read=False, restart_write=False, restart_write_freq=False)[source]#

PRMS atmospheric boundary layer model.

Implementation based on PRMS 5.2.1 with theoretical documentation given in the PRMS-IV documentation:

Markstrom, S. L., Regan, R. S., Hay, L. E., Viger, R. J., Webb, R. M., Payn, R. A., & LaFontaine, J. H. (2015). PRMS-IV, the precipitation-runoff modeling system, version 4. US Geological Survey Techniques and Methods, 6, B7.

This representation uses precipitation and temperature inputs. Relative humidity could be added as well.

The boundary layer calculates and manages the following variables (given by PRMSAtmosphere.get_variables()):

  • tmaxf, tminf, prmx, hru_ppt, hru_rain, hru_snow, swrad, potet, transp_on

PRMS adjustments to temperature and precipitation are applied here to the inputs. Shortwave radiation (using degree day method) and potential evapotranspiration (Jensen and Haise ,1963) and a temperature based transpiration flag (transp_on) are also calculated.

Note that all variables are calculated for all time upon the first advance and that all calculated variables are written to NetCDF (when netcdf output is requested) the first time output is requested. This is effectively a complete preprocessing of the input CBH files to the fields the model actually uses on initialization. For an example of preprocessing the variables in PRMSAtmosphere, see this notebook.

The full time version of a variable is given by the “private” version of the variable which is named with a single-leading underscore (eg tmaxf for all time is _tmaxf).

This full-time initialization may not be tractable for large domains and/or long periods of time and require changes to batch the processing of the variables. The benefits of full-time initialization are 1) the code is vectorized and fast for such a large calculation, 2) the initialization of this class effectively preprocess all the inputs to the rest of the model and can then be skipped in subsequent model calls (unless the parameters are changing).

Parameters:
  • control (Control) – a Control object

  • discretization (Parameters) – a discretization of class Parameters

  • parameters (Parameters) – a parameter object of class Parameters

  • prcp (Union[str, Path]) – daily precipitation

  • tmax (Union[str, Path]) – daily maximum temperature

  • tmin (Union[str, Path]) – daily minimum temperature

  • soltab_potsw (Union[str, Path, ndarray, Adapter, PrmsDynamicParameter]) – the solar table of potential shortwave radiation

  • soltab_horad_potsw (Union[str, Path, ndarray, Adapter, PrmsDynamicParameter]) – the solar table of potential shortwave radiation on a horizontal plane

  • verbose (bool) – Print extra information or not?

  • 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', 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, prcp, tmax, tmin, soltab_potsw, soltab_horad_potsw, input_aliases=None, verbose=False, restart_read=False, restart_write=False, restart_write_freq=False)[source]#

Methods

__init__(control, discretization, ...[, ...])

adjust_precip()

Input precipitation adjustments using calibrated parameters.

adjust_temperature()

Input temperature adjustments using calibrated parameters.

advance()

Advance the Process in time.

calc_transp_tindex()

calculate(time_length, **kwargs)

Calculate Process terms for a time step

calculate_potential_et_jh()

Calculate potential evapotranspiration following Jensen and Haise

calculate_sw_rad_degree_day()

Calculate shortwave radiation using the degree day method.

description()

A dictionary description of this Process.

finalize()

Finalize the Process, output methods, and close input adapters.

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()

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, ...)

Set input variables to adapter.current and manage the adapter.

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

previous.

variables

A tuple of public variable names.

adjust_precip()[source]#

Input precipitation adjustments using calibrated parameters.

Snow/rain partitioning of total precip depends on adjusted temperature in addition to depending on additonal parameters.

Returns:

None

adjust_temperature()[source]#

Input temperature adjustments using calibrated parameters.

advance()#

Advance the Process in time.

Returns:

None

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

Calculate Process terms for a time step

Parameters:

simulation_time – current simulation time

Return type:

None

Returns:

None

calculate_potential_et_jh()[source]#

Calculate potential evapotranspiration following Jensen and Haise

Jensen and Haise (1963)

Return type:

None

Returns:

None

calculate_sw_rad_degree_day()[source]#

Calculate shortwave radiation using the degree day method.

Return type:

None

Returns:

None

classmethod description()#

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()#

Finalize the Process, output methods, and close input adapters.

Return type:

None

Returns:

None

static get_dimensions()[source]#

Get a tuple of dimension names for this Process.

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.

static get_restart_variables()[source]#

A list of restart varible names.

Return type:

list

classmethod get_variables()#

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, **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 variable

  • output_vars (list) – list of variable names to output.

Returns:

None

property inputs: tuple#

A tuple of input variable names.

output()[source]#

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

output_to_csv(pth)#

Save each output variable to separate csv file in specified path

property parameters: tuple#

A tuple of parameter names.

property restart_variables: dict#

previous.

Type:

A dict of restart variable names mapping current

set_input_to_adapter(input_variable_name, adapter)#

Set input variables to adapter.current and manage the adapter.

TODO: make this private?

Parameters:
  • input_variable_name (str) – key of input variable

  • adapter (Adapter) – the Adapter for the input.

property variables: tuple#

A tuple of public variable names.