Skip to content

shp: Spatially Homogeneous Pixels Identification

Commands of moraine.cli.shp (source); the same functions are called in Python as mc.<name>(...) with import moraine.cli as mc. The help below is generated from the docstrings, like moraine COMMAND --help.

command summary
shp-test SHP identification through hypothesis test, and the selection of the SHPs at the level alpha.
select-shp Select SHP based on pvalue of SHP test.

shp-test

SHP identification through hypothesis test, and the selection of the SHPs at the level alpha.

moraine shp-test --rslc STR --is_shp STR --shp_num STR --az_half_win VALUE --r_half_win VALUE [--alpha VALUE] [--pvalue STR] [--method STR] [--chunks INT INT] [--cuda | --no-cuda] [--processes VALUE] [--n_workers VALUE] [--threads_per_worker VALUE]
argument type default description
--rslc str required input rslc stack, shape (nlines, width, nimages)
--is_shp str required output True for the SHPs of each pixel, i.e. the pixels of its window whose p value is at least alpha, shape (nlines, width, 2az_half_win+1, 2r_half_win+1), bool
--shp_num str required output number of SHPs of each pixel, shape (nlines, width), int32
--az_half_win int required azimuth half window size
--r_half_win int required range half window size
--alpha float 0.05 significance level of the test, in (0, 1): a pixel is an SHP of the centre pixel of its window when its p value is at least alpha; a larger alpha keeps fewer SHPs
--pvalue str None output p value of the test between each pixel and the pixels in its window, same shape as is_shp, float32; needed only to select the SHPs again at another level with select-shp
--method str None test method, only 'ks' (two-sample Kolmogorov-Smirnov) is implemented. Default: 'ks'
--chunks tuple[int, int] None (azimuth, range) processing chunk size, same as rslc by default
--cuda bool False if use cuda for processing, false by default
--processes None use processes (True) or threads (False) for the workers, only for cpu processing. Default: False
--n_workers None number of workers. Default: 1 for cpu, one per GPU for cuda
--threads_per_worker None tasks a worker runs at the same time. Default: 1

Global options: --json, --traceback, --log FILE, -q / --quiet (conventions).

In a pipeline (examples/03_ds.toml, step shp_test):

[[step]]
name = "shp_test"                 # two sample KS test in a 7 x 27 window (about 100 m x 60 m on the ground), SHPs = p value >= alpha
run = "shp-test"
rslc = "raw/rslc.zarr"
az_half_win = 3
r_half_win = 13
is_shp = "ds/ras_is_shp.zarr"
shp_num = "ds/ras_shp_num.zarr"
alpha = 0.05                      # significance level; add pvalue = "ds/ras_pvalue.zarr" to keep the p values

In Python:

import moraine.cli as mc
mc.shp_test(rslc, is_shp, shp_num, az_half_win, r_half_win, alpha=0.05, pvalue=None, method=None, chunks=None, cuda=False, processes=None, n_workers=None, threads_per_worker=None)

select-shp

Select SHP based on pvalue of SHP test.

moraine select-shp --pvalue STR --is_shp STR --shp_num STR [--alpha VALUE] [--chunks INT INT] [--processes | --no-processes] [--n_workers VALUE] [--threads_per_worker VALUE]
argument type default description
--pvalue str required input pvalue of hypothesis test
--is_shp str required output bool array, True for SHPs, same shape as pvalue
--shp_num str required output number of SHPs of each pixel, shape (nlines, width), int32
--alpha float 0.05 significance level of the test, in (0, 1): a pixel is an SHP of the centre pixel of its window when its p value is at least alpha, i.e. the test does not reject that both have the same distribution; a larger alpha keeps fewer SHPs
--chunks tuple[int, int] None (azimuth, range) processing chunk size, same as pvalue by default
--processes False use processes for the workers instead of threads, the default is False
--n_workers 1 number of workers, the default is 1
--threads_per_worker 1 tasks a worker runs at the same time

Global options: --json, --traceback, --log FILE, -q / --quiet (conventions).

In a pipeline (not used by the example pipelines; required arguments only):

[[step]]
name = "select_shp"
run = "select-shp"
pvalue = "..."
is_shp = "..."
shp_num = "..."

In Python:

import moraine.cli as mc
mc.select_shp(pvalue, is_shp, shp_num, alpha=0.05, chunks=None, processes=False, n_workers=1, threads_per_worker=1)

The array function mr.select_shp does the same on numpy / cupy arrays in memory.