Skip to content

Commit

Permalink
add prep_nisar to load NISAR GUNW products (#1035)
Browse files Browse the repository at this point in the history
* add `prep_nisar.py` and `cli/prep_nisar.py` to prepare and load NISAR GUNW products into HDF5/MintPy format.

* add `prep_nisar` to `setup` and `__main__`

---------

Co-authored-by: Scott Staniewicz <[email protected]>
Co-authored-by: Zhang Yunjun <[email protected]>
  • Loading branch information
3 people authored Sep 8, 2023
1 parent 7ff149b commit ce93e2e
Show file tree
Hide file tree
Showing 7 changed files with 558 additions and 5 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
'prep_gmtsar.py = mintpy.cli.prep_gmtsar:main',
'prep_hyp3.py = mintpy.cli.prep_hyp3:main',
'prep_isce.py = mintpy.cli.prep_isce:main',
'prep_nisar.py = mintpy.cli.prep_nisar:main',
'prep_roipac.py = mintpy.cli.prep_roipac:main',
'prep_snap.py = mintpy.cli.prep_snap:main',
'reference_date.py = mintpy.cli.reference_date:main',
Expand Down
8 changes: 8 additions & 0 deletions src/mintpy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ def get_prep_isce_parser(subparsers=None):
return parser


def get_prep_nisar_parser(subparsers=None):
from mintpy.cli import prep_nisar
parser = prep_nisar.create_parser(subparsers)
parser.set_defaults(func=prep_nisar.main)
return parser


def get_prep_roipac_parser(subparsers=None):
from mintpy.cli import prep_roipac
parser = prep_roipac.create_parser(subparsers)
Expand Down Expand Up @@ -628,6 +635,7 @@ def get_parser():
get_prep_gmtsar_parser(sp)
get_prep_hyp3_parser(sp)
get_prep_isce_parser(sp)
get_prep_nisar_parser(sp)
get_prep_roipac_parser(sp)
get_prep_snap_parser(sp)

Expand Down
104 changes: 104 additions & 0 deletions src/mintpy/cli/prep_nisar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env python
############################################################
# Program is part of MintPy #
# Copyright (c) 2013, Zhang Yunjun, Heresh Fattahi #
# Author: Sara Mirzaee, Jul 2023 #
############################################################

import sys

from mintpy.utils.arg_utils import create_argument_parser

############################################################
EXAMPLE = """example:
prep_nisar.py -i 'interferograms/stitched/*.h5' -d dem.tiff
"""

def create_parser(subparsers=None):
"""Command line parser."""
synopsis = 'Prepare NISAR GUNW products for MintPy.'
epilog = EXAMPLE
name = __name__.split('.')[-1]
parser = create_argument_parser(
name, synopsis=synopsis, description=synopsis, epilog=epilog, subparsers=subparsers)

parser.add_argument(
"-i",
"--input-file-glob",
dest='input_glob',
type=str,
default="./interferograms/NISAR*.h5",
help="path pattern of NISAR interferograms (default: %(default)s).",
)

parser.add_argument(
"-d",
"--dem-file",
dest="dem_file",
type=str,
default="./dem.tif",
help="path to the DEM (default: %(default)s).",
)

parser.add_argument(
"-o",
"--out-dir",
dest="out_dir",
type=str,
default="./mintpy",
help="output directory (default: %(default)s).",
)

parser.add_argument(
'--force',
dest='update_mode',
action='store_false',
help='Force to overwrite all .rsc metadata files.'
)
parser.add_argument(
'--sub-lat',
'--sublat',
'--subset-lat',
dest='subset_lat',
type=float,
nargs=2,
metavar=('LATMIN', 'LATMAX'),
help='subset in latitude'
)

parser.add_argument(
'--sub-lon',
'--sublon',
'--subset-lon',
dest='subset_lon',
type=float,
nargs=2,
metavar=('LONMIN', 'LONMAX'),
help='subset in longitude'
)

return parser


def cmd_line_parse(iargs=None):
"""Create the command line parser."""
parser = create_parser()
inps = parser.parse_args(args=iargs)

return inps

####################################################################################
def main(iargs=None):
# parse
inps = cmd_line_parse(iargs)

# import
from mintpy.prep_nisar import load_nisar

# run
load_nisar(inps)


####################################################################################
if __name__=="__main__":
main(sys.argv[1:])
5 changes: 5 additions & 0 deletions src/mintpy/defaults/auto_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,18 @@
mintpy.load.waterMaskFile = ../mask/watermask.msk
'''

AUTO_PATH_NISAR = '''##----------Default file path of NISAR products
mintpy.load.unwFile = ../interferograms/*.h5
mintpy.load.demFile = ../dem.tiff
'''

AUTO_PATH_DICT = {
'isce_tops' : AUTO_PATH_ISCE_TOPS,
'isce_stripmap' : AUTO_PATH_ISCE_STRIPMAP,
'roipac' : AUTO_PATH_ROIPAC,
'gamma' : AUTO_PATH_GAMMA,
'aria' : AUTO_PATH_ARIA,
'nisar' : AUTO_PATH_NISAR,
}

prefix = 'mintpy.load.'
Expand Down
2 changes: 1 addition & 1 deletion src/mintpy/defaults/smallbaselineApp.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mintpy.compute.config = auto #[none / slurm / pbs / lsf ], auto for none (sam
## no - save 0% disk usage, fast [default]
## lzf - save ~57% disk usage, relative slow
## gzip - save ~62% disk usage, very slow [not recommend]
mintpy.load.processor = auto #[isce, aria, hyp3, gmtsar, snap, gamma, roipac], auto for isce
mintpy.load.processor = auto #[isce, aria, hyp3, gmtsar, snap, gamma, roipac, nisar], auto for isce
mintpy.load.autoPath = auto #[yes / no], auto for no, use pre-defined auto path
mintpy.load.updateMode = auto #[yes / no], auto for yes, skip re-loading if HDF5 files are complete
mintpy.load.compression = auto #[gzip / lzf / no], auto for no.
Expand Down
30 changes: 26 additions & 4 deletions src/mintpy/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from mintpy.utils import ptime, readfile, utils as ut

#################################################################
PROCESSOR_LIST = ['isce', 'aria', 'hyp3', 'gmtsar', 'snap', 'gamma', 'roipac', 'cosicorr']
PROCESSOR_LIST = ['isce', 'aria', 'hyp3', 'gmtsar', 'snap', 'gamma', 'roipac', 'cosicorr', 'nisar']

# primary observation dataset names
OBS_DSET_NAMES = ['unwrapPhase', 'rangeOffset', 'azimuthOffset']
Expand Down Expand Up @@ -601,7 +601,6 @@ def run_or_skip(outFile, inObj, box, updateMode=True, xstep=1, ystep=1, geom_obj

def prepare_metadata(iDict):
"""Prepare metadata via prep_{processor}.py scripts."""

processor = iDict['processor']
script_name = f'prep_{processor}.py'
print('-'*50)
Expand Down Expand Up @@ -632,6 +631,29 @@ def prepare_metadata(iDict):
# run
prep_module.main(iargs)

elif processor == 'nisar':
dem_file = iDict['mintpy.load.demFile']
gunw_files = iDict['mintpy.load.unwFile']

# run prep_*.py
iargs = ['-i', gunw_files, '-d', dem_file, '-o', '../mintpy']

if iDict['mintpy.subset.yx']:
warnings.warn('Subset in Y/X is not implemented for NISAR. \n'
'There might be shift in the coordinates of different products. \n'
'Use lat/lon instead.')
if iDict['mintpy.subset.lalo']:
lalo = iDict['mintpy.subset.lalo'].split(',')
lats = lalo[0].split(':')
lons = lalo[1].split(':')
iargs = iargs + ['--sub-lat', lats[0], lats[1], '--sub-lon', lons[0], lons[1]]

ut.print_command_line(script_name, iargs)
try:
prep_module.main(iargs)
except:
warnings.warn('prep_nisar.py failed. Assuming its result exists and continue...')

elif processor == 'isce':
from mintpy.utils import isce_utils, s1_utils

Expand Down Expand Up @@ -784,8 +806,8 @@ def load_data(inps):
prepare_metadata(iDict)
extraDict = get_extra_metadata(iDict)

# skip data writing for aria as it is included in prep_aria
if iDict['processor'] == 'aria':
# skip data writing as it is included in prep_aria/nisar
if iDict['processor'] in ['aria', 'nisar']:
return

## 2. search & write data files
Expand Down
Loading

0 comments on commit ce93e2e

Please sign in to comment.