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, tnet:str=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
tnet str None temporal network, full network by default
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)
2024-11-25 16:59:28 - log_args - INFO - running function: temp_coh
2024-11-25 16:59:28 - log_args - INFO - fetching args:
2024-11-25 16:59:28 - log_args - INFO - intf = './co/ds_can_coh.zarr'
2024-11-25 16:59:28 - log_args - INFO - rslc = './pl/ds_can_ph.zarr'
2024-11-25 16:59:28 - log_args - INFO - t_coh = './pqm/ds_can_t_coh.zarr'
2024-11-25 16:59:28 - log_args - INFO - tnet = None
2024-11-25 16:59:28 - log_args - INFO - chunks = None
2024-11-25 16:59:28 - log_args - INFO - cuda = False
2024-11-25 16:59:28 - log_args - INFO - processes = None
2024-11-25 16:59:28 - log_args - INFO - n_workers = None
2024-11-25 16:59:28 - log_args - INFO - threads_per_worker = None
2024-11-25 16:59:28 - log_args - INFO - rmm_pool_size = 0.9
2024-11-25 16:59:28 - log_args - INFO - dask_cluster_arg = {}
2024-11-25 16:59:28 - log_args - INFO - fetching args done.
2024-11-25 16:59:28 - zarr_info - INFO - ./co/ds_can_coh.zarr zarray shape, chunks, dtype: (732727, 136), (100000, 1), complex64
2024-11-25 16:59:28 - zarr_info - INFO - ./pl/ds_can_ph.zarr zarray shape, chunks, dtype: (732727, 17), (100000, 1), complex64
2024-11-25 16:59:28 - temp_coh - INFO - starting dask local cluster.
2024-11-25 16:59:29 - temp_coh - INFO - dask local cluster started.
2024-11-25 16:59:29 - dask_cluster_info - INFO - dask cluster: LocalCluster(dashboard_link='http://10.211.48.22:8787/status', workers=1, threads=1, memory=150.00 GiB)
2024-11-25 16:59:29 - darr_info - INFO - intf dask array shape, chunksize, dtype: (732727, 136), (100000, 136), complex64
2024-11-25 16:59:29 - darr_info - INFO - rslc dask array shape, chunksize, dtype: (732727, 17), (100000, 17), complex64
2024-11-25 16:59:29 - temp_coh - INFO - Estimate temporal coherence for DS.
2024-11-25 16:59:29 - temp_coh - INFO - got temporal coherence t_coh.
2024-11-25 16:59:29 - darr_info - INFO - t_coh dask array shape, chunksize, dtype: (732727,), (100000,), float32
2024-11-25 16:59:29 - temp_coh - INFO - saving t_coh.
2024-11-25 16:59:29 - temp_coh - INFO - computing graph setted. doing all the computing.
2024-11-25 16:59:32 - temp_coh - INFO - computing finished. |  3.5s
2024-11-25 16:59:32 - temp_coh - INFO - dask cluster closed.
if is_cuda_available():
    temp_coh(ds_can_coh,ds_can_ph, ds_can_t_coh,cuda=True)
2024-11-25 16:59:32 - log_args - INFO - running function: temp_coh
2024-11-25 16:59:32 - log_args - INFO - fetching args:
2024-11-25 16:59:32 - log_args - INFO - intf = './co/ds_can_coh.zarr'
2024-11-25 16:59:32 - log_args - INFO - rslc = './pl/ds_can_ph.zarr'
2024-11-25 16:59:32 - log_args - INFO - t_coh = './pqm/ds_can_t_coh.zarr'
2024-11-25 16:59:32 - log_args - INFO - tnet = None
2024-11-25 16:59:32 - log_args - INFO - chunks = None
2024-11-25 16:59:32 - log_args - INFO - cuda = True
2024-11-25 16:59:32 - log_args - INFO - processes = None
2024-11-25 16:59:32 - log_args - INFO - n_workers = None
2024-11-25 16:59:32 - log_args - INFO - threads_per_worker = None
2024-11-25 16:59:32 - log_args - INFO - rmm_pool_size = 0.9
2024-11-25 16:59:32 - log_args - INFO - dask_cluster_arg = {}
2024-11-25 16:59:32 - log_args - INFO - fetching args done.
2024-11-25 16:59:32 - zarr_info - INFO - ./co/ds_can_coh.zarr zarray shape, chunks, dtype: (732727, 136), (100000, 1), complex64
2024-11-25 16:59:32 - zarr_info - INFO - ./pl/ds_can_ph.zarr zarray shape, chunks, dtype: (732727, 17), (100000, 1), complex64
2024-11-25 16:59:32 - temp_coh - INFO - starting dask local cluster.
2024-11-25 16:59:38 - temp_coh - INFO - dask local cluster started.
2024-11-25 16:59:38 - dask_cluster_info - INFO - dask cluster: LocalCUDACluster(dashboard_link='http://127.0.0.1:8787/status', workers=8, threads=8, memory=150.00 GiB)
2024-11-25 16:59:38 - darr_info - INFO - intf dask array shape, chunksize, dtype: (732727, 136), (100000, 136), complex64
2024-11-25 16:59:38 - darr_info - INFO - rslc dask array shape, chunksize, dtype: (732727, 17), (100000, 17), complex64
2024-11-25 16:59:38 - temp_coh - INFO - Estimate temporal coherence for DS.
2024-11-25 16:59:39 - temp_coh - INFO - got temporal coherence t_coh.
2024-11-25 16:59:39 - darr_info - INFO - t_coh dask array shape, chunksize, dtype: (732727,), (100000,), float32
2024-11-25 16:59:39 - temp_coh - INFO - saving t_coh.
2024-11-25 16:59:39 - temp_coh - INFO - computing graph setted. doing all the computing.
2024-11-25 16:59:40 - temp_coh - INFO - computing finished. |  1.5s
2024-11-25 16:59:43 - 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/','r')
mc.pc2ras(ds_can_gix, ds_can_t_coh,t_coh,rslc_zarr.shape[:2])
2024-11-25 16:59:43 - log_args - INFO - running function: pc2ras
2024-11-25 16:59:43 - log_args - INFO - fetching args:
2024-11-25 16:59:43 - log_args - INFO - idx = './shp/ds_can_gix.zarr'
2024-11-25 16:59:43 - log_args - INFO - pc = './pqm/ds_can_t_coh.zarr'
2024-11-25 16:59:43 - log_args - INFO - ras = './pqm/t_coh.zarr'
2024-11-25 16:59:43 - log_args - INFO - shape = (2500, 1834)
2024-11-25 16:59:43 - log_args - INFO - chunks = (1000, 1000)
2024-11-25 16:59:43 - log_args - INFO - processes = False
2024-11-25 16:59:43 - log_args - INFO - n_workers = 1
2024-11-25 16:59:43 - log_args - INFO - threads_per_worker = 1
2024-11-25 16:59:43 - log_args - INFO - dask_cluster_arg = {}
2024-11-25 16:59:43 - log_args - INFO - fetching args done.
2024-11-25 16:59:43 - zarr_info - INFO - ./shp/ds_can_gix.zarr zarray shape, chunks, dtype: (732727, 2), (100000, 1), int32
2024-11-25 16:59:43 - pc2ras - INFO - loading gix into memory.
2024-11-25 16:59:43 - pc2ras - INFO - starting dask local cluster.
2024-11-25 16:59:43 - pc2ras - INFO - dask local cluster started.
2024-11-25 16:59:43 - dask_cluster_info - INFO - dask cluster: LocalCluster(dashboard_link='http://10.211.48.22:8787/status', workers=1, threads=1, memory=150.00 GiB)
2024-11-25 16:59:43 - pc2ras - INFO - start to work on ./pqm/ds_can_t_coh.zarr
2024-11-25 16:59:43 - zarr_info - INFO - ./pqm/ds_can_t_coh.zarr zarray shape, chunks, dtype: (732727,), (100000,), float32
2024-11-25 16:59:43 - darr_info - INFO - pc dask array shape, chunksize, dtype: (732727,), (732727,), float32
2024-11-25 16:59:43 - pc2ras - INFO - create ras dask array
2024-11-25 16:59:43 - darr_info - INFO - ras dask array shape, chunksize, dtype: (2500, 1834), (2500, 1834), float32
2024-11-25 16:59:43 - pc2ras - INFO - save ras to ./pqm/t_coh.zarr
2024-11-25 16:59:43 - zarr_info - INFO - ./pqm/t_coh.zarr zarray shape, chunks, dtype: (2500, 1834), (1000, 1000), float32
2024-11-25 16:59:43 - pc2ras - INFO - computing graph setted. doing all the computing.
2024-11-25 16:59:44 - pc2ras - INFO - computing finished.ed |  0.1s
2024-11-25 16:59:44 - pc2ras - INFO - dask cluster closed.
t_coh_zarr = zarr.open(t_coh,'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,'r').shape[-1],1)
tnet.save('pqm/tnet.zarr')
temp_coh(intf,rslc,tcoh,tnet='pqm/tnet.zarr')
2024-11-25 16:59:44 - log_args - INFO - running function: temp_coh
2024-11-25 16:59:44 - log_args - INFO - fetching args:
2024-11-25 16:59:44 - log_args - INFO - intf = 'dl/n2f_intf.zarr'
2024-11-25 16:59:44 - log_args - INFO - rslc = 'raw/rslc.zarr/'
2024-11-25 16:59:44 - log_args - INFO - t_coh = 'pqm/n2f_tcoh.zarr'
2024-11-25 16:59:44 - log_args - INFO - tnet = 'pqm/tnet.zarr'
2024-11-25 16:59:44 - log_args - INFO - chunks = None
2024-11-25 16:59:44 - log_args - INFO - cuda = False
2024-11-25 16:59:44 - log_args - INFO - processes = None
2024-11-25 16:59:44 - log_args - INFO - n_workers = None
2024-11-25 16:59:44 - log_args - INFO - threads_per_worker = None
2024-11-25 16:59:44 - log_args - INFO - rmm_pool_size = 0.9
2024-11-25 16:59:44 - log_args - INFO - dask_cluster_arg = {}
2024-11-25 16:59:44 - log_args - INFO - fetching args done.
2024-11-25 16:59:44 - zarr_info - INFO - dl/n2f_intf.zarr zarray shape, chunks, dtype: (2500, 1834, 16), (1000, 1000, 1), complex64
2024-11-25 16:59:44 - zarr_info - INFO - raw/rslc.zarr/ zarray shape, chunks, dtype: (2500, 1834, 17), (1000, 1000, 1), complex64
2024-11-25 16:59:44 - temp_coh - INFO - starting dask local cluster.
2024-11-25 16:59:44 - temp_coh - INFO - dask local cluster started.
2024-11-25 16:59:44 - dask_cluster_info - INFO - dask cluster: LocalCluster(dashboard_link='http://10.211.48.22:8787/status', workers=1, threads=1, memory=150.00 GiB)
2024-11-25 16:59:44 - darr_info - INFO - intf dask array shape, chunksize, dtype: (2500, 1834, 16), (1000, 1000, 16), complex64
2024-11-25 16:59:44 - darr_info - INFO - rslc dask array shape, chunksize, dtype: (2500, 1834, 17), (1000, 1000, 17), complex64
2024-11-25 16:59:44 - temp_coh - INFO - Estimate temporal coherence for DS.
2024-11-25 16:59:44 - temp_coh - INFO - got temporal coherence t_coh.
2024-11-25 16:59:44 - darr_info - INFO - t_coh dask array shape, chunksize, dtype: (2500, 1834), (1000, 1000), float32
2024-11-25 16:59:44 - temp_coh - INFO - saving t_coh.
2024-11-25 16:59:44 - temp_coh - INFO - computing graph setted. doing all the computing.
2024-11-25 16:59:46 - temp_coh - INFO - computing finished. |  1.2s
2024-11-25 16:59:46 - temp_coh - INFO - dask cluster closed.

or with gpu:

if is_cuda_available():
    temp_coh(intf,rslc,tcoh,tnet='pqm/tnet.zarr',cuda=True)
2024-11-25 16:59:46 - log_args - INFO - running function: temp_coh
2024-11-25 16:59:46 - log_args - INFO - fetching args:
2024-11-25 16:59:46 - log_args - INFO - intf = 'dl/n2f_intf.zarr'
2024-11-25 16:59:46 - log_args - INFO - rslc = 'raw/rslc.zarr/'
2024-11-25 16:59:46 - log_args - INFO - t_coh = 'pqm/n2f_tcoh.zarr'
2024-11-25 16:59:46 - log_args - INFO - tnet = 'pqm/tnet.zarr'
2024-11-25 16:59:46 - log_args - INFO - chunks = None
2024-11-25 16:59:46 - log_args - INFO - cuda = True
2024-11-25 16:59:46 - log_args - INFO - processes = None
2024-11-25 16:59:46 - log_args - INFO - n_workers = None
2024-11-25 16:59:46 - log_args - INFO - threads_per_worker = None
2024-11-25 16:59:46 - log_args - INFO - rmm_pool_size = 0.9
2024-11-25 16:59:46 - log_args - INFO - dask_cluster_arg = {}
2024-11-25 16:59:46 - log_args - INFO - fetching args done.
2024-11-25 16:59:46 - zarr_info - INFO - dl/n2f_intf.zarr zarray shape, chunks, dtype: (2500, 1834, 16), (1000, 1000, 1), complex64
2024-11-25 16:59:46 - zarr_info - INFO - raw/rslc.zarr/ zarray shape, chunks, dtype: (2500, 1834, 17), (1000, 1000, 1), complex64
2024-11-25 16:59:46 - temp_coh - INFO - starting dask local cluster.
2024-11-25 16:59:52 - temp_coh - INFO - dask local cluster started.
2024-11-25 16:59:52 - dask_cluster_info - INFO - dask cluster: LocalCUDACluster(dashboard_link='http://127.0.0.1:8787/status', workers=8, threads=8, memory=150.00 GiB)
2024-11-25 16:59:52 - darr_info - INFO - intf dask array shape, chunksize, dtype: (2500, 1834, 16), (1000, 1000, 16), complex64
2024-11-25 16:59:52 - darr_info - INFO - rslc dask array shape, chunksize, dtype: (2500, 1834, 17), (1000, 1000, 17), complex64
2024-11-25 16:59:52 - temp_coh - INFO - Estimate temporal coherence for DS.
2024-11-25 16:59:52 - temp_coh - INFO - got temporal coherence t_coh.
2024-11-25 16:59:52 - darr_info - INFO - t_coh dask array shape, chunksize, dtype: (2500, 1834), (1000, 1000), float32
2024-11-25 16:59:52 - temp_coh - INFO - saving t_coh.
2024-11-25 16:59:52 - temp_coh - INFO - computing graph setted. doing all the computing.
2024-11-25 16:59:54 - temp_coh - INFO - computing finished. |  1.6s
2024-11-25 16:59:56 - temp_coh - INFO - dask cluster closed.
fig, ax = plt.subplots(1,1,figsize=(10,10))
pcm = ax.imshow(zarr.open(tcoh,'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()