Skip to content

Commit

Permalink
Merge pull request #97 from opera-adt/dswx-s1-final
Browse files Browse the repository at this point in the history
Main branch update from DSWx-S1-final
  • Loading branch information
oberonia78 authored Jul 17, 2024
2 parents 80e1a5a + 8819117 commit 2786b44
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 107 deletions.
4 changes: 2 additions & 2 deletions src/dswx_sar/defaults/algorithm_parameter_ni.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ runconfig:
# using bimodality strategy.
# One values are required for bimodality method
tile_selection_bimodality: 0.7
# Stratey to interpolate the tile-based thresholds.
# Strategy to interpolate the tile-based thresholds.
# Currently, only 'smoothed' is available.
extending_method: 'gdal_grid'
# Thresholding algorithm for initial thresholds.
Expand Down Expand Up @@ -161,7 +161,7 @@ runconfig:
# The elements will be masked out during this step.
land_cover_darkland_list: ['Bare sparse vegetation', 'Urban', 'Moss and lichen']
# The elements is considered as the dark land candidates
# where these elemtns are spatially connected to the dark land.
# where these elements are spatially connected to the dark land.
land_cover_darkland_extension_list: ['Grassland', 'Shrubs']
land_cover_water_label: ['Permanent water bodies']
# VV and VH threshold values for dark land candidates
Expand Down
4 changes: 2 additions & 2 deletions src/dswx_sar/defaults/algorithm_parameter_s1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ runconfig:
# using bimodality strategy.
# One values are required for bimodality method
tile_selection_bimodality: 0.7
# Stratey to interpolate the tile-based thresholds.
# Strategy to interpolate the tile-based thresholds.
# Currently, only 'smoothed' is available.
extending_method: 'gdal_grid'
# Thresholding algorithm for initial thresholds.
Expand Down Expand Up @@ -178,7 +178,7 @@ runconfig:
# The elements will be masked out during this step.
land_cover_darkland_list: ['Bare sparse vegetation', 'Urban', 'Moss and lichen']
# The elements is considered as the dark land candidates
# where these elemtns are spatially connected to the dark land.
# where these elements are spatially connected to the dark land.
land_cover_darkland_extension_list: ['Grassland', 'Shrubs']
land_cover_water_label: ['Permanent water bodies']
# VV and VH threshold values for dark land candidates
Expand Down
2 changes: 1 addition & 1 deletion src/dswx_sar/defaults/dswx_ni.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ runconfig:
# algorithm parameter
algorithm_parameters:

# placeholder for inundated vegettion
# placeholder for inundated vegetation
mean_backscattering:
standard_deviation_backscattering:

Expand Down
2 changes: 1 addition & 1 deletion src/dswx_sar/dswx_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _compare_dswx_sar_metadata(metadata_1, metadata_2):
metadata_error_message = (
f'* input 1 metadata has {len(metadata_1.keys())} entries'
f' whereas input 2 metadata has {len(metadata_2.keys())} entries.')

set_1_m_2 = set(metadata_1.keys()) - set(metadata_2.keys())
if len(set_1_m_2) > 0:
metadata_error_message += (' Input 1 metadata has extra entries'
Expand Down
1 change: 0 additions & 1 deletion src/dswx_sar/dswx_geogrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,3 @@ def update_geogrid(self, geotiff_path):

self.epsg = new_geogrid.epsg \
if not np.isnan(new_geogrid.epsg) else self.epsg

2 changes: 1 addition & 1 deletion src/dswx_sar/dswx_ni_runconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def custom_sort(pol):
pol_mode = pol_mode_name

if pol_mode is None:
err_msg = 'unable to identify polarzation mode.'
err_msg = 'unable to identify polarization mode.'
logger.warning(err_msg)
return co_pol_list, cross_pol_list, sorted_pol_list, pol_mode

Expand Down
8 changes: 4 additions & 4 deletions src/dswx_sar/dswx_runconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

# Potential polarization scenarios for DSWx-S1
# NOTE: DO NOT CHANGE THE ORDER of the items in the dictionary below.
# There are more modes such as 'MIX_DUAL_V_SINGLE_V' and
# There are more modes such as 'MIX_DUAL_V_SINGLE_V' and
# 'MIX_DUAL_H_SINGLE_H' describing the dual_polarization and
# single polarization with same polarization. This mode will be
# deteremine by counting the available bursts.
# single polarization with same polarization. This mode will be
# determined by counting the available bursts.
DSWX_S1_POL_DICT = {
'CO_POL': ['HH', 'VV'],
'CROSS_POL': ['HV', 'VH'],
Expand Down Expand Up @@ -305,7 +305,7 @@ def custom_sort(pol):
pol_mode = pol_mode_name

if pol_mode is None:
err_msg = 'unable to identify polarzation mode.'
err_msg = 'unable to identify polarization mode.'
logger.warning(err_msg)
return co_pol_list, cross_pol_list, sorted_pol_list, pol_mode

Expand Down
12 changes: 6 additions & 6 deletions src/dswx_sar/dswx_sar_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
Internally, DSWx-S1 has 2 water classes;
1. low-backscattering water
2. high-backscattering water
There classes are collapesed into water class when
There classes are collapsed into water class when
WTR layers converts to BWTR.
Low-backscattering land (dark land) is captured from
Expand Down Expand Up @@ -477,15 +477,15 @@ def change_epsg_tif(input_tif, output_tif, epsg_output,

# Get pixel dimensions
pixel_x_spacing = metadata['geotransform'][1]
pixel_y_sapcing = metadata['geotransform'][5]
pixel_y_spacing = metadata['geotransform'][5]

# Get the number of rows and columns
cols = metadata['width']
rows = metadata['length']

# Calculate coordinates of the lower right corner
x_max = x_min + (cols * pixel_x_spacing)
y_min = y_max + (rows * pixel_y_sapcing)
y_min = y_max + (rows * pixel_y_spacing)

corners = [
(x_min, y_max), # Top-left
Expand All @@ -499,7 +499,7 @@ def change_epsg_tif(input_tif, output_tif, epsg_output,
metadata['epsg'],
epsg_output,
x_snap=pixel_x_spacing,
y_snap=pixel_y_sapcing)
y_snap=pixel_y_spacing)

x_coords, y_coords = zip(*corner_output)
x_min_output, x_max_output = min(x_coords), max(x_coords)
Expand Down Expand Up @@ -1120,7 +1120,7 @@ def merge_binary_layers(layer_list, value_list, merged_layer_path,
cog_flag : bool, optional
Write to COG if True. Defaults to True.
scratch_dir : str, optional
Path to scrath dir. Defaults to '.'.
Path to scratch dir. Defaults to '.'.
Returns
-------
Expand Down Expand Up @@ -1182,7 +1182,7 @@ def intensity_display(intensity, outputdir, pol, immin=-30, immax=0):
pol: str
specific polarization added to the file name
immin: float
mininum dB value for displaying intensity
minimum dB value for displaying intensity
immax: float
maximum dB value for displaying intensity
"""
Expand Down
2 changes: 1 addition & 1 deletion src/dswx_sar/filter_SAR.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def compute_window_mean_std(arr, winsize):
mean = masked_convolve2d(arr_masked, window, mode='same')
c2 = masked_convolve2d(arr_masked*arr_masked, window, mode='same')

var = (c2 - mean * mean)
var = c2 - mean * mean

# The negative number in sqrt is replaced
# with the negligibly small number to avoid numpy warning message.
Expand Down
6 changes: 3 additions & 3 deletions src/dswx_sar/fuzzy_value_computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def compute_fuzzy_value(intensity,
workflows i.e.twele or opera_dswx_s1
fuzzy_option : dict
fuzzy options to compute the fuzzy values containing
fllowing key:value parameters
following key:value parameters
'hand_threshold': HAND value to mask out
'slope_min': minimum value for z membership function for slope
'slope_max': maximum value for z membership function for slope
Expand Down Expand Up @@ -291,7 +291,7 @@ def compute_fuzzy_value(intensity,
s-membership for reference water
copol_only : numpy.ndarray
binary image showing the area where
ony co-polization is used.
ony co-polarization is used.
'''
_, rows, cols = intensity.shape

Expand Down Expand Up @@ -377,7 +377,7 @@ def compute_fuzzy_value(intensity,
change_ind = co_pol_ind

# Cross-polarization intensity is replaced with co- (or span-) pol
# where water varation is high and areas are dark/flat.
# where water variation is high and areas are dark/flat.
intensity_z_set[cross_pol_ind][high_frequent_water] = \
intensity_z_set[change_ind][high_frequent_water]
intensity_z_set[cross_pol_ind][landcover_flat_area] = \
Expand Down
12 changes: 6 additions & 6 deletions src/dswx_sar/initial_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def select_tile_bimodality(self,
numstep+1),
density=True)

bincenter = ((intensity_bins[:-1] + intensity_bins[1:]) / 2)
bincenter = (intensity_bins[:-1] + intensity_bins[1:]) / 2
intensity_db_variance = np.nanstd(intensity_db)**2

intensity_bins_step = intensity_bins[2] - intensity_bins[1]
Expand Down Expand Up @@ -268,7 +268,7 @@ def tile_selection_wbd(self,
water_mask,
win_size=200,
selection_methods=['combined'],
mininum_tile=20,
minimum_tile=20,
minimum_pixel_number=40):
'''Select the tile candidates containing water and non-water
from aid of water body layer based on the selection method
Expand Down Expand Up @@ -369,7 +369,7 @@ def tile_selection_wbd(self,
# both water bodies and lands from the reference water map.
# if 0.0 < water_coverage < 1 and 0.0 < land_coverage < 1:
if water_area_flag:
while (num_detected_box_sum <= mininum_tile) and \
while (num_detected_box_sum <= minimum_tile) and \
(win_size >= minimum_pixel_number):

subrun += 1
Expand Down Expand Up @@ -489,7 +489,7 @@ def tile_selection_wbd(self,
selected_tile_chini.append(False)
selected_tile_bimodality.append(False)

# keep coordiates for the searching window.
# keep coordinates for the searching window.
coordinate.append(
[ind_subtile,
x_start, x_end,
Expand Down Expand Up @@ -524,7 +524,7 @@ def tile_selection_wbd(self,
selected_tile_bimodality)
num_detected_box = np.sum(detected_box_array)

if num_detected_box_sum <= mininum_tile:
if num_detected_box_sum <= minimum_tile:
# try tile-selection with smaller win size
win_size = int(win_size * 0.5)
num_pixel_max = win_size * win_size / 3
Expand Down Expand Up @@ -1581,7 +1581,7 @@ def fill_threshold_with_distance(threshold_array,
for block in range(0, nblocks):
row_start = block * lines_per_block

if (row_start + lines_per_block > rows):
if row_start + lines_per_block > rows:
block_rows = rows - row_start
else:
block_rows = lines_per_block
Expand Down
26 changes: 13 additions & 13 deletions src/dswx_sar/masking_with_ancillary.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def extract_bbox_with_buffer(
sizes : np.ndarray
Sizes of the connected components.
label_image : np.ndarray
2 dimensional lebel array for each binary object
2 dimensional label array for each binary object
"""
rows, cols = binary.shape

Expand Down Expand Up @@ -515,7 +515,7 @@ def split_extended_water_parallel(


def compute_spatial_coverage_from_ancillary_parallel(
flase_water_binary_path: str,
false_water_binary_path: str,
reference_water_path: str,
mask_landcover_path: str,
output_file_path: str,
Expand All @@ -530,7 +530,7 @@ def compute_spatial_coverage_from_ancillary_parallel(
Parameters
----------
flase_water_binary_path : str
false_water_binary_path : str
Path to the binary water mask GeoTIFF file.
reference_water_path : str
Path to the reference water GeoTIFF file.
Expand All @@ -555,8 +555,8 @@ def compute_spatial_coverage_from_ancillary_parallel(
Saves the computed water mask indicating water areas in the
specified output file path.
"""
water_mask = dswx_sar_util.read_geotiff(flase_water_binary_path)
meta_info = dswx_sar_util.get_meta_from_tif(flase_water_binary_path)
water_mask = dswx_sar_util.read_geotiff(false_water_binary_path)
meta_info = dswx_sar_util.get_meta_from_tif(false_water_binary_path)

# Extract bounding boxes with buffer
coord_list, sizes, label_image = extract_bbox_with_buffer(
Expand Down Expand Up @@ -611,7 +611,7 @@ def compute_spatial_coverage_from_ancillary_parallel(
water_label_str, ref_land_tif_str)
for i in range(len(sizes))]

# Output consists of index and 2D image consisting of True/Flase.
# Output consists of index and 2D image consisting of True/False.
# True represents the land and False represents not-land.
results = Parallel(n_jobs=number_workers)(
delayed(compute_spatial_coverage)(args)
Expand Down Expand Up @@ -997,7 +997,7 @@ def hand_filter_along_boundary(
scratch_dir=scratch_dir,
datatype='float32')
hand_binary_path = os.path.join(
scratch_dir, "landcover_hand_bindary.tif")
scratch_dir, "landcover_hand_binary.tif")
dswx_sar_util.save_dswx_product(
hand_filtered_binary,
hand_binary_path,
Expand Down Expand Up @@ -1164,7 +1164,7 @@ def run(cfg):
# spatially connected with `mask_excluded_landcover` are added.
if extended_landcover_flag:
logger.info('Extending landcover enabled.')
rg_excluded_area = (interp_wbd > dry_water_area_threshold)
rg_excluded_area = interp_wbd > dry_water_area_threshold

mask_excluded_landcover = extend_land_cover(
landcover_path=landcover_path,
Expand All @@ -1187,7 +1187,7 @@ def run(cfg):
projection=water_meta['projection'],
scratch_dir=outputdir)

# 2) Create intial mask binary
# 2) Create initial mask binary
# mask_excluded indicates the areas satisfying all conditions which are
# 1: `dry_water_area_threshold` of water occurrence over 37 year (Pekel)
# 2: specified landcovers (bare ground, sparse vegetation, urban, moss...)
Expand Down Expand Up @@ -1259,14 +1259,14 @@ def run(cfg):
cog_flag=True,
scratch_dir=outputdir)

adjacent_false_positive_bindary_path = \
adjacent_false_positive_binary_path = \
os.path.join(outputdir, 'false_positive_connected_water.tif')

compute_spatial_coverage_from_ancillary_parallel(
flase_water_binary_path=false_water_candidate_path,
false_water_binary_path=false_water_candidate_path,
reference_water_path=interp_wbd_str,
mask_landcover_path=mask_excluded_landcover_path,
output_file_path=adjacent_false_positive_bindary_path,
output_file_path=adjacent_false_positive_binary_path,
outputdir=outputdir,
water_max_value=ref_water_max,
number_workers=number_workers,
Expand All @@ -1282,7 +1282,7 @@ def run(cfg):
os.path.join(outputdir, f"refine_landcover_binary_{pol_str}.tif")

dswx_sar_util.merge_binary_layers(
layer_list=[adjacent_false_positive_bindary_path,
layer_list=[adjacent_false_positive_binary_path,
darkland_cand_path,
water_map_tif_str],
value_list=[0, 0, 1],
Expand Down
2 changes: 1 addition & 1 deletion src/dswx_sar/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,4 @@ def create_dswx_ni_metadata(cfg,
# Merge extra_meta_data with dswx_metadata_dict if provided
if extra_meta_data is not None:
dswx_metadata_dict.update(extra_meta_data)
return dswx_metadata_dict
return dswx_metadata_dict
Loading

0 comments on commit 2786b44

Please sign in to comment.