Skip to content

Commit c100885

Browse files
committed
Merge branch 'KW_Variables' into IJM_NSM_nb
2 parents 2779567 + 24feee4 commit c100885

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1606
-1168
lines changed

src/clearwater_modules/nsm1/CBOD/dynamic_variables.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# TODO: figure out imports...
1+
"""
2+
File contains dynamic variables related to the CBOD module
3+
"""
24

35
import clearwater_modules.shared.processes as shared_processes
46
from clearwater_modules import base
@@ -12,21 +14,21 @@ class Variable(base.Variable):
1214

1315

1416
Variable(
15-
name='kbod_T',
17+
name='kbod_tc',
1618
long_name='Temperature adjusted oxidation rate',
1719
units='1/d',
1820
description='Temperature adjusted oxidation rate',
1921
use='dynamic',
20-
process=processes.kbod_T
22+
process=processes.kbod_tc
2123
)
2224

2325
Variable(
24-
name='ksbod_T',
26+
name='ksbod_tc',
2527
long_name='Temperature adjusted sedimentation rate',
2628
units='m/d',
2729
description='Temperature adjusted sedimentation rate',
2830
use='dynamic',
29-
process=processes.ksbod_T
31+
process=processes.ksbod_tc
3032
)
3133

3234
Variable(

src/clearwater_modules/nsm1/CBOD/processes.py

+23-26
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,49 @@
1-
import numpy as np
1+
"""
2+
File contains process to calculate new CBOD concentration and associated dependent variables
3+
"""
4+
25
import numba
36
import xarray as xr
4-
from clearwater_modules.shared.processes import (
5-
arrhenius_correction,
6-
)
7-
7+
from clearwater_modules.shared.processes import arrhenius_correction
8+
import math
89

910
@numba.njit
10-
def kbod_T(
11-
water_temp_c: xr.DataArray,
11+
def kbod_tc(
12+
TwaterC: xr.DataArray,
1213
kbod_20: xr.DataArray,
13-
theta: xr.DataArray
1414
) -> xr.DataArray:
1515
"""Calculate the temperature adjusted CBOD oxidation rate (1/d)
1616
1717
Args:
18-
water_temp_c: water temperature in Celsius
18+
TwaterC: water temperature in Celsius
1919
kbod_20: CBOD oxidation rate at 20 degrees Celsius (1/d)
20-
theta: Arrhenius coefficient
2120
"""
2221

23-
kbod_T = arrhenius_correction(water_temp_c, kbod_20, theta)
24-
return kbod_T
22+
kbod_tc = arrhenius_correction(TwaterC, kbod_20, 1.047)
23+
return kbod_tc
2524

2625

2726
@numba.njit
28-
def ksbod_T(
29-
water_temp_c: xr.DataArray,
27+
def ksbod_tc(
28+
TwaterC: xr.DataArray,
3029
ksbod_20: xr.DataArray,
31-
theta: xr.DataArray
3230
) -> xr.DataArray:
3331
"""Calculate the temperature adjusted CBOD sedimentation rate (m/d)
3432
3533
Args:
36-
water_temp_c: water temperature in Celsius
34+
TwaterC: water temperature in Celsius
3735
ksbod_20: CBOD sedimentation rate at 20 degrees Celsius (m/d)
38-
theta: Arrhenius coefficient
3936
"""
4037

41-
ksbod_T = arrhenius_correction(water_temp_c, ksbod_20, theta)
42-
return ksbod_T
38+
ksbod_tc = arrhenius_correction(TwaterC, ksbod_20, 1.024)
39+
return ksbod_tc
4340

4441

4542

4643
def CBOD_oxidation(
4744
DOX: xr.DataArray,
4845
CBOD: xr.DataArray,
49-
kbod_T: xr.DataArray,
46+
kbod_tc: xr.DataArray,
5047
KsOxbod: xr.DataArray,
5148
use_DOX: xr.DataArray
5249
) -> xr.DataArray:
@@ -55,28 +52,28 @@ def CBOD_oxidation(
5552
Args:
5653
DOX: Dissolved oxygen concentration (mg-O2/L)
5754
CBOD: Carbonaceous biochemical oxygen demand (mg-O2/L)
58-
kbod_T: Temperature adjusted CBOD oxidation rate (1/d)
55+
kbod_tc: Temperature adjusted CBOD oxidation rate (1/d)
5956
KsOxbod: Half-saturation oxygen attenuation for CBOD oxidation (mg-O2/L)
6057
use_DOX: Option to consider DOX concentration in calculation of CBOD oxidation
6158
"""
62-
da: xr.DataArray = xr.where(use_DOX == True, (DOX / (KsOxbod + DOX)) * kbod_T * CBOD, kbod_T * CBOD)
59+
da: xr.DataArray = xr.where(use_DOX == True, (DOX / (KsOxbod + DOX)) * kbod_tc * CBOD, kbod_tc * CBOD)
6360

6461
return da
6562

6663

6764
@numba.njit
6865
def CBOD_sedimentation(
6966
CBOD: xr.DataArray,
70-
ksbod_T: xr.DataArray
67+
ksbod_tc: xr.DataArray
7168
) -> xr.DataArray:
7269
"""Calculates CBOD sedimentation for each group
7370
7471
Args:
7572
CBOD: CBOD concentration (mg-O2/L)
76-
ksbod_T: Temperature adjusted sedimentation rate (m/d)
73+
ksbod_tc: Temperature adjusted sedimentation rate (m/d)
7774
"""
7875

79-
CBOD_sedimentation = CBOD * ksbod_T
76+
CBOD_sedimentation = CBOD * ksbod_tc
8077
return CBOD_sedimentation
8178

8279

@@ -95,7 +92,7 @@ def dCBODdt(
9592

9693

9794
@numba.njit
98-
def CBOD_new(
95+
def CBOD(
9996
CBOD: xr.DataArray,
10097
dCBODdt: xr.DataArray,
10198
timestep: xr.DataArray

src/clearwater_modules/nsm1/CBOD/static_variables.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
# TODO: figure out what 'model' to import
1+
"""
2+
File contains static variables related to the CBOD module
3+
"""
4+
25
import clearwater_modules.base as base
3-
from clearwater_modules.tsm.model import EnergyBudget
6+
from clearwater_modules.nsm1.model import NutrientBudget
47

58

6-
@base.register_variable(models=EnergyBudget)
9+
@base.register_variable(models=NutrientBudget)
710
class Variable(base.Variable):
811
...
912

1013

11-
# CBOD variables for each CBOD group - array
1214
Variable(
1315
name='kbod_20',
1416
long_name='CBOD oxidation rate at 20C',
@@ -26,9 +28,10 @@ class Variable(base.Variable):
2628
)
2729

2830
Variable(
29-
name='ksOxbod',
31+
name='KsOxbod',
3032
long_name='Half saturation oxygen attenuation constant for CBOD oxidation',
3133
units='mg-O2/L',
3234
description='Half saturation oxygen attenuation constant for CBOD oxidation',
3335
use='static'
3436
)
37+

src/clearwater_modules/nsm1/DOX/processes.py

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,76 @@
1-
import numpy as np
1+
"""
2+
File contains dynamic variables related to the DOX module
3+
"""
4+
25
import numba
36
import xarray as xr
4-
from clearwater_modules.shared.processes import (
5-
arrhenius_correction,
6-
)
7+
from clearwater_modules.shared.processes import arrhenius_correction
8+
import math
79

810

911
#TODO: make sure np.exp will work here...
1012
@numba.njit
1113
def pwv(
12-
t_water_k: xr.DataArray
14+
TwaterK: xr.DataArray
1315
) -> xr.DataArray:
1416
"""Calculate partial pressure of water vapor
1517
1618
Args:
17-
t_water_k: Water temperature kelvin
19+
TwaterK: Water temperature kelvin
1820
"""
19-
return np.exp(11.8571 - 3840.70 / t_water_k - 216961 / t_water_k ** 2)
21+
return np.exp(11.8571 - 3840.70 / TwaterK - 216961 / TwaterK ** 2)
2022

2123

2224
@numba.njit
2325
def DOs_atm_alpha(
24-
t_water_k: xr.DataArray
26+
TwaterK: xr.DataArray
2527
) -> xr.DataArray:
2628
"""Calculate DO saturation atmospheric correction coefficient
2729
2830
Args:
29-
t_water_k: Water temperature kelvin
31+
TwaterK: Water temperature kelvin
3032
"""
31-
return .000975 - 1.426 * 10 ** -5 * t_water_k + 6.436 * 10 ** -8 * t_water_k ** 2
33+
return .000975 - 1.426 * 10 ** -5 * TwaterK + 6.436 * 10 ** -8 * TwaterK ** 2
3234

3335

3436
@numba.njit
3537
def DOX_sat(
36-
t_water_k: xr.DataArray,
37-
patm: xr.DataArray,
38+
TwaterK: xr.DataArray,
39+
pressure_atm: xr.DataArray,
3840
pwv: xr.DataArray,
3941
DOs_atm_alpha: xr.DataArray
4042
) -> xr.DataArray:
4143
"""Calculate DO saturation value
4244
4345
Args:
44-
t_water_k: Water temperature kelvin
45-
patm: Atmospheric pressure (atm)
46+
TwaterK: Water temperature kelvin
47+
pressure_atm: Atmospheric pressure (atm)
4648
pwv: Patrial pressure of water vapor (atm)
4749
DOs_atm_alpha: DO saturation atmospheric correction coefficient
4850
"""
49-
DOX_sat_uncorrected = np.exp(-139.34410 + 1.575701 * 10 ** 5 / t_water_k - 6.642308 * 10 ** 7 / t_water_k ** 2
50-
+ 1.243800 * 10 ** 10 / t_water_k - 8.621949 * 10 ** 11 / t_water_k)
51+
DOX_sat_uncorrected = np.exp(-139.34410 + 1.575701 * 10 ** 5 / TwaterK - 6.642308 * 10 ** 7 / TwaterK ** 2
52+
+ 1.243800 * 10 ** 10 / TwaterK - 8.621949 * 10 ** 11 / TwaterK)
5153

52-
DOX_sat_corrected = DOX_sat_uncorrected * patm * \
53-
(1 - pwv / patm) * (1 - DOs_atm_alpha * patm) / \
54+
DOX_sat_corrected = DOX_sat_uncorrected * pressure_atm * \
55+
(1 - pwv / pressure_atm) * (1 - DOs_atm_alpha * pressure_atm) / \
5456
((1 - pwv) * (1 - DOs_atm_alpha))
5557
return DOX_sat_corrected
5658

5759

5860
@numba.njit
5961
def Atm_O2_reaeration(
60-
ka_T: xr.DataArray,
62+
ka_tc: xr.DataArray,
6163
DOX_sat: xr.DataArray,
6264
DOX: xr.DataArray
6365
) -> xr.DataArray:
6466
"""Compute the atmospheric O2 reaeration flux
6567
6668
Args:
67-
ka_T: Oxygen reaeration rate adjusted for temperature (1/d)
69+
ka_tc: Oxygen reaeration rate adjusted for temperature (1/d)
6870
DOX_sat: Dissolved oxygen saturation concentration (mg/L)
6971
DOX: Dissolved oxygen concentration (mg/L)
7072
"""
71-
return ka_T * (DOX_sat - DOX)
73+
return ka_tc * (DOX_sat - DOX)
7274

7375

7476
def DOX_ApGrowth(
@@ -258,7 +260,7 @@ def dDOXdt(
258260

259261

260262
@numba.njit
261-
def DOX_new(
263+
def DOX(
262264
DOX: xr.DataArray,
263265
dDOXdt: xr.DataArray,
264266
timestep: xr.DataArray
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,76 @@
1-
# TODO: figure out what 'model' to import
1+
"""
2+
File contains static variables related to the DOX module
3+
"""
4+
25
import clearwater_modules.base as base
3-
from clearwater_modules.tsm.model import EnergyBudget
6+
from clearwater_modules.nsm1.model import NutrientBudget
47

58

6-
@base.register_variable(models=EnergyBudget)
9+
@base.register_variable(models=NutrientBudget)
710
class Variable(base.Variable):
811
...
912

1013

14+
Variable(
15+
name='ron',
16+
long_name='O2:N ratio for nitrification',
17+
units='mg-O2/mg-N',
18+
description='2*32/14',
19+
use='static'
20+
)
21+
22+
Variable(
23+
name='SOD_20',
24+
long_name='Sediment oxygen demand at 20C',
25+
units='mg-O2/m2/d',
26+
description='Sediment oxygen demand at 20C',
27+
use='static'
28+
)
29+
30+
Variable(
31+
name='kaw_20_user',
32+
long_name='Wind oxygen reaeration velocity at 20C',
33+
units='m/d',
34+
description='Wind oxygen reaeration velocity at 20C',
35+
use='static'
36+
)
37+
38+
Variable(
39+
name='kah_20_user',
40+
long_name='Hydraulic oxygen reaeration rate at 20C',
41+
units='1/d',
42+
description='Hydraulic oxygen reaeration rate at 20C',
43+
use='static'
44+
)
45+
46+
Variable(
47+
name='hydraulic_reaeration_option',
48+
long_name='Option for chosing the method by which O2 reaeration rate is calculated',
49+
units='unitless',
50+
description='Selects method for computing O2 reaeration rate',
51+
use='static'
52+
)
53+
54+
Variable(
55+
name='wind_reaeration_option',
56+
long_name='Option for chosing the method by which wind reaeration is calculated',
57+
units='unitless',
58+
description='Selects method for computing O2 reaeration due to wind',
59+
use='static'
60+
)
61+
62+
Variable(
63+
name='patm',
64+
long_name='Atmospheric pressure',
65+
units='atm',
66+
description='Atmospheric pressure',
67+
use='static'
68+
)
69+
70+
Variable(
71+
name='KsSOD',
72+
long_name='half saturation oxygen attenuation constant for SOD',
73+
units='mg/L',
74+
description='half saturation oxygen attenuation constant for SOD',
75+
use='static'
76+
)

0 commit comments

Comments
 (0)