shp: Spatially Homogeneous Pixels Identification¶
moraine.api.shp (source). Every name is also moraine.<name> (import moraine as mr).
ks_test
¶
ks_test(rmli: ndarray, az_half_win: int, r_half_win: int, block_size: int = 128, return_dist: bool = False) -> tuple[ndarray, ndarray]
SHP identification based on Two-Sample Kolmogorov-Smirnov Test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rmli
|
ndarray
|
the rmli stack, dtype: cupy.floating |
required |
az_half_win
|
int
|
SHP identification half search window size in azimuth direction |
required |
r_half_win
|
int
|
SHP identification half search window size in range direction |
required |
block_size
|
int
|
the CUDA block size, it only affects the calculation speed, only applied if input is cupy.ndarray |
128
|
return_dist
|
bool
|
if return the KS test statistics |
False
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
if return_dist == True, return |
select_shp
¶
Select the SHPs: the pixels whose test against the centre pixel is not rejected at the level alpha.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
p value of the test between each pixel and the pixels in its window, shape (n_az, n_r, az_win, r_win), floating; nan for no test |
required | |
alpha
|
significance level, float in (0, 1): a pixel is an SHP when its p value is at least |
required |
Returns:
| Type | Description |
|---|---|
is_shp
|
True for SHPs, shape (n_az, n_r, az_win, r_win), bool |
shp_num
|
number of SHPs of each pixel, shape (n_az, n_r), int32 |
Examples¶
Run when this manual is built; the output follows each snippet.
import numpy as np
import moraine as mr
rng = np.random.default_rng(0)
nlines, width, nimages = 12, 16, 30
# two homogeneous regions of different brightness, side by side (exponential intensity: speckle)
rmli = rng.exponential(1.0, (nlines, width, nimages)).astype(np.float32)
rmli[:, 8:] *= 4.0
p = mr.ks_test(rmli, az_half_win=2, r_half_win=2) # p value of the KS test, (nlines, width, 5, 5)
is_shp, shp_num = mr.select_shp(p, alpha=0.05) # SHP: p >= alpha
print(p.shape, is_shp.shape, shp_num.shape, shp_num.dtype)
print('inside the left region', shp_num[6, 3], ' at the boundary', shp_num[6, 7], ' of', 5 * 5)
A pixel with many SHPs is a DS candidate (e.g. shp_num >= 50 of a 11 x 11 window in the pipelines); is_shp
is the input of the coherence estimation.