import numpy as np
import zarr
from matplotlib import pyplot as plt
from moraine.utils_ import is_cuda_available
if is_cuda_available():
import cupy as cp
from cupyx.scipy.ndimage import uniform_filter
import moraine as mr
Adaptive Multilook
In this tutorial, we demostrate how to use Moraine package to identify spatially homogeneous pixels, extimate the coherence matrix and compare the original interferogram, multilook intergerogram and the adaptive multilook interferogram.
Load rslc stack
if is_cuda_available():
print(cp.cuda.Device(1).use())
= cp.asarray(zarr.open('../../data/rslc.zarr','r')[:])
rslc print(rslc.shape)
<CUDA Device 1>
(2500, 1834, 17)
Apply ks test
if is_cuda_available():
= cp.abs(rslc)**2
rmli
= 5
az_half_win = 5
r_half_win = 2*az_half_win+1
az_win = 2*r_half_win+1
r_win
= mr.ks_test(rmli,az_half_win=az_half_win,r_half_win=r_half_win) p
CPU times: user 164 ms, sys: 23.8 ms, total: 188 ms
Wall time: 192 ms
Select SHPs
if is_cuda_available():
= (p < 0.05) & (p >= 0.0) is_shp
if is_cuda_available():
= cp.count_nonzero(is_shp,axis=(-2,-1))
shp_num = cp.asnumpy(shp_num) shp_num_np
if is_cuda_available():
= plt.subplots(1,1,figsize=(10,10))
fig, ax = ax.imshow(shp_num_np)
pcm set(title='Number of SHPs',xlabel='Range Index',ylabel='Azimuth Index')
ax.
fig.colorbar(pcm) fig.show()
Estimate coherence matrix
if is_cuda_available():
= mr.emperical_co(rslc,is_shp)[1] coh
CPU times: user 4.19 ms, sys: 12.2 ms, total: 16.4 ms
Wall time: 16 ms
Compare
Here we compare 1-look interferogram, multilook interferogram and adaptive multilook interferogram
= 15
ref_image = 16 sec_image
1 look interferogram:
if is_cuda_available():
= rslc[:,:,ref_image]*rslc[:,:,sec_image].conj() diff
Multilook interferogram:
if is_cuda_available():
= uniform_filter(diff,size=(az_win,r_win)) ml_diff
Adaptive multilook interferogram:
if is_cuda_available():
= coh[:,:,ref_image,sec_image] ad_ml_diff
The plot background:
if is_cuda_available():
= rmli[:,:,0]
plot_bg = cp.asnumpy(plot_bg)
plot_bg = mr.bg_alpha(plot_bg) alpha
Plot:
if is_cuda_available():
= plt.subplots(1,3,figsize=(24/2,7/2))
fig,axes = 'Range Index'
xlabel = 'Azimuth Index'
ylabel = axes[0].imshow(cp.asnumpy(cp.angle(diff)),alpha=alpha,interpolation='nearest',cmap='hsv')
pcm0 = axes[1].imshow(cp.asnumpy(cp.angle(ml_diff)),alpha=alpha,interpolation='nearest',cmap='hsv')
pcm1 = axes[2].imshow(cp.asnumpy(cp.angle(ad_ml_diff)),alpha=alpha,interpolation='nearest',cmap='hsv')
pcm2 for ax in axes:
set(facecolor = "black")
ax.0].set(title='Orignal Interferogram',xlabel=xlabel,ylabel=ylabel)
axes[1].set(title=f'Multilook {az_win} by {r_win}',xlabel=xlabel,ylabel=ylabel)
axes[2].set(title=f'Adaptively multilook {az_win} by {r_win}',xlabel=xlabel,ylabel=ylabel)
axes[=axes[0])
fig.colorbar(pcm0,ax=axes[1])
fig.colorbar(pcm1,ax=axes[2])
fig.colorbar(pcm1,ax fig.show()
Conclusion
- Adaptive multilooking based on SHPs selection performs better than non-adaptive one;
ks_test
andemperical_co
implemented in Moraine package are fast.