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

Exception 'PosixPath' object is not iterable when using the Herbie xarray method #44

Open
mattatwork26 opened this issue Feb 9, 2022 · 8 comments
Labels

Comments

@mattatwork26
Copy link

There appears to be a bug in the Herbie.xarray method where the file path is not made into a string before calling cfgrib.open_datasets

Logs in question:

πŸ‹πŸ»β€β™‚οΈ Found  2022-Feb-09 00:00 UTC F01 [HRRR] [product=sfc] GRIB2 file from aws and index file from aws.

Search string: APCP:surface:0-1 hour
πŸ‘¨πŸ»β€πŸ­ Created directory: [/tmp/hrrr/20220209]
πŸ“‡ Download subset: [HRRR] model [sfc] product run at 2022-Feb-09 00:00 UTC F01
 cURL from https://noaa-hrrr-bdp-pds.s3.amazonaws.com/hrrr.20220209/conus/hrrr.t00z.wrfsfcf01.grib2
   1: GRIB_message=84  :APCP:surface:0-1 hour acc fcst
indexpath value  is ignored
No results found for search string: APCP:surface:0-1 hour, Exception: 'PosixPath' object is not iterable

After changing

        Hxr = cfgrib.open_datasets(
            self.get_localFilePath(searchString=searchString),
            backend_kwargs=backend_kwargs,
        )

to

        fp = self.get_localFilePath(searchString=searchString)
        Hxr = cfgrib.open_datasets(
            str(fp),
            backend_kwargs=backend_kwargs,
        )

in the herbie.archive xarray method, the exception no longer occurs.

@mattatwork26
Copy link
Author

this is addressed in PR #43

@blaylockbk
Copy link
Owner

Thanks for reporting this @mattatwork26 and the pull request.
Can you tell me the version of python and cfgrib you are using?

@mattatwork26
Copy link
Author

Np, thanks for the package

cfgrib 0.9.10.0
python 3.9.1

Just for clarity, the PR is not mine.

@blaylockbk
Copy link
Owner

This is interesting. I was not able to recreate the problem with the following:

  • Python version 3.9.5
  • cfgrib 0.9.9.1
from herbie.archive import Herbie
date = '2022-02-09T00:00'
fxx = 1
H = Herbie(date, model='hrrr', fxx=1)

ds = H.xarray('APCP:surface:0-1 hour')
ds

image

I'll have to look more into this later. I like that the PR gets around this by converting the path back into a string, but it may be that the latest release of cfgrib has an issue opening pathlib.Path objects that needs to be reported.

@blaylockbk
Copy link
Owner

Ok, I was curious and had to see what was wrong. It does appear to be an issue with cfgrib. When I updated to 0.9.10.0, I got the same error. See ecmwf/cfgrib#282

On the Herbie side of things, for now, I updated the recommended environment.yml file to use cfgrib=0.9.9.1.

- cfgrib=0.9.9.1

@mattatwork26
Copy link
Author

I can confirm that using version cfgrib 0.9.9.1 resolves my issue, thanks!

@blaylockbk
Copy link
Owner

Looks like this will be fixed in cfgrib 0.9.10.1 πŸ˜„
ecmwf/cfgrib#282

@blaylockbk
Copy link
Owner

Fixed in https://github.com/ecmwf/cfgrib/tree/0.9.10.1.
Waiting to see what happens with ecmwf/cfgrib#293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants