ps

persistent scatterers identification
import zarr
import numpy as np
from matplotlib import pyplot as plt
import colorcet
import moraine.cli as mc
from moraine.utils_ import is_cuda_available

source

amp_disp

 amp_disp (rslc:str, adi:str, chunks:tuple[int,int]=None,
           out_chunks:tuple[int,int]=None, cuda:bool=False,
           processes=None, n_workers=None, threads_per_worker=None,
           rmm_pool_size=0.9, **dask_cluster_arg)

calculation the amplitude dispersion index from SLC stack.

Type Default Details
rslc str rslc stack
adi str output, amplitude dispersion index
chunks tuple None data processing chunk size, same as rslc by default
out_chunks tuple None output data chunk size, same as chunks by default
cuda bool False if use cuda for processing, false by default
processes NoneType None use process for dask worker over thread, the default is False for cpu, only applied if cuda==False
n_workers NoneType None number of dask worker, the default is 1 for cpu, number of GPU for cuda
threads_per_worker NoneType None number of threads per dask worker, the default is 2 for cpu, only applied if cuda==False
rmm_pool_size float 0.9 set the rmm pool size, only applied when cuda==True
dask_cluster_arg

Using amplitude dispersion index (ADI) to identify persistent scatterers is first used in (Ferretti, Prati, and Rocca Jan./2001).

Ferretti, A., C. Prati, and F. Rocca. Jan./2001. “Permanent Scatterers in SAR Interferometry.” IEEE Transactions on Geoscience and Remote Sensing 39 (1): 8–20. https://doi.org/10.1109/36.898661.

Usage:

rslc = './raw/rslc.zarr'
adi = './ps/adi.zarr'
logger = mc.get_logger()
amp_disp(rslc,adi)
2024-08-14 17:08:55 - log_args - INFO - running function: amp_disp
2024-08-14 17:08:55 - log_args - INFO - fetching args:
2024-08-14 17:08:55 - log_args - INFO - rslc = './raw/rslc.zarr'
2024-08-14 17:08:55 - log_args - INFO - adi = './ps/adi.zarr'
2024-08-14 17:08:55 - log_args - INFO - chunks = None
2024-08-14 17:08:55 - log_args - INFO - out_chunks = None
2024-08-14 17:08:55 - log_args - INFO - cuda = False
2024-08-14 17:08:55 - log_args - INFO - processes = None
2024-08-14 17:08:55 - log_args - INFO - n_workers = None
2024-08-14 17:08:55 - log_args - INFO - threads_per_worker = None
2024-08-14 17:08:55 - log_args - INFO - rmm_pool_size = 0.9
2024-08-14 17:08:55 - log_args - INFO - dask_cluster_arg = {}
2024-08-14 17:08:55 - log_args - INFO - fetching args done.
2024-08-14 17:08:55 - zarr_info - INFO - ./raw/rslc.zarr zarray shape, chunks, dtype: (2500, 1834, 17), (1000, 1000, 1), complex64
2024-08-14 17:08:55 - amp_disp - INFO - starting dask local cluster.
2024-08-14 17:08:55 - amp_disp - INFO - dask local cluster started.
2024-08-14 17:08:55 - dask_cluster_info - INFO - dask cluster: LocalCluster(dashboard_link='http://10.211.48.16:8787/status', workers=1, threads=1, memory=1.46 TiB)
2024-08-14 17:08:55 - darr_info - INFO - rslc dask array shape, chunksize, dtype: (2500, 1834, 17), (1000, 1000, 17), complex64
2024-08-14 17:08:55 - amp_disp - INFO - calculate amplitude dispersion index.
2024-08-14 17:08:55 - amp_disp - INFO - got amplitude dispersion index.
2024-08-14 17:08:55 - darr_info - INFO - adi dask array shape, chunksize, dtype: (2500, 1834), (1000, 1000), float32
2024-08-14 17:08:55 - darr_info - INFO - adi dask array shape, chunksize, dtype: (2500, 1834), (1000, 1000), float32
2024-08-14 17:08:55 - amp_disp - INFO - saving adi.
2024-08-14 17:08:55 - zarr_info - INFO - ./ps/adi.zarr zarray shape, chunks, dtype: (2500, 1834), (1000, 1000), float32
2024-08-14 17:08:55 - amp_disp - INFO - computing graph setted. doing all the computing.
2024-08-14 17:08:58 - amp_disp - INFO - computing finished. |  2.5s
2024-08-14 17:08:58 - amp_disp - INFO - dask cluster closed.
if is_cuda_available:
    amp_disp(rslc,adi,cuda=True)
2024-08-14 17:08:58 - log_args - INFO - running function: amp_disp
2024-08-14 17:08:58 - log_args - INFO - fetching args:
2024-08-14 17:08:58 - log_args - INFO - rslc = './raw/rslc.zarr'
2024-08-14 17:08:58 - log_args - INFO - adi = './ps/adi.zarr'
2024-08-14 17:08:58 - log_args - INFO - chunks = None
2024-08-14 17:08:58 - log_args - INFO - out_chunks = None
2024-08-14 17:08:58 - log_args - INFO - cuda = True
2024-08-14 17:08:58 - log_args - INFO - processes = None
2024-08-14 17:08:58 - log_args - INFO - n_workers = None
2024-08-14 17:08:58 - log_args - INFO - threads_per_worker = None
2024-08-14 17:08:58 - log_args - INFO - rmm_pool_size = 0.9
2024-08-14 17:08:58 - log_args - INFO - dask_cluster_arg = {}
2024-08-14 17:08:58 - log_args - INFO - fetching args done.
2024-08-14 17:08:58 - zarr_info - INFO - ./raw/rslc.zarr zarray shape, chunks, dtype: (2500, 1834, 17), (1000, 1000, 1), complex64
2024-08-14 17:08:58 - amp_disp - INFO - starting dask local cluster.
2024-08-14 17:09:04 - amp_disp - INFO - dask local cluster started.
2024-08-14 17:09:04 - dask_cluster_info - INFO - dask cluster: LocalCUDACluster(dashboard_link='http://127.0.0.1:8787/status', workers=8, threads=8, memory=1.46 TiB)
2024-08-14 17:09:04 - darr_info - INFO - rslc dask array shape, chunksize, dtype: (2500, 1834, 17), (1000, 1000, 17), complex64
2024-08-14 17:09:04 - amp_disp - INFO - calculate amplitude dispersion index.
2024-08-14 17:09:05 - amp_disp - INFO - got amplitude dispersion index.
2024-08-14 17:09:05 - darr_info - INFO - adi dask array shape, chunksize, dtype: (2500, 1834), (1000, 1000), float32
2024-08-14 17:09:05 - darr_info - INFO - adi dask array shape, chunksize, dtype: (2500, 1834), (1000, 1000), float32
2024-08-14 17:09:05 - amp_disp - INFO - saving adi.
2024-08-14 17:09:05 - zarr_info - INFO - ./ps/adi.zarr zarray shape, chunks, dtype: (2500, 1834), (1000, 1000), float32
2024-08-14 17:09:05 - amp_disp - INFO - computing graph setted. doing all the computing.
2024-08-14 17:09:07 - amp_disp - INFO - computing finished. |  1.3s
2024-08-14 17:09:09 - amp_disp - INFO - dask cluster closed.
adi = zarr.open('./ps/adi.zarr/','r')[:]
fig, ax = plt.subplots(1,1,figsize=(10,10))
pcm = ax.imshow(adi,vmin=0,vmax=1)
ax.set(title='Amplitude Dispersion Index',xlabel='Range Index',ylabel='Azimuth Index')
fig.colorbar(pcm)
fig.show()

We can then select PS candidate according to adi:

ps_can_gix = './ps/ps_can_gix.zarr'
mc.pc_logic_ras('./ps/adi.zarr/',ps_can_gix,'(ras>=0)&(ras<=0.3)')
mc.ras2pc(
    ps_can_gix, 
    ['raw/rslc.zarr', 'ps/adi.zarr',  'transform/e.zarr', 'transform/n.zarr'],
    ['ps/ps_can_rslc.zarr', 'ps/ps_can_adi.zarr',  'ps/ps_can_e.zarr', 'ps/ps_can_n.zarr'],
)
2024-08-14 17:09:09 - log_args - INFO - running function: pc_logic_ras
2024-08-14 17:09:09 - log_args - INFO - fetching args:
2024-08-14 17:09:09 - log_args - INFO - ras = './ps/adi.zarr/'
2024-08-14 17:09:09 - log_args - INFO - gix = './ps/ps_can_gix.zarr'
2024-08-14 17:09:09 - log_args - INFO - operation = '(ras>=0)&(ras<=0.3)'
2024-08-14 17:09:09 - log_args - INFO - chunks = 100000
2024-08-14 17:09:09 - log_args - INFO - fetching args done.
2024-08-14 17:09:09 - zarr_info - INFO - ./ps/adi.zarr/ zarray shape, chunks, dtype: (2500, 1834), (1000, 1000), float32
2024-08-14 17:09:09 - pc_logic_ras - INFO - loading ras into memory.
2024-08-14 17:09:09 - pc_logic_ras - INFO - select pc based on operation: (ras>=0)&(ras<=0.3)
2024-08-14 17:09:09 - pc_logic_ras - INFO - number of selected pixels: 43201.
2024-08-14 17:09:09 - zarr_info - INFO - ./ps/ps_can_gix.zarr zarray shape, chunks, dtype: (43201, 2), (100000, 1), int32
2024-08-14 17:09:09 - pc_logic_ras - INFO - writing gix.
2024-08-14 17:09:09 - pc_logic_ras - INFO - write done.
2024-08-14 17:09:09 - log_args - INFO - running function: ras2pc
2024-08-14 17:09:09 - log_args - INFO - fetching args:
2024-08-14 17:09:09 - log_args - INFO - idx = './ps/ps_can_gix.zarr'
2024-08-14 17:09:09 - log_args - INFO - ras = ['raw/rslc.zarr', 'ps/adi.zarr', 'transform/e.zarr', 'transform/n.zarr']
2024-08-14 17:09:09 - log_args - INFO - pc = ['ps/ps_can_rslc.zarr', 'ps/ps_can_adi.zarr', 'ps/ps_can_e.zarr', 'ps/ps_can_n.zarr']
2024-08-14 17:09:09 - log_args - INFO - chunks = None
2024-08-14 17:09:09 - log_args - INFO - processes = False
2024-08-14 17:09:09 - log_args - INFO - n_workers = 1
2024-08-14 17:09:10 - log_args - INFO - threads_per_worker = 1
2024-08-14 17:09:10 - log_args - INFO - dask_cluster_arg = {}
2024-08-14 17:09:10 - log_args - INFO - fetching args done.
2024-08-14 17:09:10 - zarr_info - INFO - ./ps/ps_can_gix.zarr zarray shape, chunks, dtype: (43201, 2), (100000, 1), int32
2024-08-14 17:09:10 - ras2pc - INFO - loading gix into memory.
2024-08-14 17:09:10 - ras2pc - INFO - starting dask local cluster.
2024-08-14 17:09:10 - ras2pc - INFO - dask local cluster started.
2024-08-14 17:09:10 - dask_cluster_info - INFO - dask cluster: LocalCluster(dashboard_link='http://10.211.48.16:8787/status', workers=1, threads=1, memory=1.46 TiB)
2024-08-14 17:09:10 - ras2pc - INFO - start to slice on raw/rslc.zarr
2024-08-14 17:09:10 - zarr_info - INFO - raw/rslc.zarr zarray shape, chunks, dtype: (2500, 1834, 17), (1000, 1000, 1), complex64
2024-08-14 17:09:10 - darr_info - INFO - ras dask array shape, chunksize, dtype: (2500, 1834, 17), (2500, 1834, 1), complex64
2024-08-14 17:09:10 - darr_info - INFO - pc dask array shape, chunksize, dtype: (43201, 17), (43201, 1), complex64
2024-08-14 17:09:10 - ras2pc - INFO - saving to ps/ps_can_rslc.zarr.
2024-08-14 17:09:10 - zarr_info - INFO - ps/ps_can_rslc.zarr zarray shape, chunks, dtype: (43201, 17), (100000, 1), complex64
2024-08-14 17:09:10 - ras2pc - INFO - start to slice on ps/adi.zarr
2024-08-14 17:09:10 - zarr_info - INFO - ps/adi.zarr zarray shape, chunks, dtype: (2500, 1834), (1000, 1000), float32
2024-08-14 17:09:10 - darr_info - INFO - ras dask array shape, chunksize, dtype: (2500, 1834), (2500, 1834), float32
2024-08-14 17:09:10 - darr_info - INFO - pc dask array shape, chunksize, dtype: (43201,), (43201,), float32
2024-08-14 17:09:10 - ras2pc - INFO - saving to ps/ps_can_adi.zarr.
2024-08-14 17:09:10 - zarr_info - INFO - ps/ps_can_adi.zarr zarray shape, chunks, dtype: (43201,), (100000,), float32
2024-08-14 17:09:10 - ras2pc - INFO - start to slice on transform/e.zarr
2024-08-14 17:09:10 - zarr_info - INFO - transform/e.zarr zarray shape, chunks, dtype: (2500, 1834), (1000, 1000), float64
2024-08-14 17:09:10 - darr_info - INFO - ras dask array shape, chunksize, dtype: (2500, 1834), (2500, 1834), float64
2024-08-14 17:09:10 - darr_info - INFO - pc dask array shape, chunksize, dtype: (43201,), (43201,), float64
2024-08-14 17:09:10 - ras2pc - INFO - saving to ps/ps_can_e.zarr.
2024-08-14 17:09:10 - zarr_info - INFO - ps/ps_can_e.zarr zarray shape, chunks, dtype: (43201,), (100000,), float64
2024-08-14 17:09:10 - ras2pc - INFO - start to slice on transform/n.zarr
2024-08-14 17:09:10 - zarr_info - INFO - transform/n.zarr zarray shape, chunks, dtype: (2500, 1834), (1000, 1000), float64
2024-08-14 17:09:10 - darr_info - INFO - ras dask array shape, chunksize, dtype: (2500, 1834), (2500, 1834), float64
2024-08-14 17:09:10 - darr_info - INFO - pc dask array shape, chunksize, dtype: (43201,), (43201,), float64
2024-08-14 17:09:10 - ras2pc - INFO - saving to ps/ps_can_n.zarr.
2024-08-14 17:09:10 - zarr_info - INFO - ps/ps_can_n.zarr zarray shape, chunks, dtype: (43201,), (100000,), float64
2024-08-14 17:09:10 - ras2pc - INFO - computing graph setted. doing all the computing.
2024-08-14 17:09:11 - ras2pc - INFO - computing finished.ed |  1.0s
2024-08-14 17:09:11 - ras2pc - INFO - dask cluster closed.