Skip to content

Commit

Permalink
Merge pull request #183 from raphaelrpl/b-0.6
Browse files Browse the repository at this point in the history
Fix post processing nodata with db band values
  • Loading branch information
raphaelrpl authored Apr 22, 2021
2 parents 31d4861 + c649a7a commit a82efe4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cube_builder/celery/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def prepare_blend(merges, band_map: dict, **kwargs):
if not was_reused:
logging.info(f'Applying post-processing in {str(quality_file)}')
post_processing_quality(quality_file, bands, merges[0]['warped_collection_id'],
period, merges[0]['tile_id'], quality_band, version=version, block_size=block_size)
period, merges[0]['tile_id'], quality_band, band_map,
version=version, block_size=block_size)
else:
logging.info(f'Skipping post-processing {str(quality_file)}')

Expand Down
9 changes: 6 additions & 3 deletions cube_builder/utils/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def merge(merge_file: str, mask: dict, assets: List[dict], band: str, band_map:


def post_processing_quality(quality_file: str, bands: List[str], cube: str,
date: str, tile_id, quality_band: str, version: int, block_size:int=None):
date: str, tile_id, quality_band: str, band_map: dict, version: int, block_size:int=None):
"""Stack the merge bands in order to apply a filter on the quality band.
We have faced some issues regarding `nodata` value in spectral bands, which was resulting
Expand Down Expand Up @@ -419,7 +419,9 @@ def post_processing_quality(quality_file: str, bands: List[str], cube: str,
with rasterio.open(str(quality_file)) as merge_dataset:
blocks = list(merge_dataset.block_windows())
profile = merge_dataset.profile
nodata = profile.get('nodata', 255)
nodata = profile.get('nodata', band_map[quality_band]['nodata'])
if nodata is not None:
nodata = float(nodata)
raster_merge = merge_dataset.read(1)

_default_bands = DATASOURCE_NAME, 'ndvi', 'evi', 'cnc', TOTAL_OBSERVATION_NAME, CLEAR_OBSERVATION_NAME, PROVENANCE_NAME
Expand All @@ -438,7 +440,8 @@ def post_processing_quality(quality_file: str, bands: List[str], cube: str,
with rasterio.open(str(band_file)) as ds:
raster = ds.read(1, window=block)

nodata_found = numpy.where(raster == -9999)
band_nodata = band_map[band]['nodata']
nodata_found = numpy.where(raster == float(band_nodata))
raster_nodata_pos = numpy.ravel_multi_index(nodata_found, raster.shape)
nodata_positions = numpy.union1d(nodata_positions, raster_nodata_pos)

Expand Down

0 comments on commit a82efe4

Please sign in to comment.