Skip to content

Commit

Permalink
Fixing that hc is only required in 3D
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvansebille committed Nov 25, 2024
1 parent 4195fc9 commit bd2e6c0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions parcels/fieldset.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def from_croco(
filenames,
variables,
dimensions,
hc: float,
hc: float | None = None,
indices=None,
mesh="spherical",
allow_time_extrapolation=None,
Expand All @@ -728,8 +728,8 @@ def from_croco(
fields from CROCO, in order to account for the sigma-grid.
The horizontal interpolation uses the MITgcm grid indexing as described in FieldSet.from_mitgcm().
The sigma grid scaling means that FieldSet.from_croco() requires variables
``H: h`` and ``Zeta: zeta``, as well as he ``hc`` parameter to work.
In 3D, when there is a ``depth`` dimension, the sigma grid scaling means that FieldSet.from_croco()
requires variables ``H: h`` and ``Zeta: zeta``, as well as he ``hc`` parameter to work.
See `the CROCO 3D tutorial <../examples/tutorial_croco_3D.ipynb>`__ for more infomation.
"""
Expand All @@ -741,17 +741,19 @@ def from_croco(
)

dimsU = dimensions["U"] if "U" in dimensions else dimensions
if "depth" in dimsU:
croco3D = True if "depth" in dimsU else False

if croco3D:
if "W" in variables and variables["W"] == "omega":
warnings.warn(
"Note that Parcels expects 'w' for vertical velicites in 3D CROCO fields.\nSee https://docs.oceanparcels.org/en/latest/examples/tutorial_croco_3D.html for more information",
FieldSetWarning,
stacklevel=2,
)
if "H" not in variables:
raise ValueError("FieldSet.from_croco() requires a field 'H' for the bathymetry")
raise ValueError("FieldSet.from_croco() requires a bathymetry field 'H' for 3D CROCO fields")
if "Zeta" not in variables:
raise ValueError("FieldSet.from_croco() requires a field 'Zeta' for the free_surface")
raise ValueError("FieldSet.from_croco() requires a free-surface field 'Zeta' for 3D CROCO fields")

interp_method = {}
for v in variables:
Expand Down Expand Up @@ -781,7 +783,10 @@ def from_croco(
gridindexingtype="croco",
**kwargs,
)
fieldset.add_constant("hc", hc)
if croco3D:
if hc is None:
raise ValueError("FieldSet.from_croco() requires the hc parameter for 3D CROCO fields")
fieldset.add_constant("hc", hc)
return fieldset

@classmethod
Expand Down

0 comments on commit bd2e6c0

Please sign in to comment.