feat: add script to apply ESA quality mask #15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What I'm changing
This PR is intended to address this ticket, NASA-IMPACT/hls-sentinel#155
This PR replaces the original PR (#14) that I submitted from a fork because my forked branch wasn't triggering CI tests.
Specifically this is intended to replace a utility written in C to apply a binary quality mask to Sentinel-2 L1C data that masks lost or degraded MSI pixel values. The original PR was, NASA-IMPACT/hls-sentinel#152
This utility script is intended to fit into the rest of the HLS Sentinel-2 related processing. To apply the script we would need to do a few extra steps,
hls-utilities@v1.10
)hls-utilities
in thehls-sentinel
container to include this update (https://github.com/NASA-IMPACT/hls-sentinel/blob/20180e0d0cd286ffefe61bd6aeeaeff056874102/Dockerfile#L123)hls-sentinel
processing steps to include running this script as part ofsentinel_granule.sh
(e.g., around here https://github.com/NASA-IMPACT/hls-sentinel/blob/20180e0d0cd286ffefe61bd6aeeaeff056874102/scripts/sentinel_granule.sh#L44)hls-sentinel
image used in our production pipelines by tagging our new container appropriately (i.e., "latest")How I did it
The ESA quality mask is an 8 band single bit image that encodes 0/1 for 8 quality related attributes. The bands we're interested in are bands 3 & 4 (counting from 1 in GDAL notation) which encode if the pixel retrieval was either lost or degraded.
I followed the original C code implementation with a few modifications...
04.00
).HLS_REFL_FILLVAL
(-9999
) to any pixel where the mask was TRUE for either band.-9999
value is not suitable for us because the original L1C images in JPEG2000 format use0
as the nodata value (since-9999
is out of data type range)0
value is used as a no data value for L1C imagery and this is noted in the metadatahls-sentinel
that some utilities modify in place while others create new data. If it'd be useful for a "debug mode" it would be easy to rewrite the images to new filesHow you can test it
Install the test dependencies and run unit tests for this script,
The unit tests are what helped me discover that JPEG2000 driver will apply lossy compression when we update the file (
r+
access mode) even though the original file had lossless compression in creation options 🙃I ran this for one of the granules mentioned in the original C code PR and recorded a tiny demo,
Note the "inspect tool" that shows the imagery values on the right hand side. The S2 L1C imagery don't have a No Data Value set, so QGIS shows the 0 as valid pixels. Still we can see the individual pixel values are correct (0 instead of ~1,000) and the image is stretched differently because of the different minimum values.