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

Use pyresample's boundary classes #292

Merged
merged 9 commits into from
May 14, 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
6 changes: 2 additions & 4 deletions satpy/readers/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2014-2018 PyTroll developers
Expand Down Expand Up @@ -32,6 +31,7 @@
import os
import numpy as np
from pyresample.geometry import AreaDefinition
from pyresample.boundary import AreaDefBoundary, Boundary

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -87,7 +87,7 @@ def _lonlat_from_geos_angle(x, y, geos_area):
sd = np.sqrt((h * np.cos(x) * np.cos(y)) ** 2 -
(np.cos(y)**2 + b__ * np.sin(y)**2) *
(h**2 - (geos_area.proj_dict['a'] / 1000)**2))
#sd = 0
# sd = 0

sn = (h * np.cos(x) * np.cos(y) - sd) / (np.cos(y)**2 + b__ * np.sin(y)**2)
s1 = h - sn * np.cos(x) * np.cos(y)
Expand Down Expand Up @@ -140,8 +140,6 @@ def get_area_slices(data_area, area_to_cover):

return slice(x[0], x[1] + 1), slice(y[1], y[0] + 1)

from trollsched.boundary import AreaDefBoundary, Boundary

data_boundary = Boundary(*get_geostationary_bounding_box(data_area))

area_boundary = AreaDefBoundary(area_to_cover, 100)
Expand Down
8 changes: 3 additions & 5 deletions satpy/readers/yaml_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import logging
import os
from abc import ABCMeta, abstractmethod, abstractproperty
from collections import deque, namedtuple, OrderedDict
from collections import deque, OrderedDict
from fnmatch import fnmatch

import six
Expand All @@ -36,6 +36,8 @@
from weakref import WeakValueDictionary

from pyresample.geometry import StackedAreaDefinition, SwathDefinition
from pyresample.boundary import AreaDefBoundary, Boundary
from satpy.resample import get_area_def
from satpy.config import recursive_dict_update
from satpy.dataset import DATASET_KEYS, DatasetID
from satpy.readers import DatasetDict, get_key
Expand All @@ -45,8 +47,6 @@

logger = logging.getLogger(__name__)

Shuttle = namedtuple('Shuttle', ['data', 'mask', 'info'])


def listify_string(something):
"""Takes *something* and make it a list.
Expand Down Expand Up @@ -303,8 +303,6 @@ def check_file_covers_area(file_handler, check_area):
If the file doesn't provide any bounding box information or 'area'
was not provided in `filter_parameters`, the check returns True.
"""
from trollsched.boundary import AreaDefBoundary, Boundary
from satpy.resample import get_area_def
try:
gbb = Boundary(*file_handler.get_bounding_box())
except NotImplementedError as err:
Expand Down
44 changes: 19 additions & 25 deletions satpy/tests/test_yaml_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,35 +296,29 @@ def test_filter_fh_by_time(self):
# only the first one should be false
self.assertEqual(res, idx not in [0, 4])

@patch('satpy.resample.get_area_def')
def test_file_covers_area(self, gad):
@patch('satpy.readers.yaml_reader.get_area_def')
@patch('satpy.readers.yaml_reader.AreaDefBoundary')
@patch('satpy.readers.yaml_reader.Boundary')
def test_file_covers_area(self, bnd, adb, gad):
"""Test that area coverage is checked properly."""
file_handler = FakeFH(datetime(1999, 12, 31, 10, 0),
datetime(2000, 1, 3, 12, 30))

trollsched = MagicMock()
adb = trollsched.boundary.AreaDefBoundary
bnd = trollsched.boundary.Boundary

modules = {'trollsched': trollsched,
'trollsched.boundary': trollsched.boundary}

with patch.dict('sys.modules', modules):
self.reader.filter_parameters['area'] = True
bnd.return_value.contour_poly.intersection.return_value = True
adb.return_value.contour_poly.intersection.return_value = True
res = self.reader.check_file_covers_area(file_handler, True)
self.assertTrue(res)

bnd.return_value.contour_poly.intersection.return_value = False
adb.return_value.contour_poly.intersection.return_value = False
res = self.reader.check_file_covers_area(file_handler, True)
self.assertFalse(res)

file_handler.get_bounding_box.side_effect = NotImplementedError()
self.reader.filter_parameters['area'] = True
res = self.reader.check_file_covers_area(file_handler, True)
self.assertTrue(res)
self.reader.filter_parameters['area'] = True
bnd.return_value.contour_poly.intersection.return_value = True
adb.return_value.contour_poly.intersection.return_value = True
res = self.reader.check_file_covers_area(file_handler, True)
self.assertTrue(res)

bnd.return_value.contour_poly.intersection.return_value = False
adb.return_value.contour_poly.intersection.return_value = False
res = self.reader.check_file_covers_area(file_handler, True)
self.assertFalse(res)

file_handler.get_bounding_box.side_effect = NotImplementedError()
self.reader.filter_parameters['area'] = True
res = self.reader.check_file_covers_area(file_handler, True)
self.assertTrue(res)

def test_start_end_time(self):
"""Check start and end time behaviours."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
BASE_PATH = os.path.sep.join(os.path.dirname(os.path.realpath(__file__)).split(
os.path.sep))

requires = ['numpy >=1.4.1', 'pillow', 'pyresample >=1.9.1', 'trollsift',
requires = ['numpy >=1.4.1', 'pillow', 'pyresample >=1.9.2', 'trollsift',
'trollimage >=1.5.1', 'pykdtree', 'six', 'pyyaml', 'xarray >=0.10.1',
'dask[array] >=0.17.1']

Expand Down