Skip to content

Commit

Permalink
Test Suit
Browse files Browse the repository at this point in the history
Added back in algae, balgae, and nitogen. Adapted all tests to new theta variable. One failing test change kbod in Carbon and Alkalinity. Incomplete suit for PX and N2. Questions on DOX_Sat concentration.
  • Loading branch information
kewalak committed Jul 31, 2024
1 parent ee895b8 commit 78a59a9
Show file tree
Hide file tree
Showing 10 changed files with 4,210 additions and 121 deletions.
26 changes: 13 additions & 13 deletions src/clearwater_modules/nsm1/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class BalgaeStaticVariables(TypedDict):
krb_20=0.2,
kdb_20=0.3,
mub_max_theta = 1.047,
krb_theta = 1.047,
krb_theta = 1.06,
kdb_theta = 1.047,
b_growth_rate_option=1,
b_light_limitation_option=1,
Expand Down Expand Up @@ -130,11 +130,11 @@ class NitrogenStaticVariables(TypedDict):
kdnit_20=0.002,
rnh4_20=0,
vno3_20=0,
knit_theta= 1.047, ## Check values RAS/Kelsey's
kon_theta= 1.047,
kdnit_theta= 1.047,
knit_theta= 1.083,
kon_theta= 1.074,
kdnit_theta= 1.08,
rnh4_theta= 1.047,
vno3_theta= 1.047,
vno3_theta= 1.045,
KsOxdn=0.1,
PN=0.5,
PNb=0.5
Expand All @@ -156,10 +156,10 @@ class CarbonStaticVariables(TypedDict):
DEFAULT_CARBON = CarbonStaticVariables(
f_pocp = 0.9,
kdoc_20= 0.01,
kdoc_theta = 1.047,
f_pocb=0.9,
kpoc_20= 0.005,
kpoc_theta = 1.047,
kdoc_theta = 1.047,
KsOxmc=1.0,
pCO2 = 383.0,
FCO2 = 0.2,
Expand Down Expand Up @@ -218,7 +218,7 @@ class PathogenStaticVariables(TypedDict):

DEFAULT_PATHOGEN = PathogenStaticVariables(
kdx_20=0.8,
kdx_theta = 1.047,
kdx_theta = 1.07,
apx=1,
vx=1
)
Expand All @@ -234,7 +234,7 @@ class PhosphorusStaticVariables(TypedDict):
kop_20 = 0.1,
rpo4_20 =0,
kop_theta = 1.047,
rpo4_theta = 1.047,
rpo4_theta = 1.074,
kdpo4 = 0.0,
)

Expand Down Expand Up @@ -321,18 +321,18 @@ class GlobalVars(TypedDict):
vs = 999,
SOD_20 = 999,
SOD_theta = 999,
theta=1.047,
vb = 0.01,
fcom = 0.4,
kaw_20_user = 999,
kah_20_user = 999,
kaw_theta = 1.047,
kah_theta = 1.047,
hydraulic_reaeration_option = 2,
wind_reaeration_option = 2,
kaw_theta = 1.024,
kah_theta = 1.024,
hydraulic_reaeration_option = 1,
wind_reaeration_option = 1,
dt = 1, #TODO Dynamic or static?
depth = 1.5, #TODO Dynamic or static?
TwaterC = 20,
theta = 1.047,
velocity = 1,
flow = 2,
topwidth = 1,
Expand Down
8 changes: 0 additions & 8 deletions src/clearwater_modules/nsm1/dynamic_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1371,14 +1371,6 @@ class Variable(base.Variable):
process=processes.KHN2_tc
)

Variable(
name='P_wv',
long_name='Partial pressure water vapor',
units='atm',
description='Partial pressure water vapor',
use='dynamic',
process=processes.P_wv
)

Variable(
name='N2sat',
Expand Down
29 changes: 9 additions & 20 deletions src/clearwater_modules/nsm1/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def celsius_to_kelvin(tempc: xr.DataArray) -> xr.DataArray:


def kelvin_to_celsius(tempk: xr.DataArray) -> xr.DataArray:
return tempk - 273.16
return tempk - 273.15


def arrhenius_correction(
Expand Down Expand Up @@ -1512,6 +1512,8 @@ def NH4_ApGrowth(
def NH4_AbRespiration(
use_Balgae: bool,
rnb: xr.DataArray,
Fb: xr.DataArray,
depth: xr.DataArray,
AbRespiration: xr.DataArray,

) -> xr.DataArray:
Expand All @@ -1521,10 +1523,12 @@ def NH4_AbRespiration(
use_Balgae: true/false to use benthic algae module (unitless),
rnb: xr.DataArray,
AbRespiration: Benthic algal respiration rate (g/m^2/d),
depth: water depth (m),
Fb: Fraction of bottom area for benthic algae (unitless),
"""
# TODO changed the calculation for respiration from the inital FORTRAN due to conflict with the reference guide

return xr.where(use_Balgae, rnb * AbRespiration, 0.0 )
return xr.where(use_Balgae, (rnb * AbRespiration*Fb)/depth, 0.0 )

def NH4_AbGrowth(
use_Balgae: bool,
Expand Down Expand Up @@ -3469,36 +3473,21 @@ def KHN2_tc(
return 0.00065 * np.exp(1300.0 * (1.0 / TwaterK - 1 / 298.15))


def P_wv(
TwaterK : xr.DataArray,
) -> xr.DataArray :

"""Calculate partial pressure water vapor (atm)
Constant values found in documentation
Args:
TwaterK: water temperature kelvin (K)
"""
return np.exp(11.8571 - (3840.70 / TwaterK) - (216961.0 / (TwaterK**2)))


def N2sat(
KHN2_tc : xr.DataArray,
pressure_atm: xr.DataArray,
P_wv: xr.DataArray
pwv: xr.DataArray
) -> xr.DataArray:

"""Calculate N2 at saturation f(Twater and atm pressure) (mg-N/L)
Args:
KHN2_tc: Henry's law constant (mol/L/atm)
pressure_atm: atmosphric pressure in atm (atm)
P_wv: Partial pressure of water vapor (atm)
pwv: Partial pressure of water vapor (atm)
"""

N2sat = 2.8E+4 * KHN2_tc * 0.79 * (pressure_atm - P_wv)
N2sat = 2.8E+4 * KHN2_tc * 0.79 * (pressure_atm - pwv)
N2sat = xr.where(N2sat < 0.0,0.000001,N2sat) #Trap saturation concentration to ensure never negative

return N2sat
Expand Down
43 changes: 32 additions & 11 deletions tests/test_14_nsm_phosphrous_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def default_algae_params() -> AlgaeStaticVariables:
vsap= 0.15,
growth_rate_option = 1,
light_limitation_option = 1,
mu_max_theta= 1.047,
kdp_theta= 1.047,
krp_theta= 1.047,
)

@pytest.fixture(scope='function')
Expand Down Expand Up @@ -119,7 +122,10 @@ def default_balgae_params() -> BalgaeStaticVariables:
b_growth_rate_option=1,
b_light_limitation_option=1,
Fw=0.9,
Fb=0.9
Fb=0.9,
mub_max_theta = 1.047,
krb_theta = 1.06,
kdb_theta = 1.047,
)

@pytest.fixture(scope='function')
Expand All @@ -140,7 +146,12 @@ def default_nitrogen_params() -> NitrogenStaticVariables:
vno3_20=0,
KsOxdn=0.1,
PN=0.5,
PNb=0.5
PNb=0.5,
knit_theta= 1.083,
kon_theta= 1.047,
kdnit_theta= 1.045,
rnh4_theta= 1.074,
vno3_theta= 1.08,
)

@pytest.fixture(scope='function')
Expand All @@ -160,7 +171,9 @@ def default_carbon_params() -> CarbonStaticVariables:
KsOxmc=1.0,
pCO2 = 383.0,
FCO2 = 0.2,
roc = 32.0/12.0
roc = 32.0/12.0,
kpoc_theta = 1.047,
kdoc_theta = 1.047,
)

@pytest.fixture(scope='function')
Expand All @@ -175,7 +188,9 @@ def default_CBOD_params() -> CBODStaticVariables:
return CBODStaticVariables(
KsOxbod = 0.5,
kbod_20 = 0.12,
ksbod_20 = 0.0
ksbod_20 = 0.0,
kbod_theta = 1.047,
ksbod_theta = 1.047
)

@pytest.fixture(scope='function')
Expand Down Expand Up @@ -215,7 +230,9 @@ def default_POM_params() -> POMStaticVariables:
Returns a typed dictionary, with string keys and float values.
"""
return POMStaticVariables(
kpom_20 = 0.1
kpom_20 = 0.1,
h2 = 0.1,
kpom_theta = 1.047
)

@pytest.fixture(scope='function')
Expand All @@ -230,7 +247,8 @@ def default_pathogen_params() -> PathogenStaticVariables:
return PathogenStaticVariables(
kdx_20=0.8,
apx=1,
vx=1
vx=1,
kdx_theta = 1.07,
)

@pytest.fixture(scope='function')
Expand All @@ -246,6 +264,8 @@ def default_phosphorus_params() -> PhosphorusStaticVariables:
kop_20 = 0.1,
rpo4_20 =0,
kdpo4 = 0.0,
kop_theta = 1.047,
rpo4_theta = 1.074,
)

@pytest.fixture(scope='function')
Expand Down Expand Up @@ -294,14 +314,15 @@ def default_gvars_params() -> GlobalVars:
SOD_theta = 999,
vb = 0.01,
fcom = 0.4,
kaw_20_user = 999,
kah_20_user = 999,
hydraulic_reaeration_option = 2,
wind_reaeration_option = 2,
kaw_20_user = 0,
kah_20_user = 1,
hydraulic_reaeration_option = 1,
wind_reaeration_option = 1,
timestep = 1, #TODO Dynamic or static?
depth = 1.5, #TODO Dynamic or static?
TwaterC = 25,
theta = 1.047,
kaw_theta = 1.024,
kah_theta = 1.024,
velocity = 1,
flow = 150,
topwidth = 100,
Expand Down
45 changes: 32 additions & 13 deletions tests/test_15_nsm_POM_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def initial_nsm1_state() -> dict[str, float]:
'OrgN': 1.726,
'N2': 1,
'TIP': 0.071,
'OrgP': 0.24,
'OrgP': 0.25,
'POC': 4.356,
'DOC': 1,
'DIC': 1,
Expand Down Expand Up @@ -74,6 +74,9 @@ def default_algae_params() -> AlgaeStaticVariables:
vsap= 0.15,
growth_rate_option = 1,
light_limitation_option = 1,
mu_max_theta= 1.047,
kdp_theta= 1.047,
krp_theta= 1.047,
)

@pytest.fixture(scope='function')
Expand Down Expand Up @@ -119,7 +122,10 @@ def default_balgae_params() -> BalgaeStaticVariables:
b_growth_rate_option=1,
b_light_limitation_option=1,
Fw=0.9,
Fb=0.9
Fb=0.9,
mub_max_theta = 1.047,
krb_theta = 1.06,
kdb_theta = 1.047,
)

@pytest.fixture(scope='function')
Expand All @@ -140,7 +146,12 @@ def default_nitrogen_params() -> NitrogenStaticVariables:
vno3_20=0,
KsOxdn=0.1,
PN=0.5,
PNb=0.5
PNb=0.5,
knit_theta= 1.083,
kon_theta= 1.047,
kdnit_theta= 1.045,
rnh4_theta= 1.074,
vno3_theta= 1.08,
)

@pytest.fixture(scope='function')
Expand All @@ -160,7 +171,9 @@ def default_carbon_params() -> CarbonStaticVariables:
KsOxmc=1.0,
pCO2 = 383.0,
FCO2 = 0.2,
roc = 32.0/12.0
roc = 32.0/12.0,
kpoc_theta = 1.047,
kdoc_theta = 1.047,
)

@pytest.fixture(scope='function')
Expand All @@ -175,7 +188,9 @@ def default_CBOD_params() -> CBODStaticVariables:
return CBODStaticVariables(
KsOxbod = 0.5,
kbod_20 = 0.12,
ksbod_20 = 0.0
ksbod_20 = 0.0,
kbod_theta = 1.047,
ksbod_theta = 1.047
)

@pytest.fixture(scope='function')
Expand Down Expand Up @@ -216,7 +231,8 @@ def default_POM_params() -> POMStaticVariables:
"""
return POMStaticVariables(
kpom_20 = 0.1,
h2 = 0.1
h2 = 0.1,
kpom_theta = 1.047
)

@pytest.fixture(scope='function')
Expand All @@ -231,7 +247,8 @@ def default_pathogen_params() -> PathogenStaticVariables:
return PathogenStaticVariables(
kdx_20=0.8,
apx=1,
vx=1
vx=1,
kdx_theta = 1.07,
)

@pytest.fixture(scope='function')
Expand All @@ -247,8 +264,9 @@ def default_phosphorus_params() -> PhosphorusStaticVariables:
kop_20 = 0.1,
rpo4_20 =0,
kdpo4 = 0.0,
kop_theta = 1.047,
rpo4_theta = 1.074,
)

@pytest.fixture(scope='function')
def default_gp_params() -> GlobalParameters:
"""Returns default global parameter static variable values for the model.
Expand Down Expand Up @@ -295,14 +313,15 @@ def default_gvars_params() -> GlobalVars:
SOD_theta = 999,
vb = 0.01,
fcom = 0.4,
kaw_20_user = 999,
kah_20_user = 999,
hydraulic_reaeration_option = 2,
wind_reaeration_option = 2,
kaw_20_user = 0,
kah_20_user = 1,
hydraulic_reaeration_option = 1,
wind_reaeration_option = 1,
timestep = 1, #TODO Dynamic or static?
depth = 1.5, #TODO Dynamic or static?
TwaterC = 25,
theta = 1.047,
kaw_theta = 1.024,
kah_theta = 1.024,
velocity = 1,
flow = 150,
topwidth = 100,
Expand Down
Loading

0 comments on commit 78a59a9

Please sign in to comment.