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 handling of area creation in the grib reader #484

Merged
merged 2 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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