load

Module for loading result from other software
import zarr
import numpy as np
from matplotlib import pyplot as plt
import moraine.cli as mc

source

load_gamma_flatten_rslc

 load_gamma_flatten_rslc (rslc_dir:str, reference:str, hgt:str,
                          scratch_dir:str, rslc:str,
                          chunks:tuple[int,int]=(1000, 1000),
                          processes=False, n_workers=1,
                          threads_per_worker=1, **dask_cluster_arg)

Generate flatten rslc data from gamma command and convert them into zarr format. The shape of hgt should be same as one rslc image, i.e. the hgt file is generated with 1 by 1 look geocoding. All data equal to 0 are replaced with nan.

Type Default Details
rslc_dir str gamma rslc directory, the name of the rslc and their par files should be ‘????????.rslc’ and ‘????????.rslc.par’
reference str reference date, eg: ‘20200202’
hgt str the DEM in radar coordinate
scratch_dir str directory for preserve gamma intermediate files
rslc str output, the flattened rslcs stack in zarr format
chunks tuple (1000, 1000) rslc chunk size
processes bool False use process for dask worker or thread
n_workers int 1 number of dask worker
threads_per_worker int 1 number of threads per dask worker
dask_cluster_arg

The method behind the flattened RSLC:

Let the value of i-th rslc be \(s_i\), the simulated phase due to DEM and position difference be \(u_{ij}\). D-InSAR basically is: \[d_{ij}=s_i \times s_j^* \times e^{-ju_{ij}}.\] Let the distance between satellite and ground target for th i-th observation be \(l_i\). Then, the simulated phase for DInSAR \[u_{ij} = l_i-l_j.\] So, a simple conclusion is \[u_{ij}-u_{ik}=-u_{jk}.\] If we define \[s_i^{\prime} = s_i \times e^{ju_{xi}},\] where \(X\) can be any arbitrary interger less than \(N\)- the total number of the RSLCs. Then we can find that \[int_{ij}^{\prime} = s_i^{\prime} \times s_j^{\prime*} = s_i \times s_j^* \times e^{j(u_{xi}-u_{xj})} = s_i \times s_j^* \times e^{j(u_{xi}-u_{xj})} = s_i \times s_j^* \times e^{-ju_{ij}} = d_{ij}.\]

We call \(s_i^{\prime}\) as flattened RSLC. The advantage of flattened RSLC is DInSAR can be easily calculated by simple conjugate multiplication.

An example:

rslc_dir = '../../data/gamma/rslc'
reference = '20220620'
hgt = '../../data/gamma/geocoding/20210802.hgt'
rslc = './raw/rslc.zarr'
scratch_dir = './raw/scratch'
logger = mc.get_logger()
load_gamma_flatten_rslc(rslc_dir,reference,hgt,scratch_dir,rslc,chunks=(1000,1000))
2024-08-09 12:20:09 - log_args - INFO - running function: load_gamma_flatten_rslc
2024-08-09 12:20:09 - log_args - INFO - fetching args:
2024-08-09 12:20:09 - log_args - INFO - rslc_dir = '../../data/gamma/rslc'
2024-08-09 12:20:09 - log_args - INFO - reference = '20220620'
2024-08-09 12:20:09 - log_args - INFO - hgt = '../../data/gamma/geocoding/20210802.hgt'
2024-08-09 12:20:09 - log_args - INFO - scratch_dir = './raw/scratch'
2024-08-09 12:20:09 - log_args - INFO - rslc = './raw/rslc.zarr'
2024-08-09 12:20:09 - log_args - INFO - chunks = (1000, 1000)
2024-08-09 12:20:09 - log_args - INFO - processes = False
2024-08-09 12:20:09 - log_args - INFO - n_workers = 1
2024-08-09 12:20:09 - log_args - INFO - threads_per_worker = 1
2024-08-09 12:20:09 - log_args - INFO - dask_cluster_arg = {}
2024-08-09 12:20:09 - log_args - INFO - fetching args done.
2024-08-09 12:20:09 - load_gamma_flatten_rslc - INFO - rslc found: 
        date                                 rslc  \
0   20210802  ../../data/gamma/rslc/20210802.rslc   
1   20210816  ../../data/gamma/rslc/20210816.rslc   
2   20210830  ../../data/gamma/rslc/20210830.rslc   
3   20210913  ../../data/gamma/rslc/20210913.rslc   
4   20211011  ../../data/gamma/rslc/20211011.rslc   
5   20211025  ../../data/gamma/rslc/20211025.rslc   
6   20220606  ../../data/gamma/rslc/20220606.rslc   
7   20220620  ../../data/gamma/rslc/20220620.rslc   
8   20220704  ../../data/gamma/rslc/20220704.rslc   
9   20220718  ../../data/gamma/rslc/20220718.rslc   
10  20220801  ../../data/gamma/rslc/20220801.rslc   
11  20220815  ../../data/gamma/rslc/20220815.rslc   
12  20220829  ../../data/gamma/rslc/20220829.rslc   
13  20220912  ../../data/gamma/rslc/20220912.rslc   
14  20220926  ../../data/gamma/rslc/20220926.rslc   
15  20221010  ../../data/gamma/rslc/20221010.rslc   
16  20221024  ../../data/gamma/rslc/20221024.rslc   

                                        par  
0   ../../data/gamma/rslc/20210802.rslc.par  
1   ../../data/gamma/rslc/20210816.rslc.par  
2   ../../data/gamma/rslc/20210830.rslc.par  
3   ../../data/gamma/rslc/20210913.rslc.par  
4   ../../data/gamma/rslc/20211011.rslc.par  
5   ../../data/gamma/rslc/20211025.rslc.par  
6   ../../data/gamma/rslc/20220606.rslc.par  
7   ../../data/gamma/rslc/20220620.rslc.par  
8   ../../data/gamma/rslc/20220704.rslc.par  
9   ../../data/gamma/rslc/20220718.rslc.par  
10  ../../data/gamma/rslc/20220801.rslc.par  
11  ../../data/gamma/rslc/20220815.rslc.par  
12  ../../data/gamma/rslc/20220829.rslc.par  
13  ../../data/gamma/rslc/20220912.rslc.par  
14  ../../data/gamma/rslc/20220926.rslc.par  
15  ../../data/gamma/rslc/20221010.rslc.par  
16  ../../data/gamma/rslc/20221024.rslc.par  
2024-08-09 12:20:09 - load_gamma_flatten_rslc - INFO - number of images: 17.
2024-08-09 12:20:09 - load_gamma_flatten_rslc - INFO - image number of lines: 2500.
2024-08-09 12:20:09 - load_gamma_flatten_rslc - INFO - image width: 1834.
2024-08-09 12:20:09 - load_gamma_flatten_rslc - INFO - run gamma command to generate required data for flattened rslcs:
2024-08-09 12:20:09 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20210802.rslc.par raw/scratch/20220620_20210802.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:09 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20210802.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20210802.rslc.par raw/scratch/20220620_20210802.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20210802.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:09 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20210816.rslc.par raw/scratch/20220620_20210816.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:09 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20210816.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20210816.rslc.par raw/scratch/20220620_20210816.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20210816.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:09 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20210830.rslc.par raw/scratch/20220620_20210830.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:09 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20210830.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20210830.rslc.par raw/scratch/20220620_20210830.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20210830.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:09 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20210913.rslc.par raw/scratch/20220620_20210913.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20210913.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20210913.rslc.par raw/scratch/20220620_20210913.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20210913.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20211011.rslc.par raw/scratch/20220620_20211011.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20211011.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20211011.rslc.par raw/scratch/20220620_20211011.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20211011.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20211025.rslc.par raw/scratch/20220620_20211025.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20211025.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20211025.rslc.par raw/scratch/20220620_20211025.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20211025.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220606.rslc.par raw/scratch/20220620_20220606.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20220606.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220606.rslc.par raw/scratch/20220620_20220606.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20220606.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220620.rslc.par raw/scratch/20220620_20220620.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20220620.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220620.rslc.par raw/scratch/20220620_20220620.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20220620.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220704.rslc.par raw/scratch/20220620_20220704.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20220704.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220704.rslc.par raw/scratch/20220620_20220704.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20220704.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220718.rslc.par raw/scratch/20220620_20220718.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20220718.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220718.rslc.par raw/scratch/20220620_20220718.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20220718.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220801.rslc.par raw/scratch/20220620_20220801.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20220801.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220801.rslc.par raw/scratch/20220620_20220801.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20220801.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220815.rslc.par raw/scratch/20220620_20220815.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20220815.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220815.rslc.par raw/scratch/20220620_20220815.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20220815.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220829.rslc.par raw/scratch/20220620_20220829.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20220829.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220829.rslc.par raw/scratch/20220620_20220829.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20220829.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220912.rslc.par raw/scratch/20220620_20220912.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20220912.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220912.rslc.par raw/scratch/20220620_20220912.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20220912.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220926.rslc.par raw/scratch/20220620_20220926.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20220926.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20220926.rslc.par raw/scratch/20220620_20220926.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20220926.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20221010.rslc.par raw/scratch/20220620_20221010.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20221010.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20221010.rslc.par raw/scratch/20220620_20221010.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20221010.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - run command: create_offset ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20221024.rslc.par raw/scratch/20220620_20221024.off 1 1 1 0 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - raw/scratch/20220620_20221024.sim_orb exists. skip runing phase_sim_orb ../../data/gamma/rslc/20220620.rslc.par ../../data/gamma/rslc/20221024.rslc.par raw/scratch/20220620_20221024.off ../../data/gamma/geocoding/20210802.hgt raw/scratch/20220620_20221024.sim_orb ../../data/gamma/rslc/20220620.rslc.par - - 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - gamma command finished.
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - using dask to load data in gamma binary format to calculate flatten rslcs and save it to zarr.
2024-08-09 12:20:10 - load_gamma_flatten_rslc - INFO - starting dask local cluster.
2024-08-09 12:20:11 - load_gamma_flatten_rslc - INFO - dask local cluster started.
2024-08-09 12:20:11 - dask_cluster_info - INFO - dask cluster: LocalCluster(dashboard_link='http://10.211.48.20:8787/status', workers=1, threads=1, memory=1.46 TiB)
2024-08-09 12:20:11 - darr_info - INFO - flattened rslc dask array shape, chunksize, dtype: (2500, 1834, 17), (2500, 1834, 1), complex64
2024-08-09 12:20:11 - zarr_info - INFO - ./raw/rslc.zarr zarray shape, chunks, dtype: (2500, 1834, 17), (1000, 1000, 1), complex64
2024-08-09 12:20:11 - load_gamma_flatten_rslc - INFO - computing graph setted. doing all the computing.
2024-08-09 12:20:15 - load_gamma_flatten_rslc - INFO - computing finished.
2024-08-09 12:20:16 - load_gamma_flatten_rslc - INFO - dask cluster closed.

source

load_gamma_lat_lon_hgt

 load_gamma_lat_lon_hgt (diff_par:str, rslc_par:str, dem_par:str, hgt:str,
                         scratch_dir:str, lat_zarr:str, lon_zarr:str,
                         hgt_zarr:str, chunks:tuple[int,int]=(1000, 1000))

Function to load longitude and latitude from gamma binary format to zarr. All data equal to 0 are replaced with nan.

Type Default Details
diff_par str geocoding diff_par,using the simulated image as reference
rslc_par str par file of the reference rslc
dem_par str dem par
hgt str DEM in radar coordinate
scratch_dir str directory for preserve gamma intermediate files
lat_zarr str output, latitude zarr
lon_zarr str output, longitude zarr
hgt_zarr str output, height zarr
chunks tuple (1000, 1000) rslc chunk size
diff_par = '../../data/gamma/geocoding/20210802.diff_par'
rslc_par = '../../data/gamma/rslc/20220620.rslc.par'
dem_par = '../../data/gamma/DEM/dem_seg_par'
hgt = '../../data/gamma/geocoding/20210802.hgt'
scratch_dir = './raw/scratch'
lat_zarr = './raw/lat.zarr'
lon_zarr = './raw/lon.zarr'
hgt_zarr = './raw/hgt.zarr'

An example:

load_gamma_lat_lon_hgt(diff_par,rslc_par,dem_par,hgt,scratch_dir,lat_zarr,lon_zarr,hgt_zarr,chunks=(1000,1000))
2024-08-09 12:20:16 - log_args - INFO - running function: load_gamma_lat_lon_hgt
2024-08-09 12:20:16 - log_args - INFO - fetching args:
2024-08-09 12:20:16 - log_args - INFO - diff_par = '../../data/gamma/geocoding/20210802.diff_par'
2024-08-09 12:20:16 - log_args - INFO - rslc_par = '../../data/gamma/rslc/20220620.rslc.par'
2024-08-09 12:20:16 - log_args - INFO - dem_par = '../../data/gamma/DEM/dem_seg_par'
2024-08-09 12:20:16 - log_args - INFO - hgt = '../../data/gamma/geocoding/20210802.hgt'
2024-08-09 12:20:16 - log_args - INFO - scratch_dir = './raw/scratch'
2024-08-09 12:20:16 - log_args - INFO - lat_zarr = './raw/lat.zarr'
2024-08-09 12:20:16 - log_args - INFO - lon_zarr = './raw/lon.zarr'
2024-08-09 12:20:16 - log_args - INFO - hgt_zarr = './raw/hgt.zarr'
2024-08-09 12:20:16 - log_args - INFO - chunks = (1000, 1000)
2024-08-09 12:20:16 - log_args - INFO - fetching args done.
2024-08-09 12:20:16 - load_gamma_lat_lon_hgt - INFO - image shape: (2500,1834)
2024-08-09 12:20:16 - load_gamma_lat_lon_hgt - INFO - run gamma command to generate longitude, latitude and height:
2024-08-09 12:20:16 - load_gamma_lat_lon_hgt - INFO - raw/scratch/plist exists. skip runing mkgrid raw/scratch/plist 1834 2500 1 1 >> raw/scratch/gamma.log
2024-08-09 12:20:16 - load_gamma_lat_lon_hgt - INFO - raw/scratch/phgt_wgs84 exists. skip runing pt2geo raw/scratch/plist - ../../data/gamma/rslc/20220620.rslc.par - ../../data/gamma/geocoding/20210802.hgt ../../data/gamma/DEM/dem_seg_par ../../data/gamma/geocoding/20210802.diff_par 1 1 - - raw/scratch/plat_lon raw/scratch/phgt_wgs84 >> raw/scratch/gamma.log
2024-08-09 12:20:16 - load_gamma_lat_lon_hgt - INFO - writing zarr file.
2024-08-09 12:20:16 - load_gamma_lat_lon_hgt - INFO - write done.
lon_data = zarr.open(lon_zarr,mode='r')[:]
lat_data = zarr.open(lat_zarr,mode='r')[:]
hgt_data = zarr.open(hgt_zarr,mode='r')[:]
fig,axes = plt.subplots(1,3,figsize=(16,5))
im0 = axes[0].imshow(lon_data)
axes[0].set_title('Longitude')
fig.colorbar(im0, ax=axes[0])
im1 = axes[1].imshow(lat_data)
axes[1].set_title('Latitude')
fig.colorbar(im1, ax=axes[1])
im2 = axes[2].imshow(hgt_data)
axes[2].set_title('Height')
fig.colorbar(im2, ax=axes[2])
fig.show()


source

load_gamma_look_vector

 load_gamma_look_vector (theta:str, phi:str, lt:str, rslc_par:str,
                         dem_par:str, scratch_dir:str, theta_zarr:str,
                         phi_zarr:str, chunks:tuple[int,int]=(1000, 1000))

Load look vector (elevation angle and orientation angle) in map geometry from gamma binary format to look vector in radar geometry zarr file. The two input data should be generated with the look_vector gamma command. All data equal to 0 are replaced with nan.

Type Default Details
theta str elevation angle
phi str orientation angle
lt str lookup table
rslc_par str par file of the reference rslc
dem_par str dem par
scratch_dir str directory for preserve gamma intermediate files
theta_zarr str output, elevation angle zarr
phi_zarr str output, orientation angle zarr
chunks tuple (1000, 1000) rslc chunk size

An example:

lt = '../../data/gamma/geocoding/20210802.lt_fine'
rslc_par = '../../data/gamma/rslc/20220620.rslc.par'
dem_par = '../../data/gamma/DEM/dem_seg_par'
theta = '../../data/gamma/geocoding/20210802.lv_theta'
phi = '../../data/gamma/geocoding/20210802.lv_phi'
scratch_dir = './raw/scratch'
theta_zarr = './raw/theta.zarr'
phi_zarr = './raw/phi.zarr'
load_gamma_look_vector(theta,phi,lt,rslc_par,dem_par,scratch_dir,theta_zarr,phi_zarr,chunks=(1000,1000))
2024-08-09 12:20:18 - log_args - INFO - running function: load_gamma_look_vector
2024-08-09 12:20:18 - log_args - INFO - fetching args:
2024-08-09 12:20:18 - log_args - INFO - theta = '../../data/gamma/geocoding/20210802.lv_theta'
2024-08-09 12:20:18 - log_args - INFO - phi = '../../data/gamma/geocoding/20210802.lv_phi'
2024-08-09 12:20:18 - log_args - INFO - lt = '../../data/gamma/geocoding/20210802.lt_fine'
2024-08-09 12:20:18 - log_args - INFO - rslc_par = '../../data/gamma/rslc/20220620.rslc.par'
2024-08-09 12:20:18 - log_args - INFO - dem_par = '../../data/gamma/DEM/dem_seg_par'
2024-08-09 12:20:18 - log_args - INFO - scratch_dir = './raw/scratch'
2024-08-09 12:20:18 - log_args - INFO - theta_zarr = './raw/theta.zarr'
2024-08-09 12:20:18 - log_args - INFO - phi_zarr = './raw/phi.zarr'
2024-08-09 12:20:18 - log_args - INFO - chunks = (1000, 1000)
2024-08-09 12:20:18 - log_args - INFO - fetching args done.
2024-08-09 12:20:18 - load_gamma_look_vector - INFO - image shape: (2500,1834)
2024-08-09 12:20:18 - load_gamma_look_vector - INFO - raw/scratch/theta_rdc exists. skip runing geocode ../../data/gamma/geocoding/20210802.lt_fine ../../data/gamma/geocoding/20210802.lv_theta 5741 raw/scratch/theta_rdc 1834 2500 >> raw/scratch/gamma.log
2024-08-09 12:20:18 - load_gamma_look_vector - INFO - writing data.
2024-08-09 12:20:18 - load_gamma_look_vector - INFO - raw/scratch/phi_rdc exists. skip runing geocode ../../data/gamma/geocoding/20210802.lt_fine ../../data/gamma/geocoding/20210802.lv_phi 5741 raw/scratch/phi_rdc 1834 2500 >> raw/scratch/gamma.log
2024-08-09 12:20:18 - load_gamma_look_vector - INFO - writing data.
2024-08-09 12:20:18 - load_gamma_look_vector - INFO - Done.
theta_data = zarr.open(theta_zarr,mode='r')[:]
phi_data = zarr.open(phi_zarr,mode='r')[:]
# theta_data[theta_data==0] = np.nan
# phi_data[phi_data==0] = np.nan
fig,axes = plt.subplots(1,2,figsize=(11,5))
im0 = axes[0].imshow(np.rad2deg(theta_data))
axes[0].set_title('Elevation angle')
fig.colorbar(im0, ax=axes[0])
im1 = axes[1].imshow(np.rad2deg(phi_data))
axes[1].set_title('Orientation anlge')
fig.colorbar(im1, ax=axes[1])
fig.show()


source

load_gamma_range

 load_gamma_range (rslc_par:str, range_zarr:str,
                   chunks:tuple[int,int]=(1000, 1000))

Generate slant range distance and save to zarr.

Type Default Details
rslc_par str par file of one rslc
range_zarr str output, range distance zarr
chunks tuple (1000, 1000) rslc chunk size

An example:

rslc_par = '../../data/gamma/rslc/20220620.rslc.par'
range_zarr = './raw/range.zarr'
load_gamma_range(rslc_par,range_zarr)
2024-08-09 12:20:19 - log_args - INFO - running function: load_gamma_range
2024-08-09 12:20:19 - log_args - INFO - fetching args:
2024-08-09 12:20:19 - log_args - INFO - rslc_par = '../../data/gamma/rslc/20220620.rslc.par'
2024-08-09 12:20:19 - log_args - INFO - range_zarr = './raw/range.zarr'
2024-08-09 12:20:19 - log_args - INFO - chunks = (1000, 1000)
2024-08-09 12:20:19 - log_args - INFO - fetching args done.
2024-08-09 12:20:19 - load_gamma_range - INFO - image shape: (2500,1834)
2024-08-09 12:20:19 - load_gamma_range - INFO - Calculating slant range distance.
2024-08-09 12:20:19 - load_gamma_range - INFO - writing data.
2024-08-09 12:20:19 - load_gamma_range - INFO - Done.
range_data = zarr.open(range_zarr,mode='r')[:]
plt.imshow(range_data)
plt.colorbar()
plt.title("Slant range distance")
plt.show()


source

load_gamma_metadata

 load_gamma_metadata (rslc_dir:str, dem_par:str, reference:str,
                      meta_file:str)

Load necessary metadata into a toml file.

Type Details
rslc_dir str gamma rslc directory, the name of the rslc and their par files should be ‘????????.rslc’ and ‘????????.rslc.par’
dem_par str dem par
reference str reference date, eg: ‘20200202’
meta_file str output, text toml file for meta data

An example:

rslc_dir = '../../data/gamma/rslc'
dem_par = '../../data/gamma/DEM/dem_seg_par'
reference = '20220620'
meta_file = './raw/meta.toml'
load_gamma_metadata(rslc_dir,dem_par,reference,meta_file)
2024-08-09 12:20:19 - log_args - INFO - running function: load_gamma_metadata
2024-08-09 12:20:19 - log_args - INFO - fetching args:
2024-08-09 12:20:19 - log_args - INFO - rslc_dir = '../../data/gamma/rslc'
2024-08-09 12:20:19 - log_args - INFO - dem_par = '../../data/gamma/DEM/dem_seg_par'
2024-08-09 12:20:19 - log_args - INFO - reference = '20220620'
2024-08-09 12:20:19 - log_args - INFO - meta_file = './raw/meta.toml'
2024-08-09 12:20:19 - log_args - INFO - fetching args done.
2024-08-09 12:20:19 - load_gamma_metadata - INFO - fetching slc related metadata.
2024-08-09 12:20:19 - load_gamma_metadata - INFO - Fetching heading angle
2024-08-09 12:20:19 - load_gamma_metadata - INFO - Fetching range pixel spacing
2024-08-09 12:20:19 - load_gamma_metadata - INFO - fetching azimuth pixel spacing
2024-08-09 12:20:19 - load_gamma_metadata - INFO - Fetching randar wavelength
2024-08-09 12:20:19 - load_gamma_metadata - INFO - fetching dem related metadata
2024-08-09 12:20:20 - load_gamma_metadata - INFO - Run gamma command to calculate baseline:
2024-08-09 12:20:20 - load_gamma_metadata - INFO - run command: base_calc /tmp/tmpgq5qdkzy/slc_tab ../../data/gamma/rslc/20220620.rslc.par /tmp/tmpgq5qdkzy/bperp /tmp/tmpgq5qdkzy/itab - > /tmp/tmpgq5qdkzy/log
2024-08-09 12:20:20 - load_gamma_metadata - INFO - gamma command finished.
2024-08-09 12:20:20 - load_gamma_metadata - INFO - All meta data: 
dates = [ "20210802", "20210816", "20210830", "20210913", "20211011", "20211025", "20220606", "20220620", "20220704", "20220718", "20220801", "20220815", "20220829", "20220912", "20220926", "20221010", "20221024",]
radar_wavelength = 0.24245249210715603
range_pixel_spacing = 4.29054
azimuth_pixel_spacing = 3.740105
lonlat_bbox = [ -148.2606018, 61.099475398661994, -147.89598577255998, 61.2183333,]
merca_bbox = [ -16504294.694782883, 8648700.085300261, -16463705.824278845, 8676129.004166307,]
perpendicular_baseline = [ -97.61360168457031, -45.58580017089844, 17.86680030822754, -26.258899688720703, -63.72420120239258, -56.363399505615234, 64.75759887695312, 0.0, -9.043999671936035, -13.02869987487793, -112.94960021972656, -86.09490203857422, -129.9635009765625, -127.6594009399414, -182.29519653320312, -129.735107421875, -184.31100463867188,]

2024-08-09 12:20:20 - load_gamma_metadata - INFO - writing data in toml file.
2024-08-09 12:20:20 - load_gamma_metadata - INFO - Done.
with open(meta_file,'r') as f:
    meta_read = toml.load(f)
meta_read
{'dates': ['20210802',
  '20210816',
  '20210830',
  '20210913',
  '20211011',
  '20211025',
  '20220606',
  '20220620',
  '20220704',
  '20220718',
  '20220801',
  '20220815',
  '20220829',
  '20220912',
  '20220926',
  '20221010',
  '20221024'],
 'radar_wavelength': 0.24245249210715603,
 'range_pixel_spacing': 4.29054,
 'azimuth_pixel_spacing': 3.740105,
 'lonlat_bbox': [-148.2606018,
  61.099475398661994,
  -147.89598577255998,
  61.2183333],
 'merca_bbox': [-16504294.694782883,
  8648700.085300261,
  -16463705.824278845,
  8676129.004166307],
 'perpendicular_baseline': [-97.61360168457031,
  -45.58580017089844,
  17.86680030822754,
  -26.258899688720703,
  -63.72420120239258,
  -56.363399505615234,
  64.75759887695312,
  0.0,
  -9.043999671936035,
  -13.02869987487793,
  -112.94960021972656,
  -86.09490203857422,
  -129.9635009765625,
  -127.6594009399414,
  -182.29519653320312,
  -129.735107421875,
  -184.31100463867188]}