Commit a7c6c26f authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

moved a couple of functions from GEOPROCESSING to external package...

moved a couple of functions from GEOPROCESSING to external package 'py_tools_ds' and added direct imports within respective modules
GEOP:
- the following functions moved to 'py_tools_ds':
    - transform_utm_to_wgs84
    - transform_wgs84_to_utm
    - transform_any_prj
    - reproject_shapelyPoly
    - lonlat_to_pixel
    - latLonToPixel
    - pixelToLatLon
    - pixelToMapYX
    - mapXY2imXY
    - imXY2mapXY
    - isProjectedOrGeographic
    - EPSG2Proj4
    - EPSG2WKT
    - WKT2EPSG
    - get_UTMzone
    - geotransform2mapinfo
    - mapinfo2geotransform
    - get_corner_coordinates
    - get_prjLonLat
    - get_proj4info
    - proj4_to_dict
    - prj_equal
    - corner_coord_to_minmax
    - get_footprint_polygon
    - get_overlap_polygon
    - find_line_intersection_point
    - calc_FullDataset_corner_positions
    - is_point_on_grid
    - is_coord_grid_equal
    - snap_bounds_to_pixGrid
IO:
- deleted deprecated module envifilehandling
- renamed envifilehandling_BD to envifilehandling
- deleted deprecated module sysenvironment
parent be17e860
This diff is collapsed.
...@@ -50,10 +50,15 @@ from ..io import Output_writer as OUT_W ...@@ -50,10 +50,15 @@ from ..io import Output_writer as OUT_W
from ..misc import path_generator as PG from ..misc import path_generator as PG
from ..misc import database_tools as DB_T from ..misc import database_tools as DB_T
from ..misc.mgrs_tile import MGRS_tile from ..misc.mgrs_tile import MGRS_tile
#from ..io.GeoArray import GeoArray
from py_tools_ds.ptds import GeoArray from py_tools_ds.ptds import GeoArray
job, usecase = builtins.GMS_config.job, builtins.GMS_config.usecase # read from builtins (set by process_controller) from py_tools_ds.ptds.geo.coord_calc import calc_FullDataset_corner_positions
from py_tools_ds.ptds.geo.coord_trafo import pixelToLatLon, pixelToMapYX
from py_tools_ds.ptds.geo.map_info import geotransform2mapinfo, mapinfo2geotransform
from py_tools_ds.ptds.geo.projection import WKT2EPSG
from py_tools_ds.ptds.geo.coord_grid import is_coord_grid_equal
job, usecase = builtins.GMS_config.job, builtins.GMS_config.usecase # read from builtins (set by process_controller)
############################# L1A object ###################################### ############################# L1A object ######################################
class L1A_object(object): class L1A_object(object):
...@@ -214,8 +219,8 @@ class L1A_object(object): ...@@ -214,8 +219,8 @@ class L1A_object(object):
@property @property
def coreg_needed(self): def coreg_needed(self):
gt = GEOP.mapinfo2geotransform(self.meta['map info']) gt = mapinfo2geotransform(self.meta['map info'])
return (GEOP.is_coord_grid_equal(gt, usecase.spatial_ref_gridx, usecase.spatial_ref_gridy) and return (is_coord_grid_equal(gt, usecase.spatial_ref_gridx, usecase.spatial_ref_gridy) and
self.dataset_ID == usecase.datasetid_spatial_ref) is False self.dataset_ID == usecase.datasetid_spatial_ref) is False
...@@ -787,7 +792,7 @@ class L1A_object(object): ...@@ -787,7 +792,7 @@ class L1A_object(object):
previous_dataname = self.MetaObj.Dataname previous_dataname = self.MetaObj.Dataname
if hasattr(self,'arr') and isinstance(self.arr,np.ndarray) and self.MetaObj.Dataname.startswith('/vsi'): if hasattr(self,'arr') and isinstance(self.arr,np.ndarray) and self.MetaObj.Dataname.startswith('/vsi'):
outP = os.path.join(self.ExtractedFolder, self.baseN+'__' + self.arr_desc) outP = os.path.join(self.ExtractedFolder, self.baseN+'__' + self.arr_desc)
GEOP.ndarray2gdal(self.arr,outPath=outP, geotransform=GEOP.mapinfo2geotransform(self.MetaObj.map_info), GEOP.ndarray2gdal(self.arr,outPath=outP, geotransform=mapinfo2geotransform(self.MetaObj.map_info),
projection=self.MetaObj.projection, direction=3) # FIXME ineffective but needed as long as georeference_by_TieP_or_inherent_GCPs does not support direct array inputs projection=self.MetaObj.projection, direction=3) # FIXME ineffective but needed as long as georeference_by_TieP_or_inherent_GCPs does not support direct array inputs
assert os.path.isfile(outP), 'Writing tempfile failed.' assert os.path.isfile(outP), 'Writing tempfile failed.'
self.MetaObj.Dataname = outP self.MetaObj.Dataname = outP
...@@ -1012,21 +1017,21 @@ class L1A_object(object): ...@@ -1012,21 +1017,21 @@ class L1A_object(object):
self.logger.info('Calculating true data corner positions (image and world coordinates)...') self.logger.info('Calculating true data corner positions (image and world coordinates)...')
if re.search('ETM+', self.sensor) and self.acquisition_date > datetime.datetime(year=2003, month=5, day=31): # FIXME add time if re.search('ETM+', self.sensor) and self.acquisition_date > datetime.datetime(year=2003, month=5, day=31): # FIXME add time
self.trueDataCornerPos = GEOP.calc_FullDataset_corner_positions(self.mask_1bit,algorithm='numpy') self.trueDataCornerPos = calc_FullDataset_corner_positions(self.mask_1bit,algorithm='numpy')
else: else:
self.trueDataCornerPos = GEOP.calc_FullDataset_corner_positions(self.mask_1bit) self.trueDataCornerPos = calc_FullDataset_corner_positions(self.mask_1bit)
trueCorPosXY = [tuple(reversed(i)) for i in self.trueDataCornerPos] trueCorPosXY = [tuple(reversed(i)) for i in self.trueDataCornerPos]
gt = GEOP.mapinfo2geotransform(self.MetaObj.map_info gt = mapinfo2geotransform(self.MetaObj.map_info
if hasattr(self,'MetaObj') and self.MetaObj else self.meta['map info']) if hasattr(self,'MetaObj') and self.MetaObj else self.meta['map info'])
prj = self.MetaObj.projection if hasattr(self,'MetaObj') and self.MetaObj else \ prj = self.MetaObj.projection if hasattr(self,'MetaObj') and self.MetaObj else \
self.meta['projection'] if 'projection' in self.meta else self.meta['coordinate system string'] self.meta['projection'] if 'projection' in self.meta else self.meta['coordinate system string']
trueCorLatLon = GEOP.pixelToLatLon(trueCorPosXY,geotransform=gt,projection=prj) trueCorLatLon = pixelToLatLon(trueCorPosXY,geotransform=gt,projection=prj)
self.trueDataCornerLonLat = [tuple(reversed(i)) for i in trueCorLatLon] self.trueDataCornerLonLat = [tuple(reversed(i)) for i in trueCorLatLon]
rows,cols = self.shape_fullArr[:2] rows,cols = self.shape_fullArr[:2]
CorPosXY = [(0,0),(cols,0),(0,rows),(cols,rows)] CorPosXY = [(0,0),(cols,0),(0,rows),(cols,rows)]
CorLatLon = GEOP.pixelToLatLon(CorPosXY,geotransform=gt,projection=prj) CorLatLon = pixelToLatLon(CorPosXY,geotransform=gt,projection=prj)
self.corner_lonlat = [tuple(reversed(i)) for i in CorLatLon] self.corner_lonlat = [tuple(reversed(i)) for i in CorLatLon]
...@@ -1260,7 +1265,7 @@ class L1A_object(object): ...@@ -1260,7 +1265,7 @@ class L1A_object(object):
geoArr = getattr(self,arrname) if isinstance(getattr(self,arrname),GeoArray) else getattr(self,arrname) geoArr = getattr(self,arrname) if isinstance(getattr(self,arrname),GeoArray) else getattr(self,arrname)
nodata = HLP_F.get_outFillZeroSaturated(geoArr)[0] nodata = HLP_F.get_outFillZeroSaturated(geoArr)[0]
meta2update = sub_GMS_obj.meta if arrname == 'arr' else sub_GMS_obj.masks_meta meta2update = sub_GMS_obj.meta if arrname == 'arr' else sub_GMS_obj.masks_meta
gt = GEOP.mapinfo2geotransform(meta2update['map info']) gt = mapinfo2geotransform(meta2update['map info'])
prj = meta2update['coordinate system string'] prj = meta2update['coordinate system string']
# get subsetted and (possibly) reprojected array # get subsetted and (possibly) reprojected array
...@@ -1273,11 +1278,11 @@ class L1A_object(object): ...@@ -1273,11 +1278,11 @@ class L1A_object(object):
# update array-related attributes of sub_GMS_obj # update array-related attributes of sub_GMS_obj
setattr(sub_GMS_obj, arrname, sub_arr) setattr(sub_GMS_obj, arrname, sub_arr)
meta2update['map info'] = GEOP.geotransform2mapinfo(sub_gt,sub_prj) meta2update['map info'] = geotransform2mapinfo(sub_gt,sub_prj)
meta2update['coordinate system string'] = sub_prj meta2update['coordinate system string'] = sub_prj
meta2update['lines'], meta2update['samples'] = sub_arr.shape[:2] meta2update['lines'], meta2update['samples'] = sub_arr.shape[:2]
meta2update['CS_UTM_ZONE'] = GEOP.get_UTMzone(prj=sub_prj) # FIXME only works for UTM meta2update['CS_UTM_ZONE'] = GEOP.get_UTMzone(prj=sub_prj) # FIXME only works for UTM
meta2update['CS_EPSG'] = GEOP.WKT2EPSG(sub_prj) meta2update['CS_EPSG'] = WKT2EPSG(sub_prj)
# copy subset mask data to mask_1bit and mask_clouds # copy subset mask data to mask_1bit and mask_clouds
sub_GMS_obj.mask_1bit = sub_GMS_obj.masks[:,:,0] sub_GMS_obj.mask_1bit = sub_GMS_obj.masks[:,:,0]
...@@ -1292,8 +1297,8 @@ class L1A_object(object): ...@@ -1292,8 +1297,8 @@ class L1A_object(object):
# calculate new attributes 'corner_utm' and 'corner_lonlat' # calculate new attributes 'corner_utm' and 'corner_lonlat'
ULxy, URxy, LLxy, LRxy = [[0, 0], [cols - 1, 0], [0, rows - 1], [cols - 1, rows - 1]] ULxy, URxy, LLxy, LRxy = [[0, 0], [cols - 1, 0], [0, rows - 1], [cols - 1, rows - 1]]
utm_coord_YX = GEOP.pixelToMapYX ([ULxy, URxy, LLxy, LRxy], geotransform=sub_gt, projection=sub_prj) # FIXME asserts gt in UTM coordinates utm_coord_YX = pixelToMapYX ([ULxy, URxy, LLxy, LRxy], geotransform=sub_gt, projection=sub_prj) # FIXME asserts gt in UTM coordinates
lonlat_coord = GEOP.pixelToLatLon([ULxy, URxy, LLxy, LRxy], geotransform=sub_gt, projection=sub_prj) # ULyx,URyx,LLyx,LRyx lonlat_coord = pixelToLatLon([ULxy, URxy, LLxy, LRxy], geotransform=sub_gt, projection=sub_prj) # ULyx,URyx,LLyx,LRyx
sub_GMS_obj.corner_utm = [[YX[1], YX[0]] for YX in utm_coord_YX] # ULxy,URxy,LLxy,LRxy sub_GMS_obj.corner_utm = [[YX[1], YX[0]] for YX in utm_coord_YX] # ULxy,URxy,LLxy,LRxy
sub_GMS_obj.corner_lonlat = [[YX[1], YX[0]] for YX in lonlat_coord] # ULxy,URxy,LLxy,LRxy sub_GMS_obj.corner_lonlat = [[YX[1], YX[0]] for YX in lonlat_coord] # ULxy,URxy,LLxy,LRxy
...@@ -1303,22 +1308,22 @@ class L1A_object(object): ...@@ -1303,22 +1308,22 @@ class L1A_object(object):
# calculate data_corners_imXY # calculate data_corners_imXY
if isinstance(sub_GMS_obj.mask_1bit, np.ndarray): if isinstance(sub_GMS_obj.mask_1bit, np.ndarray):
corners_imYX = GEOP.calc_FullDataset_corner_positions( corners_imYX = calc_FullDataset_corner_positions(
sub_GMS_obj.mask_1bit, assert_four_corners=False, algorithm='shapely') sub_GMS_obj.mask_1bit, assert_four_corners=False, algorithm='shapely')
else: # str # FIXME not needed anymore because geoArr.get_mapPos always returns an array? else: # str # FIXME not needed anymore because geoArr.get_mapPos always returns an array?
from ..io.Input_reader import read_mask_subset from ..io.Input_reader import read_mask_subset
subset = ('block', ((rS, rE), (cS, cE))) subset = ('block', ((rS, rE), (cS, cE)))
mask_1bit = read_mask_subset(sub_GMS_obj.mask_1bit, 'mask_1bit', sub_GMS_obj.logger, subset) mask_1bit = read_mask_subset(sub_GMS_obj.mask_1bit, 'mask_1bit', sub_GMS_obj.logger, subset)
corners_imYX = GEOP.calc_FullDataset_corner_positions(mask_1bit, assert_four_corners=False, algorithm='shapely') corners_imYX = calc_FullDataset_corner_positions(mask_1bit, assert_four_corners=False, algorithm='shapely')
sub_GMS_obj.data_corners_imXY = [(YX[1], YX[0]) for YX in corners_imYX] sub_GMS_obj.data_corners_imXY = [(YX[1], YX[0]) for YX in corners_imYX]
# calculate data_corners_LonLat # calculate data_corners_LonLat
data_corners_LatLon = GEOP.pixelToLatLon(sub_GMS_obj.data_corners_imXY, data_corners_LatLon = pixelToLatLon(sub_GMS_obj.data_corners_imXY,
geotransform=sub_gt, projection=sub_prj) geotransform=sub_gt, projection=sub_prj)
sub_GMS_obj.data_corners_LonLat = [(YX[1], YX[0]) for YX in data_corners_LatLon] sub_GMS_obj.data_corners_LonLat = [(YX[1], YX[0]) for YX in data_corners_LatLon]
# calculate data_corners_utm # calculate data_corners_utm
data_corners_utmYX = GEOP.pixelToMapYX([ULxy, URxy, LLxy, LRxy], data_corners_utmYX = pixelToMapYX([ULxy, URxy, LLxy, LRxy],
geotransform=sub_gt, projection=sub_prj) # FIXME asserts gt in UTM coordinates geotransform=sub_gt, projection=sub_prj) # FIXME asserts gt in UTM coordinates
sub_GMS_obj.data_corners_utm = [(YX[1], YX[0]) for YX in data_corners_utmYX] sub_GMS_obj.data_corners_utm = [(YX[1], YX[0]) for YX in data_corners_utmYX]
...@@ -1346,7 +1351,7 @@ class L1A_object(object): ...@@ -1346,7 +1351,7 @@ class L1A_object(object):
trueDataCornerLonLat=self.trueDataCornerLonLat) trueDataCornerLonLat=self.trueDataCornerLonLat)
# calculate image coordinate bounds of the full GMS object for each MGRS tile within the GeoDataFrame # calculate image coordinate bounds of the full GMS object for each MGRS tile within the GeoDataFrame
gt, prj = GEOP.mapinfo2geotransform(self.meta['map info']), self.meta['coordinate system string'] gt, prj = mapinfo2geotransform(self.meta['map info']), self.meta['coordinate system string']
get_arrBounds = lambda MGRStileObj: \ get_arrBounds = lambda MGRStileObj: \
list(np.array(MGRStileObj.poly_utm.buffer(pixbuffer*gt[1]).bounds)[[0, 2, 1, 3]]) list(np.array(MGRStileObj.poly_utm.buffer(pixbuffer*gt[1]).bounds)[[0, 2, 1, 3]])
......
...@@ -54,7 +54,7 @@ from geopandas import GeoDataFrame ...@@ -54,7 +54,7 @@ from geopandas import GeoDataFrame
job, usecase, GMS_call_type = builtins.GMS_config.job, builtins.GMS_config.usecase, builtins.GMS_config.GMS_call_type job, usecase, GMS_call_type = builtins.GMS_config.job, builtins.GMS_config.usecase, builtins.GMS_config.GMS_call_type
from ..io import Output_writer as OUT_W from ..io import Output_writer as OUT_W
from ..misc import helper_functions as HLP_F from ..misc import helper_functions as HLP_F
from . import GEOPROCESSING as GEOP from . import GEOPROCESSING as GEOP # FIXME import functions directly as soon as GEOPROCESSING is included in algorithms.__init__.__all__
from ..misc import path_generator as PG from ..misc import path_generator as PG
from ..misc import database_tools as DB_T from ..misc import database_tools as DB_T
from .L1A_P import L1A_object from .L1A_P import L1A_object
...@@ -63,6 +63,14 @@ from ..misc.SpatialIndexMediator import SpatialIndexMediator ...@@ -63,6 +63,14 @@ from ..misc.SpatialIndexMediator import SpatialIndexMediator
#sys.path.append('/home/gfz-fe/') #sys.path.append('/home/gfz-fe/')
from CoReg_Sat import COREG, DESHIFTER from CoReg_Sat import COREG, DESHIFTER
from py_tools_ds.ptds import GeoArray from py_tools_ds.ptds import GeoArray
from py_tools_ds.ptds.geo.map_info import mapinfo2geotransform
from py_tools_ds.ptds.geo.coord_grid import is_coord_grid_equal
from py_tools_ds.ptds.geo.projection import get_proj4info, get_prjLonLat, prj_equal, EPSG2WKT
from py_tools_ds.ptds.geo.coord_calc import corner_coord_to_minmax
from py_tools_ds.ptds.geo.coord_trafo import reproject_shapelyPoly, transform_wgs84_to_utm, pixelToMapYX, transform_any_prj
from py_tools_ds.ptds.geo.vector.topology import get_overlap_polygon
from py_tools_ds.ptds.geo.raster.reproject import warp_ndarray
# <editor-fold desc="deprecated/unused functions"> # <editor-fold desc="deprecated/unused functions">
...@@ -224,8 +232,8 @@ class COREG_OLD(object): ...@@ -224,8 +232,8 @@ class COREG_OLD(object):
self.footprint_poly = HLP_F.CornerLonLat_to_shapelyPoly(dict_L1A_Instance['trueDataCornerLonLat']) self.footprint_poly = HLP_F.CornerLonLat_to_shapelyPoly(dict_L1A_Instance['trueDataCornerLonLat'])
self.map_info_to_update = dict_L1A_Instance['meta']['map info'] self.map_info_to_update = dict_L1A_Instance['meta']['map info']
self.shift_prj = dict_L1A_Instance['meta']['coordinate system string'] self.shift_prj = dict_L1A_Instance['meta']['coordinate system string']
self.shift_gt = GEOP.mapinfo2geotransform(self.map_info_to_update) self.shift_gt = mapinfo2geotransform(self.map_info_to_update)
self.coreg_needed = (GEOP.is_coord_grid_equal(self.shift_gt,usecase.spatial_ref_gridx, self.coreg_needed = (is_coord_grid_equal(self.shift_gt,usecase.spatial_ref_gridx,
usecase.spatial_ref_gridy) and usecase.spatial_ref_gridy) and
self.dataset_ID==usecase.datasetid_spatial_ref)==False self.dataset_ID==usecase.datasetid_spatial_ref)==False
...@@ -296,7 +304,7 @@ class COREG_OLD(object): ...@@ -296,7 +304,7 @@ class COREG_OLD(object):
assert self.shift_prj , 'The image to be shifted has no projection.' assert self.shift_prj , 'The image to be shifted has no projection.'
assert not re.search('LOCAL_CS',self.shift_prj), 'The image to be shifted is not georeferenced.' assert not re.search('LOCAL_CS',self.shift_prj), 'The image to be shifted is not georeferenced.'
assert self.shift_gt , 'The image to be shifted has no map information.' assert self.shift_gt , 'The image to be shifted has no map information.'
assert GEOP.get_proj4info(self.ds_imref) == GEOP.get_proj4info(self.ds_im2shift),\ assert get_proj4info(self.ds_imref) == get_proj4info(self.ds_im2shift),\
'Input projections are not equal. Different projections are currently not supported.' 'Input projections are not equal. Different projections are currently not supported.'
"""optionally write shapes (always LonLat because GMS shapely polygons are always LonLat""" """optionally write shapes (always LonLat because GMS shapely polygons are always LonLat"""
...@@ -305,9 +313,9 @@ class COREG_OLD(object): ...@@ -305,9 +313,9 @@ class COREG_OLD(object):
self.verbose_out = os.path.join(PG.path_generator(dict_L1A_Instance).get_path_procdata(), self.verbose_out = os.path.join(PG.path_generator(dict_L1A_Instance).get_path_procdata(),
'CoReg_verboseOut__%s__shifted_to__%s' %(get_baseN(self.path_im2shift), get_baseN(self.path_imref))) 'CoReg_verboseOut__%s__shifted_to__%s' %(get_baseN(self.path_im2shift), get_baseN(self.path_imref)))
if not os.path.isdir(self.verbose_out): os.makedirs(self.verbose_out) if not os.path.isdir(self.verbose_out): os.makedirs(self.verbose_out)
OUT_W.write_shp_OLD(self.imref_footprint_poly, os.path.join(self.verbose_out, 'poly_imref.shp'), GEOP.get_prjLonLat()) OUT_W.write_shp_OLD(self.imref_footprint_poly, os.path.join(self.verbose_out, 'poly_imref.shp'), get_prjLonLat())
OUT_W.write_shp_OLD(self.footprint_poly, os.path.join(self.verbose_out, 'poly_im2shift.shp'), GEOP.get_prjLonLat()) OUT_W.write_shp_OLD(self.footprint_poly, os.path.join(self.verbose_out, 'poly_im2shift.shp'), get_prjLonLat())
OUT_W.write_shp_OLD(self.overlap_poly, os.path.join(self.verbose_out, 'overlap_poly.shp'), GEOP.get_prjLonLat()) OUT_W.write_shp_OLD(self.overlap_poly, os.path.join(self.verbose_out, 'overlap_poly.shp'), get_prjLonLat())
"""get bands to use for matching""" """get bands to use for matching"""
self.get_opt_bands4matching(target_cwlPos_nm=550) self.get_opt_bands4matching(target_cwlPos_nm=550)
...@@ -330,7 +338,7 @@ class COREG_OLD(object): ...@@ -330,7 +338,7 @@ class COREG_OLD(object):
max_cloudcov = 20 # % max_cloudcov = 20 # %
plusminus_days = 30 plusminus_days = 30
plusminus_years = 10 plusminus_years = 10
boundsLonLat = GEOP.corner_coord_to_minmax(self.trueDataCornerLonLat) boundsLonLat = corner_coord_to_minmax(self.trueDataCornerLonLat)
AcqDate = self.im2shift_objDict['acquisition_date'] AcqDate = self.im2shift_objDict['acquisition_date']
add_years = lambda dt, years: dt.replace(dt.year + years) \ add_years = lambda dt, years: dt.replace(dt.year + years) \
if not (dt.month==2 and dt.day==29) else dt.replace(dt.year+years,3,1) if not (dt.month==2 and dt.day==29) else dt.replace(dt.year+years,3,1)
...@@ -365,12 +373,12 @@ class COREG_OLD(object): ...@@ -365,12 +373,12 @@ class COREG_OLD(object):
GDF['cloudcover'] = [*GDF['object'].map(lambda scene: scene.cloudcover)] GDF['cloudcover'] = [*GDF['object'].map(lambda scene: scene.cloudcover)]
GDF['polyLonLat'] = [*GDF['object'].map(lambda scene: scene.polyLonLat)] GDF['polyLonLat'] = [*GDF['object'].map(lambda scene: scene.polyLonLat)]
LonLat2UTM = lambda polyLL: GEOP.reproject_shapelyPoly(polyLL,self.shift_prj) LonLat2UTM = lambda polyLL: reproject_shapelyPoly(polyLL,self.shift_prj)
GDF['polyUTM'] = [*GDF['polyLonLat'].map(LonLat2UTM)] GDF['polyUTM'] = [*GDF['polyLonLat'].map(LonLat2UTM)]
#get overlap parameter #get overlap parameter
get_OL_prms = lambda poly: GEOP.get_overlap_polygon(poly, self.footprint_poly) get_OL_prms = lambda poly: get_overlap_polygon(poly, self.footprint_poly)
GDF['overlapParams'] = [*GDF['polyLonLat'].map(get_OL_prms)] GDF['overlapParams'] = [*GDF['polyLonLat'].map(get_OL_prms)]
GDF['overlap area'] = [*GDF['overlapParams'].map(lambda OL_prms: OL_prms['overlap area'])] GDF['overlap area'] = [*GDF['overlapParams'].map(lambda OL_prms: OL_prms['overlap area'])]
GDF['overlap percentage'] = [*GDF['overlapParams'].map(lambda OL_prms: OL_prms['overlap percentage'])] GDF['overlap percentage'] = [*GDF['overlapParams'].map(lambda OL_prms: OL_prms['overlap percentage'])]
...@@ -418,7 +426,7 @@ class COREG_OLD(object): ...@@ -418,7 +426,7 @@ class COREG_OLD(object):
from ..io.Input_reader import read_ENVIhdr_to_dict from ..io.Input_reader import read_ENVIhdr_to_dict
get_prj = lambda path_binary: \ get_prj = lambda path_binary: \
read_ENVIhdr_to_dict(os.path.splitext(path_binary)[0]+'.hdr')['coordinate system string'] read_ENVIhdr_to_dict(os.path.splitext(path_binary)[0]+'.hdr')['coordinate system string']
is_prj_equal = lambda path_binary: GEOP.prj_equal(self.shift_prj, get_prj(path_binary)) is_prj_equal = lambda path_binary: prj_equal(self.shift_prj, get_prj(path_binary))
GDF['prj_equal'] = [*GDF['path_ref'].map(is_prj_equal)] GDF['prj_equal'] = [*GDF['path_ref'].map(is_prj_equal)]
# filter scenes out that have a different projection # filter scenes out that have a different projection
...@@ -591,7 +599,7 @@ class COREG_OLD(object): ...@@ -591,7 +599,7 @@ class COREG_OLD(object):
# get overlap polygons and their parameters. result: [{overlap poly, overlap percentage, overlap area}] # get overlap polygons and their parameters. result: [{overlap poly, overlap percentage, overlap area}]
for dic in dict_sceneID_poly: # input: dicts {scene_ID, ref_poly} for dic in dict_sceneID_poly: # input: dicts {scene_ID, ref_poly}
dict_overlap_poly_params = GEOP.get_overlap_polygon(dic['scene poly'], self.footprint_poly) dict_overlap_poly_params = get_overlap_polygon(dic['scene poly'], self.footprint_poly)
dic.update(dict_overlap_poly_params) # adds {overlap poly, overlap percentage, overlap area} dic.update(dict_overlap_poly_params) # adds {overlap poly, overlap percentage, overlap area}
#print('polygon creation time', time.time()-t0) #print('polygon creation time', time.time()-t0)
...@@ -624,11 +632,11 @@ class COREG_OLD(object): ...@@ -624,11 +632,11 @@ class COREG_OLD(object):
overlap_center_pos_x, overlap_center_pos_y = self.overlap_poly.centroid.coords.xy overlap_center_pos_x, overlap_center_pos_y = self.overlap_poly.centroid.coords.xy
# transform to reference projection if needed (get_image_windows_to_match expects win_pos as ref_prj # transform to reference projection if needed (get_image_windows_to_match expects win_pos as ref_prj
if GEOP.get_proj4info(proj=self.ref_prj) != GEOP.get_prjLonLat(fmt='Proj4'): # reference has no LonLat projection if get_proj4info(proj=self.ref_prj) != get_prjLonLat(fmt='Proj4'): # reference has no LonLat projection
srs = osr.SpatialReference() srs = osr.SpatialReference()
srs.ImportFromWkt(self.ref_prj) srs.ImportFromWkt(self.ref_prj)
assert srs.IsProjected(), 'L1B processor only takes LonLat or UTM datasets' # FIXME Bug assert srs.IsProjected(), 'L1B processor only takes LonLat or UTM datasets' # FIXME Bug
X,Y = GEOP.transform_wgs84_to_utm(overlap_center_pos_x[0],overlap_center_pos_y[0],srs.GetUTMZone())[:2] X,Y = transform_wgs84_to_utm(overlap_center_pos_x[0],overlap_center_pos_y[0],srs.GetUTMZone())[:2]
overlap_center_pos = [Y,X] overlap_center_pos = [Y,X]
else: else:
overlap_center_pos = [overlap_center_pos_y[0], overlap_center_pos_x[0]] overlap_center_pos = [overlap_center_pos_y[0], overlap_center_pos_x[0]]
...@@ -798,7 +806,7 @@ class COREG_OLD(object): ...@@ -798,7 +806,7 @@ class COREG_OLD(object):
# map-koordinaten der clip-box von imref ausrechnen # map-koordinaten der clip-box von imref ausrechnen
imref_box_xy = [[int(i[1]), int(i[0])] for i in imref_box] # swap X and Y values imref_box_xy = [[int(i[1]), int(i[0])] for i in imref_box] # swap X and Y values
imref_box_map = GEOP.pixelToMapYX(imref_box_xy, geotransform=self.ref_gt, projection=self.ref_prj) # [[4455560.0, 299060.0], [4450440.0, 293940.0]] [[HW,RW],[HW,RW]] imref_box_map = pixelToMapYX(imref_box_xy, geotransform=self.ref_gt, projection=self.ref_prj) # [[4455560.0, 299060.0], [4450440.0, 293940.0]] [[HW,RW],[HW,RW]]
map_xvals = [i[1] for i in imref_box_map] # UTM-RW map_xvals = [i[1] for i in imref_box_map] # UTM-RW
map_yvals = [i[0] for i in imref_box_map] # UTM-HW map_yvals = [i[0] for i in imref_box_map] # UTM-HW
...@@ -811,9 +819,9 @@ class COREG_OLD(object): ...@@ -811,9 +819,9 @@ class COREG_OLD(object):
rsp_algor = 2 # 'cubic' rsp_algor = 2 # 'cubic'
im2shift_nodata = HLP_F.get_outFillZeroSaturated(im2shift_data.dtype)[0] im2shift_nodata = HLP_F.get_outFillZeroSaturated(im2shift_data.dtype)[0]
im2shift_clip_data = GEOP.warp_ndarray(im2shift_data,self.shift_gt,self.shift_prj,self.ref_prj, im2shift_clip_data = warp_ndarray(im2shift_data,self.shift_gt,self.shift_prj,self.ref_prj,
out_res=(imfft_gsd_mapvalues, imfft_gsd_mapvalues),out_extent=([min(map_xvals), min(map_yvals), out_gsd=(imfft_gsd_mapvalues, imfft_gsd_mapvalues),out_bounds=([min(map_xvals), min(map_yvals),
max(map_xvals),max(map_yvals)]), rsp_alg=rsp_algor, in_nodata=im2shift_nodata) [0] max(map_xvals),max(map_yvals)]), rspAlg=rsp_algor, in_nodata=im2shift_nodata) [0]
else: else:
"""falls referenz die höhere auflösung hat""" """falls referenz die höhere auflösung hat"""
...@@ -839,7 +847,7 @@ class COREG_OLD(object): ...@@ -839,7 +847,7 @@ class COREG_OLD(object):
imref_box = [[winPosDict_imref['row']-clip_sz//2, winPosDict_imref['col']-clip_sz//2], imref_box = [[winPosDict_imref['row']-clip_sz//2, winPosDict_imref['col']-clip_sz//2],
[winPosDict_imref['row']+clip_sz//2, winPosDict_imref['col']+clip_sz//2]] # [UL,LR] [winPosDict_imref['row']+clip_sz//2, winPosDict_imref['col']+clip_sz//2]] # [UL,LR]
imref_box_xy = [[int(i[1]), int(i[0])] for i in imref_box] # swap X and Y values imref_box_xy = [[int(i[1]), int(i[0])] for i in imref_box] # swap X and Y values
imref_box_map = GEOP.pixelToMapYX(imref_box_xy, geotransform=self.ref_gt, projection=self.ref_prj) # [[4455560.0, 299060.0], [4450440.0, 293940.0]] [[HW,RW],[HW,RW]] imref_box_map = pixelToMapYX(imref_box_xy, geotransform=self.ref_gt, projection=self.ref_prj) # [[4455560.0, 299060.0], [4450440.0, 293940.0]] [[HW,RW],[HW,RW]]
map_xvals = [i[1] for i in imref_box_map] # UTM-RW map_xvals = [i[1] for i in imref_box_map] # UTM-RW
map_yvals = [i[0] for i in imref_box_map] # UTM-HW map_yvals = [i[0] for i in imref_box_map] # UTM-HW
...@@ -860,15 +868,15 @@ class COREG_OLD(object): ...@@ -860,15 +868,15 @@ class COREG_OLD(object):
raise TypeError('COREG.imref must contain a path, a numpy array or None. Got %s' %type(self.imref)) raise TypeError('COREG.imref must contain a path, a numpy array or None. Got %s' %type(self.imref))
im2ref_nodata = HLP_F.get_outFillZeroSaturated(imref_data.dtype)[0] im2ref_nodata = HLP_F.get_outFillZeroSaturated(imref_data.dtype)[0]
imref_clip_data = GEOP.warp_ndarray(imref_data,self.ref_gt,self.ref_prj,self.ref_prj, imref_clip_data = warp_ndarray(imref_data,self.ref_gt,self.ref_prj,self.ref_prj,
out_res=(imfft_gsd_mapvalues, imfft_gsd_mapvalues),out_extent=([min(map_xvals), min(map_yvals), out_gsd=(imfft_gsd_mapvalues, imfft_gsd_mapvalues),out_bounds=([min(map_xvals), min(map_yvals),
max(map_xvals),max(map_yvals)]), rsp_alg=rsp_algor, in_nodata=im2ref_nodata) [0] max(map_xvals),max(map_yvals)]), rspAlg=rsp_algor, in_nodata=im2ref_nodata) [0]
# im2shift mit imref_box_map ausclippen (cubic, da pixelgrenzen verschoben werden müssen aber auflösung # im2shift mit imref_box_map ausclippen (cubic, da pixelgrenzen verschoben werden müssen aber auflösung
# gleich bleibt) # gleich bleibt)
im2shift_clip_data = GEOP.warp_ndarray(im2shift_data,self.shift_gt,self.shift_prj,self.ref_prj, im2shift_clip_data = warp_ndarray(im2shift_data,self.shift_gt,self.shift_prj,self.ref_prj,
out_res=(imfft_gsd_mapvalues, imfft_gsd_mapvalues),out_extent=([min(map_xvals), min(map_yvals), out_gsd=(imfft_gsd_mapvalues, imfft_gsd_mapvalues),out_bounds=([min(map_xvals), min(map_yvals),
max(map_xvals),max(map_yvals)]), rsp_alg=2, in_nodata=im2ref_nodata) [0] max(map_xvals),max(map_yvals)]), rspAlg=2, in_nodata=im2ref_nodata) [0]
# te_srs is not neccessary because -t_srs = imref_proj and output extent is derived from imref # te_srs is not neccessary because -t_srs = imref_proj and output extent is derived from imref
gsd_factor = imfft_gsd_mapvalues/im2shift_gsd gsd_factor = imfft_gsd_mapvalues/im2shift_gsd
...@@ -1073,7 +1081,7 @@ class COREG_OLD(object): ...@@ -1073,7 +1081,7 @@ class COREG_OLD(object):
def get_updated_map_info(self): def get_updated_map_info(self):
if not self.q: print('Original map info:', self.map_info_to_update) if not self.q: print('Original map info:', self.map_info_to_update)
new_originY, new_originX = GEOP.pixelToMapYX([self.x_shift_px,self.y_shift_px], new_originY, new_originX = pixelToMapYX([self.x_shift_px,self.y_shift_px],
geotransform=self.shift_gt, projection=self.shift_prj)[0] geotransform=self.shift_gt, projection=self.shift_prj)[0]
self.x_shift_map = new_originX - self.shift_gt[0] self.x_shift_map = new_originX - self.shift_gt[0]
self.y_shift_map = new_originY - self.shift_gt[3] self.y_shift_map = new_originY - self.shift_gt[3]
...@@ -1133,7 +1141,7 @@ class Scene_getter(object): ...@@ -1133,7 +1141,7 @@ class Scene_getter(object):
GDF['acquisitiondate'] = [*GDF['object'].map(lambda scene: scene.acquisitiondate)] GDF['acquisitiondate'] = [*GDF['object'].map(lambda scene: scene.acquisitiondate)]
GDF['cloudcover'] = [*GDF['object'].map(lambda scene: scene.cloudcover)] GDF['cloudcover'] = [*GDF['object'].map(lambda scene: scene.cloudcover)]
GDF['polyLonLat'] = [*GDF['object'].map(lambda scene: scene.polyLonLat)] GDF['polyLonLat'] = [*GDF['object'].map(lambda scene: scene.polyLonLat)]
LonLat2UTM = lambda polyLL: GEOP.reproject_shapelyPoly(polyLL, self.src_prj) LonLat2UTM = lambda polyLL: reproject_shapelyPoly(polyLL, self.src_prj)
GDF['polyUTM'] = [*GDF['polyLonLat'].map(LonLat2UTM)] GDF['polyUTM'] = [*GDF['polyLonLat'].map(LonLat2UTM)]
self.GDF_ref_scenes = GDF self.GDF_ref_scenes = GDF
...@@ -1164,7 +1172,7 @@ class Scene_getter(object): ...@@ -1164,7 +1172,7 @@ class Scene_getter(object):
GDF = self.GDF_ref_scenes GDF = self.GDF_ref_scenes
if not GDF.empty: if not GDF.empty:
#get overlap parameter #get overlap parameter
get_OL_prms = lambda poly: GEOP.get_overlap_polygon(poly, self.src_footprint_poly) get_OL_prms = lambda poly: get_overlap_polygon(poly, self.src_footprint_poly)
GDF['overlapParams'] = [*GDF['polyLonLat'].map(get_OL_prms)] GDF['overlapParams'] = [*GDF['polyLonLat'].map(get_OL_prms)]
GDF['overlap area'] = [*GDF['overlapParams'].map(lambda OL_prms: OL_prms['overlap area'])] GDF['overlap area'] = [*GDF['overlapParams'].map(lambda OL_prms: OL_prms['overlap area'])]
GDF['overlap percentage'] = [*GDF['overlapParams'].map(lambda OL_prms: OL_prms['overlap percentage'])] GDF['overlap percentage'] = [*GDF['overlapParams'].map(lambda OL_prms: OL_prms['overlap percentage'])]
...@@ -1225,7 +1233,7 @@ class Scene_getter(object): ...@@ -1225,7 +1233,7 @@ class Scene_getter(object):
from ..io.Input_reader import read_ENVIhdr_to_dict from ..io.Input_reader import read_ENVIhdr_to_dict
get_prj = lambda path_binary: \ get_prj = lambda path_binary: \
read_ENVIhdr_to_dict(os.path.splitext(path_binary)[0] + '.hdr')['coordinate system string'] read_ENVIhdr_to_dict(os.path.splitext(path_binary)[0] + '.hdr')['coordinate system string']
is_prj_equal = lambda path_binary: GEOP.prj_equal(self.src_prj, get_prj(path_binary)) is_prj_equal = lambda path_binary: prj_equal(self.src_prj, get_prj(path_binary))
GDF['prj_equal'] = [*GDF['path_ref'].map(is_prj_equal)] GDF['prj_equal'] = [*GDF['path_ref'].map(is_prj_equal)]
# filter scenes out that have a different projection # filter scenes out that have a different projection
...@@ -1276,7 +1284,7 @@ class L1B_object(L1A_object): ...@@ -1276,7 +1284,7 @@ class L1B_object(L1A_object):
def get_spatial_reference_scene(self): def get_spatial_reference_scene(self):
boundsLonLat = GEOP.corner_coord_to_minmax(self.trueDataCornerLonLat) boundsLonLat = corner_coord_to_minmax(self.trueDataCornerLonLat)
footprint_poly = HLP_F.CornerLonLat_to_shapelyPoly(self.trueDataCornerLonLat) footprint_poly = HLP_F.CornerLonLat_to_shapelyPoly(self.trueDataCornerLonLat)
RSG = Scene_getter(boundsLonLat, self.acquisition_date, self.meta['coordinate system string'], RSG = Scene_getter(boundsLonLat, self.acquisition_date, self.meta['coordinate system string'],
footprint_poly, 20, 0, 20, 30, 10) footprint_poly, 20, 0, 20, 30, 10)
...@@ -1374,7 +1382,7 @@ class L1B_object(L1A_object): ...@@ -1374,7 +1382,7 @@ class L1B_object(L1A_object):
'align_grids' : True, # FIXME not needed here 'align_grids' : True, # FIXME not needed here
'match_gsd' : True, # FIXME not needed here 'match_gsd' : True, # FIXME not needed here
'data_corners_im0' : [[x,y] for x,y in self.spatRef_scene.polyUTM.convex_hull.exterior.coords], 'data_corners_im0' : [[x,y] for x,y in self.spatRef_scene.polyUTM.convex_hull.exterior.coords],
'data_corners_im1' : [GEOP.transform_any_prj(GEOP.EPSG2WKT(4326),self.meta['coordinate system string'], 'data_corners_im1' : [transform_any_prj(EPSG2WKT(4326),self.meta['coordinate system string'],
x,y) for x,y in HLP_F.reorder_CornerLonLat(self.trueDataCornerLonLat)], x,y) for x,y in HLP_F.reorder_CornerLonLat(self.trueDataCornerLonLat)],
'nodata' : (HLP_F.get_outFillZeroSaturated(geoArr_ref .dtype)[0], 'nodata' : (HLP_F.get_outFillZeroSaturated(geoArr_ref .dtype)[0],
HLP_F.get_outFillZeroSaturated(geoArr_shift.dtype)[0]), HLP_F.get_outFillZeroSaturated(geoArr_shift.dtype)[0]),
...@@ -1429,9 +1437,9 @@ class L1B_object(L1A_object): ...@@ -1429,9 +1437,9 @@ class L1B_object(L1A_object):
def correct_spatial_shifts(self, attrname, band2process=None): def correct_spatial_shifts(self, attrname, band2process=None):
raise NotImplementedError raise NotImplementedError
# get target bounds # get target bounds
trueDataCornerUTM = [GEOP.transform_any_prj(GEOP.EPSG2WKT(4326), self.meta['coordinate system string'], x, y) trueDataCornerUTM = [transform_any_prj(EPSG2WKT(4326), self.meta['coordinate system string'], x, y)
for x, y in self.trueDataCornerLonLat] for x, y in self.trueDataCornerLonLat]
xmin, xmax, ymin, ymax = GEOP.corner_coord_to_minmax(trueDataCornerUTM) xmin, xmax, ymin, ymax = corner_coord_to_minmax(trueDataCornerUTM)
mapBounds = box(xmin, ymin, xmax, ymax).bounds mapBounds = box(xmin, ymin, xmax, ymax).bounds
# correct shifts and clip to extent # correct shifts and clip to extent
......
...@@ -33,6 +33,7 @@ from . import GEOPROCESSING as GEOP ...@@ -33,6 +33,7 @@ from . import GEOPROCESSING as GEOP
from ..io import Input_reader as INP_R from ..io import Input_reader as INP_R
from ..misc import path_generator as PG from ..misc import path_generator as PG
from .L1B_P import L1B_object from .L1B_P import L1B_object
from py_tools_ds.ptds.geo.map_info import mapinfo2geotransform
job = builtins.GMS_config.job job = builtins.GMS_config.job
...@@ -67,7 +68,7 @@ class L1C_object(L1B_object): ...@@ -67,7 +68,7 @@ class L1C_object(L1B_object):
fillVal = HLP_F.get_outFillZeroSaturated(np.float32)[0] fillVal = HLP_F.get_outFillZeroSaturated(np.float32)[0]
lonlat_arr = GEOP.get_lonlat_coord_array(self.shape_fullArr, subset[1], lonlat_arr = GEOP.get_lonlat_coord_array(self.shape_fullArr, subset[1],
GEOP.mapinfo2geotransform(self.meta['map info']), mapinfo2geotransform(self.meta['map info']),
self.meta['coordinate system string'], mask_1bit_temp, fillVal)[0] self.meta['coordinate system string'], mask_1bit_temp, fillVal)[0]
if job.exec_mode == 'Flink' and subset[0]=='cube': if job.exec_mode == 'Flink' and subset[0]=='cube':
......
...@@ -17,10 +17,18 @@ import gdal ...@@ -17,10 +17,18 @@ import gdal
import numpy as np import numpy as np
import rasterio import rasterio
from . import GEOPROCESSING as GEOP from . import GEOPROCESSING as GEOP # FIXME import functions directly as soon as GEOPROCESSING is included in algorithms.__init__.__all__
from ..misc import path_generator as PG from ..misc import path_generator as PG
from ..misc import helper_functions as HLP_F