Skip to content

Commit

Permalink
Use readers def area_extent if calculation fails
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Raspaud <martin.raspaud@smhi.se>
  • Loading branch information
ch-k authored and mraspaud committed May 17, 2016
1 parent 2eb952a commit 5caa4a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
22 changes: 16 additions & 6 deletions mpop/satin/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ def area_def_names_to_extent(area_def_names, proj4_str,
except AttributeError:
boundaries = name.get_boundary_lonlats()

if (all(boundaries[0].side1 > 1e20) or
all(boundaries[0].side2 > 1e20) or
all(boundaries[0].side3 > 1e20) or
all(boundaries[0].side4 > 1e20)):
maximum_extent = list(default_extent)
continue
if (any(boundaries[0].side1 > 1e20) or
any(boundaries[0].side2 > 1e20) or
any(boundaries[0].side3 > 1e20) or
any(boundaries[0].side4 > 1e20)):
if default_extent:
maximum_extent = list(default_extent)
continue
else:
return None

lon_sides = (boundaries[0].side1, boundaries[0].side2,
boundaries[0].side3, boundaries[0].side4)
Expand All @@ -76,6 +79,8 @@ def area_def_names_to_extent(area_def_names, proj4_str,
maximum_extent = boundaries_to_extent(proj4_str, maximum_extent,
default_extent,
lon_sides, lat_sides)
if not maximum_extent:
return None

maximum_extent[0] -= 10000
maximum_extent[1] -= 10000
Expand Down Expand Up @@ -104,6 +109,11 @@ def boundaries_to_extent(proj4_str, maximum_extent, default_extent,
# replace invalid values with NaN
x_dir[np.abs(x_dir) > 1e20] = np.nan
y_dir[np.abs(y_dir) > 1e20] = np.nan

# return None when no default specified
if not default_extent:
if any(np.isnan(x_dir)) or any(np.isnan(x_dir)):
return None

# Get the maximum needed extent from different corners.
extent = [np.nanmin(x_dir),
Expand Down
6 changes: 5 additions & 1 deletion mpop/satin/mipp_xrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ def load_generic(satscene, options, calibrate=True, area_extent=None,
# lon0=0.0), that is, do not pass default_extent=area_extent
else:
area_extent = area_def_names_to_extent(area_def_names,
metadata.proj4_params)
metadata.proj4_params,
default_extent=None)

if area_extent is None:
LOGGER.info('Could not derive area_extent from area_def_names')

area_converted_to_extent = True

Expand Down

0 comments on commit 5caa4a4

Please sign in to comment.