Skip to content

Commit

Permalink
Fix HDF4 support in geocat reader with hardcoded engine (#2507)
Browse files Browse the repository at this point in the history
Co-authored-by: David Hoese <david.hoese@ssec.wisc.edu>
  • Loading branch information
joleenf and djhoese committed Jun 20, 2023
1 parent 9415ad9 commit 1d37638
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion satpy/etc/readers/nwcsaf-pps_nc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,4 @@ datasets:
name: cmic_dcot
file_key: dcot
file_type: [nc_nwcsaf_cpp, nc_nwcsaf_cmic]
coordinates: [lon, lat]
coordinates: [lon, lat]
25 changes: 24 additions & 1 deletion satpy/readers/geocat.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,30 @@


class GEOCATFileHandler(NetCDF4FileHandler):
"""GEOCAT netCDF4 file handler."""
"""GEOCAT netCDF4 file handler.
**Loading data with decode_times=True**
By default, this reader will use ``xarray_kwargs={"engine": "netcdf4", "decode_times": False}``.
to match behavior of xarray when the geocat reader was first written. To use different options
use reader_kwargs when loading the Scene::
scene = satpy.Scene(filenames,
reader='geocat',
reader_kwargs={'xarray_kwargs': {'engine': 'netcdf4', 'decode_times': True}})
"""

def __init__(self, filename, filename_info, filetype_info,
**kwargs):
"""Open and perform initial investigation of NetCDF file."""
kwargs.setdefault('xarray_kwargs', {}).setdefault(
'engine', "netcdf4")
kwargs.setdefault('xarray_kwargs', {}).setdefault(
'decode_times', False)

super(GEOCATFileHandler, self).__init__(
filename, filename_info, filetype_info,
xarray_kwargs=kwargs["xarray_kwargs"])

sensors = {
'goes': 'goes_imager',
Expand Down
16 changes: 14 additions & 2 deletions satpy/tests/reader_tests/test_geocat.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,22 @@ def test_init(self):
loadables = r.select_files_from_pathnames([
'geocatL2.GOES-13.2015143.234500.nc',
])
self.assertEqual(len(loadables), 1)
assert len(loadables) == 1
r.create_filehandlers(loadables)
# make sure we have some files
self.assertTrue(r.file_handlers)
assert r.file_handlers

def test_init_with_kwargs(self):
"""Test basic init with extra parameters."""
from satpy.readers import load_reader
r = load_reader(self.reader_configs, xarray_kwargs={"decode_times": True})
loadables = r.select_files_from_pathnames([
'geocatL2.GOES-13.2015143.234500.nc',
])
assert len(loadables) == 1
r.create_filehandlers(loadables, fh_kwargs={"xarray_kwargs": {'decode_times': True}})
# make sure we have some files
assert r.file_handlers

def test_load_all_old_goes(self):
"""Test loading all test datasets from old GOES files."""
Expand Down

0 comments on commit 1d37638

Please sign in to comment.