Commit 2159a21e authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

SensorMapGeometryTransformer.compute_areadefinition_sensor2map() now directly...


SensorMapGeometryTransformer.compute_areadefinition_sensor2map() now directly uses pyresample instead of GDAL if the target resolution is given.
Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 84ab0604
Pipeline #8573 failed with stage
in 53 seconds
......@@ -26,6 +26,7 @@
from typing import Union, List, Tuple, Optional
import os
import warnings
from tempfile import TemporaryDirectory
import numpy as np
......@@ -38,7 +39,7 @@ from py_tools_ds.processing.shell import subcall_with_output
# NOTE: In case of ImportError: dlopen: cannot load any more object with static TLS,
# one could add 'from pykdtree.kdtree import KDTree' here (before pyresample import)
from pyresample.geometry import AreaDefinition, SwathDefinition
from pyresample.geometry import AreaDefinition, SwathDefinition, DynamicAreaDefinition, create_area_def
from pyresample.bilinear import resample_bilinear
from pyresample.kd_tree import resample_nearest, resample_gauss, resample_custom
......@@ -140,6 +141,24 @@ class SensorMapGeometryTransformer(object):
:param tgt_res: target X/Y resolution (e.g., (30, 30))
:return:
"""
if tgt_res:
area_definition = \
create_area_def(area_id='',
projection=get_proj4info(proj=tgt_prj),
area_extent=tgt_extent,
resolution=tgt_res)
if isinstance(area_definition, DynamicAreaDefinition):
area_definition = area_definition.freeze(lonslats=(self.lons, self.lats),
resolution=tgt_res)
out_res = (area_definition.pixel_size_x, area_definition.pixel_size_y)
if tgt_res and tgt_res != out_res:
warnings.warn('With respect to the Lon/Lat arrays the pixel size was set to %s instead of the desired '
'%s. Provide a target extent where the coordinates are multiples of the pixel sizes to '
'avoid this.' % (str(out_res), str(tgt_res)), UserWarning)
else:
tgt_epsg = WKT2EPSG(proj4_to_WKT(get_proj4info(proj=tgt_prj)))
tgt_extent = tgt_extent or self._get_target_extent(tgt_epsg)
......
......@@ -26,8 +26,6 @@
from typing import Union, Tuple
import multiprocessing
import sys
import warnings
import numpy as np
from py_tools_ds.geo.projection import WKT2EPSG, proj4_to_WKT
......@@ -97,13 +95,6 @@ class SensorMapGeometryTransformer3D(object):
self.opts['nprocs'] = opts.get('nprocs', multiprocessing.cpu_count())
self.mp_alg = ('bands' if self.lons.shape[2] >= opts['nprocs'] else 'tiles') if mp_alg == 'auto' else mp_alg
# override self.mp_alg if SensorMapGeometryTransformer3D is called by nosetest or unittest
is_called_by_nose_cmd = 'nosetest' in sys.argv[0]
if self.opts['nprocs'] > 1 and self.mp_alg == 'bands' and is_called_by_nose_cmd:
warnings.warn("mp_alg='bands' causes deadlocks if SensorMapGeometryTransformer3D is called within a "
"nosetest console call. Using mp_alg='tiles'.")
self.mp_alg = 'tiles'
@staticmethod
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)]
......
......@@ -47,20 +47,20 @@ class Test_SensorMapGeometryTransformer(TestCase):
self.dem_sensor_geo = LoadFile(os.path.join(tests_path, 'data', 'dem_sensor_geo.bsq'))
self.lons = LoadFile(os.path.join(tests_path, 'data', 'lons_full_vnir.bsq'))
self.lats = LoadFile(os.path.join(tests_path, 'data', 'lats_full_vnir.bsq'))
self.dem_area_extent_coarse_subset_utm = [622613.864409047, # LL_x
self.dem_area_extent_coarse_subset_utm = (622613.864409047, # LL_x
5254111.40255343, # LL_x
660473.864409047, # LL_x
5269351.40255343] # UR_y
5269351.40255343) # UR_y
self.expected_dem_area_extent_lonlat = [10.685733901515151, # LL_x
self.expected_dem_area_extent_lonlat = (10.685733901515151, # LL_x
47.44113415492957, # LL_y
11.073066098484848, # UR_x
47.54576584507042] # UR_y
47.54576584507042) # UR_y
self.expected_dem_area_extent_utm = [626938.928052, # LL_x
self.expected_dem_area_extent_utm = (626938.928052, # LL_x
5256253.56579, # LL_y
656188.928052, # UR_x
5267203.56579] # UR_y
5267203.56579) # UR_y
def test_to_sensor_geometry(self):
for rsp_alg in rsp_algs:
......@@ -147,20 +147,20 @@ class Test_SensorMapGeometryTransformer3D(TestCase):
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.dem_area_extent_coarse_subset_utm = [622613.864409047, # LL_x
self.dem_area_extent_coarse_subset_utm = (622613.864409047, # LL_x
5254111.40255343, # LL_x
660473.864409047, # LL_x
5269351.40255343] # UR_y
5269351.40255343) # UR_y
self.expected_dem_area_extent_lonlat = [10.685733901515151, # LL_x
self.expected_dem_area_extent_lonlat = (10.685733901515151, # LL_x
47.44113415492957, # LL_y
11.073066098484848, # UR_x
47.54576584507042] # UR_y
47.54576584507042) # UR_y
self.expected_dem_area_extent_utm = [626938.928052, # LL_x
self.expected_dem_area_extent_utm = (626938.928052, # LL_x
5256253.56579, # LL_y
656188.928052, # UR_x
5267203.56579] # UR_y
5267203.56579) # UR_y
def test_to_map_geometry_lonlat_3D_geolayer(self):
for rsp_alg in rsp_algs:
......
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