Skip to content

Commit

Permalink
Merge branch 'master' into 95-code-breaks-if-iswcal=0
Browse files Browse the repository at this point in the history
  • Loading branch information
wathen authored Jun 27, 2024
2 parents c72d53d + eb6acc1 commit 24cf361
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 16 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ersem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ jobs:
with:
python-version: '3.x'
- name: Installing GOTM-FABM-ERSEM dependences
run: ./github-actions/gotm-fabm-ersem/gotm-fabm-ersem-dep-debian.sh
run: ./github-actions/gotm-fabm-ersem/gotm-fabm-ersem-dep-debian.sh
- name: Building and installing GOTM-FABM-ERSEM
run: |
BRANCH=${{ github.head_ref }}
./github-actions/gotm-fabm-ersem/gotm-fabm-ersem-build.sh -b $BRANCH
./github-actions/gotm-fabm-ersem/gotm-fabm-ersem-build.sh -b $BRANCH -f '-DCMAKE_Fortran_FLAGS="-fcheck=all"'
- name: Running tutorial
run: |
./github-actions/gotm-fabm-ersem/gotm-tut-config-setup.sh
Expand All @@ -70,7 +70,7 @@ jobs:
- name: Building and installing FABM0d-GOTM-ERSEM
run: |
BRANCH=${{ github.head_ref }}
./github-actions/fabm0d-gotm-ersem/fabm0d-gotm-ersem-build.sh -b $BRANCH
./github-actions/fabm0d-gotm-ersem/fabm0d-gotm-ersem-build.sh -b $BRANCH -f '-DCMAKE_Fortran_FLAGS="-fcheck=all"'
- name: Running tutorial
run: |
./github-actions/fabm0d-gotm-ersem/aquarium-tut-config-setup.sh
Expand All @@ -90,11 +90,11 @@ jobs:
with:
python-version: '3.x'
- name: Installing GOTM-FABM-ERSEM dependences
run: ./github-actions/gotm-fabm-ersem/gotm-fabm-ersem-dep-debian.sh
run: ./github-actions/gotm-fabm-ersem/gotm-fabm-ersem-dep-debian.sh
- name: Building and installing GOTM-FABM-ERSEM
run: |
BRANCH=${{ github.head_ref }}
./github-actions/gotm-fabm-ersem/gotm-fabm-ersem-build.sh -f "-DCMAKE_Fortran_FLAGS="-pg"" -b $BRANCH
./github-actions/gotm-fabm-ersem/gotm-fabm-ersem-build.sh -f "-DCMAKE_Fortran_FLAGS="-pg -fcheck=all"" -b $BRANCH
- name: Running config
run: |
./github-actions/gotm-fabm-ersem/gotm-profiling.sh
Expand Down
9 changes: 8 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.8"

# Build documentation in the docs/ directory with Sphinx
sphinx:
builder: html
Expand All @@ -15,6 +21,7 @@ formats:
- pdf

python:
version: 3.8
install:
- requirements: docs/requirements.txt
- method: pip
path: .
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Tests](https://github.com/pmlmodelling/ersem/workflows/build-ersem/badge.svg)
![Tests](https://img.shields.io/github/actions/workflow/status/pmlmodelling/ersem/ersem.yml?label=tests&style=flat-square)
[![Documentation Status](https://readthedocs.org/projects/ersem/badge/?version=latest)](https://ersem.readthedocs.io/en/latest/?badge=latest)

# ERSEM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ git clone https://github.com/fabm-model/fabm.git

echo "Cloning GOTM"
git clone https://github.com/gotm-model/code.git gotm
# Od driver needs a stable version of GOTM, currently that is v6
cd gotm && git checkout v6.0 && git submodule update --init --recursive && cd ..

echo "Checking out branch: $BRANCH"
Expand Down
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.

2 changes: 1 addition & 1 deletion github-actions/gotm-fabm-ersem/gotm-tut-config-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ cp ersem/testcases/fabm-ersem-15.06-L4-ben-docdyn-iop.yaml ersem-setups/L4/fabm.
cd ersem-setups/L4

echo "Running GOTM with repo configuration"
~/local/gotm/bin/gotm
~/local/gotm/bin/gotm --ignore_unknown_config
1 change: 1 addition & 0 deletions github-actions/gotm-fabm-ersem/gotm_tut.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
import re


try:
import netCDF4 as nc
except ImportError:
Expand Down
75 changes: 75 additions & 0 deletions github-actions/gotm-fabm-ersem/regen_expected_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""
Script that regenerates expected results. You will need to install GOTM on your machine
first and use those results to regenerate the expected values
"""


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 GOTM run')
args, _ = parser.parse_known_args()
data_path = args.data_path

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"]

gotm_vars_test = ["dates", "N1_p", "N3_n", "N5_s"]

data_dict = {"expected": gotm_vars_test, "expected_state": state_vars}

for key, items in data_dict.items():
data = nc.Dataset(data_path, 'r')
expected_results = {}
for v in items:
if key == "expected":
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
else:
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()[-1, :]
elif data.variables[v].ndim == 3:
expected_results[v] = float(data.variables[v][:].squeeze()[-1])
else:
raise RuntimeError

with open(f'{key}.json', 'w') as f:
json.dump(expected_results, f, cls=NumpyEncoder)

3 changes: 1 addition & 2 deletions github-actions/pyfabm-ersem/pyfabm_tut.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from matplotlib import cm
import matplotlib.pylab as plt
import numpy as np
import os
Expand Down Expand Up @@ -70,7 +69,7 @@ def main():
axes = plt.gca()

# Set color map
cmap = cm.get_cmap('YlOrRd')
cmap = plt.colormaps.get_cmap('YlOrRd')

# Plot
plot = axes.pcolormesh(salinity_array,
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[project]
name = "ERSEM"
dynamic = ["version"]
authors = [{ name = "PML modelling" }]
readme = "README.md"
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ add_library(fabm_models_ersem OBJECT
zenith_angle.F90
)

add_dependencies(fabm_models_ersem fabm_base)
target_link_libraries(fabm_models_ersem PRIVATE fabm_base)

if(FABM_EMBED_VERSION)
# Dynamically generate "ersem_version" module with git commit/branch information at every build.
Expand Down
4 changes: 2 additions & 2 deletions src/bacteria_docdyn.F90
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ subroutine initialize(self,configunit)
call self%register_diagnostic_variable(self%id_fR2B1c,'fR2B1c','mg C/m^3/d','uptake of semi-labile DOC ')
call self%register_diagnostic_variable(self%id_fR3B1c,'fR3B1c','mg C/m^3/d','uptake of semi-refractory DOC ')
call self%register_diagnostic_variable(self%id_fRPB1c,'fRPB1c','mg C/m^3/d','total uptake of POC')
call self%register_diagnostic_variable(self%id_fRPB1n,'fRPB1n','mg N/m^3/d','total uptake of PON')
call self%register_diagnostic_variable(self%id_fRPB1p,'fRPB1p','mg P/m^3/d','total uptake of POP')
call self%register_diagnostic_variable(self%id_fRPB1n,'fRPB1n','mmol N/m^3/d','total uptake of PON')
call self%register_diagnostic_variable(self%id_fRPB1p,'fRPB1p','mmol P/m^3/d','total uptake of POP')
call self%register_diagnostic_variable(self%id_fR1B1n,'fR1B1n','mmol N/m^3/d','uptake of DON')
call self%register_diagnostic_variable(self%id_fR1B1p,'fR1B1p','mmol P/m^3/d','uptake of DOP')

Expand Down
3 changes: 2 additions & 1 deletion src/pelagic_base.F90
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ subroutine do_bottom(self,_ARGUMENTS_DO_BOTTOM_)

! Retrieve sinking rate (at centre of cell closest to the bottom)
! NB by ERSEM convention, this rate is returned in m/d, positive for sinking, negative for floating!
w = self%get_sinking_rate(_ARGUMENTS_LOCAL_)
! Avoid negative sinking rate across the pelagic-benthic boundary to stop mass being moved from benthos to pelagic as conceptually incorrect for vertical movement
w = max(0._rk,self%get_sinking_rate(_ARGUMENTS_LOCAL_))

! Store near-bed vertical velocity. Use FABM convention (m/s, negative for downward) to
! allow this custom fuctionality to be ultimately be replaced by a FABM API.
Expand Down

0 comments on commit 24cf361

Please sign in to comment.