├── .gitignore ├── ALOS ├── README.md ├── baselines.png ├── baselines_estimate.png ├── baselines_prf.txt ├── do_make_raw_alos.py ├── estimate_alos_baselines.py ├── example_p98_f6730.csv ├── get_roi_baselines.py └── plot_alos_baselines.py ├── DEM ├── README.md ├── byte-swap.c ├── dem2envi.py └── get_SRTM3.pl ├── README.md └── TSX ├── README.md ├── get_height.pl ├── plot_baselines_prf.py ├── prepare_tsx.py └── sar-0.5.tar.gz /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | bin 14 | var 15 | sdist 16 | develop-eggs 17 | .installed.cfg 18 | lib 19 | lib64 20 | __pycache__ 21 | 22 | # Installer logs 23 | pip-log.txt 24 | 25 | # Unit test / coverage reports 26 | .coverage 27 | .tox 28 | nosetests.xml 29 | 30 | # Translations 31 | *.mo 32 | 33 | # Mr Developer 34 | .mr.developer.cfg 35 | .project 36 | .pydevproject 37 | -------------------------------------------------------------------------------- /ALOS/README.md: -------------------------------------------------------------------------------- 1 | ALOS Scripts 2 | ============= 3 | 4 | The following Python scripts are helpful if you're processing ALOS data with [ROI_PAC](www.roipac.org). Followed in sequence, they do the following: 5 | 6 | 1. Estimate baselines for achived frames 7 | 2. Set up directory structure with downloaded frames for ROI_PAC processing 8 | 3. Calculate more accurate baselines with ROI_PAC 9 | 10 | #In more detail: 11 | 12 | ##estimate_alos_baselines.py 13 | Search for available data at the Japanese Space Agency 'ALOS User Interface Gateway' [AUIG](https://auig.eoc.jaxa.jp/auigs/). Login as '*Guest*' in upper left panel, then click on `Order and Obs. Requests`. In the map search interface be sure to select the following: 14 | 15 | * SearchType = Archives 16 | * Sensor = PALSAR 17 | * Ope. Mode = FBS, FBD 18 | 19 | After search completes, select all the scenes from *a single path*, click the `Option` button in the bottom right, and then `CSV`. This will export a spreadsheet file that is read by the script. 20 | 21 | ``` 22 | estimate_alos_baselines.py search.csv 23 | ``` 24 | 25 | The script outputs the file *baselines.txt*, and generates a plot of estimated baselines with dates colored by FBD or FBS acquisition style: 26 | 27 | ![baseline_plot](baselines_estimate.png) 28 | 29 | **Note that estimated baselines are generally within 200m of ROI_PAC calculation** 30 | 31 | 32 | ##do_make_raw_alos.py 33 | Assuming you've selected the scenes you want and downloaded them from the [Alaska Satellite Facility Archives](https://ursa.asfdaac.alaska.edu). You're now ready to generate 'raw' files in the directory structure required by ROI_PAC. With ALOS, you need to keep track of FBS or FBD acquisitions... This script does all that. Just run it in the directory with all zip files (e.g. /data/alos/p420): 34 | 35 | ``` 36 | do_make_raw_alos.py 37 | ``` 38 | 39 | 40 | ##get_roi_baselines.py 41 | With raw files generate in each date folder, you can now run this to output a file called *dolist.in* that has perpendicular baselines compared to a master date (typically the earliest one). The script simply calls the ROI_PAC command `process_2pass.pl [pair] raw orbbase` for each date pair: 42 | 43 | ``` 44 | get_roi_baselines.py 070721 45 | ``` 46 | 47 | 48 | ##plot_alos_baselines.py 49 | You're now ready to start [making interferograms with ROI_PAC](http://www.geo.cornell.edu/eas/PeoplePlaces/Faculty/matt/flowchart.html). First, though, it's helpful to generate another baseline plot with the perpendicular baseline values actually calculated by ROI_PAC. This plot will have the additional information of the Pulse Repition Frequency (PRF) for each date. Here is an example with the estimated values also included so you can see the general agreement: 50 | 51 | ![baseline_plot](baselines.png) 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /ALOS/baselines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyhq/insar_scripts/b4a1d1aef41649408ca01c21382817506d92f70d/ALOS/baselines.png -------------------------------------------------------------------------------- /ALOS/baselines_estimate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyhq/insar_scripts/b4a1d1aef41649408ca01c21382817506d92f70d/ALOS/baselines_estimate.png -------------------------------------------------------------------------------- /ALOS/baselines_prf.txt: -------------------------------------------------------------------------------- 1 | 111019 0 4955.1822601 2 | 131116 59.7008177282794 4448.11024126 3 | 140110 22.7939942118882 4408.14005937 4 | 140430 147.689111371907 4408.14005937 5 | -------------------------------------------------------------------------------- /ALOS/do_make_raw_alos.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Generate raw format for a bunch of zipped frame data downloaded from ASF 4 | Should work for single frames of concatenated frames 5 | 6 | Does the following steps (see end of file to comment out individual steps) 7 | 1) Unzips everything 8 | 2) makes date folders 9 | 3) calls make_raw_alos.pl 10 | 4) removes raw data files and puts zip files in folder 11 | 12 | Author: Scott Henderson 13 | """ 14 | 15 | import os 16 | import subprocess 17 | import shlex 18 | import shutil 19 | import glob 20 | 21 | def unzip(): 22 | print 'Unzipping all data...\n' 23 | zipfiles = glob.glob('*.zip') 24 | for z in zipfiles: 25 | if not os.path.isdir(z[:-4]): 26 | os.system('unzip {0}'.format(z)) 27 | else: 28 | print '{0} alread unzipped... skipping'.format(z) 29 | 30 | 31 | def make_date_folders(): 32 | print '\nMaking date folders...\n' 33 | zipfiles = glob.glob('*.zip') 34 | folders = [ x[:-4] for x in zipfiles] 35 | dates = [] 36 | for f in folders: 37 | with open(f + '/workreport','r') as wr: 38 | lines = wr.readlines() 39 | 40 | # get date 41 | time = [x for x in lines if x.startswith('Img_SceneCenter')] 42 | date = time[0].split('"')[1][2:8] 43 | 44 | # make date folder if it doesn't exist 45 | if not os.path.isdir(date): 46 | os.mkdir(date) 47 | dates.append(date) 48 | 49 | # move important files to date folder 50 | os.system('mv {0}/IMG* {0}/LED* {1}'.format(f,date)) 51 | 52 | #write list of dates to files 53 | with open('dates.txt','w') as f: 54 | dates.sort() 55 | f.write('\n'.join(dates)) 56 | 57 | 58 | def make_raw(): 59 | print '\nRunning make_raw_alos.pl...\n' 60 | with open('dates.txt','r') as f: 61 | dates = f.readlines() 62 | dates = [x.strip() for x in dates] #strip newline characters 63 | 64 | for date in dates: 65 | print date 66 | os.chdir(date) 67 | # Check for HV 68 | if len([x for x in os.listdir('.') if x.startswith('IMG-HV')]) > 0: 69 | fbd2fbs = 'FBD2FBS' 70 | # make a directory to store extra HV files 71 | print 'moving IMG-HV files to HVfiles directory' 72 | os.mkdir('HVfiles') 73 | os.system('mv *HV* HVfiles') 74 | else: 75 | fbd2fbs = 'NO' 76 | 77 | cmd = 'make_raw_alos.pl IMG {0} {1} &> make_raw_alos.out'.format(date, fbd2fbs) 78 | print cmd 79 | with open('make_raw_alos.out','w') as out: 80 | subprocess.call(shlex.split(cmd), stdout=out) 81 | 82 | os.chdir('../') 83 | 84 | 85 | def clean_up(): 86 | print '\n Removing tmp files and stashing raw_data...\n' 87 | os.mkdir('raw_data') 88 | os.system('mv ALPS* raw_data') 89 | 90 | with open('dates.txt','r') as f: 91 | dates = f.readlines() 92 | dates = [x.strip() for x in dates] #strip newline characters 93 | 94 | for date in dates: 95 | print date 96 | os.chdir(date) 97 | 98 | os.system('rm {0}-* IMG*PRM IMG*raw'.format(date)) 99 | os.mkdir('raw_data') 100 | os.system('mv IMG* LED* raw_data') 101 | 102 | os.chdir('../') 103 | 104 | 105 | if __name__ == '__main__': 106 | # NOTE: comment out commands below if you want to re-run make_raw w/o unzipping 107 | unzip() 108 | make_date_folders() 109 | make_raw() 110 | clean_up() 111 | print 'Done' 112 | -------------------------------------------------------------------------------- /ALOS/estimate_alos_baselines.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Estimate ALOS baselines from JAXA search csv file output 4 | 5 | Based on a Matlab code by Yo Fukushima 6 | 7 | Author: Scott Henderson 8 | """ 9 | import sys 10 | import numpy as np 11 | import pyproj 12 | 13 | import matplotlib.pyplot as plt 14 | import datetime 15 | from matplotlib.dates import MonthLocator, DateFormatter 16 | import matplotlib.mlab as mlab 17 | 18 | 19 | def make_baseline_plot(recarray,title): 20 | ''' More informative version using record array for a particular track''' 21 | fig = plt.figure(figsize=(11,8.5)) 22 | ax = fig.add_subplot(111) 23 | 24 | # sort by beam mode 25 | fbs = (recarray.mode == 'FBS') 26 | fbd = -fbs 27 | 28 | #pltdates = np.array([datetime.datetime.strptime(date,'%Y/%m/%d') for date in recarray.date]) 29 | #mlab.rec_append_fields(recarray,'pltdate',pltdates,object) # append datetime objects as new field 30 | 31 | plt.plot(recarray[fbs].pltdate, recarray[fbs].bperp, 'bo', label='FBS') 32 | plt.plot(recarray[fbd].pltdate, recarray[fbd].bperp, 'rs', label='FBD') 33 | 34 | #plot text shorthand date next to point 35 | for D,B in zip(recarray.pltdate,recarray.bperp): 36 | plt.text(D,B,D.strftime('%y%m%d')) 37 | 38 | plt.title(title) 39 | plt.ylabel('Perpendicular Baseline [m]') 40 | 41 | months = MonthLocator() # every month 42 | ax.xaxis.set_minor_locator(months) 43 | ax.fmt_xdata = DateFormatter('%Y-%m-%d') #lower left coodinate display 44 | fig.autofmt_xdate() 45 | 46 | plt.legend(loc='best', numpoints=1) 47 | plt.grid(True) 48 | plt.show() 49 | plt.savefig('baseline.ps') 50 | 51 | 52 | 53 | def add_timespan(recarray): 54 | ''' input: array of dates as strings 55 | output: datetime list, dt relative to first date [days]''' 56 | pltdates = np.array([datetime.datetime.strptime(date,'%Y/%m/%d') for date in recarray.date]) 57 | 58 | dt = np.cumsum(np.diff(pltdates)) #could do array of total seconds or decimal years 59 | dt = np.insert(dt,0,datetime.timedelta(0)) 60 | 61 | roidates = np.array([D.strftime('%y%m%d') for D in pltdates]) 62 | 63 | recarray = mlab.rec_append_fields(recarray,'dt',dt,object) 64 | recarray = mlab.rec_append_fields(recarray,'pltdate',pltdates,object) # append datetime objects as new field 65 | recarray = mlab.rec_append_fields(recarray,'roidate',roidates, roidates.dtype) 66 | #print "appended 'dt' and 'pltdate' fields" 67 | return recarray 68 | 69 | 70 | def ecef2enu(pos, ref): 71 | """ 72 | http://en.wikipedia.org/wiki/Geodetic_datum#Geodetic_versus_geocentric_latitude 73 | """ 74 | xm,ym,zm = ref.flat #extracts elements of column or row vector 75 | # duplicate reference vector rows into matrix 76 | ref = np.vstack((ref,)*pos.shape[0]) 77 | 78 | # get geodetic lat/lon/height (above wgs84) of satellite 79 | ecef = pyproj.Proj(proj='geocent', ellps='WGS84', datum='WGS84') 80 | wgs84 = pyproj.Proj(proj='latlong', ellps='WGS84', datum='WGS84') 81 | lon, lat, h = pyproj.transform(ecef, wgs84, xm, ym, zm, radians=True) 82 | 83 | # make transformation matrix 84 | transform = np.array([ 85 | [-np.sin(lon), np.cos(lon), 0.0], 86 | [-np.sin(lat)*np.cos(lon), -np.sin(lat)*np.sin(lon), np.cos(lat)], 87 | [np.cos(lat)*np.cos(lon), np.cos(lat)*np.sin(lon), np.sin(lat)] 88 | ]) 89 | 90 | # do matrix multiplication 91 | enu = np.dot(transform, pos.T - ref.T) 92 | 93 | return enu 94 | 95 | 96 | 97 | def add_bperp(recarray): 98 | ''' input: position vector [m], velocity vector [m], offnadir angle [deg] 99 | output: perpendicular baseline [m] ''' 100 | pos = np.vstack((recarray.x, recarray.y, recarray.z)).T * 1000 101 | vel = np.vstack((recarray.dx, recarray.dy, recarray.dz)).T * 1000 102 | 103 | x,y,z = np.hsplit(pos,3) #if pos.shape = (7,3) 104 | #dx,dy,dz = np.hsplit(vel,3) 105 | #x,y,z = pos[0],pos[1],pos[2] #pos is (3,7) 106 | offnadir = np.radians(recarray.offnadir) 107 | 108 | # Get mean parameters of satellite ((1,n) row vector) 109 | pos0 = np.mean(pos,0).reshape(1,-1) #average position of all acquisitions 110 | xm,ym,zm = pos0.flat 111 | vel0 = np.mean(vel,0).reshape(1,-1) 112 | 113 | # get geodetic lat/lon/height (above wgs84) of satellite 114 | ecef = pyproj.Proj(proj='geocent', ellps='WGS84', datum='WGS84') 115 | wgs84 = pyproj.Proj(proj='latlong', ellps='WGS84', datum='WGS84') 116 | lon, lat, h = pyproj.transform(ecef, wgs84, x, y, z, radians=True) 117 | h_ave = np.mean(h) 118 | 119 | # Convert geocentric coordinates to average ENU in plane of satellite 120 | xl,yl,zl = ecef2enu(pos, pos0) 121 | 122 | # Calculate travel direction in ENU coordinates from differencing unit velocity motion 123 | # NOTE: not sure why this works..., need to *1000 to keep consistent w/ matlab code, but units don't exactly match 124 | pos1 = pos0 + vel0/np.linalg.norm(vel0)*1000 125 | pos2 = pos0 - vel0/np.linalg.norm(vel0)*1000 126 | p1,p2,p3 = ecef2enu(pos1, pos0) 127 | q1,q2,q3 = ecef2enu(pos2, pos0) 128 | vxl = q1 - p1 129 | vyl = q2 - p2 130 | vzl = q3 - p3 131 | 132 | # Along-track direction 133 | trackdir = np.arctan(vxl/vyl) 134 | 135 | # Calculate perpendicular baseline 136 | Bx = xl-xl[0] 137 | By = yl-yl[0] 138 | zr = h.flat-h_ave 139 | Br = zr-zr[0] 140 | #Bv = zl-zl[0] 141 | Bh = Bx*np.cos(trackdir) - By*np.sin(trackdir) 142 | 143 | Bperp = Bh*np.cos(offnadir) + Br*np.sin(offnadir) 144 | Bpara = Bh*np.sin(offnadir) - Br*np.cos(offnadir) 145 | 146 | # Match ROI_PAC Baseline sign convention for ascending data 147 | if trackdir < 0: 148 | Bperp = -Bperp 149 | 150 | recarray = mlab.rec_append_fields(recarray,'bperp',Bperp,float) 151 | #print "appended 'bperp' field" 152 | return recarray 153 | 154 | 155 | def write_baseline_file(recarray, track): 156 | ''' write a simple ascii file with date and baseline columns ''' 157 | subset = mlab.rec_keep_fields(recarray, ['roidate','bperp']) 158 | mlab.rec2csv(subset,'baselines.txt'.format(track), withheader=False, delimiter=' ') 159 | #NOTE: this is like dolist.in for batch processing 160 | 161 | def main(csvfile): 162 | ''' call other functions to produce baseline plots ''' 163 | # see also csv2rec() & rec2csv 164 | #os.chdir('/home/scott/data/insar/alos') 165 | alldata = np.genfromtxt(csvfile, 166 | skip_header=1, 167 | delimiter=',', 168 | comments='#', 169 | usecols=(2,3,4,5,9,24,25,26,27,28,29), 170 | names=('mode','date','track','frame','offnadir','x','y','z','dx','dy','dz'), 171 | dtype=('|S4','|S10','i4','i4') + ('f4',)*7, 172 | ) 173 | 174 | for track in np.unique(alldata['track']): 175 | ind = (alldata['track'] == track) 176 | data = alldata[ind] 177 | 178 | # If multiple frames in csv file, just plot first frame... could instead loop over them 179 | first_frame = data['frame'][0] 180 | ind = (data['frame'] == first_frame) 181 | data = data[ind] 182 | recarray = np.array(data.copy()).view(np.recarray) #allows attribute access recarray.date 183 | recarray = add_bperp(recarray) 184 | recarray = add_timespan(recarray) 185 | 186 | title = 'path={0}, frame={1}'.format(track, first_frame) 187 | make_baseline_plot(recarray, title) 188 | write_baseline_file(recarray, track) 189 | 190 | 191 | if __name__ == '__main__': 192 | csvfile = sys.argv[1] 193 | main(csvfile) 194 | -------------------------------------------------------------------------------- /ALOS/example_p98_f6730.csv: -------------------------------------------------------------------------------- 1 | SENSOR,SCNID,OPEMD,SCN_CDATE,PATHNO,CENFLMNO,REC_CLDSCENE,UCUT,PNTANG,OFFNADIR,REC_ALLQLTY,DLSEGNO,OBTDIR,GSCD,PROOFFLG,ORBITSTAT,FCUT,RCUT,POINTFLG,L0STATUS,TBLNO,SCN_CTIME,SCN_CLAT,SCN_CLON,SCN_POSX,SCN_POSY,SCN_POSZ,SCN_SPDX,SCN_SPDY,SCN_SPDZ,STEERING 2 | PALSAR,ALPSRP059086730,FBS,2007/03/05,98,6730,-,-,-,34.3,-,W0406236001-06,A,HEOC,exclude,Precision,-,-,-,OK,7,03:31:30.093,-22.358,-67.193,2024.819133,-6181.057440,-2793.707909,-0.645335,-3.284152,6.812652,Yes 3 | PALSAR,ALPSRP085926730,FBD,2007/09/05,98,6730,-,-,-,34.3,-,W0590190001-08,A,HEOC,exclude,Precision,-,-,-,OK,43,03:31:17.452,-22.365,-67.195,2024.478833,-6180.926483,-2794.305325,-0.643574,-3.284059,6.812676,Yes 4 | PALSAR,ALPSRP092636730,FBD,2007/10/21,98,6730,-,-,-,34.3,-,W0636190001-05,A,HEOC,exclude,Precision,-,-,-,OK,43,03:31:01.937,-22.365,-67.199,2024.061811,-6180.856345,-2794.204602,-0.643051,-3.284152,6.812828,Yes 5 | PALSAR,ALPSRP106056730,FBS,2008/01/21,98,6730,-,-,-,34.3,-,W0728144001-01,A,TKSC,exclude,Precision,-,-,-,OK,7,03:30:12.793,-22.370,-67.202,2023.656788,-6180.835001,-2794.633945,-0.641800,-3.284070,6.812765,Yes 6 | PALSAR,ALPSRP119476730,FBS,2008/04/22,98,6730,-,-,-,34.3,-,W0820190001-05,A,HEOC,exclude,Precision,-,-,-,OK,7,03:28:49.900,-22.369,-67.207,2023.213932,-6181.221630,-2794.449220,-0.640110,-3.283092,6.813082,Yes 7 | PALSAR,ALPSRP139606730,FBD,2008/09/07,98,6730,-,-,-,34.3,-,W0958190001-07,A,HEOC,exclude,Precision,-,-,-,OK,43,03:28:56.429,-22.355,-67.179,2026.422462,-6180.440011,-2793.683933,-0.649842,-3.285692,6.811904,Yes 8 | PALSAR,ALPSRP146316730,FBD,2008/10/23,98,6730,-,-,-,34.3,-,W1004144001-02,A,HEOC,exclude,Precision,-,-,-,OK,43,03:29:49.186,-22.358,-67.178,2026.552175,-6180.415415,-2794.025415,-0.649079,-3.285936,6.811706,Yes 9 | PALSAR,ALPSRP166446730,FBS,2009/03/10,98,6730,-,-,-,34.3,-,W1142190001-06,A,HEOC,exclude,Precision,-,-,-,OK,7,03:31:49.929,-22.361,-67.186,2025.607565,-6180.657046,-2794.095507,-0.646993,-3.285187,6.812094,Yes 10 | PALSAR,ALPSRP193286730,FBD,2009/09/10,98,6730,-,-,-,34.3,-,W1326190001-05,A,HEOC,exclude,Precision,-,-,-,OK,43,03:33:04.847,-22.361,-67.193,2024.892093,-6180.775805,-2793.890649,-0.645554,-3.284540,6.812595,Yes 11 | PALSAR,ALPSRP199996730,FBD,2009/10/26,98,6730,-,-,-,34.3,-,W1372144001-02,A,HEOC,exclude,Precision,-,-,-,OK,43,03:33:10.752,-22.361,-67.195,2024.662583,-6181.059720,-2793.928404,-0.645117,-3.284320,6.812487,Yes 12 | PALSAR,ALPSRP220126730,FBS,2010/03/13,98,6730,-,-,-,34.3,-,A1510098001-01,A,TDRS,exclude,Precision,-,-,-,OK,7,03:32:49.134,-22.365,-67.200,2024.150439,-6181.019705,-2794.157637,-0.642777,-3.283827,6.812754,Yes 13 | PALSAR,ALPSRP226836730,FBS,2010/04/28,98,6730,-,-,-,34.3,-,A1556098001-01,A,TDRS,exclude,Precision,-,-,-,OK,7,03:32:26.452,-22.380,-67.200,2023.703815,-6180.418896,-2795.923828,-0.641802,-3.285334,6.811960,Yes 14 | PALSAR,ALPSRP233546730,FBD,2010/06/13,98,6730,-,-,-,34.3,-,A1602098002-01,A,TDRS,exclude,Precision,-,-,-,OK,43,03:32:00.088,-22.368,-67.205,2023.473375,-6181.143345,-2794.475067,-0.642312,-3.283752,6.812779,Yes 15 | PALSAR,ALPSRP240256730,FBD,2010/07/29,98,6730,-,-,-,34.3,-,A1648098003-01,A,TDRS,exclude,Precision,-,-,-,OK,43,03:31:30.585,-22.365,-67.205,2023.601776,-6181.173324,-2794.155478,-0.641974,-3.283460,6.813083,Yes 16 | PALSAR,ALPSRP253676730,FBD,2010/10/29,98,6730,-,-,-,34.3,-,A1740098002-01,A,TDRS,exclude,Precision,-,-,-,OK,43,03:30:14.827,-22.370,-67.209,2023.004265,-6181.178659,-2794.517939,-0.640776,-3.283477,6.812946,Yes 17 | PALSAR,ALPSRP267096730,FBS,2011/01/29,98,6730,-,-,-,34.3,-,A1832098004-01,A,TDRS,exclude,Precision,-,-,-,OK,7,03:28:33.665,-22.370,-67.214,2022.551643,-6181.346549,-2794.386406,-0.639559,-3.282929,6.813215,Yes 18 | PALSAR,ALPSRP273806730,FBS,2011/03/16,98,6730,-,-,-,34.3,-,A1878098002-01,A,TDRS,exclude,Precision,-,-,-,OK,7,03:27:29.348,-22.387,-67.210,2022.649645,-6180.469952,-2796.294436,-0.637790,-3.284664,6.812628,Yes 19 | -------------------------------------------------------------------------------- /ALOS/get_roi_baselines.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | ''' 3 | Call ROI_PAC process_2pass.pl from raw to orbbase for combinations with master date 4 | 5 | NOTE: calls process_2pass.pl *.proc roi_prep orbbase 6 | which overwrites early processing files if it's already been done! 7 | 8 | probably could write PRF to this file too! 9 | 10 | Author: Scott Henderson 11 | ''' 12 | import sys 13 | import os 14 | import glob 15 | from numpy import genfromtxt 16 | 17 | masterdate = sys.argv[1] 18 | 19 | # Write .proc files with master date 20 | dates = genfromtxt('dates.txt',dtype=str).tolist() 21 | dates.remove(masterdate) 22 | for d in dates: 23 | procname = 'int_{0}_{1}.proc'.format(d,masterdate) 24 | with open(procname, 'w') as f: 25 | f.write('''SarDir1={0} 26 | SarDir2={1} 27 | IntDir=int_{0}_{1} 28 | SimDir=int_{0}_{1}/SIM 29 | GeoDir=int_{0}_{1}/GEO 30 | flattening = topo 31 | 32 | BaselineOrder = QUAD 33 | 34 | DEM=/home/mpguest/final.dem 35 | OrbitType=HDR 36 | Rlooks_sim=4 37 | Rlooks_geo=4 38 | Rlooks_int=4 39 | Rlooks_unw=16 40 | pixel_ratio=2 41 | 42 | concurrent_roi=yes 43 | '''.format(d,masterdate)) 44 | 45 | # Run ROI_PAC to orbbase 46 | inputs = glob.glob('*{}.proc'.format(masterdate)) 47 | for proc in inputs: 48 | cmd = 'process_2pass.pl {} raw orbbase'.format(proc) 49 | print cmd 50 | os.system(cmd) 51 | 52 | # Extract baseline values from rscs and write to dolist.in file 53 | cmd = "grep P_BASELINE_TOP int*{0}/*baseline.rsc | mawk '{{print substr($1,5,6)\" \"$2}}' > dolist.in".format(masterdate) 54 | print cmd 55 | os.system(cmd) 56 | 57 | #add master date to dolist.in 58 | with open('dolist.in','r') as f: 59 | lines = f.readlines() 60 | 61 | lines.insert(0, '{} 0\n'.format(masterdate)) 62 | 63 | with open('dolist.in','w') as f: 64 | f.writelines(lines) 65 | 66 | # Remove ROI_PAC output 67 | cmd = 'rm -r int* log*' 68 | print 'to remove files:\n',cmd 69 | #os.system('rm -r int* log*') 70 | 71 | print 'Wrote dolist.in file' 72 | -------------------------------------------------------------------------------- /ALOS/plot_alos_baselines.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Baseline plot for directory of ALOS data, with dates colored by PRF 4 | 5 | Author: Scott Henderson 6 | """ 7 | import sys 8 | import os 9 | import numpy as np 10 | import matplotlib.pyplot as plt 11 | import datetime 12 | from matplotlib.dates import MonthLocator, DateFormatter 13 | import matplotlib.mlab as mlab 14 | 15 | def load_rsc(path): 16 | """ 17 | Read metadata from .rsc file into python dictionary 18 | """ 19 | metadata = {} 20 | rsc = open(path + '.rsc', 'r') 21 | # Remove blank lines, retaining only lines with key, value pairs 22 | allLines = [line for line in rsc.readlines() if line.strip()] 23 | for line in allLines: 24 | items = line.split() 25 | var = items[0] 26 | value = '_'.join(items[1:]) #replace space w/underscore 27 | metadata[var] = value 28 | rsc.close() 29 | return metadata 30 | 31 | 32 | def get_PRF(dates): 33 | prfs = np.zeros(dates.size) 34 | for i,date in enumerate(dates): 35 | rsc = load_rsc('{0}/{0}.raw'.format(date)) 36 | prfs[i] = float(rsc['PRF']) 37 | 38 | #print prfs 39 | return prfs 40 | 41 | 42 | def make_baseline_plot(baseline_file): 43 | ''' More informative version using record array for a particular track''' 44 | fig = plt.figure(figsize=(11,8.5)) 45 | ax = fig.add_subplot(111) 46 | 47 | # Load date and baseline data from file 48 | #dates, bperps = np.loadtxt(baseline_file,unpack=True) 49 | dates, bperps = np.genfromtxt(baseline_file,unpack=True,comments='#',dtype=str) #easiest way to get columns of text, then convert after 50 | bperps = bperps.astype('f4') 51 | #print dates 52 | 53 | pltdates = np.array([datetime.datetime.strptime(date,'%y%m%d') for date in dates]) 54 | #dt = np.cumsum(np.diff(pltdates)) #could do array of total seconds or decimal years 55 | #dt = np.insert(dt,0,datetime.timedelta(0)) 56 | #print pltdates 57 | prfs = get_PRF(dates) 58 | 59 | #plt.plot(pltdates,bperps,'ro',label='estimation') 60 | #NOTE: pltdates not woriking with scatter plot for some reason?! 61 | #print pltdates,bperps,prfs 62 | unique_prfs = np.unique(prfs) 63 | cmap = plt.get_cmap('jet', unique_prfs.size) #discrete colors! 64 | sc = plt.scatter(pltdates,bperps,s=80,c=prfs,cmap=cmap) 65 | cb = plt.colorbar(sc,ticks=unique_prfs,format='%.2f') 66 | cb.set_label('PRF [Hz]') #automatically sets long axis label 67 | #cb.ax.set_xlabel('PRF [Hz]',labelpad=30) #label on top of colorbar? 68 | 69 | #plot text shorthand date next to point 70 | for D,B in zip(pltdates, bperps): 71 | plt.text(D,B,D.strftime('%y%m%d')) 72 | 73 | # add baselines estimated by python script 74 | #estimate_file = 'baselines.txt' 75 | #estimate_file = 'baselines_bottom.txt' 76 | #dates, bperps = np.genfromtxt(estimate_file,unpack=True,comments='#',dtype=str) 77 | #pltdates = np.array([datetime.datetime.strptime(date,'%y%m%d') for date in dates]) 78 | #plt.plot(pltdates,bperps,'ko',label='estimate') 79 | 80 | plt.title(os.getcwd()) 81 | plt.ylabel('B_Perp [m]') 82 | 83 | months = MonthLocator() # every month 84 | ax.xaxis.set_minor_locator(months) 85 | ax.fmt_xdata = DateFormatter('%Y-%m-%d') #lower left coodinate display 86 | fig.autofmt_xdate() 87 | 88 | plt.legend(loc='upper left', numpoints=1) #note: legend='best' doesn;t always work 89 | plt.grid(True) 90 | plt.savefig('baseline.ps') 91 | plt.show() 92 | 93 | 94 | if __name__ == '__main__': 95 | basefile = sys.argv[1] 96 | make_baseline_plot(basefile) 97 | -------------------------------------------------------------------------------- /DEM/README.md: -------------------------------------------------------------------------------- 1 | # Digital Elevation Model Stuff 2 | 3 | This folder contains scripts that are useful for obtaining and working with DEMS 4 | 5 | I posted some notes one working with the scripts [here](https://scottyhq.github.io/blog/2014/04/29/get-roipac-dem/) 6 | -------------------------------------------------------------------------------- /DEM/byte-swap.c: -------------------------------------------------------------------------------- 1 | 2 | /* compile cc -o byte-swap byte-swap.c 3 | * written by: Brian Savage 4 | * savage13@gps.caltech.edu 5 | * March 25, 2003 6 | * 7 | * byte-swap will byte swap a flat binary file 8 | * of any length and any number length 9 | * 10 | * */ 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /* 17 | * void swap(char *p, int len) 18 | * 19 | * *p is a pointer to an memory space 20 | * and points to the first byte of our "thing" 21 | * len is the length of our "thing" we want to swap 22 | * 23 | * our number is represented by [0][1][2][3]... 24 | * Where each [#] represents a byte 25 | * 26 | * For 4 bytes 27 | * byte swapping means taking 28 | * [0][1][2][3] and turning it into 29 | * [3][2][1][0] 30 | * 31 | * 2 bytes 32 | * [0][1] => [1][0] 33 | * 34 | * */ 35 | 36 | void 37 | swap(char *p, int len) { 38 | int i; 39 | char tmp; 40 | for(i = 0; i < len/2; i++) { 41 | tmp = p[len-i-1]; 42 | p[len-i-1] = p[i]; 43 | p[i] = tmp; 44 | } 45 | } 46 | 47 | int 48 | main(int argc, char *argv[]) { 49 | void *in; 50 | int len; 51 | 52 | if(argc < 2) { 53 | fprintf(stderr, "usage %s [size in bytes] < in > out\n", argv[0]); 54 | exit(-1); 55 | } 56 | 57 | fprintf(stderr, "Reading from stdin and writing swapped output to stdout\n"); 58 | len = atoi(argv[1]); 59 | in = (void *) malloc(len); 60 | /* Read in the data */ 61 | while(fread(in, len, 1, stdin) == 1) { 62 | /* Byte swap the data */ 63 | swap((char*)in,len); 64 | /* Rewrite back into the file */ 65 | fwrite(in, len, 1, stdout); 66 | } 67 | free(in); 68 | return(0); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /DEM/dem2envi.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Quickly convert dem to envi format for using gdal tools 4 | 5 | Usage: dem2envi.py file 6 | 7 | """ 8 | import sys 9 | 10 | def load_rsc(path): 11 | """ 12 | Read metadata from .rsc file into python dictionary 13 | """ 14 | metadata = {} 15 | rsc = open(path + '.rsc', 'r') 16 | # Remove blank lines, retaining only lines with key, value pairs 17 | allLines = [line for line in rsc.readlines() if line.strip()] 18 | for line in allLines: 19 | items = line.split() 20 | var = items[0] 21 | value = '_'.join(items[1:]) #replace space w/underscore 22 | metadata[var] = value 23 | rsc.close() 24 | return metadata 25 | 26 | def write_envi_header(path,rsc): 27 | """ 28 | write envi header format to use ROI_PAC dem with gdal 29 | """ 30 | # need to strip negative in rsc 31 | rsc['Y_STEP'] = rsc['Y_STEP'].strip('-') 32 | 33 | with open(path + '.hdr', "w") as f: #NOTE: automatically closes file 34 | f.write("""ENVI 35 | description = {0} 36 | samples = {WIDTH} 37 | lines = {FILE_LENGTH} 38 | bands = 1 39 | file type = ENVI Standard 40 | data type = 2 41 | interleave = bsq 42 | byte order = 0 43 | map info = {{Geographic Lat/Lon, 1.0000, 1.0000, {X_FIRST}, {Y_FIRST}, {X_STEP}, {Y_STEP}, WGS-84, units=Degrees}} 44 | """.format(path,**rsc)) 45 | 46 | 47 | 48 | if __name__ == '__main__': 49 | path = sys.argv[1] 50 | rsc = load_rsc(path) 51 | write_envi_header(path,rsc) 52 | print 'Done. to convert to geotif run:\ngdal_translate {0}.dem {0}.tif'.format(path[:-4]) 53 | 54 | 55 | -------------------------------------------------------------------------------- /DEM/get_SRTM3.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | ### get_SRTM.pl 3 | 4 | # 10/01/2010: Downloaded from ROIPAC wiki 5 | # ftp://www.geo.cornell.edu/pub/rlohman/get_SRTM.pl 6 | # Limitation: Worked only up to 2x2 tiles 7 | # Had accss to only SRTM3 8 | # 10/15/2010: Oh-ig Kwoun, JPL 9 | # Fixed coordinate orientation error 10 | # Fixed debugging statements 11 | # Added option to search for public SRTM1 DEMs over US 12 | # Works for any # of tiles 13 | # Warning: .rsc keyword/value for X_,Y_UNIT, Z_OFFSET, Z_SCALE, PROJECTION 14 | # require confirmation 15 | # 2011/01/26: Sang-Ho Yun, JPL 16 | # Removed redundancy of single row/column at each 17 | # tile boundary in SRTM DEMs (Look for SHY) 18 | # with help provided by Walter Szeliga, JPL 19 | # 2011/11/11: Sven Borgstrom, INGV 20 | # Row 155: from `rm tmp`; to `rm tmp *.hgt *.hgt.zip`; 21 | # to remove all the SRTM tiles after processing; 22 | # Last row: added to remove also the *.dem.rsc.hst file; 23 | # if you need it, just comment (#) or delete the last row. 24 | # 2012/02/19: Rowena Lohman 25 | # added loop that also seeks filenames with *hgt.zip rather than *.hgt.zip 26 | # since SRTM tiles are stored that way for some high-latitude tiles. Commented 27 | # out automatic deletion of all .hgt files since that can be dangerous. 28 | # Note: original version didn't have single pixel redundancy - someone else 29 | # commented it out for some reason. SHY fix has same effect as original 30 | # version, just with a fseek instead of a junk variable for that pixel. 31 | # also switched so that it writes zeros to file for open water tiles. 32 | # Previously would paste copies of other files in that region. 33 | # 2014/01/01: Scott Henderson 34 | # Changed default server to get VOID-filled version 3 SRTM from LPDAAC datapool 35 | # This dataset (SRTM plus) was released 10/20/2013 36 | # 2014/08/20: Joey Durkin 37 | # Added a block that checks if the hgt.zip file already exists in the local directory, 38 | # and if it does then it will use that instead of downloading it from SRTM. 39 | # Useful for creating a mosaic of hgt files north of 60 degrees. 40 | # 41 | $] >= 5.004 or die "Perl version must be >= 5.004 (Currently $]).\n"; 42 | 43 | use Env qw(INT_SCR); 44 | use lib "$INT_SCR"; #### Location of Generic.pm 45 | use POSIX qw(ceil floor); 46 | use Generic; 47 | 48 | $argcnt=$#ARGV + 1; 49 | if ( $argcnt < 7 ) { 50 | print "\n"; 51 | print "Usage: get_SRTM.pl .dem min_lat max_lat min_lon max_lon byteswap source\n"; 52 | print "\t.dem : output DEM filename MUST have <.dem> extension\n"; 53 | print "\tbyteswap: [0] No - if you do not have executable\n"; 54 | print "\t [1] little-endian (Linux)\n"; 55 | print "\tsource: [1] SRTM1 30m, US\n"; 56 | print "\t [3] SRTM3 90m, Global\n"; 57 | print "\n"; 58 | die "# of arguments is WRONG\n"; 59 | } 60 | 61 | $outfile=shift; 62 | $lat1=shift; 63 | $lat2=shift; 64 | $lon1=shift; 65 | $lon2=shift; 66 | #$swap=shift or $swap=0; 67 | $swap=shift; 68 | $source=shift or $source=1; 69 | 70 | if ($source eq 3) { 71 | # @dirs=("Africa","Australia","Eurasia","Islands","North_America","South_America"); 72 | $type='SRTMGL3' 73 | } else { 74 | $type='SRTMUS1' 75 | # @dirs=("Region_01", "Region_02","Region_03","Region_04","Region_05","Region_06","Region_07"); 76 | } 77 | 78 | if ($lon1>180 or $lon2>180) { 79 | print "\n"; 80 | die "Use lons in -180 to 180 mode\n"; 81 | } 82 | 83 | if (($lat1<=0 && $lat2>=0) or ($lon1<=0 && $lon2>=0) or ($lon2<$lon1)) { 84 | print "\n"; 85 | die "Not ready for boxes that cross equator or prime meridians\n"; 86 | } 87 | 88 | $lat1=floor($lat1); 89 | $lat2=ceil($lat2); 90 | $lon1=floor($lon1); 91 | $lon2=ceil($lon2); 92 | 93 | $minlon=$lon1; 94 | $maxlat=$lat2; 95 | 96 | $dlat=$lat2-$lat1; 97 | $dlon=$lon2-$lon1; 98 | 99 | if ($lat1<0) { 100 | $latpre="S"; 101 | } else { 102 | $latpre="N"; 103 | } 104 | if ($lon1<0) { 105 | $lonpre="W"; 106 | } else { 107 | $lonpre="E"; 108 | } 109 | 110 | $byte_size=2; # short integer 111 | 112 | if ($source eq 3) { $n=1200; } # SHY: 1201 -> 1200 113 | if ($source eq 1) { $n=3600; } # SHY: 3601 -> 3600 114 | 115 | $zeros = pack("n[$n]",0); 116 | 117 | print "$dlat by $dlon tiles requested\n"; 118 | open(OUT,">$outfile") or die "Can't open $outfile for writing\n"; 119 | 120 | for ($i=$dlat-1;$i>=0;$i--) 121 | { 122 | $a=abs($lat1+$i); 123 | #print "$dlon\n"; 124 | 125 | for ($j=0;$j<$dlon;$j++) 126 | { 127 | #print "$j\n"; 128 | $b=abs($lon1+$j); 129 | 130 | 131 | # DON'T DOWNLOAD, file exists - Added by JD 132 | $file=sprintf("%s%02d%s%03d.hgt",$latpre,$a,$lonpre,$b); 133 | if (-e $file) 134 | { 135 | print "$file found in local directory, skipping download\n"; 136 | $found[$j]=1; 137 | open $IN[$j], "$file" or die "Can't open $file for reading\n"; 138 | } 139 | 140 | else 141 | { # DOWNLOAD FILE 142 | $file=sprintf("%s%02d%s%03d.%s.hgt.zip",$latpre,$a,$lonpre,$b,$type); 143 | #print "$file \n"; 144 | $found[$j]=0; 145 | unless (-e $file) 146 | { 147 | $cmd = "curl -s http://e4ftl01.cr.usgs.gov/SRTM/$type.003/2000.02.11/$file --fail -o $file"; 148 | print "$cmd\n"; 149 | system($cmd); 150 | } 151 | 152 | if ($?==0) 153 | { print "downloaded $file\n"; 154 | $found[$j]=1; 155 | `unzip $file`; 156 | $file=sprintf("%s%02d%s%03d.hgt",$latpre,$a,$lonpre,$b); #unzipped file 157 | open $IN[$j], "$file" or die "Can't open $file for reading\n"; 158 | } 159 | else 160 | {print "downloading $file failed! assuming open water\n"; 161 | } 162 | } 163 | } 164 | } 165 | 166 | 167 | for ($j=0;$j<$n;$j++) { 168 | for ($k=0;$k<$dlon;$k++) { 169 | if($found[$k]==0) { 170 | print OUT "$zeros"; 171 | } 172 | else{ 173 | read $IN[$k],$num,$n*$byte_size; 174 | seek $IN[$k],$byte_size,1; # SHY: added this line 175 | # read $IN[$k],$jnk,$byte_size; # why ?? 176 | print OUT "$num"; 177 | } 178 | # print OUT "$jnk"; 179 | } 180 | } 181 | if ($i>0) { 182 | for ($k=0;$k<$dlon;$k++) { 183 | close $IN[$k]; 184 | } 185 | } 186 | 187 | 188 | 189 | #for ($k=0;$k<$dlon;$k++) { # why?? 190 | # read $IN[$k],$num,$n*$byte_size; 191 | ## read $IN[$k],$jnk,$byte_size; 192 | # close $IN[$k]; 193 | # print OUT "$num"; 194 | #} 195 | #print OUT "$jnk"; 196 | 197 | close(OUT); 198 | if ($swap) { 199 | `mv $outfile tmp`; 200 | `byte-swap 2 < tmp > $outfile`; 201 | #`rm tmp *hgt *hgt.zip`; #commented this out since it was dangerous - people may have .hgt files they don't want to delete 202 | } 203 | 204 | # original 205 | #$width=$n*$dlat+1; 206 | #$length=$n*$dlon+1; 207 | $width=$n*$dlon; 208 | $length=$n*$dlat; 209 | if ($source eq 3) { 210 | $dx=0.00083333333333; 211 | $dy=-0.00083333333333; 212 | } else { 213 | $dx=0.00083333333333/3; 214 | $dy=-0.00083333333333/3; 215 | } 216 | $x1=$minlon; # SHY: removed -$dx/2 217 | $y1=$maxlat; # SHY: removed +$dy/2 218 | Use_rsc "$outfile write WIDTH $width"; 219 | Use_rsc "$outfile write FILE_LENGTH $length"; 220 | Use_rsc "$outfile write X_STEP $dx"; # longitude 221 | Use_rsc "$outfile write Y_STEP $dy"; # latitude 222 | Use_rsc "$outfile write X_FIRST $x1"; 223 | Use_rsc "$outfile write Y_FIRST $y1"; 224 | 225 | # ohig: to make it compatible with other existing DEM .rsc file 226 | # This section is TBC 227 | Use_rsc "$outfile write X_UNIT degres"; 228 | Use_rsc "$outfile write Y_UNIT degres"; 229 | Use_rsc "$outfile write Z_OFFSET 0"; 230 | Use_rsc "$outfile write Z_SCALE 1"; 231 | Use_rsc "$outfile write PROJECTION LATLON"; 232 | 233 | `rm *.dem.rsc.hst`; 234 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InSAR Scripts 2 | 3 | I keep useful scripts for working with ROI_PAC here. Put them on your computer with: 4 | 5 | ``` 6 | git clone https://github.com/scottyhq/insar_scripts 7 | ``` 8 | 9 | ## Additional Information 10 | I have a [web page](http://scottyhq.github.io/blog) with more indepth notes for certain procedures. I don't forsee updating it regularly, but there currently instructions for [installing ROI_PAC on MacOSX](https://scottyhq.github.io/blog/2014/02/01/install-roipac-mac/) and [installing MDX software](https://scottyhq.github.io/blog/2014/02/03/install-mdx-mac/)... among a few other things. 11 | 12 | ## Wikis, etc. 13 | There are several user-contributed wiki pages that have lots of information on InSAR and ROI_PAC. 14 | 15 | * [WinSAR Wiki](https://winsar.unavco.org/portal/wiki/WikiIndex) probably is the most up-to-date, and includes the old ROI_PAC wiki website. 16 | 17 | * [ROI_PAC Tutorial](http://faculty.washington.edu/dasc/WikiRoiPac/welcome) by Professor Dave Schmidt. 18 | 19 | * [UNAVCO Short Courses](https://www.unavco.org/education/advancing-geodetic-skills/short-courses/short-courses.html) are run every summer and have lots of useful content. 20 | -------------------------------------------------------------------------------- /TSX/README.md: -------------------------------------------------------------------------------- 1 | # TSX Scripts 2 | 3 | Scripts in this directory are helpful for processing TerraSAR-X (TSX) data with ROI_PAC 4 | 5 | ## TSX Pre-processor 6 | Unlike other satellites, skip generating raw files and go straight to slc files. [Walter Szeliga](http://www.geology.cwu.edu/facstaff/walter) has made code available that reads the raw formats of current satellites (TSX, CSK, RS2). You must run this code before proceeding with ROI_PAC. 7 | 8 | The [GMTSAR website](http://topex.ucsd.edu/gmtsar/downloads/) also has a modified version of the pre-processors that work with GMTSAR. The following notes are for using the version downloaded via the version posted on this page. Here is the basic procedure: 9 | 10 | ``` 11 | wget https://github.com/scottyhq/insar_scripts/raw/master/TSX/sar-0.5.tar.gz 12 | tar -xzvf sar-0.5.tar.gz 13 | cd sar-0.5 14 | ./configure 15 | make install 16 | ``` 17 | 18 | ##### Troubleshooting install on Ubuntu Linux 19 | In order to successfully install the pre-processors on a lab computer we had to install additional libraries and modify the configure step to find them: 20 | 21 | ``` 22 | apt-get install libtiff-dev libboost-all-dev libhdf5-dev 23 | 24 | ./configure --with-boost-libdir=/usr/lib/x86_64-linux-gnu --prefix=/home/mpguest/MY_BIN LDFLAGS='-L/usr/lib/x86_64-linux-gnu -L/home/mpguest/miniconda/lib' CPPFLAGS='-I/home/mpguest/miniconda/include' LIBS='-lhdf5 -lhdf5_cpp' 25 | ``` 26 | 27 | Also, compiling the TSX preprocessor required commenting out the following lines in `tsx/src/Header.cpp` (59,60,95,96): 28 | 29 | ``` 30 | std::string formatCheck("CSAR"); 31 | if (formatCheck.compare(format) != 0) {throw "Not a valid COSAR file";} 32 | ``` 33 | 34 | You can do this automatically with a tricky command `sed -i 's,.*SAR.*,//&,g' Header.cpp` 35 | 36 | Finally, I had to add a flag `-std=c++0x` when the following TSX portion of the code failed: 37 | 38 | ``` 39 | g++ -std=c++0x -DHAVE_CONFIG_H -I. -I.. -I../include -I.. -I../../libsar/include -I../../tinyxpath/include -I/usr/include -I/home/mpguest/miniconda/include -g -O2 -MT make_slc_tsx.o -MD -MP -MF .deps/make_slc_tsx.Tpo -c -o make_slc_tsx.o make_slc_tsx.cpp 40 | ``` 41 | 42 | 43 | ##### Troubleshooting install on MacOSX 44 | In order to install the pre-processor successfully on my computer I had to download a few libraries and then point to their location at the configure step: 45 | 46 | ``` 47 | brew install boost 48 | brew install hdf5 --enable-cxx 49 | ./configure --with-boost=/usr/local/Cellar/boost/1.55.0 CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib --prefix=/Users/scott/Software/ROI_PAC_3_0_1/sar-0.5 50 | make install 51 | ``` 52 | 53 | ##### Create SLCs 54 | 55 | Be sure to add the pre-processor exectuables to your search path `export PATH=$PATH:[rootdir]/sar-0.5/bin` and then try running: 56 | 57 | ``` 58 | tar -xzvf dims_op_oc_dfd2_372011900_1.tar.gz 59 | make_slc_tsx -i dims_op_oc_dfd2_372011900_1/TSX-1.SAR.L1B/TDX1_SAR__SSC______SM_S_SRA_20111024T230132_20111024T230140/TDX1_SAR__SSC______SM_S_SRA_20111024T230132_20111024T230140.xml -p 111024 60 | ``` 61 | 62 | **NOTE** 63 | Before running roi_pac you have to also run `get_height.pl` in the folder where you created the SLC. If you miss this step, ROI_PAC will fail at `diffnsim.pl` because important orbital information is missing from the .rsc files. 64 | 65 | ``` 66 | get_height.pl 111024 67 | ``` 68 | 69 | ## Prepare_tsx.py 70 | Assuming you've ordered data through the German Aerospace Center (DLR) [Web Portal](https://centaurus.caf.dlr.de:8443/eoweb-ng/template/default/welcome/entryPage.vm) you should have a few tar.gz files in a directory. Running this script will unarchive the data, and automatically create the required directory structure for processing with ROI_PAC. Note that this requires TSX pre-processor scripts (above) to be installed. 71 | 72 | 73 | ## Running ROI_PAC 74 | The standard process_2pass.pl script has to be *run in two steps*: 75 | ``` 76 | process_2pass.pl int.proc roi_prep orbbase 77 | process_2pass.pl int.proc slcs done_sim_removal 78 | ``` 79 | 80 | 81 | ## Different PRFs 82 | TSX/TDX data tends to have PRFs that can vary by >100Hz. This causes a linear change in azimuth offsets, so if you have to run ampcor manually be sure to find the offset towards the top of your SLC file and use the **rds** specifier: 83 | 84 | ``` 85 | ampcor ampcor.in rds > ampcor.out 86 | ``` 87 | -------------------------------------------------------------------------------- /TSX/get_height.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | ### get_height.pl 3 | 4 | use Env qw(INT_SCR INT_BIN ); 5 | use lib "$INT_SCR"; #### Location of Generic.pm 6 | use Generic; 7 | use POSIX qw(ceil floor); 8 | 9 | 10 | sub Usage { 11 | print STDERR <.slc.rsc with height and other parameters 17 | 18 | 19 | END 20 | exit 1; 21 | } 22 | 23 | @ARGV >= 1 or Usage(); 24 | @args = @ARGV; 25 | 26 | $date = shift; 27 | $orbit_type = shift or $orbit_type = "HDR"; 28 | 29 | ################# 30 | #Message "Checking I/O"; 31 | ################# 32 | #@Infiles = ($asa_file_prefix, @imagery); 33 | #@Outfiles = ("$outname.raw", "$outname.raw.rsc"); 34 | #&IOcheck(\@Infiles, \@Outfiles); 35 | Log ("get_height.pl", @args); 36 | 37 | $day = Use_rsc "$date.slc read FIRST_LINE_DAY_OF_MONTH"; 38 | $month = Use_rsc "$date.slc read FIRST_LINE_MONTH_OF_YEAR"; 39 | $year = Use_rsc "$date.slc read FIRST_LINE_YEAR"; 40 | $sat = Use_rsc "$date.slc read PLATFORM"; 41 | $center_utc = Use_rsc "$date.slc read CENTER_LINE_UTC"; 42 | $first_line_utc = Use_rsc "$date.slc read FIRST_LINE_UTC"; 43 | $prf = Use_rsc "$date.slc read PRF"; 44 | 45 | if ($sat eq "TSX" || $sat eq "TDX" ||$sat eq "TSX-1" || $sat eq "TDX-1" ){ 46 | # this should be already in .rsc, but added here for now 47 | $range_pixel_size = Use_rsc "$date.slc read RANGE_PIXEL_SIZE"; 48 | $C = 299792458; 49 | $range_sampling_frequency = $C / (2 * $range_pixel_size); 50 | $antenna_length = 4.784; # from Eric Gurrola script 51 | 52 | Use_rsc "$date.slc write RANGE_SAMPLING_FREQUENCY $range_sampling_frequency"; 53 | Use_rsc "$date.slc write ANTENNA_LENGTH $antenna_length"; 54 | } 55 | 56 | # this part from make_raw_envi.pl 57 | ############################### 58 | Message "Using Orbit Information"; 59 | ############################### 60 | ($q1,$q2,$Lat,$Lon,$height_mid, $x0, $y0, $z0, $vx0, $vy0,$vz0) = split /\s+/, 61 | `$INT_SCR/state_vector.pl $year$month$day $center_utc $sat $orbit_type $date`; 62 | Status "state_vector.pl"; 63 | 64 | $pi = atan2(1,1)*4; 65 | if ($orbit_type eq "HDR"){ 66 | $ae = 6378137; #GRS80 reference ellipsoid 67 | $flat = 1/298.257223563; 68 | $r = sqrt($x0**2+$y0**2+$z0**2); 69 | $r1 = sqrt($x0**2+$y0**2); 70 | $Lat = atan2($z0,$r1); 71 | $Lon = atan2($y0,$x0); 72 | $H = $r-$ae; 73 | for ($i=1; $i<7; $i++){ 74 | $N = $ae/(sqrt(1-$flat*(2-$flat)*sin($Lat)**2)); 75 | $TanLat = $z0/$r1/(1-(2-$flat)*$flat*$N/($N+$H)); 76 | $Lat = atan2($TanLat,1); 77 | $H = $r1/cos($Lat)-$N; 78 | } 79 | $height_mid=$H; 80 | } 81 | 82 | $ae = 6378137; #WGS84 reference ellipsoid 83 | $flat = 1./298.257223563; 84 | $N = $ae/sqrt(1-$flat*(2-$flat)*sin($Lat)**2); 85 | $re_mid=$N; 86 | 87 | $ve=-sin($Lon)*$vx0+cos($Lon)*$vy0; 88 | $vn=-sin($Lat)*cos($Lon)*$vx0-sin($Lat)*sin($Lon)*$vy0+cos($Lat)*$vz0; 89 | $hdg = atan2($ve,$vn); 90 | $e2 = $flat*(2-$flat); 91 | $M = $ae*(1-$e2)/(sqrt(1-$e2*sin($Lat)**2))**3; 92 | $earth_radius_mid = $N*$M/($N*(cos($hdg))**2+$M*(sin($hdg))**2); 93 | 94 | ($q1,$q2,$q3,$q4,$height_top, $x0, $y0, $z0, $vx, $vy,$vz) = split /\s+/, 95 | `$INT_SCR/state_vector.pl $year$month$day $first_line_utc $sat $orbit_type $date`; 96 | Status "state_vector.pl"; 97 | 98 | if ($orbit_type eq "HDR" ){ 99 | $ae = 6378137; #GRS80 reference ellipsoid 100 | $flat = 1/298.257223563; 101 | $r = sqrt($x0**2+$y0**2+$z0**2); 102 | $r1 = sqrt($x0**2+$y0**2); 103 | $Lat = atan2($z0,$r1); 104 | $Lon = atan2($y0,$x0); 105 | $H = $r-$ae; 106 | for ($i=1; $i<7; $i++){ 107 | $N = $ae/(sqrt(1-$flat*(2-$flat)*sin($Lat)**2)); 108 | $TanLat = $z0/$r1/(1-(2-$flat)*$flat*$N/($N+$H)); 109 | $Lat = atan2($TanLat,1); 110 | $H = $r1/cos($Lat)-$N; 111 | } 112 | $height_top=$H; 113 | } 114 | 115 | $height_dt=($height_mid-$height_top)/($center_utc-$first_line_utc); 116 | if ($vz0 > 0) {$orbit_direction = "ascending";} 117 | else {$orbit_direction = "descending";} 118 | $velocity_mid=sqrt($vx0**2 + $vy0**2 + $vz0**2); 119 | 120 | $Latd=$Lat*180./$pi; 121 | $Lond=$Lon*180./$pi; 122 | $hdgd=$hdg*180./$pi; 123 | 124 | # some of these already calculated by Walter's make_slc_tsx 125 | Use_rsc "$date.slc write HEIGHT_TOP $height_top"; 126 | #Use_rsc "$date.slc write HEIGHT $height_mid"; 127 | #Use_rsc "$date.slc write HEIGHT_DT $height_dt"; 128 | #Use_rsc "$date.slc write VELOCITY $velocity_mid"; 129 | Use_rsc "$date.slc write LATITUDE $Latd"; 130 | Use_rsc "$date.slc write LONGITUDE $Lond"; 131 | Use_rsc "$date.slc write HEADING $hdgd"; 132 | #Use_rsc "$date.slc write EQUATORIAL_RADIUS $ae"; 133 | #Use_rsc "$date.slc write ECCENTRICITY_SQUARED $e2"; 134 | Use_rsc "$date.slc write EARTH_EAST_RADIUS $N"; 135 | Use_rsc "$date.slc write EARTH_NORTH_RADIUS $M"; 136 | #Use_rsc "$date.slc write EARTH_RADIUS $earth_radius_mid"; 137 | Use_rsc "$date.slc write ORBIT_DIRECTION $orbit_direction"; 138 | 139 | # these calculations from roi_prep.pl 140 | $delta_line_utc = 1/$prf; 141 | $azimuth_pixel_size = $velocity_mid/$prf; 142 | Use_rsc "$date.slc write DELTA_LINE_UTC $delta_line_utc"; 143 | Use_rsc "$date.slc write AZIMUTH_PIXEL_SIZE $azimuth_pixel_size"; 144 | Use_rsc "$date.slc write ALOOKS 1"; 145 | Use_rsc "$date.slc write RLOOKS 1"; 146 | 147 | # starting with SLC so infile and outfile the same 148 | $infile = "$date.slc"; 149 | $outfile = "$date.slc"; 150 | 151 | ############################################### 152 | # Get peg info and update geometry parameters # 153 | # now extracted for SLC, not raw data # 154 | ############################################### 155 | 156 | system "cp ${infile}.rsc debug.rsc"; 157 | 158 | system "$INT_SCR/GetPeg.pl $outfile $orbit_type"; 159 | 160 | ($name = $outfile) =~ s/\.[^.]*$//; #strip the last extension from the input file name 161 | 162 | open PEGOUT, "$name.peg.out"; 163 | while( defined( $Line = ) ){ 164 | if( $Line =~ /Peg Lat\/Lon , H =\s+(\S+)\s+(\S+)\s+(\S+)/ ){ 165 | $Latd = $1; 166 | $Lond = $2; 167 | $PegHgt = $3; 168 | } 169 | if( $Line =~ /Peg Heading =\s+(\S+)/ ){ 170 | $hdgd = $1; 171 | } 172 | if( $Line =~ /Vertical Fit:\s+(\S+)\s+(\S+)\s+(\S+)/ ){ 173 | @Height_poly = ( $1, $2, $3 ); 174 | } 175 | if( $Line =~ /Horizontal Fit:\s+(\S+)\s+(\S+)\s+(\S+)/ ){ 176 | @CrossT_poly = ( $1, $2, $3 ); 177 | } 178 | if( $Line =~ /Vertical Velocity Fit:\s+(\S+)\s+(\S+)/ ){ 179 | @Vert_V_poly = ( $1, $2 ); 180 | } 181 | if( $Line =~ /Cross-Track Velocity Fit:\s+(\S+)\s+(\S+)/ ){ 182 | @CrossT_V_poly = ( $1, $2 ); 183 | } 184 | if( $Line =~ /Along-Track Velocity Fit:\s+(\S+)\s+(\S+)/ ){ 185 | @AlongT_V_poly = ( $1, $2 ); 186 | } 187 | if( $Line =~ /Platform SCH Velocity \(m\/s\):\s+(\S+)\s+(\S+)\s+(\S+)/ ){ 188 | @VelocitySCH = ( $1, $2, $3 ); 189 | $velocity_mid = Norm( @VelocitySCH ); 190 | } 191 | if( $Line =~ /Platform SCH Acceleration \(m\/s\^2\):\s+(\S+)\s+(\S+)\s+(\S+)/ ){ 192 | @AccelerationSCH = ( $1, $2, $3 ); 193 | } 194 | if( $Line =~ /Time to first\/middle scene:\s+\S+\s+(\S+)/ ){ 195 | $PegUtc = $1; 196 | } 197 | } 198 | 199 | close PEGOUT; 200 | 201 | $HgtDt = $Height_poly[1] * $VelocitySCH[0]; 202 | 203 | Use_rsc "$outfile write HEIGHT $Height_poly[0]"; 204 | Doc_rsc( 205 | RSC_Tip => 'Platform Altitude at Peg Point', 206 | RSC_Doc => q[ 207 | "Platform Altitude" based on RDF usage in diffnsim.pl 208 | 209 | First coefficient (constant term) of orbit "Vertical Fit" polynomial 210 | output by get_peg_info run by GetPeg.pl. 211 | 212 | Polynomial is function of SCH 'S' coordinate. 213 | Value is in 'H' direction, which is height above SCH reference sphere. 214 | 215 | SCH Coordinate system. 216 | ], 217 | RSC_Derivation => q[ 218 | See baseline/get_peg_info.f 219 | ], 220 | RSC_Type => Real, 221 | RSC_Unit => 'SI:meter', 222 | ); 223 | 224 | Use_rsc "$outfile write HEIGHT_DS $Height_poly[1]"; 225 | Doc_rsc( 226 | RSC_Tip => 'Platform Altitude Rate at Peg Point', 227 | RSC_Doc => q[ 228 | "Platform Altitude Rate" based on RDF usage in diffnsim.pl 229 | 230 | Second coefficient (linear term) of orbit "Vertical Fit" polynomial 231 | output by get_peg_info run by GetPeg.pl. 232 | 233 | Polynomial is function of SCH 'S' coordinate. 234 | Value is in 'H' direction, which is height above SCH reference sphere. 235 | 236 | SCH Coordinate system. 237 | ], 238 | RSC_Derivation => q[ 239 | See baseline/get_peg_info.f 240 | ], 241 | RSC_Type => Real, 242 | RSC_Unit => 'SI:meter/SI:meter', 243 | ); 244 | 245 | Use_rsc "$outfile write HEIGHT_DDS $Height_poly[2]"; 246 | Doc_rsc( 247 | RSC_Tip => 'Platform Altitude Acceleration at Peg Point', 248 | RSC_Doc => q[ 249 | "Platform Altitude Acceleration" based on RDF usage in diffnsim.pl 250 | 251 | Third coefficient (quadratic term) of orbit "Vertical Fit" polynomial 252 | output by get_peg_info run by GetPeg.pl. 253 | 254 | Polynomial is function of SCH 'S' coordinate. 255 | Value is in 'H' direction, which is height above SCH reference sphere. 256 | 257 | SCH Coordinate system. 258 | ], 259 | RSC_Derivation => q[ 260 | See baseline/get_peg_info.f 261 | ], 262 | RSC_Type => Real, 263 | RSC_Unit => 'SI:meter/SI:meter**2', 264 | ); 265 | 266 | Use_rsc "$outfile write HEIGHT_DT $HgtDt"; 267 | Doc_rsc( 268 | RSC_Tip => 'Platform Altitude change w.r.t. time at Peg Point', 269 | RSC_Derivation => q[ 270 | $HgtDt = $Height_poly[1] * $VelocitySCH[0]; 271 | ], 272 | RSC_Comment => q[ 273 | Does not appear to ever be used. 274 | ], 275 | RSC_Type => Real, 276 | RSC_Unit => 'SI:second', 277 | ); 278 | 279 | Use_rsc "$outfile write CROSSTRACK_POS $CrossT_poly[0]"; 280 | Use_rsc "$outfile write CROSSTRACK_POS_DS $CrossT_poly[1]"; 281 | Use_rsc "$outfile write CROSSTRACK_POS_DDS $CrossT_poly[2]"; 282 | Use_rsc "$outfile write VELOCITY $velocity_mid"; 283 | Doc_rsc( 284 | RSC_Tip => 'Norm of Platform SCH Velocity at Peg Point', 285 | RSC_Doc => q[ 286 | "Body fixed S/C velocities" based on RDF usage in roi_prep.pl and autofocus.pl. 287 | "Spacecraft Along Track Velocity" based on RDF usage in inverse3d.pl 288 | "Platform Velocity" based on RDF usage in diffnsim.pl and phase2base.pl 289 | ], 290 | RSC_Derivation => q[ 291 | $velocity_mid = Norm( @VelocitySCH ); 292 | ], 293 | RSC_Type => Real, 294 | RSC_Unit => 'SI:meter/SI:second', 295 | ); 296 | 297 | Use_rsc "$outfile write VELOCITY_S $VelocitySCH[0]"; 298 | Doc_rsc( 299 | RSC_Tip => 'Platform Velocity S Component', 300 | RSC_Doc => q[ 301 | 'S' Component of 'Platform SCH Velocity' 302 | produced by get_peg_info run by GetPeg.pl. 303 | 304 | SCH Coordinate system. 305 | ], 306 | RSC_Derivation => q[ 307 | See baseline/get_peg_info.f 308 | ], 309 | RSC_Comment => q[ 310 | Appears to only be used by roi_prep.pl and autofocus.pl 311 | ], 312 | RSC_Type => Real, 313 | RSC_Unit => 'SI:meter/SI:second', 314 | ); 315 | 316 | Use_rsc "$outfile write VELOCITY_C $VelocitySCH[1]"; 317 | Doc_rsc( 318 | RSC_Tip => 'Platform Velocity C Component', 319 | RSC_Doc => q[ 320 | 'C' Component of 'Platform SCH Velocity' 321 | produced by get_peg_info run by GetPeg.pl. 322 | 323 | SCH Coordinate system. 324 | ], 325 | RSC_Derivation => q[ 326 | See baseline/get_peg_info.f 327 | ], 328 | RSC_Comment => q[ 329 | Appears to only be used by roi_prep.pl and autofocus.pl 330 | Note - this is not the speed of light. 331 | ], 332 | RSC_Type => Real, 333 | RSC_Unit => 'SI:meter/SI:second', 334 | ); 335 | Use_rsc "$outfile write VELOCITY_H $VelocitySCH[2]"; 336 | Doc_rsc( 337 | RSC_Tip => 'Platform Velocity H Component', 338 | RSC_Doc => q[ 339 | 'H' Component of 'Platform SCH Velocity' 340 | produced by get_peg_info run by GetPeg.pl. 341 | 342 | SCH Coordinate system. 343 | ], 344 | RSC_Derivation => q[ 345 | See baseline/get_peg_info.f 346 | ], 347 | RSC_Comment => q[ 348 | Appears to only be used by roi_prep.pl and autofocus.pl 349 | ], 350 | RSC_Type => Real, 351 | RSC_Unit => 'SI:meter/SI:second', 352 | ); 353 | 354 | Use_rsc "$outfile write ACCELERATION_S $AccelerationSCH[0]"; 355 | Doc_rsc( 356 | RSC_Tip => 'Platform Acceleration S Component', 357 | RSC_Doc => q[ 358 | 'S' Component of 'Platform SCH Acceleration' 359 | produced by get_peg_info run by GetPeg.pl. 360 | 361 | SCH Coordinate system. 362 | ], 363 | RSC_Derivation => q[ 364 | See baseline/get_peg_info.f 365 | ], 366 | RSC_Comment => q[ 367 | Appears to only be used by roi_prep.pl and autofocus.pl 368 | ], 369 | RSC_Type => Real, 370 | RSC_Unit => 'SI:meter/SI:second**2', 371 | ); 372 | 373 | Use_rsc "$outfile write ACCELERATION_C $AccelerationSCH[1]"; 374 | Doc_rsc( 375 | RSC_Tip => 'Platform Acceleration C Component', 376 | RSC_Doc => q[ 377 | 'C' Component of 'Platform SCH Acceleration' 378 | produced by get_peg_info run by GetPeg.pl. 379 | 380 | SCH Coordinate system. 381 | ], 382 | RSC_Derivation => q[ 383 | See baseline/get_peg_info.f 384 | ], 385 | RSC_Comment => q[ 386 | Appears to only be used by roi_prep.pl and autofocus.pl 387 | ], 388 | RSC_Type => Real, 389 | RSC_Unit => 'SI:meter/SI:second**2', 390 | ); 391 | 392 | Use_rsc "$outfile write ACCELERATION_H $AccelerationSCH[2]"; 393 | Doc_rsc( 394 | RSC_Tip => 'Platform Acceleration H Component', 395 | RSC_Doc => q[ 396 | 'H' Component of 'Platform SCH Acceleration' 397 | produced by get_peg_info run by GetPeg.pl. 398 | 399 | SCH Coordinate system. 400 | ], 401 | RSC_Derivation => q[ 402 | See baseline/get_peg_info.f 403 | ], 404 | RSC_Comment => q[ 405 | Appears to only be used by roi_prep.pl and autofocus.pl 406 | ], 407 | RSC_Type => Real, 408 | RSC_Unit => 'SI:meter/SI:second**2', 409 | ); 410 | 411 | Use_rsc "$outfile write VERT_VELOCITY $Vert_V_poly[0]"; 412 | Use_rsc "$outfile write VERT_VELOCITY_DS $Vert_V_poly[1]"; 413 | Use_rsc "$outfile write CROSSTRACK_VELOCITY $CrossT_V_poly[0]"; 414 | Use_rsc "$outfile write CROSSTRACK_VELOCITY_DS $CrossT_V_poly[1]"; 415 | Use_rsc "$outfile write ALONGTRACK_VELOCITY $AlongT_V_poly[0]"; 416 | Use_rsc "$outfile write ALONGTRACK_VELOCITY_DS $AlongT_V_poly[1]"; 417 | Use_rsc "$outfile write LATITUDE $Latd"; 418 | Doc_rsc( 419 | RSC_Tip => 'Latitude of SCH Peg Point', 420 | RSC_Doc => q[ 421 | 'Lat' value of 'Peg Lat/Lon , H' 422 | produced by get_peg_info run by GetPeg.pl. 423 | 424 | ], 425 | RSC_Derivation => q[ 426 | See baseline/get_peg_info.f 427 | ], 428 | RSC_Comment => q[ 429 | Appears to only be used in inverse3d.pl to specify "Peg Point Data" 430 | ], 431 | RSC_Type => Real, 432 | RSC_Unit => 'SI:degree', 433 | ); 434 | 435 | Use_rsc "$outfile write LONGITUDE $Lond"; 436 | Doc_rsc( 437 | RSC_Tip => 'Longitude of SCH Peg Point', 438 | RSC_Doc => q[ 439 | 'Lon' value of 'Peg Lat/Lon , H' 440 | produced by get_peg_info run by GetPeg.pl. 441 | 442 | ], 443 | RSC_Derivation => q[ 444 | See baseline/get_peg_info.f 445 | ], 446 | RSC_Comment => q[ 447 | Appears to only be used in inverse3d.pl to specify "Peg Point Data" 448 | ], 449 | RSC_Type => Real, 450 | RSC_Unit => 'SI:degree', 451 | ); 452 | 453 | Use_rsc "$outfile write HEADING $hdgd"; 454 | Doc_rsc( 455 | RSC_Tip => 'Heading of SCH Peg Point', 456 | RSC_Doc => q[ 457 | 'Peg Heading' value 458 | produced by get_peg_info run by GetPeg.pl. 459 | ], 460 | RSC_Derivation => q[ 461 | See baseline/get_peg_info.f 462 | ], 463 | RSC_Comment => q[ 464 | Appears to only be used in inverse3d.pl to specify "Peg Point Data" 465 | ], 466 | RSC_Type => Real, 467 | RSC_Unit => 'SI:degree', 468 | ); 469 | 470 | Use_rsc "$outfile write PEG_UTC $PegUtc"; 471 | Doc_rsc( 472 | RSC_Tip => 'Scene start time-of-day', 473 | RSC_Doc => q[ 474 | 'first' value of 'Time to first/middle scene' 475 | produced by get_peg_info run by GetPeg.pl. 476 | ], 477 | RSC_Derivation => q[ 478 | See baseline/get_peg_info.f 479 | ], 480 | RSC_Comment => q[ 481 | Appears to only be used in inverse3d.pl to calculate 482 | $PegLine = int( ( $PegUtc - $slc_first_line_utc ) / $delta_line_utc ); 483 | which is used for 484 | 'Reference Line for SCH Coordinates' RDF value 485 | ], 486 | RSC_Type => Real, 487 | RSC_Unit => 'SI:second', 488 | ); 489 | 490 | ######################### 491 | Message "SLC data ready for processing"; 492 | ######################### 493 | 494 | exit 0; 495 | 496 | 497 | =pod 498 | 499 | =head1 USAGE 500 | 501 | B I< asa_file_prefix_root [orbit type] > 502 | 503 | orbit type: ODR, HDR(HDR ECEF), HDI (HDR ECI), DOR(DORIS ECEF), DOI(DORIS ECI), UCL (GSFC+UCL), NOM (GSFC+Norminal) 504 | 505 | =head1 FUNCTION 506 | 507 | Creates I.raw and I.raw.rsc from imagery files 508 | 509 | =head1 ROUTINES CALLED 510 | 511 | state_vector.pl 512 | 513 | 514 | =head1 CALLED BY 515 | 516 | none 517 | 518 | =head1 FILES USED 519 | 520 | 521 | =head1 FILES CREATED 522 | 523 | I.raw 524 | 525 | I.raw.rsc 526 | 527 | I_parse_line.out 528 | 529 | shift.out 530 | 531 | shift.out.rsc 532 | 533 | =head1 HISTORY 534 | 535 | Perl Script : Yuri Fialko 03/24/2004 536 | modified by Ingrid Johanson 10/2004 to include DOR as orbit option 537 | modified to add range bias adjustment Eric Fielding 1/2005 538 | Other cleanup Eric Fielding 2/2005 539 | added HEIGHT_TOP keyword to .raw.rsc to keep both top and middle (peg) heights EJF 2005/3/21 540 | modified code to find orbit file with Mark Simon's fix to avoid problems with underscores in directory path EJF 2005/8/19 541 | added optional choice of starting window code EJF 2005/9/28 542 | added UCL and NOM orbit options by Zhenhong Li on 24 Oct 2005 543 | added DOI option by Zhenhong Li on 12 Nov 2005 544 | 545 | =head1 LAST UPDATE 546 | 547 | 2005/11/12 Zhenhong Li 548 | 549 | =cut 550 | -------------------------------------------------------------------------------- /TSX/plot_baselines_prf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Baseline plot for directory of ALOS or TSX data, with dates colored by PRF 4 | 5 | Usage: plot_baselines_prf.py [baseline_file] 6 | 7 | baselines_prf.txt can be created with: 8 | 1) If ROI_PAC hasn't been run yet: 9 | get_roi_baselines.py 111019 10 | 11 | 2) If it has (sometimes awk/mawk/gawk/ depending on platform): 12 | grep PRF 1*/*raw.rsc | awk '{ print $2}' > prfs.txt 13 | # change master date dir 14 | grep P_BASELINE_TOP int*111019/*baseline.rsc | awk '{{print substr($1,5,6)" "$2}}' > dolist.in 15 | sed -i '1i111019 0' dolist.in 16 | paste dolist.in prfs.txt > baselines_prfs.txt 17 | 18 | Author: Scott Henderson 19 | """ 20 | import sys 21 | import os 22 | import numpy as np 23 | import matplotlib.pyplot as plt 24 | import datetime 25 | from matplotlib.dates import MonthLocator, DateFormatter 26 | import matplotlib.mlab as mlab 27 | 28 | 29 | def make_baseline_plot(baseline_file): 30 | ''' More informative version using record array for a particular track''' 31 | fig = plt.figure(figsize=(11,8.5)) 32 | ax = fig.add_subplot(111) 33 | 34 | # Load date and baseline data from file 35 | dates, bperps, prfs = np.genfromtxt(baseline_file,unpack=True,comments='#',dtype=str) #easiest way to get columns of text, then convert after 36 | prfs = prfs.astype('f4') 37 | bperps = bperps.astype('f4') 38 | unique_prfs = np.unique(prfs) 39 | 40 | pltdates = np.array([datetime.datetime.strptime(date,'%y%m%d') for date in dates]) 41 | #colors = plt.cm.cool(unique_prfs/unique_prfs.max()) #color scaled by PRF value 42 | colors = plt.cm.cool(np.linspace(0,1,unique_prfs.size)) #max dicrete color separation 43 | for p,color in zip(unique_prfs,colors): 44 | ind = (prfs == p) 45 | plt.scatter(pltdates[ind], bperps[ind], s=100, c=color, label=p) 46 | 47 | #plot text shorthand date next to point 48 | for D,B in zip(pltdates, bperps): 49 | plt.text(D,B,D.strftime('%y%m%d')) 50 | 51 | plt.title(os.getcwd()) 52 | plt.ylabel('B_Perp [m]') 53 | 54 | months = MonthLocator() # every month 55 | ax.xaxis.set_minor_locator(months) 56 | ax.fmt_xdata = DateFormatter('%Y-%m-%d') #lower left coodinate display 57 | fig.autofmt_xdate() 58 | 59 | plt.legend(loc='upper left', title='PRF [Hz]', scatterpoints=1) #note: legend='best' doesn;t always work 60 | plt.grid(True) 61 | plt.savefig('baseline_plot.pdf',bbox_inches='tight') 62 | plt.show() 63 | 64 | 65 | if __name__ == '__main__': 66 | basefile = sys.argv[1] 67 | make_baseline_plot(basefile) 68 | -------------------------------------------------------------------------------- /TSX/prepare_tsx.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | unarchive tsx data from DLR into ROI_PAC directory structure to start from 'slcs' 4 | 5 | Usage: prepare_tsx.py 6 | """ 7 | 8 | import shutil 9 | import sys 10 | import os 11 | from optparse import OptionParser 12 | import tarfile 13 | import subprocess 14 | import shlex 15 | 16 | def locate_files(folder): 17 | '''copy xml file from tar directory to date folder (needed to create slc)''' 18 | path = os.path.join(folder, 'TSX-1.SAR.L1B') 19 | subfolder = os.listdir(path)[0] 20 | files = os.listdir(os.path.join(path,subfolder)) 21 | for f in files: 22 | if f.endswith('xml'): 23 | xml = f 24 | xmlpath = os.path.join(path,subfolder,xml) 25 | kmlpath = os.path.join(path,subfolder,'SUPPORT','GEARTH_POLY.kml') 26 | 27 | return os.path.abspath(xmlpath), os.path.abspath(kmlpath) 28 | 29 | 30 | def untar(file): 31 | '''Untar file from DLR''' 32 | directory = file.rstrip('tar.gz') 33 | if os.path.isdir(directory): 34 | print 'Directory exists... skipping untar step' 35 | else: 36 | print 'Untarring {0}...'.format(file) 37 | f = tarfile.open(file) 38 | f.extractall('.') 39 | 40 | return directory 41 | 42 | 43 | def create_slc(directory): 44 | ''' call make_slc_tsx.csh from date folder''' 45 | xmlpath, kmlpath = locate_files(directory) 46 | xml = os.path.basename(xmlpath) 47 | fulldate = xml.split('_')[-1].split('T')[0] 48 | date = fulldate[2:] 49 | 50 | print '\nCreating SLC:\n', date, xml 51 | if not os.path.isdir(date): 52 | os.mkdir(date) 53 | os.chdir(date) 54 | 55 | # Create copies of footprint kml and xml metadata in date folder 56 | shutil.copyfile(xmlpath, date + '.xml') 57 | shutil.copyfile(kmlpath, date + '.kml') 58 | 59 | # Call Walter Z's preprocessor 60 | cmd = 'make_slc_tsx -i {0} -p {1}'.format(xmlpath,date) 61 | print cmd 62 | if os.path.isfile(date + '.slc'): 63 | print '{0}.slc already exists, skipping creation...'.format(date) 64 | else: 65 | with open('make_slc_tsx.out','w') as out: 66 | subprocess.call(shlex.split(cmd), stdout=out) 67 | 68 | # in preparation for ROI_PAC, create empty raw files 69 | open('{0}.raw'.format(date),'w').close() 70 | shutil.copyfile('{0}.slc.rsc'.format(date), '{0}.raw.rsc'.format(date)) 71 | 72 | # Run get_height.pl 73 | cmd = 'get_height.pl {0}'.format(date) 74 | print cmd 75 | subprocess.call(shlex.split(cmd)) 76 | 77 | return date + '.slc' 78 | 79 | 80 | def done_message(slc): 81 | #NOTE: could check baseline first: (grep rsc file for P_BASELINE_TOP_HDR 82 | print '\nCreated {0}.\nReady to run ROI_PAC from slcs:\n'.format(slc) 83 | cmd1 = 'process_2pass.pl [?].proc roi_prep orbbase' 84 | print cmd1 85 | cmd2 = 'process_2pass.pl [?].proc slcs done_sim_removal' 86 | print cmd2 87 | 88 | 89 | def main(): 90 | #args = ['-n'] #testing 91 | parser = OptionParser(usage="Usage %prog [options] dims_file", version="%prog 1.0") 92 | (options, args) = parser.parse_args() 93 | if len(args) != 1: 94 | parser.error("must specify dims_ directory or tar file") 95 | if not os.path.exists(args[0]): 96 | parser.error("{0} not found".format(args[0])) 97 | 98 | file = args[0] 99 | if os.path.isdir(file): 100 | directory = file 101 | else: 102 | directory = untar(file) 103 | slc = create_slc( directory) 104 | done_message(slc) 105 | 106 | 107 | if __name__ == '__main__': 108 | main() 109 | -------------------------------------------------------------------------------- /TSX/sar-0.5.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyhq/insar_scripts/b4a1d1aef41649408ca01c21382817506d92f70d/TSX/sar-0.5.tar.gz --------------------------------------------------------------------------------