Commit 063c8835 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Some adjustments to recent changes in py_tools_ds and pyproj. Added pyproj as...


Some adjustments to recent changes in py_tools_ds and pyproj. Added pyproj as direct dependency to requirements. Updated HISTORY.rst and version info.
Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 71ff4941
Pipeline #12140 failed with stages
in 2 minutes and 57 seconds
...@@ -2,6 +2,13 @@ ...@@ -2,6 +2,13 @@
History History
======= =======
0.4.2 (2020-09-01)
------------------
* Some adjustments to recent changes in py_tools_ds and pyproj.
* Added pyproj as direct dependency to requirements.
0.4.1 (2020-08-17) 0.4.1 (2020-08-17)
------------------ ------------------
......
...@@ -32,8 +32,8 @@ from time import sleep ...@@ -32,8 +32,8 @@ from time import sleep
import numpy as np import numpy as np
import gdal import gdal
from py_tools_ds.geo.projection import EPSG2WKT, WKT2EPSG, proj4_to_WKT, proj4_to_dict from pyproj import CRS
from py_tools_ds.geo.coord_trafo import get_proj4info, transform_coordArray, transform_any_prj from py_tools_ds.geo.coord_trafo import transform_coordArray, transform_any_prj
from py_tools_ds.geo.coord_calc import corner_coord_to_minmax, get_corner_coordinates from py_tools_ds.geo.coord_calc import corner_coord_to_minmax, get_corner_coordinates
from py_tools_ds.geo.coord_grid import find_nearest from py_tools_ds.geo.coord_grid import find_nearest
from py_tools_ds.io.raster.writer import write_numpy_to_image from py_tools_ds.io.raster.writer import write_numpy_to_image
...@@ -145,7 +145,7 @@ class SensorMapGeometryTransformer(object): ...@@ -145,7 +145,7 @@ class SensorMapGeometryTransformer(object):
""" """
# get the target extent if not given # get the target extent if not given
# (this also makes sure that create_area_def does not return a DynamicAreaDefinition) # (this also makes sure that create_area_def does not return a DynamicAreaDefinition)
tgt_epsg = WKT2EPSG(proj4_to_WKT(get_proj4info(proj=tgt_prj))) tgt_epsg = CRS(tgt_prj).to_epsg()
tgt_extent = tgt_extent or self._get_target_extent(tgt_epsg) tgt_extent = tgt_extent or self._get_target_extent(tgt_epsg)
if tgt_res: if tgt_res:
...@@ -159,7 +159,7 @@ class SensorMapGeometryTransformer(object): ...@@ -159,7 +159,7 @@ class SensorMapGeometryTransformer(object):
# passing LonLats and resolution # passing LonLats and resolution
area_definition = \ area_definition = \
create_area_def(area_id='', create_area_def(area_id='',
projection=get_proj4info(proj=tgt_prj), projection=CRS(tgt_prj).to_dict(),
area_extent=tgt_extent, area_extent=tgt_extent,
resolution=tgt_res) resolution=tgt_res)
...@@ -189,7 +189,7 @@ class SensorMapGeometryTransformer(object): ...@@ -189,7 +189,7 @@ class SensorMapGeometryTransformer(object):
# xy_coords = np.dstack([self.swath_definition.lons[::10, ::10], # xy_coords = np.dstack([self.swath_definition.lons[::10, ::10],
# self.swath_definition.lats[::10, ::10]]) # self.swath_definition.lats[::10, ::10]])
else: else:
xy_coords = np.dstack(list(transform_coordArray(EPSG2WKT(4326), EPSG2WKT(tgt_epsg), xy_coords = np.dstack(list(transform_coordArray(CRS(4326).to_wkt(), CRS(tgt_epsg).to_wkt(),
self.swath_definition.lons, self.swath_definition.lons,
self.swath_definition.lats))) self.swath_definition.lats)))
write_numpy_to_image(xy_coords, path_xycoords, 'ENVI') write_numpy_to_image(xy_coords, path_xycoords, 'ENVI')
...@@ -214,7 +214,7 @@ class SensorMapGeometryTransformer(object): ...@@ -214,7 +214,7 @@ class SensorMapGeometryTransformer(object):
"LINE_OFFSET": "0", "LINE_OFFSET": "0",
"PIXEL_STEP": "1", "PIXEL_STEP": "1",
"LINE_STEP": "1", "LINE_STEP": "1",
"SRS": EPSG2WKT(tgt_epsg), "SRS": CRS(tgt_epsg).to_wkt(),
}, "GEOLOCATION") }, "GEOLOCATION")
vrt.FlushCache() vrt.FlushCache()
del ds_data, vrt del ds_data, vrt
...@@ -260,7 +260,7 @@ class SensorMapGeometryTransformer(object): ...@@ -260,7 +260,7 @@ class SensorMapGeometryTransformer(object):
area_definition = AreaDefinition(area_id='', area_definition = AreaDefinition(area_id='',
description='', description='',
proj_id='', proj_id='',
projection=get_proj4info(proj=tgt_prj), projection=CRS(tgt_prj),
width=x_size, width=x_size,
height=y_size, height=y_size,
area_extent=list(out_extent), area_extent=list(out_extent),
...@@ -321,13 +321,7 @@ class SensorMapGeometryTransformer(object): ...@@ -321,13 +321,7 @@ class SensorMapGeometryTransformer(object):
float, float, float], str): float, float, float], str):
gt = area_definition.area_extent[0], area_definition.pixel_size_x, 0, \ gt = area_definition.area_extent[0], area_definition.pixel_size_x, 0, \
area_definition.area_extent[3], 0, -area_definition.pixel_size_y area_definition.area_extent[3], 0, -area_definition.pixel_size_y
with warnings.catch_warnings(): prj = area_definition.crs_wkt
# suppress a UserWarning coming from pyresample v0.15.0
warnings.filterwarnings('ignore', category=UserWarning,
message='You will likely lose important projection information when converting '
'to a PROJ string from another format.')
proj4_str = area_definition.proj_str
prj = proj4_to_WKT(proj4_str)
return gt, prj return gt, prj
...@@ -366,7 +360,7 @@ class SensorMapGeometryTransformer(object): ...@@ -366,7 +360,7 @@ class SensorMapGeometryTransformer(object):
if not tgt_prj: if not tgt_prj:
raise ValueError(tgt_prj, 'Target projection must be given if area_definition is not given.') raise ValueError(tgt_prj, 'Target projection must be given if area_definition is not given.')
tgt_epsg = WKT2EPSG(proj4_to_WKT(get_proj4info(proj=tgt_prj))) tgt_epsg = CRS(tgt_prj).to_epsg()
tgt_extent = tgt_extent or self._get_target_extent(tgt_epsg) tgt_extent = tgt_extent or self._get_target_extent(tgt_epsg)
if tgt_coordgrid: if tgt_coordgrid:
...@@ -400,10 +394,8 @@ class SensorMapGeometryTransformer(object): ...@@ -400,10 +394,8 @@ class SensorMapGeometryTransformer(object):
:param src_prj: projection of the input map geometry array (WKT or 'epsg:1234' or <EPSG_int>) :param src_prj: projection of the input map geometry array (WKT or 'epsg:1234' or <EPSG_int>)
:param src_extent: extent coordinates of input map geometry array (LL_x, LL_y, UR_x, UR_y) in the src_prj :param src_extent: extent coordinates of input map geometry array (LL_x, LL_y, UR_x, UR_y) in the src_prj
""" """
proj4_args = proj4_to_dict(get_proj4info(proj=src_prj))
# get area_definition # get area_definition
self.area_definition = AreaDefinition('', '', '', proj4_args, data.shape[1], data.shape[0], self.area_definition = AreaDefinition('', '', '', CRS(src_prj), data.shape[1], data.shape[0],
list(src_extent)) list(src_extent))
# resample # resample
...@@ -423,7 +415,7 @@ class SensorMapGeometryTransformer(object): ...@@ -423,7 +415,7 @@ class SensorMapGeometryTransformer(object):
def _corner_coords_lonlat_to_extent(corner_coords_ll: List, tgt_epsg: int): def _corner_coords_lonlat_to_extent(corner_coords_ll: List, tgt_epsg: int):
corner_coords_tgt_prj = [transform_any_prj(EPSG2WKT(4326), EPSG2WKT(tgt_epsg), x, y) corner_coords_tgt_prj = [transform_any_prj(4326, tgt_epsg, x, y)
for x, y in corner_coords_ll] for x, y in corner_coords_ll]
corner_coords_tgt_prj_np = np.array(corner_coords_tgt_prj) corner_coords_tgt_prj_np = np.array(corner_coords_tgt_prj)
x_coords = corner_coords_tgt_prj_np[:, 0] x_coords = corner_coords_tgt_prj_np[:, 0]
......
...@@ -28,8 +28,8 @@ from typing import Union, Tuple ...@@ -28,8 +28,8 @@ from typing import Union, Tuple
import multiprocessing import multiprocessing
import numpy as np import numpy as np
from py_tools_ds.geo.projection import WKT2EPSG, EPSG2WKT, proj4_to_WKT from pyproj import CRS
from py_tools_ds.geo.coord_trafo import get_proj4info, transform_any_prj from py_tools_ds.geo.coord_trafo import transform_any_prj
from .transformer_2d import \ from .transformer_2d import \
SensorMapGeometryTransformer, _corner_coords_lonlat_to_extent, \ SensorMapGeometryTransformer, _corner_coords_lonlat_to_extent, \
...@@ -128,7 +128,7 @@ class SensorMapGeometryTransformer3D(object): ...@@ -128,7 +128,7 @@ class SensorMapGeometryTransformer3D(object):
UL_UR_LL_LR_ll = [(self.lons[y, x], self.lats[y, x]) for y, x in [(0, 0), (0, -1), (-1, 0), (-1, -1)]] UL_UR_LL_LR_ll = [(self.lons[y, x], self.lats[y, x]) for y, x in [(0, 0), (0, -1), (-1, 0), (-1, -1)]]
# transform them to target projection # transform them to target projection
UL_UR_LL_LR_prj = [transform_any_prj(EPSG2WKT(4326), EPSG2WKT(tgt_epsg), x, y) for x, y in UL_UR_LL_LR_ll] UL_UR_LL_LR_prj = [transform_any_prj(4326, tgt_epsg, x, y) for x, y in UL_UR_LL_LR_ll]
# separate X and Y # separate X and Y
X_prj, Y_prj = zip(*UL_UR_LL_LR_prj) X_prj, Y_prj = zip(*UL_UR_LL_LR_prj)
...@@ -154,7 +154,7 @@ class SensorMapGeometryTransformer3D(object): ...@@ -154,7 +154,7 @@ class SensorMapGeometryTransformer3D(object):
tgt_coordgrid: Tuple[Tuple, Tuple] = None tgt_coordgrid: Tuple[Tuple, Tuple] = None
) -> AreaDefinition: ) -> AreaDefinition:
# get common target extent # get common target extent
tgt_epsg = WKT2EPSG(proj4_to_WKT(get_proj4info(proj=tgt_prj))) tgt_epsg = CRS(tgt_prj).to_epsg()
tgt_extent = tgt_extent or self._get_common_target_extent(tgt_epsg, tgt_coordgrid=tgt_coordgrid) tgt_extent = tgt_extent or self._get_common_target_extent(tgt_epsg, tgt_coordgrid=tgt_coordgrid)
SMGT2D = SensorMapGeometryTransformer(lons=self.lons[:, :, 0], # does NOT affect the computed area definition SMGT2D = SensorMapGeometryTransformer(lons=self.lons[:, :, 0], # does NOT affect the computed area definition
......
...@@ -37,7 +37,7 @@ version = {} ...@@ -37,7 +37,7 @@ version = {}
with open("sensormapgeo/version.py") as version_file: with open("sensormapgeo/version.py") as version_file:
exec(version_file.read(), version) exec(version_file.read(), version)
requirements = ['numpy', 'gdal', 'pyresample>=1.11.0', 'py_tools_ds>=0.14.26'] requirements = ['numpy', 'gdal', 'pyresample>=1.11.0', 'py_tools_ds>=0.14.26', 'pyproj>=2.2']
setup_requirements = [] setup_requirements = []
......
...@@ -10,12 +10,12 @@ dependencies: ...@@ -10,12 +10,12 @@ dependencies:
- gdal - gdal
- conda-forge::libgdal # force to use conda-forge for libgdal to avoid package version incompatiblies due to mixed channels (libkea.so.1.4.7: cannot open shared object file: No such file or directory) - conda-forge::libgdal # force to use conda-forge for libgdal to avoid package version incompatiblies due to mixed channels (libkea.so.1.4.7: cannot open shared object file: No such file or directory)
- pyresample>=1.11.0 - pyresample>=1.11.0
- pyproj>=2.2
# py_tools_ds # py_tools_ds
- pyqt - pyqt
- scikit-image - scikit-image
- rasterio - rasterio
- pyproj
- lxml - lxml
- geopandas - geopandas
- ipython - ipython
......
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