Skip to content

Commit a8ec5d8

Browse files
Add adi2() function
1 parent 8cb82cb commit a8ec5d8

2 files changed

Lines changed: 35 additions & 39 deletions

File tree

insardev/insardev/Stack.py

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -243,73 +243,69 @@ def optimize2(self, angle_coarse: float = 15, angle_fine: float = 5, device: str
243243

244244
return type(self)(s_opt_dict)
245245

246-
def adi(self, device: str = 'auto') -> Batch:
246+
def adi2(self,
247+
angle_coarse: float = 15,
248+
angle_fine: float = 5,
249+
device: str = 'auto') -> Batch:
247250
"""
248-
Compute Amplitude Dispersion Index (ADI) for calibrated σ₀ data.
251+
Dual-pol ADI: optimize2() + adi() in one call.
249252
250-
Wrapper that calls BatchComplex.adi() on complex variables.
253+
NOTE: Requires insardev_polsar extension.
254+
255+
Finds optimal VV/VH amplitude combination that minimizes ADI,
256+
then computes ADI on the optimized amplitudes.
251257
252258
Parameters
253259
----------
260+
angle_coarse : float
261+
Coarse grid step in degrees. Default 15.
262+
angle_fine : float
263+
Fine grid step in degrees. Default 5.
254264
device : str
255265
PyTorch device: 'auto', 'cuda', 'mps', or 'cpu'.
256266
257267
Returns
258268
-------
259269
Batch
260-
ADI values for each polarization variable present.
270+
ADI values computed on polarimetrically optimized amplitudes.
261271
262272
Examples
263273
--------
264-
>>> adi = stack.adi()
265-
>>> ps_mask = adi < 0.25
274+
>>> import insardev_polsar
275+
>>> adi = stack.adi2()
276+
>>> ps_mask = adi[['VV']] < 0.4
266277
"""
267-
# Get complex variables
268278
sample_ds = next(iter(self.values()))
269-
complex_vars = [v for v in sample_ds.data_vars
270-
if sample_ds[v].dtype.kind == 'c' and 'date' in sample_ds[v].dims]
271-
272-
if not complex_vars:
273-
raise ValueError("No complex time-series data found")
279+
if 'VV' in sample_ds.data_vars and 'VH' in sample_ds.data_vars:
280+
pols = ['VV', 'VH']
281+
elif 'HH' in sample_ds.data_vars and 'HV' in sample_ds.data_vars:
282+
pols = ['HH', 'HV']
283+
else:
284+
raise ValueError("Dual-pol data required (VV+VH or HH+HV)")
274285

275-
# Get as BatchComplex and call adi()
276-
batch_complex = self[complex_vars]
277-
return batch_complex.adi(device)
286+
batch_complex = self[pols]
287+
return batch_complex.adi2(angle_coarse, angle_fine, device)
278288

279-
def similars(
280-
self,
281-
window: tuple = (5, 5),
282-
threshold: float = 0.5,
283-
valid_threshold: float = 0.5,
284-
device: str = 'auto'
285-
) -> Batch:
289+
def adi(self, device: str = 'auto') -> Batch:
286290
"""
287-
Count temporally phase-similar neighbors per pixel.
288-
289-
NOTE: Requires insardev_polsar extension.
291+
Compute Amplitude Dispersion Index (ADI) for calibrated σ₀ data.
290292
291-
Wrapper that calls BatchComplex.similars() on complex variables.
293+
Wrapper that calls BatchComplex.adi() on complex variables.
292294
293295
Parameters
294296
----------
295-
window : tuple of int
296-
Window size (y, x). Asymmetric to account for different pixel spacing.
297-
threshold : float
298-
Maximum phase std (radians) for a neighbor to count as similar.
299-
valid_threshold : float
300-
Minimum fraction of dates with valid (non-NaN) data.
301297
device : str
302-
PyTorch device: 'auto', 'cuda', 'mps', 'cpu'
298+
PyTorch device: 'auto', 'cuda', 'mps', or 'cpu'.
303299
304300
Returns
305301
-------
306302
Batch
307-
Count of phase-similar neighbors per pixel. Higher = more stable.
303+
ADI values for each polarization variable present.
308304
309305
Examples
310306
--------
311-
>>> sim = stack.similars(window=(11, 41), threshold=1.0)
312-
>>> ps_mask = sim >= 40
307+
>>> adi = stack.adi()
308+
>>> ps_mask = adi < 0.25
313309
"""
314310
# Get complex variables
315311
sample_ds = next(iter(self.values()))
@@ -319,9 +315,9 @@ def similars(
319315
if not complex_vars:
320316
raise ValueError("No complex time-series data found")
321317

322-
# Get as BatchComplex and call similars()
318+
# Get as BatchComplex and call adi()
323319
batch_complex = self[complex_vars]
324-
return batch_complex.similars(window, threshold, valid_threshold, device)
320+
return batch_complex.adi(device)
325321

326322
def neighbors(
327323
self,

insardev/insardev/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# See the LICENSE file in the insardev directory for license terms.
99
# Professional use requires an active per-seat subscription at: https://patreon.com/pechnikov
1010
# ----------------------------------------------------------------------------
11-
__version__ = '2026.3.8.post8'
11+
__version__ = '2026.3.8.post10'
1212

1313
# processing functions
1414
from .Stack import Stack

0 commit comments

Comments
 (0)