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

Fix GPM IMERG reader. #2137

Merged
merged 7 commits into from Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions satpy/readers/gpm_imerg.py
Expand Up @@ -26,6 +26,7 @@
import logging
from datetime import datetime

import dask.array as da
import h5py
import numpy as np
from pyresample.geometry import AreaDefinition
Expand Down Expand Up @@ -69,18 +70,22 @@ def get_dataset(self, dataset_id, ds_info):
"""Load a dataset."""
file_key = ds_info.get('file_key', dataset_id['name'])
dsname = 'Grid/' + file_key
data = self[dsname].squeeze().transpose()
data.values = np.flipud(data.values)
data = self.get(dsname)
data = data.squeeze().transpose()
if data.ndim >= 2:
data = data.rename({data.dims[-2]: 'y', data.dims[-1]: 'x'})
data.data = da.flip(data.data, axis=0)

fill = data.attrs['_FillValue']
pts = (data.values == fill).nonzero()
data.values[pts] = np.nan
data = data.where(data != fill)

for key in list(data.attrs.keys()):
val = data.attrs[key]
if isinstance(val, h5py.h5r.Reference):
del data.attrs[key]

if isinstance(val, np.ndarray):
if isinstance(val[0][0], h5py.h5r.Reference):
del data.attrs[key]
djhoese marked this conversation as resolved.
Show resolved Hide resolved
return data

def get_area_def(self, dsid):
Expand Down
5 changes: 4 additions & 1 deletion satpy/tests/reader_tests/test_gpm_imerg.py
Expand Up @@ -23,6 +23,7 @@
from unittest import mock

import dask.array as da
import h5py
import numpy as np
import xarray as xr

Expand Down Expand Up @@ -55,12 +56,14 @@ def _get_precip_data(self, num_rows, num_cols):
selection = {
'Grid/IRprecipitation':
xr.DataArray(
da.ones((1, num_rows, num_cols), chunks=1024,
da.ones((1, num_cols, num_rows), chunks=1024,
dtype=np.float32),
attrs={
'_FillValue': -9999.9,
'units': 'mm/hr',
'Units': 'mm/hr',
'badval': h5py.h5r.Reference,
'badvals': np.array([[h5py.h5r.Reference]])
},
dims=('time', 'lon', 'lat')),
}
Expand Down