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

Geogrid update for post-processing correction #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 57 additions & 4 deletions testGeogrid_ISCE.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def cmdLineParse():
help='Input stable surface mask')
parser.add_argument('-fo', '--flag_optical', dest='optical_flag', type=bool, required=False, default=0,
help='flag for reading optical data (e.g. Landsat): use 1 for on and 0 (default) for off')
parser.add_argument('-b', '--buffer', dest='buffer', type=bool, required=False, default=0,
help='buffer to add to the starting/end range accounting for all passes from the same relative orbit')
parser.add_argument('-p', '--parse', dest='parse', action='store_true',
default=False, help='Parse the SAFE zip file to get radar image and orbit metadata; no need to run ISCE')
Comment on lines +72 to +73
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
parser.add_argument('-p', '--parse', dest='parse', action='store_true',
default=False, help='Parse the SAFE zip file to get radar image and orbit metadata; no need to run ISCE')
parser.add_argument('-p', '--parse', dest='parse', action='store_true',
default=False, help='Parse the SAFE zip file to get radar image and orbit metadata; no need to run ISCE')
parser.add_argument('--orbit-dir', hep='Directory of Sentinel-1 orbit files')
parser.add_argument('--aux-dir', hep='Directory of Sentinel-1 aux files')


return parser.parse_args()

Expand Down Expand Up @@ -113,7 +117,7 @@ def getMergedOrbit(product):
return orb


def loadMetadata(indir):
def loadMetadata(indir,buffer=0):
'''
Input file.
'''
Expand All @@ -135,12 +139,57 @@ def loadMetadata(indir):
info.prf = 1.0 / frames[0].bursts[0].azimuthTimeInterval
info.rangePixelSize = frames[0].bursts[0].rangePixelSize
info.lookSide = -1

info.startingRange -= buffer * info.rangePixelSize
info.farRange += buffer * info.rangePixelSize

info.numberOfLines = int( np.round( (info.sensingStop - info.sensingStart).total_seconds() * info.prf)) + 1
info.numberOfSamples = int( np.round( (info.farRange - info.startingRange)/info.rangePixelSize)) + 1
info.numberOfSamples = int( np.round( (info.farRange - info.startingRange)/info.rangePixelSize)) + 1 + 2 * buffer
info.orbit = getMergedOrbit(frames)

return info

def loadParsedata(indir,buffer=0):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def loadParsedata(indir,buffer=0):
def loadParsedata(indir, orbit_dir, aux_dir, buffer=0):

'''
Input file.
'''
import os
import numpy as np
import isce
from isceobj.Sensor.TOPS.Sentinel1 import Sentinel1


frames = []
for swath in range(1,4):
rdr=Sentinel1()
rdr.configure()
# rdr.safe=['./S1A_IW_SLC__1SDH_20180401T100057_20180401T100124_021272_024972_8CAF.zip']
rdr.safe=[indir]
rdr.output='reference'
rdr.orbitDir='/Users/yanglei/orbit/S1A/precise'
rdr.auxDir='/Users/yanglei/orbit/S1A/aux'
Comment on lines +169 to +170
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
rdr.orbitDir='/Users/yanglei/orbit/S1A/precise'
rdr.auxDir='/Users/yanglei/orbit/S1A/aux'
rdr.orbitDir=orbit_dir
rdr.auxDir='aux_dir

These are hard-coded to your system, so they'll need to be input parameters.

rdr.swathNumber=swath
rdr.polarization='hh'
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also hard-coded and should be parsed from the SLC name. Can use a function like:

from typing import Tuple
from pathlib import Path


def get_polarizations(s1_safe: str) -> Tuple[str]:
    mapping = {
        'SH': ('hh',),
        'SV': ('vv',),
        'DH': ('hh', 'hv'),
        'DV': ('vv', 'vh'),
    }
    key = Path(s1_safe).name[14:16]
    return mapping[key]

and selected like:

Suggested change
rdr.polarization='hh'
rdr.polarization=get_polarizations(indir)[0]

rdr.parse()
frames.append(rdr.product)

info = Dummy()
info.sensingStart = min([x.sensingStart for x in frames])
info.sensingStop = max([x.sensingStop for x in frames])
info.startingRange = min([x.startingRange for x in frames])
info.farRange = max([x.farRange for x in frames])
info.prf = 1.0 / frames[0].bursts[0].azimuthTimeInterval
info.rangePixelSize = frames[0].bursts[0].rangePixelSize
info.lookSide = -1

info.startingRange -= buffer * info.rangePixelSize
info.farRange += buffer * info.rangePixelSize

info.numberOfLines = int( np.round( (info.sensingStop - info.sensingStart).total_seconds() * info.prf)) + 1
info.numberOfSamples = int( np.round( (info.farRange - info.startingRange)/info.rangePixelSize)) + 1 + 2 * buffer
info.orbit = getMergedOrbit(frames)

return info

def coregisterLoadMetadataOptical(indir_m, indir_s):
'''
Expand Down Expand Up @@ -383,8 +432,12 @@ def main():
metadata_m, metadata_s = coregisterLoadMetadataOptical(inps.indir_m, inps.indir_s)
runGeogridOptical(metadata_m, metadata_s, inps.demfile, inps.dhdxfile, inps.dhdyfile, inps.vxfile, inps.vyfile, inps.srxfile, inps.sryfile, inps.csminxfile, inps.csminyfile, inps.csmaxxfile, inps.csmaxyfile, inps.ssmfile)
else:
metadata_m = loadMetadata(inps.indir_m)
metadata_s = loadMetadata(inps.indir_s)
if inps.parse:
metadata_m = loadParsedata(inps.indir_m,inps.buffer)
metadata_s = loadParsedata(inps.indir_s,inps.buffer)
Comment on lines +436 to +437
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
metadata_m = loadParsedata(inps.indir_m,inps.buffer)
metadata_s = loadParsedata(inps.indir_s,inps.buffer)
metadata_m = loadParsedata(inps.indir_m, inps.orbit_dir, inputs.aux_dir, inps.buffer)
metadata_s = loadParsedata(inps.indir_s, inps.orbit_dir, inputs.aux_dir, inps.buffer)

else:
metadata_m = loadMetadata(inps.indir_m,inps.buffer)
metadata_s = loadMetadata(inps.indir_s,inps.buffer)
runGeogrid(metadata_m, metadata_s, inps.demfile, inps.dhdxfile, inps.dhdyfile, inps.vxfile, inps.vyfile, inps.srxfile, inps.sryfile, inps.csminxfile, inps.csminyfile, inps.csmaxxfile, inps.csmaxyfile, inps.ssmfile)


Expand Down