Skip to content

Commit 7cbb774

Browse files
committed
changed workflow order
1 parent 880da3e commit 7cbb774

File tree

2 files changed

+121
-42
lines changed

2 files changed

+121
-42
lines changed

python/packages/isce3/splitspectrum/splitspectrum.py

Lines changed: 114 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,111 @@ def __init__(self,
109109
self.rg_bandwidth = rg_bandwidth
110110
self.center_frequency = center_frequency
111111
self.slant_range = slant_range
112+
113+
def bandpass_shift_spectrum(self,
114+
slc_raster,
115+
low_frequency,
116+
high_frequency,
117+
new_center_frequency,
118+
window,
119+
window_shape=0.25,
120+
fft_size=None,
121+
resampling=True
122+
):
123+
124+
"""Bandpass SLC for given center frequency and bandwidth
125+
126+
Parameters
127+
----------
128+
slc_raster : numpy.ndarray
129+
numpy array of slc raster,
130+
low_frequency : float
131+
low frequency of band to be passed [Hz]
132+
high_frequency : float
133+
high frequency band to be passed [Hz]
134+
new_center_frequency : float
135+
new center frequency for bandpass [Hz]
136+
window_shape : float
137+
parameter for the raised cosine filter (e.g. 0 ~ 1)
138+
fft_size : int
139+
fft size.
140+
resampling : bool
141+
if True, then resample SLC and meta data with new range spacing
142+
If False, return SLC and meta with original range spacing
143+
144+
Returns
145+
-------
146+
resampled_slc or slc_demodulate: numpy.ndarray
147+
numpy array of bandpassed slc
148+
if resampling is True, return resampled_slc
149+
if resampling is False, return slc_demodulate
150+
meta : dict
151+
dict containing meta data of bandpassed slc
152+
center_frequency, rg_bandwidth, range_spacing, slant_range
153+
"""
154+
error_channel = journal.error('splitspectrum.bandpass_shift_spectrum')
155+
156+
rg_sample_freq = self.rg_sample_freq
157+
rg_bandwidth = self.rg_bandwidth
158+
diff_frequency = self.center_frequency - new_center_frequency
159+
height, width = slc_raster.shape
160+
slc_raster = np.asanyarray(slc_raster, dtype='complex')
161+
162+
slc_bp = self.bandpass_spectrum(
163+
slc_raster=slc_raster,
164+
low_frequency=low_frequency,
165+
high_frequency=high_frequency,
166+
window=window,
167+
window_shape=window_shape,
168+
fft_size=fft_size,
169+
)
170+
171+
# demodulate the SLC to be baseband to new center frequency
172+
# if fft_size > width, then crop the spectrum from 0 to width
173+
slc_demodulate = self.demodulate_slc(slc_bp[:, :width],
174+
diff_frequency,
175+
rg_sample_freq)
176+
177+
# update metadata with new parameters
178+
meta = dict()
179+
new_bandwidth = high_frequency - low_frequency
180+
meta['center_frequency'] = new_center_frequency
181+
meta['rg_bandwidth'] = new_bandwidth
182+
183+
# Resampling changes the spacing and slant range
184+
if resampling:
185+
resampling_scale_factor = rg_bandwidth / new_bandwidth
186+
sub_width = int(width / resampling_scale_factor)
187+
188+
x_cand = np.arange(1, width + 1)
189+
# find the maximum of the multiple of resampling_scale_factor
190+
resample_width_end = np.max(x_cand[x_cand % resampling_scale_factor == 0])
191+
192+
# resample SLC
193+
resampled_slc = resample(slc_demodulate[:, :resample_width_end], sub_width, axis=1)
194+
195+
meta['range_spacing'] = self.rg_pxl_spacing * resampling_scale_factor
196+
meta['slant_range'] = np.linspace(self.slant_range(0), self.slant_range(width),\
197+
sub_width, endpoint=False)
198+
199+
return resampled_slc, meta
200+
201+
else:
202+
filtered_slc = slc_demodulate
203+
204+
meta['range_spacing'] = self.rg_pxl_spacing
205+
meta['slant_range'] = np.linspace(self.slant_range(0), self.slant_range(width),\
206+
width, endpoint=False)
207+
208+
return slc_demodulate, meta
112209

113210
def bandpass_spectrum(self,
114211
slc_raster,
115212
low_frequency,
116213
high_frequency,
117-
new_center_frequency,
118214
window,
119215
window_shape=0.25,
120-
fft_size=None
216+
fft_size=None,
121217
):
122218
"""Bandpass SLC for given center frequency and bandwidth
123219
@@ -129,10 +225,12 @@ def bandpass_spectrum(self,
129225
low frequency of band to be passed [Hz]
130226
high_frequency : float
131227
high frequency band to be passed [Hz]
132-
new_center_frequency : float
133-
new center frequency for bandpass [Hz]
228+
window: str
229+
window type {'tukey', 'kaiser', 'cosine'}
134230
window_shape : float
135-
parameter for the raised cosine filter (e.g. 0 ~ 1)
231+
parameter for the window shape
232+
kaiser 0<= window_shape < inf
233+
tukey and cosine 0 <= window_shape <= 1
136234
fft_size : int
137235
fft size.
138236
@@ -149,11 +247,11 @@ def bandpass_spectrum(self,
149247
rg_sample_freq = self.rg_sample_freq
150248
rg_bandwidth = self.rg_bandwidth
151249
center_frequency = self.center_frequency
152-
diff_frequency = self.center_frequency - new_center_frequency
153250
height, width = slc_raster.shape
154251
slc_raster = np.asanyarray(slc_raster, dtype='complex')
155252
new_bandwidth = high_frequency - low_frequency
156-
253+
resampling_scale_factor = rg_bandwidth / new_bandwidth
254+
157255
if new_bandwidth < 0:
158256
err_str = f"Low frequency is higher than high frequency"
159257
error_channel.log(err_str)
@@ -167,7 +265,7 @@ def bandpass_spectrum(self,
167265
error_channel.log(err_str)
168266
raise ValueError(err_str)
169267

170-
# construct window to remove window effect in freq domain
268+
# construct window to be deconvolved from the original SLC in freq domain
171269
window_target = self.get_range_bandpass_window(
172270
center_frequency=0,
173271
frequencyLH=[-rg_bandwidth/2,
@@ -176,7 +274,7 @@ def bandpass_spectrum(self,
176274
fft_size=fft_size,
177275
window_function=window,
178276
window_shape=window_shape
179-
)
277+
)
180278
# construct window to bandpass spectrum
181279
# for given low and high frequencies
182280
window_bandpass = self.get_range_bandpass_window(
@@ -187,10 +285,7 @@ def bandpass_spectrum(self,
187285
fft_size=fft_size,
188286
window_function=window,
189287
window_shape=window_shape
190-
)
191-
192-
resampling_scale_factor = rg_bandwidth / new_bandwidth
193-
sub_fft_size = int(width / resampling_scale_factor)
288+
)
194289

195290
# remove the windowing effect from the spectrum
196291
spectrum_target = fft(slc_raster, n=fft_size) / \
@@ -200,23 +295,7 @@ def bandpass_spectrum(self,
200295
* window_bandpass
201296
* np.sqrt(resampling_scale_factor), n=fft_size)
202297

203-
# demodulate the SLC to be baseband to new center frequency
204-
# if fft_size > width, then crop the spectrum from 0 to width
205-
slc_demodulate = self.demodulate_slc(slc_bp[:, :width],
206-
diff_frequency,
207-
rg_sample_freq)
208-
209-
# resample SLC
210-
filtered_slc = resample(slc_demodulate, sub_fft_size, axis=1)
211-
212-
meta = dict()
213-
meta['center_frequency'] = new_center_frequency
214-
meta['rg_bandwidth'] = new_bandwidth
215-
meta['range_spacing'] = self.rg_pxl_spacing * resampling_scale_factor
216-
meta['slant_range'] = np.linspace(self.slant_range(0), self.slant_range(width),\
217-
sub_fft_size, endpoint=False)
218-
219-
return filtered_slc, meta
298+
return slc_bp
220299

221300
def demodulate_slc(self, slc_array, diff_frequency, rg_sample_freq):
222301
""" Demodulate SLC
@@ -240,9 +319,9 @@ def demodulate_slc(self, slc_array, diff_frequency, rg_sample_freq):
240319
"""
241320
height, width = slc_array.shape
242321
range_time = np.arange(width) / rg_sample_freq
243-
slc_baseband = slc_array * np.exp(-1 * 1j * 2.0 * np.pi * -1
322+
slc_shifted = slc_array * np.exp(-1 * 1j * 2.0 * np.pi * -1
244323
* diff_frequency * range_time)
245-
return slc_baseband
324+
return slc_shifted
246325

247326
def freq_spectrum(self, cfrequency, dt, fft_size):
248327
freq = cfrequency + fftfreq(fft_size, dt)
@@ -282,7 +361,7 @@ def get_range_bandpass_window(self,
282361
filter_1d : np.ndarray
283362
one dimensional bandpass filter in frequency domain
284363
'''
285-
#
364+
# construct the freqeuncy bin [Hz]
286365
frequency = self.freq_spectrum(
287366
cfrequency=center_frequency,
288367
dt=1.0/sampling_frequency,
@@ -291,7 +370,8 @@ def get_range_bandpass_window(self,
291370

292371
fL, fH = frequencyLH
293372
window_kind = window_function.lower()
294-
373+
374+
# Windowing effect will appear from fL to fH for given frequency bin
295375
if window_kind == 'tukey':
296376
if not (0 <= window_shape <= 1):
297377
raise ValueError(f"Expected window_shape between 0 and 1, got {window_shape}.")
@@ -303,10 +383,8 @@ def get_range_bandpass_window(self,
303383
)
304384

305385
elif window_kind == 'kaiser' or window_kind == 'cosine':
306-
307386
if (window_kind == 'kaiser') and not (window_shape > 0):
308387
raise ValueError(f"Expected pedestal bigger than 0, got {window_shape}.")
309-
310388
if (window_kind == 'cosine') and not (0 <= window_shape <= 1):
311389
raise ValueError(f"Expected window_shape between 0 and 1, got {window_shape}.")
312390

python/packages/nisar/workflows/bandpass_insar.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ def run(cfg: dict):
135135

136136
# Specify low and high frequency to be passed (bandpass)
137137
# and the center frequency to be basebanded (demodulation)
138-
bandpass_slc, bandpass_meta = bandpass.bandpass_spectrum(
138+
bandpass_slc, bandpass_meta = bandpass.bandpass_shift_spectrum(
139139
slc_raster=target_slc_image,
140140
low_frequency=low_frequency_base,
141141
high_frequency=high_frequency_base,
142142
new_center_frequency=base_meta_data['center_frequency'],
143143
fft_size=fft_size,
144144
window_shape=window_shape,
145-
window=window_function
145+
window=window_function,
146+
resampling=True
146147
)
147148

148149
if block == 0:
@@ -170,14 +171,14 @@ def run(cfg: dict):
170171
dst_h5.create_dataset(f"{dest_freq_path}/slantRange",
171172
data=bandpass_meta['slant_range'])
172173

173-
# update HDF5
174-
if bandpass_modes:
175-
h5_prep.run(cfg)
174+
# # update HDF5
175+
# if bandpass_modes:
176+
# h5_prep.run(cfg)
176177

177178
t_all_elapsed = time.time() - t_all
178179
print('total processing time: ', t_all_elapsed, ' sec')
179180
info_channel.log(
180-
f"successfully ran bandpass in {t_all_elapsed:.3f} seconds")
181+
f"successfully ran bandpass_insar in {t_all_elapsed:.3f} seconds")
181182

182183

183184
if __name__ == "__main__":

0 commit comments

Comments
 (0)