-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun3_RLE_mintpy_ts_proc.py
98 lines (80 loc) · 3.75 KB
/
run3_RLE_mintpy_ts_proc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
import argparse
import pandas as pd
import numpy as np
import glob
import time
import os
import subprocess
import matplotlib.pyplot as plt
from src.RLE_utils import simple_SBAS_stats, mintpy_SBAS_stats
def createParser(iargs = None):
'''Commandline input parser'''
parser = argparse.ArgumentParser(description='MintPy time-series processing after pycuampcor offset tracking')
parser.add_argument("--inputDir", dest="inputDir",
default='./offsets', type=str, help='Input directory of the offsets with geotiff files of range/azimuth offsets and SNR (default: offsets)')
parser.add_argument("--burst_id", dest='burst_id',
required=True, type=str, help='burst ID to be processed')
parser.add_argument("--snr", dest="snr",
default=10, type=int, help='SNR threshold to be used for SBAS approach (default: 10)')
parser.add_argument("--tsmethod", dest="tsmethod",
default='mintpy', type=str, help='method for time-series inversion: mintpy (default), sbas (simple SBAS method)')
parser.add_argument("--nprocs", dest="nprocs",
default=2, type=int, help='Number of processes to run (default: 2)')
return parser.parse_args(args=iargs)
def main(inps):
snr_th = inps.snr
tsmethod = inps.tsmethod
burst_id = inps.burst_id
offset_dir = f'{inps.inputDir}/{burst_id.upper()}/offsets'
nprocs = inps.nprocs
# Create necessary folders
os.makedirs(f'{inps.inputDir}/{burst_id.upper()}/mintpy', exist_ok=True)
os.makedirs(f'{inps.inputDir}/{burst_id.upper()}/summary', exist_ok=True)
savedir = f'{inps.inputDir}/{burst_id.upper()}/mintpy'
list_rg_tif = glob.glob(f'{offset_dir}/*.rg_off.tif') #geotiff of range offsets
refDates = []
secDates = []
for _ in list_rg_tif:
_rgtif = _.split('/')[-1]
refDate = _rgtif[0:8]
refDates.append(refDate)
secDate = _rgtif[9:17]
secDates.append(secDate)
_ = {'ref': refDates, 'sec': secDates}
df = pd.DataFrame.from_dict(_)
days = refDates + secDates
days = list(np.unique(sorted(days)))
exclude_days_ = df[(df.ref<='20150515')]
exclude_days = exclude_days_.ref.unique()
days = (list(filter(lambda x: x not in exclude_days, days)) )
print(f'Removing CSLCs with dates: {exclude_days}')
num_pairs = df.shape[0] #number of pairs
n_days = len(days) #number of unique days
print('')
print(f'Number of pairs for offset tracking {num_pairs}\n')
start_time = time.time()
#applying SBAS approach
list_rgoff = df['ref'] + '_' + df['sec'] + '.rg_off.tif'
list_azoff = df['ref'] + '_' + df['sec'] + '.az_off.tif'
list_snr = df['ref'] + '_' + df['sec'] + '.snr.tif'
if ( tsmethod == 'sbas'):
rg_avg, rg_std, _ = simple_SBAS_stats(list_rgoff,list_snr,savedir,snr_th)
az_avg, az_std, _ = simple_SBAS_stats(list_azoff,list_snr,savedir,snr_th)
else:
rg_avg, rg_std, az_avg, az_std = mintpy_SBAS_stats(list_rgoff,list_azoff,list_snr,savedir,snr_th,0.25,nprocs)
end_time = time.time()
time_taken = (end_time - start_time)/60.
print(f'{time_taken} min taken for SBAS processing')
df = None
_ = {'date':days, 'rg_avg':rg_avg, 'rg_std':rg_std, 'az_avg':az_avg, 'az_std':az_std}
df = pd.DataFrame.from_dict(_)
df.to_csv(f'{inps.inputDir}/{burst_id.upper()}/summary/RLE_{burst_id.upper()}.csv', index=False)
if __name__ == '__main__':
# load arguments from command line
inps = createParser()
print("=========================================================================")
print("Running Step 3 of the RLE: SBAS analysis")
print("=========================================================================")
# Run workflow
main(inps)