Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codebase wide Path object support #1706

Open
VeckoTheGecko opened this issue Sep 16, 2024 · 2 comments
Open

Codebase wide Path object support #1706

VeckoTheGecko opened this issue Sep 16, 2024 · 2 comments

Comments

@VeckoTheGecko
Copy link
Contributor

VeckoTheGecko commented Sep 16, 2024

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
Copy link
Contributor Author

As @michaeldenes mentioned this is an enhancement not a bug :))

@VeckoTheGecko VeckoTheGecko changed the title Field.from_netcdf() doesn't work for filenames provided as Path object Codebase wide Path object support Sep 16, 2024
@VeckoTheGecko VeckoTheGecko added help wanted good first issue Good for new parcels developers labels Sep 16, 2024
@VeckoTheGecko VeckoTheGecko removed their assignment Sep 16, 2024
@VeckoTheGecko VeckoTheGecko removed good first issue Good for new parcels developers help wanted labels Dec 4, 2024
VeckoTheGecko added a commit that referenced this issue Dec 4, 2024
@VeckoTheGecko
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

1 participant