Skip to content

Commit 0f867a3

Browse files
authored
Merge pull request #88 from EcohydrologyTeam/KW_Phosphorus
Phosphorus, N2, POM, and PX
2 parents dc14869 + b3ac970 commit 0f867a3

17 files changed

+9357
-106
lines changed

examples/dev_sandbox/DOX_sat_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def DOs_atm_alpha(
2525

2626
def DOX_sat(
2727
TwaterK: xr.DataArray,
28-
pressure_atm: xr.DataArray,
28+
pressure_mb: xr.DataArray,
2929
pwv: xr.DataArray,
3030
DOs_atm_alpha: xr.DataArray
3131
) -> xr.DataArray:
3232
"""Calculate DO saturation value
3333
3434
Args:
3535
TwaterK: Water temperature kelvin
36-
pressure_atm: Atmospheric pressure (atm)
36+
pressure_mb: Atmospheric pressure (mb)
3737
pwv: Patrial pressure of water vapor (atm)
3838
DOs_atm_alpha: DO saturation atmospheric correction coefficient
3939
"""
@@ -44,8 +44,8 @@ def DOX_sat(
4444

4545
DOX_sat_uncorrected = -139.34410 + ( 1.575701E05 / TwaterK ) - ( 6.642308E07 / (TwaterK**2.0) ) + ( 1.243800E10 / (TwaterK**3.0) ) - ( 8.621949E11 / (TwaterK**4.0) )
4646

47-
DOX_sat_corrected = DOX_sat_uncorrected * pressure_atm * \
48-
(1 - pwv / pressure_atm) * (1 - DOs_atm_alpha * pressure_atm) / \
47+
DOX_sat_corrected = DOX_sat_uncorrected * pressure_mb * \
48+
(1 - pwv / pressure_mb) * (1 - DOs_atm_alpha * pressure_mb) / \
4949
((1 - pwv) * (1 - DOs_atm_alpha))
5050

5151
print(no_exp)

examples/dev_sandbox/prof_nsm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
'topwidth': 1,
164164
'slope': 2,
165165
'shear_velocity': 4,
166-
'pressure_atm': 2,
166+
'pressure_mb': 2026.5,
167167
'wind_speed': 4,
168168
'q_solar': 4,
169169
'Solid': 1,

src/clearwater_modules/nsm1/constants.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class BalgaeStaticVariables(TypedDict):
9898
krb_20=0.2,
9999
kdb_20=0.3,
100100
mub_max_theta = 1.047,
101-
krb_theta = 1.047,
101+
krb_theta = 1.06,
102102
kdb_theta = 1.047,
103103
b_growth_rate_option=1,
104104
b_light_limitation_option=1,
@@ -130,11 +130,11 @@ class NitrogenStaticVariables(TypedDict):
130130
kdnit_20=0.002,
131131
rnh4_20=0,
132132
vno3_20=0,
133-
knit_theta= 1.047, ## Check values RAS/Kelsey's
134-
kon_theta= 1.047,
135-
kdnit_theta= 1.047,
133+
knit_theta= 1.083,
134+
kon_theta= 1.074,
135+
kdnit_theta= 1.08,
136136
rnh4_theta= 1.047,
137-
vno3_theta= 1.047,
137+
vno3_theta= 1.045,
138138
KsOxdn=0.1,
139139
PN=0.5,
140140
PNb=0.5
@@ -156,10 +156,10 @@ class CarbonStaticVariables(TypedDict):
156156
DEFAULT_CARBON = CarbonStaticVariables(
157157
f_pocp = 0.9,
158158
kdoc_20= 0.01,
159-
kdoc_theta = 1.047,
160159
f_pocb=0.9,
161160
kpoc_20= 0.005,
162161
kpoc_theta = 1.047,
162+
kdoc_theta = 1.047,
163163
KsOxmc=1.0,
164164
pCO2 = 383.0,
165165
FCO2 = 0.2,
@@ -200,10 +200,12 @@ class N2StaticVariables(TypedDict):
200200

201201
class POMStaticVariables(TypedDict):
202202
kpom_20: float
203+
h2: float
203204
kpom_theta: float
204205

205206
DEFAULT_POM = POMStaticVariables(
206207
kpom_20 = 0.1,
208+
h2=0.1,
207209
kpom_theta = 1.047
208210
)
209211

@@ -216,7 +218,7 @@ class PathogenStaticVariables(TypedDict):
216218

217219
DEFAULT_PATHOGEN = PathogenStaticVariables(
218220
kdx_20=0.8,
219-
kdx_theta = 1.047,
221+
kdx_theta = 1.07,
220222
apx=1,
221223
vx=1
222224
)
@@ -232,7 +234,7 @@ class PhosphorusStaticVariables(TypedDict):
232234
kop_20 = 0.1,
233235
rpo4_20 =0,
234236
kop_theta = 1.047,
235-
rpo4_theta = 1.047,
237+
rpo4_theta = 1.074,
236238
kdpo4 = 0.0,
237239
)
238240

@@ -299,7 +301,7 @@ class GlobalVars(TypedDict):
299301
topwidth: float
300302
slope: float
301303
shear_velocity: float
302-
pressure_atm: float
304+
pressure_mb: float
303305
wind_speed: float
304306
q_solar: float
305307
Solid: int
@@ -319,24 +321,24 @@ class GlobalVars(TypedDict):
319321
vs = 999,
320322
SOD_20 = 999,
321323
SOD_theta = 999,
324+
theta=1.047,
322325
vb = 0.01,
323326
fcom = 0.4,
324327
kaw_20_user = 999,
325328
kah_20_user = 999,
326-
kaw_theta = 1.047,
327-
kah_theta = 1.047,
328-
hydraulic_reaeration_option = 2,
329-
wind_reaeration_option = 2,
329+
kaw_theta = 1.024,
330+
kah_theta = 1.024,
331+
hydraulic_reaeration_option = 1,
332+
wind_reaeration_option = 1,
330333
dt = 1, #TODO Dynamic or static?
331334
depth = 1.5, #TODO Dynamic or static?
332335
TwaterC = 20,
333-
theta = 1.047,
334336
velocity = 1,
335337
flow = 2,
336338
topwidth = 1,
337339
slope = 2,
338340
shear_velocity = 4,
339-
pressure_atm = 2,
341+
pressure_mb = 2026.5,
340342
wind_speed = 4,
341343
q_solar = 500,
342344
Solid = 1,

src/clearwater_modules/nsm1/dynamic_variables.py

-8
Original file line numberDiff line numberDiff line change
@@ -1371,14 +1371,6 @@ class Variable(base.Variable):
13711371
process=processes.KHN2_tc
13721372
)
13731373

1374-
Variable(
1375-
name='P_wv',
1376-
long_name='Partial pressure water vapor',
1377-
units='atm',
1378-
description='Partial pressure water vapor',
1379-
use='dynamic',
1380-
process=processes.P_wv
1381-
)
13821374

13831375
Variable(
13841376
name='N2sat',

src/clearwater_modules/nsm1/processes.py

+33-46
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
############################################ From shared processes
88

99
def celsius_to_kelvin(tempc: xr.DataArray) -> xr.DataArray:
10-
return tempc + 273.16
11-
12-
13-
14-
def kelvin_to_celsius(tempk: xr.DataArray) -> xr.DataArray:
15-
return tempk - 273.16
16-
10+
return tempc + 273.15
1711

1812
def arrhenius_correction(
1913
TwaterC: xr.DataArray,
@@ -1512,6 +1506,8 @@ def NH4_ApGrowth(
15121506
def NH4_AbRespiration(
15131507
use_Balgae: bool,
15141508
rnb: xr.DataArray,
1509+
Fb: xr.DataArray,
1510+
depth: xr.DataArray,
15151511
AbRespiration: xr.DataArray,
15161512

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

1527-
return xr.where(use_Balgae, rnb * AbRespiration, 0.0 )
1525+
return xr.where(use_Balgae, (rnb * AbRespiration*Fb)/depth, 0.0 )
15281526

15291527
def NH4_AbGrowth(
15301528
use_Balgae: bool,
@@ -2022,17 +2020,21 @@ def DIP_ApGrowth(
20222020
def DIP_AbRespiration(
20232021
rpb: xr.DataArray,
20242022
AbRespiration: xr.DataArray,
2025-
use_Balgae: bool
2023+
use_Balgae: bool,
2024+
Fb: xr.DataArray,
2025+
depth: xr.DataArray
20262026

20272027
) -> xr.DataArray :
20282028
"""Calculate DIP_AbRespiration: Dissolved inorganic phosphorus released for benthic algal respiration (mg-P/L/d).
20292029
20302030
Args:
20312031
rpb: Benthic algal P : Benthic algal dry ratio (mg-P/mg-D)
20322032
AbRespiration: Benthic algal respiration rate (g/m^2/d)
2033-
use_Blgae: true/false to use benthic algae module (t/f)
2033+
use_Blgae: true/false to use benthic algae module (t/f)
2034+
Fb: Fraction of bottom area available for benthic algal (unitless)
2035+
depth: water depth (m)
20342036
"""
2035-
return xr.where(use_Balgae, rpb * AbRespiration,0)
2037+
return xr.where(use_Balgae, rpb * Fb * AbRespiration /depth,0)
20362038

20372039
def DIP_AbGrowth(
20382040
rpb: xr.DataArray,
@@ -2199,7 +2201,7 @@ def POM_algal_settling(
21992201
Ap: xr.DataArray,
22002202
vsap: xr.DataArray,
22012203
rda: xr.DataArray,
2202-
depth: xr.DataArray,
2204+
h2: xr.DataArray,
22032205
use_Algae: xr.DataArray
22042206
) -> xr.DataArray:
22052207
"""Calculates the particulate organic matter concentration change due to algal mortality
@@ -2208,10 +2210,10 @@ def POM_algal_settling(
22082210
Ap: Algae concentration (mg/L)
22092211
vsap: Algal settling velocity (m/d)
22102212
rda: Ratio of algal biomass to chlorophyll-a
2211-
depth: Depth of water in computation cell (m)
2213+
h2: active sediment layer thickness (m)
22122214
use_Algae: Option to consider algal kinetics
22132215
"""
2214-
da: xr.DataArray = xr.where(use_Algae == True, vsap * Ap * rda / depth, 0)
2216+
da: xr.DataArray = xr.where(use_Algae == True, vsap * Ap * rda / h2, 0)
22152217

22162218
return da
22172219

@@ -2234,7 +2236,7 @@ def POM_dissolution(
22342236
def POM_POC_settling(
22352237
POC: xr.DataArray,
22362238
vsoc: xr.DataArray,
2237-
depth: xr.DataArray,
2239+
h2: xr.DataArray,
22382240
fcom: xr.DataArray,
22392241
use_POC: xr.DataArray
22402242
) -> xr.DataArray:
@@ -2243,11 +2245,11 @@ def POM_POC_settling(
22432245
Args:
22442246
POC: Concentration of particulate organic carbon (mg/L)
22452247
vsoc: POC settling velocity (m/d)
2246-
depth: Depth of water (m)
2248+
h2: active sediment layer thickness (m)
22472249
fcom: Fraction of carbon in organic matter (mg-C/mg-D)
22482250
use_POC: Option to consider particulate organic carbon
22492251
"""
2250-
da: xr.DataArray = xr.where(use_POC == True, vsoc * POC / depth / fcom, 0)
2252+
da: xr.DataArray = xr.where(use_POC == True, vsoc * POC / h2 / fcom, 0)
22512253

22522254
return da
22532255

@@ -2257,7 +2259,7 @@ def POM_benthic_algae_mortality(
22572259
kdb_tc: xr.DataArray,
22582260
Fb: xr.DataArray,
22592261
Fw: xr.DataArray,
2260-
depth: xr.DataArray,
2262+
h2: xr.DataArray,
22612263
use_Balgae: xr.DataArray
22622264
) -> xr.DataArray:
22632265
"""Calculates particulate organic matter concentration change due to benthic algae mortality
@@ -2267,10 +2269,10 @@ def POM_benthic_algae_mortality(
22672269
kdb_tc: Benthic algae death rate (1/d)
22682270
Fb: Fraction of bottom area available for benthic algae growth
22692271
Fw: Fraction of benthic algae mortality into water column
2270-
depth: Depth of water in computation cell (m)
2272+
h2: active sediment layer thickness (m)
22712273
use_Balgae: Option for considering benthic algae in DOC budget (boolean)
22722274
"""
2273-
da: xr.DataArray = xr.where(use_Balgae == True, Ab * kdb_tc * Fb * (1 - Fw) / depth, 0)
2275+
da: xr.DataArray = xr.where(use_Balgae == True, Ab * kdb_tc * Fb * (1 - Fw) / h2, 0)
22742276

22752277
return da
22762278

@@ -2279,16 +2281,16 @@ def POM_benthic_algae_mortality(
22792281
def POM_burial(
22802282
vb: xr.DataArray,
22812283
POM: xr.DataArray,
2282-
depth: xr.DataArray
2284+
h2: xr.DataArray
22832285
) -> xr.DataArray:
22842286
"""Calculates particulate organic matter concentration change due to POM burial in the sediments
22852287
22862288
Args:
22872289
vb: Velocity of burial (m/d)
22882290
POM: POM concentration (mg/L)
2289-
depth: Depth of water in computation cell (m)
2291+
h2: active sediment layer thickness (m)
22902292
"""
2291-
return vb * POM / depth
2293+
return vb * POM / h2 #note removed 365 from FORTRAN
22922294

22932295

22942296

@@ -2898,19 +2900,19 @@ def DOs_atm_alpha(
28982900

28992901
def DOX_sat(
29002902
TwaterK: xr.DataArray,
2901-
pressure_atm: xr.DataArray,
2903+
pressure_mb: xr.DataArray,
29022904
pwv: xr.DataArray,
29032905
DOs_atm_alpha: xr.DataArray
29042906
) -> xr.DataArray:
29052907
"""Calculate DO saturation value
29062908
29072909
Args:
29082910
TwaterK: Water temperature kelvin
2909-
pressure_atm: Atmospheric pressure (atm)
2911+
pressure_mb: Atmospheric pressure (mb)
29102912
pwv: Patrial pressure of water vapor (atm)
29112913
DOs_atm_alpha: DO saturation atmospheric correction coefficient
29122914
"""
2913-
pressure_atm = pressure_atm * 0.000986923
2915+
pressure_atm = pressure_mb * 0.000986923
29142916

29152917
DOX_sat_uncorrected = np.exp(-139.34410 + ( 1.575701E05 / TwaterK ) - ( 6.642308E07 / (TwaterK**2.0) ) + ( 1.243800E10 / (TwaterK**3.0) ) - ( 8.621949E11 / (TwaterK**4.0) ))
29162918

@@ -3465,36 +3467,21 @@ def KHN2_tc(
34653467
return 0.00065 * np.exp(1300.0 * (1.0 / TwaterK - 1 / 298.15))
34663468

34673469

3468-
def P_wv(
3469-
TwaterK : xr.DataArray,
3470-
) -> xr.DataArray :
3471-
3472-
"""Calculate partial pressure water vapor (atm)
3473-
3474-
Constant values found in documentation
3475-
3476-
Args:
3477-
TwaterK: water temperature kelvin (K)
3478-
3479-
"""
3480-
return np.exp(11.8571 - (3840.70 / TwaterK) - (216961.0 / (TwaterK**2)))
3481-
3482-
34833470
def N2sat(
34843471
KHN2_tc : xr.DataArray,
3485-
pressure_atm: xr.DataArray,
3486-
P_wv: xr.DataArray
3472+
pressure_mb: xr.DataArray,
3473+
pwv: xr.DataArray
34873474
) -> xr.DataArray:
34883475

34893476
"""Calculate N2 at saturation f(Twater and atm pressure) (mg-N/L)
34903477
34913478
Args:
34923479
KHN2_tc: Henry's law constant (mol/L/atm)
3493-
pressure_atm: atmosphric pressure in atm (atm)
3494-
P_wv: Partial pressure of water vapor (atm)
3480+
pressure_mb: atmosphric pressure in mb (mb)
3481+
pwv: Partial pressure of water vapor (atm)
34953482
"""
34963483

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

35003487
return N2sat

0 commit comments

Comments
 (0)