Commit b2394ba8 authored by Daniel Scheffler's avatar Daniel Scheffler

Merge branch 'enhancement/remove_sensormapgeo_code' into 'master'

Enhancement/remove sensormapgeo code

See merge request !15
parents 30fd8a63 07856b8f
Pipeline #5506 failed with stages
in 61 minutes and 21 seconds
......@@ -57,12 +57,16 @@ test_py_tools_ds_install:
- source /root/miniconda3/bin/activate
- conda create -y -q --name py_tools_ds_testinstall python=3
- source activate py_tools_ds_testinstall
# avoid package incompatibilities due to usage of wrong channels
- conda config --set channel_priority strict # otherwise gdal or libgdal may be installed from defaults channel
# resolve some requirements with conda
- conda install --yes -q -c conda-forge numpy gdal scikit-image pyproj rasterio shapely geopandas pyresample>=1.11.0
- conda install --yes -q -c conda-forge libgdal ncurses # Fix for libgdal installed from defaults channel causing libkea.so.1.4.7: cannot open shared object file: No such file or directory
# - conda install --yes -q -c conda-forge kealib # fix for libkea.so.1.4.7: cannot open shared object file: No such file or directory
- conda install --yes -q -c conda-forge numpy gdal scikit-image pyproj rasterio shapely geopandas
# run installer
- python setup.py install
# test if its importable
- cd ..
- pwd
......
......@@ -23,7 +23,7 @@ Status
:target: https://pyup.io/repos/github/danschef/py_tools_ds/
:alt: Updates
.. image:: https://gitext.gfz-potsdam.de/danschef/py_tools_ds/badges/master/build.svg
.. image:: https://gitext.gfz-potsdam.de/danschef/py_tools_ds/badges/master/pipeline.svg
:target: https://gitext.gfz-potsdam.de/danschef/py_tools_ds/commits/master
.. image:: https://gitext.gfz-potsdam.de/danschef/py_tools_ds/badges/master/coverage.svg
:target: http://danschef.gitext.gfz-potsdam.de/py_tools_ds/coverage/
......
This diff is collapsed.
......@@ -89,7 +89,7 @@ def get_GDAL_driverList():
if drv.GetMetadataItem(gdal.DCAP_RASTER):
meta = drv.GetMetadataItem(gdal.DMD_EXTENSIONS)
extensions = meta.split() if meta else []
df.ix[i] = [drv.GetDescription(),
df.loc[i] = [drv.GetDescription(),
drv.GetMetadataItem(gdal.DMD_LONGNAME),
extensions[0] if len(extensions) > 0 else np.nan,
extensions[1] if len(extensions) > 1 else np.nan,
......
......@@ -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.23'
__versionalias__ = '20191017_01'
__version__ = '0.14.24'
__versionalias__ = '20200107_01'
six
spectral
pyresample>=1.11.0
......@@ -37,7 +37,7 @@ with open("py_tools_ds/version.py") as version_file:
exec(version_file.read(), version)
requirements = ['gdal', 'numpy', 'shapely', 'six', 'rasterio', 'pandas', 'geopandas',
'scikit-image', 'pyproj', 'spectral', 'pyresample>=1.11.0']
'scikit-image', 'pyproj', 'spectral']
setup_requirements = [] # TODO(danschef): put setup requirements (distutils extensions, etc.) here
test_requirements = requirements + ["coverage", "nose", "nose2", "nose-htmloutput", "rednose"]
......
name: py_tools_ds
channels: &id1
- http://conda.anaconda.org/ioam # only for holoviews
- http://conda.anaconda.org/conda-forge
dependencies:
......@@ -16,7 +15,6 @@ dependencies:
- pyproj
- lxml
- geopandas
- pyresample>=1.11.0
- ipython
- conda-build # for conda deployment
- conda-build-all
......
ENVI
description = {
/home/gfz-fe/scheffler/temp/enpt_testing/geoloc_arr_warping/DEM_UTM32.bsq}
samples = 1262
lines = 508
bands = 1
header offset = 0
file type = ENVI Standard
data type = 2
interleave = bsq
byte order = 0
map info = {UTM, 1, 1, 622613.864409047, 5269351.40255343, 30, 30, 32, North,WGS-84}
coordinate system string = {PROJCS["WGS_1984_UTM_Zone_32N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",9],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]}
band names = {
Band 1}
ENVI
description = {
/home/gfz-fe/scheffler/temp/enpt_testing/geoloc_arr_warping/DEM_UTM33_sensor_geo.bsq}
samples = 1000
lines = 150
bands = 1
header offset = 0
file type = ENVI Standard
data type = 2
interleave = bsq
byte order = 0
map info = {Arbitrary, 1, 1, 0, 0, 1, 1, 0, North}
band names = {
Band 1}
ENVI
description = {
/home/gfz-fe/scheffler/temp/enpt_testing/geoloc_arr_warping/lats_full_vnir.bsq}
samples = 1000
lines = 150
bands = 1
header offset = 0
file type = ENVI Standard
data type = 4
interleave = bsq
byte order = 0
map info = {Arbitrary, 1, 1, 0, 0, 1, 1, 0, North}
band names = {
Band 1}
ENVI
description = {
/home/gfz-fe/scheffler/temp/enpt_testing/geoloc_arr_warping/lons_full_vnir.bsq}
samples = 1000
lines = 150
bands = 1
header offset = 0
file type = ENVI Standard
data type = 4
interleave = bsq
byte order = 0
map info = {Arbitrary, 1, 1, 0, 0, 1, 1, 0, North}
band names = {
Band 1}
......@@ -29,159 +29,4 @@ test_reproject
Tests for `py_tools_ds.geo.raster.reproject` module.
"""
import os
from unittest import TestCase
import numpy as np
from gdalnumeric import LoadFile
from py_tools_ds import __path__
from py_tools_ds.geo.coord_calc import corner_coord_to_minmax, get_corner_coordinates
from py_tools_ds.geo.raster.reproject import SensorMapGeometryTransformer, SensorMapGeometryTransformer3D
tests_path = os.path.abspath(os.path.join(__path__[0], "..", "tests"))
rsp_algs = ['nearest', 'bilinear', 'gauss']
class Test_SensorMapGeometryTransformer(TestCase):
def setUp(self):
self.dem_map_geo = LoadFile(os.path.join(tests_path, 'data', 'dem_map_geo.bsq'))
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
5254111.40255343, # LL_x
660473.864409047, # LL_x
5269351.40255343] # UR_y
self.expected_dem_area_extent_lonlat = [10.685733901515151, # LL_x
47.44113415492957, # LL_y
11.073066098484848, # UR_x
47.54576584507042] # UR_y
self.expected_dem_area_extent_utm = [626938.928052, # LL_x
5256253.56579, # LL_y
656188.928052, # UR_x
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=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)
self.assertFalse(np.array_equal(np.unique(dem_sensors_geo), np.array([0])))
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=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)
self.assertFalse(np.array_equal(np.unique(dem_sensors_geo), np.array([0])))
self.assertEquals(dem_sensors_geo.shape, (150, 1000, 2))
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=rsp_alg)
# to Lon/Lat
dem_map_geo, dem_gt, dem_prj = SMGT.to_map_geometry(self.dem_sensor_geo, tgt_prj=4326)
self.assertIsInstance(dem_map_geo, np.ndarray)
self.assertEquals(dem_map_geo.shape, (SMGT.area_definition.height,
SMGT.area_definition.width))
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_lonlat)))
self.assertFalse(np.array_equal(np.unique(dem_map_geo), np.array([0])))
with self.assertRaises(ValueError):
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=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))
self.assertIsInstance(dem_map_geo, np.ndarray)
self.assertEquals(dem_map_geo.shape, (365, 975))
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)))
self.assertFalse(np.array_equal(np.unique(dem_map_geo), np.array([0])))
class Test_SensorMapGeometryTransformer3D(TestCase):
def setUp(self):
dem_map_geo = LoadFile(os.path.join(tests_path, 'data', 'dem_map_geo.bsq'))
dem_sensor_geo = LoadFile(os.path.join(tests_path, 'data', 'dem_sensor_geo.bsq'))
lons = LoadFile(os.path.join(tests_path, 'data', 'lons_full_vnir.bsq'))
lats = LoadFile(os.path.join(tests_path, 'data', 'lats_full_vnir.bsq'))
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.dem_area_extent_coarse_subset_utm = [622613.864409047, # LL_x
5254111.40255343, # LL_x
660473.864409047, # LL_x
5269351.40255343] # UR_y
self.expected_dem_area_extent_lonlat = [10.685733901515151, # LL_x
47.44113415492957, # LL_y
11.073066098484848, # UR_x
47.54576584507042] # UR_y
self.expected_dem_area_extent_utm = [626938.928052, # LL_x
5256253.56579, # LL_y
656188.928052, # UR_x
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=rsp_alg,
)
# to Lon/Lat
data_mapgeo_3D, dem_gt, dem_prj = SMGT.to_map_geometry(self.data_sensor_geo_3D, tgt_prj=4326)
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.assertEquals(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_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=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)
self.assertIsInstance(dem_sensors_geo, np.ndarray)
self.assertEquals(dem_sensors_geo.shape, (150, 1000, 2))
# TODO
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