├── combination ├── guideline_insar_g2s.pdf ├── cut.bash ├── correct_forum ├── correct_forum_sbas ├── README.md ├── param_INSAR_G2S.txt ├── cut_SM.bash ├── cut_sbas.bash ├── fix_pscands_SM.sh ├── fix_pscands_SB.sh ├── combination.c ├── process_intf.csh ├── sm_config.sh ├── mt_extract_info_gmtsar_SB ├── mt_extract_info_gmtsar_SM ├── devide_region.sh ├── prep_orb.sh ├── prep.sh ├── scihub_poeorb_download.sh ├── stamps_reg.csh ├── mt_prep_gmtsar_SM ├── mt_prep_gmtsar_SB ├── intf_kml.sh ├── prep_dir.sh ├── pair_config.sh ├── baseline_sen.sh ├── mt_extract_cands_gmtsar_SM ├── mt_extract_cands_gmtsar_SB ├── dispersion.csh ├── dispersion_sbas.sh ├── gmtsar_matlab ├── sb_load_initial_gmtsar.m ├── ps_load_initial_gmtsar.m └── stamps.m └── INSAR_G2S.sh /combination: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dedetmix/INSAR_G2S/HEAD/combination -------------------------------------------------------------------------------- /guideline_insar_g2s.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dedetmix/INSAR_G2S/HEAD/guideline_insar_g2s.pdf -------------------------------------------------------------------------------- /cut.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | region="11000/15000/10500/11500" 4 | 5 | rm re_*.grd im_*.grd 6 | cat list | while read a b c 7 | do 8 | echo $a 9 | gmt grdmath real_$a.grd FLIPUD = tmp.grd=bf 10 | gmt grdsample tmp.grd -T -Gtmp.grd 11 | gmt grdcut tmp.grd -R$region -Gre_$a.grd=bf 12 | gmt grdmath imag_$a.grd FLIPUD = tmp.grd=bf 13 | gmt grdsample tmp.grd -T -Gtmp.grd 14 | gmt grdcut tmp.grd -R$region -Gim_$a.grd=bf 15 | done 16 | rm tmp.grd 17 | -------------------------------------------------------------------------------- /correct_forum: -------------------------------------------------------------------------------- 1 | mv pscands.1.ph pscands.1.ph0 2 | 3 | cat << son > swap_pixels.m 4 | % baseline list used to get number of interferograms 5 | bperpname=['bperp.1.in']; 6 | bperp=load(bperpname); 7 | n_ifg=size(bperp,1); 8 | 9 | ijname=['pscands.1.ij']; 10 | ij=load(ijname); 11 | n_ps=size(ij,1); 12 | n_l=n_ps*n_ifg*2; %(2 for real and imag parts) 13 | phname=['pscands.1.ph0']; 14 | fid=fopen(phname,'r'); 15 | ph=zeros(n_l,1,'single'); 16 | byte_count=n_l*2; 17 | [ph_bit,byte_count]=fread(fid,[n_l,1],'float'); 18 | 19 | aa=1; 20 | for ii=1:n_ps*2:n_l 21 | for j=ii:ii+n_ps-1 22 | ph(aa,1)=ph_bit(j,1); 23 | ph(aa+1,1)=ph_bit(j+n_ps,1); 24 | aa = aa + 2; 25 | end 26 | end 27 | 28 | fileID = fopen('pscands.1.ph', 'w'); 29 | fwrite(fileID,ph,'single'); 30 | delete('pscands.1.ph0') 31 | exit; 32 | son 33 | 34 | matlab -nodesktop -nodisplay -r "swap_pixels;exit" 35 | 36 | -------------------------------------------------------------------------------- /correct_forum_sbas: -------------------------------------------------------------------------------- 1 | cp pscands.1.ph pscands.1.ph0 2 | 3 | cat << son > swap_pixels.m 4 | % baseline list used to get number of interferograms 5 | ifgname=['ifgday.1.in']; 6 | ifg=load(ifgname); 7 | n_ifg=size(ifg,1); 8 | 9 | ijname=['pscands.1.ij']; 10 | ij=load(ijname); 11 | n_ps=size(ij,1); 12 | n_l=n_ps*n_ifg*2; %(2 for real and imag parts) 13 | phname=['pscands.1.ph0']; 14 | fid=fopen(phname,'r'); 15 | ph=zeros(n_l,1,'single'); 16 | byte_count=n_l*2; 17 | [ph_bit,byte_count]=fread(fid,[n_l,1],'float'); 18 | 19 | aa=1; 20 | for ii=1:n_ps*2:n_l 21 | for j=ii:ii+n_ps-1 22 | ph(aa,1)=ph_bit(j,1); 23 | ph(aa+1,1)=ph_bit(j+n_ps,1); 24 | aa = aa + 2; 25 | end 26 | end 27 | 28 | fileID = fopen('pscands.1.ph', 'w'); 29 | fwrite(fileID,ph,'single'); 30 | %delete('pscands.1.ph0') 31 | exit; 32 | son 33 | 34 | matlab -nodesktop -nodisplay -r "swap_pixels;exit" 35 | 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | INSAR_G2S is an automated processing to integrate between GMTSAR (the interferogram generation) and StaMPS (the time series InSAR analysis using PS and SB or both). 2 | 3 | This program was established by the scripts of gmtsar_process, gmtsar2stamps, and gmtsar2stamps_sbas. 4 | gmtsar2stamps was originally from : 5 | - Xiaopeng Tong, Chinese Academy of Sciences 6 | - Xiaohua (Eric) Xu - Scripps Institution of Oceanography 7 | - David Sandwell, Scripps Institution of Oceanography 8 | 9 | Please read the guideline to use INSAR_G2S --> guideline_insar_g2s.pdf 10 | 11 | For question and feedback, contact to : Noorlaila Hayati (email: noorlaila@geodesy.its.ac.id) 12 | 13 | Credit to users from GMTSAR forum 14 | http://gmt.soest.hawaii.edu/boards/6/topics/4346 15 | 16 | This is research code provided to you "AS IS" with no warranties of correctness. Use at your own risk. 17 | 18 | -------------------------------------------------------------------------------- /param_INSAR_G2S.txt: -------------------------------------------------------------------------------- 1 | ############ set parameters ################################################ 2 | dataorbit = descending 3 | # OPTION: ascending or descending 4 | raw_path = /media/isya/649d6fa0-f505-4c78-9eb5-78d4aec5c2f3/RAW/Celle/Descending 5 | sen_POE = /home/isya/APPS/ciloto/sen_orbit/aux_poeorb/ 6 | temp_bl = 50 7 | spatial_bl = 100 8 | region = 1000/16000/9000/12000 9 | reg_ll = 9.47916666667/10.9652777778/52.4958333333/53.15 10 | n_range = 2 11 | n_azimuth = 3 12 | ov_range = 50 13 | ov_azimuth = 200 14 | threshold = 0.4 15 | heading = auto # for descending:-164.296, for ascending: -12.00707218611660e 16 | master_date= 20180128 17 | master_PRM = S1_20180128_ALL_F2 18 | suffix = F2 19 | tiff_id = 005 20 | type_data = dual 21 | # OPTION: single | dual | mix 22 | ############################################################################ 23 | -------------------------------------------------------------------------------- /cut_SM.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | inputfile=$1 4 | region=$2 5 | raw=$3 6 | 7 | rm re_*.grd im_*.grd 8 | [ -d crop_SM ] && echo "Directory crop exists" || mkdir crop_SM 9 | 10 | shopt -s extglob 11 | IFS=":" 12 | while read master slave 13 | do 14 | echo "cut $master"_"$slave grd files to size area" 15 | master_id=$(grep SC_clock_start $raw/$master.PRM | awk '{printf("%d",int($3))}') 16 | slave_id=$(grep SC_clock_start $raw/$slave.PRM | awk '{printf("%d",int($3))}') 17 | gmt grdmath real_$master_id"_""$slave_id".grd FLIPUD = tmp.grd=bf 18 | gmt grdsample tmp.grd -T -Gtmp.grd 19 | gmt grdcut tmp.grd -R$region -Gre_$master_id"_""$slave_id".grd=bf 20 | gmt grdmath imag_$master_id"_""$slave_id".grd FLIPUD = tmp.grd=bf 21 | gmt grdsample tmp.grd -T -Gtmp.grd 22 | gmt grdcut tmp.grd -R$region -Gim_$master_id"_""$slave_id".grd=bf 23 | mv im_$master_id"_""$slave_id".grd re_$master_id"_""$slave_id".grd crop_SM/. 24 | done < $inputfile 25 | rm tmp.grd 26 | -------------------------------------------------------------------------------- /cut_sbas.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | inputfile=$1 4 | region=$2 5 | raw=$3 6 | 7 | rm re_*.grd im_*.grd 8 | [ -d crop_SB ] && echo "Directory crop exists" || mkdir crop_SB 9 | 10 | shopt -s extglob 11 | IFS=":" 12 | while read master slave 13 | do 14 | echo "cut $master"_"$slave grd files to size area" 15 | master_id=$(grep SC_clock_start $raw/$master.PRM | awk '{printf("%d",int($3))}') 16 | slave_id=$(grep SC_clock_start $raw/$slave.PRM | awk '{printf("%d",int($3))}') 17 | gmt grdmath real_$master_id"_""$slave_id".grd FLIPUD = tmp.grd=bf 18 | gmt grdsample tmp.grd -T -Gtmp.grd 19 | gmt grdcut tmp.grd -R$region -Gre_$master_id"_""$slave_id".grd=bf 20 | gmt grdmath imag_$master_id"_""$slave_id".grd FLIPUD = tmp.grd=bf 21 | gmt grdsample tmp.grd -T -Gtmp.grd 22 | gmt grdcut tmp.grd -R$region -Gim_$master_id"_""$slave_id".grd=bf 23 | mv im_$master_id"_""$slave_id".grd re_$master_id"_""$slave_id".grd crop_SB/. 24 | done < $inputfile 25 | rm tmp.grd 26 | -------------------------------------------------------------------------------- /fix_pscands_SM.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # bugs; fix matrix on pscands1.ll and pscands.hgt 4 | # go to PS dir 5 | 6 | echo -n "How many patches do you have? " 7 | read n 8 | 9 | for (( c=1; c<=$n; c++ )) 10 | do 11 | cd cands_SM_$c 12 | 13 | # Get the difference dispersion index for PS candidates 14 | gmt grd2xyz cands.grd -s > cands.dat 15 | gmt gmtconvert cands.dat -o2 > pscands.1.da 16 | awk '{printf("%d %d %d\n", NR,$2,$1)}' cands.dat > pscands.1.ij 17 | 18 | # Retrieve lon/lat for PS candidates 19 | ln -s ../trans.dat . 20 | ln -s ../dem.grd . 21 | gmt grd2xyz cands_old.grd -s > cands_old.dat 22 | proj_ra2ll_ascii.csh trans.dat cands_old.dat cands.ll.dat 23 | rm -f ralt.grd raln.grd 24 | gmt gmtconvert cands.ll.dat -o0,1 -bos > pscands.1.ll 25 | gmt grdtrack cands.ll.dat -Gdem.grd -Z -nb -bos > pscands.1.hgt 26 | cp -f pscands.1.ij ../PATCH_$c/. 27 | cp -f pscands.1.ll ../PATCH_$c/. 28 | cp -f pscands.1.hgt ../PATCH_$c/. 29 | rm -f cands.ll.dat cands.dat cands_old.dat pscands* ralt raln 30 | cd .. 31 | 32 | done 33 | 34 | echo " " 35 | echo "$n PATCHES have been fixed" 36 | -------------------------------------------------------------------------------- /fix_pscands_SB.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # bugs; fix matrix on pscands1.ll and pscands.hgt 4 | # go to PS dir 5 | 6 | echo -n "How many patches do you have? " 7 | read n 8 | 9 | for (( c=1; c<=$n; c++ )) 10 | do 11 | cd ../cands_$c 12 | 13 | # Get the difference dispersion index for PS candidates 14 | gmt grd2xyz cands.grd -s > cands.dat 15 | gmt gmtconvert cands.dat -o2 > pscands.1.da 16 | awk '{printf("%d %d %d\n", NR,$2,$1)}' cands.dat > pscands.1.ij 17 | 18 | # Retrieve lon/lat for PS candidates 19 | ln -s ../trans.dat . 20 | ln -s ../dem.grd . 21 | gmt grd2xyz cands_old.grd -s > cands_old.dat 22 | proj_ra2ll_ascii.csh trans.dat cands_old.dat cands.ll.dat 23 | rm -f ralt.grd raln.grd 24 | gmt gmtconvert cands.ll.dat -o0,1 -bos > pscands.1.ll 25 | gmt grdtrack cands.ll.dat -Gdem.grd -Z -nb -bos > pscands.1.hgt 26 | cp -f pscands.1.ij ../SMALL_BASELINES/PATCH_$c/. 27 | cp -f pscands.1.ll ../SMALL_BASELINES/PATCH_$c/. 28 | cp -f pscands.1.hgt ../SMALL_BASELINES/PATCH_$c/. 29 | rm -f cands.ll.dat cands.dat cands_old.dat pscands* ralt raln 30 | cd .. 31 | cd SMALL_BASELINES 32 | 33 | done 34 | 35 | echo " " 36 | echo "$n PATCHES have been fixed" 37 | -------------------------------------------------------------------------------- /combination.c: -------------------------------------------------------------------------------- 1 | #include 2 | // N.Isya 2017.11.01 3 | 4 | int main (int argc, char **argv, int *arr) 5 | { 6 | //remove dummy result 7 | char filename[] = "result_combination.txt"; 8 | remove(filename); 9 | 10 | FILE *indate, *result_combination; 11 | //read date file 12 | indate = fopen(argv[1],"r+"); 13 | 14 | if (indate == NULL) { 15 | printf("Couldn't open the file."); 16 | return 1; 17 | } 18 | 19 | char tmp1[200]; 20 | int k; 21 | k=0; 22 | while(fscanf(indate, "%s", &tmp1[0])) 23 | { 24 | if (feof(indate)) break; 25 | arr[k]=atoi(tmp1); 26 | k=k+1; 27 | } 28 | printf ("number of dates = %i \n", k); 29 | 30 | 31 | //make simple combination and write on file 32 | result_combination = fopen("result_combination.txt","a"); 33 | //int arr[] = {1, 2, 3}; 34 | int i,j,*data; 35 | data=arr; 36 | for (i=0; i tmp 18 | BPR=$(grep B_perpendicular tmp | awk '{print $3}') 19 | BPR2=${BPR%.*} 20 | rm -f tmp 21 | 22 | cd $dir_path 23 | 24 | #calculate temporal baseline from combination 25 | master_ts=$(date -d "$master" '+%s') 26 | slave_ts=$(date -d "$date_acq" '+%s') 27 | temporal=$(echo "scale=0; ( $slave_ts - $master_ts)/(60*60*24)" | bc) 28 | 29 | #make parameter baseline 30 | echo $master $date_acq $temporal $BPR >> temp_bperp_combination_SM.txt 31 | if [ "$master" = "$date_acq" ]; then 32 | echo "Exclude $master - $master line" 33 | else 34 | echo "write intf_SM.in" 35 | echo "S1_"$master"_ALL_"$suffix":S1_"$date_acq"_ALL_"$suffix"" >> intf_SM.in 36 | fi 37 | 38 | done < $1 39 | -------------------------------------------------------------------------------- /mt_extract_info_gmtsar_SB: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Extract info from various files for use by StaMPS 5 | # 6 | # make sure you have (files): intf_SB_list , date_dsc_no_master.txt 7 | 8 | raw=$1 9 | raw_orig=$2 10 | topo=$3 11 | SLC=$4 12 | heading=$5 13 | master_date=$6 14 | 15 | SLC_OSF="1" # check if oversampled or not 16 | echo $SLC_OSF > slc_osfactor.1.in # put oversampling factor to file 17 | 18 | # Create other input files for PS SBAS candidates, make sure folder stack/PS has been processed, if not: 19 | #cp ../../bperp.1.in . 20 | awk '{printf("%0.4f\n", $5)}' $raw_orig/baseline_table.dat | sed '1d' > bperp.1.in 21 | #cp ../../day.1.in . 22 | cp date_no_master.txt day.1.in 23 | #cp ../../master_day.1.in . 24 | echo "$master_date" > master_day.1.in #put your date of super master here 25 | 26 | rm -f ifgday.1.in 27 | cat intf_SB_list.in | while read date_master date_slave 28 | do 29 | echo $date_master $date_slave >> ifgday.1.in 30 | done 31 | 32 | echo $heading > heading.1.in # for Sentinel-1 ASC: "-12.00707218611660e" 33 | cp $raw/*LED . 34 | cp $raw/*.PRM . 35 | cp $topo/master.PRM . 36 | ln -s -f $topo/trans.dat . 37 | ln -s -f $topo/dem.grd . 38 | ln -s -f $SLC/scatter_SB.grd . 39 | grep radar_wavelength $topo/master.PRM | awk '{print $3}' > lambda.1.in # in meters 40 | -------------------------------------------------------------------------------- /mt_extract_info_gmtsar_SM: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Extract info from various files for use by StaMPS 5 | # 6 | # make sure you have (files): intf_SM_list , date_dsc_no_master.txt 7 | 8 | raw=$1 9 | raw_orig=$2 10 | topo=$3 11 | heading=$4 12 | master_date=$5 13 | 14 | SLC_OSF="1" # check if oversampled or not 15 | echo $SLC_OSF > slc_osfactor.1.in # put oversampling factor to file 16 | 17 | # Create other input files for PS candidates 18 | if [ -f bperp.1.in ]; then 19 | echo "File bperp.1.in exists." 20 | else 21 | echo "File bperp.1.in does not exist." 22 | awk '{printf("%0.4f\n", $5)}' $raw_orig/baseline_table.dat | sed '1d' > bperp.1.in 23 | cp date_no_master.txt day.1.in 24 | echo "$master_date" > master_day.1.in 25 | grep radar_wavelength $topo/master.PRM | awk '{print $3}' > lambda.1.in # in meters 26 | fi 27 | 28 | #awk '{print substr($0,4,8)}' baseline_info.dat > day.1.in 29 | #awk '{printf("%d\n", $1)}' baseline_info.dat > day.1.in 30 | #awk '{print $3}' list > day.1.in 31 | #echo "19930112" > master_day.1.in 32 | 33 | echo $heading > heading.1.in # for Sentinel-1 ASC: "-12.00707218611660e" 34 | cp $raw/*LED . 35 | cp $raw/*.PRM . 36 | cp $topo/master.PRM . 37 | ln -s -f $topo/trans.dat . 38 | ln -s -f $topo/dem.grd . 39 | ln -s -f $raw/scatter_SM.grd . 40 | -------------------------------------------------------------------------------- /devide_region.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | region=$1 4 | R=$2 5 | A=$3 6 | ov_R=$4 7 | ov_A=$5 8 | 9 | x2=$(echo $region $ov_R | sed -r 's/[/]+/\t/g' | cut -f 2 | awk '{print $1}') 10 | x1=$(echo $region | sed -r 's/[/]+/\t/g' | cut -f 1 | awk '{print $1}') 11 | y2=$(echo $region $ov_A | sed -r 's/[/]+/\t/g' | cut -f 4 | awk '{print $1}') 12 | y1=$(echo $region | sed -r 's/[/]+/\t/g' | cut -f 3 | awk '{print $1}') 13 | 14 | range_x=$(( $x2-$x1+1 )); echo "width = "$range_x 15 | range_y=$(( $y2-$y1+1 )); echo "length = "$range_y 16 | echo $range_x > width.txt 17 | echo $range_y > len.txt 18 | shift_x=$(expr $range_x / $R); echo "width range = "$shift_x 19 | shift_y=$(expr $range_y / $A); echo "length azimuth = "$shift_y 20 | #x1=$(( $x1-50 )) 21 | #y1=$(( $y1-50 )) 22 | num=1 23 | rm -f -r PATCH.loc PATCH_* 24 | 25 | # create patch.in and patch.noover.in 26 | echo " " 27 | stamps_reg.csh $range_x $range_y $R $A $ov_R $ov_A 28 | echo " " 29 | 30 | # create PATCH.loc 31 | 32 | n=1 33 | shopt -s extglob 34 | IFS=" " 35 | while read start_rg end_rg start_az end_az 36 | do 37 | #if [ $i == 1 ]; then 38 | x1_coor=$(( $x1+$start_rg-1 )) 39 | x2_coor=$(( $x1_coor+($end_rg-$start_rg) )) 40 | y1_coor=$(( $y1+$start_az-1 )) 41 | y2_coor=$(( $y1_coor+($end_az-$start_az) )) 42 | echo $x1_coor/$x2_coor/$y1_coor/$y2_coor >> PATCH.loc 43 | #else 44 | #x1_coor=$(( $x2_coor+$start_rg-1 )) 45 | 46 | done < patch_all.in 47 | -------------------------------------------------------------------------------- /prep_orb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ###################################################################### 4 | # 02 5 | # script to prepare the precise orbit ephemeris (POEORB) 6 | # GMT5SAR processing for sentinel1A/B 7 | # 2017.02.28 "Noorlaila Hayati" 8 | # email: n.isya@tu-braunschweig.de or noorlaila@geodesy.its.ac.id 9 | ###################################################################### 10 | 11 | sen_orbit=$1 12 | raw_org=$2 13 | orb=$3 14 | 15 | dir_path=$(pwd) 16 | #rm -f data_orb_$orb.txt 17 | rm -f data_$orb.in 18 | rm -f -r $raw_org/aux_poeorb 19 | 20 | shopt -s extglob 21 | IFS=" " 22 | while read dataname date_aqc 23 | do 24 | type=$(echo $dataname | awk '{print substr ($0, 0, 3)}') 25 | if [ $type = "S1A" ]; then 26 | echo "Date: $date_aqc | go to S1A POE" 27 | cd $sen_orbit/S1A 28 | elif [ $type = "S1B" ]; then 29 | echo "Date: $date_aqc | go to S1B POE" 30 | cd $sen_orbit/S1B 31 | else 32 | echo "$type is unknown" 33 | fi 34 | yesterday=$( date -d "${date_aqc} -1 days" +'%Y%m%d' ) 35 | orb_fix=$(grep -r -l V"$yesterday"T | head -1) 36 | ln -s $sen_orbit/"$type"/"$orb_fix" $raw_org/. 37 | #cd $raw_org 38 | #ls *.EOF > data_orb.txt 39 | #mv data_orb.txt $dir_path 40 | 41 | #write data.in 42 | cd $raw_org 43 | tiffname=$(find -name "*$date_aqc*.tiff" -print | sed 's/^..//' | sed -e 's/\.tiff$//') 44 | cd $dir_path 45 | echo "$tiffname":"$orb_fix" >> data_$orb.in 46 | 47 | done < data_"$orb"_grub.txt 48 | 49 | -------------------------------------------------------------------------------- /prep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ###################################################################### 4 | # 03 5 | # script to prepare product information (.xml) combined to auxilary calibration 6 | # GMT5SAR processing for sentinel1A/B 7 | # 2017.01.30 "Noorlaila Hayati" 8 | # email: n.isya@tu-braunschweig.de or noorlaila@geodesy.its.ac.id 9 | ###################################################################### 10 | 11 | orb=$1 12 | dir_path=$(pwd) 13 | 14 | if [[ ! -d xml_origin ]]; then 15 | mkdir xml_origin 16 | cp *.xml $dir_path/xml_origin/. 17 | else 18 | echo "xml_origin already exists, OK" 19 | fi 20 | 21 | #make sure date_dsc_sp.txt & data_sp.in are exist 22 | paste -d\ date_"$orb"_sp.txt data_"$orb"_sp.in | sed -r 's/[:]+/ /g'> date_xml.in 23 | 24 | shopt -s extglob 25 | IFS=" " 26 | while read date_acq xml orb 27 | do 28 | 29 | type=$(echo $xml | awk '{print substr ($0, 0, 3)}') 30 | 31 | awk 'NR>1 {print $0}' < "$date_acq"_manifest.safe > tmp_file 32 | #cat $xml.xml tmp_file > ./"$xml"_a.xml #if there is no file aux_cal during the SAR images, use this command 33 | 34 | # define s1a or s1b 35 | if [ $type = "s1a" ]; then 36 | echo "Date: $date_acq | Use S1A aux cal" 37 | cat $xml.xml tmp_file s1a-aux-cal.xml > ./"$xml"_a.xml 38 | elif [ $type = "s1b" ]; then 39 | echo "Date: $date_acq | Use S1B aux cal" 40 | cat $xml.xml tmp_file s1b-aux-cal.xml > ./"$xml"_a.xml 41 | else 42 | echo "$type is unknown" 43 | fi 44 | rm tmp_file 45 | rm $xml.xml 46 | mv "$xml"_a.xml $xml.xml 47 | 48 | done < date_xml.in 49 | 50 | -------------------------------------------------------------------------------- /scihub_poeorb_download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | raw_org=$1 4 | orb=$2 5 | 6 | dir=$(pwd) 7 | 8 | mkdir -p tmp 9 | 10 | rm -f data_asc.in 11 | 12 | shopt -s extglob 13 | IFS=" " 14 | while read dataname date_aqc 15 | do 16 | 17 | type=$(echo $dataname | awk '{print substr ($0, 1, 3)}') #($0, 0, 3)}' 18 | cd tmp 19 | date_tmp=$(date '+%C%y%m%d' -d"$date_aqc + 20 day") 20 | year=$(echo $date_aqc | awk '{print substr($0,1,4)}') 21 | month=$(echo $date_aqc | awk '{print substr($0,5,2)}') 22 | day=$(echo $date_aqc | awk '{print substr($0,7,2)}') 23 | 24 | #anticipate for the first day of month 25 | if [ $day == 01 ]; then 26 | yesterday=$( date -d "${date_aqc} -1 days" +'%Y%m%d') 27 | lastmonth=$( echo $yesterday | awk '{print substr($0,5,2)}') 28 | month=$lastmonth 29 | fi 30 | 31 | #find list EOF name in the online directory 32 | wget --no-remove-listing "http://step.esa.int/auxdata/orbits/Sentinel-1/POEORB/$type/$year/$month" 33 | grep '' $month | tail -n +2 | cut -d'>' -f7 | cut -d'<' -f1 > list_tmp 34 | EOF_name=$(grep "$type"_OPER_AUX_POEORB_OPOD_$date_tmp list_tmp | head -n 1) 35 | rm $month 36 | 37 | # download POE 38 | wget -r -l1 -nd "http://step.esa.int/auxdata/orbits/Sentinel-1/POEORB/$type/$year/$month/$EOF_name" --no-parent 39 | unzip -j $EOF_name 40 | rm $EOF_name 41 | #orb_fix=$(ls -1 "$type"*.EOF) 42 | orb_fix=$(echo "${EOF_name%.*}") 43 | 44 | echo "put $orb_fix in raw_orig" 45 | #mv $orb_fix $raw_org/. 46 | # fixed by andretheronsa 47 | find -name "$type*.EOF" -exec mv '{}' $raw_org/. \; 48 | 49 | #write data.in 50 | cd $raw_org 51 | tiffname=$(find -name "*$date_aqc*.tiff" -print | sed 's/^..//' | sed -e 's/\.tiff$//') 52 | cd $dir 53 | echo "$tiffname":"$orb_fix" >> data_$orb.in 54 | 55 | done < data_"$orb"_grub.txt 56 | 57 | rm -f -r tmp 58 | -------------------------------------------------------------------------------- /stamps_reg.csh: -------------------------------------------------------------------------------- 1 | #!/bin/csh -f 2 | 3 | # get from mt_prep (STAMPS) script 4 | 5 | rm -f patch_all.in 6 | 7 | set width = $1 8 | set length = $2 9 | set prg = $3 10 | set paz = $4 11 | set overlap_rg = $5 12 | set overlap_az = $6 13 | 14 | 15 | @ width_p = $width / $prg 16 | echo $width_p 17 | @ length_p = $length / $paz 18 | echo $length_p 19 | set irg = 0 20 | set iaz = 0 21 | set ip = 0 22 | while ($irg < $prg) 23 | @ irg = $irg + 1 24 | while ($iaz < $paz) 25 | @ iaz = $iaz + 1 26 | @ ip = $ip + 1 27 | @ start_rg1 = $width_p * ($irg - 1) + 1 28 | @ start_rg = $start_rg1 - $overlap_rg 29 | if ($start_rg < 1) then 30 | set start_rg = 1 31 | endif 32 | @ end_rg1 = $width_p * $irg 33 | @ end_rg = $end_rg1 + $overlap_rg 34 | if ($end_rg > $width) then 35 | @ end_rg = $width 36 | endif 37 | @ start_az1 = $length_p * ($iaz - 1) + 1 38 | @ start_az = $start_az1 - $overlap_az 39 | if ($start_az < 1) then 40 | set start_az = 1 41 | endif 42 | @ end_az1 = $length_p * $iaz 43 | @ end_az = $end_az1 + $overlap_az 44 | 45 | if ($end_az > $length) then 46 | @ end_az = $length 47 | endif 48 | 49 | if (! -e PATCH_$ip) then 50 | mkdir PATCH_$ip 51 | endif 52 | echo $start_rg $end_rg $start_az $end_az 53 | echo $start_rg $end_rg $start_az $end_az >> patch_all.in 54 | cd PATCH_$ip 55 | echo $start_rg > patch.in 56 | echo $end_rg >> patch.in 57 | echo $start_az >> patch.in 58 | echo $end_az >> patch.in 59 | echo $start_rg1 > patch_noover.in 60 | echo $end_rg1 >> patch_noover.in 61 | echo $start_az1 >> patch_noover.in 62 | echo $end_az1 >> patch_noover.in 63 | cd .. 64 | end 65 | set iaz = 0 66 | end 67 | -------------------------------------------------------------------------------- /mt_prep_gmtsar_SM: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Creator: Xiaopeng Tong, David Sandwell 4 | # Date: July 4th 2013 5 | # Modified by 6 | # NI, 07.10.2019 (noorlaila@geodesy.its.ac.id) 7 | # mt_prep gmtsar for SM configuration 8 | 9 | region=$1 10 | R=$2 11 | A=$3 12 | ov_R=$4 13 | ov_A=$5 14 | threshold=$6 15 | master_date=$7 16 | suffix=$8 17 | heading=$9 18 | 19 | ################# grap directory path from param_dir.txt ############ 20 | crop_SM=$(grep crop_SM param_dir.txt | sed 's/^.*= //') 21 | raw=$(grep raw_data param_dir.txt | sed 's/^.*= //') 22 | raw_orig=$(grep raw_orig param_dir.txt | sed 's/^.*= //') 23 | topo=$(grep topo param_dir.txt | sed 's/^.*= //') 24 | SLC=$(grep SLC param_dir.txt | sed 's/^.*= //') 25 | ##################################################################### 26 | 27 | 28 | # file input (automatic): 29 | # date_no_master.txt 30 | # intf_SM_list.in 31 | 32 | rm -r -f patch_SM cands_SM_* 33 | mkdir patch_SM 34 | cd patch_SM 35 | devide_region.sh $region $R $A $ov_R $ov_A 36 | cd .. 37 | 38 | echo "gmtsar" > processor.txt 39 | matlab -nojvm -nosplash -nodisplay < $STAMPS/matlab/ps_parms_initial.m > ps_parms_initial.log 40 | 41 | rm -r -f PATCH_* 42 | ln -f -s $topo/master.PRM . 43 | 44 | # read azimuth heading angle from the master image 45 | if [ $heading == auto ]; then 46 | heading=$(grep platformHeading $raw_orig/*$master_date*.xml | awk -F"[>||<]" '{print $3}') 47 | fi 48 | 49 | p=1 50 | while read region 51 | do 52 | 53 | mt_extract_info_gmtsar_SM $raw $raw_orig $topo $heading $master_date 54 | mt_extract_cands_gmtsar_SM $crop_SM $threshold $region $suffix 55 | 56 | mkdir -p cands_SM_$p 57 | mv cands_old.grd cands_SM_"$p"/. 58 | mv cands0.grd cands_SM_"$p"/. 59 | mv cands.grd cands_SM_"$p"/. 60 | 61 | patch=$(echo PATCH_$p) 62 | mkdir $patch 63 | mv pscands* $patch/. 64 | ln -s -f $PWD/bperp.1.in $patch/. 65 | cd $patch 66 | correct_forum 67 | rm -f swap_pixels.m 68 | cd .. 69 | (( p++ )) 70 | done < patch_SM/PATCH.loc 71 | 72 | rsync -av patch_SM/PATCH_* . 73 | cp patch_SM/width.txt . 74 | cp patch_SM/len.txt . 75 | #ln -f -s ../*.in . 76 | ls -d PATCH_* > patch.list 77 | cd .. 78 | 79 | -------------------------------------------------------------------------------- /mt_prep_gmtsar_SB: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # NI, 08.02.2018 (noorlaila@geodesy.its.ac.id) 4 | # mt_prep gmtsar for SBAS configuration 5 | 6 | region=$1 7 | R=$2 8 | A=$3 9 | ov_R=$4 10 | ov_A=$5 11 | threshold=$6 12 | master_date=$7 13 | suffix=$8 14 | heading=$9 15 | 16 | ################# grap directory path from param_dir.txt ############ 17 | crop_SB=$(grep crop_SB param_dir.txt | sed 's/^.*= //') 18 | raw=$(grep raw_data param_dir.txt | sed 's/^.*= //') 19 | raw_orig=$(grep raw_orig param_dir.txt | sed 's/^.*= //') 20 | topo=$(grep topo param_dir.txt | sed 's/^.*= //') 21 | SLC=$(grep SLC param_dir.txt | sed 's/^.*= //') 22 | ##################################################################### 23 | 24 | # file input (automatic): 25 | # date_no_master.txt 26 | # intf_SB_list.in 27 | 28 | rm -r -f SMALL_BASELINES patch_reg cands_* 29 | mkdir patch_reg 30 | cd patch_reg 31 | devide_region.sh $region $R $A $ov_R $ov_A 32 | cd .. 33 | 34 | mkdir SMALL_BASELINES 35 | cd SMALL_BASELINES 36 | 37 | echo "gmtsar" > processor.txt 38 | matlab -nojvm -nosplash -nodisplay < $STAMPS/matlab/sb_parms_initial.m > sb_parms_initial.log 39 | 40 | cd .. 41 | rm -r -f SMALL_BASELINES/PATCH_* 42 | ln -f -s $topo/master.PRM . 43 | 44 | # read azimuth heading angle from the master image 45 | if [ $heading == auto ]; then 46 | heading=$(grep platformHeading $raw_orig/*$master_date*.xml | awk -F"[>||<]" '{print $3}') 47 | fi 48 | 49 | p=1 50 | while read region 51 | do 52 | 53 | mt_extract_info_gmtsar_SB $raw $raw_orig $topo $SLC $heading $master_date 54 | mt_extract_cands_gmtsar_SB $crop_SB $threshold $region $suffix 55 | 56 | mkdir -p cands_$p 57 | mv cands_old.grd cands_"$p"/. 58 | mv cands0.grd cands_"$p"/. 59 | mv cands.grd cands_"$p"/. 60 | 61 | patch=$(echo PATCH_$p) 62 | mkdir SMALL_BASELINES/$patch 63 | mv pscands* SMALL_BASELINES/$patch/. 64 | ln -s -f $PWD/ifgday.1.in SMALL_BASELINES/$patch/. 65 | cd SMALL_BASELINES/$patch 66 | correct_forum_sbas 67 | rm -f swap_pixels.m 68 | cd ../.. 69 | (( p++ )) 70 | done < patch_reg/PATCH.loc 71 | 72 | rsync -av patch_reg/PATCH_* SMALL_BASELINES/. 73 | cp patch_reg/width.txt SMALL_BASELINES/. 74 | cp patch_reg/len.txt SMALL_BASELINES/. 75 | cd SMALL_BASELINES 76 | ln -f -s ../*.in . 77 | ls -d PATCH_* > patch.list 78 | cd .. 79 | 80 | -------------------------------------------------------------------------------- /intf_kml.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | inputfile=$1 4 | raw=$2 5 | topo=$3 6 | region=$4 7 | 8 | shopt -s extglob 9 | IFS=":" 10 | while read master slave 11 | do 12 | 13 | mkdir view 14 | 15 | master_id=$(grep SC_clock_start $raw/$master.PRM | awk '{printf("%d",int($3))}') 16 | slave_id=$(grep SC_clock_start $raw/$slave.PRM | awk '{printf("%d",int($3))}') 17 | ln -s $raw/"$master".SLC . 18 | ln -s $raw/"$master".LED . 19 | ln -s $raw/"$slave".SLC . 20 | ln -s $raw/"$slave".LED . 21 | rm -f imag.grd real.grd 22 | ln -s real_$master_id"_"$slave_id.grd real.grd 23 | ln -s imag_$master_id"_"$slave_id.grd imag.grd 24 | 25 | # do filter and create phase & amplitude 26 | # recommended range decimation to be 8, azimuth decimation to be 2 for S1A 27 | filter.csh $raw/"$master".PRM $raw/"$slave".PRM 200 1 8 2 28 | # project to global coordinate 29 | proj_ra2ll.csh trans.dat phase.grd phase_ll.grd 30 | proj_ra2ll.csh trans.dat display_amp.grd amp_ll.grd 31 | proj_ra2ll.csh trans.dat corr.grd corr_ll.grd 32 | 33 | # convert to kml data (Google Earth) 34 | grd2kml.csh amp_ll display_amp.cpt 35 | grd2kml.csh corr_ll corr.cpt 36 | 37 | gmt grdimage phase_ll.grd -JX6 -Cphase.cpt -B0.5WesN -P -Y3 -R$region --MAP_FRAME_TYPE=inside > phase_ll.ps 38 | gmt psconvert phase_ll.ps -TG -W+k+t"phase_$master"_"$slave"+l256/-1 -V -E526 39 | gmt grdimage amp_ll.grd -JX6 -Cdisplay_amp.cpt -B0.5WesN -P -Y3 -R$region --MAP_FRAME_TYPE=inside > amp_ll.ps 40 | gmt psconvert amp_ll.ps -TG -W+k+t"amp_$master"_"$slave"+l256/-1 -V -E526 41 | 42 | mkdir view/view_"$master"_"$slave" 43 | mv display_amp.grd view/view_"$master"_"$slave"/. 44 | mv phase_ll.grd view/view_"$master"_"$slave"/. 45 | mv amp_ll.grd view/view_"$master"_"$slave"/. 46 | mv amp_ll.png view/view_"$master"_"$slave"/. 47 | mv amp_ll.kml view/view_"$master"_"$slave"/. 48 | mv phase_ll.png view/view_"$master"_"$slave"/. 49 | mv phase_ll.kml view/view_"$master"_"$slave"/. 50 | mv corr.grd view/view_"$master"_"$slave"/. 51 | mv corr.pdf view/view_"$master"_"$slave"/. 52 | mv corr_ll.kml view/view_"$master"_"$slave"/. 53 | mv phase_ll.ps view/view_"$master"_"$slave"/. 54 | mv amp_ll.ps view/view_"$master"_"$slave"/. 55 | 56 | #rm -f phase_ll.grd amp_ll.grd 57 | rm -f amp1.grd amp2.grd filtcorr.grd mask.grd phasefilt.grd phasefilt.pdf phase.grd phase_ll.ps phase.pdf raln.grd ralt.grd realfilt.grd amp.grd imagfilt.grd ijdec 58 | rm -f "$master".SLC "$master".LED "$slaver".SLC "$slave".LED 59 | done < $inputfile 60 | -------------------------------------------------------------------------------- /prep_dir.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ###################################################################### 4 | # 01 5 | # script to prepare the directory 6 | # GMT5SAR processing for sentinel1A/B 7 | # 2017.01.30 "Noorlaila Hayati" 8 | # email: n.isya@tu-braunschweig.de or noorlaila@geodesy.its.ac.id 9 | ###################################################################### 10 | 11 | raw_path=$1 12 | suffix_tiff=$2 13 | type_data=$3 14 | orb=$4 15 | 16 | mkdir batch_"$orb" 17 | cd batch_"$orb" 18 | mkdir raw_orig 19 | cd .. 20 | ls "$raw_path" -1 | sed -e 's/\.zip$//' > data_orb_"$orb".txt 21 | ls "$raw_path" | awk '{print substr($0,18,8)}' > date_"$orb".txt 22 | paste -d\ data_orb_"$orb".txt date_"$orb".txt > data_"$orb"_grub.txt 23 | # sorted data 24 | sort -k 2 data_"$orb"_grub.txt > data_"$orb"_grub_tmp.txt 25 | mv data_"$orb"_grub_tmp.txt data_"$orb"_grub.txt 26 | sort -k 1 date_"$orb".txt > date_"$orb"_tmp.txt 27 | mv date_"$orb"_tmp.txt date_"$orb".txt 28 | rm -f data_orb_"$orb".txt 29 | dir_path=$(pwd) 30 | suffix_tmp=$suffix_tiff 31 | 32 | shopt -s extglob 33 | IFS=" " 34 | while read name date 35 | do 36 | 37 | # identify Single or Dual Polarisation 38 | if [ $type_data == "mix" ]; then 39 | polar=$(echo $name | awk '{print substr ($0, 14, 3)}') 40 | if [ $polar == "SDV" ]; then 41 | i=$(expr $suffix_tiff + 3) 42 | suffix_tiff=$(printf "%03d" "$i") 43 | echo " TIFF number has changed $suffix_tiff , Dual Polarisation is identified" 44 | elif [ $polar == "SSV" ]; then 45 | suffix_tiff=$suffix_tmp 46 | echo " Keep TIFF number $suffix_tiff, Single Polarisation is identified" 47 | fi 48 | elif [ $type_data == "single" ]; then 49 | echo " TIFF number doesn't change, all data are Single Polarisation" 50 | elif [ $type_data == "dual" ]; then 51 | echo " TIFF number doesn't change, all data are Dual Polarisation" 52 | fi 53 | 54 | unzip "$raw_path"/"$name".zip "$name".SAFE/measurement/*"$suffix_tiff".tiff 55 | mv "$name".SAFE/measurement/*"$suffix_tiff".tiff $dir_path/batch_"$orb"/raw_orig/. 56 | unzip "$raw_path"/"$name".zip "$name".SAFE/manifest.safe 57 | mv "$name".SAFE/manifest.safe $dir_path/batch_"$orb"/raw_orig/"$date"_manifest.safe 58 | unzip "$raw_path"/"$name".zip "$name".SAFE/annotation/*"$suffix_tiff".xml 59 | mv "$name".SAFE/annotation/*"$suffix_tiff".xml $dir_path/batch_"$orb"/raw_orig/. 60 | rm -r -f $name.SAFE 61 | suffix_tiff=$suffix_tmp 62 | done < data_"$orb"_grub.txt 63 | 64 | 65 | cd $dir_path 66 | 67 | -------------------------------------------------------------------------------- /pair_config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ###################################################################### 4 | # 5 | # script to make master-slave configuration 6 | # based on temporal and perpendicular baseline 7 | # 2017.10.30 "Noorlaila Isya" 8 | # email: n.isya@tu-bs.de or noorlaila@geodesy.its.ac.id 9 | ###################################################################### 10 | 11 | if [[ $# -ne 5 ]]; then 12 | echo "" 13 | echo "Usage: pair_config.sh date_file temporal perpendicular PATH_PRM_file" 14 | echo "" 15 | echo " script to make master - slave configuration" 16 | echo "" 17 | echo " temporal = threshold number for temporal baseline (days), example : 100" 18 | echo " perpendicular = theshold number for spatial baseline (m), example : 100" 19 | echo "" 20 | echo " example : pair_config.sh date_asc.txt 100 100 /home/user/batch/raw" 21 | echo "" 22 | echo " format of date_asc.txt:" 23 | echo " 20160101" 24 | echo " 20160113" 25 | echo " 20160224" 26 | echo "" 27 | echo " output : " 28 | echo " - result_combination.txt (all of possibilties for master-slave pairs)" 29 | echo " - temp_bperp_combination.txt (+ with temporal & perp baseline parameters)" 30 | echo " - intf.in (to be used for intf_tops.csh)" 31 | echo "" 32 | exit 1 33 | fi 34 | 35 | infile=$1 36 | raw=$4 37 | suffix=$5 38 | 39 | 40 | combination $infile 41 | 42 | rm -f temp_bperp_combination_SB.txt intf_SB.in 43 | shopt -s extglob 44 | IFS=" " 45 | while read master slave 46 | do 47 | 48 | #calculate perpendicular baseline from combination 49 | dir=$(pwd) 50 | cd $raw 51 | echo S1_$master"_ALL_$suffix.PRM" S1_$slave"_ALL_$suffix.PRM" 52 | SAT_baseline S1_$master"_ALL_$suffix.PRM" S1_$slave"_ALL_$suffix.PRM" > tmp 53 | BPR=$(grep B_perpendicular tmp | awk '{print $3}') 54 | #BPR2=$(echo "scale=0; $BPR" | bc) 55 | BPR2=${BPR%.*} 56 | rm -f tmp 57 | 58 | cd $dir 59 | 60 | #calculate temporal baseline from combination 61 | master_ts=$(date -d "$master" '+%s') 62 | slave_ts=$(date -d "$slave" '+%s') 63 | temporal=$(echo "scale=0; ( $slave_ts - $master_ts)/(60*60*24)" | bc) 64 | 65 | #make parameter baseline 66 | if [ "$temporal" -lt $2 ] 67 | then 68 | if [ "$BPR2" -gt -$3 ] && [ "$BPR2" -lt $3 ] 69 | then 70 | echo "--Matching -- Write the data:" "S1_"$master"_ALL_"$suffix" S1_"$slave"_ALL_"$suffix"" $temporal $BPR 71 | echo $master $slave $temporal $BPR >> temp_bperp_combination_SB.txt 72 | echo "S1_"$master"_ALL_"$suffix":S1_"$slave"_ALL_"$suffix"" >> intf_SB.in 73 | fi 74 | fi 75 | 76 | done < result_combination.txt 77 | -------------------------------------------------------------------------------- /baseline_sen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # created by N.Isya 01.11.2017 4 | 5 | ################################################################### 6 | network=$5 7 | if [ $network = "SM" ]; then 8 | inputfile=temp_bperp_combination_SM.txt 9 | elif [ $network = "SB" ]; then 10 | inputfile=temp_bperp_combination_SB.txt 11 | else 12 | echo "--------------> Input: Network is unknown" 13 | fi 14 | dir_path=$(pwd) 15 | min=-150 #for y coordinate (baseline range) 16 | max=150 17 | raw_orig=$dir_path/raw_orig 18 | ################################################################### 19 | 20 | start_date=$1 #for x coordinate (date range) 21 | end_date=$2 22 | suffix=$3 23 | super_master=$4 24 | 25 | #create baseline_configuration.txt 26 | rm -f baseline_pair.ps base_config.txt 27 | year=$(echo "$super_master" | awk '{print substr($0,1,4)}') 28 | month=$(echo "$super_master" | awk '{print substr($0,5,2)}') 29 | day=$(echo "$super_master" | awk '{print substr($0,7,2)}') 30 | #echo "$year-$month-$day,0,S1A"$super_master"_ALL_F1" > base_config.txt 31 | 32 | shopt -s extglob 33 | IFS=" " 34 | number=1 35 | while read master slave temp bperp 36 | do 37 | 38 | cd $raw_orig 39 | baseline_table.csh S1_"$super_master"_ALL_"$suffix".PRM S1_"$master"_ALL_"$suffix".PRM GMT > table.gmt 40 | y_m=$(cat table.gmt | awk '{print $2}') 41 | baseline_table.csh S1_"$super_master"_ALL_"$suffix".PRM S1_"$slave"_ALL_"$suffix".PRM GMT > table.gmt 42 | y_s=$(cat table.gmt | awk '{print $2}') 43 | cd $dir_path 44 | year_m=$(echo "$master" | awk '{print substr($0,1,4)}') 45 | month_m=$(echo "$master" | awk '{print substr($0,5,2)}') 46 | day_m=$(echo "$master" | awk '{print substr($0,7,2)}') 47 | year_s=$(echo "$slave" | awk '{print substr($0,1,4)}') 48 | month_s=$(echo "$slave" | awk '{print substr($0,5,2)}') 49 | day_s=$(echo "$slave" | awk '{print substr($0,7,2)}') 50 | echo "#$number" >> base_config.txt 51 | echo "$year_m-$month_m-$day_m,$y_m,$master" >> base_config.txt 52 | echo "$year_s-$month_s-$day_s,$y_s,$slave" >> base_config.txt 53 | echo ">" >> base_config.txt 54 | (( number++ )) 55 | 56 | done < $inputfile 57 | 58 | # plot baseline using GMT 59 | 60 | gmt gmtset PS_PAGE_ORIENTATION=Landscape 61 | gmt gmtset FORMAT_DATE_IN yyyy-mm-dd FORMAT_DATE_MAP o FONT_ANNOT_PRIMARY +10p 62 | gmt gmtset FORMAT_TIME_PRIMARY_MAP abbreviated PS_CHAR_ENCODING ISOLatin1+ 63 | #gmtset FORMAT_DATE_OUT yyyy-mm-dd 64 | gmt psxy base_config.txt -R"$start_date"T/"$end_date"T/"$min"/"$max" -JX9i/6i -Bsx1Y -Bpxa3Of1o+l"Acqusition time" -Bpy50+l"Perpendicular Baseline (m)" -BWeSn+t"Sentinel-1 $network Network" -K -Wthinner > baseline_pair.ps 65 | gmt pstext base_config.txt -R -J -B -F+f7p,Helvetica,blue+jTL -O -K >> baseline_pair.ps 66 | gmt psxy base_config.txt -R -J -O -W -Si0.05i >> baseline_pair.ps 67 | -------------------------------------------------------------------------------- /mt_extract_cands_gmtsar_SM: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # extract data for SM candididate pixels 5 | # 6 | 7 | # Parameter (should be not changed) # 8 | crop_SM=$1 9 | threshold=$2 10 | region=$3 11 | suffix=$4 12 | ##################################### 13 | dir_path=$(pwd) 14 | 15 | 16 | gmt grdmath scatter_SM.grd $threshold LT 0 NAN scatter_SM.grd MUL = cands0.grd 17 | 18 | gmt grdsample -T cands0.grd -R$region -Gcands.grd 19 | cp cands.grd cands_old.grd 20 | gmt grdedit cands.grd -R$region 21 | 22 | input="cands.grd" 23 | width=`gmt grdinfo -C $input | awk '{print $10}'` 24 | echo $width > width.txt # range 25 | length=`gmt grdinfo -C $input | awk '{print $11}'` 26 | echo $length > len.txt # azimuth 27 | 28 | # Get the dispersion index for PS candidates 29 | gmt grd2xyz cands.grd -s > cands.dat 30 | gmt gmtconvert cands.dat -o2 > pscands.1.da 31 | awk '{printf("%d %d %d\n", NR,$2,$1)}' cands.dat > pscands.1.ij 32 | 33 | # Retrieve lon/lat for PS candidates 34 | gmt grd2xyz cands_old.grd -s > cands_old.dat 35 | proj_ra2ll_ascii.csh trans.dat cands_old.dat cands.ll.dat 36 | rm ralt.grd raln.grd 37 | gmt gmtconvert cands.ll.dat -o0,1 -bos > pscands.1.ll 38 | 39 | # Retrieve hgt for PS candidates 40 | gmt grdtrack cands.ll.dat -Gdem.grd -Z -nb -bos > pscands.1.hgt 41 | 42 | # Retrieve look angles 43 | gmt grdsample cands_old.grd -I50+/50+ -Gtmp.grd 44 | gmt grd2xyz tmp.grd | awk '{print $1,$2,1}' > tmp.xy 45 | proj_ra2ll_ascii.csh trans.dat tmp.xy tmp.ll 46 | #rm ralt.grd raln.grd 47 | awk '{printf("%f %f %d\n%f %f %d\n",$1,$2,0,$1,$2,1000)}' tmp.ll > tmp.llt 48 | ln -s ../topo/master.PRM . 49 | SAT_look master.PRM < tmp.llt > tmp.lltn 50 | gmt gmtmath -C5 -o5 tmp.lltn ACOS 180 MUL PI DIV = look_angle.1.in 51 | rm tmp.xy tmp.ll tmp.llt tmp.lltn 52 | 53 | rm -f list 54 | master_id=$(grep SC_clock_start master.PRM | awk '{printf("%d",int($3))}') 55 | cat date_no_master.txt | while read date; do slave_id=$(grep SC_clock_start "S1_"$date"_ALL_"$suffix"".PRM | awk '{printf("%d",int($3))}'); echo $master_id"_"$slave_id "S1_"$date"_ALL_"$suffix"" $date >> list; done 56 | 57 | # Retrieve perpendicular baseline for each interferogram 58 | cat list | while read name prm date 59 | do 60 | #cp ../raw/*PRM . 61 | SAT_baseline master.PRM $prm.PRM >> $prm.PRM 62 | bperp $prm.PRM tmp.grd bperp.grd 63 | gmt grd2xyz bperp.grd | awk '{print $3}' > bperp0 64 | value=`grep earth_radius $prm.PRM | awk '{print $3+1000}'` 65 | update_PRM.csh $prm.PRM earth_radius $value 66 | bperp $prm.PRM tmp.grd bperp.grd 67 | gmt grd2xyz bperp.grd | awk '{print $3}' > bperp1000 68 | paste bperp0 bperp1000 > tmp 69 | awk '{printf("%f\n%f\n", $1,$2)}' tmp > bperp_$date.1.in 70 | done 71 | rm tmp bperp0 bperp1000 bperp.grd tmp.grd 72 | 73 | # Retrieve phase for PS candidates 74 | rm pscands.1.ph 75 | if [ -d "$crop_SM" ]; then 76 | cd $crop_SM 77 | else 78 | cd .. 79 | fi 80 | cat $dir_path/list | while read name prm date 81 | do 82 | if [ -f "re_$name.grd" ]; then 83 | gmt grdtrack $dir_path/cands_old.dat -Gre_$name.grd -Z -bos >> $dir_path/pscands.1.ph 84 | gmt grdtrack $dir_path/cands_old.dat -Gim_$name.grd -Z -bos >> $dir_path/pscands.1.ph 85 | else 86 | gmt grdmath real_$name.grd FLIPUD = tmp_re.grd=bf 87 | gmt grdtrack $dir_path/cands_old.dat -Gtmp_re.grd -Z -bos >> $dir_path/pscands.1.ph 88 | gmt grdmath imag_$name.grd FLIPUD = tmp_im.grd=bf 89 | gmt grdtrack $dir_path/cands_old.dat -Gtmp_im.grd -Z -bos >> $dir_path/pscands.1.ph 90 | fi 91 | done 92 | cd $dir_path 93 | 94 | 95 | rm *.PRM *.LED 96 | #rm cands_old.grd cands0.grd cands.grd 97 | -------------------------------------------------------------------------------- /mt_extract_cands_gmtsar_SB: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # extract data for SB candidiate pixels 5 | # 6 | 7 | # make sure you have (files): list , date_no_master.txt , list_sbas (generate automatically) 8 | 9 | # Parameter (should be not changed) # 10 | crop_SB=$1 11 | threshold=$2 12 | region=$3 13 | suffix=$4 14 | ##################################### 15 | dir_path=$(pwd) 16 | 17 | gmt grdmath scatter_SB.grd $threshold LT 0 NAN scatter_SB.grd MUL = cands0.grd 18 | 19 | gmt grdsample -T cands0.grd -R$region -Gcands.grd 20 | cp cands.grd cands_old.grd 21 | gmt grdedit cands.grd -R$region 22 | 23 | input="cands.grd" 24 | width=`gmt grdinfo -C $input | awk '{print $10}'` 25 | echo $width > width.txt # range 26 | length=`gmt grdinfo -C $input | awk '{print $11}'` 27 | echo $length > len.txt # azimuth 28 | 29 | # Get the difference dispersion index for PS candidates 30 | gmt grd2xyz cands.grd -s > cands.dat 31 | gmt gmtconvert cands.dat -o2 > pscands.1.da 32 | awk '{printf("%d %d %d\n", NR,$2,$1)}' cands.dat > pscands.1.ij 33 | 34 | # Retrieve lon/lat for PS candidates 35 | gmt grd2xyz cands_old.grd -s > cands_old.dat 36 | proj_ra2ll_ascii.csh trans.dat cands_old.dat cands.ll.dat 37 | rm ralt.grd raln.grd 38 | gmt gmtconvert cands.ll.dat -o0,1 -bos > pscands.1.ll 39 | 40 | # Retrieve hgt for PS candidates 41 | gmt grdtrack cands.ll.dat -Gdem.grd -Z -nb -bos > pscands.1.hgt 42 | 43 | # Retrieve look angles 44 | gmt grdsample cands_old.grd -I50+/50+ -Gtmp.grd 45 | gmt grd2xyz tmp.grd | awk '{print $1,$2,1}' > tmp.xy 46 | proj_ra2ll_ascii.csh trans.dat tmp.xy tmp.ll 47 | #rm ralt.grd raln.grd 48 | awk '{printf("%f %f %d\n%f %f %d\n",$1,$2,0,$1,$2,1000)}' tmp.ll > tmp.llt 49 | SAT_look master.PRM < tmp.llt > tmp.lltn 50 | gmt gmtmath -C5 -o5 tmp.lltn ACOS 180 MUL PI DIV = look_angle.1.in 51 | awk '{printf("%0.4f\n", $1)}' look_angle.1.in > look_angle0.1.in 52 | rm look_angle.1.in 53 | mv look_angle0.1.in look_angle.1.in 54 | rm tmp.xy tmp.ll tmp.llt tmp.lltn 55 | 56 | # Retrieve perpendicular baseline for each interferogram 57 | # copy the calculation from PS folder 58 | 59 | # cp ../../bperp* . # uncomment if PS processing has been processed and comment following lines 60 | 61 | # or do 62 | #generate list, before modify date_asc.txt without date for master! 63 | 64 | if [ ! -f list ]; then 65 | 66 | master_id=$(grep SC_clock_start master.PRM | awk '{printf("%d",int($3))}') 67 | cat date_no_master.txt | while read date; do slave_id=$(grep SC_clock_start "S1_"$date"_ALL_"$suffix"".PRM | awk '{printf("%d",int($3))}'); echo $master_id"_"$slave_id "S1_"$date"_ALL_"$suffix"" $date >> list; done 68 | 69 | cat list | while read name prm date 70 | do 71 | SAT_baseline master.PRM $prm.PRM >> $prm.PRM 72 | bperp $prm.PRM tmp.grd bperp.grd 73 | gmt grd2xyz bperp.grd | awk '{print $3}' > bperp0 74 | value=`grep earth_radius $prm.PRM | awk '{print $3+1000}'` 75 | update_PRM.csh $prm.PRM earth_radius $value 76 | bperp $prm.PRM tmp.grd bperp.grd 77 | gmt grd2xyz bperp.grd | awk '{print $3}' > bperp1000 78 | paste bperp0 bperp1000 > tmp 79 | awk '{printf("%f\n%f\n", $1,$2)}' tmp > bperp_$date.1.in 80 | done 81 | fi 82 | rm tmp bperp0 bperp1000 bperp.grd tmp.grd 83 | 84 | # Retrieve phase for PS candidates 85 | rm -f pscands.1.ph 86 | 87 | if [ -d "$crop_SB" ]; then 88 | cd $crop_SB 89 | else 90 | cd .. 91 | fi 92 | identity=$(ls -1 im* | head -1 | awk '{print substr($0,4,15)}') 93 | if [ -f "re_$identity.grd" ]; then 94 | echo "re_$identity.grd exist" 95 | ls -1 im* | sed 's/im_//' | sed 's/.grd//' > $dir_path/list_sbas 96 | else 97 | echo "re_$identity.grd does not exist, use the original imag and real files" 98 | ls -1 imag* | sed 's/imag_//' | sed 's/.grd//' > $dir_path/list_sbas 99 | fi 100 | cat $dir_path/list_sbas | while read name 101 | do 102 | if [ -f "re_$name.grd" ]; then 103 | gmt grdtrack $dir_path/cands_old.dat -Gre_$name.grd -Z -bos >> $dir_path/pscands.1.ph 104 | gmt grdtrack $dir_path/cands_old.dat -Gim_$name.grd -Z -bos >> $dir_path/pscands.1.ph 105 | else 106 | gmt grdmath real_$name.grd FLIPUD = tmp_re.grd=bf 107 | gmt grdtrack $dir_path/cands_old.dat -Gtmp_re.grd -Z -bos >> $dir_path/pscands.1.ph 108 | gmt grdmath imag_$name.grd FLIPUD = tmp_im.grd=bf 109 | gmt grdtrack $dir_path/cands_old.dat -Gtmp_im.grd -Z -bos >> $dir_path/pscands.1.ph 110 | fi 111 | done 112 | cd $dir_path 113 | 114 | rm *.PRM *.LED 115 | #rm cands_old.grd cands0.grd cands.grd 116 | -------------------------------------------------------------------------------- /dispersion.csh: -------------------------------------------------------------------------------- 1 | #!/bin/csh -f 2 | 3 | # Amplitude dispersion from a stack of aligned SLCs 4 | 5 | # Creator: Xiaopeng Tong, David Sandwell 6 | # Date: July 4th 2013 7 | 8 | # input: PRM.list 9 | # output: amplitude dispersion 10 | 11 | # The principle: first calibrate each images by a weighting 12 | # factor then compute the mean amplitude M_A 13 | # and the standard deviation of the amplitude sig_A 14 | # then take the ratio of the M_A and sig_A 15 | 16 | # Reference: Lyons and Sandwell, Fault creep along the southern San Andreas from InSAR, permanent scatterers, and stacking, J. Geophys. Res., 108 (B1), 2047, doi:10.1029/ 2002JB001831 2003 17 | 18 | alias rm 'rm -f' 19 | 20 | if ($#argv != 3) then 21 | echo "" 22 | echo "Usage: dispersion.csh PRM.list scatter.grd ///" 23 | echo "" 24 | echo " Amplitude dispersion from a stack of aligned SLCs" 25 | echo "" 26 | echo " PRM.list -- a list of PRM files of the aligned SLC" 27 | echo " scatter.grd -- output scattering coeffient grid" 28 | echo " /// — region of interests in radar coordinates" 29 | echo "" 30 | exit 1 31 | endif 32 | 33 | if (! -e $1) then 34 | echo "" 35 | echo "no input file found: $1" 36 | echo "" 37 | exit 1 38 | endif 39 | 40 | set list = $1 41 | set outgrd = $2 42 | set region = $3 43 | set filter = $GMTSAR/gmtsar/filters/gauss5x5 #gauss5x5 has better result 44 | #set filter = gauss5x3 45 | set namearray = 46 | set weightarray = 47 | 48 | 49 | echo "" 50 | echo "Start -- compute amplitude dispersion" 51 | echo "" 52 | 53 | # 54 | # conv to get amplitude of the SLCs and compute their sum and average 55 | # 56 | 57 | echo "compute amplitude from SLCs ..." 58 | @ num = 1 59 | foreach prm (`cat $list`) 60 | set name = `grep input_file $prm | awk '{print $3}' | sed 's/\.raw//'` 61 | set namearray = ($namearray $name) 62 | if (-e $prm) then 63 | if (! -e $name".grd") then 64 | echo "running conv on file $name" 65 | conv 1 1 $filter $prm $name".grd" 66 | gmt grdmath $name".grd" FLIPUD = $name".grd" 67 | endif 68 | # gmt grd2cpt $name".grd" -Cgray -Z -D > cpt 69 | gmt makecpt -Cgray -T1e-8/1e-7/1e-8 -Z > a.cpt 70 | gmt grdimage $name".grd" -Ca.cpt -JX6i -P -Xc -Yc -V -R0/6144/0/25200 -Bf2500a5000WSen > $name".ps" 71 | else 72 | echo "" 73 | echo "no PRM file found: $prm" 74 | echo "" 75 | exit 1 76 | endif 77 | gmt grdcut $name".grd" -R$region -Gtmp.grd 78 | mv tmp.grd $name".grd" 79 | if ($num == 1) then 80 | gmt grdmath $name".grd" = sum.grd 81 | else 82 | gmt grdmath sum.grd $name".grd" ADD = sumtmp.grd 83 | mv sumtmp.grd sum.grd 84 | endif 85 | @ num ++ 86 | end 87 | @ num -- 88 | gmt grdmath sum.grd $num DIV = ave.grd 89 | set avemean = `gmt grdinfo ave.grd -L2 -C | cut -f 12` 90 | echo $avemean 91 | # 92 | 93 | 94 | # 95 | # compute the M_A term 96 | # 97 | 98 | rm -f weightarray.txt 99 | echo "" 100 | echo "compute the M_A term ..." 101 | @ num = 1 102 | foreach name ($namearray) 103 | echo $name 104 | set ampmean = `gmt grdinfo $name".grd" -L2 -C | cut -f 12` 105 | set weight = `echo $ampmean $avemean | awk '{print $1/$2}'` 106 | echo $weight 107 | set weightarray = ($weightarray $weight) 108 | echo $weightarray >> weightarray.txt 109 | gmt grdmath $name".grd" $weight DIV = tmp.grd 110 | if ($num == 1) then 111 | gmt grdmath $name".grd" $weight DIV = sum.grd 112 | else 113 | gmt grdmath $name".grd" $weight DIV sum.grd ADD = sumtmp.grd 114 | mv sumtmp.grd sum.grd 115 | endif 116 | @ num ++ 117 | end 118 | @ num -- 119 | gmt grdmath sum.grd $num DIV = M_A.grd 120 | #rm tmp.grd 121 | # 122 | 123 | 124 | # 125 | # compute the sig_A term 126 | # 127 | 128 | echo "compute the sig_A term ..." 129 | @ num = 1 130 | foreach name ($namearray) 131 | if ($num == 1) then 132 | gmt grdmath $name".grd" $weightarray[$num] DIV M_A.grd SUB SQR = sum2.grd 133 | else 134 | gmt grdmath $name".grd" $weightarray[$num] DIV M_A.grd SUB SQR sum2.grd ADD = sum2tmp.grd 135 | mv sum2tmp.grd sum2.grd 136 | endif 137 | @ num ++ 138 | end 139 | @ num -- 140 | gmt grdmath sum2.grd $num DIV SQRT = sig_A.grd 141 | # 142 | 143 | 144 | # 145 | # compute the amplitude dispersion 146 | # 147 | 148 | echo "" 149 | echo "compute the scattering amplitude ... " 150 | gmt grdmath sig_A.grd M_A.grd DIV = $outgrd 151 | 152 | gmt makecpt -Cgray -T0.1/1/0.1 -Z -D > scatter.cpt 153 | 154 | gmt grdimage $outgrd -Cscatter.cpt -JX6i -P -X1i -Y3i -V -R$region -Bf5000a10000WSen -K > scatter_AD.ps 155 | gmt psscale -D3/-0.8/5/0.5h -Cscatter.cpt -Ba0.2f0.1:"amplitude dispersion": -O >> scatter_AD.ps 156 | 157 | echo "" 158 | echo "Finish -- compute amplitude dispersion" 159 | echo "" 160 | 161 | 162 | # 163 | # clean up 164 | # 165 | foreach name ($namearray) 166 | # rm $name".grd" 167 | end 168 | rm sum.grd sumtmp.grd sum2.grd sum2tmp.grd ave.grd 169 | #rm scatter.cpt M_A.grd sig_A.grd 170 | -------------------------------------------------------------------------------- /dispersion_sbas.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Amplitude difference dispersion from a stack of aligned SLCs for master-slave SB pairs 4 | 5 | # Creator: Xiaopeng Tong, David Sandwell 6 | # Date: July 4th 2013 7 | # Modified by NI, 06.02.2018 8 | 9 | # input: PRM.list 10 | # input: sbas.list 11 | # output: amplitude difference dispersion 12 | 13 | # The principle: first calibrate each images by a weighting 14 | # factor then compute the mean amplitude M_A_sb for all master-slave pairs 15 | # and the standard deviation of the difference amplitude sig_delta_A 16 | # then take the ratio of the M_A_sb and sig_delta_A 17 | 18 | # Reference: Lyons and Sandwell, Fault creep along the southern San Andreas from InSAR, permanent scatterers, and stacking, J. Geophys. Res., 108 (B1), 2047, doi:10.1029/ 2002JB001831 2003 19 | # Hooper, Andy, A multi-temporal InSAR method incorporating both persistent scatterer and small baseline approaches, GEOPHYSICAL RESEARCH LETTERS, VOL. 35, L16302, doi:10.1029/2008GL034654, 2008 20 | 21 | #alias rm 'rm -f' 22 | 23 | if [[ $# -ne 4 ]]; then 24 | echo "" 25 | echo "Usage: dispersion_sbas.sh PRM.list scatter.grd /// sbas.list" 26 | echo "" 27 | echo " Amplitude difference dispersion from a stack of aligned SLCs between master and slave" 28 | echo "" 29 | echo " PRM.list -- a list of PRM files of the aligned SLC" 30 | echo " sbas.list -- a list of PRM files of the aligned SLC for master-slave pairs" 31 | echo " scatter.grd -- output scattering coeffient grid" 32 | echo " /// — region of interests in radar coordinates" 33 | echo "" 34 | echo " example:" 35 | echo " PRM.list >> S1A20141113_ALL_F1.PRM" 36 | echo " S1A20141207_ALL_F1.PRM" 37 | echo " sbas.list >> S1A20141113_ALL_F1 S1A20141207_ALL_F1" 38 | echo " S1A20141113_ALL_F1 S1A20141231_ALL_F1" 39 | echo "" 40 | exit 1 41 | fi 42 | 43 | if [ ! -e $1 ]; then 44 | echo "" 45 | echo "no input file found: $1" 46 | echo "" 47 | exit 1 48 | fi 49 | 50 | list=$1 51 | outgrd=$2 52 | region=$3 53 | sbas_list=$4 54 | #filter = $GMT5SAR/gmtsar/filters/gauss1x1 55 | filter=$GMTSAR/gmtsar/filters/gauss5x5 56 | namearray= 57 | weightarray= 58 | 59 | 60 | echo "" 61 | echo "Start -- compute amplitude difference dispersion" 62 | echo "" 63 | 64 | # 65 | # conv to get amplitude of the SLCs and compute their sum and average 66 | # 67 | 68 | echo "compute amplitude from SLCs ..." 69 | num=1 70 | rm -f namearray.txt weightarray.txt 71 | while read prm 72 | do 73 | name=$(grep input_file $prm | awk '{print $3}' | sed 's/\.raw//') 74 | #namearray=(${namearray[*]} $name".grd") 75 | #echo "${namearray[*]}" >> namearray.txt 76 | echo $name >> namearray.txt 77 | if [ -e $prm ]; then 78 | if [ ! -e $name".grd" ]; then 79 | echo "running conv on file $name" 80 | conv 1 1 $filter $prm $name".grd" #2-D image convolution, makes and filters amplitude file from an SLC-file 81 | gmt grdmath $name".grd" FLIPUD = $name".grd" 82 | fi 83 | #gmt grd2cpt $name".grd" -Cgray -Z -D > b.cpt 84 | gmt makecpt -Cgray -T1e-8/1e-7/1e-8 -Z > a.cpt 85 | gmt grdimage $name".grd" -Ca.cpt -JX6i -P -Xc -Yc -V -R$region -Bf250a500WSen > $name".ps" 86 | else 87 | echo "" 88 | echo "no PRM file found: $prm" 89 | echo "" 90 | exit 1 91 | fi 92 | gmt grdcut $name".grd" -R$region -Gtmp.grd 93 | mv tmp.grd $name".grd" 94 | if [ $num == 1 ]; then 95 | gmt grdmath $name".grd" = sum.grd 96 | else 97 | gmt grdmath sum.grd $name".grd" ADD = sumtmp.grd 98 | mv sumtmp.grd sum.grd 99 | fi 100 | (( num++ )) 101 | 102 | done < $list 103 | 104 | (( num-- )) 105 | gmt grdmath sum.grd $num DIV = ave.grd 106 | avemean=$(gmt grdinfo ave.grd -L2 -C | cut -f 12) 107 | echo $avemean 108 | # 109 | 110 | 111 | # 112 | # compute the M_A_sb term 113 | # 114 | 115 | echo "" 116 | echo "compute the M_A term for SB and calibration factor..." 117 | shopt -s extglob 118 | IFS=" " 119 | num=1 120 | while read master slave 121 | do 122 | ampmean_m=$(gmt grdinfo $master".grd" -L2 -C | cut -f 12) 123 | weight_m=$(echo $ampmean_m $avemean | awk '{print $1/$2}') 124 | ampmean_s=$(gmt grdinfo $slave".grd" -L2 -C | cut -f 12) 125 | weight_s=$(echo $ampmean_s $avemean | awk '{print $1/$2}') 126 | #echo "calib factor for master: "$weight_m " ... and for slave: "$weight_s 127 | echo $weight_m $weight_s >> weightarray.txt 128 | #weightarray=(${weightarray[*]} $weight) 129 | #echo "${weightarray[*]}" >> weightarraySB.txt 130 | #gmt grdmath $name".grd" $weight DIV = tmp.grd 131 | if [ $num == 1 ]; then 132 | gmt grdmath $master".grd" $weight_m DIV = sum.grd 133 | gmt grdmath $slave".grd" $weight_s DIV sum.grd ADD = sumtmp1.grd 134 | mv sumtmp1.grd sum.grd 135 | else 136 | gmt grdmath $master".grd" $weight_m DIV sum.grd ADD = sumtmp2.grd 137 | mv sumtmp2.grd sum.grd 138 | gmt grdmath $slave".grd" $weight_s DIV sum.grd ADD = sumtmp3.grd 139 | mv sumtmp3.grd sum.grd 140 | fi 141 | (( num++ )) 142 | done < $sbas_list 143 | (( num-- )) 144 | num=$(( $num*2 )) 145 | gmt grdmath sum.grd $num DIV = M_A_sb.grd 146 | #rm tmp.grd 147 | # 148 | 149 | 150 | # 151 | # compute the sig_delta_A term : the standard deviation of the difference in amplitude between master and slave 152 | # 153 | echo "" 154 | echo "compute the sig_delta_A term" 155 | echo "Step 1, compute sum of square diff A = (Amp1-Amp2)*(Amp1-Amp2) ..." 156 | paste -d\ $sbas_list weightarray.txt > sigA_variable.txt 157 | num=1 158 | while read master slave weight_m weight_s 159 | do 160 | name_m=$(grep input_file $master".PRM" | awk '{print $3}' | sed 's/\.raw//') 161 | name_s=$(grep input_file $slave".PRM" | awk '{print $3}' | sed 's/\.raw//') 162 | gmt grdmath $name_m".grd" $weight_m DIV = amp_m_calib.grd 163 | gmt grdmath $name_s".grd" $weight_s DIV = amp_s_calib.grd 164 | if [ $num == 1 ]; then 165 | gmt grdmath amp_m_calib.grd amp_s_calib.grd SUB SQR = sum_diff.grd 166 | else 167 | gmt grdmath amp_m_calib.grd amp_s_calib.grd SUB SQR sum_diff.grd ADD = sum_difftmp.grd 168 | mv sum_difftmp.grd sum_diff.grd 169 | fi 170 | (( num++ )) 171 | rm -f amp_m_calib.grd amp_s_calib.grd 172 | done < sigA_variable.txt 173 | (( num-- )) 174 | echo "Step 2, compute sigma delta A ..." 175 | gmt grdmath sum_diff.grd $num DIV = var_MS.grd 176 | gmt grdmath var_MS.grd SQRT = sig_delta_A.grd 177 | 178 | # 179 | # compute the amplitude difference dispersion 180 | # 181 | echo "" 182 | echo "compute the scattering difference amplitude ... " 183 | gmt grdmath sig_delta_A.grd M_A_sb.grd DIV = $outgrd 184 | 185 | gmt makecpt -Cgray -T0/1/0.1 -Z -D > scatter.cpt 186 | 187 | gmt grdimage $outgrd -Cscatter.cpt -JX6i -P -X1i -Y3i -V -Bf500a2000WSen -K > scatter_SB.ps 188 | gmt psscale -D3/-0.8/5/0.5h -Cscatter.cpt -Ba0.2f0.1:"amplitude difference dispersion": -O >> scatter_SB.ps 189 | 190 | echo "" 191 | echo "Finish -- compute amplitude difference dispersion" 192 | echo "" 193 | 194 | 195 | # 196 | # clean up 197 | # 198 | # 199 | rm -f sum.grd sumtmp.grd sum2.grd sum2tmp.grd ave.grd sum_MS.grd sum_delta_MS.grd ave_sum_ms.grd sum_MS_sqrt.grd sum_MS.grd var_MS.grd namearray.txt weightarray.txt sum_diff.grd scatter.cpt 200 | #rm -f M_A_sb.grd sig_delta_A.grd sigA_variable.txt 201 | -------------------------------------------------------------------------------- /gmtsar_matlab/sb_load_initial_gmtsar.m: -------------------------------------------------------------------------------- 1 | function []=sb_load_initial() 2 | %SB_LOAD_INITIAL Initial load of PS files into matlab workspace 3 | % SB_LOAD_INITIAL() loads 'pscands.1.*' files and stores them 4 | % in various workspaces. The version number, PSVER, is set to 1. 5 | % 6 | % Andy Hooper, Spetember 2006 7 | % 8 | % ====================================================================== 9 | % Change Log: 10 | % 11/2007 AH: change bperp to be bperp at 0 m 11 | % 12/2012 DB: Add compatibility with Matlab2012B, keep backward compatible 12 | % 02/2015 DB: save phase using slower method to allow for larger files 13 | % 01/2016 DB: Replace save with stamps_save which checks for var size when 14 | % saving 15 | % ====================================================================== 16 | 17 | %NB IFGS assumed in ascending date order 18 | 19 | phname=['pscands.1.ph']; % for each PS candidate, a float complex value for each ifg 20 | ijname=['pscands.1.ij']; % ID# Azimuth# Range# 1 line per PS candidate 21 | bperpname=['bperp.1.in']; % in meters 1 line per slave image 22 | dayname=['day.1.in']; % YYYYMMDD, 1 line per slave image 23 | ifgdayname=['ifgday.1.in']; % YYYYMMDD YYYYMMDD, 1 line per ifg 24 | masterdayname=['master_day.1.in']; % YYYYMMDD 25 | llname=['pscands.1.ll']; % 2 float values (lon and lat) per PS candidate 26 | daname=['pscands.1.da']; % 1 float value per PS candidate 27 | hgtname=['pscands.1.hgt']; % 1 float value per PS candidate 28 | laname=['look_angle.1.in']; % grid of look angle values 29 | headingname=['heading.1.in']; % satellite heading 30 | lambdaname=['lambda.1.in']; % wavelength 31 | calname=['calamp.out']; % amplitide calibrations 32 | widthname=['width.txt']; % width of interferograms 33 | lenname=['len.txt']; % length of interferograms 34 | 35 | psver=1; 36 | 37 | % Get matlab version as function arguments change with the matlab version 38 | matlab_version = version('-release'); % [DB] getting the matlab version 39 | matlab_version = str2num(matlab_version(1:4)); % [DB] the year 40 | 41 | if ~exist(dayname,'file') 42 | dayname= ['../',dayname]; 43 | end 44 | day_yyyymmdd=load(dayname); 45 | year=floor(day_yyyymmdd/10000); 46 | month=floor((day_yyyymmdd-year*10000)/100); 47 | monthday=day_yyyymmdd-year*10000-month*100; 48 | slave_day=datenum(year,month,monthday); 49 | [slave_day,day_ix]=sort(slave_day); 50 | day_yyyymmdd=day_yyyymmdd(day_ix); 51 | 52 | 53 | if ~exist(masterdayname,'file') 54 | masterdayname= ['../',masterdayname]; 55 | end 56 | master_day_yyyymmdd=load(masterdayname); 57 | year=floor(master_day_yyyymmdd/10000); 58 | month=floor((master_day_yyyymmdd-year*10000)/100); 59 | monthday=master_day_yyyymmdd-year*10000-month*100; 60 | master_day=datenum(year,month,monthday); 61 | master_ix=sum(master_day>slave_day)+1; 62 | day=[slave_day(1:master_ix-1);master_day;slave_day(master_ix:end)]; % insert master day 63 | n_image=size(day,1); 64 | 65 | if ~exist(ifgdayname,'file') 66 | ifgdayname= ['../',ifgdayname]; 67 | end 68 | ifgday=load(ifgdayname); 69 | year=floor(ifgday/10000); 70 | month=floor((ifgday-year*10000)/100); 71 | monthday=ifgday-year*10000-month*100; 72 | ifgday=datenum(year,month,monthday); 73 | n_ifg=size(ifgday,1); 74 | [found_true,ifgday_ix]=ismember(ifgday,day); 75 | if sum(found_true~=1)>0 76 | error('one or more days in ifgday.1.in not in day.1.in') 77 | end 78 | 79 | if ~exist(bperpname,'file') 80 | bperpname= ['../',bperpname]; 81 | end 82 | bperp=load(bperpname); 83 | bperp=bperp(day_ix); 84 | bperp=[bperp(1:master_ix-1);0;bperp(master_ix:end)]; % insert master-master bperp (zero) 85 | bperp=bperp(ifgday_ix(:,2))-bperp(ifgday_ix(:,1)); 86 | 87 | 88 | if ~exist(headingname,'file') 89 | headingname= ['../',headingname]; 90 | end 91 | heading=load(headingname); 92 | if isempty(heading) 93 | error('heading.1.in is empty') 94 | end 95 | setparm('heading',heading,1); 96 | 97 | if ~exist(lambdaname,'file') 98 | lambdaname= ['../',lambdaname]; 99 | end 100 | lambda=load(lambdaname); 101 | setparm('lambda',lambda,1); 102 | 103 | 104 | ij=load(ijname); 105 | n_ps=size(ij,1); 106 | 107 | fid=fopen(phname,'r'); 108 | if fid < 0 109 | error([phname,' cannot be openned']) 110 | end 111 | ph_bit=fread(fid,[1,1],'float'); 112 | float_bytes=ftell(fid); 113 | fseek(fid,0,1); 114 | nbytes=ftell(fid); 115 | if nbytes~=n_ps*n_ifg*float_bytes*2 116 | error([phname,' has ',num2str(nbytes/float_bytes/2),' complex float values which does not equal ',num2str(n_ps),'*',num2str(n_ifg),' (pixels*images)']) 117 | end 118 | fseek(fid,0,-1); 119 | ph=zeros(n_ps,n_ifg,'single'); 120 | byte_count=n_ps*2; 121 | for i=1:n_ifg 122 | [ph_bit,byte_count]=fread(fid,[(n_ps)*2,1],'float'); 123 | ph_bit=single(ph_bit); 124 | ph(:,i)=complex(ph_bit(1:2:end),ph_bit(2:2:end)); 125 | end 126 | 127 | fclose(fid); 128 | %ph=single(ph'); 129 | %ph=complex(ph(:,1:2:end),ph(:,2:2:end)); 130 | zero_ph=sum(ph==0,2); 131 | nonzero_ix=zero_ph<=1; % if more than 1 phase is zero, drop node 132 | ph(ph~=0)=ph(ph~=0)./abs(ph(ph~=0)); % scale amplitudes 133 | 134 | 135 | fid=fopen(llname,'r'); 136 | if fid < 0 137 | error([llname,' cannot be openned']) 138 | end 139 | lonlat=fread(fid,[2,inf],'float'); 140 | lonlat=lonlat'; 141 | fclose(fid); 142 | if size(lonlat,1) ~= n_ps 143 | error([llname,' has ',num2str(size(lonlat,1)),' entries whereas ',ijname,' has ',num2str(n_ps)]) 144 | end 145 | 146 | ll0=(max(lonlat)+min(lonlat))/2; 147 | xy=llh2local(lonlat',ll0)*1000; 148 | xy=xy'; 149 | sort_x=sortrows(xy,1); 150 | sort_y=sortrows(xy,2); 151 | n_pc=round(n_ps*0.001); 152 | bl=mean(sort_x(1:n_pc,:)); % bottom left corner 153 | tr=mean(sort_x(end-n_pc:end,:)); % top right corner 154 | br=mean(sort_y(1:n_pc,:)); % bottom right corner 155 | tl=mean(sort_y(end-n_pc:end,:)); % top left corner 156 | 157 | theta=(180-heading)*pi/180; 158 | if theta>pi 159 | theta=theta-2*pi; 160 | end 161 | 162 | rotm=[cos(theta),sin(theta); -sin(theta),cos(theta)]; 163 | xy=xy'; 164 | xynew=rotm*xy; % rotate so that scene axes approx align with x=0 and y=0 165 | if max(xynew(1,:))-min(xynew(1,:))0 255 | bperp_mat=zeros(n_ps,n_image,'single'); 256 | for i=setdiff([1:n_image],master_ix); 257 | bperp_fname=['bperp_',datestr(day(i),'yyyymmdd'),'.1.in']; 258 | if updir==1 259 | bperp_fname=['../',bperp_fname]; 260 | end 261 | bperp_grid=load(bperp_fname); 262 | bp0=bperp_grid(1:2:end); 263 | bp0=reshape(bp0,50,50)'; 264 | bp1000=bperp_grid(2:2:end); 265 | bp1000=reshape(bp1000,50,50)'; 266 | bp0_ps=griddata_version_control(gridX,gridY,bp0,ij(:,3),ij(:,2),'linear',matlab_version); % [DB] fix matlab2012 version and older 267 | %bp1000_ps=griddata(gridX,gridY,bp1000,ij(:,3),ij(:,2),'linear',{'QJ'}); 268 | %bperp_mat(:,i)=bp0_ps+(bp1000_ps-bp0_ps).*hgt/1000; 269 | bperp_mat(:,i)=bp0_ps; 270 | end 271 | %bperp_mat=[bperp_mat(:,1:master_ix-1),zeros(n_ps,1),bperp_mat(:,master_ix:end)]; % insert master-master bperp (zero) 272 | bperp_mat=bperp_mat(:,ifgday_ix(:,2))-bperp_mat(:,ifgday_ix(:,1)); 273 | else 274 | bperp_mat=repmat(single(bperp)',n_ps,1); 275 | end 276 | 277 | bpsavename=['bp',num2str(psver)]; 278 | stamps_save(bpsavename,bperp_mat); 279 | 280 | end % end-if 281 | 282 | 283 | 284 | -------------------------------------------------------------------------------- /gmtsar_matlab/ps_load_initial_gmtsar.m: -------------------------------------------------------------------------------- 1 | function []=ps_load_initial() 2 | %PS_LOAD_INITIAL Initial load of PS files into matlab workspace 3 | % PS_LOAD_INITIAL() loads various files and stores them 4 | % in various workspaces. The version number, PSVER, is set to 1. 5 | % 6 | % Andy Hooper, June 2006 7 | % 8 | % ====================================================================== 9 | % 06/2006 AH: Initialize day variable 10 | % 07/2006 AH: Fix error in la and bperp matrix calculation 11 | % 07/2006 AH: Add patch compatibility 12 | % 09/2006 AH: Store wrapped phase in separate workspace 13 | % 11/2007 AH: Change bperp to be the bperp at 0 m 14 | % 01/2008 AH: Selection of bperp files made more rigourous 15 | % 03/2009 AH: Change bperp back to be the bperp at local height 16 | % 10/2009 AH: Add n_image to mat file 17 | % 04/2010 KS: Fixed small issue with new logit function 18 | % 10/2009 MA: Oversampling factor file introduced 19 | % 12/2012 DB: Add compatiblility with Matlab2012B, keep backward compatible 20 | % 01/2016 DB: Replace save with stamps_save which checks for var size when saving 21 | % 04/2017 DB: Include fix for isce2stamps calamp.out slc filenaming 22 | % ====================================================================== 23 | 24 | 25 | %NB IFGS assumed in ascending date order 26 | logit; 27 | logit('Loading data into matlab...') 28 | 29 | phname=['pscands.1.ph']; % for each PS candidate, a float complex value for each ifg 30 | ijname=['pscands.1.ij']; % ID# Azimuth# Range# 1 line per PS candidate 31 | bperpname=['bperp.1.in']; % in meters 1 line per ifg 32 | dayname=['day.1.in']; % YYYYMMDD, 1 line per ifg 33 | masterdayname=['master_day.1.in']; % YYYYMMDD 34 | llname=['pscands.1.ll']; % 2 float values (lon and lat) per PS candidate 35 | daname=['pscands.1.da']; % 1 float value per PS candidate 36 | hgtname=['pscands.1.hgt']; % 1 float value per PS candidate 37 | laname=['look_angle.1.in']; % grid of look angle values 38 | headingname=['heading.1.in']; % satellite heading 39 | lambdaname=['lambda.1.in']; % wavelength 40 | calname=['calamp.out']; % amplitide calibrations 41 | widthname=['width.txt']; % width of interferograms 42 | lenname=['len.txt']; % length of interferograms 43 | slc_osfname=['slc_osfactor.1.in']; % oversampling factor value 1 for no oversampling 44 | 45 | psver=1; 46 | 47 | % Get matlab version as function arguments change with the matlab version 48 | matlab_version = version('-release'); % [DB] getting the matlab version 49 | matlab_version = str2num(matlab_version(1:4)); % [DB] the year 50 | 51 | if ~exist(dayname,'file') 52 | dayname= ['../',dayname]; 53 | end 54 | day=load(dayname); 55 | year=floor(day/10000); 56 | month=floor((day-year*10000)/100); 57 | monthday=day-year*10000-month*100; 58 | slave_day=datenum(year,month,monthday); 59 | [slave_day,day_ix]=sort(slave_day); 60 | 61 | if ~exist(masterdayname,'file') 62 | masterdayname= ['../',masterdayname]; 63 | end 64 | master_day=load(masterdayname); 65 | master_day_yyyymmdd=master_day; 66 | year=floor(master_day/10000); 67 | month=floor((master_day-year*10000)/100); 68 | monthday=master_day-year*10000-month*100; 69 | master_day=datenum(year,month,monthday); 70 | 71 | master_ix=sum(slave_daypi 173 | theta=theta-2*pi; 174 | end 175 | 176 | rotm=[cos(theta),sin(theta); -sin(theta),cos(theta)]; 177 | xy=xy'; 178 | xynew=rotm*xy; % rotate so that scene axes approx align with x=0 and y=0 179 | if max(xynew(1,:))-min(xynew(1,:))0 265 | i2=0; 266 | for i=setdiff([1:n_ifg],master_ix); 267 | i2=i2+1; 268 | bperp_fname=['bperp_',datestr(day(i),'yyyymmdd'),'.1.in']; 269 | if updir==1 270 | bperp_fname=['../',bperp_fname]; 271 | end 272 | bperp_grid=load(bperp_fname); 273 | bp0=bperp_grid(1:2:end); 274 | bp0=reshape(bp0,50,50)'; 275 | bp1000=bperp_grid(2:2:end); 276 | bp1000=reshape(bp1000,50,50)'; 277 | bp0_ps=griddata_version_control(gridX,gridY,bp0,ij(:,3),ij(:,2),'linear',matlab_version); % [DB] fix matlab2012 version and older 278 | % AH adjust bperp for local height 279 | bp1000_ps=griddata_version_control(gridX,gridY,bp1000,ij(:,3),ij(:,2),'linear',matlab_version); % [DB] fix matlab2012 version and older 280 | bperp_mat(:,i2)=bp0_ps+(bp1000_ps-bp0_ps).*hgt/1000; 281 | end 282 | end 283 | 284 | bpsavename=['bp',num2str(psver)]; 285 | % save(bpsavename,'bperp_mat'); 286 | stamps_save(bpsavename,bperp_mat); 287 | 288 | %end % end-if 289 | 290 | logit(1); 291 | -------------------------------------------------------------------------------- /INSAR_G2S.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # INSAR_G2S 1.0 4 | # InSAR processing Sentinel-1 TOPS SAR data to be able run by the time series InSAR processing (StaMPS software | PS and Small Baseline Method) 5 | # A bundle script to generate the interferogram from GMTSAR software and further export to STAMPS format 6 | # This program is established by the scripts of gmtsar_process, gmtsar2stamps, and gmtsar2stamps_sbas. 7 | # gmtsar2stamps is originally from : 8 | # - Xiaopeng Tong - Chinese Academy of Sciences 9 | # - David Sandwell - Scripps Institution of Oceanography 10 | 11 | # Created by Noorlaila Isya 01.10.2019 12 | # IGP, TU Braunschweig - Germany 13 | # Department of Geomatics Engineering, ITS - Indonesia 14 | # n.isya@tu-bs.de / noorlaila@geodesy.its.ac.id 15 | 16 | dir=$(pwd) 17 | if [[ $# -ne 2 ]]; then 18 | echo "" 19 | echo "Usage: INSAR_G2S.sh [step] [parameter_with_path_directory]" 20 | echo "" 21 | echo " Script to pre-process SAR data and export to STAMPS format" 22 | echo "" 23 | echo " example : INSAR_G2S.sh 1 /home/isya/3d_disp/param_INSAR_G2S.txt" 24 | echo "" 25 | echo " Step: Data Preparation --> " 26 | echo " 1 Prepare the directory arrangement" 27 | echo " 2 Prepare the POE data" 28 | echo " 3 Prepare the EAP data" 29 | echo " 4 Preprocess SAR data: Compute Baseline and Alignment" 30 | echo " 5 Create a configuration of master-slave for SM or SB network" 31 | echo "" 32 | echo " Interferogram Generation --> " 33 | echo " 6 Project DEM to radar coordinates" 34 | echo " 7 Generate Interferogram (Real and Imaginary format) [SM | SB]" 35 | echo " 8 Overview the sample of amplitude and phase file on Google Earth (optional)" 36 | echo " 9 Cut the interferograms based on ROI (optional) [SM | SB]" 37 | echo "" 38 | echo " GMTSAR2STAMPS (PS Method) --> " 39 | echo " 10 Create Amplitude Dispersion Index" 40 | echo " 11 Convert GMTSAR result to be able processed by STAMPS PS" 41 | echo " 12 Fix the result of PS Candidates (PS)" 42 | echo "" 43 | echo " GMTSAR2STAMPS (Small Baseline [SB] Method) --> " 44 | echo " 13 Create Amplitude Difference Dispersion Index" 45 | echo " 14 Convert GMTSAR result to be able processed by STAMPS SB" 46 | echo " 15 Fix the result of PS Candidates (SB)" 47 | echo "" 48 | echo "" 49 | exit 1 50 | fi 51 | 52 | step=$1 53 | path=$2 54 | 55 | # define parameter from param_INSAR_G2S.txt 56 | orbit=$(grep dataorbit $path | sed 's/^.*= //') 57 | raw_path=$(grep raw_path $path | sed 's/^.*= //') 58 | sen_orbit=$(grep sen_POE $path | sed 's/^.*= //') 59 | temp_bl=$(grep temp_bl $path | sed 's/^.*= //') 60 | spatial_bl=$(grep spatial_bl $path | sed 's/^.*= //') 61 | region=$(grep region $path | sed 's/^.*= //'); 62 | region_ll=$(grep reg_ll $path | sed 's/^.*= //'); 63 | R=$(grep n_range $path | sed 's/^.*= //') 64 | A=$(grep n_azimuth $path | sed 's/^.*= //') 65 | ov_R=$(grep ov_range $path | sed 's/^.*= //') 66 | ov_A=$(grep ov_azimuth $path | sed 's/^.*= //') 67 | threshold=$(grep threshold $path | sed 's/^.*= //') 68 | master_date=$(grep master_date $path | sed 's/^.*= //') 69 | master_PRM=$(grep master_PRM $path | sed 's/^.*= //') 70 | suffix=$(grep suffix $path | sed 's/^.*= //') 71 | suffix_tiff=$(grep tiff_id $path | sed 's/^.*= //') 72 | type_data=$(grep type_data $path | sed 's/^.*= //') 73 | heading=$(grep heading $path | sed 's/^.*= //') 74 | 75 | # define orbit data 76 | if [ $orbit = "ascending" ]; then 77 | echo "--------------> Prepare the directory arrangement for ascending SAR data" 78 | orb=asc 79 | elif [ $orbit = "descending" ]; then 80 | echo "--------------> Prepare the directory arrangement for descending SAR data" 81 | orb=dsc 82 | else 83 | echo "--------------> Input: orbit is unknown" 84 | fi 85 | 86 | # go to Step [1] 87 | 88 | if [ $step -eq 1 ]; then 89 | echo " " 90 | echo "INSAR_G2S STEP ---->>" $step 91 | echo "1 Prepare the directory arrangement" 92 | echo "Path must be located on the basement" 93 | echo " " 94 | 95 | prep_dir.sh $raw_path $suffix_tiff $type_data $orb 96 | 97 | echo "raw_orig= $dir/batch_$orb/raw_orig" > param_dir_$orb.txt 98 | echo "raw_data= $dir/batch_$orb/raw" >> param_dir_$orb.txt 99 | echo "topo = $dir/batch_$orb/topo" >> param_dir_$orb.txt 100 | echo "SLC = $dir/batch_$orb/raw" >> param_dir_$orb.txt 101 | echo "stack = $dir/batch_$orb/stack" >> param_dir_$orb.txt 102 | echo "crop_SM = $dir/batch_$orb/stack/crop_SM" >> param_dir_$orb.txt 103 | echo "crop_SB = $dir/batch_$orb/stack/crop_SB" >> param_dir_$orb.txt 104 | echo "PS = $dir/batch_$orb/stack/PS" >> param_dir_$orb.txt 105 | echo "SB = $dir/batch_$orb/stack/PS/SMALL_BASELINES" >> param_dir_$orb.txt 106 | 107 | fi 108 | 109 | # go to Step [2] 110 | if [ $step -eq 2 ]; then 111 | echo " " 112 | echo "INSAR_G2S STEP ---->>" $step 113 | echo "2 Prepare the POE data" 114 | echo "Path must be located on the basement" 115 | echo " " 116 | 117 | raw_org=$dir/batch_"$orb"/raw_orig 118 | echo "--------------> Prepare the precise orbit ephemeris (POE) data" 119 | echo "--------------> Please choose an option " 120 | echo -n "Do you have the POE data on your local computer [type: yes or no]? " 121 | read option 122 | if [ $option = "yes" ]; then 123 | 124 | echo "Use the POE data on your local directory" 125 | prep_orb.sh $sen_orbit $raw_org $orb 126 | 127 | elif [ $option = "no" ]; then 128 | 129 | echo "Download the POE files and put in raw_orig directory" 130 | scihub_poeorb_download.sh $raw_org $orb 131 | 132 | else 133 | echo "--------------> Input: Option is unknown" 134 | fi 135 | echo " " 136 | 137 | fi 138 | 139 | # go to Step [3] 140 | if [ $step -eq 3 ]; then 141 | echo " " 142 | echo "INSAR_G2S STEP ---->>" $step 143 | echo "3 Prepare the EAP data" 144 | echo "Path must be located on the basement" 145 | echo " " 146 | 147 | cd $dir/batch_"$orb"/raw_orig 148 | cp ../../date_"$orb".txt . 149 | cp ../../data_"$orb".in . 150 | rm -f date_"$orb"_sp.txt 151 | rm -f data_"$orb"_sp.in 152 | 153 | # create date_sp.txt and data_sp.in 154 | echo $master_date >> date_"$orb"_sp.txt 155 | echo $(grep "$master_date" data_"$orb".in) | sed 's/ /:/g' >> data_"$orb"_sp.in 156 | IFS=':' 157 | while read -r -u3 date_num && read -r -u4 tiff_name POE_name 158 | do 159 | if [ $date_num = "$master_date" ]; then 160 | echo "Arrange the master date at the first line" 161 | else 162 | echo $date_num >> date_"$orb"_sp.txt 163 | echo ""$tiff_name":"$POE_name"" >> data_"$orb"_sp.in 164 | fi 165 | done 3 Prepare EAP" 168 | echo "--------------> Please choose an option " 169 | echo -n "Do you want to add EAP data [type: yes or no]? " 170 | read option 171 | 172 | if [ $option = "yes" ]; then 173 | echo "apply EAP on the xml files" 174 | # apply EAP on the xml files 175 | prep.sh $orb 176 | elif [ $option = "no" ]; then 177 | 178 | echo "Step 3 skip, just add some parameter files" 179 | else 180 | echo "--------------> Input: Option is unknown" 181 | fi 182 | echo " " 183 | 184 | rm -f date_"$orb".txt 185 | rm -f data_"$orb".in 186 | 187 | cd $dir/batch_"$orb" 188 | mkdir topo 189 | cd $dir 190 | echo " " 191 | echo "==== Please save dem.grd file in topo folder ====" 192 | echo " " 193 | 194 | fi 195 | 196 | # go to Step [4] 197 | if [ $step -eq 4 ]; then 198 | echo " " 199 | echo "INSAR_G2S STEP ---->>" $step 200 | echo "4 Preprocess SAR data: Compute Baseline and Alignment" 201 | echo "Path must be located on the basement" 202 | echo " " 203 | 204 | cd $dir/batch_"$orb"/raw_orig 205 | ln -s ../topo/dem.grd . 206 | preproc_batch_tops.csh data_"$orb"_sp.in dem.grd 1 207 | preproc_batch_tops.csh data_"$orb"_sp.in dem.grd 2 208 | 209 | #check if baseline_table.dat exists 210 | FILE=baseline_table.dat 211 | if [ -f "$FILE" ]; then 212 | echo "$FILE exists." 213 | else 214 | echo "$FILE does not exist, try to regenerate." 215 | ls *ALL*PRM > prmlist 216 | get_baseline_table.csh prmlist "$master_PRM".PRM 217 | rm prmlist 218 | fi 219 | 220 | cd $dir 221 | 222 | cd $dir/batch_"$orb" 223 | ln -s ../param* . 224 | mkdir raw 225 | cd raw 226 | ln -s ../raw_orig/*.PRM . 227 | ln -s ../raw_orig/*.PRM0 . 228 | ln -s ../raw_orig/*.LED . 229 | ln -s ../raw_orig/*.SLC . 230 | ln -s ../raw_orig/*.dat . 231 | ln -s ../raw_orig/*.grd . 232 | ln -s ../raw_orig/*.xml . 233 | 234 | echo " " 235 | echo "From now you will work on batch_"$orb" directory" 236 | echo " " 237 | 238 | fi 239 | 240 | # go to Step [5] 241 | if [ $step -eq 5 ]; then 242 | echo " " 243 | echo "INSAR_G2S STEP ---->>" $step 244 | echo "5 Create a configuration of master-slave for SM or SB network" 245 | echo "Path must be located on batch_$orb" 246 | echo " " 247 | 248 | cp ../date_"$orb".txt . 249 | tmp_start=$(head -n 1 date_"$orb".txt) 250 | start_date=$(date -I -d "$tmp_start - 15 day") 251 | tmp_end=$(tail -n 1 date_"$orb".txt) 252 | end_date=$(date -I -d "$tmp_end + 45 day") 253 | 254 | 255 | echo "--------------> Create Master-Slave network for PS (SM) and SB mentod" 256 | echo "--------------> Please choose an option " 257 | echo -n "Single Master (MS) or Small Baseline (SB) network [type: SM or SB]? " 258 | read option 259 | if [ $option = "SM" ]; then 260 | 261 | echo "SM network is created with date of master: $master_date" 262 | sm_config.sh date_"$orb".txt $master_date $dir/raw $suffix 263 | baseline_sen.sh $start_date $end_date $suffix $master_date SM 264 | mv baseline_pair.ps baseline_pair_SM.ps 265 | 266 | elif [ $option = "SB" ]; then 267 | 268 | echo "SB network is created" 269 | pair_config.sh date_"$orb".txt $temp_bl $spatial_bl $dir/raw $suffix 270 | baseline_sen.sh $start_date $end_date $suffix $master_date SB 271 | mv baseline_pair.ps baseline_pair_"$temp_bl"_"$spatial_bl".ps 272 | 273 | else 274 | echo "--------------> Input: Option is unknown" 275 | fi 276 | echo " " 277 | 278 | fi 279 | 280 | # go to Step [6] 281 | if [ $step -eq 6 ]; then 282 | echo " " 283 | echo "INSAR_G2S STEP ---->>" $step 284 | echo "6 Project DEM to radar coordinates" 285 | echo "Path must be located on the batch_$orb" 286 | echo " " 287 | 288 | cd topo 289 | cp ../raw_orig/"$master_PRM".PRM . 290 | cp ../raw_orig/"$master_PRM".LED . 291 | mv "$master_PRM".PRM master.PRM 292 | 293 | dem2topo_ra.csh master.PRM dem.grd 294 | 295 | cd $dir 296 | echo " " 297 | echo "dem.grd has been projected to radar coordinates" 298 | echo " " 299 | 300 | fi 301 | 302 | # go to Step [7] 303 | if [ $step -eq 7 ]; then 304 | echo " " 305 | echo "INSAR_G2S STEP ---->>" $step 306 | echo "7 Generate Interferogram (Real and Imaginary format) [SM | SB]" 307 | echo "Path must be located on the batch_$orb" 308 | echo " " 309 | 310 | echo " " 311 | echo "Working on batch_"$orb" directory" 312 | echo " " 313 | echo "--------------> Please choose an option " 314 | echo -n "Single Master (MS) or Small Baseline (SB) mode [type: SM or SB]? " 315 | read option 316 | 317 | mkdir -p stack 318 | cd stack 319 | if [ $option = "SM" ]; then 320 | 321 | echo "Interferogram is generated with SM network" 322 | ln -s ../intf_SM.in . 323 | process_intf.csh intf_SM.in $dir/raw $dir/topo 324 | 325 | elif [ $option = "SB" ]; then 326 | 327 | echo "Interferogram is generated with SB network" 328 | ln -s ../intf_SB.in . 329 | process_intf.csh intf_SB.in $dir/raw $dir/topo 330 | 331 | else 332 | echo "--------------> Input: Option is unknown" 333 | fi 334 | 335 | echo " " 336 | echo "Interferograms have been generated" 337 | echo " " 338 | cd .. 339 | 340 | fi 341 | 342 | # go to Step [8] 343 | if [ $step -eq 8 ]; then 344 | echo " " 345 | echo "INSAR_G2S STEP ---->>" $step 346 | echo "8 Overview the sample of amplitude and phase file on Google Earth (optional)" 347 | echo "Path must be located on the batch_$orb/stack" 348 | echo " " 349 | 350 | echo " " 351 | echo "Working on batch_"$orb"/stack directory" 352 | echo " " 353 | 354 | intf_kml.sh intf_tes.in ../raw ../topo $region_ll 355 | 356 | echo " " 357 | echo "Open kml file on Google Earth" 358 | echo " " 359 | cd .. 360 | 361 | fi 362 | 363 | # go to Step [9] 364 | if [ $step -eq 9 ]; then 365 | echo " " 366 | echo "INSAR_G2S STEP ---->>" $step 367 | echo "9 Cut the interferograms based on ROI (optional) [SM | SB]" 368 | echo "Path must be located on the batch_$orb/stack" 369 | echo " " 370 | 371 | echo " " 372 | echo "Working on batch_"$orb"/stack directory" 373 | echo " " 374 | echo "--------------> Please choose an option " 375 | echo -n "Single Master (MS) or Small Baseline (SB) mode [type: SM or SB]? " 376 | read option 377 | 378 | if [ $option = "SM" ]; then 379 | 380 | echo "Interferogram is generated with SM network" 381 | cut_SM.bash intf_SM.in $region ../raw 382 | 383 | elif [ $option = "SB" ]; then 384 | 385 | echo "Interferogram is cropped for the SB Intf result" 386 | cut_sbas.bash intf_SB.in $region ../raw 387 | 388 | else 389 | echo "--------------> Input: Option is unknown" 390 | fi 391 | 392 | echo " " 393 | echo "Interferograms have been cropped" 394 | echo " " 395 | 396 | fi 397 | 398 | # go to Step [10] 399 | if [ $step -eq 10 ]; then 400 | echo " " 401 | echo "INSAR_G2S STEP ---->>" $step 402 | echo "10 Create Amplitude Dispersion Index" 403 | echo "Path must be located on the batch_$orb/stack" 404 | echo " " 405 | 406 | echo " " 407 | echo "Working on batch_"$orb"/raw directory" 408 | echo " " 409 | 410 | cd ../raw 411 | ls -1 *ALL_"$suffix".PRM --ignore="PRM.list*" > PRM.list 412 | echo " " 413 | echo "Compute AD for PS method" 414 | echo " " 415 | 416 | dispersion.csh PRM.list scatter_SM.grd $region 417 | 418 | cd $dir 419 | 420 | fi 421 | 422 | # go to Step [11] 423 | if [ $step -eq 11 ]; then 424 | echo " " 425 | echo "INSAR_G2S STEP ---->>" $step 426 | echo "11 Convert GMTSAR result to be able processed by STAMPS PS" 427 | echo "Path must be located on the batch_$orb/stack" 428 | echo " " 429 | 430 | echo " " 431 | echo "Working on batch_"$orb"/stack directory" 432 | echo " " 433 | 434 | mkdir -p PS 435 | cd PS 436 | cp ../intf_SM.in . 437 | ln -s ../../../param_dir_$orb.txt param_dir.txt 438 | sed -i -e 's/[:]/ /g' intf_SM.in 439 | cat intf_SM.in | sed "s/S1_//g" | sed "s/_ALL_$suffix//g" > intf_SM_list.in 440 | rm intf_SM.in 441 | cp ../../date_$orb.txt date_no_master.txt 442 | sed -i "/\b\($master_date\)\b/d" date_no_master.txt 443 | 444 | mt_prep_gmtsar_SM $region $R $A $ov_R $ov_A $threshold $master_date $suffix $heading 445 | 446 | cd $dir 447 | 448 | fi 449 | 450 | # go to Step [12] 451 | if [ $step -eq 12 ]; then 452 | echo " " 453 | echo "INSAR_G2S STEP ---->>" $step 454 | echo "12 Fix the result of PS Candidates (PS)" 455 | echo "Path must be located on the batch_$orb/stack/PS" 456 | echo " " 457 | 458 | echo " " 459 | echo "Working on PS directory" 460 | echo " " 461 | 462 | fix_pscands_SM.sh 463 | 464 | fi 465 | 466 | # go to Step [13] 467 | if [ $step -eq 13 ]; then 468 | echo " " 469 | echo "INSAR_G2S STEP ---->>" $step 470 | echo "13 Create Amplitude Difference Dispersion Index" 471 | echo "Path must be located on the batch_$orb/stack" 472 | echo " " 473 | 474 | echo " " 475 | echo "Working on batch_"$orb"/raw directory" 476 | echo " " 477 | 478 | cd ../raw 479 | ls -1 *ALL_"$suffix".PRM --ignore="PRM.list*" > PRM.list 480 | cp ../intf_SB.in sbas.list 481 | sed -i -e 's/[:]/ /g' sbas.list 482 | echo " " 483 | echo "Compute ADD for SB method" 484 | echo " " 485 | 486 | dispersion_sbas.sh PRM.list scatter_SB.grd $region sbas.list 487 | 488 | cd $dir 489 | 490 | fi 491 | 492 | # go to Step [14] 493 | if [ $step -eq 14 ]; then 494 | echo " " 495 | echo "INSAR_G2S STEP ---->>" $step 496 | echo "14 Convert GMTSAR result to be able processed by STAMPS SB" 497 | echo "Path must be located on the batch_$orb/stack" 498 | echo " " 499 | 500 | echo " " 501 | echo "Working on batch_"$orb"/stack directory" 502 | echo " " 503 | 504 | mkdir -p PS 505 | cd PS 506 | cp ../intf_SB.in . 507 | ln -s ../../../param_dir_$orb.txt param_dir.txt 508 | sed -i -e 's/[:]/ /g' intf_SB.in 509 | cat intf_SB.in | sed "s/S1_//g" | sed "s/_ALL_$suffix//g" > intf_SB_list.in 510 | rm intf_SB.in 511 | cp ../../date_$orb.txt date_no_master.txt 512 | sed -i "/\b\($master_date\)\b/d" date_no_master.txt 513 | 514 | mt_prep_gmtsar_SB $region $R $A $ov_R $ov_A $threshold $master_date $suffix $heading 515 | 516 | cd $dir 517 | 518 | fi 519 | 520 | # go to Step [15] 521 | if [ $step -eq 15 ]; then 522 | echo " " 523 | echo "INSAR_G2S STEP ---->>" $step 524 | echo "15 Fix the result of PS Candidates (SB)" 525 | echo "Path must be located on the batch_$orb/stack/PS/SMALL_BASELINES" 526 | echo " " 527 | 528 | echo " " 529 | echo "Working on SMALL_BASELINES directory" 530 | echo " " 531 | 532 | fix_pscands_SB.sh 533 | 534 | fi 535 | -------------------------------------------------------------------------------- /gmtsar_matlab/stamps.m: -------------------------------------------------------------------------------- 1 | function stamps(start_step,end_step,patches_flag,est_gamma_parm,patch_list_file,stamps_PART_limitation) 2 | %STAMPS Stanford Method for Persistent Scatterers 3 | % STAMPS(START_STEP,END_STEP,PATCHES_FLAG,EST_GAMMA_FLAG) Default is to run all steps. 4 | % A subset of steps may be selected with START_STEP and/or END_STEP 5 | % STEP 1 = Initial load of data 6 | % STEP 2 = Estimate gamma 7 | % STEP 3 = Select PS pixels 8 | % STEP 4 = Weed out adjacent pixels 9 | % STEP 5 = Correct wrapped phase for spatially-uncorrelated look angle error and merge patches 10 | % STEP 6 = Unwrap phase 11 | % STEP 7 = Calculate spatially correlated look angle (DEM) error 12 | % STEP 8 = Filter spatially correlated noise 13 | % STEP 0 = Continue from the last known stage till the end-stage selected 14 | % 15 | % PATCHES_FLAG Default 'y'. Set to 'n' to process all data as one patch 16 | % 17 | % EST_GAMMA_PARM is an optional parameter passed to PS_EST_GAMMA_QUICK 18 | % 19 | % PATCH_LIST_FILE is an optional argument specifying the file list of 20 | % patches to be processed. Note that from step 5 and above one should use 21 | % all patches to merge results. 22 | % 23 | % If current directory is a single patch, stamps only operates in the 24 | % current directory, but if current directory contains many patches, 25 | % stamps operates on them all. 26 | % 27 | % Andy Hooper, June 2006 28 | 29 | % ================================================================= 30 | % 07/2006 AH: END_STEP added 31 | % 09/2006 AH: ps_load removed (obsolete) 32 | % 09/2006 AH: small baselines added 33 | % 11/2006 AH: patches added 34 | % 01/2007 AH: calculate spatially correlated look angle error added 35 | % 03/2009 AH: simultaneously estimate velocity when SCLA estimated 36 | % 03/2009 AH: smooth SCLA for unwrapping iteration 37 | % 03/2010 AH: move ps_cal_ifg_std to after merge step 38 | % 12/2012 AH: add gamma option 39 | % 12/2012 DB: add patch_list_file argument as option 40 | % 09/2013 DB: update the stamps version number 41 | % 09/2015 DB: Check if patches do have PS before proceeding with 42 | % processing. 43 | % 09/2015 DB: Fix when running stamps in a patch folder mode when no PS are left 44 | % 09/2015 AH: allow for non-differentiation of caps by dir 45 | % 01/2016 DB: include stamps_save in step 1-4. 46 | % 08/2016 AH: Fix bug of scn_kriging_flag not being set 47 | % 06/2017 DB: Catching when no PS are left from step 1, allow for re-run 48 | % when parameters have changed. 49 | % 06/2017 DB: Option to continue from last know processing step 50 | % 08/2107 AH: Removed catch as proceeds also when error in Step 1 51 | % ================================================================= 52 | 53 | nfill=40; 54 | fillstr=[repmat('#',1,nfill),'\n']; 55 | skipstr='\n'; 56 | msgstr=fillstr; 57 | 58 | fprintf(skipstr); 59 | logit(fillstr); 60 | msgstr(round(nfill)/2-12:round(nfill/2)+13)=' StaMPS/MTI Version 4.0b6 '; 61 | logit(msgstr); 62 | msgstr(round(nfill)/2-12:round(nfill/2)+13)=' Beta version, Jun 2018 '; 63 | logit(msgstr); 64 | logit(fillstr); 65 | fprintf(skipstr); 66 | 67 | 68 | 69 | quick_est_gamma_flag=getparm('quick_est_gamma_flag'); 70 | reest_gamma_flag=getparm('select_reest_gamma_flag'); 71 | unwrap_method=getparm('unwrap_method'); 72 | unwrap_prefilter_flag=getparm('unwrap_prefilter_flag'); 73 | small_baseline_flag=getparm('small_baseline_flag'); 74 | insar_processor=getparm('insar_processor'); 75 | scn_kriging_flag=getparm('scn_kriging_flag'); 76 | 77 | if nargin<1 || isempty(start_step)==1 78 | start_step=1; 79 | end 80 | 81 | if nargin<2 || isempty(end_step)==1 82 | end_step=8; 83 | end 84 | 85 | if nargin<3 || isempty(patches_flag)==1 86 | if start_step<6 87 | patches_flag='y'; 88 | else 89 | patches_flag='n'; 90 | end 91 | end 92 | 93 | if nargin<4 || isempty(est_gamma_parm)==1 94 | est_gamma_parm=0; 95 | end 96 | 97 | if nargin<5 || isempty(patch_list_file) % [DB] allow for own specified patch list file 98 | patch_list_file = 'patch.list'; 99 | new_patch_file = 0; 100 | else 101 | % use own file 102 | new_patch_file = 1; 103 | end 104 | 105 | % In support of the multi-core option limit processing to steps 1-5a, 106 | % 5b-upwards, or the old method where all is processed together. 107 | if nargin<6 || isempty(stamps_PART_limitation) 108 | stamps_PART_limitation=0; 109 | end 110 | stamps_PART1_flag='y'; 111 | stamps_PART2_flag='y'; 112 | if stamps_PART_limitation==1 113 | stamps_PART2_flag='n'; 114 | end 115 | if stamps_PART_limitation==2 116 | stamps_PART1_flag='n'; 117 | end 118 | 119 | if strcmpi(patches_flag,'y') 120 | if exist(patch_list_file,'file') 121 | fid=fopen(patch_list_file); 122 | i=0; 123 | while 1 124 | nextline=fgetl(fid); 125 | if ischar(nextline) 126 | i=i+1; 127 | patchdir(i).name=nextline; 128 | else 129 | break 130 | end 131 | end 132 | fclose(fid) 133 | else 134 | patchdir=dir('PATCH_*'); 135 | patchdir = patchdir(find(~cellfun(@(x) strcmpi(x,'patch_noover.in'),{patchdir(:).name}))); 136 | end 137 | if isempty(patchdir) 138 | patches_flag='n'; 139 | else 140 | ps_parms_default 141 | patches_flag='y'; 142 | end 143 | end 144 | 145 | if ~strcmpi(patches_flag,'y') 146 | patchdir(1).name='.'; 147 | logit('Will process current directory only') 148 | else 149 | logit('Will process patch subdirectories') 150 | end 151 | 152 | currdir=pwd; 153 | 154 | nfill=40; 155 | fillstr=[repmat('#',1,nfill),'\n']; 156 | msgstr=fillstr; 157 | 158 | 159 | 160 | 161 | 162 | % limit the processing to step 1-5a 163 | start_step_or = start_step; 164 | if strcmpi(stamps_PART1_flag,'y') 165 | for i=1:length(patchdir) 166 | if ~isempty(patchdir(i).name) 167 | cd(patchdir(i).name) 168 | patchsplit=strsplit(pwd,'/'); 169 | %fprintf(skipstr); 170 | %logit(sprintf('Processing %s',patchsplit{end})) 171 | 172 | % store if patch dir is empty 173 | if exist('no_ps_info.mat','file')~=2 174 | stamps_step_no_ps = zeros([5 1 ]); % keep for the first 5 steps only 175 | save('no_ps_info.mat','stamps_step_no_ps') 176 | end 177 | 178 | 179 | % if start_step is 0, then start from the latest stage it was 180 | if start_step_or==0 181 | % check the processing stage of stamps for all the patches 182 | % step 4 find a ps_weed file 183 | % step 3 find a ps_select file 184 | % step 2 find a pm file 185 | % step 1 find a ps file 186 | % or no PS in case stamps_step_no_ps is found with a 1 in there 187 | 188 | if exist('weed1.mat','file')==2 189 | start_step=5; 190 | setpsver(2); 191 | elseif exist('select1.mat','file')==2 192 | start_step=4; 193 | elseif exist('pm1.mat','file')==2 194 | start_step=3; 195 | elseif exist('ps1.mat','file')==2 196 | start_step=2; 197 | else 198 | start_step=1; 199 | end 200 | 201 | if start_step>end_step 202 | fprintf(['\n' patchsplit{end} ': already up to end stage ' num2str(end_step) ' \n']) 203 | else 204 | fprintf(['\n' patchsplit{end} ': complete up to stage ' num2str(start_step-1) ' \n']) 205 | end 206 | end 207 | 208 | 209 | 210 | 211 | if start_step==1 212 | msgstr(round(nfill)/2-3:round(nfill/2)+4)=' Step 1 '; 213 | fprintf(skipstr); 214 | logit(fillstr); 215 | logit(msgstr); 216 | logit(fillstr) 217 | logit(['Directory is ',patchsplit{end}]) 218 | fprintf(skipstr); 219 | if strcmpi(small_baseline_flag,'y') 220 | % try 221 | if strcmpi(insar_processor,'gamma') | strcmpi(insar_processor,'snap') 222 | sb_load_initial_gamma; 223 | elseif strcmpi(insar_processor,'gsar') 224 | sb_load_initial_gsar; 225 | elseif strcmpi(insar_processor,'gmtsar') 226 | sb_load_initial_gmtsar; 227 | elseif strcmpi(insar_processor,'isce') 228 | if exist('data_inc','var')==0 229 | % already in patch dir, file contained in the InSAR dir 230 | inc_angle = ['..' filesep 'inc_angle.raw']; 231 | if exist(inc_angle,'file')~=2 232 | inc_angle = ['..' filesep inc_angle]; 233 | end 234 | if exist(inc_angle,'file')==2 235 | fprintf('Found inc angle file, will load the data \n') 236 | data_inc = (load_isce(inc_angle)); 237 | else 238 | data_inc=[]; 239 | end 240 | end 241 | sb_load_initial_isce(data_inc) 242 | else 243 | sb_load_initial; 244 | end 245 | load('no_ps_info.mat'); 246 | % reset as we are currently re-processing 247 | stamps_step_no_ps(1:end)=0; 248 | 249 | % catch 250 | % 251 | % load('no_ps_info.mat'); 252 | % % reset as we are currently re-processing 253 | % stamps_step_no_ps(1:end)=0; 254 | % fprintf('***No PS points left. Updating the stamps log for this****\n') 255 | % % update the flag indicating no PS left in step 1 256 | % stamps_step_no_ps(1)=1; 257 | % psver =1; 258 | % save('psver.mat','psver') 259 | % 260 | % end 261 | save('no_ps_info.mat','stamps_step_no_ps') 262 | 263 | else 264 | % try 265 | if strcmpi(insar_processor,'gamma') | strcmpi(insar_processor,'snap') 266 | ps_load_initial_gamma; 267 | elseif strcmpi(insar_processor,'gsar') 268 | ps_load_initial_gsar; 269 | elseif strcmpi(insar_processor,'gmtsar') 270 | ps_load_initial_gmtsar; 271 | elseif strcmpi(insar_processor,'isce') 272 | if exist('data_inc','var')==0 273 | % already in patch dir, file contained in the InSAR dir 274 | inc_angle = ['..' filesep 'inc_angle.raw']; 275 | if exist(inc_angle,'file')~=2 276 | inc_angle = ['..' filesep inc_angle]; 277 | end 278 | if exist(inc_angle,'file')==2 279 | fprintf('Found inc angle file, will load the data \n') 280 | data_inc = (load_isce(inc_angle)); 281 | else 282 | data_inc=[]; 283 | end 284 | end 285 | ps_load_initial_isce(data_inc) 286 | 287 | else 288 | ps_load_initial; 289 | end 290 | load('no_ps_info.mat'); 291 | % reset as we are currently re-processing 292 | stamps_step_no_ps(1:end)=0; 293 | % catch 294 | % load('no_ps_info.mat'); 295 | % % reset as we are currently re-processing 296 | % stamps_step_no_ps(1:end)=0; 297 | % fprintf('***No PS points left. Updating the stamps log for this****\n') 298 | % % update the flag indicating no PS left in step 1 299 | % stamps_step_no_ps(1)=1; 300 | % save('no_ps_info.mat','stamps_step_no_ps') 301 | % psver =1; 302 | % save('psver.mat','psver') 303 | % 304 | % end 305 | save('no_ps_info.mat','stamps_step_no_ps') 306 | end 307 | elseif start_step <=4 308 | setpsver(1) 309 | end 310 | 311 | 312 | 313 | 314 | if start_step<=2 & end_step >=2 315 | msgstr(round(nfill)/2-3:round(nfill/2)+4)=' Step 2 '; 316 | fprintf(skipstr); 317 | logit(fillstr); 318 | logit(msgstr); 319 | logit(fillstr) 320 | logit(['Directory is ',patchsplit{end}]) 321 | fprintf(skipstr); 322 | 323 | % check if step 1 had more than 0 PS points 324 | load('no_ps_info.mat'); 325 | % reset as we are currently re-processing 326 | stamps_step_no_ps(2:end)=0; 327 | 328 | % run step 2 when there are PS left in step 1 329 | if stamps_step_no_ps(1)==0 330 | if strcmpi(quick_est_gamma_flag,'y') 331 | ps_est_gamma_quick(est_gamma_parm); 332 | else 333 | ps_est_gamma(est_gamma_parm); 334 | end 335 | else 336 | stamps_step_no_ps(2)=1; 337 | fprintf('No PS left in step 1, so will skip step 2 \n') 338 | end 339 | save('no_ps_info.mat','stamps_step_no_ps') 340 | end 341 | 342 | if start_step<=3 & end_step >=3 343 | msgstr(round(nfill)/2-3:round(nfill/2)+4)=' Step 3 '; 344 | fprintf(skipstr); 345 | logit(fillstr); 346 | logit(msgstr); 347 | logit(fillstr) 348 | logit(['Directory is ',patchsplit{end}]) 349 | fprintf(skipstr); 350 | 351 | 352 | 353 | % check if step 2 had more than 0 PS points 354 | load('no_ps_info.mat'); 355 | % reset as we are currently re-processing 356 | stamps_step_no_ps(3:end)=0; 357 | 358 | % run step 3 when there are PS left in step 2 359 | if stamps_step_no_ps(2)==0 360 | if strcmpi(quick_est_gamma_flag,'y') & strcmpi(reest_gamma_flag,'y') 361 | ps_select; 362 | else 363 | ps_select(1); 364 | end 365 | else 366 | fprintf('No PS left in step 2, so will skip step 3 \n') 367 | stamps_step_no_ps(3)=1; 368 | end 369 | save('no_ps_info.mat','stamps_step_no_ps') 370 | end 371 | 372 | if start_step<=4 & end_step >=4 373 | msgstr(round(nfill)/2-3:round(nfill/2)+4)=' Step 4 '; 374 | fprintf(skipstr); 375 | logit(fillstr); 376 | logit(msgstr); 377 | logit(fillstr) 378 | logit(['Directory is ',patchsplit{end}]) 379 | fprintf(skipstr); 380 | 381 | % check if step 3 had more than 0 PS points 382 | load('no_ps_info.mat'); 383 | % reset as we are currently re-processing 384 | stamps_step_no_ps(4:end) =0; % keep for the first 5 steps only 385 | 386 | 387 | % run step 4 when there are PS left in step 3 388 | if stamps_step_no_ps(3)==0 389 | if strcmpi(small_baseline_flag,'y') 390 | ps_weed(0,1); 391 | else 392 | ps_weed; 393 | end 394 | else 395 | fprintf('No PS left in step 3, so will skip step 4 \n') 396 | stamps_step_no_ps(4)=1; 397 | 398 | end 399 | save('no_ps_info.mat','stamps_step_no_ps') 400 | end 401 | 402 | if start_step<=5 & end_step >=5 403 | msgstr(round(nfill)/2-3:round(nfill/2)+4)=' Step 5 '; 404 | fprintf(skipstr); 405 | logit(fillstr); 406 | logit(msgstr); 407 | logit(fillstr) 408 | logit(['Directory is ',patchsplit{end}]) 409 | fprintf(skipstr); 410 | 411 | 412 | % check if step 4 had more than 0 PS points 413 | load('no_ps_info.mat'); 414 | % reset as we are currently re-processing 415 | stamps_step_no_ps(5:end) = 0; % keep for the first 5 steps only 416 | 417 | % run step 5 when there are PS left in step 3 418 | if stamps_step_no_ps(4)==0 419 | ps_correct_phase; 420 | else 421 | fprintf('No PS left in step 4, so will skip step 5 \n') 422 | stamps_step_no_ps(5)=1; 423 | end 424 | save('no_ps_info.mat','stamps_step_no_ps') 425 | end 426 | 427 | 428 | cd(currdir) 429 | end 430 | end 431 | end 432 | 433 | patchsplit=strsplit(pwd,'/'); 434 | 435 | 436 | % check if one can process second part of step 5b and above 437 | if strcmpi(stamps_PART2_flag,'y') 438 | %%% Loop throught the patches and update the patch.list and keep only those 439 | %%% that have PS left. 440 | if patches_flag=='y' 441 | % go in reverse order such patches can be dropped when needed 442 | 443 | fid = fopen('patch.list_new','w'); 444 | for i=1:length(patchdir) 445 | % check the file with the PS information 446 | filename_PS_check = [patchdir(i).name filesep 'no_ps_info.mat']; 447 | 448 | % assume by default to keep patch for backward compatibility 449 | keep_patch = 1; 450 | if exist(filename_PS_check,'file')==2 451 | load(filename_PS_check) 452 | if sum(stamps_step_no_ps)>=1 453 | keep_patch=0; 454 | end 455 | end 456 | 457 | % update the patch list. 458 | if keep_patch==1 459 | fprintf(fid,[patchdir(i).name '\n']); 460 | end 461 | if i==length(patchdir) 462 | fclose(fid) ; 463 | end 464 | end 465 | 466 | % update the files such in futhre the new patch list will be used. 467 | movefile('patch.list','patch.list_old'); 468 | movefile('patch.list_new','patch.list'); 469 | end 470 | 471 | 472 | if start_step<=5 & end_step >=5 473 | abord_flag=0; 474 | if patches_flag=='y' 475 | fprintf(skipstr); 476 | logit(['Directory is ',patchsplit{end}]) 477 | fprintf(skipstr); 478 | ps_merge_patches 479 | else 480 | % this is processing of an individual patch 481 | % see if there are any PS left 482 | if exist('no_ps_info.mat','file')==2 483 | load('no_ps_info.mat') 484 | if sum(stamps_step_no_ps)>=1 485 | abord_flag=1; 486 | end 487 | end 488 | end 489 | 490 | % see if step 5 can be ran 491 | if abord_flag==0 492 | ps_calc_ifg_std; 493 | else 494 | fprintf('No PS left in step 4, so will skip step 5 \n') 495 | end 496 | end 497 | 498 | 499 | if start_step<=6 & end_step >=6 500 | msgstr(round(nfill)/2-3:round(nfill/2)+4)=' Step 6 '; 501 | fprintf(skipstr); 502 | logit(fillstr); 503 | logit(msgstr); 504 | logit(fillstr) 505 | logit(['Directory is ',patchsplit{end}]) 506 | fprintf(skipstr); 507 | 508 | ps_unwrap 509 | if strcmpi(small_baseline_flag,'y') 510 | sb_invert_uw 511 | end 512 | end 513 | 514 | if start_step<=7 & end_step >=7 515 | msgstr(round(nfill)/2-3:round(nfill/2)+4)=' Step 7 '; 516 | fprintf(skipstr); 517 | logit(fillstr); 518 | logit(msgstr); 519 | logit(fillstr) 520 | logit(['Directory is ',patchsplit{end}]) 521 | fprintf(skipstr); 522 | 523 | if strcmpi(small_baseline_flag,'y') 524 | ps_calc_scla(1,1) % small baselines 525 | ps_smooth_scla(1) 526 | ps_calc_scla(0,1) % single master 527 | else 528 | ps_calc_scla(0,1) 529 | ps_smooth_scla 530 | end 531 | end 532 | 533 | if start_step<=8 & end_step >=8 534 | msgstr(round(nfill)/2-3:round(nfill/2)+4)=' Step 8 '; 535 | fprintf(skipstr); 536 | logit(fillstr); 537 | logit(msgstr); 538 | logit(fillstr) 539 | logit(['Directory is ',patchsplit{end}]) 540 | fprintf(skipstr); 541 | 542 | if strcmpi(scn_kriging_flag,'y') 543 | ps_scn_filt_krig 544 | else 545 | ps_scn_filt 546 | end 547 | end 548 | end 549 | 550 | logit(1); 551 | --------------------------------------------------------------------------------