Skip to content

Commit 5be9ea2

Browse files
Removing FieldSet.from_pop()
As it uses som field data manipulation that will have to be done by the user in xarray in v4
1 parent 29798dc commit 5be9ea2

File tree

5 files changed

+8
-109
lines changed

5 files changed

+8
-109
lines changed

docs/examples/documentation_indexing.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
"\n",
240240
"Interpolation for Arakawa B-grids is detailed in [Section 2.1.3 of Delandmeter and Van Sebille (2019)](https://www.geosci-model-dev.net/12/3571/2019/gmd-12-3571-2019.html). Again, the dimensions that need to be provided are those of the barycentric cell edges `(i, j, k)`.\n",
241241
"\n",
242-
"To load B-grid data, you can use the method `FieldSet.from_b_grid_dataset`, or specifically in the case of POP-model data `FieldSet.from_pop`.\n"
242+
"To load B-grid data, you can use the method `FieldSet.from_b_grid_dataset`.\n"
243243
]
244244
},
245245
{

parcels/fieldset.py

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -754,113 +754,6 @@ def from_c_grid_dataset(
754754
**kwargs,
755755
)
756756

757-
@classmethod
758-
def from_pop(
759-
cls,
760-
filenames,
761-
variables,
762-
dimensions,
763-
mesh: Mesh = "spherical",
764-
allow_time_extrapolation: bool | None = None,
765-
tracer_interp_method: InterpMethodOption = "bgrid_tracer",
766-
depth_units="m",
767-
**kwargs,
768-
):
769-
"""Initialises FieldSet object from NetCDF files of POP fields.
770-
It is assumed that the velocities in the POP fields is in cm/s.
771-
772-
Parameters
773-
----------
774-
filenames :
775-
Dictionary mapping variables to file(s). The
776-
filepath may contain wildcards to indicate multiple files,
777-
or be a list of file.
778-
filenames can be a list ``[files]``, a dictionary ``{var:[files]}``,
779-
a dictionary ``{dim:[files]}`` (if lon, lat, depth and/or data not stored in same files as data),
780-
or a dictionary of dictionaries ``{var:{dim:[files]}}``
781-
time values are in ``filenames[data]``
782-
variables : dict
783-
Dictionary mapping variables to variable names in the netCDF file(s).
784-
Note that the built-in Advection kernels assume that U and V are in m/s
785-
dimensions : dict
786-
Dictionary mapping data dimensions (lon,
787-
lat, depth, time, data) to dimensions in the netCF file(s).
788-
Note that dimensions can also be a dictionary of dictionaries if
789-
dimension names are different for each variable.
790-
Watch out: POP is discretised on a B-grid:
791-
U and V velocity nodes are not located as W velocity and T tracer nodes (see http://www2.cesm.ucar.edu/models/cesm1.0/pop2/doc/sci/POPRefManual.pdf ). ::
792-
793-
+-----------------------------+-----------------------------+-----------------------------+
794-
|U[k,j+1,i],V[k,j+1,i] | |U[k,j+1,i+1],V[k,j+1,i+1] |
795-
+-----------------------------+-----------------------------+-----------------------------+
796-
| |W[k:k+2,j+1,i+1],T[k,j+1,i+1]| |
797-
+-----------------------------+-----------------------------+-----------------------------+
798-
|U[k,j,i],V[k,j,i] | |U[k,j,i+1],V[k,j,i+1] |
799-
+-----------------------------+-----------------------------+-----------------------------+
800-
801-
In 2D: U and V nodes are on the cell vertices and interpolated bilinearly as a A-grid.
802-
T node is at the cell centre and interpolated constant per cell as a C-grid.
803-
In 3D: U and V nodes are at the middle of the cell vertical edges,
804-
They are interpolated bilinearly (independently of z) in the cell.
805-
W nodes are at the centre of the horizontal interfaces.
806-
They are interpolated linearly (as a function of z) in the cell.
807-
T node is at the cell centre, and constant per cell.
808-
Note that Parcels assumes that the length of the depth dimension (at the W-points)
809-
is one larger than the size of the velocity and tracer fields in the depth dimension.
810-
fieldtype :
811-
Optional dictionary mapping fields to fieldtypes to be used for UnitConverter.
812-
(either 'U', 'V', 'Kh_zonal', 'Kh_meridional' or None)
813-
mesh : str
814-
String indicating the type of mesh coordinates and
815-
units used during velocity interpolation, see also `this tutorial <../examples/tutorial_unitconverters.ipynb>`__:
816-
817-
1. spherical (default): Lat and lon in degree, with a
818-
correction for zonal velocity U near the poles.
819-
2. flat: No conversion, lat/lon are assumed to be in m.
820-
allow_time_extrapolation : bool
821-
boolean whether to allow for extrapolation
822-
(i.e. beyond the last available time snapshot)
823-
Default is False if dimensions includes time, else True
824-
tracer_interp_method : str
825-
Method for interpolation of tracer fields. It is recommended to use 'bgrid_tracer' (default)
826-
Note that in the case of from_pop() and from_b_grid_dataset(), the velocity fields are default to 'bgrid_velocity'
827-
depth_units :
828-
The units of the vertical dimension. Default in Parcels is 'm',
829-
but many POP outputs are in 'cm'
830-
**kwargs :
831-
Keyword arguments passed to the :func:`Fieldset.from_b_grid_dataset` constructor.
832-
833-
"""
834-
if "creation_log" not in kwargs.keys():
835-
kwargs["creation_log"] = "from_pop"
836-
fieldset = cls.from_b_grid_dataset(
837-
filenames,
838-
variables,
839-
dimensions,
840-
mesh=mesh,
841-
allow_time_extrapolation=allow_time_extrapolation,
842-
tracer_interp_method=tracer_interp_method,
843-
gridindexingtype="pop",
844-
**kwargs,
845-
)
846-
if hasattr(fieldset, "U"):
847-
fieldset.U.set_scaling_factor(0.01) # cm/s to m/s
848-
if hasattr(fieldset, "V"):
849-
fieldset.V.set_scaling_factor(0.01) # cm/s to m/s
850-
if hasattr(fieldset, "W"):
851-
if depth_units == "m":
852-
fieldset.W.set_scaling_factor(-0.01) # cm/s to m/s and change the W direction
853-
warnings.warn(
854-
"Parcels assumes depth in POP output to be in 'm'. Use depth_units='cm' if the output depth is in 'cm'.",
855-
FieldSetWarning,
856-
stacklevel=2,
857-
)
858-
elif depth_units == "cm":
859-
fieldset.W.set_scaling_factor(-1.0) # change the W direction but keep W in cm/s because depth is in cm
860-
else:
861-
raise SyntaxError("'depth_units' has to be 'm' or 'cm'")
862-
return fieldset
863-
864757
@classmethod
865758
def from_mom5(
866759
cls,

tests/test_fieldset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,8 @@ def generate_dataset(xdim, ydim, zdim=1, tdim=1):
659659
assert np.allclose(pset.lon_nextloop[0], 5.0) and np.allclose(pset.lat_nextloop[0], 10)
660660

661661

662+
@pytest.mark.v4alpha
663+
@pytest.mark.xfail(reason="From_pop is not supported during v4-alpha development. This will be reconsidered in v4.")
662664
def test_fieldset_frompop():
663665
filenames = str(TEST_DATA / "POPtestdata_time.nc")
664666
variables = {"U": "U", "V": "V", "W": "W", "T": "T"}

tests/test_grids.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ def sampleVel(particle, fieldset, time): # pragma: no cover
575575
assert abs(pset[0].vertical - 1) < 1e-3
576576

577577

578+
@pytest.mark.v4alpha
579+
@pytest.mark.xfail(reason="From_pop is not supported during v4-alpha development. This will be reconsidered in v4.")
578580
@pytest.mark.parametrize("vert_discretisation", ["zlevel", "slevel", "slevel2"])
579581
def test_popgrid(vert_discretisation):
580582
if vert_discretisation == "zlevel":
@@ -868,7 +870,7 @@ def UpdateR(particle, fieldset, time): # pragma: no cover
868870
assert np.allclose(pset.radius, pset.radius_start, atol=10)
869871

870872

871-
@pytest.mark.parametrize("gridindexingtype", ["pop", "mom5"])
873+
@pytest.mark.parametrize("gridindexingtype", ["mom5"]) # TODO add pop in v4?
872874
@pytest.mark.parametrize("extrapolation", [True, False])
873875
def test_bgrid_interpolation(gridindexingtype, extrapolation):
874876
xi, yi = 3, 2

tests/tools/test_warnings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from tests.utils import TEST_DATA
1818

1919

20+
@pytest.mark.v4alpha
21+
@pytest.mark.xfail(reason="From_pop is not supported during v4-alpha development. This will be reconsidered in v4.")
2022
def test_fieldset_warning_pop():
2123
filenames = str(TEST_DATA / "POPtestdata_time.nc")
2224
variables = {"U": "U", "V": "V", "W": "W", "T": "T"}

0 commit comments

Comments
 (0)