parcels
parcels copied to clipboard
Codebase wide `Path` object support
Parcels version
v3.0.5
Description
Field.from_netcdf() doesn't work for filenames provided as Path object. It would be good to ensure the whole codebase is Path object compatible.
Code sample
from pathlib import Path
@pytest.mark.parametrize("with_timestamps", [False])
def test(with_timestamps):
TEST_DATA = Path(__file__).resolve().parent / "test_data"
filenames = {
"lon": TEST_DATA / "mask_nemo_cross_180lon.nc",
"lat": TEST_DATA / "mask_nemo_cross_180lon.nc",
"data": TEST_DATA / "Uu_eastward_nemo_cross_180lon.nc",
}
variable = "U"
dimensions = {"lon": "glamf", "lat": "gphif"}
Field.from_netcdf(filenames, variable, dimensions, interp_method="cgrid_velocity")
lonlat_filename = cls.get_dim_filenames(filenames, "lon")
if isinstance(filenames, dict):
> assert len(lonlat_filename) == 1
E TypeError: object of type 'PosixPath' has no len()
parcels/field.py:477: TypeError
As @michaeldenes mentioned this is an enhancement not a bug :))
from pathlib import Path @pytest.mark.parametrize("with_timestamps", [False]) def test(with_timestamps): TEST_DATA = Path(__file__).resolve().parent / "test_data" filenames = { "lon": TEST_DATA / "mask_nemo_cross_180lon.nc", "lat": TEST_DATA / "mask_nemo_cross_180lon.nc", "data": TEST_DATA / "Uu_eastward_nemo_cross_180lon.nc", } variable = "U" dimensions = {"lon": "glamf", "lat": "gphif"} Field.from_netcdf(filenames, variable, dimensions, interp_method="cgrid_velocity")
01efbb8 implements this test case. I wouldn't go so far to say we now have full Path support, but its a step in the right direction
Only relevant to v3 (will be free in v4). Closing