Skip to content

Commit

Permalink
Merge pull request #484 from djhoese/bugfix-grib-areas
Browse files Browse the repository at this point in the history
Fix handling of area creation in the grib reader
  • Loading branch information
djhoese authored Nov 2, 2018
2 parents bf61a3e + c404a93 commit 5dd28ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 11 additions & 7 deletions satpy/readers/grib.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,15 @@ def _area_def_from_msg(self, msg):

proj = Proj(**proj_params)
x, y = proj(lons, lats)
x[np.abs(x) >= 1e30] = np.nan
y[np.abs(y) >= 1e30] = np.nan
min_x = np.nanmin(x)
max_x = np.nanmax(x)
min_y = np.nanmin(y)
max_y = np.nanmax(y)
extents = (min_x, min_y, max_x, max_y)
if msg.valid_key('jScansPositively') and msg['jScansPositively'] == 1:
min_x, min_y = x[0], y[0]
max_x, max_y = x[3], y[3]
else:
min_x, min_y = x[2], y[2]
max_x, max_y = x[1], y[1]
half_x = abs((max_x - min_x) / (shape[1] - 1)) / 2.
half_y = abs((max_y - min_y) / (shape[0] - 1)) / 2.
extents = (min_x - half_x, min_y - half_y, max_x + half_x, max_y + half_y)

return geometry.AreaDefinition(
'on-the-fly grib area',
Expand Down Expand Up @@ -251,6 +253,8 @@ def get_dataset(self, dataset_id, ds_info):
ds_info = self.get_metadata(msg, ds_info)
fill = msg['missingValue']
data = msg.values.astype(np.float32)
if msg.valid_key('jScansPositively') and msg['jScansPositively'] == 1:
data = data[::-1]

if isinstance(data, np.ma.MaskedArray):
data = data.filled(np.nan)
Expand Down
6 changes: 6 additions & 0 deletions satpy/tests/reader_tests/test_grib.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def latlons(self):
def __getitem__(self, item):
return self.attrs[item]

def valid_key(self, key):
return True


class FakeGRIB(object):
"""Fake GRIB file returned by pygrib.open."""
Expand Down Expand Up @@ -66,6 +69,7 @@ def __init__(self, messages=None, proj_params=None, latlons=None):
minimum=100.,
maximum=200.,
typeOfLevel='isobaricInhPa',
jScansPositively=0,
proj_params=proj_params,
latlons=latlons,
),
Expand All @@ -88,6 +92,7 @@ def __init__(self, messages=None, proj_params=None, latlons=None):
minimum=100.,
maximum=200.,
typeOfLevel='isobaricInhPa',
jScansPositively=0,
proj_params=proj_params,
latlons=latlons,
),
Expand All @@ -110,6 +115,7 @@ def __init__(self, messages=None, proj_params=None, latlons=None):
minimum=100.,
maximum=200.,
typeOfLevel='isobaricInhPa',
jScansPositively=0,
proj_params=proj_params,
latlons=latlons,
),
Expand Down

0 comments on commit 5dd28ea

Please sign in to comment.