Skip to content
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cae9757
jbibkbkj
maagusrm Jun 25, 2024
b361348
Revert "jbibkbkj"
maagusrm Jun 25, 2024
a4335a7
add experiments module
maagusrm Jun 25, 2024
03b9cdf
return to previous
maagusrm Jun 26, 2024
709ff94
added calculate_burial
maagusrm Jun 26, 2024
7a74bd4
chore(esbmtk): Fix formatting in experiments.py file
uliw Jun 26, 2024
61e9fee
commiting uli change
maagusrm Jun 26, 2024
ba6c1c4
chore(src/esbmtk): refactor code formatting for clarity and consistency
uliw Jun 26, 2024
79b40cb
function in proper format
maagusrm Jun 26, 2024
87f2170
changed function
maagusrm Jun 26, 2024
4016700
cleaned up code
maagusrm Jun 27, 2024
a272e00
updated with correct inputs?
maagusrm Jun 27, 2024
6753d99
restructured experiment
maagusrm Jun 27, 2024
a68f23b
removed unaccessed esbmtk imports to test if q is a problem
maagusrm Jun 27, 2024
405786c
added p
maagusrm Jun 27, 2024
1f36c11
changed frac_burial
maagusrm Jun 27, 2024
86368b6
fixing p
maagusrm Jun 27, 2024
fac4082
changes to p
maagusrm Jun 27, 2024
d3ab502
new sync
maagusrm Jun 27, 2024
0354fee
change dbv to query
maagusrm Jun 27, 2024
02f64ce
changed registry
maagusrm Jun 27, 2024
7115eab
cleaned up structure
maagusrm Jun 28, 2024
aabaf1e
after looking at documentation, source is properly registered
maagusrm Jun 28, 2024
a75841f
added debug messaged
maagusrm Jun 28, 2024
2f0a85f
still same species properties error
maagusrm Jun 28, 2024
68195cd
Merge branch 'uliw:magnus' into magnus
maagusrm Jun 29, 2024
5070198
persistent error
maagusrm Jul 2, 2024
12f27c7
Merge branch 'uliw:magnus' into magnus
maagusrm Jul 2, 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
83 changes: 83 additions & 0 deletions src/esbmtk/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,86 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

from esbmtk import (
ExternalCode,
register_return_values,
)


def calculate_burial(po4_export_flux: float, o2_c: float, p: tuple) -> float:
"""#add an empty tuple
Calculate burial as a function of productivity and oxygen concentration.

:param po4_export_flux: Surface ocean productivity in umol/L
:type po4_export_flux: float
:param o2_con: Oxygen concentration in the deep box in umol/L
:type o2_con: float
:return: Burial flux in mol/year
:rtype: float
"""
frac_burial, dbv, min_burial_fraction, max_burial_fraction = p

frac_burial = min_burial_fraction + (max_burial_fraction - min_burial_fraction) * (
o2_c / 100
)

# productivity in mol/year
productivity_mol_year = po4_export_flux * dbv * 1e-6 # Convert umol/L to mol

burial_flux = productivity_mol_year * frac_burial
return burial_flux


def add_my_burial(
source,
sink,
species,
o2_c,
po4_export_flux: float,
frac_burial,
min_burial_fraction,
max_burial_fraction,
) -> None:
"""
This function initializes a user supplied function so that it can be used within the ESBMTK ecosystem.

Parameters
----------
source : Source | Species | Reservoir
A source
sink : Sink | Species | Reservoir
A sink
species : SpeciesProperties
A model species
po4_export_flux : float
PO4 export flux in umol/L
o2_c : float
Oxygen concentration in umol/L
frac_burial : float
A scaling factor of burial fraction
min_burial_fraction : float
Minimum burial fraction
max_burial_fraction : float
Maximum burial fraction
"""
print(f"Type of source: {type(source)}")
print(f"Type of sink: {type(sink)}")
print(f"Type of species: {type(species)}")

dbv = source.volume

p = (frac_burial, dbv, min_burial_fraction, max_burial_fraction) # float into tuple
print(f"Source name: {source.full_name}")
ec = ExternalCode(
name="calculate_burial",
species=species,
function=calculate_burial,
fname="calculate_burial",
function_input_data=[po4_export_flux, o2_c],
function_params=p,
return_values=[
{f"F_{sink.name}.{species.name}": "burial_flux"},
],
register=source,
)
register_return_values(ec, source)