Skip to content

Commit

Permalink
Added a validation to reject images that only contain nodata values +…
Browse files Browse the repository at this point in the history
… test.

Signed-off-by: Daniel Scheffler <danschef@gfz-potsdam.de>
  • Loading branch information
danschef committed Jul 21, 2022
1 parent 37b38fc commit 03eb074
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------

Expand Down
8 changes: 6 additions & 2 deletions arosics/CoReg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand All @@ -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

Expand Down
16 changes: 16 additions & 0 deletions tests/test_COREG.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 03eb074

Please sign in to comment.