├── LICENSE ├── README.md ├── pyint.template └── pyint ├── ASAR_orb_cor.py ├── ASAR_orb_cor_all .py ├── ASAR_orb_cor_par.py ├── Down2SLC_ASAR_Cat.py ├── Down2SLC_ASAR_Cat_All.py ├── Down2SLC_ERS.py ├── Down2SLC_ERS_All.py ├── Down2SLC_ERS_Cat.py ├── Down2SLC_ERS_Cat_All.py ├── ERS_DEOS.py ├── ERS_orb_cor.py ├── ERS_orb_cor_all.py ├── ERS_orb_cor_par.py ├── Get_off_std.py ├── NameChange.py ├── RSI_SLC_Gamma.py ├── Raw2SLC_ERS_Cat.py ├── Raw2SLC_ERS_Cat_All.py ├── SAR2LATLON.py ├── UTM2SARPIX.py ├── _network.py ├── _utils.py ├── coreg_gamma.py ├── coreg_gamma_all.py ├── coreg_s1_gamma.py ├── diff_gamma.py ├── diff_gamma_all.py ├── down2ifg.py ├── down2slc_cat_all.py ├── down2slc_csk.py ├── down2slc_csk_all.py ├── down2slc_sen.py ├── down2slc_sen_all.py ├── download_ers_deos.py ├── download_url.py ├── extract_s1_bursts.py ├── extract_s1_bursts_all.py ├── generate_amp_all.py ├── generate_bursts_par.py ├── generate_multilook_amp.py ├── generate_rdc_dem.py ├── geocode_gamma.py ├── geocode_gamma_all.py ├── get_master_burst_numb.py ├── ionosphere_gamma.py ├── makedem.py ├── makedem_pyint.py ├── pot_gamma_subset.py ├── pot_gamma_subset_combine.py ├── pot_gamma_subset_jobs.py ├── process_tsifg.py ├── pyintApp.py ├── raw2ifg.py ├── raw2ifg_s1.py ├── raw2slc_ers_envisat.py ├── rslcCopy_gamma.py ├── rslcCopy_gamma_jobs.py ├── s1_orb_all.py ├── select_pairs.py ├── slc2ifg.py ├── unwrap_gamma.py └── unwrap_gamma_all.py /README.md: -------------------------------------------------------------------------------- 1 | # PyINT 2 | [![Language](https://img.shields.io/badge/python-3.5%2B-blue.svg)](https://www.python.org/) 3 | [![License](https://img.shields.io/badge/license-GPL-yellow.svg)](https://github.com/ymcmrs/PyINT/blob/master/LICENSE) 4 | 5 | PYthon-based INterferometry Toolbox (PyINT) is an open-source package for single or time-series of interferograms processing from downloading data (or SLC) to generating differential-unwrapped interferograms by using GAMMA software. You can process in a routine way (e.g., raw2ifg.py, slc2ifg.py or pyintApp.py) or process step by step. There are many GAMMA-independent tools of PyINT could be useful for you no matter you use GAMMA or other interferometry softwares (e.g., ISCE, SNAP). Advantages include (but not limited to) download and update precise-orbit data automatically (support S1, ERS, ASAR), download and process 30m-SRTM dem automatically, cat multi-frames automatically, select swaths and bursts flexibly (for S1), extract the related S1 butsts for Coregistration automatically, etc. Welcome to contribute/improve PyINT. 6 | 7 | 8 | ### 1 Download 9 | 10 | Download the development version using git: 11 | 12 | cd ~/python 13 | git clone https://github.com/ymcmrs/PyINT 14 | 15 | 16 | ### 2 Installation 17 | 18 | 1) To make pyint importable in python, by adding the path PyINT directory to your $PYTHONPATH 19 | For csh/tcsh user, add to your **_~/.cshrc_** file for example: 20 | 21 | ############################ Python ############################### 22 | if ( ! $?PYTHONPATH ) then 23 | setenv PYTHONPATH "" 24 | endif 25 | 26 | ##--------- Anaconda ---------------## 27 | setenv PYTHON3DIR ~/python/anaconda3 28 | setenv PATH ${PATH}:${PYTHON3DIR}/bin 29 | 30 | ##--------- PyINT ------------------## 31 | setenv PYINT_HOME ~/python/PyINT 32 | setenv PYTHONPATH ${PYTHONPATH}:${PYINT_HOME} 33 | setenv PATH ${PATH}:${PYINT_HOME}/pyint 34 | 35 | 2) Install gdal, elevation module using pip or conda for DEM processing. 36 | 37 | 3) Install [SSARA](https://github.com/bakerunavco/SSARA) and set account info for downloading data. [option] 38 | 39 | 40 | ### 3 Running PyINT 41 | 42 | 1). $SCRATCHDIR and $TEMPLATEDIR should be available in your system environment. $SCRATCHDIR for processing, $TEMPLATEDIR for template files to set the related processing parameters, $DEMDIR for saving DEMs: 43 | 44 | setenv SCRATCHDIR /Users/Yunmeng/Documents/SCRATCH 45 | setenv TEMPLATEDIR /Users/Yunmeng/Documents/development/TEMPLATEDIR 46 | setenv DEMDIR /Users/Yunmeng/Documents/SCRATCH/DEM 47 | 48 | 2). Preparing your template file, which should be saved in $TEMPLATEDIR, for setting some basic parameters (see the template file above).The template file should be named with a prefix of your project name: 49 | 50 | e.g., MexicoCityT143F529S1D.template [Region + Track + Frame + Satellite + Orbit] 51 | 52 | 53 | 3). Single interferogram processing: 54 | 55 | slc2ifg.py projectName Mdate Sdate # start from SLC to unwrapped-differential Ifg 56 | raw2ifg.py projectName Mdate Sdate # start from raw data to unwrapped-differential Ifg 57 | 58 | e.g. : 59 | slc2ifg.py HawaiiT87F526S1D 20150101 20160201 60 | raw2ifg.py HawaiiT87F526S1D 20150101 20160201 61 | 62 | 4). Time-series of interferograms processing. 63 | 64 | pyintApp.py projectName 65 | 66 | e.g. : 67 | pyintApp.py MexicoCityT143F529S1D # template file MexicoCityT143F529S1D.template should be availabe in TEMPLATEDIR 68 | 69 | General work-flow: 70 | 71 | 1) download data : download SLCs using SSARA (please check https://github.com/bakerunavco/SSARA) 72 | [You should provide Sensor, Track, Frame, or Time information in template] 73 | 2) generate SLC : raw 2 slc (multi-frame processing is also supported) 74 | [include orbit correction for S1,ASAR,ERS and burst-extraction for S1] 75 | 3) generate DEM : reference image related geo-dem, rdc-dem, lookup table will be generated. 76 | [SRTM-1 will be downloaded and processed automatically if not provided] 77 | 4) coregister SLC : coregister SLCs to the reference SLC iamge. 78 | [with assistant of DEM] 79 | 5) select pairs : select interferometric pairs for time-series processing. 80 | [networks of sbas, sequential, delaunay, and stars are supported] 81 | 6) interferometry : generate unwrapped differential interferograms. 82 | [include differential, unwrapping, and geocoding] 83 | 7) load data : loading data for time-series analysis, mintPy is supported presently. 84 | 85 | Note: 86 | 87 | i ) Single interferogram processing please use slc2ifg.py or raw2ifg.py 88 | ii ) Multi-processor parallel processing is supported, but keep in mind GAMMA calls multi-threads already. 89 | iii) You can using pyintApp.py from downloading data to generate time-series of unwrapped-differential Ifgs, 90 | or you also can process step by step. 91 | 92 | 93 | Note: All of the above codes are based on the hypothesis that you have installed [GAMMA](https://www.gamma-rs.ch/). 94 | -------------------------------------------------------------------------------- /pyint.template: -------------------------------------------------------------------------------- 1 | # *********************************** PyINT Template *******************************************# 2 | # Modifed Sep. , 2019 - YM.Cao 3 | 4 | # ------------------- Basic parameters ----------------------- 5 | 6 | DEM = /Users/caoy0a/Documents/SCRATCH/DEM/HawaiiT87F526S1D/HawaiiT87F526S1D.dem 7 | # if not provide, SRTM-1 will be downloaded and processed automatically. 8 | 9 | masterDate = 20180101 # [If not provided, the first date in the date_list will be selected as the master date] 10 | 11 | start_swath = 1 # [option (for Sentinel-1 only)] 12 | end_swath = 1 # [option (for Sentinel-1 only)] 13 | start_burst = 1 # [option: bursts position is based on the master image (for Sentinel-1 only)] 14 | end_burst = 4 # [option: bursts position is based on the master image (for Sentinel-1 only)] 15 | 16 | range_looks = 20 # multi-look numbers in range direction 17 | azimuth_looks = 4 # multi-look numbers in azimuth direction 18 | 19 | # ------------------- download data ----------------------- 20 | 21 | sensor = Sentinel-1A # Envisat, ERS-1/2, .. please check SSARA for details 22 | track = 14 # track number of the SAR image 23 | frame = 75 # frame number of the SAR image [ defined according to ASF ] 24 | start_time = 1989-01-01 # 25 | end_time = 2189-01-01 # 26 | 27 | # ------------------- basic parameters for interferometry ----------------------- 28 | 29 | dem_lat_ovr = 0.5 # as to SRTM-1, 0.5 for 60 m, 2 for 15 m 30 | dem_lon_ovr = 0.5 31 | 32 | Igram_Spsflg = 1 # Implement range spectral filtering 33 | Igram_Azfflg = 1 # Implement azimuth common band filtering 34 | 35 | rwin4cor = 256 # range window length for coregistration 36 | azwin4cor = 256 # azimuth window length for coregistration 37 | rsample4cor = 32 # range samples used for fitting the coregistration parameters 38 | azsample4cor = 32 # azimuth samples used for fitting the coregistration parameters 39 | 40 | thresh4cor = 0.15 # 2016 GAMMA or higher version, for 2015 GAMMA or lower version should be SNR 41 | 42 | Igram_Cor_rwin = 5 # range window length for cc_wave coherence estimation 43 | Igram_Cor_awin = 5 # azimuth window length for cc_wave coherence estimation 44 | 45 | Igram_Cor_Win = 5 # cc estimation in adf 46 | adf_alpha = 0.4 # adf alpha for Gold-Stein filtering 47 | 48 | # ------------------- sim phase ----------------------- 49 | 50 | Igram_Flag_TDM = N # Y for Tandem-X 51 | Simphase_rpos = - 52 | Simphase_azpos = - 53 | Simphase_rwin = 256 54 | Simphase_azwin = 256 55 | Simphase_thresh = - 56 | 57 | # ------------------- unwrap phase ----------------------- 58 | 59 | mcf_triangular = 0 # triangular type of mcf [0: regular; 1: delaunay;] 60 | unwrap_patr = 1 # unwrap patches in range direction 61 | unwrap_pataz = 1 # unwrap patches in azimuth direction 62 | unwrapThreshold = 0.1 # coherence threshold used for unwrap 63 | 64 | # ------------------- geocode ----------------------- 65 | 66 | geo_interp = 0 # [0: nearest; 1: bicubic spline] 67 | 68 | 69 | # ------------------- select interferometric pairs -------------- 70 | 71 | network_method = sbas # sbas, sequential, delaunay, stars 72 | endDate = 21000101 # date before this date will be excluded 73 | startDate = 19000101 # date after this date will be excluded 74 | conNumb = 2 # connect number for sequential 75 | max_tb = 50000 # temporal baseline threshold in days 76 | max_sb = 50000 # spatial baseline threshold in meters 77 | exclude_date = 20180601, 20180702 # exclude the date which will not be used 78 | 79 | # ------------------- time-series process -------------- 80 | 81 | download_data = 0 # [0: skip; 1: process] 82 | down_parallel = 1 # multi-processor number used for downloading 83 | 84 | raw2slc_all = 0 # i.e., download2slc [0: skip; 1: process] 85 | raw2slc_all_parallel = 1 # multi-processor number used 86 | 87 | extract_burst_all = 0 # for TOPS SLC only [0: skip; 1: process] 88 | extract_all_parallel = 1 # multi-processor number used 89 | 90 | coreg_all = 1 # do coregister [0: skip; 1: process] 91 | coreg_all_parallel = 1 # multi-processor number used [4 or 8] 92 | 93 | select_pairs = 1 # if 0: skip, and use the ifgram_list.txt under PROJECTNAME folder 94 | 95 | diff_all = 1 # generate differential Ifg [0: skip; 1: process] 96 | diff_all_parallel = 1 # multi-processor number used [4 or 8] 97 | 98 | unwrap_all = 1 # unwrap Ifg [0: skip; 1: process] 99 | unwrap_all_parallel = 1 # multi-processor number used [8 or 10] 100 | 101 | geocode_all = 0 # geocode diff,unw products [0: skip; 1: process] 102 | geocode_all_parallel = 1 # multi-processor number used 103 | 104 | load_data = 0 # loading data for mintpy processing [0: skip; 1: process] 105 | 106 | # ------------------- Good Luck -------------- 107 | -------------------------------------------------------------------------------- /pyint/ASAR_orb_cor.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v1.0 ### 4 | ### Copy Right (c): 2017, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : Central South University & University of Miami ### 8 | ################################################################# 9 | 10 | import numpy as np 11 | import os 12 | import sys 13 | import subprocess 14 | import getopt 15 | import time 16 | import glob 17 | import argparse 18 | import linecache 19 | import datetime 20 | 21 | def StrNum(S): 22 | S = str(S) 23 | if len(S)==1: 24 | S='0' +S 25 | return S 26 | 27 | def UseGamma(inFile, task, keyword): 28 | if task == "read": 29 | f = open(inFile, "r") 30 | while 1: 31 | line = f.readline() 32 | if not line: break 33 | if line.count(keyword) == 1: 34 | strtemp = line.split(":") 35 | value = strtemp[1].strip() 36 | return value 37 | print("Keyword " + keyword + " doesn't exist in " + inFile) 38 | f.close() 39 | 40 | ######################################################################### 41 | 42 | INTRODUCTION = ''' 43 | ############################################################################# 44 | Copy Right(c): 2017-2019, Yunmeng Cao @PyINT v1.0 45 | 46 | Correct ASAR orbit using precise DORIS data. 47 | 48 | ''' 49 | 50 | EXAMPLE = ''' 51 | Usage: 52 | ASAR_orb_cor.py projectName Date 53 | 54 | Examples: 55 | ASAR_orb_cor.py AqabaERSA 960101 56 | 57 | ############################################################################## 58 | ''' 59 | 60 | 61 | def cmdLineParse(): 62 | parser = argparse.ArgumentParser(description='Download (and correct) precise ERS orbit data.',\ 63 | formatter_class=argparse.RawTextHelpFormatter,\ 64 | epilog=INTRODUCTION+'\n'+EXAMPLE) 65 | 66 | parser.add_argument('projectName',help='project name') 67 | parser.add_argument('date',help='date of the ERS data') 68 | 69 | inps = parser.parse_args() 70 | return inps 71 | 72 | ################################################################################ 73 | 74 | 75 | def main(argv): 76 | 77 | total = time.time() 78 | inps = cmdLineParse() 79 | 80 | projectName = inps.projectName 81 | DATE = inps.date 82 | scratchDir = os.getenv('SCRATCHDIR') 83 | templateDir = os.getenv('TEMPLATEDIR') 84 | ASAROrbDir = os.getenv('ASARORBDIR') 85 | 86 | 87 | slcDir = scratchDir + '/' + projectName + '/SLC' 88 | projDir = scratchDir + '/' + projectName 89 | 90 | 91 | if len(DATE)==8: 92 | DATE8 = DATE 93 | DATE6 = DATE[2:8] 94 | else: 95 | DATE8 = '20' + DATE 96 | DATE6 = DATE 97 | 98 | 99 | slcDir1 = slcDir + '/' + DATE6 100 | slcpar = slcDir1 + '/' + DATE6 + '.slc.par' 101 | 102 | 103 | Year = DATE8[0:4] 104 | Month = DATE8[4:6] 105 | Day = DATE8[6:8] 106 | 107 | DATE1 = (datetime.date(int(Year),int(Month),int(Day)) + datetime.timedelta(days=-1)).strftime("%Y%m%d") 108 | DATE2 = (datetime.date(int(Year),int(Month),int(Day)) + datetime.timedelta(days=1)).strftime("%Y%m%d") 109 | 110 | os.chdir(ASAROrbDir) 111 | call_str = 'ls > t0' 112 | os.system(call_str) 113 | 114 | call_str="grep " + DATE1 + " t0 | grep " + DATE2 + " >t01" 115 | os.system(call_str) 116 | 117 | AA= np.loadtxt('t01',dtype=np.str) 118 | AA_file = ASAROrbDir + '/' + str(AA) 119 | 120 | call_str = 'DORIS_vec ' + slcpar + ' ' + AA_file 121 | os.system(call_str) 122 | 123 | 124 | print("Using DORIS orbital data for %s is done." % DATE) 125 | sys.exit(1) 126 | 127 | if __name__ == '__main__': 128 | main(sys.argv[:]) 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /pyint/ASAR_orb_cor_all .py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v1.0 ### 4 | ### Copy Right (c): 2017, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : Central South University & University of Miami ### 8 | ################################################################# 9 | 10 | import numpy as np 11 | import os 12 | import sys 13 | import subprocess 14 | import getopt 15 | import time 16 | import glob 17 | import argparse 18 | import linecache 19 | 20 | def StrNum(S): 21 | S = str(S) 22 | if len(S)==1: 23 | S='0' +S 24 | return S 25 | 26 | def UseGamma(inFile, task, keyword): 27 | if task == "read": 28 | f = open(inFile, "r") 29 | while 1: 30 | line = f.readline() 31 | if not line: break 32 | if line.count(keyword) == 1: 33 | strtemp = line.split(":") 34 | value = strtemp[1].strip() 35 | return value 36 | print("Keyword " + keyword + " doesn't exist in " + inFile) 37 | f.close() 38 | 39 | def is_number(s): 40 | try: 41 | int(s) 42 | return True 43 | except ValueError: 44 | return False 45 | 46 | ######################################################################### 47 | 48 | INTRODUCTION = ''' 49 | ############################################################################# 50 | Copy Right(c): 2017-2019, Yunmeng Cao @PyINT v1.0 51 | 52 | Correct ASAR orbit using precise DORIS data. 53 | 54 | ''' 55 | 56 | EXAMPLE = ''' 57 | Usage: 58 | ASAR_orb_cor_all.py projectName 59 | 60 | Examples: 61 | ASAR_orb_cor_all.py AqabaERSA 62 | 63 | ############################################################################## 64 | ''' 65 | 66 | 67 | def cmdLineParse(): 68 | parser = argparse.ArgumentParser(description='Download (and correct) precise ERS orbit data.',\ 69 | formatter_class=argparse.RawTextHelpFormatter,\ 70 | epilog=INTRODUCTION+'\n'+EXAMPLE) 71 | 72 | parser.add_argument('projectName',help='project name') 73 | 74 | inps = parser.parse_args() 75 | return inps 76 | 77 | ################################################################################ 78 | 79 | 80 | def main(argv): 81 | 82 | total = time.time() 83 | inps = cmdLineParse() 84 | 85 | projectName = inps.projectName 86 | scratchDir = os.getenv('SCRATCHDIR') 87 | templateDir = os.getenv('TEMPLATEDIR') 88 | slcDir = scratchDir + '/' + projectName + '/SLC' 89 | 90 | ListSLC = os.listdir(slcDir) 91 | Datelist = [] 92 | SLCfile = [] 93 | SLCParfile = [] 94 | 95 | 96 | for kk in range(len(ListSLC)): 97 | if ( is_number(ListSLC[kk]) and len(ListSLC[kk])==6 ): # if SAR date number is 8, 6 should change to 8. 98 | DD=ListSLC[kk] 99 | Year=int(DD[0:2]) 100 | Month = int(DD[2:4]) 101 | Day = int(DD[4:6]) 102 | Datelist.append(ListSLC[kk]) 103 | N = len(Datelist) 104 | 105 | for i in range(N): 106 | call_str = 'ERS_orb_cor.py ' + projectName + ' ' + Datelist[i] 107 | print(call_str) 108 | os.system(call_str) 109 | 110 | print("Using DEFT orbital data for project %s is done." % projectName) 111 | sys.exit(1) 112 | 113 | if __name__ == '__main__': 114 | main(sys.argv[:]) 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /pyint/ASAR_orb_cor_par.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v1.0 ### 4 | ### Copy Right (c): 2017, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : Central South University & University of Miami ### 8 | ################################################################# 9 | 10 | import numpy as np 11 | import os 12 | import sys 13 | import subprocess 14 | import getopt 15 | import time 16 | import glob 17 | import argparse 18 | import linecache 19 | import datetime 20 | 21 | def StrNum(S): 22 | S = str(S) 23 | if len(S)==1: 24 | S='0' +S 25 | return S 26 | 27 | def UseGamma(inFile, task, keyword): 28 | if task == "read": 29 | f = open(inFile, "r") 30 | while 1: 31 | line = f.readline() 32 | if not line: break 33 | if line.count(keyword) == 1: 34 | strtemp = line.split(":") 35 | value = strtemp[1].strip() 36 | return value 37 | print("Keyword " + keyword + " doesn't exist in " + inFile) 38 | f.close() 39 | 40 | ######################################################################### 41 | 42 | INTRODUCTION = ''' 43 | ############################################################################# 44 | Copy Right(c): 2017-2019, Yunmeng Cao @PyINT v1.0 45 | 46 | Precise ENVISAT orbit data from Delft (http://www.deos.tudelft.nl/). 47 | Correct the orbit parameters using DORIS_vec 48 | 49 | ''' 50 | 51 | EXAMPLE = ''' 52 | Usage: 53 | ASAR_orb_cor_par.py slc_par 54 | 55 | Examples: 56 | ASAR_orb_cor_par.py 960101.slc.par 57 | 58 | ############################################################################## 59 | ''' 60 | 61 | 62 | def cmdLineParse(): 63 | parser = argparse.ArgumentParser(description='Download (and correct) precise ERS orbit data.',\ 64 | formatter_class=argparse.RawTextHelpFormatter,\ 65 | epilog=INTRODUCTION+'\n'+EXAMPLE) 66 | 67 | parser.add_argument('slc_par',help='slc_par file.') 68 | 69 | inps = parser.parse_args() 70 | return inps 71 | 72 | ################################################################################ 73 | 74 | 75 | def main(argv): 76 | 77 | total = time.time() 78 | inps = cmdLineParse() 79 | 80 | slcpar = inps.slc_par 81 | ASAROrbDir = os.getenv('ASARORBDIR') 82 | PATH =os.getcwd() 83 | 84 | DATE = UseGamma(slcpar,'read','date:') 85 | Year = str(int(DATE[0:4])) 86 | Month = str(int(DATE[4:8])) 87 | Day = str(int(DATE[8:12])) 88 | 89 | DATE1 = (datetime.date(int(Year),int(Month),int(Day)) + datetime.timedelta(days=-1)).strftime("%Y%m%d") 90 | DATE2 = (datetime.date(int(Year),int(Month),int(Day)) + datetime.timedelta(days=1)).strftime("%Y%m%d") 91 | 92 | os.chdir(ASAROrbDir) 93 | call_str = 'ls > t0' 94 | os.system(call_str) 95 | 96 | call_str="grep " + DATE1 + " t0 | grep " + DATE2 + " > t01" 97 | os.system(call_str) 98 | 99 | AA= np.loadtxt('t01',dtype=np.str) 100 | AA_file = ASAROrbDir + '/' + str(AA) 101 | 102 | os.chdir(PATH) 103 | call_str = 'DORIS_vec ' + slcpar + ' ' + AA_file + ' 20' 104 | os.system(call_str) 105 | 106 | 107 | print("Using DORIS orbital data for %s is done." % slcpar) 108 | sys.exit(1) 109 | 110 | if __name__ == '__main__': 111 | main(sys.argv[:]) 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /pyint/Down2SLC_ASAR_Cat_All.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | #''' 3 | ################################################################################## 4 | # # 5 | # Author: Yun-Meng Cao # 6 | # Email : ymcmrs@gmail.com # 7 | # Date : March, 2017 # 8 | # # 9 | # Generate Sentinel SLC from the downloaded data # 10 | # # 11 | ################################################################################## 12 | #''' 13 | import numpy as np 14 | import os 15 | import sys 16 | import subprocess 17 | import getopt 18 | import time 19 | import glob 20 | 21 | def check_variable_name(path): 22 | s=path.split("/")[0] 23 | if len(s)>0 and s[0]=="$": 24 | p0=os.getenv(s[1:]) 25 | path=path.replace(path.split("/")[0],p0) 26 | return path 27 | 28 | def read_template(File, delimiter='='): 29 | '''Reads the template file into a python dictionary structure. 30 | Input : string, full path to the template file 31 | Output: dictionary, pysar template content 32 | Example: 33 | tmpl = read_template(KyushuT424F610_640AlosA.template) 34 | tmpl = read_template(R1_54014_ST5_L0_F898.000.pi, ':') 35 | ''' 36 | template_dict = {} 37 | for line in open(File): 38 | line = line.strip() 39 | c = [i.strip() for i in line.split(delimiter, 1)] #split on the 1st occurrence of delimiter 40 | if len(c) < 2 or line.startswith('%') or line.startswith('#'): 41 | next #ignore commented lines or those without variables 42 | else: 43 | atrName = c[0] 44 | atrValue = str.replace(c[1],'\n','').split("#")[0].strip() 45 | atrValue = check_variable_name(atrValue) 46 | template_dict[atrName] = atrValue 47 | return template_dict 48 | 49 | def UseGamma(inFile, task, keyword): 50 | if task == "read": 51 | f = open(inFile, "r") 52 | while 1: 53 | line = f.readline() 54 | if not line: break 55 | if line.count(keyword) == 1: 56 | strtemp = line.split(":") 57 | value = strtemp[1].strip() 58 | return value 59 | print("Keyword " + keyword + " doesn't exist in " + inFile) 60 | f.close 61 | 62 | def rm(TXT): 63 | call_str = 'rm ' + TXT 64 | os.system(call_str) 65 | 66 | def usage(): 67 | print(''' 68 | ****************************************************************************************************** 69 | 70 | Downloading Sentinel-1A/B data based on ssara 71 | 72 | usage: 73 | 74 | Down2SLC_ERS_Cat_All.py ProjectName 75 | 76 | e.g. Down2SLC_ERS_Cat_All.py CotopaxiT120ERSA 77 | 78 | ******************************************************************************************************* 79 | ''') 80 | 81 | def main(argv): 82 | 83 | if len(sys.argv)==2: 84 | projectName = sys.argv[1] 85 | else: 86 | usage();sys.exit(1) 87 | 88 | scratchDir = os.getenv('SCRATCHDIR') 89 | templateDir = os.getenv('TEMPLATEDIR') 90 | 91 | projectDir = scratchDir + '/' + projectName 92 | downDir = scratchDir + '/' + projectName + "/DOWNLOAD" 93 | slcDir = scratchDir + '/' + projectName + '/SLC' 94 | 95 | if not os.path.isdir(slcDir): 96 | call_str= 'mkdir ' +slcDir 97 | os.system(call_str) 98 | 99 | os.chdir(downDir) 100 | 101 | call_str = 'ls > tt0' 102 | os.system(call_str) 103 | 104 | call_str = 'grep ASA_IMS_1P tt0 >tt1' 105 | os.system(call_str) 106 | 107 | call_str = "awk -F_ '{print $3}' tt1 > tt2 " 108 | os.system(call_str) 109 | 110 | call_str = "awk -FSA '{print $2}' tt2 > ttt" 111 | os.system(call_str) 112 | 113 | call_str = 'sort ttt | uniq > ttm' 114 | os.system(call_str) 115 | 116 | AA= np.loadtxt('ttm',dtype=np.str) 117 | Na = AA.size 118 | 119 | for i in range(Na): 120 | call_str = 'Down2SLC_ASAR_Cat.py ' + projectName + ' ' + AA[i] 121 | print(call_str) 122 | call_str = 'Down2SLC_ASAR_Cat.py ' + projectName + ' ' + AA[i] + ' >/dev/null' 123 | os.system(call_str) 124 | 125 | 126 | print("Down to SLC for %s is done! " % projectName) 127 | sys.exit(1) 128 | 129 | if __name__ == '__main__': 130 | main(sys.argv[:]) 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /pyint/Down2SLC_ERS.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | #''' 3 | ################################################################################## 4 | # # 5 | # Author: Yun-Meng Cao # 6 | # Email : ymcmrs@gmail.com # 7 | # Date : June, 2019 # 8 | # # 9 | # Generate SLC from SAR_IMS_P1 data # 10 | # # 11 | ################################################################################## 12 | #''' 13 | import numpy as np 14 | import os 15 | import sys 16 | import subprocess 17 | import getopt 18 | import time 19 | import glob 20 | 21 | def check_variable_name(path): 22 | s=path.split("/")[0] 23 | if len(s)>0 and s[0]=="$": 24 | p0=os.getenv(s[1:]) 25 | path=path.replace(path.split("/")[0],p0) 26 | return path 27 | 28 | def read_template(File, delimiter='='): 29 | '''Reads the template file into a python dictionary structure. 30 | Input : string, full path to the template file 31 | Output: dictionary, pysar template content 32 | Example: 33 | tmpl = read_template(KyushuT424F610_640AlosA.template) 34 | tmpl = read_template(R1_54014_ST5_L0_F898.000.pi, ':') 35 | ''' 36 | template_dict = {} 37 | for line in open(File): 38 | line = line.strip() 39 | c = [i.strip() for i in line.split(delimiter, 1)] #split on the 1st occurrence of delimiter 40 | if len(c) < 2 or line.startswith('%') or line.startswith('#'): 41 | next #ignore commented lines or those without variables 42 | else: 43 | atrName = c[0] 44 | atrValue = str.replace(c[1],'\n','').split("#")[0].strip() 45 | atrValue = check_variable_name(atrValue) 46 | template_dict[atrName] = atrValue 47 | return template_dict 48 | 49 | def UseGamma(inFile, task, keyword): 50 | if task == "read": 51 | f = open(inFile, "r") 52 | while 1: 53 | line = f.readline() 54 | if not line: break 55 | if line.count(keyword) == 1: 56 | strtemp = line.split(":") 57 | value = strtemp[1].strip() 58 | return value 59 | print("Keyword " + keyword + " doesn't exist in " + inFile) 60 | f.close 61 | 62 | def rm(TXT): 63 | call_str = 'rm ' + TXT 64 | os.system(call_str) 65 | 66 | def usage(): 67 | print(''' 68 | ****************************************************************************************************** 69 | 70 | Generate SLC and SLC_par file for ERS/ENVISAT (SAR_IMS_1P format) 71 | 72 | usage: 73 | 74 | Down2SLC_ERS.py ProjectName DownName 75 | 76 | e.g. Down2SLC_ERS.py CotopaxiT120ERSA 910101 77 | 78 | ******************************************************************************************************* 79 | ''') 80 | 81 | def main(argv): 82 | 83 | if len(sys.argv)==3: 84 | projectName = sys.argv[1] 85 | Date = sys.argv[2] 86 | else: 87 | usage();sys.exit(1) 88 | 89 | scratchDir = os.getenv('SCRATCHDIR') 90 | templateDir = os.getenv('TEMPLATEDIR') 91 | 92 | projectDir = scratchDir + '/' + projectName 93 | downDir = scratchDir + '/' + projectName + "/DOWNLOAD" 94 | slcDir = scratchDir + '/' + projectName + '/SLC' 95 | 96 | if not os.path.isdir(slcDir): 97 | call_str= 'mkdir ' +slcDir 98 | os.system(call_str) 99 | os.chdir(downDir) 100 | 101 | t0 = 't0_' + Date 102 | call_str = 'ls >' + t0 103 | os.system(call_str) 104 | 105 | tt = 'tt_' + Date 106 | call_str = "grep " + Date + ' ' + t0 + '> ' + tt 107 | os.system(call_str) 108 | 109 | te = 'te_' + Date 110 | call_str = "grep SAR_IMS_1P " + tt + " > " + te 111 | os.system(call_str) 112 | 113 | AA= np.loadtxt(te,dtype=np.str) 114 | Na = AA.size 115 | 116 | if Na > 0: 117 | downName = str(AA[0]) 118 | FileDir = downDir + '/' + downName 119 | call_str = 'par_ASAR '+ FileDir + ' ' + Date 120 | os.system(call_str) 121 | else: 122 | print('No data is found for date:' + Date) 123 | sys.exit(1) 124 | 125 | call_str ="rename 's/VV.SLC/slc/g' *" 126 | os.system(call_str) 127 | 128 | Date0 = Date 129 | if len(Date)==6: 130 | Date0 = Date 131 | elif len(Date)==8: 132 | Date0 = Date[2:8] 133 | else: 134 | print('The input Date is invalid.') 135 | sys.exit(1) 136 | 137 | dataDir = slcDir + '/' + Date0 138 | if not os.path.isdir(dataDir): 139 | call_str = 'mkdir ' + dataDir 140 | print('Generate SLC dir for date: ' + Date0) 141 | os.system(call_str) 142 | call_str = 'mv ' + Date + '.slc* ' + dataDir 143 | os.system(call_str) 144 | 145 | print("Down to SLC for %s is done! " % Date) 146 | sys.exit(1) 147 | 148 | if __name__ == '__main__': 149 | main(sys.argv[:]) 150 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /pyint/Down2SLC_ERS_Cat_All.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | #''' 3 | ################################################################################## 4 | # # 5 | # Author: Yun-Meng Cao # 6 | # Email : ymcmrs@gmail.com # 7 | # Date : March, 2017 # 8 | # # 9 | # Generate Sentinel SLC from the downloaded data # 10 | # # 11 | ################################################################################## 12 | #''' 13 | import numpy as np 14 | import os 15 | import sys 16 | import subprocess 17 | import getopt 18 | import time 19 | import glob 20 | 21 | def check_variable_name(path): 22 | s=path.split("/")[0] 23 | if len(s)>0 and s[0]=="$": 24 | p0=os.getenv(s[1:]) 25 | path=path.replace(path.split("/")[0],p0) 26 | return path 27 | 28 | def read_template(File, delimiter='='): 29 | '''Reads the template file into a python dictionary structure. 30 | Input : string, full path to the template file 31 | Output: dictionary, pysar template content 32 | Example: 33 | tmpl = read_template(KyushuT424F610_640AlosA.template) 34 | tmpl = read_template(R1_54014_ST5_L0_F898.000.pi, ':') 35 | ''' 36 | template_dict = {} 37 | for line in open(File): 38 | line = line.strip() 39 | c = [i.strip() for i in line.split(delimiter, 1)] #split on the 1st occurrence of delimiter 40 | if len(c) < 2 or line.startswith('%') or line.startswith('#'): 41 | next #ignore commented lines or those without variables 42 | else: 43 | atrName = c[0] 44 | atrValue = str.replace(c[1],'\n','').split("#")[0].strip() 45 | atrValue = check_variable_name(atrValue) 46 | template_dict[atrName] = atrValue 47 | return template_dict 48 | 49 | def UseGamma(inFile, task, keyword): 50 | if task == "read": 51 | f = open(inFile, "r") 52 | while 1: 53 | line = f.readline() 54 | if not line: break 55 | if line.count(keyword) == 1: 56 | strtemp = line.split(":") 57 | value = strtemp[1].strip() 58 | return value 59 | print("Keyword " + keyword + " doesn't exist in " + inFile) 60 | f.close 61 | 62 | def rm(TXT): 63 | call_str = 'rm ' + TXT 64 | os.system(call_str) 65 | 66 | def usage(): 67 | print(''' 68 | ****************************************************************************************************** 69 | 70 | Downloading Sentinel-1A/B data based on ssara 71 | 72 | usage: 73 | 74 | Down2SLC_ERS_Cat_All.py ProjectName 75 | 76 | e.g. Down2SLC_ERS_Cat_All.py CotopaxiT120ERSA 77 | 78 | ******************************************************************************************************* 79 | ''') 80 | 81 | def main(argv): 82 | 83 | if len(sys.argv)==2: 84 | projectName = sys.argv[1] 85 | else: 86 | usage();sys.exit(1) 87 | 88 | scratchDir = os.getenv('SCRATCHDIR') 89 | templateDir = os.getenv('TEMPLATEDIR') 90 | 91 | projectDir = scratchDir + '/' + projectName 92 | downDir = scratchDir + '/' + projectName + "/DOWNLOAD" 93 | slcDir = scratchDir + '/' + projectName + '/SLC' 94 | 95 | if not os.path.isdir(slcDir): 96 | call_str= 'mkdir ' +slcDir 97 | os.system(call_str) 98 | 99 | os.chdir(downDir) 100 | 101 | call_str = 'ls > tt0' 102 | os.system(call_str) 103 | 104 | call_str = 'grep SAR_IMS_1P tt0 >tt1' 105 | os.system(call_str) 106 | 107 | call_str = "awk -F_ '{print $3}' tt1 > tt2 " 108 | os.system(call_str) 109 | 110 | call_str = "awk -FSA '{print $2}' tt2 > ttt" 111 | os.system(call_str) 112 | 113 | call_str = 'sort ttt | uniq > ttm' 114 | os.system(call_str) 115 | 116 | AA= np.loadtxt('ttm',dtype=np.str) 117 | Na = AA.size 118 | 119 | for i in range(Na): 120 | call_str = 'Down2SLC_ERS_Cat.py ' + projectName + ' ' + AA[i] 121 | print(call_str) 122 | call_str = 'Down2SLC_ERS_Cat.py ' + projectName + ' ' + AA[i] + ' >/dev/null' 123 | os.system(call_str) 124 | 125 | 126 | print("Down to SLC for %s is done! " % projectName) 127 | sys.exit(1) 128 | 129 | if __name__ == '__main__': 130 | main(sys.argv[:]) 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /pyint/ERS_DEOS.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v1.0 ### 4 | ### Copy Right (c): 2017, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : Central South University & University of Miami ### 8 | ################################################################# 9 | 10 | import numpy as np 11 | import os 12 | import sys 13 | import subprocess 14 | import getopt 15 | import time 16 | import glob 17 | import argparse 18 | import linecache 19 | 20 | def StrNum(S): 21 | S = str(S) 22 | if len(S)==1: 23 | S='0' +S 24 | return S 25 | 26 | def UseGamma(inFile, task, keyword): 27 | if task == "read": 28 | f = open(inFile, "r") 29 | while 1: 30 | line = f.readline() 31 | if not line: break 32 | if line.count(keyword) == 1: 33 | strtemp = line.split(":") 34 | value = strtemp[1].strip() 35 | return value 36 | print("Keyword " + keyword + " doesn't exist in " + inFile) 37 | f.close() 38 | 39 | ######################################################################### 40 | 41 | INTRODUCTION = ''' 42 | ############################################################################# 43 | Copy Right(c): 2017-2019, Yunmeng Cao @PyINT v1.0 44 | 45 | Download precise ERS orbit data from Delft (http://www.deos.tudelft.nl/). 46 | Correct the orbit parameters using DELFT_vec2 47 | 48 | ftp://dutlru2.lr.tudelft.nl/pub/orbits/ODR.ERS-2/dgm-e04/arclist 49 | 50 | 51 | ''' 52 | 53 | EXAMPLE = ''' 54 | Usage: 55 | ERS_DEOS.py projectName Date 56 | 57 | Examples: 58 | ERS_DEOS.py AqabaERSA 960101 59 | 60 | ############################################################################## 61 | ''' 62 | 63 | 64 | def cmdLineParse(): 65 | parser = argparse.ArgumentParser(description='Download (and correct) precise ERS orbit data.',\ 66 | formatter_class=argparse.RawTextHelpFormatter,\ 67 | epilog=INTRODUCTION+'\n'+EXAMPLE) 68 | 69 | parser.add_argument('projectName',help='project name') 70 | parser.add_argument('date',help='date of the ERS data') 71 | 72 | inps = parser.parse_args() 73 | return inps 74 | 75 | ################################################################################ 76 | 77 | 78 | def main(argv): 79 | 80 | total = time.time() 81 | inps = cmdLineParse() 82 | 83 | projectName = inps.projectName 84 | DATE = inps.date 85 | scratchDir = os.getenv('SCRATCHDIR') 86 | templateDir = os.getenv('TEMPLATEDIR') 87 | slcDir = scratchDir + '/' + projectName + '/SLC' 88 | projDir = scratchDir + '/' + projectName 89 | 90 | ERS1_Orb_Dir = scratchDir + '/' + projectName + '/ERS1_Orb' 91 | ERS2_Orb_Dir = scratchDir + '/' + projectName + '/ERS2_Orb' 92 | 93 | if not os.path.isdir(ERS1_Orb_Dir): 94 | call_str = 'mkdir ' + ERS1_Orb_Dir 95 | os.system(call_str) 96 | 97 | if not os.path.isdir(ERS2_Orb_Dir): 98 | call_str = 'mkdir ' + ERS2_Orb_Dir 99 | os.system(call_str) 100 | 101 | ERS1_Orb_list = ERS1_Orb_Dir + '/ERS1_Orb_list' 102 | ERS2_Orb_list = ERS2_Orb_Dir + '/ERS2_Orb_list' 103 | 104 | os.chdir(ERS1_Orb_Dir) 105 | if not os.path.isfile(ERS1_Orb_list): 106 | Url = 'ftp://dutlru2.lr.tudelft.nl/pub/orbits/ODR.ERS-1/dgm-e04/arclist' 107 | call_str = 'wget ' + Url + ' -O ERS1_Orb_list' 108 | os.system(call_str) 109 | 110 | call_str = 'cp ERS1_Orb_list arclist' 111 | os.system(call_str) 112 | 113 | os.chdir(ERS2_Orb_Dir) 114 | if not os.path.isfile(ERS2_Orb_list): 115 | Url = 'ftp://dutlru2.lr.tudelft.nl/pub/orbits/ODR.ERS-2/dgm-e04/arclist' 116 | call_str = 'wget ' + Url + ' -O ERS2_Orb_list' 117 | os.system(call_str) 118 | 119 | call_str = 'cp ERS2_Orb_list arclist' 120 | os.system(call_str) 121 | 122 | if len(DATE)==8: 123 | DATE6 = DATE[2:8] 124 | else: 125 | DATE6 = DATE 126 | 127 | slcDir1 = slcDir + '/' + DATE6 128 | slcpar = slcDir1 + '/' + DATE6 + '.slc.par' 129 | Title = UseGamma(slcpar, 'read', 'title:') 130 | if 'E1' in Title: 131 | Flag = 'ERS1' 132 | Url = 'ftp://dutlru2.lr.tudelft.nl/pub/orbits/ODR.ERS-1/dgm-e04/' 133 | List = ERS1_Orb_list 134 | Dir = ERS1_Orb_Dir 135 | elif 'E2' in Title: 136 | Flag = 'ERS2' 137 | Url = 'ftp://dutlru2.lr.tudelft.nl/pub/orbits/ODR.ERS-2/dgm-e04/' 138 | List = ERS2_Orb_list 139 | Dir = ERS2_Orb_Dir 140 | else: 141 | print('The SAR data is invalid.') 142 | sys.exit(1) 143 | 144 | if len(DATE)==6: 145 | A0 = int(DATE[0:2]) 146 | if A0 < 50: 147 | DATE = '20' + DATE 148 | else: 149 | DATA = '19' + DATE 150 | 151 | YYMM = DATE6[0:2] + DATE6[2:4] 152 | 153 | call_str = 'grep ' + YYMM + ' ' + List + ' > list0' 154 | os.system(call_str) 155 | 156 | call_str = "awk '{print $12}' list0 > start_end" 157 | os.system(call_str) 158 | 159 | call_str = "awk '{print $1}' list0 > vec_num" 160 | os.system(call_str) 161 | 162 | AA= np.loadtxt('start_end',dtype=np.str) 163 | Na = AA.size 164 | 165 | print(AA) 166 | 167 | A_num= np.loadtxt('vec_num',dtype=np.str) 168 | Na_num = A_num.size 169 | 170 | for i in range(Na-1): 171 | A0 = AA[i] 172 | A1 = AA[i+1] 173 | print(DATE6) 174 | print(A0) 175 | print(A1) 176 | if int(DATE6)==int(A0): 177 | m = i 178 | elif int(DATE6)==int(A1): 179 | m = i+1 180 | elif int(A0) < int(DATE6) < int(A1): 181 | m = i 182 | 183 | FF = A_num[int(m)] 184 | SS = Url + 'ODR.' + FF 185 | print(SS) 186 | 187 | call_str = 'wget -q --no-check-certificate ' + SS + ' -P ' + Dir 188 | os.system(call_str) 189 | 190 | 191 | print("Download precise DEFT orbital data for %s is done." % DATE) 192 | sys.exit(1) 193 | 194 | if __name__ == '__main__': 195 | main(sys.argv[:]) 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | -------------------------------------------------------------------------------- /pyint/ERS_orb_cor.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v1.0 ### 4 | ### Copy Right (c): 2017, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : Central South University & University of Miami ### 8 | ################################################################# 9 | 10 | import numpy as np 11 | import os 12 | import sys 13 | import subprocess 14 | import getopt 15 | import time 16 | import glob 17 | import argparse 18 | import linecache 19 | 20 | def StrNum(S): 21 | S = str(S) 22 | if len(S)==1: 23 | S='0' +S 24 | return S 25 | 26 | def UseGamma(inFile, task, keyword): 27 | if task == "read": 28 | f = open(inFile, "r") 29 | while 1: 30 | line = f.readline() 31 | if not line: break 32 | if line.count(keyword) == 1: 33 | strtemp = line.split(":") 34 | value = strtemp[1].strip() 35 | return value 36 | print("Keyword " + keyword + " doesn't exist in " + inFile) 37 | f.close() 38 | 39 | ######################################################################### 40 | 41 | INTRODUCTION = ''' 42 | ############################################################################# 43 | Copy Right(c): 2017-2019, Yunmeng Cao @PyINT v1.0 44 | 45 | Precise ERS orbit data from Delft (http://www.deos.tudelft.nl/). 46 | Correct the orbit parameters using DELFT_vec2 47 | 48 | ''' 49 | 50 | EXAMPLE = ''' 51 | Usage: 52 | ERS_orb_cor.py projectName Date 53 | 54 | Examples: 55 | ERS_orb_cor.py AqabaERSA 960101 56 | 57 | ############################################################################## 58 | ''' 59 | 60 | 61 | def cmdLineParse(): 62 | parser = argparse.ArgumentParser(description='Download (and correct) precise ERS orbit data.',\ 63 | formatter_class=argparse.RawTextHelpFormatter,\ 64 | epilog=INTRODUCTION+'\n'+EXAMPLE) 65 | 66 | parser.add_argument('projectName',help='project name') 67 | parser.add_argument('date',help='date of the ERS data') 68 | 69 | inps = parser.parse_args() 70 | return inps 71 | 72 | ################################################################################ 73 | 74 | 75 | def main(argv): 76 | 77 | total = time.time() 78 | inps = cmdLineParse() 79 | 80 | projectName = inps.projectName 81 | DATE = inps.date 82 | scratchDir = os.getenv('SCRATCHDIR') 83 | templateDir = os.getenv('TEMPLATEDIR') 84 | Ers1OrbDir = os.getenv('ERS1ORBDIR') 85 | Ers2OrbDir = os.getenv('ERS2ORBDIR') 86 | 87 | slcDir = scratchDir + '/' + projectName + '/SLC' 88 | projDir = scratchDir + '/' + projectName 89 | 90 | 91 | if len(DATE)==8: 92 | DATE6 = DATE[2:8] 93 | else: 94 | DATE6 = DATE 95 | 96 | slcDir1 = slcDir + '/' + DATE6 97 | slcpar = slcDir1 + '/' + DATE6 + '.slc.par' 98 | Title = UseGamma(slcpar, 'read', 'title:') 99 | if 'E1' in Title: 100 | Flag = 'ERS1' 101 | #Url = 'ftp://dutlru2.lr.tudelft.nl/pub/orbits/ODR.ERS-1/dgm-e04/' 102 | #List = ERS1_Orb_list 103 | Dir = Ers1OrbDir 104 | elif 'E2' in Title: 105 | Flag = 'ERS2' 106 | #Url = 'ftp://dutlru2.lr.tudelft.nl/pub/orbits/ODR.ERS-2/dgm-e04/' 107 | #List = ERS2_Orb_list 108 | Dir = Ers2OrbDir 109 | else: 110 | print('The SAR data is invalid.') 111 | sys.exit(1) 112 | 113 | call_str = 'DELFT_vec2 ' + slcpar + ' ' + Dir + ' 30' 114 | os.system(call_str) 115 | 116 | 117 | print("Using DEFT orbital data for %s is done." % DATE) 118 | sys.exit(1) 119 | 120 | if __name__ == '__main__': 121 | main(sys.argv[:]) 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /pyint/ERS_orb_cor_all.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v1.0 ### 4 | ### Copy Right (c): 2017, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : Central South University & University of Miami ### 8 | ################################################################# 9 | 10 | import numpy as np 11 | import os 12 | import sys 13 | import subprocess 14 | import getopt 15 | import time 16 | import glob 17 | import argparse 18 | import linecache 19 | 20 | def StrNum(S): 21 | S = str(S) 22 | if len(S)==1: 23 | S='0' +S 24 | return S 25 | 26 | def UseGamma(inFile, task, keyword): 27 | if task == "read": 28 | f = open(inFile, "r") 29 | while 1: 30 | line = f.readline() 31 | if not line: break 32 | if line.count(keyword) == 1: 33 | strtemp = line.split(":") 34 | value = strtemp[1].strip() 35 | return value 36 | print("Keyword " + keyword + " doesn't exist in " + inFile) 37 | f.close() 38 | 39 | def is_number(s): 40 | try: 41 | int(s) 42 | return True 43 | except ValueError: 44 | return False 45 | 46 | ######################################################################### 47 | 48 | INTRODUCTION = ''' 49 | ############################################################################# 50 | Copy Right(c): 2017-2019, Yunmeng Cao @PyINT v1.0 51 | 52 | Precise ERS orbit data from Delft (http://www.deos.tudelft.nl/). 53 | Correct the orbit parameters using DELFT_vec2 54 | 55 | ''' 56 | 57 | EXAMPLE = ''' 58 | Usage: 59 | ERS_orb_cor_all.py projectName 60 | 61 | Examples: 62 | ERS_orb_cor_all.py AqabaERSA 63 | 64 | ############################################################################## 65 | ''' 66 | 67 | 68 | def cmdLineParse(): 69 | parser = argparse.ArgumentParser(description='Download (and correct) precise ERS orbit data.',\ 70 | formatter_class=argparse.RawTextHelpFormatter,\ 71 | epilog=INTRODUCTION+'\n'+EXAMPLE) 72 | 73 | parser.add_argument('projectName',help='project name') 74 | 75 | inps = parser.parse_args() 76 | return inps 77 | 78 | ################################################################################ 79 | 80 | 81 | def main(argv): 82 | 83 | total = time.time() 84 | inps = cmdLineParse() 85 | 86 | projectName = inps.projectName 87 | scratchDir = os.getenv('SCRATCHDIR') 88 | templateDir = os.getenv('TEMPLATEDIR') 89 | slcDir = scratchDir + '/' + projectName + '/SLC' 90 | 91 | ListSLC = os.listdir(slcDir) 92 | Datelist = [] 93 | SLCfile = [] 94 | SLCParfile = [] 95 | 96 | 97 | for kk in range(len(ListSLC)): 98 | if ( is_number(ListSLC[kk]) and len(ListSLC[kk])==6 ): # if SAR date number is 8, 6 should change to 8. 99 | DD=ListSLC[kk] 100 | Year=int(DD[0:2]) 101 | Month = int(DD[2:4]) 102 | Day = int(DD[4:6]) 103 | Datelist.append(ListSLC[kk]) 104 | N = len(Datelist) 105 | 106 | for i in range(N): 107 | call_str = 'ERS_orb_cor.py ' + projectName + ' ' + Datelist[i] 108 | print(call_str) 109 | os.system(call_str) 110 | 111 | print("Using DEFT orbital data for project %s is done." % projectName) 112 | sys.exit(1) 113 | 114 | if __name__ == '__main__': 115 | main(sys.argv[:]) 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /pyint/ERS_orb_cor_par.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v1.0 ### 4 | ### Copy Right (c): 2017, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : Central South University & University of Miami ### 8 | ################################################################# 9 | 10 | import numpy as np 11 | import os 12 | import sys 13 | import subprocess 14 | import getopt 15 | import time 16 | import glob 17 | import argparse 18 | import linecache 19 | 20 | def StrNum(S): 21 | S = str(S) 22 | if len(S)==1: 23 | S='0' +S 24 | return S 25 | 26 | def UseGamma(inFile, task, keyword): 27 | if task == "read": 28 | f = open(inFile, "r") 29 | while 1: 30 | line = f.readline() 31 | if not line: break 32 | if line.count(keyword) == 1: 33 | strtemp = line.split(":") 34 | value = strtemp[1].strip() 35 | return value 36 | print("Keyword " + keyword + " doesn't exist in " + inFile) 37 | f.close() 38 | 39 | ######################################################################### 40 | 41 | INTRODUCTION = ''' 42 | ############################################################################# 43 | Copy Right(c): 2017-2019, Yunmeng Cao @PyINT v1.0 44 | 45 | Precise ERS orbit data from Delft (http://www.deos.tudelft.nl/). 46 | Correct the orbit parameters using DELFT_vec2 47 | 48 | ''' 49 | 50 | EXAMPLE = ''' 51 | Usage: 52 | ERS_orb_cor_par.py SLC_par 53 | 54 | Examples: 55 | ERS_orb_cor_par.py 960101.slc.par 56 | 57 | ############################################################################## 58 | ''' 59 | 60 | 61 | def cmdLineParse(): 62 | parser = argparse.ArgumentParser(description='Download (and correct) precise ERS orbit data.',\ 63 | formatter_class=argparse.RawTextHelpFormatter,\ 64 | epilog=INTRODUCTION+'\n'+EXAMPLE) 65 | 66 | parser.add_argument('slc_par',help='slc par file') 67 | 68 | inps = parser.parse_args() 69 | return inps 70 | 71 | ################################################################################ 72 | 73 | 74 | def main(argv): 75 | 76 | total = time.time() 77 | inps = cmdLineParse() 78 | 79 | slcpar = inps.slc_par 80 | 81 | Ers1OrbDir = os.getenv('ERS1ORBDIR') 82 | Ers2OrbDir = os.getenv('ERS2ORBDIR') 83 | 84 | Title = UseGamma(slcpar, 'read', 'title:') 85 | if 'E1' in Title: 86 | Flag = 'ERS1' 87 | #Url = 'ftp://dutlru2.lr.tudelft.nl/pub/orbits/ODR.ERS-1/dgm-e04/' 88 | #List = ERS1_Orb_list 89 | Dir = Ers1OrbDir 90 | elif 'E2' in Title: 91 | Flag = 'ERS2' 92 | #Url = 'ftp://dutlru2.lr.tudelft.nl/pub/orbits/ODR.ERS-2/dgm-e04/' 93 | #List = ERS2_Orb_list 94 | Dir = Ers2OrbDir 95 | else: 96 | print('The SAR data is invalid.') 97 | sys.exit(1) 98 | 99 | call_str = 'DELFT_vec2 ' + slcpar + ' ' + Dir 100 | os.system(call_str) 101 | 102 | 103 | print("Using DEFT orbital data for %s is done." % slcpar) 104 | sys.exit(1) 105 | 106 | if __name__ == '__main__': 107 | main(sys.argv[:]) 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /pyint/Get_off_std.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v1.0 ### 4 | ### Copy Right (c): 2017, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : Central South University & University of Miami ### 8 | ################################################################# 9 | 10 | 11 | import os 12 | import sys 13 | import glob 14 | import time 15 | import argparse 16 | 17 | import h5py 18 | import numpy as np 19 | 20 | def check_variable_name(path): 21 | s=path.split("/")[0] 22 | if len(s)>0 and s[0]=="$": 23 | p0=os.getenv(s[1:]) 24 | path=path.replace(path.split("/")[0],p0) 25 | return path 26 | 27 | def read_template(File, delimiter='='): 28 | '''Reads the template file into a python dictionary structure. 29 | Input : string, full path to the template file 30 | Output: dictionary, pysar template content 31 | Example: 32 | tmpl = read_template(KyushuT424F610_640AlosA.template) 33 | tmpl = read_template(R1_54014_ST5_L0_F898.000.pi, ':') 34 | ''' 35 | template_dict = {} 36 | for line in open(File): 37 | line = line.strip() 38 | c = [i.strip() for i in line.split(delimiter, 1)] #split on the 1st occurrence of delimiter 39 | if len(c) < 2 or line.startswith('%') or line.startswith('#'): 40 | next #ignore commented lines or those without variables 41 | else: 42 | atrName = c[0] 43 | atrValue = str.replace(c[1],'\n','').split("#")[0].strip() 44 | atrValue = check_variable_name(atrValue) 45 | template_dict[atrName] = atrValue 46 | return template_dict 47 | 48 | 49 | def UseGamma(inFile, task, keyword): 50 | if task == "read": 51 | f = open(inFile, "r") 52 | while 1: 53 | line = f.readline() 54 | if not line: break 55 | if line.count(keyword) == 1: 56 | strtemp = line.split(":") 57 | value = strtemp[1].strip() 58 | return value 59 | print("Keyword " + keyword + " doesn't exist in " + inFile) 60 | f.close() 61 | 62 | def UseGamma2(inFile, task, keyword): 63 | if task == "read": 64 | f = open(inFile, "r") 65 | while 1: 66 | line = f.readline() 67 | if not line: break 68 | if line.count(keyword) == 1: 69 | strtemp = line.split(":") 70 | value = strtemp[2].strip() 71 | return value 72 | print("Keyword " + keyword + " doesn't exist in " + inFile) 73 | f.close() 74 | 75 | def usage(): 76 | print(''' 77 | ****************************************************************************************************** 78 | 79 | Get co-registration standard deviation of SLCs for one project 80 | 81 | usage: 82 | 83 | GenerateRSC_Gamma.py projectName 84 | 85 | e.g. Get_off_std.py GalapagosT061EnvA 86 | 87 | ******************************************************************************************************* 88 | ''') 89 | 90 | def main(argv): 91 | 92 | if len(sys.argv)==2: 93 | if argv[0] in ['-h','--help']: usage(); sys.exit(1) 94 | else: projectName=sys.argv[1] 95 | else: 96 | usage();sys.exit(1) 97 | 98 | scratchDir = os.getenv('SCRATCHDIR') 99 | OFFDir = scratchDir + '/' + projectName + '/RSLC' 100 | OFFSTR = OFFDir + '/*.off_std' 101 | OFFFile = glob.glob(OFFSTR) 102 | STD_TXT ='COREG_STD_ALL' 103 | os.chdir(OFFDir) 104 | if os.path.isfile(STD_TXT): 105 | os.remove(STD_TXT) 106 | 107 | for ff in OFFFile: 108 | OFF_STD = ff 109 | NM = os.path.basename(ff).split('.')[0] 110 | RR = UseGamma(OFF_STD,'read','final range offset poly. coeff.:') 111 | cor_rg = RR.split(' ')[0] 112 | 113 | AA = UseGamma(OFF_STD,'read','final azimuth offset poly. coeff.:') 114 | cor_az = AA.split(' ')[0] 115 | 116 | STDRR = UseGamma(OFF_STD,'read','final model fit std. dev. (samples) range:') 117 | std_rg=STDRR.split(' ')[0] 118 | 119 | std_az = UseGamma2(OFF_STD,'read','final model fit std. dev. (samples) range:') 120 | 121 | STR = NM + ' ' + cor_rg + ' ' + cor_az + ' ' + std_rg + ' ' + std_az 122 | call_str ='echo ' + STR + ' >> ' + STD_TXT 123 | os.system(call_str) 124 | 125 | 126 | sys.exit(1) 127 | 128 | 129 | if __name__ == '__main__': 130 | main(sys.argv[1:]) 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /pyint/NameChange.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | #''' 3 | ################################################################################### 4 | # # 5 | # Author: Yun-Meng Cao # 6 | # Email : ymcmrs@gmail.com # 7 | # Date : Mar, 2017 # 8 | # # 9 | # Select Interferometry-Pairs from time series SAR images # 10 | # # 11 | ################################################################################### 12 | #''' 13 | import numpy as np 14 | import os 15 | import sys 16 | import subprocess 17 | import getopt 18 | import time 19 | import glob 20 | 21 | def check_variable_name(path): 22 | s=path.split("/")[0] 23 | if len(s)>0 and s[0]=="$": 24 | p0=os.getenv(s[1:]) 25 | path=path.replace(path.split("/")[0],p0) 26 | return path 27 | 28 | def read_template(File, delimiter='='): 29 | '''Reads the template file into a python dictionary structure. 30 | Input : string, full path to the template file 31 | Output: dictionary, pysar template content 32 | Example: 33 | tmpl = read_template(KyushuT424F610_640AlosA.template) 34 | tmpl = read_template(R1_54014_ST5_L0_F898.000.pi, ':') 35 | ''' 36 | template_dict = {} 37 | for line in open(File): 38 | line = line.strip() 39 | c = [i.strip() for i in line.split(delimiter, 1)] #split on the 1st occurrence of delimiter 40 | if len(c) < 2 or line.startswith('%') or line.startswith('#'): 41 | next #ignore commented lines or those without variables 42 | else: 43 | atrName = c[0] 44 | atrValue = str.replace(c[1],'\n','').split("#")[0].strip() 45 | atrValue = check_variable_name(atrValue) 46 | template_dict[atrName] = atrValue 47 | return template_dict 48 | 49 | 50 | def is_number(s): 51 | try: 52 | int(s) 53 | return True 54 | except ValueError: 55 | return False 56 | 57 | def add_zero(s): 58 | if len(s)==1: 59 | s="000"+s 60 | elif len(s)==2: 61 | s="00"+s 62 | elif len(s)==3: 63 | s="0"+s 64 | return s 65 | 66 | 67 | def usage(): 68 | print(''' 69 | ****************************************************************************************************** 70 | 71 | Select interferometry pairs from time series SAR images 72 | 73 | usage: 74 | 75 | SelectPairs_Gamma.py ProjectName 76 | 77 | e.g. SelectPairs_Gamma.py PacayaT163TsxHhA 78 | 79 | 80 | ******************************************************************************************************* 81 | ''') 82 | 83 | def main(argv): 84 | 85 | if len(sys.argv)==2: 86 | if argv[0] in ['-h','--help']: usage(); sys.exit(1) 87 | else: projectName=sys.argv[1] 88 | else: 89 | usage();sys.exit(1) 90 | 91 | scratchDir = os.getenv('SCRATCHDIR') 92 | templateDir = os.getenv('TEMPLATEDIR') 93 | templateFile = templateDir + "/" + projectName + ".template" 94 | templateContents=read_template(templateFile) 95 | processDir = scratchDir + '/' + projectName + "/PROCESS" 96 | slcDir = scratchDir + '/' + projectName + "/SLC" 97 | 98 | if not os.path.isdir(processDir): 99 | call_str = 'mkdir ' + processDir 100 | os.system(call_str) 101 | 102 | 103 | if 'JOB' in templateContents: JOB = templateContents['JOB'] 104 | else: JOB = 'IFG' 105 | 106 | INF=JOB 107 | if INF=='IFG': 108 | Suffix=[''] 109 | print("Time series interferograms will be processed!") 110 | elif INF=='MAI': 111 | Suffix=['.F','.B'] 112 | print("Time series multi-aperture interferograms will be processed!") 113 | elif INF=='RSI': 114 | Suffix=['.HF','.LF'] 115 | print("Time series range split-spectrum interferograms will be processed!") 116 | else: 117 | print("The folder name %s cannot be identified !" % igramDir) 118 | usage();sys.exit(1) 119 | 120 | # define files 121 | 122 | SLC_Tab = processDir + "/SLC_Tab" 123 | TS_Berp = processDir + "/TS_Berp" 124 | TS_Itab = processDir + "/TS_Itab" 125 | itab_type = '1' 126 | pltflg = '0' 127 | 128 | if 'Max_Spacial_Baseline' in templateContents: MaxSB=templateContents['Max_Spacial_Baseline'] 129 | else: 130 | print("Max_Spacial_Baseline is not found in template!! ") 131 | print("500m is chosen as the threshold for spatial baseline!") 132 | MaxSB = '500' 133 | 134 | if 'Max_Temporal_Baseline' in templateContents: MaxTB=templateContents['Max_Temporal_Baseline'] 135 | else: 136 | print("Max_Temporal_Baseline is not found in template!! ") 137 | print("500 days is chosen as the threshold for temporal baseline!") 138 | MaxTB = '500' 139 | 140 | 141 | # extract available SAR images slc and slc_par 142 | ListSLC = os.listdir(slcDir) 143 | Datelist = [] 144 | SLCfile = [] 145 | SLCParfile = [] 146 | 147 | print("All of the available SAR acquisition datelist is :") 148 | for kk in range(len(ListSLC)): 149 | if ( is_number(ListSLC[kk]) and len(ListSLC[kk])==6 ): # if SAR date number is 8, 6 should change to 8. 150 | DD=ListSLC[kk] 151 | Year=int(DD[0:2]) 152 | Month = int(DD[2:4]) 153 | Day = int(DD[4:6]) 154 | if ( 0 < Year < 20 and 0 < Month < 13 and 0 < Day < 32 ): 155 | Datelist.append(ListSLC[kk]) 156 | print(ListSLC[kk]) 157 | DateDir = slcDir+'/'+ListSLC[kk] 158 | SLC0 = glob.glob(DateDir+'/*slc')[0] 159 | SLCPar0 = glob.glob(DateDir+'/*slc.par')[0] 160 | 161 | str_slc = slcDir + "/" + ListSLC[kk] +"/" + ListSLC[kk] + ".slc" 162 | str_slc_par = slcDir + "/" + ListSLC[kk] +"/" + ListSLC[kk] + ".slc.par" 163 | 164 | call_str = 'mv ' + SLC0 + ' ' + str_slc 165 | os.system(call_str) 166 | 167 | call_str = 'mv ' + SLCPar0 + ' ' + str_slc_par 168 | os.system(call_str) 169 | 170 | SLCfile.append(str_slc) 171 | SLCParfile.append(str_slc_par) 172 | 173 | 174 | print("Change name of SLC file is done! ") 175 | sys.exit(1) 176 | 177 | if __name__ == '__main__': 178 | main(sys.argv[:]) 179 | 180 | 181 | -------------------------------------------------------------------------------- /pyint/Raw2SLC_ERS_Cat_All.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | #''' 3 | ################################################################################## 4 | # # 5 | # Author: Yun-Meng Cao # 6 | # Email : ymcmrs@gmail.com # 7 | # Date : March, 2017 # 8 | # # 9 | # Generate Sentinel SLC from the downloaded data # 10 | # # 11 | ################################################################################## 12 | #''' 13 | import numpy as np 14 | import os 15 | import sys 16 | import subprocess 17 | import getopt 18 | import time 19 | import glob 20 | 21 | def check_variable_name(path): 22 | s=path.split("/")[0] 23 | if len(s)>0 and s[0]=="$": 24 | p0=os.getenv(s[1:]) 25 | path=path.replace(path.split("/")[0],p0) 26 | return path 27 | 28 | def read_template(File, delimiter='='): 29 | '''Reads the template file into a python dictionary structure. 30 | Input : string, full path to the template file 31 | Output: dictionary, pysar template content 32 | Example: 33 | tmpl = read_template(KyushuT424F610_640AlosA.template) 34 | tmpl = read_template(R1_54014_ST5_L0_F898.000.pi, ':') 35 | ''' 36 | template_dict = {} 37 | for line in open(File): 38 | line = line.strip() 39 | c = [i.strip() for i in line.split(delimiter, 1)] #split on the 1st occurrence of delimiter 40 | if len(c) < 2 or line.startswith('%') or line.startswith('#'): 41 | next #ignore commented lines or those without variables 42 | else: 43 | atrName = c[0] 44 | atrValue = str.replace(c[1],'\n','').split("#")[0].strip() 45 | atrValue = check_variable_name(atrValue) 46 | template_dict[atrName] = atrValue 47 | return template_dict 48 | 49 | def UseGamma(inFile, task, keyword): 50 | if task == "read": 51 | f = open(inFile, "r") 52 | while 1: 53 | line = f.readline() 54 | if not line: break 55 | if line.count(keyword) == 1: 56 | strtemp = line.split(":") 57 | value = strtemp[1].strip() 58 | return value 59 | print("Keyword " + keyword + " doesn't exist in " + inFile) 60 | f.close 61 | 62 | def rm(TXT): 63 | call_str = 'rm ' + TXT 64 | os.system(call_str) 65 | 66 | def usage(): 67 | print(''' 68 | ****************************************************************************************************** 69 | 70 | Cat ERS SLC from ERS raw data with ENVISAT format. 71 | 72 | usage: 73 | 74 | Raw2SLC_ERS_Cat_All.py ProjectName 75 | 76 | e.g. Raw2SLC_ERS_Cat_All.py CotopaxiT120ERSA 77 | 78 | ******************************************************************************************************* 79 | ''') 80 | 81 | def main(argv): 82 | 83 | if len(sys.argv)==2: 84 | projectName = sys.argv[1] 85 | else: 86 | usage();sys.exit(1) 87 | 88 | scratchDir = os.getenv('SCRATCHDIR') 89 | templateDir = os.getenv('TEMPLATEDIR') 90 | 91 | projectDir = scratchDir + '/' + projectName 92 | downDir = scratchDir + '/' + projectName + "/DOWNLOAD" 93 | slcDir = scratchDir + '/' + projectName + '/SLC' 94 | 95 | if not os.path.isdir(slcDir): 96 | call_str= 'mkdir ' +slcDir 97 | os.system(call_str) 98 | 99 | os.chdir(downDir) 100 | 101 | call_str = 'ls > tt0' 102 | os.system(call_str) 103 | 104 | call_str = 'grep SAR_IM tt0 >tt1' 105 | os.system(call_str) 106 | 107 | call_str = "awk -F0PWDSI '{print $2}' tt1 > tt2 " 108 | os.system(call_str) 109 | 110 | call_str = "awk -F_ '{print $1}' tt2 > ttt" 111 | os.system(call_str) 112 | 113 | call_str = 'sort ttt | uniq > ttm' 114 | os.system(call_str) 115 | 116 | AA= np.loadtxt('ttm',dtype=np.str) 117 | Na = AA.size 118 | 119 | for i in range(Na): 120 | call_str = 'Raw2SLC_ERS_Cat.py ' + projectName + ' ' + AA[i] 121 | print(call_str) 122 | call_str = 'Raw2SLC_ERS_Cat.py ' + projectName + ' ' + AA[i] + ' >/dev/null' 123 | os.system(call_str) 124 | 125 | 126 | print("Down to SLC for %s is done! " % projectName) 127 | sys.exit(1) 128 | 129 | if __name__ == '__main__': 130 | main(sys.argv[:]) 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /pyint/SAR2LATLON.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | #''' 4 | ################################################################################## 5 | ### Author: Yun-Meng Cao ### 6 | ### Date : March, 2017 ### 7 | ### Email : ymcmrs@gmail.com ### 8 | ### Transform SAR coordinates into LAT/LON coordinates based on lookup table ### 9 | ################################################################################## 10 | #''' 11 | 12 | import os 13 | import sys 14 | import glob 15 | import time 16 | import argparse 17 | 18 | import h5py 19 | import numpy as np 20 | 21 | def check_variable_name(path): 22 | s=path.split("/")[0] 23 | if len(s)>0 and s[0]=="$": 24 | p0=os.getenv(s[1:]) 25 | path=path.replace(path.split("/")[0],p0) 26 | return path 27 | 28 | def read_template(File, delimiter='='): 29 | '''Reads the template file into a python dictionary structure. 30 | Input : string, full path to the template file 31 | Output: dictionary, pysar template content 32 | Example: 33 | tmpl = read_template(KyushuT424F610_640AlosA.template) 34 | tmpl = read_template(R1_54014_ST5_L0_F898.000.pi, ':') 35 | ''' 36 | template_dict = {} 37 | for line in open(File): 38 | line = line.strip() 39 | c = [i.strip() for i in line.split(delimiter, 1)] #split on the 1st occurrence of delimiter 40 | if len(c) < 2 or line.startswith('%') or line.startswith('#'): 41 | next #ignore commented lines or those without variables 42 | else: 43 | atrName = c[0] 44 | atrValue = str.replace(c[1],'\n','').split("#")[0].strip() 45 | atrValue = check_variable_name(atrValue) 46 | template_dict[atrName] = atrValue 47 | return template_dict 48 | 49 | def read_data(inFile, dtype, nWidth, nLength): 50 | data = np.fromfile(inFile, dtype, int(nLength)*int(nWidth)).reshape(int(nLength),int(nWidth)) 51 | 52 | return data 53 | 54 | def is_number(s): 55 | try: 56 | int(s) 57 | return True 58 | except ValueError: 59 | return False 60 | 61 | def add_zero(s): 62 | if len(s)==1: 63 | s="000"+s 64 | elif len(s)==2: 65 | s="00"+s 66 | elif len(s)==3: 67 | s="0"+s 68 | return s 69 | 70 | 71 | def UseGamma(inFile, task, keyword): 72 | if task == "read": 73 | f = open(inFile, "r") 74 | while 1: 75 | line = f.readline() 76 | if not line: break 77 | if line.count(keyword) == 1: 78 | strtemp = line.split(":") 79 | value = strtemp[1].strip() 80 | return value 81 | print("Keyword " + keyword + " doesn't exist in " + inFile) 82 | f.close() 83 | 84 | 85 | def usage(): 86 | print(''' 87 | ****************************************************************************************************** 88 | 89 | Transform SAR coordinates into LAT/LON coordinates based on lookup table 90 | 91 | usage: 92 | 93 | SAR2LATLON.py Range Azimuth LookupTableFile UTMDEMpar 94 | 95 | e.g. SAR2LATLON.py 1500 1000 /Yunmeng/20201230.utm_to_rdc /Yunmeng/20201230.dem.utm.par 96 | 97 | 98 | ******************************************************************************************************* 99 | ''') 100 | 101 | def main(argv): 102 | 103 | if len(sys.argv)==5: 104 | Range = sys.argv[1] 105 | Azimuth = sys.argv[2] 106 | LtFile = sys.argv[3] 107 | UTMPAR = sys.argv[4] 108 | else: 109 | usage();sys.exit(1) 110 | 111 | nWidthUTM = UseGamma(UTMPAR, 'read', 'width:') 112 | nLineUTM = UseGamma(UTMPAR, 'read', 'nlines:') 113 | 114 | Corner_LAT = UseGamma(UTMPAR, 'read', 'corner_lat:') 115 | Corner_LON = UseGamma(UTMPAR, 'read', 'corner_lon:') 116 | 117 | Corner_LAT =Corner_LAT.split(' ')[0] 118 | Corner_LON =Corner_LON.split(' ')[0] 119 | 120 | post_Lat = UseGamma(UTMPAR, 'read', 'post_lat:') 121 | post_Lon = UseGamma(UTMPAR, 'read', 'post_lon:') 122 | 123 | post_Lat =post_Lat.split(' ')[0] 124 | post_Lon =post_Lon.split(' ')[0] 125 | data = read_data(LtFile,'>c8',nWidthUTM,nLineUTM) # real: range imaginary: azimuth 126 | 127 | Range_LT = data.real 128 | Azimuth_LT = data.imag 129 | 130 | CPX_input =complex(Range + '+' + Azimuth+'j') 131 | 132 | DD = abs(CPX_input - data) 133 | 134 | LL= abs(DD) 135 | IDX= np.where(LL == LL.min()) 136 | Lat_out = float(Corner_LAT) + IDX[0]*float(post_Lat) 137 | Lon_out = float(Corner_LON) + IDX[1]*float(post_Lon) 138 | 139 | print(' Range: ' + Range + ' ' + 'Azimuth: ' + Azimuth) 140 | print(' Latitude: ' + str(Lat_out[0]) + ' ' + 'Longitude: ' + str(Lon_out[0])) 141 | 142 | ############################################################################## 143 | if __name__ == '__main__': 144 | main(sys.argv[1:]) 145 | -------------------------------------------------------------------------------- /pyint/UTM2SARPIX.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | #''' 3 | ################################################################################### 4 | # # 5 | # Author: Yun-Meng Cao # 6 | # Email : ymcmrs@gmail.com # 7 | # Date : March, 2017 # 8 | # # 9 | # Transform lat and lon to SAR coordinates based on SLCPar and DEM # 10 | # # 11 | ################################################################################### 12 | #''' 13 | 14 | import numpy as np 15 | import os 16 | import sys 17 | import subprocess 18 | import getopt 19 | import time 20 | import glob 21 | 22 | def UseGamma(inFile, task, keyword): 23 | if task == "read": 24 | f = open(inFile, "r") 25 | while 1: 26 | line = f.readline() 27 | if not line: break 28 | if line.count(keyword) == 1: 29 | strtemp = line.split(":") 30 | value = strtemp[1].strip() 31 | return value 32 | print("Keyword " + keyword + " doesn't exist in " + inFile) 33 | f.close() 34 | 35 | 36 | def usage(): 37 | print(''' 38 | ****************************************************************************************************** 39 | 40 | Transform lat and lon to SAR coordinates based on SLCPar and DEM 41 | 42 | usage: 43 | 44 | UTM2SARPIX.py latitude longitude SLCPar DEM 45 | 46 | e.g. UTM2SARPIX.py 31.1 -108.2 /Yunmeng/2010.slc.par /Yunmeng/2010.dem 47 | 48 | ******************************************************************************************************* 49 | ''') 50 | 51 | 52 | def main(argv): 53 | 54 | if len(sys.argv)==5: 55 | LAT = sys.argv[1] 56 | LON = sys.argv[2] 57 | PAR = sys.argv[3] 58 | DEM = sys.argv[4] 59 | else: 60 | usage();sys.exit(1) 61 | 62 | DEMpar = DEM + '.par' 63 | 64 | DateFormat = UseGamma(DEMpar, 'read', 'data_format:') 65 | 66 | nWidth = UseGamma(DEMpar, 'read', 'width:') 67 | nLength = UseGamma(DEMpar, 'read', 'nlines:') 68 | 69 | Corner_LAT = UseGamma(DEMpar, 'read', 'corner_lat:') 70 | Corner_LON = UseGamma(DEMpar, 'read', 'corner_lon:') 71 | 72 | Corner_LAT =Corner_LAT.split(' ')[0] 73 | Corner_LON =Corner_LON.split(' ')[0] 74 | 75 | post_Lat = UseGamma(DEMpar, 'read', 'post_lat:') 76 | post_Lon = UseGamma(DEMpar, 'read', 'post_lon:') 77 | 78 | post_Lat =post_Lat.split(' ')[0] 79 | post_Lon =post_Lon.split(' ')[0] 80 | 81 | if DateFormat =='INTEGER*2': 82 | STR = '>i2' 83 | else: 84 | STR = '>f4' 85 | 86 | TXT = 'SARCOORD' 87 | 88 | DEMdate = np.fromfile(DEM,STR,int(nLength)*int(nWidth)).reshape(int(nLength),int(nWidth)) 89 | 90 | LAT = float(LAT); LON =float(LON) 91 | nWidth=int(nWidth);nLength=int(nLength) 92 | Corner_LAT = float(Corner_LAT); Corner_LON=float(Corner_LON) 93 | post_Lat = float(post_Lat); post_Lon=float(post_Lon) 94 | 95 | XX = int (( LAT - Corner_LAT ) / post_Lat) # latitude width range 96 | YY = int (( LON - Corner_LON ) / post_Lon) # longitude nline azimuth 97 | 98 | 99 | ELEV = DEMdate[XX][YY] 100 | 101 | call_str = 'coord_to_sarpix ' + PAR + ' - - ' + str(LAT) + ' ' + str(LON) + ' ' + str(ELEV) + ' >' +TXT 102 | os.system(call_str) 103 | 104 | call_str = 'cat ' + TXT 105 | os.system(call_str) 106 | 107 | 108 | if __name__ == '__main__': 109 | main(sys.argv[:]) 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /pyint/coreg_gamma_all.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import getopt 13 | import time 14 | import glob 15 | import argparse 16 | 17 | import subprocess 18 | from pyint import _utils as ut 19 | 20 | 21 | def work(data0): 22 | cmd = data0[0] 23 | err_txt = data0[1] 24 | 25 | p = subprocess.run(cmd, shell=False,stderr=subprocess.PIPE, stdout=subprocess.PIPE) 26 | stdout = p.stdout 27 | stderr = p.stderr 28 | 29 | if type(stderr) == bytes: 30 | aa=stderr.decode("utf-8") 31 | else: 32 | aa = stderr 33 | 34 | if aa: 35 | str0 = cmd[0] + ' ' + cmd[1] + ' ' + cmd[2] + '\n' 36 | #print(aa) 37 | with open(err_txt, 'a') as f: 38 | f.write(str0) 39 | f.write(aa) 40 | f.write('\n') 41 | 42 | return 43 | ######################################################################### 44 | 45 | INTRODUCTION = ''' 46 | ------------------------------------------------------------------- 47 | Coregister all of the SLCs to the reference SAR image using GAMMA. 48 | [with assistant of DEM] 49 | 50 | ''' 51 | 52 | EXAMPLE = ''' 53 | Usage: 54 | coreg_gamma_all.py projectName 55 | coreg_gamma_all.py projectName --parallel 4 56 | ------------------------------------------------------------------- 57 | ''' 58 | 59 | 60 | def cmdLineParse(): 61 | parser = argparse.ArgumentParser(description='Coregister all of the SLCs to the reference SAR image using GAMMA.',\ 62 | formatter_class=argparse.RawTextHelpFormatter,\ 63 | epilog=INTRODUCTION+'\n'+EXAMPLE) 64 | 65 | parser.add_argument('projectName',help='projectName for processing.') 66 | parser.add_argument('--parallel', dest='parallelNumb', type=int, default=1, help='Enable parallel processing and Specify the number of processors.') 67 | 68 | inps = parser.parse_args() 69 | return inps 70 | 71 | 72 | def main(argv): 73 | start_time = time.time() 74 | inps = cmdLineParse() 75 | projectName = inps.projectName 76 | scratchDir = os.getenv('SCRATCHDIR') 77 | projectDir = scratchDir + '/' + projectName 78 | slcDir = scratchDir + '/' + projectName + '/SLC' 79 | rslcDir = scratchDir + '/' + projectName + '/RSLC' 80 | if not os.path.isdir(rslcDir): os.mkdir(rslcDir) 81 | 82 | 83 | templateDir = os.getenv('TEMPLATEDIR') 84 | templateFile = templateDir + "/" + projectName + ".template" 85 | templateDict=ut.update_template(templateFile) 86 | 87 | demDir = scratchDir + '/' + projectName + '/DEM' 88 | 89 | Mdate = templateDict['masterDate'] 90 | rlks = templateDict['range_looks'] 91 | azlks = templateDict['azimuth_looks'] 92 | 93 | 94 | ################## generate SLC of the mater date for S1 95 | 96 | if 'S1' in projectName: 97 | 98 | SLC_Tab = slcDir + '/' + Mdate + '/' + Mdate + '_SLC_Tab' 99 | TSLC = slcDir + '/' + Mdate + '/' + Mdate + '.slc' 100 | TSLCPar = slcDir + '/' + Mdate + '/' + Mdate + '.slc.par' 101 | 102 | k0 = 0 103 | if os.path.isfile(TSLCPar): 104 | if os.path.getsize(TSLCPar) > 0: 105 | k0 = 1 106 | 107 | if k0 ==0: 108 | call_str = 'SLC_mosaic_S1_TOPS ' + SLC_Tab + ' ' + TSLC + ' ' + TSLCPar + ' ' + rlks + ' ' + azlks 109 | os.system(call_str) 110 | 111 | ###################################################### 112 | 113 | HGTSIM = demDir + '/' + Mdate + '_' + rlks + 'rlks.rdc.dem' 114 | if not os.path.isfile(HGTSIM): 115 | call_str = 'generate_rdc_dem.py ' + projectName 116 | os.system(call_str) 117 | 118 | 119 | if 'S1' in projectName: cmd_command = 'coreg_s1_gamma.py' 120 | else: cmd_command = 'coreg_gamma.py' 121 | 122 | err_txt = scratchDir + '/' + projectName + '/coreg_gamma_all.err' 123 | if os.path.isfile(err_txt): os.remove(err_txt) 124 | 125 | data_para = [] 126 | #slc_list = [os.path.basename(fname) for fname in sorted(glob.glob(slcDir + '/*'))] 127 | slc_list = ut.get_project_slcList(projectName) 128 | for i in range(len(slc_list)): 129 | cmd0 = [cmd_command,projectName,slc_list[i]] 130 | data0 = [cmd0,err_txt] 131 | data_para.append(data0) 132 | 133 | ut.parallel_process(data_para, work, n_jobs=inps.parallelNumb, use_kwargs=False) 134 | print("Coregister all of the SLCs %s is done! " % projectName) 135 | ut.print_process_time(start_time, time.time()) 136 | 137 | sys.exit(1) 138 | 139 | if __name__ == '__main__': 140 | main(sys.argv[:]) 141 | -------------------------------------------------------------------------------- /pyint/diff_gamma.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import getopt 13 | import time 14 | import glob 15 | import argparse 16 | 17 | from pyint import _utils as ut 18 | 19 | 20 | INTRODUCTION = ''' 21 | ------------------------------------------------------------------- 22 | Generate differential interferogram image from SLC using GAMMA. 23 | 24 | ''' 25 | 26 | EXAMPLE = ''' 27 | Usage: 28 | diff_gamma.py projectName Mdate Sdate 29 | diff_gamma.py PacayaT163TsxHhA 20150102 20150601 30 | ------------------------------------------------------------------- 31 | ''' 32 | 33 | 34 | def cmdLineParse(): 35 | parser = argparse.ArgumentParser(description='Coregister all of the SLCs to the reference SAR image using GAMMA.',\ 36 | formatter_class=argparse.RawTextHelpFormatter,\ 37 | epilog=INTRODUCTION+'\n'+EXAMPLE) 38 | 39 | parser.add_argument('projectName',help='projectName for processing.') 40 | parser.add_argument('Mdate',help='Master date.') 41 | parser.add_argument('Sdate',help='Slave date.') 42 | 43 | inps = parser.parse_args() 44 | return inps 45 | 46 | 47 | def main(argv): 48 | 49 | start_time = time.time() 50 | inps = cmdLineParse() 51 | Mdate = inps.Mdate 52 | Sdate = inps.Sdate 53 | 54 | projectName = inps.projectName 55 | scratchDir = os.getenv('SCRATCHDIR') 56 | templateDir = os.getenv('TEMPLATEDIR') 57 | templateFile = templateDir + "/" + projectName + ".template" 58 | templateDict=ut.update_template(templateFile) 59 | rlks = templateDict['range_looks'] 60 | azlks = templateDict['azimuth_looks'] 61 | masterDate = templateDict['masterDate'] 62 | 63 | projectDir = scratchDir + '/' + projectName 64 | demDir = scratchDir + '/' + projectName + '/DEM' 65 | 66 | slcDir = scratchDir + '/' + projectName + '/SLC' 67 | rslcDir = scratchDir + '/' + projectName + '/RSLC' 68 | ifgDir = projectDir + '/ifgrams' 69 | if not os.path.isdir(ifgDir): os.mkdir(ifgDir) 70 | 71 | Pair = Mdate + '-' + Sdate 72 | workDir = ifgDir + '/' + Pair 73 | if not os.path.isdir(workDir): os.mkdir(workDir) 74 | 75 | ####################################################################### 76 | Mamp = rslcDir + '/' + Mdate + '/' + Mdate + '_' + rlks + 'rlks.amp' 77 | MampPar = rslcDir + '/' + Mdate + '/' + Mdate + '_' + rlks + 'rlks.amp.par' 78 | Samp = rslcDir + '/' + Sdate + '/' + Sdate + '_' + rlks + 'rlks.amp' 79 | SampPar = rslcDir + '/' + Sdate + '/' + Sdate + '_' + rlks + 'rlks.amp.par' 80 | 81 | Mrslc = rslcDir + '/' + Mdate + '/' + Mdate + '.rslc' 82 | MrslcPar = rslcDir + '/' + Mdate + '/' + Mdate + '.rslc.par' 83 | Srslc = rslcDir + '/' + Sdate + '/' + Sdate + '.rslc' 84 | SrslcPar = rslcDir + '/' + Sdate + '/' + Sdate + '.rslc.par' 85 | 86 | HGT = demDir + '/' + masterDate + '_' + rlks + 'rlks.rdc.dem' 87 | 88 | MasterPar = rslcDir + '/' + masterDate + '/' + masterDate + '.rslc.par' 89 | 90 | ################# copy file for parallel processing ########################## 91 | #Mamp = workDir + '/' + Mdate + '_' + rlks + 'rlks.amp' 92 | #MampPar = workDir + '/' + Mdate + '_' + rlks + 'rlks.amp.par' 93 | #Samp = workDir + '/' + Sdate + '_' + rlks + 'rlks.amp' 94 | #SampPar = workDir + '/' + Sdate + '_' + rlks + 'rlks.amp.par' 95 | 96 | #if not templateDict['diff_all_parallel'] == '1': 97 | 98 | # Mrslc = workDir + '/' + Mdate + '.rslc' 99 | # MrslcPar = workDir + '/' + Mdate + '.rslc.par' 100 | # Srslc = workDir + '/' + Sdate + '.rslc' 101 | # SrslcPar = workDir + '/' + Sdate + '.rslc.par' 102 | # ut.copy_file(Mrslc0,Mrslc) 103 | # ut.copy_file(MrslcPar0,MrslcPar) 104 | # ut.copy_file(Srslc0,Srslc) 105 | # ut.copy_file(SrslcPar0,SrslcPar) 106 | 107 | #else: 108 | 109 | # Mrslc = Mrslc0 110 | # MrslcPar = MrslcPar0 111 | # Srslc = Srslc0 112 | # SrslcPar = SrslcPar0 113 | # HGT = HGT0 114 | # MasterPar = MasterPar0 115 | 116 | #ut.copy_file(Mamp0,Mamp) 117 | #ut.copy_file(MampPar0,MampPar) 118 | #ut.copy_file(Samp0,Samp) 119 | #ut.copy_file(SampPar0,SampPar) 120 | 121 | #ut.copy_file(HGT0,HGT) 122 | #ut.copy_file(MasterPar0,MasterPar) 123 | 124 | ############################################################################ 125 | 126 | OFF = workDir + '/' + Pair +'_' + rlks + 'rlks.off' 127 | call_str = 'create_offset '+ MrslcPar + ' ' + SrslcPar + ' ' + OFF + ' 1 ' + rlks + ' ' + azlks + ' 0' 128 | os.system(call_str) 129 | 130 | SIM_UNW = workDir + '/' + Pair + '.sim_unw' 131 | call_str = 'phase_sim_orb ' + MrslcPar + ' ' + SrslcPar + ' ' + OFF + ' ' + HGT + ' ' + SIM_UNW + ' ' + MasterPar + ' - - 1 1' 132 | os.system(call_str) 133 | 134 | DIFF_IFG = workDir + '/' + Pair + '_' + rlks + 'rlks.diff' 135 | call_str = 'SLC_diff_intf ' + Mrslc + ' ' + Srslc + ' ' + MrslcPar + ' ' + SrslcPar + ' ' + OFF + ' ' + SIM_UNW + ' ' + DIFF_IFG + ' ' + rlks + ' ' + azlks + ' ' + templateDict['Igram_Spsflg'] + ' ' + templateDict['Igram_Azfflg'] + ' - 1 1' 136 | os.system(call_str) 137 | 138 | ##### filtering process & coherence estimation ########### 139 | DIFFFILT = workDir + '/' + Pair + '_' + rlks + 'rlks.diff_filt' 140 | COHFILT = workDir + '/' + Pair + '_' + rlks + 'rlks.diff_filt.cor' 141 | 142 | nWIDTH = ut.read_gamma_par(OFF, 'read', 'interferogram_width') 143 | call_str = 'adf ' + DIFF_IFG + ' ' + DIFFFILT + ' ' + COHFILT + ' ' + nWIDTH + ' ' + templateDict['adf_alpha'] + ' - ' + templateDict['Igram_Cor_Win'] 144 | os.system(call_str) 145 | 146 | ################# coherence estimation ##################### 147 | call_str = 'cc_wave ' + DIFFFILT + ' ' + Mamp + ' ' + Samp + ' ' + COHFILT + ' ' + nWIDTH + ' ' + templateDict['Igram_Cor_rwin'] + ' ' + templateDict['Igram_Cor_awin'] 148 | os.system(call_str) 149 | 150 | 151 | ################ save images ##################### 152 | call_str = 'rasmph_pwr ' + DIFFFILT + ' ' + Mamp + ' ' + nWIDTH + ' - - - - - - - - - ' + COHFILT + ' - 0.1' 153 | os.system(call_str) 154 | 155 | call_str = 'rasmph_pwr ' + DIFF_IFG + ' ' + Mamp + ' ' + nWIDTH + ' - - - - - - - - - ' + COHFILT + ' - 0.1' 156 | os.system(call_str) 157 | 158 | call_str = 'rascc ' + COHFILT + ' ' + Mamp + ' ' + nWIDTH 159 | os.system(call_str) 160 | 161 | #os.remove(Mamp) 162 | #os.remove(MampPar) 163 | #os.remove(Samp) 164 | #os.remove(SampPar) 165 | 166 | #if not templateDict['diff_all_parallel'] == '1': 167 | # if os.path.isfile(Mrslc): os.remove(Mrslc) 168 | # if os.path.isfile(Srslc):os.remove(Srslc) 169 | 170 | # if os.path.isfile(HGT):os.remove(HGT) 171 | 172 | print("Subtraction of topography and flattening phase is done!") 173 | ut.print_process_time(start_time, time.time()) 174 | sys.exit(1) 175 | 176 | if __name__ == '__main__': 177 | main(sys.argv[:]) 178 | -------------------------------------------------------------------------------- /pyint/diff_gamma_all.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import getopt 13 | import time 14 | import glob 15 | import argparse 16 | 17 | import subprocess 18 | from pyint import _utils as ut 19 | 20 | 21 | def work(data0): 22 | cmd = data0[0] 23 | err_file = data0[1] 24 | p = subprocess.run(cmd, shell=False,stderr=subprocess.PIPE, stdout=subprocess.PIPE) 25 | stdout = p.stdout 26 | stderr = p.stderr 27 | 28 | if type(stderr) == bytes: 29 | aa=stderr.decode("utf-8") 30 | else: 31 | aa = stderr 32 | 33 | if aa: 34 | str0 = cmd[0] + ' ' + cmd[1] + ' ' + cmd[2] + ' ' + cmd[3] + '\n' 35 | #print(aa) 36 | with open(err_file, 'a') as f: 37 | f.write(str0) 38 | f.write(aa) 39 | f.write('\n') 40 | 41 | return 42 | ######################################################################### 43 | 44 | INTRODUCTION = ''' 45 | ------------------------------------------------------------------- 46 | Geneate differential interferograms for one project using GAMMA. 47 | 48 | ''' 49 | 50 | EXAMPLE = ''' 51 | Usage: 52 | diff_gamma_all.py projectName 53 | diff_gamma_all.py projectName --parallel 4 54 | diff_gamma_all.py projectName --parallel 4 --ifgramList-txt /test/ifgram_list.txt 55 | ------------------------------------------------------------------- 56 | ''' 57 | 58 | 59 | def cmdLineParse(): 60 | parser = argparse.ArgumentParser(description='Geneate differential interferograms for one project using GAMMA.',\ 61 | formatter_class=argparse.RawTextHelpFormatter,\ 62 | epilog=INTRODUCTION+'\n'+EXAMPLE) 63 | 64 | parser.add_argument('projectName',help='projectName for processing.') 65 | parser.add_argument('--parallel', dest='parallelNumb', type=int, default=1, help='Enable parallel processing and Specify the number of processors.') 66 | parser.add_argument('--ifgarmList-txt', dest='ifgarmListTxt', help='provided ifgram_list_txt. default: using ifgram_list.txt under projectName folder.') 67 | 68 | inps = parser.parse_args() 69 | return inps 70 | 71 | 72 | def main(argv): 73 | start_time = time.time() 74 | inps = cmdLineParse() 75 | projectName = inps.projectName 76 | scratchDir = os.getenv('SCRATCHDIR') 77 | templateDir = os.getenv('TEMPLATEDIR') 78 | templateFile = templateDir + "/" + projectName + ".template" 79 | projectDir = scratchDir + '/' + projectName 80 | ifgDir = scratchDir + '/' + projectName + '/ifgrams' 81 | templateDict=ut.update_template(templateFile) 82 | rlks = templateDict['range_looks'] 83 | azlks = templateDict['azimuth_looks'] 84 | 85 | if inps.ifgarmListTxt: ifgramList_txt = inps.ifgarmListTxt 86 | else: ifgramList_txt = scratchDir + '/' + projectName + '/ifgram_list.txt' 87 | ifgList0 = ut.read_txt2array(ifgramList_txt) 88 | ifgList = ifgList0[:,0] 89 | 90 | err_txt = scratchDir + '/' + projectName + '/diff_gamma_all.err' 91 | if os.path.isfile(err_txt): os.remove(err_txt) 92 | 93 | data_para = [] 94 | for i in range(len(ifgList)): 95 | m0 = ut.yyyymmdd(ifgList[i].split('-')[0]) 96 | s0 = ut.yyyymmdd(ifgList[i].split('-')[1]) 97 | cmd0 = ['diff_gamma.py',projectName, m0, s0] 98 | diff_file0 = ifgDir + '/' + ifgList[i] + '/' + ifgList[i] + '_' + rlks + 'rlks.diff_filt.bmp' 99 | data0 = [cmd0,err_txt] 100 | 101 | k00 = 0 102 | if os.path.isfile(diff_file0): 103 | if os.path.getsize(diff_file0) > 0: 104 | k00 = 1 105 | if k00==0: 106 | data_para.append(data0) 107 | 108 | ut.parallel_process(data_para, work, n_jobs=inps.parallelNumb, use_kwargs=False) 109 | print("Generate differential interferograms for project %s is done! " % projectName) 110 | ut.print_process_time(start_time, time.time()) 111 | 112 | sys.exit(1) 113 | 114 | if __name__ == '__main__': 115 | main(sys.argv[:]) 116 | -------------------------------------------------------------------------------- /pyint/down2ifg.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import subprocess 13 | import time 14 | import glob 15 | import argparse 16 | 17 | import datetime as dt 18 | from dateutil.relativedelta import relativedelta 19 | 20 | from pyint import _utils as ut 21 | 22 | def get_e_s_date(date): 23 | date = str(date) 24 | year = date[0:4] 25 | month = date[4:6] 26 | day = date[6:8] 27 | 28 | org_date = dt.date(day=int(day), month=int(month), year=int(year)) 29 | sdate = org_date - relativedelta(days=1) 30 | edate = org_date + relativedelta(days=1) 31 | 32 | return sdate, edate 33 | 34 | def get_s1_date(raw_file): 35 | file0 = os.path.basename(raw_file) 36 | date = file0[17:25] 37 | return date 38 | 39 | def get_satellite(raw_file): 40 | if 'S1A_IW_SLC_' in raw_file: 41 | s0 = 'A' 42 | else: 43 | s0 = 'B' 44 | 45 | return s0 46 | 47 | 48 | def cmdLineParse(): 49 | parser = argparse.ArgumentParser(description='Generate Ifg from Sentinel-1 raw data with orbit correction using GAMMA.',\ 50 | formatter_class=argparse.RawTextHelpFormatter,\ 51 | epilog=INTRODUCTION+'\n'+EXAMPLE) 52 | 53 | parser.add_argument('projectName', help='name of the project.') 54 | parser.add_argument('Mdate',help='master date for interferometry.') 55 | parser.add_argument('Sdate',help='slave date for interferometry.') 56 | 57 | inps = parser.parse_args() 58 | 59 | return inps 60 | 61 | 62 | INTRODUCTION = ''' 63 | --------------------------------------------------------------------------------------------------- 64 | Generate unwrapped differential Ifg from downloading Sentinel-1 raw data with orbit correction using GAMMA. 65 | 66 | Note: 1) Precise orbit data will be downloaded and processed automatically 67 | 2) SRTM-1 will be downloaded and processed automatically if not provided 68 | in the template file 69 | 3) SSARA is used 70 | 71 | ''' 72 | 73 | EXAMPLE = """Usage: 74 | 75 | down2ifg.py projectName Mdate Sdate 76 | ---------------------------------------------------------------------------------------------------- 77 | """ 78 | 79 | def main(argv): 80 | 81 | start_time = time.time() 82 | inps = cmdLineParse() 83 | Mdate = inps.Mdate 84 | Sdate = inps.Sdate 85 | 86 | projectName = inps.projectName 87 | scratchDir = os.getenv('SCRATCHDIR') 88 | templateDir = os.getenv('TEMPLATEDIR') 89 | templateFile = templateDir + "/" + projectName + ".template" 90 | templateDict=ut.update_template(templateFile) 91 | 92 | track = templateDict['track'] 93 | frame = templateDict['frame'] 94 | rlks = templateDict['range_looks'] 95 | azlks = templateDict['azimuth_looks'] 96 | masterDate = templateDict['masterDate'] 97 | projectDir = scratchDir + '/' + projectName 98 | downDir = scratchDir + '/' + projectName + '/DOWNLOAD' 99 | slcDir = scratchDir + '/' + projectName + '/SLC' 100 | 101 | rlks = templateDict['range_looks'] 102 | azlks = templateDict['azimuth_looks'] 103 | demDir = scratchDir + '/' + projectName + '/DEM' 104 | ######### download data ############ 105 | print('Start to download data ...') 106 | 107 | if not os.path.isdir(projectDir): 108 | os.mkdir(projectDir) 109 | if not os.path.isdir(downDir): 110 | os.mkdir(downDir) 111 | 112 | os.chdir(downDir) 113 | call_str = 'ssara_federated_query.py -p Sentinel-1A,Sentinel-1B -r ' + track + ' -f ' + frame + ' --date ' + Mdate + ',' + Sdate + ' --print --download --parallel 10' 114 | print(call_str) 115 | os.system(call_str) 116 | 117 | ######### down 2 slc ############# 118 | #M_raw = glob.glob(downDir + '/S1*_' + ut.yyyymmdd(Mdate)+'*')[0] 119 | #S_raw = glob.glob(downDir + '/S1*_' + ut.yyyymmdd(Sdate)+'*')[0] 120 | 121 | call_str = 'down2slc_sen.py ' + projectName + ' ' + Mdate 122 | os.system(call_str) 123 | 124 | call_str = 'down2slc_sen.py ' + projectName + ' ' + Sdate 125 | os.system(call_str) 126 | 127 | ########## extract common bursts ## 128 | #call_str = 'extract_s1_bursts.py ' + projectName + ' ' + Mdate 129 | #os.system(call_str) 130 | 131 | #call_str = 'extract_s1_bursts.py ' + projectName + ' ' + Sdate 132 | #os.system(call_str) 133 | 134 | ######### generate rdc_dem ########## 135 | Masterdate = templateDict['masterDate'] 136 | HGTSIM = demDir + '/' + Masterdate + '_' + rlks + 'rlks.rdc.dem' 137 | if not os.path.isfile(HGTSIM): 138 | call_str = 'generate_rdc_dem.py ' + projectName 139 | os.system(call_str) 140 | #call_str = 'generate_rdc_dem.py ' + projectName 141 | #os.system(call_str) 142 | 143 | ########## coregister SLC ######## 144 | 145 | call_str = 'coreg_s1_gamma.py ' + projectName + ' ' + Mdate 146 | os.system(call_str) 147 | 148 | call_str = 'coreg_s1_gamma.py ' + projectName + ' ' + Sdate 149 | os.system(call_str) 150 | 151 | ######## Interferometry process ########### 152 | call_str = 'diff_gamma.py ' + projectName + ' ' + Mdate + ' ' + Sdate 153 | os.system(call_str) 154 | 155 | call_str = 'unwrap_gamma.py ' + projectName + ' ' + Mdate + ' ' + Sdate 156 | os.system(call_str) 157 | 158 | call_str = 'geocode_gamma.py ' + projectName + ' ' + Mdate + '-' + Sdate 159 | os.system(call_str) 160 | 161 | print("Generate Ifg from raw-TOPs data is done! ") 162 | ut.print_process_time(start_time, time.time()) 163 | sys.exit(1) 164 | 165 | if __name__ == '__main__': 166 | main(sys.argv[:]) 167 | 168 | 169 | 170 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /pyint/down2slc_cat_all.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v1.0 ### 4 | ### Copy Right (c): 2017, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : Central South University & University of Miami ### 8 | ################################################################# 9 | 10 | import numpy as np 11 | import os 12 | import sys 13 | import subprocess 14 | import getopt 15 | import time 16 | import glob 17 | 18 | def check_variable_name(path): 19 | s=path.split("/")[0] 20 | if len(s)>0 and s[0]=="$": 21 | p0=os.getenv(s[1:]) 22 | path=path.replace(path.split("/")[0],p0) 23 | return path 24 | 25 | def read_template(File, delimiter='='): 26 | '''Reads the template file into a python dictionary structure. 27 | Input : string, full path to the template file 28 | Output: dictionary, pysar template content 29 | Example: 30 | tmpl = read_template(KyushuT424F610_640AlosA.template) 31 | tmpl = read_template(R1_54014_ST5_L0_F898.000.pi, ':') 32 | ''' 33 | template_dict = {} 34 | for line in open(File): 35 | line = line.strip() 36 | c = [i.strip() for i in line.split(delimiter, 1)] #split on the 1st occurrence of delimiter 37 | if len(c) < 2 or line.startswith('%') or line.startswith('#'): 38 | next #ignore commented lines or those without variables 39 | else: 40 | atrName = c[0] 41 | atrValue = str.replace(c[1],'\n','').split("#")[0].strip() 42 | atrValue = check_variable_name(atrValue) 43 | template_dict[atrName] = atrValue 44 | return template_dict 45 | 46 | def is_number(s): 47 | try: 48 | int(s) 49 | return True 50 | except ValueError: 51 | return False 52 | 53 | 54 | def ras2jpg(input, strTitle): 55 | call_str = "convert " + input + ".ras " + input + ".jpg" 56 | os.system(call_str) 57 | call_str = "convert " + input + ".jpg -resize 250 " + input + ".thumb.jpg" 58 | os.system(call_str) 59 | call_str = "convert " + input + ".jpg -resize 500 " + input + ".bthumb.jpg" 60 | os.system(call_str) 61 | call_str = "$INT_SCR/addtitle2jpg.pl " + input + ".thumb.jpg 14 " + strTitle 62 | os.system(call_str) 63 | call_str = "$INT_SCR/addtitle2jpg.pl " + input + ".bthumb.jpg 24 " + strTitle 64 | os.system(call_str) 65 | 66 | def UseGamma(inFile, task, keyword): 67 | if task == "read": 68 | f = open(inFile, "r") 69 | while 1: 70 | line = f.readline() 71 | if not line: break 72 | if line.count(keyword) == 1: 73 | strtemp = line.split(":") 74 | value = strtemp[1].strip() 75 | return value 76 | print("Keyword " + keyword + " doesn't exist in " + inFile) 77 | f.close() 78 | 79 | def write_template(File, Str): 80 | f = open(File,'a') 81 | f.write(Str) 82 | f.close() 83 | 84 | def write_run_coreg_all(projectName,master,slavelist,workdir): 85 | scratchDir = os.getenv('SCRATCHDIR') 86 | projectDir = scratchDir + '/' + projectName 87 | run_coreg_all = projectDir + "/run_coreg_all" 88 | f_coreg = open(run_coreg_all,'w') 89 | 90 | for kk in range(len(slavelist)): 91 | str_coreg = "GenOff_Gamma.py " + projectName + ' ' + master + ' ' + slavelist[kk] + ' ' + workdir + '\n' 92 | f_coreg.write(str_coreg) 93 | f_coreg.close() 94 | 95 | 96 | def usage(): 97 | print(''' 98 | ****************************************************************************************************** 99 | 100 | SLC cat for time-series of SAR datasets. 101 | 102 | usage: 103 | 104 | down2slc_cat_all.py projectName 105 | 106 | e.g. down2slc_cat_all.py PacayaERST163A 107 | down2slc_cat_all.py PacayaEnvT163A 108 | 109 | ******************************************************************************************************* 110 | ''') 111 | 112 | def main(argv): 113 | 114 | if len(sys.argv)==2: 115 | if argv[0] in ['-h','--help']: usage(); sys.exit(1) 116 | else: projectName=sys.argv[1] 117 | else: 118 | usage();sys.exit(1) 119 | 120 | if 'ERS' in projectName: 121 | call_str='Down2SLC_ERS_Cat_All.py ' + projectName 122 | else: 123 | call_str='Down2SLC_ASAR_Cat_All.py ' + projectName 124 | 125 | os.system(call_str) 126 | 127 | 128 | if __name__ == '__main__': 129 | main(sys.argv[:]) 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /pyint/down2slc_csk.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.0 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : Now at KAUST ### 8 | ################################################################# 9 | 10 | import numpy as np 11 | import os 12 | import sys 13 | import subprocess 14 | import getopt 15 | import time 16 | import glob 17 | import argparse 18 | import linecache 19 | import datetime 20 | 21 | def StrNum(S): 22 | S = str(S) 23 | if len(S)==1: 24 | S='0' +S 25 | return S 26 | 27 | def UseGamma(inFile, task, keyword): 28 | if task == "read": 29 | f = open(inFile, "r") 30 | while 1: 31 | line = f.readline() 32 | if not line: break 33 | if line.count(keyword) == 1: 34 | strtemp = line.split(":") 35 | value = strtemp[1].strip() 36 | return value 37 | print("Keyword " + keyword + " doesn't exist in " + inFile) 38 | f.close() 39 | 40 | 41 | def check_ERS_par(SAR_IM_0P): 42 | Name = os.path.basename(SAR_IM_0P) 43 | ff = Name.split('.')[1] 44 | date = (Name.split('SAR_IM__0PWDSI')[1]).split('_')[0] 45 | 46 | if ff == 'E1': 47 | par = 'ERS1_ESA.par' 48 | antenna = 'ERS1_antenna.gain' 49 | orbdir = os.getenv('ERS1ORBDIR') 50 | elif ff == 'E2': 51 | par = 'ERS2_ESA.par' 52 | antenna = 'ERS2_antenna.gain' 53 | orbdir = os.getenv('ERS2ORBDIR') 54 | else: 55 | print('Invalid input SAR_IM_0P file.') 56 | sys.exit(1) 57 | 58 | return par, antenna, orbdir, date 59 | 60 | ######################################################################### 61 | 62 | INTRODUCTION = ''' 63 | ############################################################################# 64 | Copy Right(c): 2017-2020, Yunmeng Cao @PyINT v2.0 65 | 66 | Generate SLC for CSK raw data (with **.tar.gz format). 67 | 68 | ''' 69 | 70 | EXAMPLE = ''' 71 | Usage: 72 | down2slc_csk.py projectName date 73 | 74 | Examples: 75 | down2slc_csk.py KilaueaT10CskA 20180419 76 | 77 | ############################################################################## 78 | ''' 79 | 80 | 81 | def cmdLineParse(): 82 | parser = argparse.ArgumentParser(description='Generate SLC for ERS raw data with ENVISAT format.',\ 83 | formatter_class=argparse.RawTextHelpFormatter,\ 84 | epilog=INTRODUCTION+'\n'+EXAMPLE) 85 | 86 | parser.add_argument('projectName',help='project name.') 87 | parser.add_argument('date',help='to be processed date.') 88 | 89 | inps = parser.parse_args() 90 | return inps 91 | 92 | ################################################################################ 93 | 94 | 95 | def main(argv): 96 | 97 | inps = cmdLineParse() 98 | projectName = inps.projectName 99 | date = inps.date 100 | 101 | scratchDir = os.getenv('SCRATCHDIR') 102 | templateDir = os.getenv('TEMPLATEDIR') 103 | templateFile = templateDir + "/" + projectName + ".template" 104 | 105 | downDir = scratchDir + '/' + projectName + "/DOWNLOAD" 106 | slcDir = scratchDir + '/' + projectName + "/SLC" 107 | rslcDir = scratchDir + '/' + projectName + "/RSLC" 108 | 109 | if not os.path.isdir(slcDir): 110 | call_str = 'mkdir ' + slcDir 111 | os.system(call_str) 112 | 113 | slcDir1 = slcDir + '/' + date 114 | if not os.path.isdir(slcDir1): 115 | call_str = 'mkdir ' + slcDir1 116 | os.system(call_str) 117 | 118 | tar0 = glob.glob(downDir + '/*' + date + '*.tar.gz')[0] 119 | rawDir = downDir + '/raw_' + date 120 | 121 | if not os.path.isdir(rawDir): 122 | call_str = 'mkdir ' + downDir + '/raw_' + date 123 | os.system(call_str) 124 | 125 | call_str = 'tar -xzf ' + tar0 + ' -C ' + rawDir 126 | os.system(call_str) 127 | 128 | par = rawDir + '/' + date + '.sar_par' 129 | raw = rawDir + '/' + date + '.raw' 130 | azsp = rawDir + '/' + date + '.azsp' 131 | dop = rawDir + '/' + date + '.dop' 132 | rspec = rawDir + '/' + date + '.rspec' 133 | rc = rawDir + '/' + date + '.rc' 134 | autof = rawDir + '/' + date + '.autof' 135 | dop_ambig = rawDir + '/' + date + '.dop_ambig' 136 | 137 | h5file = glob.glob(rawDir + '/*.h5')[0] 138 | 139 | pslc_par = rawDir + '/' + 'p' + date + '.slc.par' 140 | slc_par = slcDir1 + '/' + date + '.slc.par' 141 | slc = slcDir1 + '/' +date + '.slc' 142 | mli_par = slcDir1 + '/' +date + '.mli.par' 143 | mli = slcDir1 + '/' + date + '.mli' 144 | 145 | call_str = 'CS_proc ' + h5file + ' ' + par + ' ' + pslc_par + ' ' + raw + ' - - ' 146 | os.system(call_str) 147 | 148 | cal_str = 'dop_ambig ' + par + ' ' + pslc_par + ' ' + raw + ' 2 - ' + dop_ambig 149 | os.system(call_str) 150 | 151 | call_str = 'azsp_IQ ' + par + ' ' + pslc_par + ' ' + raw + ' ' + azsp 152 | os.system(call_str) 153 | 154 | call_str = 'doppler ' + par + ' ' + pslc_par + ' ' + raw + ' ' + dop 155 | os.system(call_str) 156 | 157 | call_str = 'rspec_IQ ' + par + ' ' + pslc_par + ' ' + raw + ' ' + rspec 158 | os.system(call_str) 159 | 160 | call_str = 'pre_rc ' + par + ' ' + pslc_par + ' ' + raw + ' ' + rc 161 | os.system(call_str) 162 | 163 | call_str = 'autof ' + par + ' ' + pslc_par + ' ' + rc + ' ' + autof + ' 2.0 ' 164 | os.system(call_str) 165 | 166 | call_str = 'autof ' + par + ' ' + pslc_par + ' ' + rc + ' ' + autof + ' 2.0 ' 167 | os.system(call_str) 168 | 169 | call_str = 'az_proc ' + par + ' ' + pslc_par + ' ' + rc + ' ' + slc + ' - 1 ' + ' - 0 2.120 ' 170 | os.system(call_str) 171 | 172 | call_str = 'par_MSP ' + par + ' ' + pslc_par + ' ' + slc_par + ' 1' 173 | os.system(call_str) 174 | 175 | call_str = 'multi_look ' + slc + ' ' + slc_par + ' ' + mli + ' ' + mli_par + ' 20 16' 176 | os.system(call_str) 177 | 178 | 179 | Width = UseGamma(mli_par, 'read', 'range_samples: ') 180 | call_str = 'raspwr ' + mli + ' ' + Width 181 | os.system(call_str) 182 | 183 | 184 | print("Generate SLC for %s is done." % date) 185 | sys.exit(1) 186 | 187 | if __name__ == '__main__': 188 | main(sys.argv[:]) 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | -------------------------------------------------------------------------------- /pyint/down2slc_csk_all.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import getopt 13 | import time 14 | import glob 15 | import argparse 16 | 17 | import subprocess 18 | from pyint import _utils as ut 19 | 20 | 21 | def get_csk_date(raw_file): 22 | file0 = os.path.basename(raw_file) 23 | date = file0[27:35] 24 | return date 25 | 26 | 27 | def work(data0): 28 | cmd = data0[0] 29 | err_txt = data0[1] 30 | p = subprocess.run(cmd, shell=False,stderr=subprocess.PIPE, stdout=subprocess.PIPE) 31 | stdout = p.stdout 32 | stderr = p.stderr 33 | 34 | if type(stderr) == bytes: 35 | aa=stderr.decode("utf-8") 36 | else: 37 | aa = stderr 38 | 39 | if aa: 40 | str0 = cmd[0] + ' ' + cmd[1] + ' ' + cmd[2] + '\n' 41 | #print(aa) 42 | with open(err_txt, 'a') as f: 43 | f.write(str0) 44 | f.write(aa) 45 | f.write('\n') 46 | 47 | return 48 | ######################################################################### 49 | 50 | INTRODUCTION = ''' 51 | ------------------------------------------------------------------- 52 | 53 | Generate SLCs from Sentinel-1 raw dataset with orbit correction using GAMMA. 54 | 55 | ''' 56 | 57 | EXAMPLE = ''' 58 | Usage: 59 | down2slc_sen_all.py projectName 60 | down2slc_sen_all.py projectName --parallel 4 61 | 62 | ------------------------------------------------------------------- 63 | ''' 64 | 65 | 66 | def cmdLineParse(): 67 | parser = argparse.ArgumentParser(description='Generate SLCs from Sentinel-1 raw dataset with orbit correction using GAMMA.',\ 68 | formatter_class=argparse.RawTextHelpFormatter,\ 69 | epilog=INTRODUCTION+'\n'+EXAMPLE) 70 | 71 | parser.add_argument('projectName',help='projectName for processing.') 72 | parser.add_argument('--parallel', dest='parallelNumb', type=int, default=1, help='Enable parallel processing and Specify the number of processors.') 73 | 74 | inps = parser.parse_args() 75 | return inps 76 | 77 | 78 | def main(argv): 79 | start_time = time.time() 80 | inps = cmdLineParse() 81 | projectName = inps.projectName 82 | scratchDir = os.getenv('SCRATCHDIR') 83 | projectDir = scratchDir + '/' + projectName 84 | downDir = scratchDir + '/' + projectName + "/DOWNLOAD" 85 | raw_file_list = glob.glob(downDir + '/CSK*.tar.gz') 86 | 87 | # get the burst number table of the mater date 88 | 89 | date_list = [] 90 | for kk in range(len(raw_file_list)): 91 | date0 = get_csk_date(os.path.basename(raw_file_list[kk])) 92 | date_list.append(date0) 93 | 94 | date_list = set(date_list) 95 | date_list = sorted(date_list) 96 | 97 | print('Date to be processed:') 98 | for k0 in date_list: 99 | print(k0) 100 | 101 | err_txt = scratchDir + '/' + projectName + '/down2slc_csk_all.err' 102 | if os.path.isfile(err_txt): os.remove(err_txt) 103 | 104 | data_para = [] 105 | for i in range(len(date_list)): 106 | cmd0 = ['down2slc_csk.py',projectName,date_list[i]] 107 | data0 = [cmd0,err_txt] 108 | data_para.append(data0) 109 | 110 | ut.parallel_process(data_para, work, n_jobs=inps.parallelNumb, use_kwargs=False) 111 | os.chdir(downDir) 112 | print("Down to SLC for project %s is done! " % projectName) 113 | ut.print_process_time(start_time, time.time()) 114 | 115 | sys.exit(1) 116 | 117 | if __name__ == '__main__': 118 | main(sys.argv[:]) 119 | 120 | -------------------------------------------------------------------------------- /pyint/down2slc_sen.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | import numpy as np 9 | import os 10 | import sys 11 | import subprocess 12 | import getopt 13 | import time 14 | import glob 15 | import argparse 16 | 17 | from pyint import _utils as ut 18 | 19 | 20 | def get_s1_date(raw_file): 21 | file0 = os.path.basename(raw_file) 22 | date = file0[17:25] 23 | return date 24 | 25 | def get_satellite(raw_file): 26 | if 'S1A_IW_SLC_' in raw_file: 27 | s0 = 'A' 28 | else: 29 | s0 = 'B' 30 | 31 | return s0 32 | 33 | 34 | def cmdLineParse(): 35 | parser = argparse.ArgumentParser(description='Generate SLC from Sentinel-1 raw data with orbit correction using GAMMA.',\ 36 | formatter_class=argparse.RawTextHelpFormatter,\ 37 | epilog=INTRODUCTION+'\n'+EXAMPLE) 38 | 39 | parser.add_argument('s1_raw', help='raw Sentinel-1 file. e.g., S1A*.zip') 40 | parser.add_argument('root_path',help='root path for saving the SLC files') 41 | 42 | inps = parser.parse_args() 43 | 44 | return inps 45 | 46 | 47 | INTRODUCTION = ''' 48 | ------------------------------------------------------------------- 49 | Generate SLC from Sentinel-1 raw data with orbit correction using GAMMA. 50 | [Precise orbit data will be downloaded automatically] 51 | ''' 52 | 53 | EXAMPLE = """Usage: 54 | 55 | down2slc_sen.py S1A_IW_SLC_XXXX.zip /Yunmeng/S1_test 56 | 57 | ------------------------------------------------------------------- 58 | """ 59 | 60 | def main(argv): 61 | 62 | inps = cmdLineParse() 63 | raw_file = inps.s1_raw 64 | root_dir = inps.root_path 65 | satellite = get_satellite(raw_file) 66 | date = get_s1_date(raw_file) 67 | if not os.path.isdir(root_dir): 68 | os.mkdir(root_dir) 69 | 70 | slc_dir = root_dir + '/' + date 71 | if not os.path.isdir(slc_dir): 72 | os.mkdir(slc_dir) 73 | 74 | if len(os.path.dirname(raw_file))==0: 75 | raw_file_dir = os.getcwd() 76 | else: 77 | raw_file_dir = os.path.dirname(raw_file) 78 | 79 | raw_dir = raw_file.replace('.zip','.SAFE') 80 | 81 | # MEASURE = glob.glob(measureDir + '/*vv*tiff') 82 | # ANNOTAT = glob.glob(annotatDir + '/*vv*xml' ) 83 | # CALIBRA = glob.glob(calibraDir+'/calibration*vv*') 84 | # NOISE = glob.glob(calibraDir+'/noise*vv*') 85 | 86 | SLC_Tab = slc_dir + '/' + date+'_SLC_Tab' 87 | TEST = slc_dir + '/' + date + '.IW3.slc.par' 88 | k0 = 0 89 | if os.path.isfile(TEST): 90 | if os.path.getsize(TEST) > 0: 91 | k0 = 1 92 | 93 | if k0==0: 94 | if not os.path.isdir(raw_dir): 95 | call_str = 'unzip ' + raw_file + ' -d ' + raw_file_dir 96 | os.system(call_str) 97 | 98 | measureDir = raw_dir + '/measurement' 99 | annotatDir = raw_dir + '/annotation' 100 | calibraDir = raw_dir + '/annotation/calibration' 101 | MM = glob.glob(measureDir + '/*vv*tiff') 102 | 103 | if os.path.isfile(SLC_Tab): 104 | os.remove(SLC_Tab) 105 | for kk in range(len(MM)): 106 | SLC = slc_dir + '/' + date + '.IW' + str(kk+1)+'.slc' 107 | SLCPar = slc_dir + '/' + date + '.IW' + str(kk+1)+'.slc.par' 108 | TOPPar = slc_dir + '/' + date + '.IW' + str(kk+1)+'.slc.TOPS_par' 109 | BURST = slc_dir + '/' + date + '.IW' + str(kk+1)+'.burst.par' 110 | 111 | if os.path.isfile(BURST): 112 | os.remove(BURST) 113 | call_str = 'echo ' + SLC + ' ' + SLCPar + ' ' + TOPPar + ' >> ' + SLC_Tab 114 | os.system(call_str) 115 | 116 | MEASURE = glob.glob(measureDir + '/*iw' + str(kk+1) + '*vv*tiff') 117 | ANNOTAT = glob.glob(annotatDir + '/*iw' + str(kk+1) + '*vv*xml' ) 118 | CALIBRA = glob.glob(calibraDir+'/calibration*'+ 'iw' + str(kk+1) + '*vv*') 119 | NOISE = glob.glob(calibraDir+'/noise*' + 'iw' + str(kk+1) + '*vv*') 120 | 121 | #call_str = 'S1_burstloc ' + ANNOTAT[0] + '> ' +BURST 122 | #os.system(call_str) 123 | 124 | if not os.path.isfile(NOISE[0]): 125 | call_str = 'par_S1_SLC ' + MEASURE[0] + ' ' + ANNOTAT[0] + ' ' + CALIBRA[0] + ' - ' + SLCPar + ' ' + SLC + ' ' + TOPPar 126 | else: 127 | call_str = 'par_S1_SLC ' + MEASURE[0] + ' ' + ANNOTAT[0] + ' ' + CALIBRA[0] + ' ' + NOISE[0] + ' ' + SLCPar + ' ' + SLC + ' ' + TOPPar 128 | 129 | #if int(date) > 180311: 130 | # call_str = 'par_S1_SLC ' + MEASURE[0] + ' ' + ANNOTAT[0] + ' ' + CALIBRA[0] + ' - ' + SLCPar + ' ' + SLC + ' ' + TOPPar 131 | #else: 132 | # call_str = 'par_S1_SLC ' + MEASURE[0] + ' ' + ANNOTAT[0] + ' ' + CALIBRA[0] + ' ' + NOISE[0] + ' ' + SLCPar + ' ' + SLC + ' ' + TOPPar 133 | 134 | os.system(call_str) 135 | 136 | call_str = 'SLC_burst_corners ' + SLCPar + ' ' + TOPPar + ' > ' +BURST 137 | os.system(call_str) 138 | 139 | # orbit correction 140 | slc_pars = glob.glob(slc_dir + '/*.IW*.slc.par') 141 | orbit_file0 = ut.download_s1_orbit(date,slc_dir,satellite=satellite) 142 | orbit_file = slc_dir + '/' + orbit_file0 143 | 144 | for i in range(len(slc_pars)): 145 | call_str = 'S1_OPOD_vec ' + slc_pars[i] + ' ' + orbit_file 146 | os.system(call_str) 147 | 148 | # generate amp file for check image quality 149 | #TSLC = slc_dir + '/' + date + '.slc' 150 | #TSLCPar = slc_dir + '/' + date + '.slc.par' 151 | 152 | #TMLI = slc_dir + '/' + date + '_40rlks.amp' 153 | #TMLIPar = slc_dir + '/' + date + '_40rlks.amp.par' 154 | 155 | #call_str = 'SLC_mosaic_S1_TOPS ' + SLC_Tab + ' ' + TSLC + ' ' + TSLCPar + ' 10 2' 156 | #os.system(call_str) 157 | 158 | #call_str = 'multi_look ' + TSLC + ' ' + TSLCPar + ' ' + TMLI + ' ' + TMLIPar + ' 40 8' 159 | #os.system(call_str) 160 | 161 | #nWidth = ut.read_gamma_par(TMLIPar, 'read','range_samples:') 162 | #call_str = 'raspwr ' + TMLI + ' ' + nWidth + ' - - - - - - - ' 163 | #os.system(call_str) 164 | 165 | if os.path.isdir(raw_dir): 166 | call_str = 'rm -rf ' + raw_dir 167 | os.system(call_str) 168 | 169 | print("Down to SLC for %s is done! " % date) 170 | sys.exit(1) 171 | 172 | if __name__ == '__main__': 173 | main(sys.argv[:]) -------------------------------------------------------------------------------- /pyint/down2slc_sen_all.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import getopt 13 | import time 14 | import glob 15 | import argparse 16 | 17 | import subprocess 18 | from pyint import _utils as ut 19 | 20 | 21 | def get_s1_date(raw_file): 22 | file0 = os.path.basename(raw_file) 23 | date = file0[17:25] 24 | return date 25 | 26 | 27 | def work(data0): 28 | cmd = data0[0] 29 | err_txt = data0[1] 30 | p = subprocess.run(cmd, shell=False,stderr=subprocess.PIPE, stdout=subprocess.PIPE) 31 | stdout = p.stdout 32 | stderr = p.stderr 33 | 34 | if type(stderr) == bytes: 35 | aa=stderr.decode("utf-8") 36 | else: 37 | aa = stderr 38 | 39 | if aa: 40 | str0 = cmd[0] + ' ' + cmd[1] + ' ' + cmd[2] + '\n' 41 | #print(aa) 42 | with open(err_txt, 'a') as f: 43 | f.write(str0) 44 | f.write(aa) 45 | f.write('\n') 46 | 47 | return 48 | ######################################################################### 49 | 50 | INTRODUCTION = ''' 51 | ------------------------------------------------------------------- 52 | 53 | Generate SLCs from Sentinel-1 raw dataset with orbit correction using GAMMA. 54 | 55 | ''' 56 | 57 | EXAMPLE = ''' 58 | Usage: 59 | down2slc_sen_all.py projectName 60 | down2slc_sen_all.py projectName --parallel 4 61 | 62 | ------------------------------------------------------------------- 63 | ''' 64 | 65 | 66 | def cmdLineParse(): 67 | parser = argparse.ArgumentParser(description='Generate SLCs from Sentinel-1 raw dataset with orbit correction using GAMMA.',\ 68 | formatter_class=argparse.RawTextHelpFormatter,\ 69 | epilog=INTRODUCTION+'\n'+EXAMPLE) 70 | 71 | parser.add_argument('projectName',help='projectName for processing.') 72 | parser.add_argument('--parallel', dest='parallelNumb', type=int, default=1, help='Enable parallel processing and Specify the number of processors.') 73 | 74 | inps = parser.parse_args() 75 | return inps 76 | 77 | 78 | def main(argv): 79 | start_time = time.time() 80 | inps = cmdLineParse() 81 | projectName = inps.projectName 82 | scratchDir = os.getenv('SCRATCHDIR') 83 | projectDir = scratchDir + '/' + projectName 84 | downDir = scratchDir + '/' + projectName + "/DOWNLOAD" 85 | raw_file_list = glob.glob(downDir + '/S1*.zip') 86 | 87 | # get the burst number table of the mater date 88 | call_str = 'get_master_burst_numb.py ' + projectName 89 | os.system(call_str) 90 | 91 | date_list = [] 92 | for kk in range(len(raw_file_list)): 93 | date0 = get_s1_date(os.path.basename(raw_file_list[kk])) 94 | date_list.append(date0) 95 | 96 | date_list = set(date_list) 97 | date_list = sorted(date_list) 98 | 99 | print('Date to be processed:') 100 | for k0 in date_list: 101 | print(k0) 102 | 103 | err_txt = scratchDir + '/' + projectName + '/down2slc_sen_all.err' 104 | if os.path.isfile(err_txt): os.remove(err_txt) 105 | 106 | data_para = [] 107 | for i in range(len(date_list)): 108 | cmd0 = ['down2slc_sen.py',projectName,date_list[i]] 109 | data0 = [cmd0,err_txt] 110 | data_para.append(data0) 111 | 112 | ut.parallel_process(data_para, work, n_jobs=inps.parallelNumb, use_kwargs=False) 113 | os.chdir(downDir) 114 | print("Down to SLC for project %s is done! " % projectName) 115 | ut.print_process_time(start_time, time.time()) 116 | 117 | sys.exit(1) 118 | 119 | if __name__ == '__main__': 120 | main(sys.argv[:]) 121 | -------------------------------------------------------------------------------- /pyint/download_ers_deos.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v1.0 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : Now at KAUST ### 8 | ################################################################# 9 | 10 | import numpy as np 11 | import os 12 | import sys 13 | import subprocess 14 | import getopt 15 | import time 16 | import glob 17 | import argparse 18 | import linecache 19 | 20 | def StrNum(S): 21 | S = str(S) 22 | if len(S)==1: 23 | S='0' +S 24 | return S 25 | 26 | def StrNum1(S): 27 | S=str(S) 28 | if len(S)==1: 29 | S='00' +S 30 | elif len(S)==2: 31 | S = '0' +S 32 | else: 33 | S = S 34 | return S 35 | 36 | def UseGamma(inFile, task, keyword): 37 | if task == "read": 38 | f = open(inFile, "r") 39 | while 1: 40 | line = f.readline() 41 | if not line: break 42 | if line.count(keyword) == 1: 43 | strtemp = line.split(":") 44 | value = strtemp[1].strip() 45 | return value 46 | print("Keyword " + keyword + " doesn't exist in " + inFile) 47 | f.close() 48 | 49 | def print_progress(iteration, total, prefix='calculating:', suffix='complete', decimals=1, barLength=50, elapsed_time=None): 50 | """Print iterations progress - Greenstick from Stack Overflow 51 | Call in a loop to create terminal progress bar 52 | @params: 53 | iteration - Required : current iteration (Int) 54 | total - Required : total iterations (Int) 55 | prefix - Optional : prefix string (Str) 56 | suffix - Optional : suffix string (Str) 57 | decimals - Optional : number of decimals in percent complete (Int) 58 | barLength - Optional : character length of bar (Int) 59 | elapsed_time- Optional : elapsed time in seconds (Int/Float) 60 | 61 | Reference: http://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console 62 | """ 63 | filledLength = int(round(barLength * iteration / float(total))) 64 | percents = round(100.00 * (iteration / float(total)), decimals) 65 | bar = '#' * filledLength + '-' * (barLength - filledLength) 66 | if elapsed_time: 67 | sys.stdout.write('%s [%s] %s%s %s %s secs\r' % (prefix, bar, percents, '%', suffix, int(elapsed_time))) 68 | else: 69 | sys.stdout.write('%s [%s] %s%s %s\r' % (prefix, bar, percents, '%', suffix)) 70 | sys.stdout.flush() 71 | if iteration == total: 72 | print("\n") 73 | 74 | ''' 75 | Sample Useage: 76 | for i in range(len(dateList)): 77 | print_progress(i+1,len(dateList)) 78 | ''' 79 | return 80 | 81 | 82 | ######################################################################### 83 | 84 | INTRODUCTION = ''' 85 | ############################################################################# 86 | Copy Right(c): 2017-2019, Yunmeng Cao @PyINT v1.0 87 | 88 | Download precise ERS orbit data from Delft Institute for Earth-Oriented Space Research (http://www.deos.tudelft.nl/). 89 | 90 | ''' 91 | 92 | EXAMPLE = ''' 93 | Usage: 94 | download_ers_deos.py ERS1 95 | download_ers_deos.py ERS2 96 | 97 | ############################################################################## 98 | ''' 99 | 100 | 101 | def cmdLineParse(): 102 | parser = argparse.ArgumentParser(description='Download (and correct) precise ERS orbit data.',\ 103 | formatter_class=argparse.RawTextHelpFormatter,\ 104 | epilog=INTRODUCTION+'\n'+EXAMPLE) 105 | 106 | parser.add_argument('sar',help='project name') 107 | 108 | inps = parser.parse_args() 109 | return inps 110 | 111 | ################################################################################ 112 | 113 | 114 | def main(argv): 115 | 116 | total = time.time() 117 | inps = cmdLineParse() 118 | sar = inps.sar 119 | PATH = os.getcwd() 120 | listfile = 'arclist' 121 | 122 | if sar == 'ERS1': 123 | Url = 'ftp://dutlru2.lr.tudelft.nl/pub/orbits/ODR.ERS-1/dgm-e04/' 124 | Url_list = 'ftp://dutlru2.lr.tudelft.nl/pub/orbits/ODR.ERS-1/dgm-e04/arclist' 125 | num_min = 6 126 | num_max = 511 127 | N_num = 506 128 | if not os.path.isfile(listfile): 129 | call_str = 'wget -q ' + Url_list 130 | os.system(call_str) 131 | 132 | elif sar =='ERS2': 133 | Url = 'ftp://dutlru2.lr.tudelft.nl/pub/orbits/ODR.ERS-2/dgm-e04/' 134 | Url_list = 'ftp://dutlru2.lr.tudelft.nl/pub/orbits/ODR.ERS-2/dgm-e04/arclist' 135 | num_min = 3 136 | num_max = 867 137 | N_num = 865 138 | if not os.path.isfile(listfile): 139 | call_str = 'wget -q ' + Url_list 140 | os.system(call_str) 141 | 142 | else: 143 | print('SAR name is invalid!') 144 | sys.exit(1) 145 | 146 | for i in range(N_num): 147 | kk = num_min + i 148 | kk=int(kk) 149 | SS = Url + 'ODR.' + StrNum1(kk) 150 | print_progress(i+1, N_num, prefix='DEFT_vec: ', suffix=StrNum1(kk)) 151 | 152 | call_str = 'wget -q --no-check-certificate ' + SS + ' -P ' + PATH 153 | os.system(call_str) 154 | 155 | 156 | print("Download precise DEFT orbital data for %s is done." % sar) 157 | sys.exit(1) 158 | 159 | if __name__ == '__main__': 160 | main(sys.argv[:]) 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /pyint/download_url.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.0 ### 4 | ### Copy Right (c): 2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : King Abdullah University of Science & Technology ### 8 | ################################################################# 9 | ## This script is modified from SSARA 10 | 11 | from __future__ import print_function 12 | import os 13 | import sys 14 | import json 15 | import datetime 16 | import time 17 | import csv 18 | from xml.dom import minidom 19 | import itertools 20 | import operator 21 | import re 22 | import optparse 23 | import threading 24 | import subprocess as sub 25 | try: 26 | # For Python 3.0 and later 27 | from urllib.request import urlopen,HTTPCookieProcessor,HTTPPasswordMgrWithDefaultRealm,HTTPBasicAuthHandler,HTTPDigestAuthHandler,build_opener,install_opener 28 | from urllib.parse import urlencode 29 | from urllib.error import HTTPError 30 | from queue import Queue 31 | except ImportError: 32 | # Fall back to Python2 33 | from urllib2 import urlopen,HTTPCookieProcessor,HTTPPasswordMgrWithDefaultRealm,HTTPBasicAuthHandler,HTTPDigestAuthHandler,build_opener,install_opener,HTTPError 34 | from urllib import urlencode 35 | from Queue import Queue 36 | import ssl 37 | 38 | import argparse 39 | from pyint import _utils as ut 40 | 41 | ################################################################################################### 42 | 43 | INTRODUCTION = ''' 44 | Download file based on url list. 45 | 46 | ''' 47 | 48 | EXAMPLE = '''EXAMPLES: 49 | 50 | download_url.py url_list username password 51 | download_url.py Tsx_r51_url ymcmrs cym6331099 52 | 53 | ''' 54 | 55 | 56 | 57 | def cmdLineParse(): 58 | parser = argparse.ArgumentParser(description='Download file based on url list.',\ 59 | formatter_class=argparse.RawTextHelpFormatter,\ 60 | epilog=INTRODUCTION+'\n'+EXAMPLE) 61 | 62 | parser.add_argument('url_list_txt',help='GPS station name.') 63 | parser.add_argument('user_name',help='user name.') 64 | parser.add_argument('password',help='password') 65 | parser.add_argument('--parallel', dest='parallelNumb', type=int, default=1, help='Enable parallel processing and Specify the number of processors.') 66 | inps = parser.parse_args() 67 | 68 | 69 | return inps 70 | 71 | #################################################################################################### 72 | def main(argv): 73 | 74 | inps = cmdLineParse() 75 | url_txt = inps.url_list_txt 76 | user_name = inps.user_name 77 | password = inps.password 78 | url_list = ut.read_txt2list(url_txt) 79 | parallel0 = inps.parallelNumb 80 | 81 | print('Download file list: '+str(len(url_list))) 82 | 83 | print('Downloading data now, %s at a time.' % str(parallel0)) 84 | #create a queue for parallel downloading 85 | queue = Queue() 86 | #spawn a pool of threads, and pass them queue instance 87 | for i in range(parallel0): 88 | t = ThreadDownload(queue) 89 | t.setDaemon(True) 90 | t.start() 91 | #populate queue with data 92 | for d in sorted(url_list): 93 | queue.put([d, user_name, password]) 94 | #wait on the queue until everything has been processed 95 | queue.join() 96 | 97 | def url_dl(url0, user_name, password): 98 | user_name = user_name 99 | user_password = password 100 | url = url0 101 | filename = os.path.basename(url) 102 | if '.gz' in filename: 103 | filename = filename.replace('.gz','') 104 | path0 = os.getcwd() 105 | filename0 = path0 + '/' + filename 106 | secp_path = os.getenv('SSARAHOME')+"/data_utils/secp" 107 | cmd = """%s -C %s:%s %s""" % (secp_path,user_name,user_password,url0) 108 | print("Downloading:",url) 109 | start = time.time() 110 | pipe = sub.Popen(cmd, shell=True, stdout=sub.PIPE, stderr=sub.STDOUT).stdout 111 | pipe.read() 112 | total_time = time.time() - start 113 | mb_sec = (os.path.getsize(filename0) / (1024 * 1024.0)) / total_time 114 | print("%s download time: %.2f secs (%.2f MB/sec)" % (filename, total_time, mb_sec)) 115 | 116 | class ThreadDownload(threading.Thread): 117 | """Threaded SAR data download""" 118 | def __init__(self, queue): 119 | threading.Thread.__init__(self) 120 | self.queue = queue 121 | 122 | def run(self): 123 | while True: 124 | url0, user_name, password = self.queue.get() 125 | url_dl(url0, user_name, password) 126 | self.queue.task_done() 127 | 128 | if __name__ == '__main__': 129 | main(sys.argv[1:]) 130 | -------------------------------------------------------------------------------- /pyint/extract_s1_bursts_all.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import getopt 13 | import time 14 | import glob 15 | import argparse 16 | 17 | import subprocess 18 | from pyint import _utils as ut 19 | 20 | 21 | def work(data0): 22 | cmd = data0[0] 23 | err_file = data0[1] 24 | p = subprocess.run(cmd, shell=False,stderr=subprocess.PIPE, stdout=subprocess.PIPE) 25 | stdout = p.stdout 26 | stderr = p.stderr 27 | 28 | if type(stderr) == bytes: 29 | aa=stderr.decode("utf-8") 30 | else: 31 | aa = stderr 32 | 33 | if aa: 34 | str0 = cmd[0] + ' ' + cmd[1] + ' ' + cmd[2] + '\n' 35 | #print(aa) 36 | with open(err_file, 'a') as f: 37 | f.write(str0) 38 | f.write(aa) 39 | f.write('\n') 40 | 41 | return 42 | ######################################################################### 43 | 44 | INTRODUCTION = ''' 45 | ------------------------------------------------------------------- 46 | Extract reference TOPS related bursts for coregistration using GAMMA. 47 | 48 | ''' 49 | 50 | EXAMPLE = ''' 51 | Usage: 52 | extract_s1_bursts_all.py projectName 53 | extract_s1_bursts_all.py projectName --parallel 4 54 | ------------------------------------------------------------------- 55 | ''' 56 | 57 | 58 | def cmdLineParse(): 59 | parser = argparse.ArgumentParser(description='Extract reference TOPS related bursts for coregistration using GAMMA.',\ 60 | formatter_class=argparse.RawTextHelpFormatter,\ 61 | epilog=INTRODUCTION+'\n'+EXAMPLE) 62 | 63 | parser.add_argument('projectName',help='projectName for processing.') 64 | parser.add_argument('--parallel', dest='parallelNumb', type=int, default=1, help='Enable parallel processing and Specify the number of processors.') 65 | 66 | inps = parser.parse_args() 67 | return inps 68 | 69 | 70 | def main(argv): 71 | start_time = time.time() 72 | inps = cmdLineParse() 73 | projectName = inps.projectName 74 | scratchDir = os.getenv('SCRATCHDIR') 75 | projectDir = scratchDir + '/' + projectName 76 | slcDir = scratchDir + '/' + projectName + '/SLC' 77 | slc_list = [os.path.basename(fname) for fname in sorted(glob.glob(slcDir + '/*'))] 78 | 79 | err_txt = scratchDir + '/' + projectName + '/extract_s1_bursts_all.err' 80 | if os.path.isfile(err_txt): os.remove(err_txt) 81 | 82 | data_para = [] 83 | for i in range(len(slc_list)): 84 | cmd0 = ['extract_s1_bursts.py',projectName,slc_list[i]] 85 | data0 = [cmd0,err_txt] 86 | data_para.append(data0) 87 | 88 | ut.parallel_process(data_para, work, n_jobs=inps.parallelNumb, use_kwargs=False) 89 | print("Extract TOPS bursts for project %s is done! " % projectName) 90 | ut.print_process_time(start_time, time.time()) 91 | 92 | sys.exit(1) 93 | 94 | if __name__ == '__main__': 95 | main(sys.argv[:]) 96 | -------------------------------------------------------------------------------- /pyint/generate_amp_all.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import getopt 13 | import time 14 | import glob 15 | import argparse 16 | 17 | import subprocess 18 | from pyint import _utils as ut 19 | 20 | 21 | def work(data0): 22 | cmd = data0[0] 23 | err_txt = data0[1] 24 | 25 | p = subprocess.run(cmd, shell=False,stderr=subprocess.PIPE, stdout=subprocess.PIPE) 26 | stdout = p.stdout 27 | stderr = p.stderr 28 | 29 | if type(stderr) == bytes: 30 | aa=stderr.decode("utf-8") 31 | else: 32 | aa = stderr 33 | 34 | if aa: 35 | str0 = cmd[0] + ' ' + cmd[1] + ' ' + cmd[2] + '\n' 36 | #print(aa) 37 | with open(err_txt, 'a') as f: 38 | f.write(str0) 39 | f.write(aa) 40 | f.write('\n') 41 | 42 | return 43 | ######################################################################### 44 | 45 | INTRODUCTION = ''' 46 | ------------------------------------------------------------------- 47 | Generate multilooked amp for one project. 48 | 49 | ''' 50 | 51 | EXAMPLE = ''' 52 | Usage: 53 | generate_amp_all.py projectName 54 | generate_amp_all.py projectName --parallel 4 55 | ------------------------------------------------------------------- 56 | ''' 57 | 58 | 59 | def cmdLineParse(): 60 | parser = argparse.ArgumentParser(description='Generate multilooked amp for one project.',\ 61 | formatter_class=argparse.RawTextHelpFormatter,\ 62 | epilog=INTRODUCTION+'\n'+EXAMPLE) 63 | 64 | parser.add_argument('projectName',help='projectName for processing.') 65 | parser.add_argument('--parallel', dest='parallelNumb', type=int, default=1, help='Enable parallel processing and Specify the number of processors.') 66 | 67 | inps = parser.parse_args() 68 | return inps 69 | 70 | 71 | def main(argv): 72 | start_time = time.time() 73 | inps = cmdLineParse() 74 | projectName = inps.projectName 75 | scratchDir = os.getenv('SCRATCHDIR') 76 | projectDir = scratchDir + '/' + projectName 77 | slcDir = scratchDir + '/' + projectName + '/SLC' 78 | rslcDir = scratchDir + '/' + projectName + '/RSLC' 79 | if not os.path.isdir(rslcDir): os.mkdir(rslcDir) 80 | 81 | cmd_command = 'generate_multilook_amp.py' 82 | 83 | err_txt = scratchDir + '/' + projectName + '/generate_amp_all.err' 84 | if os.path.isfile(err_txt): os.remove(err_txt) 85 | 86 | data_para = [] 87 | slc_list = [os.path.basename(fname) for fname in sorted(glob.glob(rslcDir + '/*'))] 88 | #slc_list = ut.get_project_slcList(projectName) 89 | for i in range(len(slc_list)): 90 | cmd0 = [cmd_command,projectName,slc_list[i]] 91 | data0 = [cmd0,err_txt] 92 | data_para.append(data0) 93 | 94 | ut.parallel_process(data_para, work, n_jobs=inps.parallelNumb, use_kwargs=False) 95 | print("Generate multilooked apm for all rslcs is done! ") 96 | ut.print_process_time(start_time, time.time()) 97 | 98 | sys.exit(1) 99 | 100 | if __name__ == '__main__': 101 | main(sys.argv[:]) 102 | -------------------------------------------------------------------------------- /pyint/generate_bursts_par.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import glob 13 | import argparse 14 | 15 | from pyint import _utils as ut 16 | 17 | 18 | 19 | INTRODUCTION = ''' 20 | ------------------------------------------------------------------- 21 | 22 | Generate burst par files for a project. 23 | ''' 24 | 25 | EXAMPLE = """Usage: 26 | 27 | generate_bursts_par.py projectName 28 | 29 | ------------------------------------------------------------------- 30 | """ 31 | 32 | def cmdLineParse(): 33 | parser = argparse.ArgumentParser(description='Check common busrts for TOPS data.',\ 34 | formatter_class=argparse.RawTextHelpFormatter,\ 35 | epilog=INTRODUCTION+'\n'+EXAMPLE) 36 | 37 | parser.add_argument('projectName',help='Name of project.') 38 | 39 | inps = parser.parse_args() 40 | 41 | return inps 42 | 43 | ################################################################################ 44 | 45 | 46 | def main(argv): 47 | 48 | inps = cmdLineParse() 49 | projectName = inps.projectName 50 | scratchDir = os.getenv('SCRATCHDIR') 51 | templateDir = os.getenv('TEMPLATEDIR') 52 | templateFile = templateDir + "/" + projectName + ".template" 53 | templateDict=ut.update_template(templateFile) 54 | 55 | rlks = templateDict['range_looks'] 56 | azlks = templateDict['azimuth_looks'] 57 | Mdate = templateDict['masterDate'] 58 | 59 | processDir = scratchDir + '/' + projectName + "/PROCESS" 60 | slcDir = scratchDir + '/' + projectName + "/SLC" 61 | rslcDir = scratchDir + '/' + projectName + "/RSLC" 62 | dateList = ut.get_project_slcList(projectName) 63 | 64 | for i in range(len(dateList)): 65 | slc_dir = slcDir + '/' + dateList[i] 66 | print(slc_dir) 67 | for j in range(3): 68 | kk = j 69 | SLC = slc_dir + '/' + dateList[i] + '.IW' + str(kk+1)+'.slc' 70 | SLCPar = slc_dir + '/' + dateList[i] + '.IW' + str(kk+1)+'.slc.par' 71 | TOPPar = slc_dir + '/' + dateList[i] + '.IW' + str(kk+1)+'.slc.TOPS_par' 72 | BURST = slc_dir + '/' + dateList[i] + '.IW' + str(kk+1)+'.burst.par' 73 | 74 | call_str = 'SLC_burst_corners ' + SLCPar + ' ' + TOPPar + ' > ' +BURST 75 | os.system(call_str) 76 | 77 | 78 | sys.exit(1) 79 | 80 | if __name__ == '__main__': 81 | main(sys.argv[:]) 82 | -------------------------------------------------------------------------------- /pyint/generate_multilook_amp.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | import numpy as np 9 | import os 10 | import sys 11 | import argparse 12 | 13 | from pyint import _utils as ut 14 | 15 | def cmdLineParse(): 16 | parser = argparse.ArgumentParser(description='Coregister TOPS S1-SLC to a reference S1-SLC using GAMMA.',\ 17 | formatter_class=argparse.RawTextHelpFormatter,\ 18 | epilog=INTRODUCTION+'\n'+EXAMPLE) 19 | 20 | parser.add_argument('projectName', help='Name of project.') 21 | parser.add_argument('date', help='date of the slave S1 image. [mater date is read from template]') 22 | inps = parser.parse_args() 23 | return inps 24 | 25 | 26 | INTRODUCTION = ''' 27 | ------------------------------------------------------------------- 28 | Generate multilook amplitude images for coregistered SLCs. 29 | 30 | ''' 31 | 32 | EXAMPLE = """Usage: 33 | 34 | generate_multilook_amp.py projectName Date 35 | 36 | generate_multilook_amp.py PacayaT163TsxHhA 20150102 37 | ------------------------------------------------------------------- 38 | """ 39 | 40 | def main(argv): 41 | 42 | inps = cmdLineParse() 43 | projectName = inps.projectName 44 | Date = inps.date 45 | 46 | scratchDir = os.getenv('SCRATCHDIR') 47 | templateDir = os.getenv('TEMPLATEDIR') 48 | templateFile = templateDir + "/" + projectName + ".template" 49 | 50 | slcDir = scratchDir + '/' + projectName + "/SLC" 51 | rslcDir = scratchDir + '/' + projectName + "/RSLC" 52 | if not os.path.isdir(rslcDir): os.mkdir(rslcDir) 53 | #workDir = processDir + '/' + igramDir 54 | workDir = rslcDir + '/' + Date 55 | if not os.path.isdir(workDir): os.mkdir(workDir) 56 | 57 | templateDict=ut.update_template(templateFile) 58 | rlks = templateDict['range_looks'] 59 | azlks = templateDict['azimuth_looks'] 60 | Mdate = templateDict['masterDate'] 61 | 62 | 63 | rslc = workDir + '/' + Date + '.rslc' 64 | rslcPar = workDir + '/' + Date + '.rslc.par' 65 | 66 | amp = workDir + '/' + Date + '_' + rlks + 'rlks.amp' 67 | ampPar = workDir + '/' + Date + '_' + rlks + 'rlks.amp.par' 68 | 69 | k0 = 0 70 | if os.path.isfile(ampPar): 71 | if os.path.getsize(ampPar) > 0: 72 | k0 =1 73 | 74 | if k0==0: 75 | call_str = 'multi_look ' + rslc + ' ' + rslcPar + ' ' + amp + ' ' + ampPar + ' ' + rlks + ' ' + azlks 76 | os.system(call_str) 77 | 78 | nWIDTH = ut.read_gamma_par(ampPar,'read', 'range_samples') 79 | 80 | call_str = 'raspwr ' + amp + ' ' + nWIDTH 81 | os.system(call_str) 82 | 83 | print("Generate amplitude image for RSLC %s is done !!" % Date) 84 | sys.exit(1) 85 | 86 | if __name__ == '__main__': 87 | main(sys.argv[:]) 88 | -------------------------------------------------------------------------------- /pyint/geocode_gamma.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | import os 9 | import sys 10 | import argparse 11 | 12 | from pyint import _utils as ut 13 | 14 | def geocode(inFile, outFile, UTMTORDC, nWidth, nWidthUTMDEM, nLineUTMDEM, geo_interp): 15 | 16 | if '.unw' in os.path.basename(inFile): 17 | call_str = 'geocode_back ' + inFile + ' ' + nWidth + ' ' + UTMTORDC + ' ' + outFile + ' ' + nWidthUTMDEM + ' ' + nLineUTMDEM + ' ' + geo_interp + ' 0' 18 | elif '.amp' in os.path.basename(inFile): 19 | call_str = 'geocode_back ' + inFile + ' ' + nWidth + ' ' + UTMTORDC + ' ' + outFile + ' ' + nWidthUTMDEM + ' ' + nLineUTMDEM + ' ' + geo_interp + ' 0' 20 | elif '.cor' in os.path.basename(inFile): 21 | call_str = 'geocode_back ' + inFile + ' ' + nWidth + ' ' + UTMTORDC + ' ' + outFile + ' ' + nWidthUTMDEM + ' ' + nLineUTMDEM + ' ' + geo_interp + ' 0' 22 | else: 23 | call_str = 'geocode_back ' + inFile + ' ' + nWidth + ' ' + UTMTORDC + ' ' + outFile + ' ' + nWidthUTMDEM + ' ' + nLineUTMDEM + ' ' + geo_interp + ' 1' 24 | 25 | os.system(call_str) 26 | 27 | return 28 | 29 | INTRODUCTION = ''' 30 | ------------------------------------------------------------------- 31 | Convert radar-coordinates unw-ifg and diff-ifg into geo-coordinates using GAMMA. 32 | 33 | ''' 34 | 35 | EXAMPLE = ''' 36 | Usage: 37 | geocode_gamma.py projectName Mdate-Sdate 38 | geocode_gamma.py PacayaT163TsxHhA 20150102-20150601 39 | ------------------------------------------------------------------- 40 | ''' 41 | 42 | def cmdLineParse(): 43 | parser = argparse.ArgumentParser(description='Unwrap differential interferogram using GAMMA-mcf method.',\ 44 | formatter_class=argparse.RawTextHelpFormatter,\ 45 | epilog=INTRODUCTION+'\n'+EXAMPLE) 46 | 47 | parser.add_argument('projectName',help='projectName for processing.') 48 | parser.add_argument('pair',help='Master-Slave, e.g., 20150101-20150106.') 49 | 50 | inps = parser.parse_args() 51 | return inps 52 | 53 | 54 | def main(argv): 55 | 56 | inps = cmdLineParse() 57 | projectName = inps.projectName 58 | Pair = inps.pair 59 | 60 | scratchDir = os.getenv('SCRATCHDIR') 61 | ifgDir = scratchDir + '/' + projectName + "/ifgrams" 62 | demDir = scratchDir + '/' + projectName + "/DEM" 63 | workDir = ifgDir + '/' + Pair 64 | 65 | templateDir = os.getenv('TEMPLATEDIR') 66 | templateFile = templateDir + "/" + projectName + ".template" 67 | templateDict=ut.update_template(templateFile) 68 | rlks = templateDict['range_looks'] 69 | azlks = templateDict['azimuth_looks'] 70 | masterDate = templateDict['masterDate'] 71 | 72 | slcDir = scratchDir + '/' + projectName + "/SLC" 73 | rslcDir = scratchDir + '/' + projectName + "/RSLC" 74 | demDir = scratchDir + '/' + projectName + '/DEM' 75 | 76 | ######### copy common file for parallel processing ############# 77 | 78 | Mamp0 = rslcDir + '/' + masterDate + '/' + masterDate + '_' + rlks + 'rlks.amp' 79 | MampPar0 = rslcDir + '/' + masterDate + '/' + masterDate + '_' + rlks + 'rlks.amp.par' 80 | 81 | Mamp = workDir + '/' + masterDate + '_' + rlks + 'rlks.amp' 82 | MampPar = workDir + '/' + masterDate + '_' + rlks + 'rlks.amp.par' 83 | 84 | ut.copy_file(Mamp0,Mamp) 85 | ut.copy_file(MampPar0,MampPar) 86 | 87 | ################################################################# 88 | UNWIFG = workDir + '/' + Pair + '_' + rlks + 'rlks.diff_filt.unw' 89 | DIFFIFG = workDir + '/' + Pair + '_' + rlks + 'rlks.diff_filt' 90 | CORIFG = workDir + '/' + Pair + '_' + rlks + 'rlks.diff_filt.cor' 91 | 92 | GeoMamp = workDir + '/geo_' + masterDate + '_' + rlks + 'rlks.amp' 93 | GeoCOR = workDir + '/geo_' + masterDate + '_' + rlks + 'rlks.diff_filt.cor' 94 | GeoUNW = workDir + '/geo_' + Pair + '_' + rlks + 'rlks.diff_filt.unw' 95 | GeoDIFF = workDir + '/geo_' + Pair + '_' + rlks + 'rlks.diff_filt' 96 | 97 | UTMTORDC0 = demDir + '/' + masterDate + '_' + rlks + 'rlks.UTM_TO_RDC' 98 | UTMDEMpar0 = demDir + '/' + masterDate + '_' + rlks + 'rlks.utm.dem.par' 99 | 100 | UTMTORDC = workDir + '/' + masterDate + '_' + rlks + 'rlks.UTM_TO_RDC' 101 | UTMDEMpar = workDir + '/' + masterDate + '_' + rlks + 'rlks.utm.dem.par' 102 | 103 | ut.copy_file(UTMTORDC0,UTMTORDC) 104 | ut.copy_file(UTMDEMpar0,UTMDEMpar) 105 | 106 | nWidth = ut.read_gamma_par(MampPar, 'read', 'range_samples') 107 | nWidthUTMDEM = ut.read_gamma_par(UTMDEMpar, 'read', 'width') 108 | nLineUTMDEM = ut.read_gamma_par(UTMDEMpar, 'read', 'nlines') 109 | print(nWidth) 110 | 111 | if 'geo_interp' in templateDict: geo_interp = templateDict['geo_interp'] 112 | else: geo_interp = '0' 113 | 114 | geocode(Mamp, GeoMamp, UTMTORDC, nWidth, nWidthUTMDEM, nLineUTMDEM, geo_interp) 115 | geocode(CORIFG, GeoCOR, UTMTORDC, nWidth, nWidthUTMDEM, nLineUTMDEM, geo_interp) 116 | geocode(DIFFIFG, GeoDIFF, UTMTORDC, nWidth, nWidthUTMDEM, nLineUTMDEM, geo_interp) 117 | geocode(UNWIFG, GeoUNW, UTMTORDC, nWidth, nWidthUTMDEM, nLineUTMDEM, geo_interp) 118 | 119 | call_str = 'rasmph_pwr ' + GeoDIFF + ' ' + GeoMamp + ' ' + nWidthUTMDEM + ' - - - - - - - - - ' + GeoCOR + ' - - ' 120 | os.system(call_str) 121 | 122 | call_str = 'raspwr ' + GeoMamp + ' ' + nWidthUTMDEM + ' - - - - - - - - - - ' 123 | os.system(call_str) 124 | 125 | call_str = 'rasrmg ' + GeoUNW + ' ' + GeoMamp + ' ' + nWidthUTMDEM + ' - - - - - - - - - - - ' + GeoCOR + ' - - ' 126 | os.system(call_str) 127 | 128 | os.remove(Mamp) 129 | #os.remove(MampPar) 130 | 131 | os.remove(UTMTORDC) 132 | os.remove(UTMDEMpar) 133 | 134 | print("Geocoding is done!") 135 | sys.exit(1) 136 | 137 | if __name__ == '__main__': 138 | main(sys.argv[:]) 139 | -------------------------------------------------------------------------------- /pyint/geocode_gamma_all.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import time 13 | import glob 14 | import argparse 15 | 16 | import subprocess 17 | from pyint import _utils as ut 18 | 19 | 20 | def work(data0): 21 | cmd = data0[0] 22 | err_file = data0[1] 23 | p = subprocess.run(cmd, shell=False,stderr=subprocess.PIPE, stdout=subprocess.PIPE) 24 | stdout = p.stdout 25 | stderr = p.stderr 26 | 27 | if type(stderr) == bytes: 28 | aa=stderr.decode("utf-8") 29 | else: 30 | aa = stderr 31 | 32 | if aa: 33 | str0 = cmd[0] + ' ' + cmd[1] + ' ' + cmd[2] + ' ' + cmd[3] + '\n' 34 | #print(aa) 35 | with open(err_file, 'a') as f: 36 | f.write(str0) 37 | f.write(aa) 38 | f.write('\n') 39 | 40 | return 41 | ######################################################################### 42 | 43 | INTRODUCTION = ''' 44 | ------------------------------------------------------------------- 45 | Geocode interferograms for one project using GAMMA. 46 | 47 | ''' 48 | 49 | EXAMPLE = ''' 50 | Usage: 51 | geocode_gamma_all.py projectName 52 | geocode_gamma_all.py projectName --parallel 4 53 | geocode_gamma_all.py projectName --parallel 4 --ifgramList-txt /test/ifgram_list.txt 54 | ------------------------------------------------------------------- 55 | ''' 56 | 57 | 58 | def cmdLineParse(): 59 | parser = argparse.ArgumentParser(description='Geocode interferograms for one project using GAMMA.',\ 60 | formatter_class=argparse.RawTextHelpFormatter,\ 61 | epilog=INTRODUCTION+'\n'+EXAMPLE) 62 | 63 | parser.add_argument('projectName',help='projectName for processing.') 64 | parser.add_argument('--parallel', dest='parallelNumb', type=int, default=1, help='Enable parallel processing and Specify the number of processors.') 65 | parser.add_argument('--ifgarmList-txt', dest='ifgarmListTxt', help='provided ifgram_list_txt. default: using ifgram_list.txt under projectName folder.') 66 | 67 | inps = parser.parse_args() 68 | return inps 69 | 70 | 71 | def main(argv): 72 | start_time = time.time() 73 | inps = cmdLineParse() 74 | projectName = inps.projectName 75 | scratchDir = os.getenv('SCRATCHDIR') 76 | templateDir = os.getenv('TEMPLATEDIR') 77 | templateFile = templateDir + "/" + projectName + ".template" 78 | projectDir = scratchDir + '/' + projectName 79 | ifgDir = scratchDir + '/' + projectName + '/ifgrams' 80 | templateDict=ut.update_template(templateFile) 81 | rlks = templateDict['range_looks'] 82 | azlks = templateDict['azimuth_looks'] 83 | 84 | if inps.ifgarmListTxt: ifgramList_txt = inps.ifgarmListTxt 85 | else: ifgramList_txt = scratchDir + '/' + projectName + '/ifgram_list.txt' 86 | ifgList0 = ut.read_txt2array(ifgramList_txt) 87 | ifgList = ifgList0[:,0] 88 | 89 | err_txt = scratchDir + '/' + projectName + '/geocode_gamma_all.err' 90 | if os.path.isfile(err_txt): os.remove(err_txt) 91 | 92 | data_para = [] 93 | for i in range(len(ifgList)): 94 | #m0 = ut.yyyymmdd(ifgList[i].split('-')[0]) 95 | #s0 = ut.yyyymmdd(ifgList[i].split('-')[1]) 96 | cmd0 = ['geocode_gamma.py',projectName, ifgList[i]] 97 | data0 = [cmd0,err_txt] 98 | geo_file0 = ifgDir + '/' + ifgList[i] + '/geo_' + ifgList[i] + '_' + rlks + 'rlks.diff_filt.unw.bmp' 99 | 100 | k00 = 0 101 | if os.path.isfile(geo_file0): 102 | if os.path.getsize(geo_file0) > 0: 103 | k00 = 1 104 | if k00==0: 105 | data_para.append(data0) 106 | 107 | data_para.append(data0) 108 | 109 | ut.parallel_process(data_para, work, n_jobs=inps.parallelNumb, use_kwargs=False) 110 | print("Geocode interferograms for project %s is done! " % projectName) 111 | ut.print_process_time(start_time, time.time()) 112 | 113 | sys.exit(1) 114 | 115 | if __name__ == '__main__': 116 | main(sys.argv[:]) 117 | -------------------------------------------------------------------------------- /pyint/makedem_pyint.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | import numpy as np 9 | import os 10 | import sys 11 | import argparse 12 | 13 | from pyint import _utils as ut 14 | 15 | def cmdLineParse(): 16 | parser = argparse.ArgumentParser(description='Generate radar-coordinates based DEM.',\ 17 | formatter_class=argparse.RawTextHelpFormatter,\ 18 | epilog=INTRODUCTION+'\n'+EXAMPLE) 19 | 20 | parser.add_argument('projectName', help='Name of project.') 21 | parser.add_argument('-p', '--processor', dest='processor',choices = {'gamma','roi_pac'}, default = 'gamma', help='Interferometry processor.[default: gamma]') 22 | # easy to extend to other porcessors, e.g., ISCE, SNAP 23 | 24 | inps = parser.parse_args() 25 | 26 | return inps 27 | 28 | 29 | INTRODUCTION = ''' 30 | ------------------------------------------------------------------- 31 | 32 | Generate radar-coordinates based DEM. 33 | [Geo-coordinates DEM can be downloaded automatically if not provided.] 34 | ''' 35 | 36 | EXAMPLE = """Usage: 37 | 38 | makedem_pyint.py projectName --processor gamma 39 | 40 | makedem_pyint.py PacayaT163TsxHhA 41 | makedem_pyint.py PacayaT163TsxHhA --processor roi_pac 42 | makedem_pyint.py PacayaT163TsxHhA --processor gamma 43 | 44 | ------------------------------------------------------------------- 45 | """ 46 | 47 | def main(argv): 48 | 49 | inps = cmdLineParse() 50 | projectName = inps.projectName 51 | processor = inps.processor 52 | scratchDir = os.getenv('SCRATCHDIR') 53 | slcDir = scratchDir + '/' + projectName + "/SLC" 54 | KK=os.listdir(slcDir) 55 | templateDir = os.getenv('TEMPLATEDIR') 56 | templateFile = templateDir + "/" + projectName + ".template" 57 | templateDict=ut.update_template(templateFile) 58 | 59 | masterDate = templateDict['masterDate'] 60 | SLC_PAR = slcDir + '/' + masterDate + '/'+ masterDate + '.slc.par' 61 | 62 | demDir = os.getenv('DEMDIR') 63 | if not os.path.isdir(demDir): 64 | os.mkdir(demDir) 65 | 66 | demDir1 = demDir + '/' + projectName 67 | if not os.path.isdir(demDir1): 68 | os.mkdir(demDir1) 69 | 70 | os.chdir(demDir1) 71 | call_str= 'makedem.py ' + '-s ' + SLC_PAR + ' -p ' + processor + ' -o ' + projectName 72 | os.system(call_str) 73 | 74 | print('Generate DEM for project %s is done.' % projectName) 75 | sys.exit(1) 76 | 77 | if __name__ == '__main__': 78 | main(sys.argv[:]) 79 | -------------------------------------------------------------------------------- /pyint/pot_gamma_subset_jobs.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2022, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import getopt 13 | import time 14 | import glob 15 | import argparse 16 | 17 | from pyint import _utils as ut 18 | 19 | 20 | INTRODUCTION = ''' 21 | ------------------------------------------------------------------- 22 | Pixel offset tracking for co-registered Images. TOPs should be deramped in advance. 23 | 24 | ''' 25 | 26 | EXAMPLE = ''' 27 | Usage: 28 | pot_gamma_subset_jobs.py projectName Mdate Sdate --memory memory_single_job --walltime walltime_single_job 29 | pot_gamma_subset_jobs.py PacayaT163TsxHhA 20150102 20150601 --memory 5000 --walltime 00:30:00 30 | ------------------------------------------------------------------- 31 | ''' 32 | 33 | 34 | def cmdLineParse(): 35 | parser = argparse.ArgumentParser(description='Pixel offset tracking based Azimuth/Range dispalcement estimation.',\ 36 | formatter_class=argparse.RawTextHelpFormatter,\ 37 | epilog=INTRODUCTION+'\n'+EXAMPLE) 38 | 39 | parser.add_argument('projectName',help='projectName for processing.') 40 | parser.add_argument('Mdate',help='Master date.') 41 | parser.add_argument('Sdate',help='Slave date.') 42 | parser.add_argument('--memory',dest = 'memory',default = '5000', help='memory to be allocated for one job, default: 5GB') 43 | parser.add_argument('--walltime',dest = 'walltime',default = '00:30:00', help='walltime to be allocated for one single job') 44 | inps = parser.parse_args() 45 | inps = parser.parse_args() 46 | return inps 47 | 48 | 49 | def main(argv): 50 | 51 | start_time = time.time() 52 | inps = cmdLineParse() 53 | Mdate = inps.Mdate 54 | Sdate = inps.Sdate 55 | 56 | projectName = inps.projectName 57 | scratchDir = os.getenv('SCRATCHDIR') 58 | templateDir = os.getenv('TEMPLATEDIR') 59 | templateFile = templateDir + "/" + projectName + ".template" 60 | templateDict=ut.update_template(templateFile) 61 | 62 | 63 | slcDir = scratchDir + '/' + projectName + '/SLC' 64 | rslcDir = scratchDir + '/' + projectName + '/RSLC' 65 | 66 | MrslcDir = rslcDir + '/' + Mdate 67 | SrslcDir = rslcDir + '/' + Sdate 68 | Pair = Mdate + '-' + Sdate 69 | batch_txt = scratchDir + '/' + projectName + '/ifgrams/' + Pair + '/Batch_POT' 70 | workDir = scratchDir + '/' + projectName + '/ifgrams/' + Pair 71 | if not os.path.isdir(workDir): 72 | os.mkdir(workDir) 73 | os.chdir(workDir) 74 | if os.path.isfile(batch_txt): 75 | os.remove(batch_txt) 76 | 77 | mrslc_list = glob.glob(MrslcDir + '/*_0*.rslc');mrslc_list.sort(); nn = len(mrslc_list) 78 | print('Total patch numbers: ' + str(nn)) 79 | 80 | for i in range(nn): 81 | base0 = os.path.basename(mrslc_list[i]); subset1 = base0.split('_')[1]; subset0 = subset1.split('.rslc')[0] 82 | str0 = 'pot_gamma_subset.py ' + projectName + ' ' + Mdate + ' ' + Sdate + ' ' + subset0 83 | call_str = 'echo ' + str0 + ' >>' + batch_txt 84 | os.system(call_str) 85 | 86 | call_str = 'sbatch_jobs.py ' + batch_txt + ' --memory ' + inps.memory + ' --walltime ' + inps.walltime + ' --job-name ' + Pair + '_POT' 87 | os.system(call_str) 88 | 89 | 90 | print("Pixel offset tracking is Done!") 91 | ut.print_process_time(start_time, time.time()) 92 | #sys.exit(1) 93 | 94 | if __name__ == '__main__': 95 | main(sys.argv[:]) 96 | -------------------------------------------------------------------------------- /pyint/process_tsifg.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v1.0 ### 4 | ### Copy Right (c): 2017, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : Central South University & University of Miami ### 8 | ################################################################# 9 | 10 | import numpy as np 11 | import os 12 | import sys 13 | import subprocess 14 | import getopt 15 | import time 16 | import glob 17 | 18 | def check_variable_name(path): 19 | s=path.split("/")[0] 20 | if len(s)>0 and s[0]=="$": 21 | p0=os.getenv(s[1:]) 22 | path=path.replace(path.split("/")[0],p0) 23 | return path 24 | 25 | def read_template(File, delimiter='='): 26 | '''Reads the template file into a python dictionary structure. 27 | Input : string, full path to the template file 28 | Output: dictionary, pysar template content 29 | Example: 30 | tmpl = read_template(KyushuT424F610_640AlosA.template) 31 | tmpl = read_template(R1_54014_ST5_L0_F898.000.pi, ':') 32 | ''' 33 | template_dict = {} 34 | for line in open(File): 35 | line = line.strip() 36 | c = [i.strip() for i in line.split(delimiter, 1)] #split on the 1st occurrence of delimiter 37 | if len(c) < 2 or line.startswith('%') or line.startswith('#'): 38 | next #ignore commented lines or those without variables 39 | else: 40 | atrName = c[0] 41 | atrValue = str.replace(c[1],'\n','').split("#")[0].strip() 42 | atrValue = check_variable_name(atrValue) 43 | template_dict[atrName] = atrValue 44 | return template_dict 45 | 46 | def is_number(s): 47 | try: 48 | int(s) 49 | return True 50 | except ValueError: 51 | return False 52 | 53 | 54 | def ras2jpg(input, strTitle): 55 | call_str = "convert " + input + ".ras " + input + ".jpg" 56 | os.system(call_str) 57 | call_str = "convert " + input + ".jpg -resize 250 " + input + ".thumb.jpg" 58 | os.system(call_str) 59 | call_str = "convert " + input + ".jpg -resize 500 " + input + ".bthumb.jpg" 60 | os.system(call_str) 61 | call_str = "$INT_SCR/addtitle2jpg.pl " + input + ".thumb.jpg 14 " + strTitle 62 | os.system(call_str) 63 | call_str = "$INT_SCR/addtitle2jpg.pl " + input + ".bthumb.jpg 24 " + strTitle 64 | os.system(call_str) 65 | 66 | def UseGamma(inFile, task, keyword): 67 | if task == "read": 68 | f = open(inFile, "r") 69 | while 1: 70 | line = f.readline() 71 | if not line: break 72 | if line.count(keyword) == 1: 73 | strtemp = line.split(":") 74 | value = strtemp[1].strip() 75 | return value 76 | print("Keyword " + keyword + " doesn't exist in " + inFile) 77 | f.close() 78 | 79 | def write_template(File, Str): 80 | f = open(File,'a') 81 | f.write(Str) 82 | f.close() 83 | 84 | def write_run_coreg_all(projectName,master,slavelist,workdir): 85 | scratchDir = os.getenv('SCRATCHDIR') 86 | projectDir = scratchDir + '/' + projectName 87 | run_coreg_all = projectDir + "/run_coreg_all" 88 | f_coreg = open(run_coreg_all,'w') 89 | 90 | for kk in range(len(slavelist)): 91 | str_coreg = "GenOff_Gamma.py " + projectName + ' ' + master + ' ' + slavelist[kk] + ' ' + workdir + '\n' 92 | f_coreg.write(str_coreg) 93 | f_coreg.close() 94 | 95 | 96 | def usage(): 97 | print(''' 98 | ****************************************************************************************************** 99 | 100 | Process time series of interferograms from downloading data or SLC images. 101 | 102 | usage: 103 | 104 | process_tsifg.py projectName 105 | 106 | e.g. process_tsifg.py PacayaT163TsxHhA 107 | process_tsifg.py PacayaT163S1A 108 | 109 | ******************************************************************************************************* 110 | ''') 111 | 112 | def main(argv): 113 | 114 | if len(sys.argv)==2: 115 | if argv[0] in ['-h','--help']: usage(); sys.exit(1) 116 | else: projectName=sys.argv[1] 117 | else: 118 | usage();sys.exit(1) 119 | 120 | if 'S1' in projectName: 121 | call_str='process_tsifg_sen.py ' + projectName 122 | else: 123 | call_str='process_tsifg_gamma.py ' + projectName 124 | 125 | os.system(call_str) 126 | 127 | 128 | if __name__ == '__main__': 129 | main(sys.argv[:]) 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /pyint/raw2ifg.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import subprocess 13 | import time 14 | import argparse 15 | 16 | from pyint import _utils as ut 17 | 18 | 19 | def cmdLineParse(): 20 | parser = argparse.ArgumentParser(description='Generate unwrapped differential Ifg from SLC-raw data using GAMMA.',\ 21 | formatter_class=argparse.RawTextHelpFormatter,\ 22 | epilog=INTRODUCTION+'\n'+EXAMPLE) 23 | 24 | parser.add_argument('projectName', help='name of the project.') 25 | parser.add_argument('Mdate',help='master date for interferometry.') 26 | parser.add_argument('Sdate',help='slave date for interferometry.') 27 | 28 | inps = parser.parse_args() 29 | 30 | return inps 31 | 32 | 33 | INTRODUCTION = ''' 34 | -------------------------------------------------------------------------------------- 35 | Generate unwrapped differential Ifg from SLC-raw data using GAMMA. 36 | 37 | Note: 1) Precise orbit data will be downloaded and processed automatically 38 | 2) SRTM-1 will be downloaded and processed automatically if not provided 39 | in the template file. 40 | 41 | ''' 42 | 43 | EXAMPLE = """Usage: 44 | 45 | raw2ifg.py projectName Mdate Sdate 46 | --------------------------------------------------------------------------------------- 47 | """ 48 | 49 | def main(argv): 50 | 51 | inps = cmdLineParse() 52 | Mdate = inps.Mdate 53 | Sdate = inps.Sdate 54 | 55 | projectName = inps.projectName 56 | 57 | if 'S1' in projectName: 58 | call_str = 'raw2ifg_s1.py ' + projectName + ' ' + ut.yyyymmdd(Mdate) + ' ' + ut.yyyymmdd(Sdate) 59 | os.system(call_str) 60 | 61 | sys.exit(1) 62 | 63 | if __name__ == '__main__': 64 | main(sys.argv[:]) 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /pyint/raw2ifg_s1.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import subprocess 13 | import time 14 | import glob 15 | import argparse 16 | 17 | from pyint import _utils as ut 18 | 19 | 20 | def get_s1_date(raw_file): 21 | file0 = os.path.basename(raw_file) 22 | date = file0[17:25] 23 | return date 24 | 25 | def get_satellite(raw_file): 26 | if 'S1A_IW_SLC_' in raw_file: 27 | s0 = 'A' 28 | else: 29 | s0 = 'B' 30 | 31 | return s0 32 | 33 | 34 | def cmdLineParse(): 35 | parser = argparse.ArgumentParser(description='Generate Ifg from Sentinel-1 raw data with orbit correction using GAMMA.',\ 36 | formatter_class=argparse.RawTextHelpFormatter,\ 37 | epilog=INTRODUCTION+'\n'+EXAMPLE) 38 | 39 | parser.add_argument('projectName', help='name of the project.') 40 | parser.add_argument('Mdate',help='master date for interferometry.') 41 | parser.add_argument('Sdate',help='slave date for interferometry.') 42 | 43 | inps = parser.parse_args() 44 | 45 | return inps 46 | 47 | 48 | INTRODUCTION = ''' 49 | --------------------------------------------------------------------------------------------------- 50 | Generate unwrapped differential Ifg from Sentinel-1 raw data with orbit correction using GAMMA. 51 | 52 | Note: 1) Precise orbit data will be downloaded and processed automatically 53 | 2) SRTM-1 will be downloaded and processed automatically if not provided 54 | in the template file. 55 | 56 | ''' 57 | 58 | EXAMPLE = """Usage: 59 | 60 | raw2ifg_s1.py projectName Mdate Sdate 61 | ---------------------------------------------------------------------------------------------------- 62 | """ 63 | 64 | def main(argv): 65 | 66 | start_time = time.time() 67 | inps = cmdLineParse() 68 | Mdate = inps.Mdate 69 | Sdate = inps.Sdate 70 | 71 | projectName = inps.projectName 72 | scratchDir = os.getenv('SCRATCHDIR') 73 | templateDir = os.getenv('TEMPLATEDIR') 74 | templateFile = templateDir + "/" + projectName + ".template" 75 | templateDict=ut.update_template(templateFile) 76 | 77 | rlks = templateDict['range_looks'] 78 | azlks = templateDict['azimuth_looks'] 79 | masterDate = templateDict['masterDate'] 80 | downDir = scratchDir + '/' + projectName + '/DOWNLOAD' 81 | #M_raw = glob.glob(downDir + '/S1*_' + ut.yyyymmdd(Mdate)+'*')[0] 82 | #S_raw = glob.glob(downDir + '/S1*_' + ut.yyyymmdd(Sdate)+'*')[0] 83 | slcDir = scratchDir + '/' + projectName + '/SLC' 84 | 85 | 86 | ######### down 2 slc ############# 87 | call_str = 'down2slc_sen.py ' + projectName + ' ' + Mdate 88 | os.system(call_str) 89 | 90 | call_str = 'down2slc_sen.py ' + projectName + ' ' + Sdate 91 | os.system(call_str) 92 | 93 | ########## extract common bursts ## 94 | #call_str = 'extract_s1_bursts.py ' + projectName + ' ' + Mdate 95 | #os.system(call_str) 96 | 97 | #call_str = 'extract_s1_bursts.py ' + projectName + ' ' + Sdate 98 | #os.system(call_str) 99 | 100 | ######### generate rdc_dem ########## 101 | demDir = scratchDir + '/' + projectName + '/DEM' 102 | HGTSIM = demDir + '/' + masterDate + '_' + rlks + 'rlks.rdc.dem' 103 | if not os.path.isfile(HGTSIM): 104 | call_str = 'generate_rdc_dem.py ' + projectName 105 | os.system(call_str) 106 | 107 | ########## coregister SLC ######## 108 | 109 | call_str = 'coreg_s1_gamma.py ' + projectName + ' ' + Mdate 110 | os.system(call_str) 111 | 112 | call_str = 'coreg_s1_gamma.py ' + projectName + ' ' + Sdate 113 | os.system(call_str) 114 | 115 | ######## Interferometry process ########### 116 | call_str = 'diff_gamma.py ' + projectName + ' ' + Mdate + ' ' + Sdate 117 | os.system(call_str) 118 | 119 | call_str = 'unwrap_gamma.py ' + projectName + ' ' + Mdate + ' ' + Sdate 120 | os.system(call_str) 121 | 122 | call_str = 'geocode_gamma.py ' + projectName + ' ' + Mdate + '-' + Sdate 123 | os.system(call_str) 124 | 125 | print("Generate Ifg from raw-TOPs data is done! ") 126 | ut.print_process_time(start_time, time.time()) 127 | sys.exit(1) 128 | 129 | if __name__ == '__main__': 130 | main(sys.argv[:]) 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /pyint/raw2slc_ers_envisat.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.0 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Email : ymcmrs@gmail.com ### 7 | ### Univ. : Now at KAUST ### 8 | ################################################################# 9 | 10 | import numpy as np 11 | import os 12 | import sys 13 | import subprocess 14 | import getopt 15 | import time 16 | import glob 17 | import argparse 18 | import linecache 19 | import datetime 20 | 21 | def StrNum(S): 22 | S = str(S) 23 | if len(S)==1: 24 | S='0' +S 25 | return S 26 | 27 | def UseGamma(inFile, task, keyword): 28 | if task == "read": 29 | f = open(inFile, "r") 30 | while 1: 31 | line = f.readline() 32 | if not line: break 33 | if line.count(keyword) == 1: 34 | strtemp = line.split(":") 35 | value = strtemp[1].strip() 36 | return value 37 | print("Keyword " + keyword + " doesn't exist in " + inFile) 38 | f.close() 39 | 40 | 41 | def check_ERS_par(SAR_IM_0P): 42 | Name = os.path.basename(SAR_IM_0P) 43 | ff = Name.split('.')[1] 44 | date = (Name.split('SAR_IM__0PWDSI')[1]).split('_')[0] 45 | 46 | if ff == 'E1': 47 | par = 'ERS1_ESA.par' 48 | antenna = 'ERS1_antenna.gain' 49 | orbdir = os.getenv('ERS1ORBDIR') 50 | elif ff == 'E2': 51 | par = 'ERS2_ESA.par' 52 | antenna = 'ERS2_antenna.gain' 53 | orbdir = os.getenv('ERS2ORBDIR') 54 | else: 55 | print('Invalid input SAR_IM_0P file.') 56 | sys.exit(1) 57 | 58 | return par, antenna, orbdir, date 59 | 60 | ######################################################################### 61 | 62 | INTRODUCTION = ''' 63 | ############################################################################# 64 | Copy Right(c): 2017-2019, Yunmeng Cao @PyINT v1.0 65 | 66 | Generate SLC for ERS raw data with ENVISAT format 67 | 68 | ''' 69 | 70 | EXAMPLE = ''' 71 | Usage: 72 | raw2slc_ers_envisat.py SAR_IM_OP -o output_prefix 73 | 74 | Examples: 75 | raw2slc_ers_envisat.py SAR_IM_OP -o 19950102 76 | 77 | ############################################################################## 78 | ''' 79 | 80 | 81 | def cmdLineParse(): 82 | parser = argparse.ArgumentParser(description='Generate SLC for ERS raw data with ENVISAT format.',\ 83 | formatter_class=argparse.RawTextHelpFormatter,\ 84 | epilog=INTRODUCTION+'\n'+EXAMPLE) 85 | 86 | parser.add_argument('ers_envisat_raw',help='ERS raw data with ENVISAT format, e.g., SAR_IM_0PXXXX.E1') 87 | parser.add_argument('-o',dest='out_put',help='prefix of the output file, e.g., output.slc, output.slc.par') 88 | 89 | inps = parser.parse_args() 90 | return inps 91 | 92 | ################################################################################ 93 | 94 | 95 | def main(argv): 96 | 97 | inps = cmdLineParse() 98 | SAR_IM_0P = inps.ers_envisat_raw 99 | par,antenna,orbdir,date = check_ERS_par(SAR_IM_0P) 100 | 101 | raw = date + '.raw' 102 | azsp = date + '.azsp' 103 | dop = date + '.dop' 104 | rspec = date + '.rspec' 105 | rc = date + '.rc' 106 | autof = date + '.autof' 107 | dop_ambig = date + '.dop_ambig' 108 | 109 | if not os.path.isfile(par): 110 | call_str = 'cp $GAMMA_HOME/MSP/sensors/' + par + ' .' 111 | os.system(call_str) 112 | if not os.path.isfile(antenna): 113 | call_str = 'cp $GAMMA_HOME/MSP/sensors/' + antenna + ' .' 114 | os.system(call_str) 115 | 116 | if inps.out_put: 117 | pslc_par = 'p' + inps.out_put + '.slc.par' 118 | slc_par = inps.out_put + '.slc.par' 119 | slc = inps.out_put + '.slc' 120 | mli_par = inps.out_put + '.mli.par' 121 | mli = inps.out_put + '.mli' 122 | else: 123 | pslc_par = 'p' + date + '.slc.par' 124 | slc_par = date + '.slc.par' 125 | slc = date + '.slc' 126 | mli_par = date + '.mli.par' 127 | mli = date + '.mli' 128 | 129 | call_str = 'ERS_ENVISAT_proc ' + SAR_IM_0P + ' ' + par + ' ' + pslc_par + ' ' + raw 130 | os.system(call_str) 131 | 132 | call_str = 'DELFT_proc2 ' + pslc_par + ' ' + orbdir + ' 20' 133 | os.system(call_str) 134 | 135 | cal_str = 'dop_ambig ' + par + ' ' + pslc_par + ' ' + raw + ' 2 - ' + dop_ambig 136 | os.system(call_str) 137 | 138 | call_str = 'azsp_IQ ' + par + ' ' + pslc_par + ' ' + raw + ' ' + azsp 139 | os.system(call_str) 140 | 141 | call_str = 'doppler ' + par + ' ' + pslc_par + ' ' + raw + ' ' + dop 142 | os.system(call_str) 143 | 144 | call_str = 'rspec_IQ ' + par + ' ' + pslc_par + ' ' + raw + ' ' + rspec 145 | os.system(call_str) 146 | 147 | call_str = 'pre_rc ' + par + ' ' + pslc_par + ' ' + raw + ' ' + rc 148 | os.system(call_str) 149 | 150 | call_str = 'autof ' + par + ' ' + pslc_par + ' ' + rc + ' ' + autof + ' 2.0 ' 151 | os.system(call_str) 152 | 153 | call_str = 'autof ' + par + ' ' + pslc_par + ' ' + rc + ' ' + autof + ' 2.0 ' 154 | os.system(call_str) 155 | 156 | call_str = 'az_proc ' + par + ' ' + pslc_par + ' ' + rc + ' ' + slc + ' 4096 1 ' + ' 57.2 0 2.120 ' 157 | os.system(call_str) 158 | 159 | call_str = 'par_MSP ' + par + ' ' + pslc_par + ' ' + slc_par + ' 1' 160 | os.system(call_str) 161 | 162 | call_str = 'multi_look ' + slc + ' ' + slc_par + ' ' + mli + ' ' + mli_par + ' 2 10' 163 | os.system(call_str) 164 | 165 | 166 | Width = UseGamma(mli_par, 'read', 'range_samples: ') 167 | call_str = 'raspwr ' + mli + ' ' + Width 168 | os.system(call_str) 169 | 170 | 171 | print("Generate SLC from %s is done." % SAR_IM_0P) 172 | sys.exit(1) 173 | 174 | if __name__ == '__main__': 175 | main(sys.argv[:]) 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /pyint/rslcCopy_gamma.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import argparse 13 | 14 | from pyint import _utils as ut 15 | 16 | 17 | INTRODUCTION = ''' 18 | ------------------------------------------------------------------- 19 | copy SLC/RSLC from large SLC/RSLC 20 | 21 | ''' 22 | 23 | EXAMPLE = ''' 24 | Usage: 25 | slcCopy_gamma.py projectName Sdate rstart rwidth astart awidth outname 26 | slcCopy_gamma.py PacayaT163TsxHhA 20150601 100 345 200 500 20150601_subset 27 | ------------------------------------------------------------------- 28 | ''' 29 | 30 | def cmdLineParse(): 31 | parser = argparse.ArgumentParser(description='Copy RSLC subset from a large SLC.',\ 32 | formatter_class=argparse.RawTextHelpFormatter,\ 33 | epilog=INTRODUCTION+'\n'+EXAMPLE) 34 | 35 | parser.add_argument('projectName',help='projectName for processing.') 36 | parser.add_argument('Date',help='Master date.') 37 | parser.add_argument('rstart',help='start point of range') 38 | parser.add_argument('rwidth',help='width of range direction') 39 | parser.add_argument('astart',help='start point of azimuth') 40 | parser.add_argument('awidth',help='width of azimith direction') 41 | parser.add_argument('name',help='output name. e.g., 20150101_subset, then .slc and .slc.par will be generated') 42 | 43 | inps = parser.parse_args() 44 | return inps 45 | 46 | 47 | def main(argv): 48 | 49 | inps = cmdLineParse() 50 | projectName = inps.projectName 51 | Date = inps.Date 52 | rstart = inps.rstart; rwidth = inps.rwidth; astart = inps.astart; awidth = inps.awidth; name = inps.name 53 | 54 | scratchDir = os.getenv('SCRATCHDIR') 55 | templateDir = os.getenv('TEMPLATEDIR') 56 | templateFile = templateDir + "/" + projectName + ".template" 57 | templateDict=ut.update_template(templateFile) 58 | rlks = templateDict['range_looks'] 59 | azlks = templateDict['azimuth_looks'] 60 | 61 | processDir = scratchDir + '/' + projectName + "/PROCESS" 62 | slcDir = scratchDir + '/' + projectName + "/SLC" 63 | rslcDir = scratchDir + '/' + projectName + '/RSLC' 64 | ifgDir = scratchDir + '/' + projectName + '/ifgrams' 65 | 66 | Dslc = rslcDir + '/' + Date + '/' + Date + '.rslc' 67 | DslcPar = rslcDir + '/' + Date + '/' + Date + '.rslc.par' 68 | 69 | Oslc = rslcDir + '/' + Date + '/' + name + '.rslc' 70 | OslcPar = rslcDir + '/' + Date + '/' + name + '.rslc.par' 71 | 72 | Oamp = rslcDir + '/' + Date + '/' + name + '_' + rlks + 'rlks.amp' 73 | OampPar = rslcDir + '/' + Date + '/' + name + '_' + rlks + 'rlks.amp.par' 74 | 75 | 76 | 77 | call_str = 'SLC_copy ' + Dslc + ' ' + DslcPar + ' ' + Oslc + ' ' + OslcPar + ' - - ' + rstart + ' ' + rwidth + ' ' + astart + ' ' + awidth + ' - -' 78 | os.system(call_str) 79 | 80 | call_str = 'multi_look ' + Oslc + ' ' + OslcPar + ' ' + Oamp + ' ' + OampPar + ' ' + rlks + ' ' + azlks 81 | os.system(call_str) 82 | #os.remove(MampPar) 83 | #os.remove(SampPar) 84 | print(call_str) 85 | print("RSLC copy done.") 86 | #sys.exit(1) 87 | 88 | if __name__ == '__main__': 89 | main(sys.argv[:]) 90 | -------------------------------------------------------------------------------- /pyint/rslcCopy_gamma_jobs.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import argparse 13 | 14 | from pyint import _utils as ut 15 | 16 | 17 | INTRODUCTION = ''' 18 | ------------------------------------------------------------------- 19 | copy SLC/RSLC from large SLC/RSLC 20 | 21 | ''' 22 | 23 | EXAMPLE = ''' 24 | Usage: 25 | slcCopy_gamma_jobs.py projectName Sdate rwidth awidth --memory memory_single_job --walltime walltime_single_job 26 | slcCopy_gamma_jobs.py PacayaT163TsxHhA 20150601 5000 5000 --memory 5000 --walltime 00:30:00 27 | ------------------------------------------------------------------- 28 | ''' 29 | 30 | def cmdLineParse(): 31 | parser = argparse.ArgumentParser(description='Copy SLC subset from a large SLC.',\ 32 | formatter_class=argparse.RawTextHelpFormatter,\ 33 | epilog=INTRODUCTION+'\n'+EXAMPLE) 34 | 35 | parser.add_argument('projectName',help='projectName for processing.') 36 | parser.add_argument('Date',help='Master date.') 37 | parser.add_argument('rwidth',help='width of range direction') 38 | parser.add_argument('awidth',help='width of azimith direction') 39 | parser.add_argument('--memory',dest = 'memory',default = '2000', help='memory to be allocated for one job, default: 5GB') 40 | parser.add_argument('--walltime',dest = 'walltime',default = '00:05:00', help='walltime to be allocated for one single job') 41 | inps = parser.parse_args() 42 | return inps 43 | 44 | 45 | def main(argv): 46 | 47 | inps = cmdLineParse() 48 | projectName = inps.projectName 49 | Date = inps.Date; rwidth = inps.rwidth; awidth = inps.awidth; memory = inps.memory; walltime = inps.walltime 50 | 51 | scratchDir = os.getenv('SCRATCHDIR') 52 | templateDir = os.getenv('TEMPLATEDIR') 53 | templateFile = templateDir + "/" + projectName + ".template" 54 | templateDict=ut.update_template(templateFile) 55 | rlks = templateDict['range_looks'] 56 | azlks = templateDict['azimuth_looks'] 57 | 58 | processDir = scratchDir + '/' + projectName + "/PROCESS" 59 | slcDir = scratchDir + '/' + projectName + "/SLC" 60 | rslcDir = scratchDir + '/' + projectName + '/RSLC' 61 | ifgDir = scratchDir + '/' + projectName + '/ifgrams' 62 | 63 | Dslc = rslcDir + '/' + Date + '/' + Date + '.rslc' 64 | DslcPar = rslcDir + '/' + Date + '/' + Date + '.rslc.par' 65 | 66 | nWidth = ut.read_gamma_par(DslcPar, 'read', 'range_samples') 67 | nLine = ut.read_gamma_par(DslcPar, 'read', 'azimuth_lines') 68 | 69 | Ap_samp = np.arange(1,int(nLine),int(awidth)); Na0 = len(Ap_samp); LA_end = int(nLine) - Ap_samp[Na0-1] 70 | Rp_samp = np.arange(1,int(nWidth),int(rwidth)); Nr0 = len(Rp_samp); LR_end = int(nWidth) - Rp_samp[Nr0-1] 71 | 72 | if LA_end > (2/3*int(awidth)): 73 | Ap_samp1 = Ap_samp 74 | else: 75 | Ap_samp1 = Ap_samp[0:(Na0-1)] # last batch with '-' means to the end 76 | 77 | if LR_end > (2/3*int(rwidth)): 78 | Rp_samp1 = Rp_samp 79 | else: 80 | Rp_samp1 = Rp_samp[0:(Nr0-1)] # last batch with '-' means to the end 81 | 82 | Na = len(Ap_samp1); Nr = len(Rp_samp1); Ntotal = Na*Nr 83 | print('Azimuth samples: ' + str(Na)) 84 | print('Range samples: ' + str(Nr)) 85 | print('Total batch numbers: ' + str(Ntotal)) 86 | 87 | batch_txt = scratchDir + '/' + projectName + '/RSLC/' + Date + '/Batch_copySLC' 88 | workDir = scratchDir + '/' + projectName + '/RSLC/' + Date 89 | if os.path.isfile(batch_txt): 90 | os.remove(batch_txt) 91 | for i in range(Na): 92 | for j in range(Nr): 93 | if len(str(i)) == 1: 94 | i0 = '0' + str(i) 95 | else: 96 | i0 = str(i) 97 | if len(str(j)) == 1: 98 | j0 = '0' + str(j) 99 | else: 100 | j0 = str(j) 101 | name0 = Date + '_' +i0 + j0 102 | rstart = str(Rp_samp1[j]); astart = str(Ap_samp1[i]) 103 | if rstart == str(Rp_samp1[Nr-1]): 104 | rwidth0 = '-' 105 | else: 106 | rwidth0 = str(int(int(rwidth) + 200)) # extend 200 to avoid edge effect 107 | 108 | if astart == str(Ap_samp1[Na-1]): 109 | awidth0 = '-' 110 | else: 111 | awidth0 = str(int(int(awidth) + 200)) # extend 200 to avoid edge effect 112 | 113 | if not i==0: 114 | astart0 = str(int(int(astart) - 200)) # extend 200 to avoid edge effect 115 | else: 116 | astart0 = astart 117 | 118 | if not j==0: 119 | rstart0 = str(int(int(rstart) - 200)) # extend 200 to avoid edge effect 120 | else: 121 | rstart0 = rstart 122 | 123 | #str0 = 'SLC_copy ' + Dslc + ' ' + DslcPar + ' ' + workDir + '/' + name0 + '.rslc' + ' ' + workDir + '/' + name0 + '.rslc.par - - ' + rstart0 + ' ' + rwidth0 + ' ' + astart0 + ' ' + awidth0 + ' - -' 124 | str0 = 'rslcCopy_gamma.py ' + projectName + ' ' + Date + ' ' + rstart0 + ' ' + rwidth0 + ' ' + astart0 + ' ' + awidth0 + ' ' + name0 125 | call_str = 'echo ' + str0 + ' >>' + batch_txt 126 | os.system(call_str) 127 | 128 | call_str = 'sbatch_jobs.py ' + batch_txt + ' --memory ' + inps.memory + ' --walltime ' + inps.walltime + ' --job-name ' + Date + '_copySLC' 129 | os.system(call_str) 130 | 131 | print("RSLC copy done: " + Date) 132 | #sys.exit(1) 133 | 134 | if __name__ == '__main__': 135 | main(sys.argv[:]) 136 | -------------------------------------------------------------------------------- /pyint/s1_orb_all.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import getopt 13 | import time 14 | import glob 15 | import argparse 16 | 17 | import subprocess 18 | from pyint import _utils as ut 19 | 20 | 21 | def work(data0): 22 | cmd = data0[0] 23 | err_txt = data0[1] 24 | 25 | p = subprocess.run(cmd, shell=False,stderr=subprocess.PIPE, stdout=subprocess.PIPE) 26 | stdout = p.stdout 27 | stderr = p.stderr 28 | 29 | if type(stderr) == bytes: 30 | aa=stderr.decode("utf-8") 31 | else: 32 | aa = stderr 33 | 34 | if aa: 35 | str0 = cmd[0] + ' ' + cmd[1] + ' ' + cmd[2] + '\n' 36 | #print(aa) 37 | with open(err_txt, 'a') as f: 38 | f.write(str0) 39 | f.write(aa) 40 | f.write('\n') 41 | 42 | return 43 | ######################################################################### 44 | 45 | INTRODUCTION = ''' 46 | ------------------------------------------------------------------- 47 | Using precise orbit data for all rslcs. 48 | 49 | ''' 50 | 51 | EXAMPLE = ''' 52 | Usage: 53 | generate_amp_all.py projectName 54 | generate_amp_all.py projectName --parallel 4 55 | ------------------------------------------------------------------- 56 | ''' 57 | 58 | 59 | def cmdLineParse(): 60 | parser = argparse.ArgumentParser(description='Using precise orbit data for all rslcs.',\ 61 | formatter_class=argparse.RawTextHelpFormatter,\ 62 | epilog=INTRODUCTION+'\n'+EXAMPLE) 63 | 64 | parser.add_argument('projectName',help='projectName for processing.') 65 | parser.add_argument('--parallel', dest='parallelNumb', type=int, default=1, help='Enable parallel processing and Specify the number of processors.') 66 | 67 | inps = parser.parse_args() 68 | return inps 69 | 70 | 71 | def main(argv): 72 | start_time = time.time() 73 | inps = cmdLineParse() 74 | projectName = inps.projectName 75 | scratchDir = os.getenv('SCRATCHDIR') 76 | projectDir = scratchDir + '/' + projectName 77 | slcDir = scratchDir + '/' + projectName + '/SLC' 78 | rslcDir = scratchDir + '/' + projectName + '/RSLC' 79 | if not os.path.isdir(rslcDir): os.mkdir(rslcDir) 80 | 81 | cmd_command = 'generate_multilook_amp.py' 82 | 83 | err_txt = scratchDir + '/' + projectName + '/generate_amp_all.err' 84 | if os.path.isfile(err_txt): os.remove(err_txt) 85 | 86 | data_para = [] 87 | slc_list = [os.path.basename(fname) for fname in sorted(glob.glob(rslcDir + '/*'))] 88 | #slc_list = ut.get_project_slcList(projectName) 89 | for i in range(len(slc_list)): 90 | rslcPar = rslcDir + '/' + slc_list[i] + '/' + slc_list[i] + '.rslc.par' 91 | #print(rslcPar) 92 | workDir0 = rslcDir + '/' + slc_list[i] 93 | BB = glob.glob(workDir0 + '/*.EOF') 94 | if len(BB)==0: 95 | Sensor = ut.read_gamma_par(rslcPar,'read','sensor') 96 | if 'A' in Sensor: satellite = 'A' 97 | else: satellite = 'B' 98 | ut.download_s1_orbit(slc_list[i],workDir0,satellite=satellite) 99 | 100 | BB = glob.glob(workDir0 + '/*.EOF') 101 | if len(BB) > 0: 102 | orb_file = BB[0] 103 | 104 | call_str = 'S1_OPOD_vec ' + rslcPar + ' ' + orb_file + ' 31' 105 | os.system(call_str) 106 | 107 | print("Using precise orbit data for all rslcs is done! ") 108 | ut.print_process_time(start_time, time.time()) 109 | 110 | sys.exit(1) 111 | 112 | if __name__ == '__main__': 113 | main(sys.argv[:]) 114 | -------------------------------------------------------------------------------- /pyint/slc2ifg.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import subprocess 13 | import time 14 | import glob 15 | import argparse 16 | 17 | from pyint import _utils as ut 18 | 19 | 20 | def get_s1_date(raw_file): 21 | file0 = os.path.basename(raw_file) 22 | date = file0[17:25] 23 | return date 24 | 25 | def get_satellite(raw_file): 26 | if 'S1A_IW_SLC_' in raw_file: 27 | s0 = 'A' 28 | else: 29 | s0 = 'B' 30 | 31 | return s0 32 | 33 | 34 | def cmdLineParse(): 35 | parser = argparse.ArgumentParser(description='Generate Ifg from SLC using GAMMA.',\ 36 | formatter_class=argparse.RawTextHelpFormatter,\ 37 | epilog=INTRODUCTION+'\n'+EXAMPLE) 38 | 39 | parser.add_argument('projectName', help='name of the project.') 40 | parser.add_argument('Mdate',help='master date for interferometry.') 41 | parser.add_argument('Sdate',help='slave date for interferometry.') 42 | 43 | inps = parser.parse_args() 44 | 45 | return inps 46 | 47 | 48 | INTRODUCTION = ''' 49 | -------------------------------------------------------------- 50 | Generate unwrapped differential Ifg from SLC using GAMMA. 51 | 52 | Note: SRTM-1 will be downloaded and processed automatically 53 | if not provided in the template file. 54 | 55 | ''' 56 | 57 | EXAMPLE = """Usage: 58 | 59 | slc2ifg.py projectName Mdate Sdate 60 | -------------------------------------------------------------- 61 | """ 62 | 63 | def main(argv): 64 | 65 | start_time = time.time() 66 | inps = cmdLineParse() 67 | Mdate = inps.Mdate 68 | Sdate = inps.Sdate 69 | 70 | projectName = inps.projectName 71 | scratchDir = os.getenv('SCRATCHDIR') 72 | templateDir = os.getenv('TEMPLATEDIR') 73 | templateFile = templateDir + "/" + projectName + ".template" 74 | templateDict=ut.update_template(templateFile) 75 | rlks = templateDict['range_looks'] 76 | azlks = templateDict['azimuth_looks'] 77 | masterDate = templateDict['masterDate'] 78 | #downDir = scratchDir + '/' + projectName + '/DOWNLOAD' 79 | #M_raw = glob.glob(downDir + '/S1*_' + ut.yyyymmdd(Mdate)+'*')[0] 80 | #S_raw = glob.glob(downDir + '/S1*_' + ut.yyyymmdd(Sdate)+'*')[0] 81 | slcDir = scratchDir + '/' + projectName + '/SLC' 82 | 83 | 84 | ######### down 2 slc ############# 85 | #call_str = 'down2slc_sen.py ' + M_raw + ' ' + slcDir 86 | #os.system(call_str) 87 | 88 | #call_str = 'down2slc_sen.py ' + S_raw + ' ' + slcDir 89 | #os.system(call_str) 90 | 91 | ########## extract common bursts ## 92 | #if 'S1' in projectName: 93 | # call_str = 'extract_s1_bursts.py ' + projectName + ' ' + Mdate 94 | # os.system(call_str) 95 | 96 | # call_str = 'extract_s1_bursts.py ' + projectName + ' ' + Sdate 97 | # os.system(call_str) 98 | 99 | ######### generate rdc_dem ########## 100 | 101 | 102 | demDir = scratchDir + '/' + projectName + '/DEM' 103 | HGTSIM = demDir + '/' + masterDate + '_' + rlks + 'rlks.rdc.dem' 104 | if not os.path.isfile(HGTSIM): 105 | call_str = 'generate_rdc_dem.py ' + projectName 106 | os.system(call_str) 107 | 108 | ########## coregister SLC ######## 109 | if 'S1' in projectName: 110 | call_str = 'coreg_s1_gamma.py ' + projectName + ' ' + Mdate 111 | os.system(call_str) 112 | 113 | call_str = 'coreg_s1_gamma.py ' + projectName + ' ' + Sdate 114 | os.system(call_str) 115 | else: 116 | call_str = 'coreg_gamma.py ' + projectName + ' ' + Mdate 117 | os.system(call_str) 118 | 119 | call_str = 'coreg_gamma.py ' + projectName + ' ' + Sdate 120 | os.system(call_str) 121 | 122 | ######## Interferometry process ########### 123 | call_str = 'diff_gamma.py ' + projectName + ' ' + Mdate + ' ' + Sdate 124 | os.system(call_str) 125 | 126 | call_str = 'unwrap_gamma.py ' + projectName + ' ' + Mdate + ' ' + Sdate 127 | os.system(call_str) 128 | 129 | call_str = 'geocode_gamma.py ' + projectName + ' ' + Mdate + '-' + Sdate 130 | os.system(call_str) 131 | 132 | print("Generate Ifg from SLC data is done! ") 133 | ut.print_process_time(start_time, time.time()) 134 | sys.exit(1) 135 | 136 | if __name__ == '__main__': 137 | main(sys.argv[:]) 138 | 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /pyint/unwrap_gamma.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import argparse 13 | 14 | from pyint import _utils as ut 15 | 16 | 17 | INTRODUCTION = ''' 18 | ------------------------------------------------------------------- 19 | Unwrap differential interferogram using GAMMA. 20 | [Only support mcf, not implement branch_cut yet] 21 | 22 | ''' 23 | 24 | EXAMPLE = ''' 25 | Usage: 26 | unwrap_gamma.py projectName Mdate Sdate 27 | unwrap_gamma.py PacayaT163TsxHhA 20150102 20150601 28 | ------------------------------------------------------------------- 29 | ''' 30 | 31 | def cmdLineParse(): 32 | parser = argparse.ArgumentParser(description='Unwrap differential interferogram using GAMMA-mcf method.',\ 33 | formatter_class=argparse.RawTextHelpFormatter,\ 34 | epilog=INTRODUCTION+'\n'+EXAMPLE) 35 | 36 | parser.add_argument('projectName',help='projectName for processing.') 37 | parser.add_argument('Mdate',help='Master date.') 38 | parser.add_argument('Sdate',help='Slave date.') 39 | 40 | inps = parser.parse_args() 41 | return inps 42 | 43 | 44 | def main(argv): 45 | 46 | inps = cmdLineParse() 47 | Mdate = inps.Mdate 48 | Sdate = inps.Sdate 49 | 50 | projectName = inps.projectName 51 | Sdate = inps.Sdate 52 | Mdate = inps.Mdate 53 | 54 | scratchDir = os.getenv('SCRATCHDIR') 55 | templateDir = os.getenv('TEMPLATEDIR') 56 | templateFile = templateDir + "/" + projectName + ".template" 57 | templateDict=ut.update_template(templateFile) 58 | rlks = templateDict['range_looks'] 59 | azlks = templateDict['azimuth_looks'] 60 | 61 | processDir = scratchDir + '/' + projectName + "/PROCESS" 62 | slcDir = scratchDir + '/' + projectName + "/SLC" 63 | rslcDir = scratchDir + '/' + projectName + '/RSLC' 64 | ifgDir = scratchDir + '/' + projectName + '/ifgrams' 65 | 66 | Pair = Mdate + '-' + Sdate 67 | workDir = ifgDir + '/' + Pair 68 | 69 | ################ copy file for parallel processing ############### 70 | Mamp0 = rslcDir + '/' + Mdate + '/' + Mdate + '_' + rlks + 'rlks.amp' 71 | MampPar0 = rslcDir + '/' + Mdate + '/' + Mdate + '_' + rlks + 'rlks.amp.par' 72 | Samp0 = rslcDir + '/' + Sdate + '/' + Sdate + '_' + rlks + 'rlks.amp' 73 | SampPar0 = rslcDir + '/' + Sdate + '/' + Sdate + '_' + rlks + 'rlks.amp.par' 74 | 75 | 76 | Mamp = workDir + '/' + Mdate + '_' + rlks + 'rlks.amp' 77 | MampPar = workDir + '/' + Mdate + '_' + rlks + 'rlks.amp.par' 78 | Samp = workDir + '/' + Sdate + '_' + rlks + 'rlks.amp' 79 | SampPar = workDir + '/' + Sdate + '_' + rlks + 'rlks.amp.par' 80 | 81 | ut.copy_file(Mamp0,Mamp) 82 | ut.copy_file(Samp0,Samp) 83 | ut.copy_file(MampPar0,MampPar) 84 | ut.copy_file(SampPar0,SampPar) 85 | ############################################################### 86 | 87 | nWidth = ut.read_gamma_par(MampPar, 'read', 'range_samples') 88 | nLine = ut.read_gamma_par(MampPar, 'read', 'azimuth_lines') 89 | 90 | CORMASK = workDir + '/' + Pair + '_' +rlks + 'rlks.diff_filt.cor' 91 | WRAPlks = workDir + '/' + Pair + '_' +rlks + 'rlks.diff_filt' 92 | UNWlks = workDir + '/' + Pair + '_' +rlks + 'rlks.diff_filt.unw' 93 | 94 | CORMASKbmp = CORMASK.replace('.diff_filt.cor','.diff_filt.cor_mask.bmp') 95 | 96 | if os.path.isfile(CORMASKbmp): 97 | os.remove(CORMASKbmp) 98 | 99 | call_str = 'rascc_mask ' + CORMASK + ' ' + Mamp + ' ' + nWidth + ' 1 1 0 1 1 ' + templateDict['unwrapThreshold'] + ' 0.0 0.1 0.9 1. .35 1 ' + CORMASKbmp # based on int coherence 100 | os.system(call_str) 101 | 102 | call_str = 'mcf ' + WRAPlks + ' ' + CORMASK + ' ' + CORMASKbmp + ' ' + UNWlks + ' ' + nWidth + ' ' + templateDict['mcf_triangular'] + ' - - - - ' + templateDict['unwrap_patr'] + ' ' + templateDict['unwrap_pataz'] 103 | os.system(call_str) 104 | 105 | call_str = 'rasrmg ' + UNWlks + ' ' + Mamp + ' ' + nWidth + ' - - - - - - - - - - ' 106 | os.system(call_str) 107 | 108 | os.remove(Mamp) 109 | os.remove(Samp) 110 | #os.remove(MampPar) 111 | #os.remove(SampPar) 112 | print("Uwrapping interferometric phase is done!") 113 | sys.exit(1) 114 | 115 | if __name__ == '__main__': 116 | main(sys.argv[:]) 117 | -------------------------------------------------------------------------------- /pyint/unwrap_gamma_all.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ################################################################# 3 | ### This program is part of PyINT v2.1 ### 4 | ### Copy Right (c): 2017-2019, Yunmeng Cao ### 5 | ### Author: Yunmeng Cao ### 6 | ### Contact : ymcmrs@gmail.com ### 7 | ################################################################# 8 | 9 | import numpy as np 10 | import os 11 | import sys 12 | import getopt 13 | import time 14 | import glob 15 | import argparse 16 | 17 | import subprocess 18 | from pyint import _utils as ut 19 | 20 | 21 | def work(data0): 22 | cmd = data0[0] 23 | err_file = data0[1] 24 | p = subprocess.run(cmd, shell=False,stderr=subprocess.PIPE, stdout=subprocess.PIPE) 25 | stdout = p.stdout 26 | stderr = p.stderr 27 | 28 | if type(stderr) == bytes: 29 | aa=stderr.decode("utf-8") 30 | else: 31 | aa = stderr 32 | 33 | if aa: 34 | str0 = cmd[0] + ' ' + cmd[1] + ' ' + cmd[2] + ' ' + cmd[3] + '\n' 35 | #print(aa) 36 | with open(err_file, 'a') as f: 37 | f.write(str0) 38 | f.write(aa) 39 | f.write('\n') 40 | 41 | return 42 | ######################################################################### 43 | 44 | INTRODUCTION = ''' 45 | ------------------------------------------------------------------- 46 | Unwrap differential interferograms for one project using GAMMA. 47 | 48 | ''' 49 | 50 | EXAMPLE = ''' 51 | Usage: 52 | unwrap_gamma_all.py projectName 53 | unwrap_gamma_all.py projectName --parallel 4 54 | unwrap_gamma_all.py projectName --parallel 4 --ifgramList-txt /test/ifgram_list.txt 55 | ------------------------------------------------------------------- 56 | ''' 57 | 58 | 59 | def cmdLineParse(): 60 | parser = argparse.ArgumentParser(description='Unwrap differential interferograms for one project using GAMMA.',\ 61 | formatter_class=argparse.RawTextHelpFormatter,\ 62 | epilog=INTRODUCTION+'\n'+EXAMPLE) 63 | 64 | parser.add_argument('projectName',help='projectName for processing.') 65 | parser.add_argument('--parallel', dest='parallelNumb', type=int, default=1, help='Enable parallel processing and Specify the number of processors.') 66 | parser.add_argument('--ifgarmList-txt', dest='ifgarmListTxt', help='provided ifgram_list_txt. default: using ifgram_list.txt under projectName folder.') 67 | 68 | inps = parser.parse_args() 69 | return inps 70 | 71 | 72 | def main(argv): 73 | start_time = time.time() 74 | inps = cmdLineParse() 75 | projectName = inps.projectName 76 | scratchDir = os.getenv('SCRATCHDIR') 77 | templateDir = os.getenv('TEMPLATEDIR') 78 | templateFile = templateDir + "/" + projectName + ".template" 79 | projectDir = scratchDir + '/' + projectName 80 | ifgDir = scratchDir + '/' + projectName + '/ifgrams' 81 | templateDict=ut.update_template(templateFile) 82 | rlks = templateDict['range_looks'] 83 | azlks = templateDict['azimuth_looks'] 84 | 85 | if inps.ifgarmListTxt: ifgramList_txt = inps.ifgarmListTxt 86 | else: ifgramList_txt = scratchDir + '/' + projectName + '/ifgram_list.txt' 87 | ifgList0 = ut.read_txt2array(ifgramList_txt) 88 | ifgList = ifgList0[:,0] 89 | 90 | err_txt = scratchDir + '/' + projectName + '/unwrap_gamma_all.err' 91 | if os.path.isfile(err_txt): os.remove(err_txt) 92 | 93 | data_para = [] 94 | for i in range(len(ifgList)): 95 | m0 = ut.yyyymmdd(ifgList[i].split('-')[0]) 96 | s0 = ut.yyyymmdd(ifgList[i].split('-')[1]) 97 | cmd0 = ['unwrap_gamma.py',projectName, m0, s0] 98 | unw_file0 = ifgDir + '/' + ifgList[i] + '/' + ifgList[i] + '_' + rlks + 'rlks.diff_filt.unw.bmp' 99 | data0 = [cmd0,err_txt] 100 | 101 | k00 = 0 102 | if os.path.isfile(unw_file0): 103 | if os.path.getsize(unw_file0) > 0: 104 | k00 = 1 105 | if k00==0: 106 | data_para.append(data0) 107 | 108 | ut.parallel_process(data_para, work, n_jobs=inps.parallelNumb, use_kwargs=False) 109 | print("Unwrap differential interferograms for project %s is done! " % projectName) 110 | ut.print_process_time(start_time, time.time()) 111 | 112 | sys.exit(1) 113 | 114 | if __name__ == '__main__': 115 | main(sys.argv[:]) 116 | --------------------------------------------------------------------------------