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
from ..misc import path_generator as PG
from ..misc import database_tools as DB_T
from ..misc.mgrs_tile import MGRS_tile
#from ..io.GeoArray 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 ######################################
class L1A_object(object):
......@@ -214,8 +219,8 @@ class L1A_object(object):
@property
def coreg_needed(self):
gt = GEOP.mapinfo2geotransform(self.meta['map info'])
return (GEOP.is_coord_grid_equal(gt, usecase.spatial_ref_gridx, usecase.spatial_ref_gridy) and
gt = mapinfo2geotransform(self.meta['map info'])
return (is_coord_grid_equal(gt, usecase.spatial_ref_gridx, usecase.spatial_ref_gridy) and
self.dataset_ID == usecase.datasetid_spatial_ref) is False
......@@ -787,7 +792,7 @@ class L1A_object(object):
previous_dataname = self.MetaObj.Dataname
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)
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
assert os.path.isfile(outP), 'Writing tempfile failed.'
self.MetaObj.Dataname = outP
......@@ -1012,21 +1017,21 @@ class L1A_object(object):
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
self.trueDataCornerPos = GEOP.calc_FullDataset_corner_positions(self.mask_1bit,algorithm='numpy')
self.trueDataCornerPos = calc_FullDataset_corner_positions(self.mask_1bit,algorithm='numpy')
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]
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'])
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']
trueCorLatLon = GEOP.pixelToLatLon(trueCorPosXY,geotransform=gt,projection=prj)
trueCorLatLon = pixelToLatLon(trueCorPosXY,geotransform=gt,projection=prj)
self.trueDataCornerLonLat = [tuple(reversed(i)) for i in trueCorLatLon]
rows,cols = self.shape_fullArr[:2]
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]
......@@ -1260,7 +1265,7 @@ class L1A_object(object):
geoArr = getattr(self,arrname) if isinstance(getattr(self,arrname),GeoArray) else getattr(self,arrname)
nodata = HLP_F.get_outFillZeroSaturated(geoArr)[0]
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']
# get subsetted and (possibly) reprojected array
......@@ -1273,11 +1278,11 @@ class L1A_object(object):
# update array-related attributes of sub_GMS_obj
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['lines'], meta2update['samples'] = sub_arr.shape[:2]
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
sub_GMS_obj.mask_1bit = sub_GMS_obj.masks[:,:,0]
......@@ -1292,8 +1297,8 @@ class L1A_object(object):
# calculate new attributes 'corner_utm' and 'corner_lonlat'
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
lonlat_coord = GEOP.pixelToLatLon([ULxy, URxy, LLxy, LRxy], geotransform=sub_gt, projection=sub_prj) # ULyx,URyx,LLyx,LRyx
utm_coord_YX = pixelToMapYX ([ULxy, URxy, LLxy, LRxy], geotransform=sub_gt, projection=sub_prj) # FIXME asserts gt in UTM coordinates
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_lonlat = [[YX[1], YX[0]] for YX in lonlat_coord] # ULxy,URxy,LLxy,LRxy
......@@ -1303,22 +1308,22 @@ class L1A_object(object):
# calculate data_corners_imXY
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')
else: # str # FIXME not needed anymore because geoArr.get_mapPos always returns an array?
from ..io.Input_reader import read_mask_subset
subset = ('block', ((rS, rE), (cS, cE)))
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]
# 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)
sub_GMS_obj.data_corners_LonLat = [(YX[1], YX[0]) for YX in data_corners_LatLon]
# 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
sub_GMS_obj.data_corners_utm = [(YX[1], YX[0]) for YX in data_corners_utmYX]
......@@ -1346,7 +1351,7 @@ class L1A_object(object):
trueDataCornerLonLat=self.trueDataCornerLonLat)
# 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: \
list(np.array(MGRStileObj.poly_utm.buffer(pixbuffer*gt[1]).bounds)[[0, 2, 1, 3]])
......
......@@ -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
from ..io import Output_writer as OUT_W
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 database_tools as DB_T
from .L1A_P import L1A_object
......@@ -63,6 +63,14 @@ from ..misc.SpatialIndexMediator import SpatialIndexMediator
#sys.path.append('/home/gfz-fe/')
from CoReg_Sat import COREG, DESHIFTER
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">
......@@ -224,8 +232,8 @@ class COREG_OLD(object):
self.footprint_poly = HLP_F.CornerLonLat_to_shapelyPoly(dict_L1A_Instance['trueDataCornerLonLat'])
self.map_info_to_update = dict_L1A_Instance['meta']['map info']
self.shift_prj = dict_L1A_Instance['meta']['coordinate system string']
self.shift_gt = GEOP.mapinfo2geotransform(self.map_info_to_update)
self.coreg_needed = (GEOP.is_coord_grid_equal(self.shift_gt,usecase.spatial_ref_gridx,
self.shift_gt = mapinfo2geotransform(self.map_info_to_update)
self.coreg_needed = (is_coord_grid_equal(self.shift_gt,usecase.spatial_ref_gridx,
usecase.spatial_ref_gridy) and
self.dataset_ID==usecase.datasetid_spatial_ref)==False
......@@ -296,7 +304,7 @@ class COREG_OLD(object):
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 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.'
"""optionally write shapes (always LonLat because GMS shapely polygons are always LonLat"""
......@@ -305,9 +313,9 @@ class COREG_OLD(object):
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)))
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.footprint_poly, os.path.join(self.verbose_out, 'poly_im2shift.shp'), GEOP.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.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'), 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"""
self.get_opt_bands4matching(target_cwlPos_nm=550)
......@@ -330,7 +338,7 @@ class COREG_OLD(object):
max_cloudcov = 20 # %
plusminus_days = 30
plusminus_years = 10
boundsLonLat = GEOP.corner_coord_to_minmax(self.trueDataCornerLonLat)
boundsLonLat = corner_coord_to_minmax(self.trueDataCornerLonLat)
AcqDate = self.im2shift_objDict['acquisition_date']
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)
......@@ -365,12 +373,12 @@ class COREG_OLD(object):
GDF['cloudcover'] = [*GDF['object'].map(lambda scene: scene.cloudcover)]
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)]
#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['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'])]
......@@ -418,7 +426,7 @@ class COREG_OLD(object):
from ..io.Input_reader import read_ENVIhdr_to_dict
get_prj = lambda path_binary: \
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)]
# filter scenes out that have a different projection
......@@ -591,7 +599,7 @@ class COREG_OLD(object):
# 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}
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}
#print('polygon creation time', time.time()-t0)
......@@ -624,11 +632,11 @@ class COREG_OLD(object):
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
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.ImportFromWkt(self.ref_prj)
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]
else:
overlap_center_pos = [overlap_center_pos_y[0], overlap_center_pos_x[0]]
......@@ -798,7 +806,7 @@ class COREG_OLD(object):
# 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_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_yvals = [i[0] for i in imref_box_map] # UTM-HW
......@@ -811,9 +819,9 @@ class COREG_OLD(object):
rsp_algor = 2 # 'cubic'
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,
out_res=(imfft_gsd_mapvalues, imfft_gsd_mapvalues),out_extent=([min(map_xvals), min(map_yvals),
max(map_xvals),max(map_yvals)]), rsp_alg=rsp_algor, in_nodata=im2shift_nodata) [0]
im2shift_clip_data = warp_ndarray(im2shift_data,self.shift_gt,self.shift_prj,self.ref_prj,
out_gsd=(imfft_gsd_mapvalues, imfft_gsd_mapvalues),out_bounds=([min(map_xvals), min(map_yvals),
max(map_xvals),max(map_yvals)]), rspAlg=rsp_algor, in_nodata=im2shift_nodata) [0]
else:
"""falls referenz die höhere auflösung hat"""
......@@ -839,7 +847,7 @@ class COREG_OLD(object):
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]
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_yvals = [i[0] for i in imref_box_map] # UTM-HW
......@@ -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))
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,
out_res=(imfft_gsd_mapvalues, imfft_gsd_mapvalues),out_extent=([min(map_xvals), min(map_yvals),
max(map_xvals),max(map_yvals)]), rsp_alg=rsp_algor, in_nodata=im2ref_nodata) [0]
imref_clip_data = warp_ndarray(imref_data,self.ref_gt,self.ref_prj,self.ref_prj,
out_gsd=(imfft_gsd_mapvalues, imfft_gsd_mapvalues),out_bounds=([min(map_xvals), min(map_yvals),
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
# gleich bleibt)
im2shift_clip_data = GEOP.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),
max(map_xvals),max(map_yvals)]), rsp_alg=2, in_nodata=im2ref_nodata) [0]
im2shift_clip_data = warp_ndarray(im2shift_data,self.shift_gt,self.shift_prj,self.ref_prj,
out_gsd=(imfft_gsd_mapvalues, imfft_gsd_mapvalues),out_bounds=([min(map_xvals), min(map_yvals),
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
gsd_factor = imfft_gsd_mapvalues/im2shift_gsd
......@@ -1073,7 +1081,7 @@ class COREG_OLD(object):
def get_updated_map_info(self):
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]
self.x_shift_map = new_originX - self.shift_gt[0]
self.y_shift_map = new_originY - self.shift_gt[3]
......@@ -1133,7 +1141,7 @@ class Scene_getter(object):
GDF['acquisitiondate'] = [*GDF['object'].map(lambda scene: scene.acquisitiondate)]
GDF['cloudcover'] = [*GDF['object'].map(lambda scene: scene.cloudcover)]
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)]
self.GDF_ref_scenes = GDF
......@@ -1164,7 +1172,7 @@ class Scene_getter(object):
GDF = self.GDF_ref_scenes
if not GDF.empty:
#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['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'])]
......@@ -1225,7 +1233,7 @@ class Scene_getter(object):
from ..io.Input_reader import read_ENVIhdr_to_dict
get_prj = lambda path_binary: \
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)]
# filter scenes out that have a different projection
......@@ -1276,7 +1284,7 @@ class L1B_object(L1A_object):
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)
RSG = Scene_getter(boundsLonLat, self.acquisition_date, self.meta['coordinate system string'],
footprint_poly, 20, 0, 20, 30, 10)
......@@ -1374,7 +1382,7 @@ class L1B_object(L1A_object):
'align_grids' : 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_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)],
'nodata' : (HLP_F.get_outFillZeroSaturated(geoArr_ref .dtype)[0],
HLP_F.get_outFillZeroSaturated(geoArr_shift.dtype)[0]),
......@@ -1429,9 +1437,9 @@ class L1B_object(L1A_object):
def correct_spatial_shifts(self, attrname, band2process=None):
raise NotImplementedError
# 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]
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
# correct shifts and clip to extent
......
......@@ -33,6 +33,7 @@ from . import GEOPROCESSING as GEOP
from ..io import Input_reader as INP_R
from ..misc import path_generator as PG
from .L1B_P import L1B_object
from py_tools_ds.ptds.geo.map_info import mapinfo2geotransform
job = builtins.GMS_config.job
......@@ -67,7 +68,7 @@ class L1C_object(L1B_object):
fillVal = HLP_F.get_outFillZeroSaturated(np.float32)[0]
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]
if job.exec_mode == 'Flink' and subset[0]=='cube':
......
......@@ -17,10 +17,18 @@ import gdal
import numpy as np
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 helper_functions as HLP_F
from .L1C_P import L1C_object
from py_tools_ds.ptds.geo.map_info import mapinfo2geotransform, geotransform2mapinfo
from py_tools_ds.ptds.geo.projection import get_proj4info
from py_tools_ds.ptds.geo.coord_calc import corner_coord_to_minmax, get_corner_coordinates
from py_tools_ds.ptds.geo.coord_trafo import pixelToMapYX
from py_tools_ds.ptds.geo.raster.reproject import warp_ndarray
usecase = builtins.GMS_config.usecase
......@@ -74,7 +82,7 @@ def get_DESHIFTER_configs(dicts_GMS_obj, attrnames2deshift, proc_bandwise=False,
# FIXME workaround für fehlende refererence geotransform -> eigentlich müsste nicht gt, sondern target grid berechnet werden
assert isinstance(obj,dict)
if not obj['coreg_info']['reference geotransform']:
obj['coreg_info']['reference geotransform'] = GEOP.mapinfo2geotransform(
obj['coreg_info']['reference geotransform'] = mapinfo2geotransform(
obj['coreg_info']['original map info'])
obj['coreg_info']['reference geotransform'][1] = usecase.target_gsd[0]
obj['coreg_info']['reference geotransform'][5] = -abs(usecase.target_gsd[1])
......@@ -155,7 +163,7 @@ class DESHIFTER(object):
self.shift_entity_ID = dict_GMS_obj['entity_ID']
self.shift_dataset_ID = dict_GMS_obj['dataset_ID']
self.shift_prj = dict_GMS_obj['meta']['coordinate system string']
self.shift_gt = GEOP.mapinfo2geotransform(dict_GMS_obj['meta']['map info'])
self.shift_gt = mapinfo2geotransform(dict_GMS_obj['meta']['map info'])
self.shift_trueDataCornerPos = dict_GMS_obj['trueDataCornerPos']
self.shift_trueDataCornerLonLat = dict_GMS_obj['trueDataCornerLonLat']
self.im2shift = dict_GMS_obj[attrname2deshift]
......@@ -168,7 +176,7 @@ class DESHIFTER(object):
self.updated_map_info = dict_GMS_obj['coreg_info']['updated map info']
self.original_map_info= dict_GMS_obj['coreg_info']['original map info']
self.updated_gt = GEOP.mapinfo2geotransform(self.updated_map_info) \
self.updated_gt = mapinfo2geotransform(self.updated_map_info) \
if self.updated_map_info else self.shift_gt
self.ref_scene_ID = dict_GMS_obj['coreg_info']['reference scene ID']
self.ref_entity_ID = dict_GMS_obj['coreg_info']['reference entity ID']
......@@ -251,7 +259,7 @@ class DESHIFTER(object):
temp_logger = HLP_F.setup_logger('log__' + self.shift_baseN, self.path_logfile, append=1)
t0 = time.time()
equal_prj = GEOP.get_proj4info(proj=self.ref_prj)==GEOP.get_proj4info(proj=self.shift_prj) \
equal_prj = get_proj4info(proj=self.ref_prj)==get_proj4info(proj=self.shift_prj) \
if self.deshift_needed else True
if equal_prj and not self.align_grids and self.out_gsd in [None,[self.shift_xgsd,self.shift_ygsd]]:
......@@ -271,7 +279,7 @@ class DESHIFTER(object):
# get true bounds in pixel coordinates
df_xmin,df_xmax,df_ymin,df_ymax = 0, self.shift_shape[1], 0, self.shift_shape[0] # defaults
xmin,xmax,ymin,ymax = GEOP.corner_coord_to_minmax([[c[1],c[0]] for c in self.shift_trueDataCornerPos])
xmin,xmax,ymin,ymax = corner_coord_to_minmax([[c[1],c[0]] for c in self.shift_trueDataCornerPos])
xmin,xmax,ymin,ymax = [int(c) if c>=0 else int(df_c) for c,df_c in # replace eventually negative px-coordinates
zip([xmin,xmax,ymin,ymax],[df_xmin,df_xmax,df_ymin,df_ymax])]
......@@ -288,8 +296,8 @@ class DESHIFTER(object):
# update gt
self.updated_projection = self.updated_projection if self.updated_projection else self.shift_prj # self.updated_projection is taken from ref_prj which is None is target image dont has to be coregistered
self.updated_gt[3],self.updated_gt[0] =\
GEOP.pixelToMapYX([xmin,ymin],geotransform=self.updated_gt,projection=self.updated_projection)[0]
self.updated_map_info = GEOP.geotransform2mapinfo(self.updated_gt,self.updated_projection)
pixelToMapYX([xmin,ymin],geotransform=self.updated_gt,projection=self.updated_projection)[0]
self.updated_map_info = geotransform2mapinfo(self.updated_gt,self.updated_projection)
else:
raise NotImplementedError # FIXME
......@@ -300,10 +308,10 @@ class DESHIFTER(object):
self.updated_gt[1], self.updated_gt[5] = xgsd, -ygsd
if self.cliptoextent:
XY = [[c[1],c[0]] for c in self.shift_trueDataCornerPos]
XY = [[c[1],c[0]] for c in GEOP.pixelToMapYX(XY, geotransform=self.shift_gt,projection=self.shift_prj)]
s_xmin,s_xmax,s_ymin,s_ymax = GEOP.corner_coord_to_minmax(XY)
XY = [[c[1],c[0]] for c in pixelToMapYX(XY, geotransform=self.shift_gt,projection=self.shift_prj)]
s_xmin,s_xmax,s_ymin,s_ymax = corner_coord_to_minmax(XY)
else:
s_xmin,s_xmax,s_ymin,s_ymax = GEOP.corner_coord_to_minmax(GEOP.get_corner_coordinates(
s_xmin,s_xmax,s_ymin,s_ymax = corner_coord_to_minmax(get_corner_coordinates(
gt=self.shift_gt,cols=self.shift_shape[1],rows=self.shift_shape[0]))
if self.align_grids:
......@@ -317,7 +325,7 @@ class DESHIFTER(object):
%(self.ref_xgsd,self.ref_ygsd,xgsd,ygsd))
xgsd, ygsd = self.ref_xgsd, self.ref_ygsd
r_xmin,r_xmax,r_ymin,r_ymax = GEOP.corner_coord_to_minmax(GEOP.get_corner_coordinates(
r_xmin,r_xmax,r_ymin,r_ymax = corner_coord_to_minmax(get_corner_coordinates(
gt=self.ref_gt,cols=self.ref_cols,rows=self.ref_rows))
imref_xgrid = np.arange(r_xmin,r_xmax,self.ref_xgsd)
imref_ygrid = np.arange(r_ymin,r_ymax,self.ref_ygsd)
......@@ -363,7 +371,7 @@ class DESHIFTER(object):
"""update map info, arr_shifted, geotransform and projection"""
ds_shifted = gdal.OpenShared(self.path_tmp) if self.outFmt == 'VRT' else gdal.Open(self.path_tmp)
self.shift_gt, self.shift_prj = ds_shifted.GetGeoTransform(), ds_shifted.GetProjection()
self.updated_map_info = GEOP.geotransform2mapinfo(self.shift_gt,self.shift_prj)
self.updated_map_info = geotransform2mapinfo(self.shift_gt,self.shift_prj)
print('reading from', ds_shifted.GetDescription())
if self.band2process is None:
......@@ -401,19 +409,19 @@ class DESHIFTER(object):
rsp_alg = 2 if self.attrname2deshift not in ['masks','mask_clouds'] else 0
if self.cliptoextent:
out_arr, out_gt, out_prj = GEOP.warp_ndarray(in_arr,self.shift_gt,self.shift_prj,self.ref_prj,
out_arr, out_gt, out_prj = warp_ndarray(in_arr,self.shift_gt,self.shift_prj,self.ref_prj,
rspAlg=rsp_alg, in_nodata=in_nodata, out_nodata=in_nodata, out_gsd=(xgsd,xgsd),
out_bounds=[xmin,ymin,xmax,ymax]) # FIXME resamp_alg: "average" causes sinus-shaped patterns in fft images
else:
out_arr, out_gt, out_prj = GEOP.warp_ndarray(in_arr,self.shift_gt,self.shift_prj,self.ref_prj,
out_arr, out_gt, out_prj = warp_ndarray(in_arr,self.shift_gt,self.shift_prj,self.ref_prj,
rspAlg=rsp_alg, in_nodata=in_nodata, out_nodata=in_nodata, out_gsd=(xgsd,xgsd), out_gt=out_gt)
# output array is shifted AND has no odd corner coordinates because it is aligned to reference grid!
self.updated_projection = self.ref_prj
self.arr_shifted = out_arr
self.updated_map_info = GEOP.geotransform2mapinfo(out_gt,out_prj)
self.shift_gt = GEOP.mapinfo2geotransform(self.updated_map_info)
self.updated_map_info = geotransform2mapinfo(out_gt,out_prj)
self.shift_gt = mapinfo2geotransform(self.updated_map_info)
self.is_shifted = True
self.is_resampled = True
......
......@@ -32,10 +32,13 @@ try: from osgeo import osr
except ImportError: import osr
from ..io import envifilehandling_BD as ef
from ..io import envifilehandling as ef
from . import GEOPROCESSING as GEOP
from ..misc import helper_functions as HLP_F
from ..misc import database_tools as DB_T
from py_tools_ds.ptds.geo.map_info import geotransform2mapinfo
from py_tools_ds.ptds.geo.projection import WKT2EPSG
job, usecase = builtins.GMS_config.job, builtins.GMS_config.usecase # read from builtins (set by process_controller)
......@@ -1308,10 +1311,10 @@ class METADATA(object):
self.cols = rasObj.cols
self.bands = rasObj.bands
if rasObj.projection!='':
self.map_info = GEOP.geotransform2mapinfo(rasObj.geotransform,rasObj.projection)
self.map_info = geotransform2mapinfo(rasObj.geotransform,rasObj.projection)
self.projection = rasObj.projection
self.gResolution = abs(rasObj.geotransform[1])
self.CS_EPSG = GEOP.WKT2EPSG(rasObj.projection)
self.CS_EPSG = WKT2EPSG(rasObj.projection)
dict_conv_physUnit = {'Rad':"W * m-2 * sr-1 * micrometer-1",
'Ref':'TOA_Reflectance in [0-10000]',
......
......@@ -7,4 +7,29 @@
#
###############################################################################
__author__='Daniel Scheffler'
\ No newline at end of file
# FIXME comment that in as soon as config is no longer part of builtins
# from . import GEOPROCESSING
# from . import METADATA
# from . import gms_cloud_classifier
# from . import L0A_P
# from . import L0B_P
# from . import L1A_P
# from . import L1B_P
# from . import L1C_P
# from . import L2A_P
# from . import L2B_P
# from . import L2C_P
#
# __all__=['GEOPROCESSING',
# 'METADATA',
# 'gms_cloud_classifier',
# 'L0A_P',
# 'L0B_P',
# 'L1A_P',
# 'L1B_P',
# 'L1C_P',
# 'L2A_P',
# 'L2B_P',
# 'L2C_P']
__author__='Daniel Scheffler'
......@@ -22,7 +22,6 @@ import socket
import psycopg2
import collections
import warnings
import osr
import numpy as np
os.environ['DISPLAY'] = '127.0.0.0:0.0'
......
This diff is collapsed.
This diff is collapsed.