pqm

Pixel Quality Metrics
import numpy as np
import zarr
import moraine.cli as mc
from moraine.utils_ import is_cuda_available
if is_cuda_available():
    import cupy as cp
from matplotlib import pyplot as plt

source

temp_coh

 temp_coh (intf:str, rslc:str, t_coh:str=None,
           image_pairs:numpy.ndarray=None, chunks:int|tuple[int,int]=None,
           cuda:bool=False, processes=None, n_workers=None,
           threads_per_worker=None, rmm_pool_size=0.9, **dask_cluster_arg)

temporal coherence.

Type Default Details
intf str complex interferograms/coherence metrix, dtype complex64, shape 2D(pc) or 3D(ras)
rslc str complex rslc/phase history, dtype complex64, shape 2D(pc) or 3D(ras)
t_coh str None output, temporal coherence
image_pairs ndarray None image pairs
chunks int | tuple[int, int] None ras/pc chunk size, same as intf 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 VAR_KEYWORD

CLI version of temp_coh.

logger = mc.get_logger()
ds_can_coh = './co/ds_can_coh.zarr'
ds_can_ph = './pl/ds_can_ph.zarr'
ds_can_t_coh = './pqm/ds_can_t_coh.zarr'
temp_coh(ds_can_coh,ds_can_ph, ds_can_t_coh)
2025-09-20 23:15:04 - log_args - INFO - running function: temp_coh
2025-09-20 23:15:04 - log_args - INFO - fetching args:
2025-09-20 23:15:04 - log_args - INFO - intf = './co/ds_can_coh.zarr'
2025-09-20 23:15:04 - log_args - INFO - rslc = './pl/ds_can_ph.zarr'
2025-09-20 23:15:04 - log_args - INFO - t_coh = './pqm/ds_can_t_coh.zarr'
2025-09-20 23:15:04 - log_args - INFO - image_pairs = None
2025-09-20 23:15:04 - log_args - INFO - chunks = None
2025-09-20 23:15:04 - log_args - INFO - cuda = False
2025-09-20 23:15:04 - log_args - INFO - processes = None
2025-09-20 23:15:04 - log_args - INFO - n_workers = None
2025-09-20 23:15:04 - log_args - INFO - threads_per_worker = None
2025-09-20 23:15:04 - log_args - INFO - rmm_pool_size = 0.9
2025-09-20 23:15:04 - log_args - INFO - dask_cluster_arg = {}
2025-09-20 23:15:04 - log_args - INFO - fetching args done.
2025-09-20 23:15:04 - zarr_info - INFO - ./co/ds_can_coh.zarr zarray shape, chunks, dtype: (732727, 136), (100000, 1), complex64
2025-09-20 23:15:04 - zarr_info - INFO - ./pl/ds_can_ph.zarr zarray shape, chunks, dtype: (732727, 17), (100000, 1), complex64
2025-09-20 23:15:04 - temp_coh - INFO - starting dask local cluster.
2025-09-20 23:15:06 - temp_coh - INFO - dask local cluster started.
2025-09-20 23:15:06 - dask_cluster_info - INFO - dask cluster: LocalCluster(dashboard_link='http://10.211.48.10:8787/status', workers=1, threads=1, memory=1.95 TiB)
2025-09-20 23:15:06 - darr_info - INFO - intf dask array shape, chunksize, dtype: (732727, 136), (100000, 136), complex64
2025-09-20 23:15:06 - darr_info - INFO - rslc dask array shape, chunksize, dtype: (732727, 17), (100000, 17), complex64
2025-09-20 23:15:06 - temp_coh - INFO - Estimate temporal coherence for DS.
2025-09-20 23:15:06 - temp_coh - INFO - got temporal coherence t_coh.
2025-09-20 23:15:06 - darr_info - INFO - t_coh dask array shape, chunksize, dtype: (732727,), (100000,), float32
2025-09-20 23:15:06 - temp_coh - INFO - saving t_coh.
2025-09-20 23:15:06 - temp_coh - INFO - computing graph setted. doing all the computing.
2025-09-20 23:15:08 - temp_coh - INFO - computing finished. |  2.6s
2025-09-20 23:15:08 - temp_coh - INFO - dask cluster closed.
if is_cuda_available():
    temp_coh(ds_can_coh,ds_can_ph, ds_can_t_coh,cuda=True)
2025-09-20 23:15:08 - log_args - INFO - running function: temp_coh
2025-09-20 23:15:08 - log_args - INFO - fetching args:
2025-09-20 23:15:08 - log_args - INFO - intf = './co/ds_can_coh.zarr'
2025-09-20 23:15:08 - log_args - INFO - rslc = './pl/ds_can_ph.zarr'
2025-09-20 23:15:08 - log_args - INFO - t_coh = './pqm/ds_can_t_coh.zarr'
2025-09-20 23:15:08 - log_args - INFO - image_pairs = None
2025-09-20 23:15:08 - log_args - INFO - chunks = None
2025-09-20 23:15:08 - log_args - INFO - cuda = True
2025-09-20 23:15:08 - log_args - INFO - processes = None
2025-09-20 23:15:08 - log_args - INFO - n_workers = None
2025-09-20 23:15:08 - log_args - INFO - threads_per_worker = None
2025-09-20 23:15:08 - log_args - INFO - rmm_pool_size = 0.9
2025-09-20 23:15:08 - log_args - INFO - dask_cluster_arg = {}
2025-09-20 23:15:08 - log_args - INFO - fetching args done.
2025-09-20 23:15:08 - zarr_info - INFO - ./co/ds_can_coh.zarr zarray shape, chunks, dtype: (732727, 136), (100000, 1), complex64
2025-09-20 23:15:08 - zarr_info - INFO - ./pl/ds_can_ph.zarr zarray shape, chunks, dtype: (732727, 17), (100000, 1), complex64
2025-09-20 23:15:08 - temp_coh - INFO - starting dask local cluster.
2025-09-20 23:15:15 - temp_coh - INFO - dask local cluster started.
2025-09-20 23:15:15 - dask_cluster_info - INFO - dask cluster: LocalCUDACluster(dashboard_link='http://127.0.0.1:8787/status', workers=8, threads=8, memory=1.95 TiB)
2025-09-20 23:15:15 - darr_info - INFO - intf dask array shape, chunksize, dtype: (732727, 136), (100000, 136), complex64
2025-09-20 23:15:15 - darr_info - INFO - rslc dask array shape, chunksize, dtype: (732727, 17), (100000, 17), complex64
2025-09-20 23:15:15 - temp_coh - INFO - Estimate temporal coherence for DS.
2025-09-20 23:15:15 - temp_coh - INFO - got temporal coherence t_coh.
2025-09-20 23:15:15 - darr_info - INFO - t_coh dask array shape, chunksize, dtype: (732727,), (100000,), float32
2025-09-20 23:15:15 - temp_coh - INFO - saving t_coh.
2025-09-20 23:15:15 - temp_coh - INFO - computing graph setted. doing all the computing.
2025-09-20 23:15:16 - temp_coh - INFO - computing finished. |  1.2s
2025-09-20 23:15:18 - temp_coh - INFO - dask cluster closed.
ds_can_gix = './shp/ds_can_gix.zarr'
t_coh = './pqm/t_coh.zarr'
rslc_zarr = zarr.open('./raw/rslc.zarr/',mode='r')
mc.pc2ras(ds_can_gix, ds_can_t_coh,t_coh,rslc_zarr.shape[:2])
2025-09-20 23:15:18 - log_args - INFO - running function: pc2ras
2025-09-20 23:15:18 - log_args - INFO - fetching args:
2025-09-20 23:15:18 - log_args - INFO - idx = './shp/ds_can_gix.zarr'
2025-09-20 23:15:18 - log_args - INFO - pc = './pqm/ds_can_t_coh.zarr'
2025-09-20 23:15:18 - log_args - INFO - ras = './pqm/t_coh.zarr'
2025-09-20 23:15:18 - log_args - INFO - shape = (2500, 1834)
2025-09-20 23:15:18 - log_args - INFO - chunks = (1000, 1000)
2025-09-20 23:15:18 - log_args - INFO - processes = False
2025-09-20 23:15:18 - log_args - INFO - n_workers = 1
2025-09-20 23:15:18 - log_args - INFO - threads_per_worker = 1
2025-09-20 23:15:18 - log_args - INFO - dask_cluster_arg = {}
2025-09-20 23:15:18 - log_args - INFO - fetching args done.
2025-09-20 23:15:18 - zarr_info - INFO - ./shp/ds_can_gix.zarr zarray shape, chunks, dtype: (732727, 2), (100000, 1), int32
2025-09-20 23:15:18 - pc2ras - INFO - loading gix into memory.
2025-09-20 23:15:18 - pc2ras - INFO - starting dask local cluster.
2025-09-20 23:15:18 - pc2ras - INFO - dask local cluster started.
2025-09-20 23:15:18 - dask_cluster_info - INFO - dask cluster: LocalCluster(dashboard_link='http://10.211.48.10:8787/status', workers=1, threads=1, memory=1.95 TiB)
2025-09-20 23:15:18 - pc2ras - INFO - start to work on ./pqm/ds_can_t_coh.zarr
2025-09-20 23:15:18 - zarr_info - INFO - ./pqm/ds_can_t_coh.zarr zarray shape, chunks, dtype: (732727,), (100000,), float32
2025-09-20 23:15:18 - darr_info - INFO - pc dask array shape, chunksize, dtype: (732727,), (732727,), float32
2025-09-20 23:15:18 - pc2ras - INFO - create ras dask array
2025-09-20 23:15:18 - darr_info - INFO - ras dask array shape, chunksize, dtype: (2500, 1834), (2500, 1834), float32
2025-09-20 23:15:18 - pc2ras - INFO - save ras to ./pqm/t_coh.zarr
2025-09-20 23:15:18 - zarr_info - INFO - ./pqm/t_coh.zarr zarray shape, chunks, dtype: (2500, 1834), (1000, 1000), float32
2025-09-20 23:15:18 - pc2ras - INFO - computing graph setted. doing all the computing.
2025-09-20 23:15:19 - pc2ras - INFO - computing finished.ed |  0.1s
2025-09-20 23:15:19 - pc2ras - INFO - dask cluster closed.
t_coh_zarr = zarr.open(t_coh,mode='r')
fig, ax = plt.subplots(1,1,figsize=(10,10))
pcm = ax.imshow(t_coh_zarr[:],interpolation='nearest',vmin=0.0,vmax=1.0)
ax.set(title='DS temporal coherence',xlabel='Range Index',ylabel='Azimuth Index')
fig.colorbar(pcm)
plt.show()

Or with raster data:

rslc = 'raw/rslc.zarr/'
intf = 'dl/n2f_intf.zarr'
tcoh = 'pqm/n2f_tcoh.zarr'
tnet = mr.TempNet.from_bandwidth(zarr.open(rslc,mode='r').shape[-1],1)
temp_coh(intf,rslc,tcoh,image_pairs=tnet.image_pairs)
2025-09-20 23:15:19 - log_args - INFO - running function: temp_coh
2025-09-20 23:15:19 - log_args - INFO - fetching args:
2025-09-20 23:15:19 - log_args - INFO - intf = 'dl/n2f_intf.zarr'
2025-09-20 23:15:19 - log_args - INFO - rslc = 'raw/rslc.zarr/'
2025-09-20 23:15:19 - log_args - INFO - t_coh = 'pqm/n2f_tcoh.zarr'
2025-09-20 23:15:19 - log_args - INFO - image_pairs = array([[ 0,  1],
       [ 1,  2],
       [ 2,  3],
       [ 3,  4],
       [ 4,  5],
       [ 5,  6],
       [ 6,  7],
       [ 7,  8],
       [ 8,  9],
       [ 9, 10],
       [10, 11],
       [11, 12],
       [12, 13],
       [13, 14],
       [14, 15],
       [15, 16]], dtype=int32)
2025-09-20 23:15:19 - log_args - INFO - chunks = None
2025-09-20 23:15:19 - log_args - INFO - cuda = False
2025-09-20 23:15:19 - log_args - INFO - processes = None
2025-09-20 23:15:19 - log_args - INFO - n_workers = None
2025-09-20 23:15:19 - log_args - INFO - threads_per_worker = None
2025-09-20 23:15:19 - log_args - INFO - rmm_pool_size = 0.9
2025-09-20 23:15:19 - log_args - INFO - dask_cluster_arg = {}
2025-09-20 23:15:19 - log_args - INFO - fetching args done.
2025-09-20 23:15:19 - zarr_info - INFO - dl/n2f_intf.zarr zarray shape, chunks, dtype: (2500, 1834, 16), (1000, 1000, 1), complex64
2025-09-20 23:15:19 - zarr_info - INFO - raw/rslc.zarr/ zarray shape, chunks, dtype: (2500, 1834, 17), (1000, 1000, 1), complex64
2025-09-20 23:15:19 - temp_coh - INFO - starting dask local cluster.
2025-09-20 23:15:19 - temp_coh - INFO - dask local cluster started.
2025-09-20 23:15:19 - dask_cluster_info - INFO - dask cluster: LocalCluster(dashboard_link='http://10.211.48.10:8787/status', workers=1, threads=1, memory=1.95 TiB)
2025-09-20 23:15:19 - darr_info - INFO - intf dask array shape, chunksize, dtype: (2500, 1834, 16), (1000, 1000, 16), complex64
2025-09-20 23:15:19 - darr_info - INFO - rslc dask array shape, chunksize, dtype: (2500, 1834, 17), (1000, 1000, 17), complex64
2025-09-20 23:15:19 - temp_coh - INFO - Estimate temporal coherence for DS.
2025-09-20 23:15:19 - temp_coh - INFO - got temporal coherence t_coh.
2025-09-20 23:15:19 - darr_info - INFO - t_coh dask array shape, chunksize, dtype: (2500, 1834), (1000, 1000), float32
2025-09-20 23:15:19 - temp_coh - INFO - saving t_coh.
2025-09-20 23:15:19 - temp_coh - INFO - computing graph setted. doing all the computing.
2025-09-20 23:15:20 - temp_coh - INFO - computing finished. |  1.1s
2025-09-20 23:15:20 - temp_coh - INFO - dask cluster closed.

or with gpu:

if is_cuda_available():
    temp_coh(intf,rslc,tcoh,image_pairs=tnet.image_pairs,cuda=True)
2025-09-20 23:15:20 - log_args - INFO - running function: temp_coh
2025-09-20 23:15:20 - log_args - INFO - fetching args:
2025-09-20 23:15:20 - log_args - INFO - intf = 'dl/n2f_intf.zarr'
2025-09-20 23:15:20 - log_args - INFO - rslc = 'raw/rslc.zarr/'
2025-09-20 23:15:20 - log_args - INFO - t_coh = 'pqm/n2f_tcoh.zarr'
2025-09-20 23:15:20 - log_args - INFO - image_pairs = array([[ 0,  1],
       [ 1,  2],
       [ 2,  3],
       [ 3,  4],
       [ 4,  5],
       [ 5,  6],
       [ 6,  7],
       [ 7,  8],
       [ 8,  9],
       [ 9, 10],
       [10, 11],
       [11, 12],
       [12, 13],
       [13, 14],
       [14, 15],
       [15, 16]], dtype=int32)
2025-09-20 23:15:20 - log_args - INFO - chunks = None
2025-09-20 23:15:20 - log_args - INFO - cuda = True
2025-09-20 23:15:20 - log_args - INFO - processes = None
2025-09-20 23:15:20 - log_args - INFO - n_workers = None
2025-09-20 23:15:20 - log_args - INFO - threads_per_worker = None
2025-09-20 23:15:20 - log_args - INFO - rmm_pool_size = 0.9
2025-09-20 23:15:20 - log_args - INFO - dask_cluster_arg = {}
2025-09-20 23:15:20 - log_args - INFO - fetching args done.
2025-09-20 23:15:20 - zarr_info - INFO - dl/n2f_intf.zarr zarray shape, chunks, dtype: (2500, 1834, 16), (1000, 1000, 1), complex64
2025-09-20 23:15:20 - zarr_info - INFO - raw/rslc.zarr/ zarray shape, chunks, dtype: (2500, 1834, 17), (1000, 1000, 1), complex64
2025-09-20 23:15:20 - temp_coh - INFO - starting dask local cluster.
2025-09-20 23:15:27 - temp_coh - INFO - dask local cluster started.
2025-09-20 23:15:27 - dask_cluster_info - INFO - dask cluster: LocalCUDACluster(dashboard_link='http://127.0.0.1:8787/status', workers=8, threads=8, memory=1.95 TiB)
2025-09-20 23:15:27 - darr_info - INFO - intf dask array shape, chunksize, dtype: (2500, 1834, 16), (1000, 1000, 16), complex64
2025-09-20 23:15:27 - darr_info - INFO - rslc dask array shape, chunksize, dtype: (2500, 1834, 17), (1000, 1000, 17), complex64
2025-09-20 23:15:27 - temp_coh - INFO - Estimate temporal coherence for DS.
2025-09-20 23:15:27 - temp_coh - INFO - got temporal coherence t_coh.
2025-09-20 23:15:27 - darr_info - INFO - t_coh dask array shape, chunksize, dtype: (2500, 1834), (1000, 1000), float32
2025-09-20 23:15:27 - temp_coh - INFO - saving t_coh.
2025-09-20 23:15:27 - temp_coh - INFO - computing graph setted. doing all the computing.
2025-09-20 23:15:28 - temp_coh - INFO - computing finished. |  1.3s
2025-09-20 23:15:30 - temp_coh - INFO - dask cluster closed.
fig, ax = plt.subplots(1,1,figsize=(10,10))
pcm = ax.imshow(zarr.open(tcoh,mode='r')[:],interpolation='nearest',vmin=0.0,vmax=1.0)
ax.set(title='Noise2Fringe Temporal Coherence',xlabel='Range Index',ylabel='Azimuth Index')
fig.colorbar(pcm)
fig.show()