diff --git a/HISTORY.rst b/HISTORY.rst index e84de20..aae002c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,12 @@ History ======= +1.7.7 (coming soon) +------------------- + +* Added a validation to reject images that only contain nodata values. + + 1.7.6 (2022-01-31) ------------------ diff --git a/arosics/CoReg.py b/arosics/CoReg.py index 4eaaebd..6be636d 100755 --- a/arosics/CoReg.py +++ b/arosics/CoReg.py @@ -98,6 +98,12 @@ def __init__(self, % (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 np.std(self.mask_nodata) == 0 and np.mean(self.mask_nodata) == 0: + 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')] given_corner_coord = CoReg_params['data_corners_%s' % ('ref' if imID == 'ref' else 'tgt')] @@ -114,8 +120,6 @@ def __init__(self, if not CoReg_params['q']: print('Calculating footprint polygon and actual data corner coordinates for %s...' % self.imName) - self.calc_mask_nodata(fromBand=self.band4match) # this avoids that all bands have to be read - with warnings.catch_warnings(record=True) as w: _ = self.footprint_poly # execute getter diff --git a/tests/test_COREG.py b/tests/test_COREG.py index d855e0b..ac3fc0a 100644 --- a/tests/test_COREG.py +++ b/tests/test_COREG.py @@ -63,6 +63,22 @@ def test_coreg_init_from_inMem_GeoArray(self): # get instance of COREG_LOCAL object self.CRL = COREG(self.ref_gA, self.tgt_gA, **self.coreg_kwargs) + def test_empty_image(self): + # get GeoArray instances + self.ref_gA = GeoArray(self.ref_path) + self.tgt_gA = GeoArray(self.tgt_path) + + # assure the raster data are in-memory + self.ref_gA.to_mem() + self.tgt_gA.to_mem() + + # fill the reference image with nodata + self.ref_gA[:] = self.ref_gA.nodata + + # get instance of COREG_LOCAL object + with self.assertRaises(RuntimeError, msg='.contains only nodata.'): + COREG(self.ref_gA, self.tgt_gA, **self.coreg_kwargs) + class CompleteWorkflow_INTER1_S2A_S2A(unittest.TestCase): """Test case for the complete workflow of global co-registration based on two Sentinel-2 datasets, one with