Commit 0f073660 authored by Daniel Scheffler's avatar Daniel Scheffler

Merge branch 'bugfix/fix_bilinear_sensorgeo_gauss_3D_trafo' into 'master'

Fixed issue where SensorMapGeometryTransformer raised an exception when trying...

See merge request !14
parents 4c725e9c 31ac77d7
Pipeline #5071 failed with stages
in 42 minutes and 8 seconds
......@@ -585,6 +585,11 @@ class SensorMapGeometryTransformer(object):
self.lats = lats
self.lons = lons
self.swath_definition = SwathDefinition(lons=lons, lats=lats)
# use a projection string for local coordinates (https://gis.stackexchange.com/a/300407)
# -> this is needed for bilinear resampling
self.swath_definition.proj_str = '+proj=omerc +lat_0=51.6959777875 +lonc=7.0923165808 +alpha=-20.145 ' \
'+gamma=0 +k=1 +x_0=50692.579 +y_0=81723.458 +ellps=WGS84 ' \
'+towgs84=0,0,0,0,0,0,0 +units=m +no_defs'
self.area_extent_ll = [np.min(lons), np.min(lats), np.max(lons), np.max(lats)]
self.area_definition = None # type: AreaDefinition
......@@ -733,6 +738,15 @@ class SensorMapGeometryTransformer(object):
elif self.resamp_alg == 'gauss':
opts = {k: v for k, v in self.opts.items()}
# ensure that sigmas are provided as list if data is 3-dimensional
if data.ndim != 2:
if not isinstance(opts['sigmas'], list):
opts['sigmas'] = [opts['sigmas']] * data.ndim
if not len(opts['sigmas']) == data.ndim:
raise ValueError("The 'sigmas' parameter must have the same number of values like data.ndim."
"n_sigmas: %d; data.ndim: %d" % (len(opts['sigmas']), data.ndim))
result = resample_gauss(source_geo_def, data, target_geo_def, **opts)
elif self.resamp_alg == 'custom':
......
......@@ -19,5 +19,5 @@
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
__version__ = '0.14.22'
__versionalias__ = '20191016_01'
__version__ = '0.14.23'
__versionalias__ = '20191017_01'
......@@ -41,6 +41,7 @@ from py_tools_ds.geo.raster.reproject import SensorMapGeometryTransformer, Senso
tests_path = os.path.abspath(os.path.join(__path__[0], "..", "tests"))
rsp_algs = ['nearest', 'bilinear', 'gauss']
class Test_SensorMapGeometryTransformer(TestCase):
......@@ -65,9 +66,11 @@ class Test_SensorMapGeometryTransformer(TestCase):
5267203.56579] # UR_y
def test_to_sensor_geometry(self):
for rsp_alg in rsp_algs:
SMGT = SensorMapGeometryTransformer(lons=self.lons,
lats=self.lats,
resamp_alg='nearest')
resamp_alg=rsp_alg,
radius_of_influence=30 if rsp_alg != 'bilinear' else 45)
dem_sensors_geo = SMGT.to_sensor_geometry(self.dem_map_geo,
src_prj=32632, src_extent=self.dem_area_extent_coarse_subset_utm)
self.assertIsInstance(dem_sensors_geo, np.ndarray)
......@@ -75,9 +78,10 @@ class Test_SensorMapGeometryTransformer(TestCase):
self.assertEquals(dem_sensors_geo.shape, (150, 1000))
def test_to_sensor_geometry_3DInput(self):
for rsp_alg in rsp_algs:
SMGT = SensorMapGeometryTransformer(lons=self.lons,
lats=self.lats,
resamp_alg='nearest')
resamp_alg=rsp_alg)
dem_sensors_geo = SMGT.to_sensor_geometry(np.dstack([self.dem_map_geo] * 2),
src_prj=32632, src_extent=self.dem_area_extent_coarse_subset_utm)
self.assertIsInstance(dem_sensors_geo, np.ndarray)
......@@ -86,9 +90,10 @@ class Test_SensorMapGeometryTransformer(TestCase):
self.assertTrue(np.array_equal(dem_sensors_geo[:, :, 0], dem_sensors_geo[:, :, 1]))
def test_to_map_geometry_lonlat(self):
for rsp_alg in rsp_algs:
SMGT = SensorMapGeometryTransformer(lons=self.lons,
lats=self.lats,
resamp_alg='nearest')
resamp_alg=rsp_alg)
# to Lon/Lat
dem_map_geo, dem_gt, dem_prj = SMGT.to_map_geometry(self.dem_sensor_geo, tgt_prj=4326)
......@@ -106,9 +111,10 @@ class Test_SensorMapGeometryTransformer(TestCase):
SMGT.to_map_geometry(self.dem_sensor_geo[:10, :10], tgt_prj=4326) # must have the shape of lons/lats
def test_to_map_geometry_utm(self):
for rsp_alg in rsp_algs:
SMGT = SensorMapGeometryTransformer(lons=self.lons,
lats=self.lats,
resamp_alg='nearest')
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))
......@@ -150,10 +156,11 @@ class Test_SensorMapGeometryTransformer3D(TestCase):
5267203.56579] # UR_y
def test_to_map_geometry_lonlat_3D_geolayer(self):
for rsp_alg in rsp_algs:
SMGT = SensorMapGeometryTransformer3D(lons=self.lons_3D,
lats=self.lats_3D,
# resamp_alg='nearest',
resamp_alg='bilinear',
resamp_alg=rsp_alg,
)
# to Lon/Lat
......@@ -169,9 +176,10 @@ class Test_SensorMapGeometryTransformer3D(TestCase):
np.array(self.expected_dem_area_extent_lonlat)))
def test_to_sensor_geometry(self):
for rsp_alg in rsp_algs:
SMGT = SensorMapGeometryTransformer3D(lons=self.lons_3D,
lats=self.lats_3D,
resamp_alg='nearest',
resamp_alg=rsp_alg,
)
dem_sensors_geo = SMGT.to_sensor_geometry(self.data_map_geo_3D,
src_prj=32632, src_extent=self.dem_area_extent_coarse_subset_utm)
......
Markdown is supported
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