Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOONE code improvements #4

Merged
merged 26 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
23acd8b
Refactor data.py in data module.
douggallup Dec 6, 2024
1f00bca
Refactoring / code cleanup for tp_variables_regions.py
douggallup Dec 6, 2024
e25f0a3
Added docstrings
douggallup Dec 9, 2024
a87d126
Code cleanup for utils module
douggallup Dec 9, 2024
6c7d63a
Refactoring for loone_nut module
douggallup Dec 9, 2024
f29c1d0
Fix function name
douggallup Dec 11, 2024
b36b4fe
Change to LOONE_WQ
douggallup Dec 11, 2024
fff0c20
Reverted typo fix
douggallup Dec 11, 2024
e002657
Fix parsing Date fields that got added by refactoring.
douggallup Dec 11, 2024
c20ff68
Fixed renamed function
douggallup Dec 11, 2024
1d5d605
Fix possible issue of whitespace in column names
douggallup Dec 11, 2024
d73773c
Fix def name
douggallup Dec 12, 2024
9e416bc
Code cleanup
douggallup Dec 12, 2024
26c96ba
Line break
douggallup Dec 12, 2024
470c15e
Code cleanup for LOONE_Q
douggallup Dec 12, 2024
547f0f1
Rename variable
douggallup Dec 12, 2024
acab226
Enhance loop
douggallup Dec 13, 2024
f94ec5f
Major refactoring of LOONE_Q into multiple subfunctions.
douggallup Dec 13, 2024
c14e14e
LOONE_WQ refactoring, moving code into functions.
douggallup Dec 13, 2024
3707e71
Minor code cleanup
douggallup Dec 16, 2024
c3259f9
Minor code cleanup
douggallup Dec 16, 2024
344553e
Fix for start_storage
douggallup Dec 16, 2024
7718633
Bias correction updates
douggallup Dec 19, 2024
dc4b7d1
Updates for cleanup
douggallup Dec 19, 2024
4630603
Added commit from:
douggallup Dec 19, 2024
23e0a92
Updated from commit:
douggallup Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Data prep
"""
from loone.loone_q import LOONE_Q
from loone.loone_nut import LOONE_NUT
from loone.loone_wq import LOONE_Constituent_SimQ
from loone.loone_wq import LOONE_WQ


LOONE_Q(
Expand All @@ -42,7 +42,7 @@ LOONE_NUT(
forecast_mode=True,
)

LOONE_Constituent_SimQ(workspace="/path/to/workspace")
LOONE_WQ(workspace="/path/to/workspace")
```


Expand Down
621 changes: 508 additions & 113 deletions loone/data/data.py

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions loone/data/model_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
class M_var:
"""Class to represents model variables."""
def __init__(self, config: dict):
"""
Initializes the M_var class with model variables.

This constructor sets up various model variables and arrays based on the provided configuration dictionary.
It calculates date ranges and initializes arrays for different time scales (daily, weekly, monthly)
and model parameters, including tributary conditions, seasonal classes, lake stages, supply, and outflows.

Args:
config (dict): A dictionary containing configuration parameters, including:
- "start_date_entry": A list of integers [year, month, day] for the start date.
- "end_date_entry": A list of integers [year, month, day] for the end date.
- "end_date_tc": A list of integers [year, month, day] for the end date of tributary conditions.
- "month_n": An integer representing the number of months for the LONINO seasonal classes.
"""
year, month, day = map(int, config["start_date_entry"])
startdate = datetime(year, month, day).date()
year, month, day = map(int, config["end_date_entry"])
Expand Down
161 changes: 86 additions & 75 deletions loone/data/tp_variables_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,80 +8,91 @@ class TP_Variables:
def __init__(self, working_path: str):
os.chdir(working_path)
config = load_config(working_path)
self.Z_sed = config['z_sed']
self.Per_H2O_M = config['per_h2o_m']
self.Per_H2O_S = config['per_h2o_s']
self.Per_H2O_R = config['per_h2o_r']
self.Per_H2O_P = config['per_h2o_p']
self.N_Per = config['n_per']
self.S_Per = config['s_per']
####
self.Bulk_density_M = config['bulk_density_m']
self.Bulk_density_S = config['bulk_density_s']
self.Bulk_density_R = config['bulk_density_r']
self.Bulk_density_P = config['bulk_density_p']
####
self.Particle_density_M = config['particle_density_m']
self.Particle_density_S = config['particle_density_s']
self.Particle_density_R = config['particle_density_r']
self.Particle_density_P = config['particle_density_p']
####
self.A_Mud_N = config['a_mud_n']
self.A_Mud_S = config['a_mud_s']
self.A_Sand_N = config['a_sand_n']
self.A_Sand_S = config['a_sand_s']
self.A_Rock_N = config['a_rock_n']
self.A_Rock_S = config['a_rock_s']
self.A_Peat_N = config['a_peat_n']
self.A_Peat_S = config['a_peat_s']
self.A_N = self.A_Mud_N + self.A_Sand_N + self.A_Rock_N + self.A_Peat_N
self.A_S = self.A_Mud_S + self.A_Sand_S + self.A_Rock_S + self.A_Peat_S
A_tot = self.A_N + self.A_S
self.Per_M_N = self.A_Mud_N / A_tot
self.Per_M_S = self.A_Mud_S / A_tot
self.Per_S_N = self.A_Sand_N / A_tot
self.Per_S_S = self.A_Sand_S / A_tot
self.Per_R_N = self.A_Rock_N / A_tot
self.Per_R_S = self.A_Rock_S / A_tot
self.Per_P_N = self.A_Peat_N / A_tot
self.Per_P_S = self.A_Peat_S / A_tot

self.Per_M_NN = self.A_Mud_N / self.A_N
self.Per_M_SS = self.A_Mud_S / self.A_S
self.Per_S_NN = self.A_Sand_N / self.A_N
self.Per_S_SS = self.A_Sand_S / self.A_S
self.Per_R_NN = self.A_Rock_N / self.A_N
self.Per_R_SS = self.A_Rock_S / self.A_S
self.Per_P_NN = self.A_Peat_N / self.A_N
self.Per_P_SS = self.A_Peat_S / self.A_S
self.Γ_inf = 91 # (mg/kg)
#####Monthly
self.v_burial_M = config["v_burial_m"]
self.v_burial_S = config["v_burial_s"]
self.v_burial_R = config["v_burial_r"]
self.v_burial_P = config["v_burial_p"]

# Sediment properties
self.sediment_depth = config['z_sed']
self.water_content_mud = config['per_h2o_m']
self.water_content_sand = config['per_h2o_s']
self.water_content_rock = config['per_h2o_r']
self.water_content_peat = config['per_h2o_p']
self.northern_percentage = config['n_per']
self.southern_percentage = config['s_per']

# Bulk density
self.bulk_density_mud = config['bulk_density_m']
self.bulk_density_sand = config['bulk_density_s']
self.bulk_density_rock = config['bulk_density_r']
self.bulk_density_peat = config['bulk_density_p']

# # Particle density
self.particle_density_mud = config['particle_density_m']
self.particle_density_sand = config['particle_density_s']
self.particle_density_rock = config['particle_density_r']
self.particle_density_peat = config['particle_density_p']

# # Area of sediments
self.area_mud_north = config['a_mud_n']
self.area_mud_south = config['a_mud_s']
self.area_sand_north = config['a_sand_n']
self.area_sand_south = config['a_sand_s']
self.area_rock_north = config['a_rock_n']
self.area_rock_south = config['a_rock_s']
self.area_peat_north = config['a_peat_n']
self.area_peat_south = config['a_peat_s']

self.total_area_north = self.area_mud_north + self.area_sand_north + self.area_rock_north + self.area_peat_north
self.total_area_south = self.area_mud_south + self.area_sand_south + self.area_rock_south + self.area_peat_south
total_area = self.total_area_north + self.total_area_south

# Percentage calculations
self.percentage_mud_north = self.area_mud_north / total_area
self.percentage_mud_south = self.area_mud_south / total_area
self.percentage_sand_north = self.area_sand_north / total_area
self.percentage_sand_south = self.area_sand_south / total_area
self.percentage_rock_north = self.area_rock_north / total_area
self.percentage_rock_south = self.area_rock_south / total_area
self.percentage_peat_north = self.area_peat_north / total_area
self.percentage_peat_south = self.area_peat_south / total_area

self.percentage_mud_north_n = self.area_mud_north / self.total_area_north
self.percentage_mud_south_s = self.area_mud_south / self.total_area_south
self.percentage_sand_north_n = self.area_sand_north / self.total_area_north
self.percentage_sand_south_s = self.area_sand_south / self.total_area_south
self.percentage_rock_north_n = self.area_rock_north / self.total_area_north
self.percentage_rock_south_s = self.area_rock_south / self.total_area_south
self.percentage_peat_north_n = self.area_peat_north / self.total_area_north
self.percentage_peat_south_s = self.area_peat_south / self.total_area_south

self.inorganic_fraction = 91 # (mg/kg)

# Burial velocities
self.burial_velocity_mud = config["v_burial_m"]
self.burial_velocity_sand = config["v_burial_s"]
self.burial_velocity_rock = config["v_burial_r"]
self.burial_velocity_peat = config["v_burial_p"]

# Read Calibration Outputs
Cal_Res = pd.read_csv(config["nondominated_sol_var"])

Par = Cal_Res["Par"]
self.v_diff_M = Par[0]
self.v_diff_S = Par[1]
self.v_diff_R = Par[2]
self.v_diff_P = Par[3]
####
self.K_decomp_M = Par[4]
self.K_decomp_S = Par[5]
self.K_decomp_R = Par[6]
self.K_decomp_P = Par[7]
###
self.K_des_M = Par[8]
self.K_des_S = Par[9]
self.K_des_R = Par[10]
self.K_des_P = Par[11]
####
self.K_ads_M = Par[12]
self.K_ads_S = Par[13]
self.K_ads_R = Par[14]
self.K_ads_P = Par[15]
# v_settle = Par[16]
calibration_results = pd.read_csv(config["nondominated_sol_var"])
parameters = calibration_results["Par"]

self.diffusion_velocity_mud = parameters[0]
self.diffusion_velocity_sand = parameters[1]
self.diffusion_velocity_rock = parameters[2]
self.diffusion_velocity_peat = parameters[3]

self.decomposition_rate_mud = parameters[4]
self.decomposition_rate_sand = parameters[5]
self.decomposition_rate_rock = parameters[6]
self.decomposition_rate_peat = parameters[7]

self.desorption_rate_mud = parameters[8]
self.desorption_rate_sand = parameters[9]
self.desorption_rate_rock = parameters[10]
self.desorption_rate_peat = parameters[11]

self.adsorption_rate_mud = parameters[12]
self.adsorption_rate_sand = parameters[13]
self.adsorption_rate_rock = parameters[14]
self.adsorption_rate_peat = parameters[15]

# self.settling_velocity = parameters[16] # Uncomment if needed
Loading