Skip to content

Commit

Permalink
Merge pull request #73 from EcohydrologyTeam/KW_CleanUp
Browse files Browse the repository at this point in the history
Moving global variables and removing repeats
  • Loading branch information
kewalak authored Feb 27, 2024
2 parents 6600e42 + b223242 commit 56cf704
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 191 deletions.
47 changes: 0 additions & 47 deletions src/clearwater_modules/nsm1/DOX/static_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,53 +19,6 @@ class Variable(base.Variable):
use='static'
)

Variable(
name='SOD_20',
long_name='Sediment oxygen demand at 20C',
units='mg-O2/m2/d',
description='Sediment oxygen demand at 20C',
use='static'
)

Variable(
name='kaw_20_user',
long_name='Wind oxygen reaeration velocity at 20C',
units='m/d',
description='Wind oxygen reaeration velocity at 20C',
use='static'
)

Variable(
name='kah_20_user',
long_name='Hydraulic oxygen reaeration rate at 20C',
units='1/d',
description='Hydraulic oxygen reaeration rate at 20C',
use='static'
)

Variable(
name='hydraulic_reaeration_option',
long_name='Option for chosing the method by which O2 reaeration rate is calculated',
units='unitless',
description='Selects method for computing O2 reaeration rate',
use='static'
)

Variable(
name='wind_reaeration_option',
long_name='Option for chosing the method by which wind reaeration is calculated',
units='unitless',
description='Selects method for computing O2 reaeration due to wind',
use='static'
)

Variable(
name='patm',
long_name='Atmospheric pressure',
units='atm',
description='Atmospheric pressure',
use='static'
)

Variable(
name='KsSOD',
Expand Down
18 changes: 0 additions & 18 deletions src/clearwater_modules/nsm1/algae/dynamic_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,6 @@
class Variable(base.Variable):
...

Variable(
name='L',
long_name='Light attenuation coefficient',
units='unitless',
description='Light attenuation coefficient',
use='dynamic',
process=processes.L
)

Variable(
name='PAR',
long_name='surface light intensity',
units='W/m2',
description='surface light intensity',
use='dynamic',
process=processes.PAR
)

Variable(
name='rna',
long_name='Algal N:Chla Ratio',
Expand Down
52 changes: 0 additions & 52 deletions src/clearwater_modules/nsm1/algae/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,58 +108,6 @@ def kdp_tc(

return arrhenius_correction(TwaterC, kdp_20, 1.047)

@numba.njit
def L(
lambda0: xr.DataArray,
lambda1: xr.DataArray,
lambda2: xr.DataArray,
lambdas: xr.DataArray,
lambdam: xr.DataArray,
Solid: xr.DataArray,
POC: xr.DataArray,
focm: xr.DataArray,
use_Algae: xr.DataArray,
use_POC: xr.DataArray,
Ap: xr.DataArray,

) -> xr.DataArray:
"""Compute L: lambda: light extinction coefficient (unitless)
Args:
lambda0: background portion (1/m)
lambda1: linear self shading (1/m/(ug Chla/L))
lambda2: non-linear (unitless),
lambdas: ISS portion (L/mg/m),
lambdam: POM portion (L/mg/m)
Solid: #TODO define this
POC: particulate organic carbon (mg-C/L)
focm: ratio of carbon to organic matter (mg-C/mg-D)
use_Algae: true/false use algae module (t/f)
use_POC: true/falseo use particulate organic carbon module (t/f)
Ap: algae concentration (ug-Chla/L)
"""
L=lambda0 + lambdas * Solid

L=xr.where (use_POC, L+lambdam*POC/focm, L)
L=xr.where (use_Algae, L+lambda1*Ap + lambda2*Ap**0.66667, L)

return L

@numba.njit
def PAR(
use_Algae : bool,
use_Balgae: bool,
q_solar: xr.DataArray,
Fr_PAR: xr.DataArray,
) -> xr.DataArray :
"""Calculate temperature in kelvin (K)
Args:
use_Algae : true/false use algae module (t/f)
use_Balgae: true/falsoe use balgae module (t/f)
q_solar: solar radiation (1/d),
Fr_PAR: fraction of soalr radiation within the PAR of the spectrum
"""
return xr.where (use_Algae or use_Balgae, q_solar * Fr_PAR)

@numba.njit
def FL(
Expand Down
2 changes: 1 addition & 1 deletion src/clearwater_modules/nsm1/balgae/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def dAbdt(
return AbGrowth - AbRespiration - AbDeath

@numba.njit
def Ab_new(
def Ab(
Ab: xr.DataArray,
dAbdt: xr.DataArray

Expand Down
14 changes: 7 additions & 7 deletions src/clearwater_modules/nsm1/carbon/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def dPOCdt(


@numba.njit
def POC_new(
def POC(
POC: xr.DataArray,
dPOCdt: xr.DataArray,
timestep: xr.DataArray
Expand Down Expand Up @@ -265,7 +265,7 @@ def Henrys_k(

@numba.njit
def Atmospheric_CO2_reaeration(
ka_T: xr.DataArray,
ka_tc: xr.DataArray,
K_H: xr.DataArray,
pCO2: xr.DataArray,
FCO2: xr.DataArray,
Expand All @@ -274,13 +274,13 @@ def Atmospheric_CO2_reaeration(
"""Calculates the atmospheric input of CO2 into the waterbody
Args:
ka_T: CO2 reaeration rate adjusted for temperature, same as O2 reaeration rate (1/d)
ka_tc: CO2 reaeration rate adjusted for temperature, same as O2 reaeration rate (1/d)
K_H: Henry's Law constant (mol/L/atm)
pCO2: Partial pressure of CO2 in the atmosphere (ppm)
FCO2: Fraction of CO2 in total inorganic carbon
DIC: Dissolved inorganic carbon concentration (mg/L)
"""
return 12 * ka_T * (10**-3 * K_H * pCO2 - 10**3 * FCO2 * DIC)
return 12 * ka_tc * (10**-3 * K_H * pCO2 - 10**3 * FCO2 * DIC)


def DIC_algal_respiration(
Expand Down Expand Up @@ -385,7 +385,7 @@ def DIC_CBOD_oxidation(


def DIC_sed_release(
SOD_tcc: xr.DataArray,
SOD_tc: xr.DataArray,
roc: xr.DataArray,
depth: xr.DataArray,
JDIC: xr.DataArray,
Expand All @@ -394,13 +394,13 @@ def DIC_sed_release(
"""Computes the sediment release of DIC
Args:
SOD_tcc: Sediment oxygen demand adjusted for water temperature (mg-O2/L/d)
SOD_tc: Sediment oxygen demand adjusted for water temperature (mg-O2/L/d)
roc: Ratio of O2 to carbon for carbon oxidation (mg-O2/mg-C)
depth: Water depth (m)
JDIC: Sediment-water flux of dissolved inorganic carbon (g-C/m2/d)
use_SedFlux: Option to consider full sediment flux budget in DIC sediment contribution (bool)
"""
da: xr.DataArray = xr.where(use_SedFlux == True, JDIC / depth, SOD_tcc / roc / depth)
da: xr.DataArray = xr.where(use_SedFlux == True, JDIC / depth, SOD_tc / roc / depth)

return da

Expand Down
29 changes: 24 additions & 5 deletions src/clearwater_modules/nsm1/dynamic_variables_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ class Variable(base.Variable):
)

Variable(
name='kah_T',
name='kah_tc',
long_name='Hydraulic oxygen reaeration rate adjusted for temperature',
units='1/d',
description='Hydraulic oxygen reaeration rate adjusted for temperature',
use='dynamic',
process=shared_processes.kah_T
process=shared_processes.kah_tc
)

Variable(
Expand All @@ -75,19 +75,38 @@ class Variable(base.Variable):
)

Variable(
name='kaw_T',
name='kaw_tc',
long_name='Wind oxygen reaeration velocity adjusted for temperature',
units='m/d',
description='Wind oxygen reaeration velocity adjusted for temperature',
use='dynamic',
process=shared_processes.kaw_T
process=shared_processes.kaw_tc
)

Variable(
name='ka_T',
name='ka_tc',
long_name='Oxygen reaeration rate',
units='1/d',
description='Oxygen reaeration rate',
use='dynamic',
process=shared_processes.ka_T
)


Variable(
name='L',
long_name='Light attenuation coefficient',
units='unitless',
description='Light attenuation coefficient',
use='dynamic',
process=processes.L
)

Variable(
name='PAR',
long_name='surface light intensity',
units='W/m2',
description='surface light intensity',
use='dynamic',
process=processes.PAR
)
4 changes: 2 additions & 2 deletions src/clearwater_modules/nsm1/nitrogen/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def NO3_AbGrowth(
return xr.where(use_Balgae, (AbUptakeFr_NO3 * rnb * Fb * AbGrowth) / depth, 0.0)

@numba.njit
def NH4_new(
def NH4(
dNH4dt: xr.DataArray,
NH4: xr.DataArray

Expand Down Expand Up @@ -621,7 +621,7 @@ def NO3(
return NO3 + dNO3dt*timestep

@numba.njit
def NO3_new(
def NO3(
dNO3dt: xr.DataArray,
NO3: xr.DataArray

Expand Down
8 changes: 0 additions & 8 deletions src/clearwater_modules/nsm1/nitrogen/static_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,3 @@ class Variable(base.Variable):
description='NH4 preference factor benthic algae (1=full NH4, 0=full NO3)',
use='static',
)

Variable(
name='vson',
long_name='OrgN settling velocity',
units='m/d',
description='OrgN settling velocity',
use='static',
)
4 changes: 2 additions & 2 deletions src/clearwater_modules/nsm1/pathogens/dynamic_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class Variable(base.Variable):
)

Variable(
name='PX_new',
name='PX',
long_name='New pathogen concentration',
units='cfu/100mL',
description='New pathogen concentration',
use='dynamic',
process=processes.PX_new
process=processes.PX
)
16 changes: 0 additions & 16 deletions src/clearwater_modules/nsm1/phosphorus/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,6 @@
import math


@numba.njit
def fdp(
use_TIP: bool,
Solid : xr.DataArray,
kdop4: xr.DataArray
) -> xr.DataArray :

"""Calculate kop_tc: Decay rate of organic P to DIP temperature correction (1/d).
Args:
use_TIP: true/false use total inorganic phosphrous,
Solid : #TODO define this
kdop4: solid partitioning coeff. of PO4 (L/kg)
"""

return xr.where(use_TIP, 1/(1+kdop4 * Solid/0.000001), 0)

@numba.njit
def kop_tc(
Expand Down
16 changes: 0 additions & 16 deletions src/clearwater_modules/nsm1/phosphorus/static_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,6 @@ class Variable(base.Variable):
use='static',
)

Variable(
name='vsop',
long_name='Orgnaic P settling velocity',
units='m/d',
description='Orgnaic P settling velocity',
use='static',
)


Variable(
name='vs',
long_name='Sediment settling velocity',
units='m/d',
description='Sediment settling velocity',
use='static',
)

Variable(
name='kdop4',
Expand Down
2 changes: 1 addition & 1 deletion src/clearwater_modules/nsm1/state_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def mock_equation(water_temp_c: float) -> float:
units='ug-Chla/L',
description='Algal Concentration',
use='state',
process=algae_processes.Ap_new
process=algae_processes.Ap
)

Variable(
Expand Down
8 changes: 0 additions & 8 deletions src/clearwater_modules/nsm1/static_variables_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,6 @@ class Variable(base.Variable):
use='static',
)

Variable(
name='wind_reaeration_option',
long_name='wind reaeration option',
units='unitless',
description='Integer value which selects method for computing wind oxygen reaeration velocity',
use='static',
)

#TODO figure out what Solid is
Variable(
name='Solid',
Expand Down
Loading

0 comments on commit 56cf704

Please sign in to comment.