Skip to content

Commit

Permalink
reactor: StorageUnit renamed to Process, before going to Conservative…
Browse files Browse the repository at this point in the history
…Process subclass Process is conservative
  • Loading branch information
jmccreight committed Jun 22, 2023
1 parent 935b6d7 commit c42808e
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 44 deletions.
2 changes: 1 addition & 1 deletion pywatershed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .base.control import Control
from .base.model import Model
from .base.parameters import Parameters
from .base.storage_unit import StorageUnit
from .base.process import Process
from .base.timeseries import TimeseriesArray
from .hydrology.PRMSCanopy import PRMSCanopy
from .hydrology.PRMSChannel import PRMSChannel
Expand Down
8 changes: 4 additions & 4 deletions pywatershed/analysis/process_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from ..base import meta
from ..base.model import Model
from ..base.storage_unit import StorageUnit
from ..base.process import Process
from ..utils.optional_import import import_optional_dependency


Expand Down Expand Up @@ -51,7 +51,7 @@ def __init__(

return

def plot(self, var_name: str, process: StorageUnit, cmap: str = None):
def plot(self, var_name: str, process: Process, cmap: str = None):
var_dims = list(meta.get_vars(var_name)[var_name]["dims"])
if "nsegment" in var_dims:
if not cmap:
Expand All @@ -62,7 +62,7 @@ def plot(self, var_name: str, process: StorageUnit, cmap: str = None):
else:
raise ValueError()

def plot_seg_var(self, var_name: str, process: StorageUnit, cmap="cool"):
def plot_seg_var(self, var_name: str, process: Process, cmap="cool"):
ccrs = import_optional_dependency("cartopy.crs")

data_df = pd.DataFrame(
Expand Down Expand Up @@ -158,7 +158,7 @@ def get_hru_var(self, var_name: str, model: Model):
def plot_hru_var(
self,
var_name: str,
process: StorageUnit,
process: Process,
data: np.ndarray = None,
data_units: str = None,
nhm_id: np.ndarray = None,
Expand Down
4 changes: 2 additions & 2 deletions pywatershed/atmosphere/PRMSAtmosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np

from pywatershed.base.storage_unit import StorageUnit
from pywatershed.base.process import Process
from pywatershed.utils.netcdf_utils import NetCdfWrite

from ..base.adapter import adaptable
Expand All @@ -23,7 +23,7 @@ def tile_time_to_space(arr: np.ndarray, n_space) -> np.ndarray:
return np.transpose(np.tile(arr, (n_space, 1)))


class PRMSAtmosphere(StorageUnit):
class PRMSAtmosphere(Process):
"""PRMS atmospheric boundary layer model.
Implementation based on PRMS 5.2.1 with theoretical documentation based on
Expand Down
7 changes: 3 additions & 4 deletions pywatershed/atmosphere/PRMSSolarGeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import numpy as np

# would like to not subclass storageUnit but it is much simpler to do so
from pywatershed.base.storage_unit import StorageUnit
from pywatershed.base.process import Process
from pywatershed.utils.netcdf_utils import NetCdfWrite

from ..base.control import Control
Expand Down Expand Up @@ -36,7 +35,7 @@ def tile_space_to_time(arr: np.ndarray) -> np.ndarray:
# return np.transpose(np.tile(arr, (n_hru, 1)))


class PRMSSolarGeometry(StorageUnit):
class PRMSSolarGeometry(Process):
"""PRMS solar geometry."""

def __init__(
Expand All @@ -56,7 +55,7 @@ def __init__(
self._set_budget(budget_type)
self.netcdf_output_dir = netcdf_output_dir

# self._time is needed by storageUnit for timeseries arrays
# self._time is needed by Process for timeseries arrays
# TODO: this is redundant because the parameter doy is set
# on load of prms file. Could pass the name to use for
# self._time to super or come up with some other work around.
Expand Down
2 changes: 1 addition & 1 deletion pywatershed/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
from .control import Control
from .model import Model
from .parameters import Parameters
from .storage_unit import StorageUnit
from .process import Process
from .timeseries import TimeseriesArray
18 changes: 9 additions & 9 deletions pywatershed/base/storage_unit.py → pywatershed/base/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from .control import Control


class StorageUnit(Accessor):
"""StorageUnit base class
class Process(Accessor):
"""Process base class
The StorageUnit is a base class for conserving mass and energy.
Process is a base class for physical processes.
It has budgets that can optionally be established for mass an energy and
these can be enforced or simply diagnosed with the model run.
Expand All @@ -32,8 +32,8 @@ class StorageUnit(Accessor):
inputs/get_inputs():
List the names of variables required from external sources.
Still working on conventions if these are to be modified but
the storageUnit. For an input to be successfully inicluded,
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
Expand Down Expand Up @@ -100,7 +100,7 @@ def __init__(
metadata_patches: dict[dict] = None,
metadata_patch_conflicts: Literal["ignore", "warn", "error"] = "error",
):
self.name = "StorageUnit"
self.name = "Process"
self.control = control

missing_params = set(self.parameters).difference(
Expand Down Expand Up @@ -152,7 +152,7 @@ def output(self) -> None:
return

def finalize(self) -> None:
"""Finalize storageUnit
"""Finalize Process
Finalizes the object, including output methods.
Expand Down Expand Up @@ -381,7 +381,7 @@ def set_input_to_adapter(self, input_variable_name: str, adapter: Adapter):

# Using a pointer between boxes means that the same pointer has to
# be used for the budget, so there's no way to have a preestablished
# pointer between storageUnit and its budget. So this stuff...
# pointer between Process and its budget. So this stuff...
if self.budget is not None:
for comp in self.budget.components:
if input_variable_name in self.budget[comp].keys():
Expand Down Expand Up @@ -439,7 +439,7 @@ def _calculate(self):
raise Exception("This must be overridden")

def calculate(self, time_length: float, **kwargs) -> None:
"""Calculate storageUnit terms for a time step
"""Calculate Process terms for a time step
Args:
simulation_time: current simulation time
Expand Down
4 changes: 2 additions & 2 deletions pywatershed/hydrology/PRMSCanopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from ..base.adapter import adaptable
from ..base.control import Control
from ..base.storage_unit import StorageUnit
from ..base.process import Process
from ..constants import CovType, HruType, numba_num_threads, zero
from ..parameters import Parameters

Expand All @@ -28,7 +28,7 @@
ACTIVE = 1


class PRMSCanopy(StorageUnit):
class PRMSCanopy(Process):
"""PRMS canopy."""

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions pywatershed/hydrology/PRMSChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import networkx as nx
import numpy as np

from pywatershed.base.storage_unit import StorageUnit
from pywatershed.base.process import Process

from ..base.adapter import adaptable
from ..base.control import Control
Expand All @@ -18,7 +18,7 @@
has_prmschannel_f = False


class PRMSChannel(StorageUnit):
class PRMSChannel(Process):
"""PRMS channel flow (muskingum_mann).
The muskingum module was originally developed for the Precipitation Runoff
Expand Down
4 changes: 2 additions & 2 deletions pywatershed/hydrology/PRMSEt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from pywatershed.base.budget import Budget
from pywatershed.base.storage_unit import StorageUnit
from pywatershed.base.process import Process

from ..base.adapter import adaptable
from ..base.control import Control
Expand All @@ -17,7 +17,7 @@
# end of each time calculation.


class PRMSEt(StorageUnit):
class PRMSEt(Process):
def __init__(
self,
control: Control,
Expand Down
4 changes: 2 additions & 2 deletions pywatershed/hydrology/PRMSGroundwater.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from pywatershed.base.storage_unit import StorageUnit
from pywatershed.base.process import Process

from ..base.adapter import adaptable
from ..base.control import Control
Expand All @@ -15,7 +15,7 @@
has_prmsgroundwater_f = False


class PRMSGroundwater(StorageUnit):
class PRMSGroundwater(Process):
"""PRMS groundwater reservoir."""

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions pywatershed/hydrology/PRMSRunoff.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from numba import prange

from pywatershed.base.storage_unit import StorageUnit
from pywatershed.base.process import Process

from ..base.adapter import adaptable
from ..base.control import Control
Expand All @@ -24,7 +24,7 @@
LAKE = HruType.LAKE.value


class PRMSRunoff(StorageUnit):
class PRMSRunoff(Process):
"""PRMS surface runoff."""

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions pywatershed/hydrology/PRMSSnow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from numba import prange

from pywatershed.base.storage_unit import StorageUnit
from pywatershed.base.process import Process

from ..base.adapter import adaptable
from ..base.control import Control
Expand Down Expand Up @@ -68,7 +68,7 @@
dbgind = 434


class PRMSSnow(StorageUnit):
class PRMSSnow(Process):
"""PRMS snow pack."""

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions pywatershed/hydrology/PRMSSoilzone.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from numba import prange

from pywatershed.base.storage_unit import StorageUnit
from pywatershed.base.process import Process

from ..base.adapter import adaptable
from ..base.control import Control
Expand All @@ -21,7 +21,7 @@
TWOTHIRDS = 2 / 3


class PRMSSoilzone(StorageUnit):
class PRMSSoilzone(Process):
"""PRMS soil zone.
Args:
Expand Down
4 changes: 2 additions & 2 deletions pywatershed/hydrology/Starfit.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import numpy as np

from pywatershed.base.storage_unit import StorageUnit
from pywatershed.base.process import Process

from ..base.adapter import adaptable
from ..base.control import Control
from ..constants import nan, one, zero
from ..parameters import Parameters


class Starfit(StorageUnit):
class Starfit(Process):
"""starfit: Storage Targets And Release Function Inference Tool
Sean W.D. Turner, Jennie Clarice Steyaert, Laura Condon, Nathalie Voisin,
Expand Down
9 changes: 9 additions & 0 deletions test_data/drb_2yr/control.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ load_n_time_batches: 1
# still used by snow and soilzone, but should be removed
init_vars_from_file: 0


dprst_flag: True

# boolean
Expand All @@ -28,3 +29,11 @@ netcdf_output_var_names:
- albedo
- cap_infil_tot
- contrib_fraction


# candidates from PRMS style control files to HONOR or keep
# modules listing: could be used to create model_dict
# parameter_file: single (multiple?) parameter file
# model.out: log file
# paths to input files (e.g. cbh files, with names)
# output frequency and output dir
13 changes: 6 additions & 7 deletions test_data/drb_2yr/nhm_model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ solargeometry:
class: PRMSSolarGeometry
parameters: parameters_PRMSSolarGeometry.nc
dis: dis_hru

atmosphere:
class: PRMSAtmosphere
parameters: parameters_PRMSAtmosphere.nc
dis: dis_hru

canopy:
class: PRMSCanopy
parameters: parameters_PRMSCanopy.nc
dis: dis_hru

snow:
class: PRMSSnow
parameters: parameters_PRMSSnow.nc
dis: dis_hru

runoff:
class: PRMSRunoff
parameters: parameters_PRMSRunoff.nc
dis: dis_hru

soilzone:
class: PRMSSoilzone
parameters: parameters_PRMSSoilzone.nc
dis: dis_hru

groundwater:
class: PRMSGroundwater
parameters: parameters_PRMSGroundwater.nc
Expand All @@ -53,4 +53,3 @@ model_order:
- soilzone
- groundwater
- channel

0 comments on commit c42808e

Please sign in to comment.