Commit 584b3947 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fixed tests.


Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 10cb1b0c
......@@ -99,7 +99,8 @@ class SensorMapGeometryTransformer3D(object):
self.mp_alg = ('bands' if self.lons.shape[2] >= opts['nprocs'] else 'tiles') if mp_alg == 'auto' else mp_alg
@staticmethod
def _to_map_geometry_2D(kwargs_dict: dict) -> Tuple[np.ndarray, tuple, str, int]:
def _to_map_geometry_2D(kwargs_dict: dict
) -> Tuple[np.ndarray, tuple, str, int]:
assert [var is not None for var in (_global_shared_lons, _global_shared_lats, _global_shared_data)]
SMGT2D = SensorMapGeometryTransformer(lons=_global_shared_lons[:, :, kwargs_dict['band_idx']],
......@@ -150,7 +151,8 @@ class SensorMapGeometryTransformer3D(object):
tgt_prj: Union[str, int],
tgt_extent: Tuple[float, float, float, float] = None,
tgt_res: Tuple = None,
tgt_coordgrid: Tuple[Tuple, Tuple] = None) -> AreaDefinition:
tgt_coordgrid: Tuple[Tuple, Tuple] = None
) -> AreaDefinition:
# get common target extent
tgt_epsg = WKT2EPSG(proj4_to_WKT(get_proj4info(proj=tgt_prj)))
tgt_extent = tgt_extent or self._get_common_target_extent(tgt_epsg, tgt_coordgrid=tgt_coordgrid)
......@@ -171,9 +173,10 @@ class SensorMapGeometryTransformer3D(object):
data: np.ndarray,
tgt_prj: Union[str, int],
tgt_extent: Tuple[float, float, float, float] = None,
tgt_res: Tuple = None,
tgt_res: Tuple[float, float] = None,
tgt_coordgrid: Tuple[Tuple, Tuple] = None,
area_definition: AreaDefinition = None) -> Tuple[np.ndarray, tuple, str]:
area_definition: AreaDefinition = None
) -> Tuple[np.ndarray, tuple, str]:
"""Transform the input sensor geometry array into map geometry.
:param data: 3D numpy array (representing sensor geometry) to be warped to map geometry
......@@ -231,7 +234,8 @@ class SensorMapGeometryTransformer3D(object):
return data_mapgeo, out_gt, out_prj
@staticmethod
def _to_sensor_geometry_2D(kwargs_dict: dict) -> (np.ndarray, int):
def _to_sensor_geometry_2D(kwargs_dict: dict
) -> (np.ndarray, int):
assert [var is not None for var in (_global_shared_lons, _global_shared_lats, _global_shared_data)]
SMGT2D = SensorMapGeometryTransformer(lons=_global_shared_lons[:, :, kwargs_dict['band_idx']],
......@@ -248,7 +252,8 @@ class SensorMapGeometryTransformer3D(object):
def to_sensor_geometry(self,
data: np.ndarray,
src_prj: Union[str, int],
src_extent: Tuple[float, float, float, float]) -> np.ndarray:
src_extent: Tuple[float, float, float, float]
) -> np.ndarray:
"""Transform the input map geometry array into sensor geometry
:param data: 3D numpy array (representing map geometry) to be warped to sensor geometry
......
......@@ -62,6 +62,11 @@ class Test_SensorMapGeometryTransformer(TestCase):
656188.928052, # UR_x
5267203.56579) # UR_y
self.expected_dem_area_extent_utm_ongrid = (626910, # LL_x
5256240, # LL_y
656190, # UR_x
5267220) # UR_y
def test_to_sensor_geometry(self):
for rsp_alg in rsp_algs:
SMGT = SensorMapGeometryTransformer(lons=self.lons,
......@@ -120,14 +125,20 @@ class Test_SensorMapGeometryTransformer(TestCase):
resamp_alg=rsp_alg)
# to UTM32
dem_map_geo, dem_gt, dem_prj = SMGT.to_map_geometry(self.dem_sensor_geo, tgt_prj=32632, tgt_res=(30, 30))
# dem_map_geo, dem_gt, dem_prj = SMGT.to_map_geometry(self.dem_sensor_geo, tgt_prj=32632, tgt_res=(30, 30))
dem_map_geo, dem_gt, dem_prj = SMGT.to_map_geometry(self.dem_sensor_geo, tgt_prj=32632,
tgt_res=(30, 30),
# tgt_extent=self.expected_dem_area_extent_utm,
tgt_coordgrid=((0, 30), (0, 30))
)
self.assertIsInstance(dem_map_geo, np.ndarray)
self.assertEqual(dem_map_geo.shape, (365, 975))
self.assertEqual(dem_map_geo.shape, (366, 976))
xmin, xmax, ymin, ymax = corner_coord_to_minmax(get_corner_coordinates(gt=dem_gt,
cols=dem_map_geo.shape[1],
rows=dem_map_geo.shape[0]))
self.assertTrue(False not in np.isclose(np.array([xmin, ymin, xmax, ymax]),
np.array(self.expected_dem_area_extent_utm)))
np.array(self.expected_dem_area_extent_utm_ongrid)))
self.assertFalse(np.array_equal(np.unique(dem_map_geo), np.array([0])))
self.assertTrue(np.isclose(np.mean(dem_map_geo[dem_map_geo != 0]),
np.mean(self.dem_sensor_geo),
......@@ -144,24 +155,31 @@ class Test_SensorMapGeometryTransformer3D(TestCase):
self.data_map_geo_3D = np.dstack([dem_map_geo, dem_map_geo])
self.data_sensor_geo_3D = np.dstack([dem_sensor_geo, dem_sensor_geo])
self.lons_3D = np.dstack([lons, lons]) # TODO use different lons per band here
self.lats_3D = np.dstack([lats, lats]) # TODO use different lats per band here
self.lons_3D = np.dstack([lons, lons + .002]) # assume slightly different coordinates in both bands
self.lats_3D = np.dstack([lats, lats + .002])
self.dem_area_extent_coarse_subset_utm = (622613.864409047, # LL_x
5254111.40255343, # LL_x
660473.864409047, # LL_x
5269351.40255343) # UR_y
# this differs from the 2D version because the geolayer in the second band has slightly different coordinates
self.expected_dem_area_extent_lonlat = (10.685733901515151, # LL_x
47.44113415492957, # LL_y
11.073066098484848, # UR_x
47.54576584507042) # UR_y
11.075064739115845, # UR_x
47.54772559829233) # UR_y
self.expected_dem_area_extent_utm = (626938.928052, # LL_x
5256253.56579, # LL_y
656188.928052, # UR_x
5267203.56579) # UR_y
# this differs from the 2D version because the geolayer in the second band has slightly different coordinates
self.expected_dem_area_extent_utm_ongrid = (626910, # LL_x
5256240, # LL_y
656340, # UR_x
5267430) # UR_y
def test_to_map_geometry_lonlat_3D_geolayer(self):
for rsp_alg in rsp_algs:
SMGT = SensorMapGeometryTransformer3D(lons=self.lons_3D,
......@@ -175,8 +193,7 @@ class Test_SensorMapGeometryTransformer3D(TestCase):
self.assertIsInstance(data_mapgeo_3D, np.ndarray)
# only validate number of bands (height and width are validated in 2D version
# fixed numbers may fail here due to float uncertainty errors
self.assertGreater(data_mapgeo_3D.shape[0], self.data_sensor_geo_3D.shape[0])
self.assertGreater(data_mapgeo_3D.shape[1], self.data_sensor_geo_3D.shape[1])
self.assertGreater(np.dot(*data_mapgeo_3D.shape[:2]), np.dot(*self.data_sensor_geo_3D.shape[:2]))
self.assertEqual(data_mapgeo_3D.shape[2], 2)
xmin, xmax, ymin, ymax = corner_coord_to_minmax(get_corner_coordinates(gt=dem_gt,
cols=data_mapgeo_3D.shape[1],
......@@ -189,6 +206,38 @@ class Test_SensorMapGeometryTransformer3D(TestCase):
rtol=0.01))
self.assertEqual(self.data_sensor_geo_3D.dtype, data_mapgeo_3D.dtype)
def test_to_map_geometry_utm_3D_geolayer(self):
for rsp_alg in rsp_algs:
SMGT = SensorMapGeometryTransformer3D(lons=self.lons_3D,
lats=self.lats_3D,
# resamp_alg='nearest',
resamp_alg=rsp_alg,
)
# to Lon/Lat
data_mapgeo_3D, dem_gt, dem_prj = SMGT.to_map_geometry(self.data_sensor_geo_3D,
tgt_prj=32632,
tgt_res=(30, 30),
# tgt_extent=self.expected_dem_area_extent_utm,
tgt_coordgrid=((0, 30), (0, 30))
)
self.assertIsInstance(data_mapgeo_3D, np.ndarray)
# only validate number of bands (height and width are validated in 2D version
# fixed numbers may fail here due to float uncertainty errors
self.assertGreater(np.dot(*data_mapgeo_3D.shape[:2]), np.dot(*self.data_sensor_geo_3D.shape[:2]))
self.assertEqual(data_mapgeo_3D.shape[2], 2)
xmin, xmax, ymin, ymax = corner_coord_to_minmax(get_corner_coordinates(gt=dem_gt,
cols=data_mapgeo_3D.shape[1],
rows=data_mapgeo_3D.shape[0]))
self.assertTrue(False not in np.isclose(np.array([xmin, ymin, xmax, ymax]),
np.array(self.expected_dem_area_extent_utm_ongrid)))
self.assertTrue(np.isclose(np.mean(data_mapgeo_3D[data_mapgeo_3D != 0]),
np.mean(self.data_sensor_geo_3D),
rtol=0.01))
self.assertEqual(self.data_sensor_geo_3D.dtype, data_mapgeo_3D.dtype)
def test_to_sensor_geometry(self):
for rsp_alg in rsp_algs:
SMGT = SensorMapGeometryTransformer3D(lons=self.lons_3D,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment