2x performance for local coreg: disable nodata check of complete image for each GCP
During local coregistration, the check if there is any valid (non-nodata) pixel is ran on the complete image for each GCP: https://git.gfz-potsdam.de/danschef/arosics/-/blob/main/arosics/CoReg.py?ref_type=heads#L109
Through the instantiation here: https://git.gfz-potsdam.de/danschef/arosics/-/blob/main/arosics/Tie_Point_Grid.py?ref_type=heads#L275
This is not necessary, since the image should already be checked once in the instantiation of COREG_LOCAL
.
It is also very slow, especially for very large images and many points.
Something like this halves the total coregistration time in our use-case:
diff --git a/CoReg.py b/CoReg.py
index 22cec69..66c428b 100644
--- a/CoReg.py
+++ b/CoReg.py
@@ -103,11 +103,11 @@ class GeoArray_CoReg(GeoArray):
% (self.imName, self.bands, 'bands' if self.bands > 1 else
'band', 'between 1 and ' if self.bands > 1 else '', self.bands, self.band4match)
- # compute nodata mask and validate that it is not completely filled with nodata
- self.calc_mask_nodata(fromBand=self.band4match) # this avoids that all bands have to be read
-
- if True not in self.mask_nodata[:]:
- raise RuntimeError(f'The {self.imName} passed to AROSICS only contains nodata values.')
+ if CoReg_params["validate_nonempty"]:
+ # compute nodata mask and validate that it is not completely filled with nodata
+ self.calc_mask_nodata(fromBand=self.band4match) # this avoids that all bands have to be read
+ if not self.mask_nodata.any():
+ raise RuntimeError(f'The {self.imName} passed to AROSICS only contains nodata values.')
# set footprint_poly
given_footprint_poly = CoReg_params['footprint_poly_%s' % ('ref' if imID == 'ref' else 'tgt')]
@@ -180,6 +180,7 @@ class COREG(object):
data_corners_ref: list = None,
data_corners_tgt: list = None,
nodata: Tuple = (None, None),
+ validate_nonempty: bool = True,
calc_corners: bool = True,
binary_ws: bool = True,
mask_baddata_ref: Union[GeoArray, str] = None,
@@ -359,7 +360,7 @@ class COREG(object):
warnings.warn("The resampling algorithm 'average' causes sinus-shaped patterns in fft images that will "
"affect the precision of the calculated spatial shifts! It is highly recommended to "
"choose another resampling algorithm.")
-
+ self.validate_nonempty = validate_nonempty
self.path_out = path_out # updated by self.set_outpathes
self.fmt_out = fmt_out
self.out_creaOpt = out_crea_options
@@ -1414,7 +1415,7 @@ class COREG(object):
band2process=otherFull.band4match + 1,
clipextent=self.matchBox.mapPoly.bounds,
target_xyGrid=matchFull.xygrid_specs,
- q=True
+ q=True,
).correct_shifts()
return ds_results['GeoArray_shifted']
diff --git a/Tie_Point_Grid.py b/Tie_Point_Grid.py
index 260ca3a..8222444 100644
--- a/Tie_Point_Grid.py
+++ b/Tie_Point_Grid.py
@@ -360,6 +360,7 @@ class Tie_Point_Grid(object):
nodata=(self.COREG_obj.ref.nodata, self.COREG_obj.shift.nodata),
force_quadratic_win=self.COREG_obj.force_quadratic_win,
binary_ws=self.COREG_obj.bin_ws,
+ validate_nonempty=False,
v=False, # True leads to massive STDOUT
q=True, # True leads to massive STDOUT
ignore_errors=True
Edited by Daniel Scheffler