Skip to content

Commit

Permalink
Fix the pad_width integral type error for `spatial_filter.py -f dou…
Browse files Browse the repository at this point in the history
…ble_difference` (#1015)

+ `spatial_filter.py`: Fix the np.pad() pad_width integral type error while using double_difference filter.

+ `writefile.write()`: do not overwrite format for .hgt file, as it can be float64 in isce2. Plus, the two-band format in roipac is weird anyway and not used much anymore [in the last 3+ years if I remember correctly].

+ `isce_utils.extract_alosStack_metadata()`: make los_file optional, because 1) attribute CENTER_INCIDENCE_ANGLE is not essential, i.e. optional; and 2) los_file does not exist sometimes, as in the post-processing of alos2App
  • Loading branch information
yunjunz authored May 30, 2023
1 parent 6cbbf29 commit c305e13
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
18 changes: 10 additions & 8 deletions src/mintpy/spatial_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ def filter_data(data, filter_type, filter_par=None):
and regional mean results are separate.
"""

local_kernel = morphology.disk(filter_par[0], np.float32)
local_kernel = np.pad(local_kernel,filter_par[1] - filter_par[0],mode='constant')
local_kernel = morphology.disk(filter_par[0], dtype=np.float32)
local_kernel = np.pad(local_kernel, pad_width=int(filter_par[1]-filter_par[0]), mode='constant')

regional_kernel = morphology.disk(filter_par[1], np.float32)
regional_kernel = morphology.disk(filter_par[1], dtype=np.float32)
regional_kernel[local_kernel == 1] = 0

# normalize
local_kernel /= local_kernel.sum(axis=(0,1))
regional_kernel /= regional_kernel.sum(axis=(0,1))

# double-difference kernel
combined_kernel = regional_kernel - local_kernel

data_filt = ndimage.convolve(data, combined_kernel)
Expand Down Expand Up @@ -107,30 +109,30 @@ def filter_file(fname, ds_names=None, filter_type='lowpass_gaussian', filter_par
# Info
filter_type = filter_type.lower()
atr = readfile.read_attribute(fname)
msg = 'filtering {} file: {} using {} filter'.format(atr['FILE_TYPE'], fname, filter_type)
print(f'input file: {fname}, file type: {atr["FILE_TYPE"]}')
print(f'filter type: {filter_type}')

if filter_type.endswith('avg'):
if not filter_par:
filter_par = 5
elif isinstance(filter_par, list):
filter_par = filter_par[0]
filter_par = int(filter_par)
msg += f' with kernel size of {filter_par}'
print(f'filter parameter: kernel size = {filter_par}')

elif filter_type.endswith('gaussian'):
if not filter_par:
filter_par = 3.0
elif isinstance(filter_par, list):
filter_par = filter_par[0]
filter_par = float(filter_par)
msg += f' with sigma of {filter_par:.1f}'
print(f'filter parameter: sigma = {filter_par:.1f}')

elif filter_type == 'double_difference':
if not filter_par:
filter_par = [1, 10]
local, regional = int(filter_par[0]), int(filter_par[1])
msg += f' with local/regional kernel sizes of {local}/{regional}'
print(msg)
print(f'filter parameter: local / regional kernel sizes = {local} / {regional}')

# output filename
if not fname_out:
Expand Down
10 changes: 6 additions & 4 deletions src/mintpy/utils/isce_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,12 @@ def extract_alosStack_metadata(meta_file, geom_dir):
meta['LON_REF3'] = str(data[-1-edge, 0+edge])
meta['LON_REF4'] = str(data[-1-edge, -1-edge])

los_file = glob.glob(os.path.join(geom_dir, f'*_{rlooks}rlks_{alooks}alks.los'))[0]
data = np.memmap(los_file, dtype='float32', mode='r', shape=(length*2, width))[0:length*2:2, :]
inc_angle = data[int(length/2), int(width/2)]
meta['CENTER_INCIDENCE_ANGLE'] = str(inc_angle)
# CENTER_INCIDENCE_ANGLE is optional
los_files = glob.glob(os.path.join(geom_dir, f'*_{rlooks}rlks_{alooks}alks.los'))
if len(los_files) > 0:
data = np.memmap(los_files[0], dtype='float32', mode='r', shape=(length*2, width))[0:length*2:2, :]
inc_angle = data[int(length/2), int(width/2)]
meta['CENTER_INCIDENCE_ANGLE'] = str(inc_angle)

pointingDirection = {'right': -1, 'left' :1}
meta['ANTENNA_SIDE'] = str(pointingDirection[track.pointingDirection])
Expand Down
2 changes: 1 addition & 1 deletion src/mintpy/utils/readfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ def auto_no_data_value(meta):

# known file types
# isce2: dense offsets from topsApp.py
if processor == 'isce' and fbase.endswith('dense_offsets') and fext == '.bil' and num_band == 2:
if processor == 'isce' and fname.endswith('dense_offsets.bil') and num_band == 2:
no_data_value = -10000.

else:
Expand Down
3 changes: 2 additions & 1 deletion src/mintpy/utils/writefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ def write(datasetDict, out_file, metadata=None, ref_file=None, compression=None,
data_list = [data_list[0], data_list[0]]
meta['BANDS'] = 2

elif fext in ['.cor', '.hgt']:
elif fext in ['.cor']:
# remove .hgt as it can be float64 in isce2.
meta['DATA_TYPE'] = 'float32'
meta['INTERLEAVE'] = 'BIL'
if meta.get('PROCESSOR', 'isce') == 'roipac':
Expand Down

0 comments on commit c305e13

Please sign in to comment.