Skip to content

Commit 2dbf67a

Browse files
author
Jungkyo Jung
committed
fast landcover in bimodality test
1 parent 1dae324 commit 2dbf67a

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

src/dswx_sar/nisar/refine_with_bimodality.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
from dswx_sar.common import _masking_with_ancillary
1111
from dswx_sar.common._refine_with_bimodality import (
1212
remove_false_water_bimodality_parallel,
13-
fill_gap_water_bimodality_parallel
13+
fill_gap_water_bimodality_parallel,
14+
write_ref_land_from_landcover_and_wbd_streaming
1415
)
1516
from dswx_sar.nisar.dswx_ni_runconfig import (
1617
_get_parser,
@@ -57,29 +58,25 @@ def run(cfg):
5758
# read landcover map
5859
landcover_map_tif_str = os.path.join(
5960
outputdir, 'interpolated_landcover.tif')
60-
landcover_map = _dswx_sar_util.read_geotiff(landcover_map_tif_str)
61+
62+
landcover_map_tif_str = os.path.join(outputdir, "interpolated_landcover.tif")
63+
reference_water_gdal_str = os.path.join(outputdir, "interpolated_wbd.tif")
64+
6165
landcover_label = _masking_with_ancillary.get_label_landcover_esa_10()
6266

63-
reference_water_gdal_str = os.path.join(outputdir, 'interpolated_wbd.tif')
67+
ref_land_str = os.path.join(outputdir, f"landcover_not_water_{pol_str}.tif")
6468

65-
# Identify the non-water area from Landcover map
66-
if 'openSea' in landcover_label:
67-
landcover_not_water = (landcover_map != landcover_label['openSea']) &\
68-
(landcover_map != landcover_label['Permanent water bodies'])
69-
else:
70-
landcover_not_water = \
71-
(landcover_map != landcover_label['Permanent water bodies']) &\
72-
(landcover_map != landcover_label['No_data'])
73-
74-
ref_land_str = os.path.join(outputdir,
75-
f'landcover_not_water_{pol_str}.tif')
76-
_dswx_sar_util.save_raster_gdal(
77-
data=landcover_not_water,
78-
output_file=ref_land_str,
79-
geotransform=im_meta['geotransform'],
80-
projection=im_meta['projection'],
81-
scratch_dir=outputdir)
82-
del landcover_not_water, landcover_map
69+
write_ref_land_from_landcover_and_wbd_streaming(
70+
landcover_path=landcover_map_tif_str,
71+
wbd_path=reference_water_gdal_str,
72+
out_path=ref_land_str,
73+
geotransform=im_meta["geotransform"],
74+
projection=im_meta["projection"],
75+
landcover_label=landcover_label,
76+
wbd_threshold=5.0,
77+
block_x=2048,
78+
block_y=2048,
79+
)
8380

8481
# If the landcover is non-water,
8582
# compute the bimnodality one more time
@@ -168,7 +165,7 @@ def main():
168165
return
169166

170167
if flag_first_file_is_text:
171-
cfg = RunConfig.load_from_yaml(args.input_yaml[0], 'dswx_s1', args)
168+
cfg = RunConfig.load_from_yaml(args.input_yaml[0], 'dswx_ni', args)
172169

173170
processing_cfg = cfg.groups.processing
174171
pol_mode = processing_cfg.polarization_mode

0 commit comments

Comments
 (0)