Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_grid_filter_valid(self):
lons = np.array([-170, -30, 30, 170])
lats = np.array([20, -40, 50, -80])
swath_def = geometry.SwathDefinition(lons, lats)
filter_area = geometry.AreaDefinition('test', 'test', 'test',
{'proj' : 'eqc', 'lon_0' : 0.0, 'lat_0' : 0.0},
8, 8,
(-20037508.34, -10018754.17, 20037508.34, 10018754.17))
filter = np.array([[1, 1, 1, 1, 0, 0, 0, 0],
[1, 1, 1, 1, 0, 0, 0, 0],
[1, 1, 1, 1, 0, 0, 0, 0],
[1, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 1],
[0, 0, 0, 0, 1, 1, 1, 1],
[0, 0, 0, 0, 1, 1, 1, 1],
[0, 0, 0, 0, 1, 1, 1, 1],
])
grid_filter = geo_filter.GridFilter(filter_area, filter)
valid_index = grid_filter.get_valid_index(swath_def)
expected = np.array([1, 0, 0, 1])
def test_swath_not_equal(self):
lats1 = np.array([65.9, 65.86, 65.82, 65.78])
lons = np.array([1.2, 1.3, 1.4, 1.5])
lats2 = np.array([65.91, 65.85, 65.80, 65.75])
swath_def = geometry.SwathDefinition(lons, lats1)
swath_def2 = geometry.SwathDefinition(lons, lats2)
self.assertFalse(swath_def == swath_def2, 'swath_defs are not expected to be equal')
def test_overlaps(self):
"""Test if two areas overlap.
"""
lons1 = np.array([[0, 90], [-90, 180]])
lats1 = np.array([[89, 89], [89, 89]])
area1 = geometry.SwathDefinition(lons1, lats1)
lons2 = np.array([[45, 135], [-45, -135]])
lats2 = np.array([[89, 89], [89, 89]])
area2 = geometry.SwathDefinition(lons2, lats2)
self.assertTrue(area1.overlaps(area2))
self.assertTrue(area2.overlaps(area1))
lons1 = np.array([[0, 45], [135, 90]])
lats1 = np.array([[89, 89], [89, 89]])
area1 = geometry.SwathDefinition(lons1, lats1)
lons2 = np.array([[180, -135], [-45, -90]])
lats2 = np.array([[89, 89], [89, 89]])
area2 = geometry.SwathDefinition(lons2, lats2)
def patch_geometry():
"""Patching the geometry module
"""
geometry.OldAreaDefinition = geometry.AreaDefinition
geometry.AreaDefinition = FakeAreaDefinition
geometry.OldSwathDefinition = geometry.SwathDefinition
geometry.SwathDefinition = FakeSwathDefinition
def test_self_map_multi(self):
data = np.column_stack((self.tb37v, self.tb37v, self.tb37v))
swath_def = geometry.SwathDefinition(lons=self.lons, lats=self.lats)
if sys.version_info < (2, 6):
res = kd_tree.resample_gauss(swath_def, data, swath_def,
radius_of_influence=70000, sigmas=[56500, 56500, 56500])
else:
with warnings.catch_warnings(record=True) as w:
res = kd_tree.resample_gauss(swath_def, data, swath_def,
radius_of_influence=70000, sigmas=[56500, 56500, 56500])
self.assertFalse(len(w) != 1, 'Failed to create neighbour radius warning')
self.assertFalse(('Possible more' not in str(w[0].message)), 'Failed to create correct neighbour radius warning')
self.assertAlmostEqual(res[:, 0].sum() / 100., 668848.082208, 1,
msg='Failed self mapping swath multi for channel 1')
self.assertAlmostEqual(res[:, 1].sum() / 100., 668848.082208, 1,
msg='Failed self mapping swath multi for channel 2')
self.assertAlmostEqual(res[:, 2].sum() / 100., 668848.082208, 1,
msg='Failed self mapping swath multi for channel 3')
def unpatch_geometry():
"""Unpatching the geometry module.
"""
geometry.AreaDefinition = geometry.OldAreaDefinition
delattr(geometry, "OldAreaDefinition")
geometry.SwathDefinition = geometry.OldSwathDefinition
delattr(geometry, "OldSwathDefinition")
def fake_parse_area_file(filename, area):
"""Fake function.
"""
del filename
if area == "raise" or not isinstance(area, str):
raise utils.AreaNotFound("This area is not to be found")
else:
return [geometry.AreaDefinition(area)]
import numpy
from pyresample import image, geometry, grid, utils
def mask(f):
f.mask = True
return f
def tmp(f):
f.tmp = True
return f
class Test(unittest.TestCase):
area_def = geometry.AreaDefinition('areaD', 'Europe (3km, HRV, VTC)', 'areaD',
{'a': '6378144.0',
'b': '6356759.0',
'lat_0': '50.00',
'lat_ts': '50.00',
'lon_0': '8.00',
'proj': 'stere'},
800,
800,
[-1370912.72,
-909968.64000000001,
1029087.28,
1490031.3600000001])
msg_area = geometry.AreaDefinition('msg_full', 'Full globe MSG image 0 degrees',
'msg_full',
{'a': '6378169.0',
def test_nearest_swath_segments(self):
data = numpy.fromfunction(lambda y, x: y*x, (50, 10))
data = numpy.dstack(3 * (data,))
lons = numpy.fromfunction(lambda y, x: 3 + x, (50, 10))
lats = numpy.fromfunction(lambda y, x: 75 - y, (50, 10))
swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
swath_con = image.ImageContainerNearest(data, swath_def, 50000, segments=2)
area_con = swath_con.resample(self.area_def)
res = area_con.image_data
cross_sum = res.sum()
expected = 3 * 15874591.0
self.assertEqual(cross_sum, expected,\
msg='ImageContainer swath segments resampling nearest failed')
def test_nearest_multi_unraveled(self):
data = numpy.fromfunction(lambda y, x: y*x, (50, 10))
lons = numpy.fromfunction(lambda y, x: 3 + x, (50, 10))
lats = numpy.fromfunction(lambda y, x: 75 - y, (50, 10))
swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
data_multi = numpy.dstack((data, data, data))
res = kd_tree.resample_nearest(swath_def, data_multi,\
self.area_def, 50000, segments=1)
cross_sum = res.sum()
expected = 3 * 15874591.0
self.assertEqual(cross_sum, expected,\
msg='Swath multi channel resampling nearest failed')