Skip to content

Commit babe12e

Browse files
gshiromanemo794
andauthored
Add ocean and invalid reflectance masking (#36)
* merge main into add_ocean_mask * update proteus version from 0.5.1 to 0.5.2 * update proteus version from 0.5.1 to 0.5.2 (2) * update identation of messages logged/printed to the user in the function `save_as_cog()` * add ocean masking using a shoreline shape file * remove debug messages and update comments * add runconfig field ocean_masking_shoreline_distance_km * add cumulative reflectance no-data masking * add cumulative reflectance no-data masking (2) * refactor `save_dswx_product()` and only add CLOUD-masked classes to colortable if layer name is WTR * add test for coverage of ancillary inputs * update snow-, cloud-, and ocean-masked values from 8, 9, and 7 to 252, 253, and 254, respectively * make ocean masked classes transparent * make ocean masked classes transparent (2) * update CLOUD_OCEAN_MASKED to 254 * Update global variable names and CONF layer with _CLEAR, _CLOUD, and _SNOW designations. * Update global variable names and CONF layer with _CLEAR, _CLOUD, and _SNOW designations. (2) * Apply suggestions from code review Whitespace and update to a docstring. Co-authored-by: Gustavo H. X. Shiroma <52007211+gshiroma@users.noreply.github.com> * update to documentation per code review * add new line to the end of the file * rename shape_file to shapefile * reduce shoreline margin from 10 km to 5 km * update comments and docstrings * close gdal dataset * simplify code * add comments for check_ancillary_inputs_coverage * update messages printed to the user regarding Sun parameters * rename `cloud_mask` to `cloud_layer` * update _load_hls_band_from_file() * add `temp_shapefile_filename` to the list of temporary files * read SOFTWARE_VERSION from version.py * update _load_hls_band_from_file() (2) * handle anti-meridian * give precedence to fill value over ocean mask * update description of CLOUD layer * change ocean masked color entry to match the open water as per S. Chan's request * give precedence to clouds over the ocean mask as per S. Chan's request * change default value for per S. Chan's request * change default of `exclude_psw_aggressive_in_browse` from `False` to `True` per chat with S. Chan * give precedence to clouds over the ocean mask as per S. Chan's request (2) * give precedence to clouds over the ocean mask as per S. Chan's request (3) * remove all temporary files * improve comments and variable names * improve comments and variable names (2) * set ocean masked values to transparent in browse images * use dark blue for ocean-masked pixels * remove temporary shape files * rename variable from `temp_file test` to `temp_file` * give precedence to the ocean mask over clouds * check for file`s existence before adding it to temporary file`s list * update OPERA Cal/Val release version from R3.2 to R3.3 * update workflow test dataset URL Co-authored-by: Samantha Niemoeller <11642807+nemo794@users.noreply.github.com>
1 parent 33d4c13 commit babe12e

11 files changed

Lines changed: 972 additions & 451 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Then, from inside the cloned repository, build the Docker image:
9898
Load the Docker container image onto your computer:
9999

100100
```bash
101-
docker load -i docker/dockerimg_proteus_cal_val_3.1.tar
101+
docker load -i docker/dockerimg_proteus_cal_val_3.3.tar
102102
```
103103

104104
See DSWx-HLS Science Algorithm Software (SAS) User Guide for instructions on processing via Docker.

bin/dswx_hls.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def main():
5151
args.output_file,
5252
hls_thresholds = runconfig_constants.hls_thresholds,
5353
dem_file=args.dem_file,
54-
dem_description=args.dem_description,
54+
dem_file_description=args.dem_file_description,
5555
output_interpreted_band=args.output_interpreted_band,
5656
output_rgb_file=args.output_rgb_file,
5757
output_infrared_rgb_file=args.output_infrared_rgb_file,
@@ -62,7 +62,7 @@ def main():
6262
output_shadow_masked_dswx=args.output_shadow_masked_dswx,
6363
output_landcover=args.output_landcover,
6464
output_shadow_layer=args.output_shadow_layer,
65-
output_cloud_mask=args.output_cloud_mask,
65+
output_cloud_layer=args.output_cloud_layer,
6666
output_dem_layer=args.output_dem_layer,
6767
output_browse_image=args.output_browse_image,
6868
browse_image_height=args.browse_image_height,
@@ -72,9 +72,11 @@ def main():
7272
cloud_in_browse=args.cloud_in_browse,
7373
snow_in_browse=args.snow_in_browse,
7474
landcover_file=args.landcover_file,
75-
landcover_description=args.landcover_description,
75+
landcover_file_description=args.landcover_file_description,
7676
worldcover_file=args.worldcover_file,
77-
worldcover_description=args.worldcover_description,
77+
worldcover_file_description=args.worldcover_file_description,
78+
shoreline_shapefile=args.shoreline_shapefile,
79+
shoreline_shapefile_description=args.shoreline_shapefile_description,
7880
flag_offset_and_scale_inputs=args.flag_offset_and_scale_inputs,
7981
scratch_dir=args.scratch_dir,
8082
product_id=args.product_id,
@@ -85,6 +87,8 @@ def main():
8587
max_sun_local_inc_angle=args.max_sun_local_inc_angle,
8688
mask_adjacent_to_cloud_mode=args.mask_adjacent_to_cloud_mode,
8789
copernicus_forest_classes=args.copernicus_forest_classes,
90+
ocean_masking_shoreline_distance_km = \
91+
args.ocean_masking_shoreline_distance_km,
8892
flag_debug=args.flag_debug)
8993

9094

build_docker_image.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
IMAGE=opera/proteus
4-
t=cal_val_3.2
4+
t=cal_val_3.3
55
echo "IMAGE is $IMAGE:$t"
66

77
# fail on any non-zero exit codes

docker/Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ RUN set -ex \
3232

3333
# set default user and workdir
3434
WORKDIR /home/conda
35-
ADD dist/proteus-0.5.1.tar.gz .
35+
ADD dist/proteus-0.5.2.tar.gz .
3636

3737
USER root
38-
RUN mkdir -p proteus-0.5.1/build
38+
RUN mkdir -p proteus-0.5.2/build
3939
RUN export PATH=/opt/conda/bin:$PATH
40-
WORKDIR /home/conda/proteus-0.5.1
40+
WORKDIR /home/conda/proteus-0.5.2
4141
RUN python3 setup.py install
4242
WORKDIR /home/conda
4343

@@ -48,7 +48,7 @@ ENV GDAL_DIR /opt/conda
4848
ENV PATH $GDAL_DIR/bin:$PATH
4949
ENV GDAL_DATA $GDAL_DIR/share/gdal
5050

51-
ENV PYTHONPATH /home/conda/proteus-0.5.1/src/:$PYTHONPATH
52-
ENV PATH /home/conda/proteus-0.5.1/bin/:$PATH
51+
ENV PYTHONPATH /home/conda/proteus-0.5.2/src/:$PYTHONPATH
52+
ENV PATH /home/conda/proteus-0.5.2/bin/:$PATH
5353

54-
CMD [ "/bin/bash" ]
54+
CMD [ "/bin/bash" ]

load_docker_tar.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
docker load -i docker/dockerimg_proteus_cal_val_3.2.tar
3+
docker load -i docker/dockerimg_proteus_cal_val_3.3.tar

src/proteus/core.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def save_as_cog(filename, scratch_dir = '.', logger = None,
2727
if logger is None:
2828
logger = logging.getLogger('proteus')
2929

30-
logger.info('COG step 1: add overviews')
30+
logger.info(f'saving file as COG: {filename}')
31+
logger.info(' step 1: add overviews')
3132
gdal_ds = gdal.Open(filename, gdal.GA_Update)
3233
gdal_dtype = gdal_ds.GetRasterBand(1).DataType
3334
dtype_name = gdal.GetDataTypeName(gdal_dtype).lower()
@@ -48,7 +49,7 @@ def save_as_cog(filename, scratch_dir = '.', logger = None,
4849
if os.path.isfile(external_overview_file):
4950
os.remove(external_overview_file)
5051

51-
logger.info('COG step 2: save as COG')
52+
logger.info(' step 2: save as COG')
5253
temp_file = tempfile.NamedTemporaryFile(
5354
dir=scratch_dir, suffix='.tif').name
5455

@@ -72,7 +73,7 @@ def save_as_cog(filename, scratch_dir = '.', logger = None,
7273

7374
shutil.move(temp_file, filename)
7475

75-
logger.info('COG step 3: validate')
76+
logger.info(' step 3: validate')
7677
try:
7778
from proteus.extern.validate_cloud_optimized_geotiff import main as validate_cog
7879
except ModuleNotFoundError:
@@ -82,10 +83,10 @@ def save_as_cog(filename, scratch_dir = '.', logger = None,
8283
argv = ['--full-check=yes', filename]
8384
validate_cog_ret = validate_cog(argv)
8485
if validate_cog_ret == 0:
85-
logger.info(f'file "{filename}" is a valid cloud optimized'
86+
logger.info(f' file "{filename}" is a valid cloud optimized'
8687
' GeoTIFF')
8788
else:
88-
logger.warning(f'file "{filename}" is NOT a valid cloud'
89+
logger.warning(f' file "{filename}" is NOT a valid cloud'
8990
f' optimized GeoTIFF!')
9091

9192

src/proteus/defaults/dswx_hls.yaml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,32 @@ runconfig:
1111

1212
dynamic_ancillary_file_group:
1313
# Digital elevation model file
14+
# (REQUIRED if check_ancillary_inputs_coverage is True)
1415
dem_file:
1516

1617
# Digital elevation model source description
17-
dem_description:
18+
dem_file_description:
1819

1920
# Copernicus Global Land Service (CGLS) Land Cover Layer file
21+
# (REQUIRED if check_ancillary_inputs_coverage is True)
2022
landcover_file:
2123

2224
# Copernicus Global Land Service (CGLS) Land Cover Layer description
23-
landcover_description:
25+
landcover_file_description:
2426

2527
# ESA WorldCover map file
28+
# (REQUIRED if check_ancillary_inputs_coverage is True)
2629
worldcover_file:
2730

2831
# ESA WorldCover map description
29-
worldcover_description:
32+
worldcover_file_description:
33+
34+
# NOAA GSHHS shapefile
35+
# (REQUIRED if check_ancillary_inputs_coverage is True)
36+
shoreline_shapefile:
37+
38+
# NOAA GSHHS shapefile description
39+
shoreline_shapefile_description:
3040

3141
primary_executable:
3242
product_type: DSWX_HLS
@@ -71,6 +81,9 @@ runconfig:
7181
# Copernicus CGLS Land Cover 100m forest classes
7282
copernicus_forest_classes: [20, 111, 113, 115, 116, 121, 123, 125, 126]
7383

84+
# Ocean masking distance from shoreline in km
85+
ocean_masking_shoreline_distance_km: 1
86+
7487
save_wtr: True # Layer 1 - WTR
7588
save_bwtr: True # Layer 2 - BWTR
7689
save_conf: True # Layer 3 - CONF
@@ -109,7 +122,7 @@ runconfig:
109122
# class in the browse image. If True, PSW-Agg pixels will
110123
# appear as Not Water. If False, this class will be displayed
111124
# in the browse image, same as in WTR. Default is False.
112-
exclude_psw_aggressive_in_browse: False
125+
exclude_psw_aggressive_in_browse: True
113126

114127
# Define how Not Water (e.g. land) appears in the browse image.
115128
# Defaults to 'white'.

0 commit comments

Comments
 (0)