From b223242794231f8bfbee282c1050a73fca834b50 Mon Sep 17 00:00:00 2001 From: kewalak Date: Mon, 26 Feb 2024 16:57:00 -0800 Subject: [PATCH] Moving global variables and removing repeats -Edited DOX for repeat global variables -Removed repeat vson, vsoc, vsop, and vs -removed _new and changed _T to _tc -moved L, fdp, and PAR to shared processes --- .../nsm1/DOX/static_variables.py | 47 ---------- .../nsm1/algae/dynamic_variables.py | 18 ---- .../nsm1/algae/processes.py | 52 ----------- .../nsm1/balgae/processes.py | 2 +- .../nsm1/carbon/processes.py | 14 +-- .../nsm1/dynamic_variables_global.py | 29 +++++-- .../nsm1/nitrogen/processes.py | 4 +- .../nsm1/nitrogen/static_variables.py | 8 -- .../nsm1/pathogens/dynamic_variables.py | 4 +- .../nsm1/phosphorus/processes.py | 16 ---- .../nsm1/phosphorus/static_variables.py | 16 ---- .../nsm1/state_variables.py | 2 +- .../nsm1/static_variables_global.py | 8 -- src/clearwater_modules/shared/processes.py | 86 +++++++++++++++++-- 14 files changed, 115 insertions(+), 191 deletions(-) diff --git a/src/clearwater_modules/nsm1/DOX/static_variables.py b/src/clearwater_modules/nsm1/DOX/static_variables.py index 4cfe567..2a3397c 100644 --- a/src/clearwater_modules/nsm1/DOX/static_variables.py +++ b/src/clearwater_modules/nsm1/DOX/static_variables.py @@ -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', diff --git a/src/clearwater_modules/nsm1/algae/dynamic_variables.py b/src/clearwater_modules/nsm1/algae/dynamic_variables.py index 01bc736..029d534 100644 --- a/src/clearwater_modules/nsm1/algae/dynamic_variables.py +++ b/src/clearwater_modules/nsm1/algae/dynamic_variables.py @@ -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', diff --git a/src/clearwater_modules/nsm1/algae/processes.py b/src/clearwater_modules/nsm1/algae/processes.py index 5ec8e77..e232666 100644 --- a/src/clearwater_modules/nsm1/algae/processes.py +++ b/src/clearwater_modules/nsm1/algae/processes.py @@ -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( diff --git a/src/clearwater_modules/nsm1/balgae/processes.py b/src/clearwater_modules/nsm1/balgae/processes.py index e94423f..f582708 100644 --- a/src/clearwater_modules/nsm1/balgae/processes.py +++ b/src/clearwater_modules/nsm1/balgae/processes.py @@ -298,7 +298,7 @@ def dAbdt( return AbGrowth - AbRespiration - AbDeath @numba.njit -def Ab_new( +def Ab( Ab: xr.DataArray, dAbdt: xr.DataArray diff --git a/src/clearwater_modules/nsm1/carbon/processes.py b/src/clearwater_modules/nsm1/carbon/processes.py index bc5c9b2..0063797 100644 --- a/src/clearwater_modules/nsm1/carbon/processes.py +++ b/src/clearwater_modules/nsm1/carbon/processes.py @@ -118,7 +118,7 @@ def dPOCdt( @numba.njit -def POC_new( +def POC( POC: xr.DataArray, dPOCdt: xr.DataArray, timestep: xr.DataArray @@ -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, @@ -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( @@ -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, @@ -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 diff --git a/src/clearwater_modules/nsm1/dynamic_variables_global.py b/src/clearwater_modules/nsm1/dynamic_variables_global.py index 02a7187..22eb811 100644 --- a/src/clearwater_modules/nsm1/dynamic_variables_global.py +++ b/src/clearwater_modules/nsm1/dynamic_variables_global.py @@ -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( @@ -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 +) diff --git a/src/clearwater_modules/nsm1/nitrogen/processes.py b/src/clearwater_modules/nsm1/nitrogen/processes.py index 63e0f96..32f7409 100644 --- a/src/clearwater_modules/nsm1/nitrogen/processes.py +++ b/src/clearwater_modules/nsm1/nitrogen/processes.py @@ -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 @@ -621,7 +621,7 @@ def NO3( return NO3 + dNO3dt*timestep @numba.njit -def NO3_new( +def NO3( dNO3dt: xr.DataArray, NO3: xr.DataArray diff --git a/src/clearwater_modules/nsm1/nitrogen/static_variables.py b/src/clearwater_modules/nsm1/nitrogen/static_variables.py index 6fc73de..52934db 100644 --- a/src/clearwater_modules/nsm1/nitrogen/static_variables.py +++ b/src/clearwater_modules/nsm1/nitrogen/static_variables.py @@ -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', -) diff --git a/src/clearwater_modules/nsm1/pathogens/dynamic_variables.py b/src/clearwater_modules/nsm1/pathogens/dynamic_variables.py index 5b82ec8..5522925 100644 --- a/src/clearwater_modules/nsm1/pathogens/dynamic_variables.py +++ b/src/clearwater_modules/nsm1/pathogens/dynamic_variables.py @@ -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 ) \ No newline at end of file diff --git a/src/clearwater_modules/nsm1/phosphorus/processes.py b/src/clearwater_modules/nsm1/phosphorus/processes.py index ae5e23d..2ec7bc9 100644 --- a/src/clearwater_modules/nsm1/phosphorus/processes.py +++ b/src/clearwater_modules/nsm1/phosphorus/processes.py @@ -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( diff --git a/src/clearwater_modules/nsm1/phosphorus/static_variables.py b/src/clearwater_modules/nsm1/phosphorus/static_variables.py index bdb1b4f..91e5d20 100644 --- a/src/clearwater_modules/nsm1/phosphorus/static_variables.py +++ b/src/clearwater_modules/nsm1/phosphorus/static_variables.py @@ -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', diff --git a/src/clearwater_modules/nsm1/state_variables.py b/src/clearwater_modules/nsm1/state_variables.py index cce553f..b986abd 100644 --- a/src/clearwater_modules/nsm1/state_variables.py +++ b/src/clearwater_modules/nsm1/state_variables.py @@ -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( diff --git a/src/clearwater_modules/nsm1/static_variables_global.py b/src/clearwater_modules/nsm1/static_variables_global.py index f15cfcd..2ee029a 100644 --- a/src/clearwater_modules/nsm1/static_variables_global.py +++ b/src/clearwater_modules/nsm1/static_variables_global.py @@ -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', diff --git a/src/clearwater_modules/shared/processes.py b/src/clearwater_modules/shared/processes.py index 3a6b151..b6a1285 100644 --- a/src/clearwater_modules/shared/processes.py +++ b/src/clearwater_modules/shared/processes.py @@ -99,7 +99,7 @@ def kah_20( @numba.njit -def kah_T( +def kah_tc( water_temp_c: xr.DataArray, kah_20: xr.DataArray, theta: xr.DataArray @@ -147,7 +147,7 @@ def kaw_20( @numba.njit -def kaw_T( +def kaw_tc( water_temp_c: xr.DataArray, kaw_20: xr.DataArray, theta: xr.DataArray @@ -163,19 +163,19 @@ def kaw_T( @numba.njit -def ka_T( - kah_T: xr.DataArray, - kaw_T: xr.DataArray, +def ka_tc( + kah_tc: xr.DataArray, + kaw_tc: xr.DataArray, depth: xr.DataArray ) -> xr.DataArray: """Compute the oxygen reaeration rate, adjusted for temperature (1/d) Args: - kah_T: Oxygen reaeration rate adjusted for temperature (1/d) - kaw_T: Wind oxygen reaeration velocity adjusted for temperature (m/d) + kah_tc: Oxygen reaeration rate adjusted for temperature (1/d) + kaw_tc: Wind oxygen reaeration velocity adjusted for temperature (m/d) depth: Average water depth in cell (m) """ - return kaw_T / depth + kah_T + return kaw_tc / depth + kah_tc def SOD_tc( SOD_20: xr.DataArray, @@ -198,3 +198,73 @@ def SOD_tc( da: xr.DataArray = xr.where(use_DOX == True, SOD_tc * DOX / (DOX + KsSOD), SOD_tc) return da + +@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 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)