Files

137 lines
5.6 KiB
Python

#! /usr/bin/env python
#################################################################
### This program is part of PyINT v2.1 ###
### Copy Right (c): 2017-2019, Yunmeng Cao ###
### Author: Wei Chen ###
### Contact : chenweicug@gmail.com ###
#################################################################
import numpy as np
import os
import sys
import argparse
import subprocess
from pyint import _utils as ut
def cmdLineParse():
parser = argparse.ArgumentParser(description='Coregister SM mode SLC to a reference SLC image using GAMMA.',\
formatter_class=argparse.RawTextHelpFormatter,\
epilog=INTRODUCTION+'\n'+EXAMPLE)
parser.add_argument('projectName', help='Name of project.')
parser.add_argument('mdate', help='date of the slave SLC image')
parser.add_argument('sdate', help='date of the slave SLC image')
inps = parser.parse_args()
return inps
INTRODUCTION = '''
-------------------------------------------------------------------
create_files for psokinv software running file by generated by Gamma
'''
EXAMPLE = """Usage:
coreg_gamma.py projectName
coreg_gamma.py PacayaT163TsxHhA
-------------------------------------------------------------------
"""
def main(argv):
inps = cmdLineParse()
projectName = inps.projectName
Sdate = inps.sdate
Mdate = inps.mdate
scratchDir = os.getenv('SCRATCHDIR')
templateDir = os.getenv('TEMPLATEDIR')
templateFile = templateDir + "/" + projectName + ".template"
templateDict=ut.update_template(templateFile)
rlks = templateDict['range_looks']
azlks = templateDict['azimuth_looks']
Smdate = templateDict['masterDate']
demDir = scratchDir + '/' + projectName + '/DEM'
slcDir = scratchDir + '/' + projectName + "/SLC"
rslcDir = scratchDir + '/' + projectName + "/RSLC"
ifgramDir = scratchDir + '/' + projectName + "/ifgrams"
workDir = ifgramDir + '/' + Mdate + '-' + Sdate
MslcDir = rslcDir + '/' + Mdate
SslcDir = rslcDir + '/' + Sdate
offpar = SslcDir + '/' + Smdate + '_' + Sdate + '.off'
slcpar = MslcDir + '/' + Smdate + '.rslc.par'
dempar = demDir + '/' + Smdate + '_' + rlks + 'rlks.utm.dem.par'
dem = demDir + '/' + Smdate + '_' + rlks + 'rlks.utm.dem'
unwpar = demDir + '/' + Mdate + '_' + rlks + 'rlks.utm.dem.par'
unw = workDir + '/geo_' + Mdate + '-' + Sdate + "_" + rlks+"rlks.diff_filt.unw"
os.chdir(workDir)
call_str = "look_vector " + slcpar+ " " + offpar + " " + dempar + " " + dem + ' lv_theta lv_phi'
os.system(call_str)
call_str = "grep 'corner_lat:' " + dempar + " | awk '{print $2}' "
North=subprocess.getstatusoutput(call_str)[1]
call_str = "grep 'corner_lon:' " + dempar + " | awk '{print $2}' "
West=subprocess.getstatusoutput(call_str)[1]
call_str = "grep 'post_lat:' " + dempar + " | awk '{print $2}' "
posty=subprocess.getstatusoutput(call_str)[1]
call_str = "grep 'post_lon:' " + dempar + " | awk '{print $2}' "
postx=subprocess.getstatusoutput(call_str)[1]
call_str = "grep 'width:' " + dempar + " | awk '{print $2}' "
width=subprocess.getstatusoutput(call_str)[1]
call_str = "grep 'nlines:' " + dempar + " | awk '{print $2}' "
length=subprocess.getstatusoutput(call_str)[1]
South=str(round(float(North)+(float(length)-1)*float(posty),7))
East=str(round(float(West)+(float(width)-1)*float(postx),7))
call_str = "swap_bytes " + unw+ " unw.phase_swap 4 >dinsar.log "
os.system(call_str)
call_str = "gmt xyz2grd unw.phase_swap -Gunw_f.grd -Ddegree/degree/cm/1/0/=/= -R" + West + "/" + East + "/" +South + "/" +North + " -I" + postx +" -ZTLf -N0"
os.system(call_str)
call_str = "gmt grdsample unw_f.grd -Gunw.grd -I3c"
os.system(call_str)
call_str = "gmt grd2xyz unw.grd -ZTLf -N0 > " + Mdate + '-' + Sdate + '.unw'
os.system(call_str)
call_str = "gmt grdinfo unw.grd -C | awk '{print $10}' "
Width=subprocess.getstatusoutput(call_str)[1]
call_str = "gmt grdinfo unw.grd -C | awk '{print $11}' "
line=subprocess.getstatusoutput(call_str)[1]
call_str = "gmt grdinfo unw.grd -C | awk '{print $2}' "
West=subprocess.getstatusoutput(call_str)[1]
call_str = "gmt grdinfo unw.grd -C | awk '{print $5}' "
North=subprocess.getstatusoutput(call_str)[1]
ymax=str(int(round(float(line) ,7)))
xmax=str(int(round(float(Width) ,7)))
output=workDir + '/' + Mdate + '-' + Sdate + '.gacos.unw.rsc'
if os.path.exists(output) is True:
os.remove(output)
fopen=open(output,'a+')
fopen.write('WIDTH ' + Width + '\n')
fopen.write('FILE_LENGTH ' + line + '\n')
fopen.write('XMIN 1' + '\n')
fopen.write('XMAX ' + xmax + '\n')
fopen.write('YMIN 1' + '\n')
fopen.write('YMAX ' + ymax + '\n')
fopen.write('X_FIRST ' + West + '\n')
fopen.write('Y_FIRST ' + North + '\n')
fopen.write('X_STEP 8.33333333E-04' + '\n')
fopen.write('Y_STEP -8.33333333E-04' + '\n')
fopen.write('X_UNIT degrees' + '\n')
fopen.write('Y_UNIT degrees' + '\n')
fopen.write('Z_OFFSET 0' + '\n')
fopen.write('Z_SCALE 1' + '\n')
fopen.write('PROJECTION LATLON' + '\n')
fopen.write('DATUM WGS84' + '\n')
print("convert gamma products to GACOS is done!")
sys.exit(1)
if __name__ == '__main__':
main(sys.argv[:])