Codebase wide `Path` object support
Opened this issue · 1 comments
VeckoTheGecko commented
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
VeckoTheGecko commented
As @michaeldenes mentioned this is an enhancement not a bug :))