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

changed default alkalinity to prognostic in main setup only #136

Merged
merged 10 commits into from
Jul 24, 2024
3 changes: 2 additions & 1 deletion github-actions/fabm0d-gotm-ersem/aquarium_tut.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ def plot_var(axes, x, y, label):

# Plotting output data
output_data = ["N1_p", "N3_n", "B1_c", "P2_c"]
fig, ax_arr = plt.subplots(len(input_data), 1)
fig, ax_arr = plt.subplots(len(output_data), 1)
DPI = fig.get_dpi()
fig.set_size_inches(1200.0/float(DPI),800.0/float(DPI))
for ax, label in zip(ax_arr, output_data):
plot_var(ax, dates, data, label)
fig.suptitle("Output data")
print(test_vars.keys())
plt.show()

return test_vars
Expand Down
2 changes: 1 addition & 1 deletion github-actions/fabm0d-gotm-ersem/expected.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion github-actions/fabm0d-gotm-ersem/test_aquarium.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ def test_ncarbon_value(self):
"""
Checks the nanophytoplankton carbon (P2_c) values are the same
"""
name = "B1_c"
name = "P2_c"
assert np.allclose(self.expected[name], self.value_dict[name])
2 changes: 1 addition & 1 deletion github-actions/gotm-fabm-ersem/expected.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion github-actions/gotm-fabm-ersem/expected_state.json

Large diffs are not rendered by default.

75 changes: 0 additions & 75 deletions github-actions/gotm-fabm-ersem/regen_expected_results.py

This file was deleted.

8 changes: 0 additions & 8 deletions github-actions/gotm-fabm-ersem/test_state_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,6 @@ def test_O3_c_value(self):
assert np.array_equal(
self.expected[name], self.data.variables[name][:].squeeze()[-1, :])

def test_O3_bioalk_value(self):
"""
Checks the O3_bioalk values are the same
"""
name = "O3_bioalk"
assert np.array_equal(
self.expected[name], self.data.variables[name][:].squeeze()[-1, :])

def test_R1_c_value(self):
"""
Checks the R1_c values are the same
Expand Down
85 changes: 85 additions & 0 deletions github-actions/regen_expected_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import argparse
import json
import netCDF4 as nc
from numpy import ndarray, interp

class NumpyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, ndarray):
temp = [float(v) for v in obj.tolist()]
return temp
return json.JSONEncoder.default(self, obj)

parser = argparse.ArgumentParser()
parser.add_argument('-p', '--data-path', type=str, required=True,
help='Path to output file from model run')
parser.add_argument('-m', '--model-run', type=str, required=True,
help='Type of model run that has been run',
choices=["gotm", "fabm0d"])
args, _ = parser.parse_known_args()
data_path = args.data_path
model_run = args.model_run

dir_mapping = {"fabm0d": "fabm0d-gotm-ersem", "gotm": "gotm-fabm-ersem"}
if model_run == "gotm":
state_vars = [
"N1_p", "N3_n", "N4_n", "N5_s", "O2_o", "O3_c", "O3_bioalk", "R1_c", "R1_n",
"R1_p", "R2_c", "R3_c", "R4_c", "R4_n", "R4_p", "R6_c", "R6_n", "R6_p",
"R6_s", "R8_c", "R8_n", "R8_p", "R8_s", "B1_c", "B1_n", "B1_p", "P1_c",
"P1_n", "P1_p", "P1_Chl", "P1_s", "P2_c", "P2_n", "P2_p", "P2_Chl", "P3_c",
"P3_n", "P3_p", "P3_Chl", "P4_c", "P4_n", "P4_p", "P4_Chl", "Z4_c", "Z5_c",
"Z5_n", "Z5_p", "Z6_c", "Z6_n", "Z6_p", "L2_c", "Q1_c", "Q1_p", "Q1_n",
"Q6_c", "Q6_p", "Q6_n", "Q6_s", "Q6_pen_depth_c", "Q6_pen_depth_n",
"Q6_pen_depth_p", "Q6_pen_depth_s", "Q7_c", "Q7_p", "Q7_n", "Q7_pen_depth_c",
"Q7_pen_depth_n", "Q7_pen_depth_p", "Q17_c", "Q17_p", "Q17_n", "bL2_c",
"ben_col_D1m", "ben_col_D2m", "K1_p", "K3_n", "K4_n", "K5_s", "G2_o",
"G2_o_deep", "G3_c", "ben_nit_G4n", "H1_c", "H2_c", "Y2_c", "Y3_c",
"Y4_c"
]
vars_of_interest = ["dates", "N1_p", "N3_n", "N5_s"]
data_dict = {"expected": vars_of_interest, "expected_state": state_vars}

elif model_run == "fabm0d":
vars_of_interest = [
"dates", "light_parEIR", "temp", "salt", "N1_p", "N3_n", "B1_c", "P2_c"
]

data_dict = {"expected": vars_of_interest}

for key, items in data_dict.items():
data = nc.Dataset(data_path, 'r')
expected_results = {}
for v in items:
try:
if v == "dates":
times = data.variables['time']
dates = nc.num2date(times[:],
units=times.units,
calendar=times.calendar)
dates = [str(d).split(" ")[0] for d in dates]
expected_results[v] = dates
elif key == "expected" and model_run == "gotm":
depth = 0.0
var = data.variables[v]
zi = data.variables['zi'][:].squeeze()
z = data.variables['z'][:].squeeze()
var_time_series = []
for i in range(var.shape[0]):
depth_offset = depth + zi[i, -1]
var_time_series.append(interp(depth_offset, z[i, :], var[i, :].squeeze()))
expected_results[v] = var_time_series

elif data.variables[v].ndim == 4:
expected_results[v] = data.variables[v][:].squeeze() \
if model_run == "fabm0d" else expected_results[v][-1, :]
elif data.variables[v].ndim == 3:
expected_results[v] = data.variables[v][:].squeeze() \
if model_run == "fabm0d" else \
float(data.variables[v][:].squeeze()[-1])
else:
raise RuntimeError
except Exception as e:
print(f"Did not update {v} since {e}")

with open(f'{dir_mapping[model_run]}/{key}.json', 'w') as f:
json.dump(expected_results, f, cls=NumpyEncoder)
5 changes: 2 additions & 3 deletions testcases/fabm-ersem-15.06-L4-ben-docdyn-iop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ instances:
parameters:
iswCO2: 1 # carbonate system diagnostics (0: off, 1: on), default = 1
iswASFLUX: 1 # air-sea CO2 exchange (0: none, 1: Nightingale et al. 2000, 2: Wanninkhof 1992 without chemical enhancement, 3: Wanninkhof 1992 with chemical enhancement, 4: Wanninkhof and McGillis 1999, 5: Wanninkhof 1992 switching to Wanninkhof and McGillis 1999, 6: Wan, default = 6
iswtalk: 2 # alkalinity formulation (1-4: from salinity and temperature, 5: dynamic alkalinity), default = 5
iswtalk: 5 # alkalinity formulation (1-4: from salinity and temperature, 5: dynamic alkalinity), default = 5
pHscale: 1 # pH scale (1: total, 0: SWS, -1: SWS backward compatible), default = 1
iswbioalk: 1 # use bioalkalinity (0: off, 1: on), default = 1
initialization:
c: 2130.0 # total dissolved inorganic carbon (mmol C/m^3)
bioalk: 0 # bioalkalinity (mmol/m^3)
TA: 2300.0 # total alkalinity (mmol/m^3)
R1:
long_name: labile dissolved organic matter
model: ersem/pelagic_base
Expand Down
Loading