pytroll / satpy

Python package for earth-observing satellite data processing
http://satpy.readthedocs.org/en/latest/
GNU General Public License v3.0
1.05k stars 289 forks source link

Grib reader not working with windows filenames #2484

Open simonrp84 opened 1 year ago

simonrp84 commented 1 year ago

Describe the bug On windows, an error is raised when trying to read data using the grib reader.

To Reproduce

from satpy import Scene
scn = Scene(['C:/some_grib_file.grb'], reader='grib')

Expected behavior A scene to be created with the grib file data.

Actual results An error:

File ~\PycharmProjects\satpy\satpy\readers\grib.py:59, in GRIBFileHandler.__init__(self, filename, filename_info, filetype_info)
     57 self._end_time = None
     58 try:
---> 59     with pygrib.open(self.filename) as grib_file:
     60         first_msg = grib_file.message(1)
     61         last_msg = grib_file.message(grib_file.messages)

File src\pygrib\_pygrib.pyx:321, in pygrib._pygrib.open.__cinit__()

TypeError: expected bytes, FSFile found

If I put the grib file in the same directory as the script and load with scn = Scene(['./some_grib_file.grb'], reader='grib') then it works fine. So the issue appears to be coming from the C:/ part of the filename.

Environment Info:

djhoese commented 1 year ago

Theoretically this should be broken for all readers with Windows paths, but maybe my guess at where this bug is is wrong.

simonrp84 commented 1 year ago

Not noticed this with any other readers, grib is the only one I've found so far that has the problem.

djhoese commented 1 year ago

I'm realizing now this is probably because other readers (at least the ones you would use) support FSFiles, but the grib reader doesn't.