Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERS stack processing #736

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
20 changes: 11 additions & 9 deletions components/isceobj/Orbit/ODR.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,17 @@ def parse(self):

def parseLine(self,line):
arc = Arc()
arc.number = line[0:3] # Arc number
arc.start = datetime.datetime.strptime(line[5:17],'%y%m%d %H:%M') # Starting time for the arc
arc.stop = datetime.datetime.strptime(line[20:32],'%y%m%d %H:%M') # End time for the arc
arc.slrResidual = line[34:38] # Satellite laser ranging residual in cm
arc.crossOver = line[39:43]
arc.altimeter = line[45:49]
arc.repeat = line[51:57] # Repeat cycle in days
arc.version = line[58:61] # Version number
arc.precise = datetime.datetime.strptime(line[63:78],'%y%m%d %H:%M:%S') # Starting time of the precise segment of the arc
###### Change to also work for the new arclist format in the recalcuated ODR orbit files.#######
arc.number = line.split()[0] # Arc number
arc.start = datetime.datetime.strptime(" ".join(line.split()[1:3]),'%y%m%d %H:%M') # Starting time for the arc
arc.stop = datetime.datetime.strptime(" ".join(line.split()[4:6]),'%y%m%d %H:%M') # End time for the arc
###### commented the following because it is not always present in the new arclist file ############
# arc.slrResidual = line[34:38] # Satellite laser ranging residual in cm
# arc.crossOver = line[39:43]
# arc.altimeter = line[45:49]
# arc.repeat = line[51:57] # Repeat cycle in days
# arc.version = line[58:61] # Version number
Comment on lines +191 to +196
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the commented code.

arc.precise = datetime.datetime.strptime(" ".join(line.split()[-2:]),'%y%m%d %H:%M:%S') # Starting time of the precise segment of the arc

return arc

Expand Down
119 changes: 119 additions & 0 deletions contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env python3

import isce
from isceobj.Sensor import createSensor
import isceobj
import shelve
import argparse
import glob
from isceobj.Util import Poly1D
from isceobj.Planet.AstronomicalHandbook import Const
import os
import datetime
import numpy as np

def cmdLineParse():
'''
Command line parser.
'''

parser = argparse.ArgumentParser(description='Unpack ERS(ESA) SLC data and store metadata in pickle file.')
parser.add_argument('-i','--input', dest='datadir', type=str,
required=True, help='Input ERS files path')
parser.add_argument('-b', '--box' ,dest='bbox', type=float, nargs=4, default=None,
help='Bbox (SNWE in degrees)')
parser.add_argument('-o', '--output', dest='slcdir', type=str,
required=True, help='Output SLC directory')
parser.add_argument('--orbitdir', dest='orbitdir', type=str, required=True, help='Orbit directory')
parser.add_argument('--orbittype',dest='orbittype', type = str, default='ODR', help='ODR, PDS, PDS')
return parser.parse_args()

def get_Date(file):
yyyymmdd=file[14:22]
return yyyymmdd

def write_xml(shelveFile, slcFile):
with shelve.open(shelveFile,flag='r') as db:
frame = db['frame']

length = frame.numberOfLines
width = frame.numberOfSamples
print (width,length)

slc = isceobj.createSlcImage()
slc.setWidth(width)
slc.setLength(length)
slc.filename = slcFile
slc.setAccessMode('write')
slc.renderHdr()
slc.renderVRT()

def unpack(fname, slcname, orbitdir, orbittype):
'''
Unpack .E* file to binary SLC file.
'''

obj = createSensor('ERS_ENviSAT_SLC')
obj._imageFileName = fname
obj._orbitDir = orbitdir
obj._orbitType = orbittype
#obj.instrumentDir = '/Users/agram/orbit/INS_DIR'
obj.output = os.path.join(slcname,os.path.basename(slcname)+'.slc')
obj.extractImage()
obj.frame.getImage().renderHdr()
obj.extractDoppler()

# #### computation of "poly" adapted from line 339 - line 353 of Components/isceobj/Sensor/ERS_EnviSAT_SLC.py ###
####### removed this section and added obj.extractDoppler() above instead. Doesn't seem to change anything in the processing. The latter is required for cropFrame.
# coeffs = obj.dopplerRangeTime
# dr = obj.frame.getInstrument().getRangePixelSize()
# rref = 0.5 * Const.c * obj.rangeRefTime
# r0 = obj.frame.getStartingRange()
# norm = 0.5 * Const.c / dr

# dcoeffs = []
# for ind, val in enumerate(coeffs):
# dcoeffs.append( val / (norm**ind))

# poly = Poly1D.Poly1D()
# poly.initPoly(order=len(coeffs)-1)
# poly.setMean( (rref - r0)/dr - 1.0)
# poly.setCoeffs(dcoeffs)
Comment on lines +66 to +81
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove commented code.



pickName = os.path.join(slcname, 'data')
with shelve.open(pickName) as db:
db['frame'] = obj.frame
# db['doppler'] = poly


if __name__ == '__main__':
'''
Main driver.
'''

inps = cmdLineParse()
if inps.slcdir.endswith('/'):
inps.slcdir = inps.slcdir[:-1]
if not os.path.isdir(inps.slcdir):
os.mkdir(inps.slcdir)
for fname in glob.glob(os.path.join(inps.datadir, '*.E*')):
date = get_Date(os.path.basename(fname))
slcname = os.path.abspath(os.path.join(inps.slcdir, date))
os.makedirs(slcname, exist_ok=True)

print(fname)
unpack(fname, slcname, inps.orbitdir, inps.orbittype)

slcFile = os.path.abspath(os.path.join(slcname, date+'.slc'))

shelveFile = os.path.join(slcname, 'data')
write_xml(shelveFile,slcFile)

if inps.bbox is not None:
slccropname = os.path.abspath(os.path.join(inps.slcdir+'_crop',date))
os.makedirs(slccropname, exist_ok=True)
cmd = 'cropFrame.py -i {} -o {} -b {}'.format(slcname, slccropname, ' '.join([str(x) for x in inps.bbox]))
print(cmd)
os.system(cmd)