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

support for alosStack in ISCE #464

Merged
merged 3 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/api/module_hierarchy.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Hierarchy of sub-modules within MintPy. Level N modules depends on level N-1, N-
/utils
plot (objects/{stack, coord, colors}, utils/{ptime, utils0, utils1, readfile, network})
utils (objects/{stack, coord}, utils/{ptime, utils0, utils1, readfile})
isce_utils (utils/{readfile, writefile, utils1})
isce_utils (utils/{ptime, readfile, writefile, utils1})
------------------ level 6 --------------------
/objects
insar_vs_gps (objects/{stack, giant}, utils/{readfile, gps, plot, utils})
Expand Down
26 changes: 26 additions & 0 deletions docs/examples/input_files/NCalAlos2Scan.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# vim: set filetype=cfg:
##-------------------------------- MintPy -----------------------------##
########## 1. Load Data (--load to exit after this step)
## load_data.py -H to check more details and example inputs.
mintpy.load.processor = isce
##NOTE: 150408 is the reference date of alosStack processing.
## (parameter "reference date of the stack" of alosStack input xml file)
##---------for ISCE only:
mintpy.load.metaFile = ../pairs/*-*/150408.track.xml
mintpy.load.baselineDir = ../baseline
##---------interferogram datasets:
mintpy.load.unwFile = ../pairs/*-*/insar/filt_*-*_5rlks_28alks.unw
mintpy.load.corFile = ../pairs/*-*/insar/*-*_5rlks_28alks.cor
mintpy.load.connCompFile = ../pairs/*-*/insar/filt_*-*_5rlks_28alks.unw.conncomp
##---------geometry datasets:
mintpy.load.demFile = ../dates_resampled/150408/insar/*_5rlks_28alks.hgt
mintpy.load.lookupYFile = ../dates_resampled/150408/insar/*_5rlks_28alks.lat
mintpy.load.lookupXFile = ../dates_resampled/150408/insar/*_5rlks_28alks.lon
mintpy.load.incAngleFile = ../dates_resampled/150408/insar/*_5rlks_28alks.los
mintpy.load.azAngleFile = ../dates_resampled/150408/insar/*_5rlks_28alks.los
mintpy.load.waterMaskFile = ../dates_resampled/150408/insar/*_5rlks_28alks.wbd

mintpy.reference.yx = 1500, 200
mintpy.networkInversion.weightFunc = no
mintpy.topographicResidual.pixelwiseGeometry = no

9 changes: 8 additions & 1 deletion mintpy/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,12 @@ def prepare_metadata(inpsDict):

elif processor == 'isce':
from mintpy import prep_isce
from mintpy.utils.isce_utils import get_processor

meta_files = sorted(glob.glob(inpsDict['mintpy.load.metaFile']))
if len(meta_files) < 1:
warnings.warn('No input metadata file found: {}'.format(inpsDict['mintpy.load.metaFile']))

try:
# metadata and auxliary data
meta_file = meta_files[0]
Expand All @@ -597,7 +600,11 @@ def prepare_metadata(inpsDict):
obs_keys = [i for i in obs_keys if i in inpsDict.keys()]
obs_paths = [inpsDict[key] for key in obs_keys if inpsDict[key].lower() != 'auto']
if len(obs_paths) > 0:
obs_dir = os.path.dirname(os.path.dirname(obs_paths[0]))
processor = get_processor(meta_file)
if processor == 'alosStack':
obs_dir = os.path.dirname(obs_paths[0])
else:
obs_dir = os.path.dirname(os.path.dirname(obs_paths[0]))
obs_file = os.path.basename(obs_paths[0])
else:
obs_dir = None
Expand Down
12 changes: 12 additions & 0 deletions mintpy/objects/stackDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ class geometryDict:
'incidenceAngle':'$PROJECT_DIR/merged/geom_reference/los.rdr',
'heandingAngle' :'$PROJECT_DIR/merged/geom_reference/los.rdr',
'shadowMask' :'$PROJECT_DIR/merged/geom_reference/shadowMask.rdr',
'waterMask' :'$PROJECT_DIR/merged/geom_reference/waterMask.rdr',
'bperp' :bperpDict
...
}
Expand Down Expand Up @@ -507,7 +508,18 @@ def write2hdf5(self, outputFile='geometryRadar.h5', access_mode='w', box=None, c
t=str(dsDataType),
s=dsShape,
c=str(compression)))

# read
data = np.array(self.read(family=dsName, box=box)[0], dtype=dsDataType)
# water body: -1 for water and 0 for land
# water mask: 0 for water and 1 for land
fname = os.path.basename(self.datasetDict[dsName])
if fname.startswith('waterBody') or fname.endswith('.wbd'):
data = data > -0.5
print((' input file "{}" is water body (-1/0 for water/land), '
'convert to water mask (0/1 for water/land).'.format(fname)))

# write
ds = f.create_dataset(dsName,
data=data,
chunks=True,
Expand Down
102 changes: 71 additions & 31 deletions mintpy/prep_isce.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@

EXAMPLE = """example:
# interferogram stack
prep_isce.py -d ./merged/interferograms -m ./reference/IW1.xml -b ./baselines -g ./merged/geom_reference #for topsStack
prep_isce.py -d ./Igrams -m ./referenceShelve/data.dat -b ./baselines -g ./geom_reference #for stripmapStack
prep_isce.py -m 20120507_slc_crop.xml -g ./geometry #for stripmapApp
prep_isce.py -d ./merged/interferograms -m ./reference/IW1.xml -b ./baselines -g ./merged/geom_reference #for topsStack
prep_isce.py -d ./Igrams -m ./referenceShelve/data.dat -b ./baselines -g ./geom_reference #for stripmapStack
prep_isce.py -m 20120507_slc_crop.xml -g ./geometry #for stripmapApp

# 150408 is the reference date of alosStack processing
prep_isce.py -d "pairs/*-*/insar" -m "pairs/*-*/150408.track.xml" -b baseline -g dates_resampled/150408/insar #for alosStack

# offset stack from topsStack
prep_isce.py -d ./merged/offsets -f filtAz*.off -m ./reference/IW1.xml -b ./baselines -g ./merged/offsets/geom_reference
Expand All @@ -33,22 +36,22 @@ def create_parser():
parser = argparse.ArgumentParser(description='Prepare ISCE metadata files.',
formatter_class=argparse.RawTextHelpFormatter,
epilog=EXAMPLE)
parser.add_argument('-d', '--ds-dir', '--dset-dir', dest='dsetDir', type=str, default=None,
parser.add_argument('-d', '--ds-dir', '--dset-dir', dest='dsetDir', type=str, default=None, required=True,
help='The directory which contains all pairs\n'
'e.g.: $PROJECT_DIR/merged/interferograms OR \n'
' $PROJECT_DIR/pairs/*-*/insar OR \n'
' $PROJECT_DIR/merged/offsets')
parser.add_argument('-f', '--file-pattern', nargs = '+', dest='dsetFiles', type=str,
default=['filt_*.unw'],
help='A list of files that will be used in mintpy\n'
'e.g.: filt_fine.unw filt_fine.cor OR\n'
' filtAz*.off filtRa*.off')
parser.add_argument('-m', '--meta-file', dest='metaFile', type=str, default=None,
parser.add_argument('-f', '--file-pattern', nargs = '+', dest='dsetFiles', type=str, default=['filt_*.unw'],
help='List of observation files, e.g.: filt_fine.unw OR filtAz*.off')
parser.add_argument('-m', '--meta-file', dest='metaFile', type=str, default=None, required=True,
help='Metadata file to extract common metada for the stack:\n'
'e.g.: for ISCE/topsStack: reference/IW3.xml;\n'
' for ISCE/stripmapStack: referenceShelve/data.dat')
'e.g.: for ISCE/topsStack : reference/IW3.xml;\n'
' for ISCE/stripmapStack: referenceShelve/data.dat;\n'
' for ISCE/alosStack : pairs/150408-150701/150408.track.xml\n'
' where 150408 is the reference date of stack processing')
parser.add_argument('-b', '--baseline-dir', dest='baselineDir', type=str, default=None,
help=' directory with baselines ')
parser.add_argument('-g', '--geometry-dir', dest='geometryDir', type=str, default=None,
parser.add_argument('-g', '--geometry-dir', dest='geometryDir', type=str, default=None, required=True,
help=' directory with geometry files ')
parser.add_argument('--force', dest='update_mode', action='store_false',
help='Force to overwrite all .rsc metadata files.')
Expand All @@ -58,9 +61,15 @@ def create_parser():
def cmd_line_parse(iargs = None):
parser = create_parser()
inps = parser.parse_args(args=iargs)
if all(not i for i in [inps.dsetDir, inps.geometryDir, inps.metaFile]):
parser.print_usage()
raise SystemExit('ERROR: at least one of the following arguments are required: -i, -g, -m')

# translate wildcard in metaFile
if "*" in inps.metaFile:
fnames = glob.glob(inps.metaFile)
if len(fnames) > 0:
inps.metaFile = fnames[0]
else:
raise FileNotFoundError(inps.metaFile)

return inps


Expand Down Expand Up @@ -89,17 +98,32 @@ def add_ifgram_metadata(metadata_in, dates=[], baseline_dict={}):
return metadata


def prepare_geometry(geom_dir, metadata=dict(), update_mode=True):
def prepare_geometry(geom_dir, metadata=dict(), processor='tops', update_mode=True):
"""Prepare and extract metadata from geometry files"""

print('prepare .rsc file for geometry files')
geom_dir = os.path.abspath(geom_dir)

# grab all existed files
isce_files = [os.path.join(os.path.abspath(geom_dir), '{}.rdr'.format(i))
for i in ['hgt','lat','lon','los','shadowMask','incLocal']]
isce_files = [i for i in isce_files if os.path.isfile(i)]
if len(isce_files) == 0:
isce_files = [os.path.join(os.path.abspath(geom_dir), '{}.rdr.full'.format(i))
for i in ['hgt','lat','lon','los','shadowMask','incLocal']]
if processor in ['tops', 'stripmap']:
fbases = ['hgt', 'lat', 'lon', 'los', 'shadowMask', 'incLocal']
isce_files = [os.path.join(geom_dir, '{}.rdr'.format(i)) for i in fbases]
isce_files = [i for i in isce_files if os.path.isfile(i)]
if len(isce_files) == 0:
isce_files = [os.path.join(geom_dir, '{}.rdr.full'.format(i)) for i in fbases]
isce_files = [i for i in isce_files if os.path.isfile(i)]

elif processor in ['alosStack']:
alooks = metadata['ALOOKS']
rlooks = metadata['RLOOKS']
isce_files = glob.glob(os.path.join(geom_dir, '*_{}rlks_{}alks.hgt'.format(rlooks, alooks)))+\
glob.glob(os.path.join(geom_dir, '*_{}rlks_{}alks.lat'.format(rlooks, alooks)))+\
glob.glob(os.path.join(geom_dir, '*_{}rlks_{}alks.lon'.format(rlooks, alooks)))+\
glob.glob(os.path.join(geom_dir, '*_{}rlks_{}alks.los'.format(rlooks, alooks)))+\
glob.glob(os.path.join(geom_dir, '*_{}rlks_{}alks.wbd'.format(rlooks, alooks)))

else:
raise Exception('unknown processor: {}'.format(processor))

# write rsc file for each file
for isce_file in isce_files:
Expand All @@ -115,12 +139,18 @@ def prepare_geometry(geom_dir, metadata=dict(), update_mode=True):
writefile.write_roipac_rsc(geom_metadata, rsc_file,
update_mode=update_mode,
print_msg=True)
return metadata
return


def prepare_stack(inputDir, filePattern, metadata=dict(), baseline_dict=dict(), update_mode=True):
def prepare_stack(inputDir, filePattern, metadata=dict(), baseline_dict=dict(), processor='tops', update_mode=True):
print('prepare .rsc file for ', filePattern)
isce_files = sorted(glob.glob(os.path.join(os.path.abspath(inputDir), '*', filePattern)))
if processor in ['tops', 'stripmap']:
isce_files = sorted(glob.glob(os.path.join(os.path.abspath(inputDir), '*', filePattern)))
elif processor == 'alosStack':
isce_files = sorted(glob.glob(os.path.join(os.path.abspath(inputDir), filePattern)))
else:
raise ValueError('Un-recognized ISCE stack processor: {}'.format(processor))

if len(isce_files) == 0:
raise FileNotFoundError('no file found in pattern: {}'.format(filePattern))

Expand All @@ -130,7 +160,14 @@ def prepare_stack(inputDir, filePattern, metadata=dict(), baseline_dict=dict(),
for i in range(num_file):
# prepare metadata for current file
isce_file = isce_files[i]
dates = os.path.basename(os.path.dirname(isce_file)).split('_') # to modify to YYYYMMDDTHHMMSS
if processor in ['tops', 'stripmap']:
dates = os.path.basename(os.path.dirname(isce_file)).split('_') # to modify to YYYYMMDDTHHMMSS
elif processor == 'alosStack':
dates = os.path.basename(os.path.dirname(os.path.dirname(isce_file))).split('-') # to modify to YYYYMMDDTHHMMSS
dates = ptime.yyyymmdd(dates)
else:
raise ValueError('Un-recognized ISCE stack processor: {}'.format(processor))

ifg_metadata = readfile.read_attribute(isce_file, metafile_ext='.xml')
ifg_metadata.update(metadata)
ifg_metadata = add_ifgram_metadata(ifg_metadata, dates, baseline_dict)
Expand Down Expand Up @@ -161,9 +198,10 @@ def main(iargs=None):

# prepare metadata for geometry file
if inps.geometryDir:
metadata = prepare_geometry(inps.geometryDir,
metadata=metadata,
update_mode=inps.update_mode)
prepare_geometry(inps.geometryDir,
metadata=metadata,
processor=inps.processor,
update_mode=inps.update_mode)

# read baseline info
baseline_dict = {}
Expand All @@ -174,9 +212,11 @@ def main(iargs=None):
# prepare metadata for ifgram file
if inps.dsetDir and inps.dsetFiles:
for namePattern in inps.dsetFiles:
prepare_stack(inps.dsetDir, namePattern,
prepare_stack(inps.dsetDir,
namePattern,
metadata=metadata,
baseline_dict=baseline_dict,
processor=inps.processor,
update_mode=inps.update_mode)
print('Done.')
return
Expand Down
Loading