Skip to content

Commit

Permalink
tropo_pyaps3: add --debug-mode option (#1322)
Browse files Browse the repository at this point in the history
+ tropo_pyaps3.py: add --debug(--mode) option to enable the debug mode to show the full error message of pyaps3 while downloading

+ requirements.txt: set min version of pyaps3 to 0.3.6 for the new CDS website
  • Loading branch information
yunjunz authored Feb 10, 2025
1 parent 42aa7b5 commit 2dcccde
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 32 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ joblib
lxml
matplotlib
numpy
pyaps3>=0.3
pyaps3>=0.3.6
pykml>=0.2
pyproj
pyresample
Expand Down
6 changes: 6 additions & 0 deletions src/mintpy/cli/tropo_pyaps3.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
tropo_pyaps3.py -d SAFE_files.txt
# download datasets (covering the area of interest)
tropo_pyaps3.py -d SAFE_files.txt -g inputs/geometryRadar.h5
# debug mode (to facilitate potential pyaps3 debugging)
tropo_pyaps3.py -f timeseries.h5 -g inputs/geometryRadar.h5 --debug
"""

SAFE_FILE = """SAFE_files.txt:
Expand Down Expand Up @@ -90,6 +93,9 @@ def create_parser(subparsers=None):
parser.add_argument('--hour', type=str, help='time of data in HH, e.g. 12, 06')
parser.add_argument('-o','--output', dest='cor_dis_file',
help='Output file name for trospheric corrected timeseries.')
parser.add_argument('--debug', '--debug-mode', dest='debug_mode', action='store_true',
help='Enable debug mode, i.e. run pyaps3 without try/except to show the full message '
'and potential stopping points.')

# delay calculation
delay = parser.add_argument_group('delay calculation')
Expand Down
75 changes: 44 additions & 31 deletions src/mintpy/tropo_pyaps3.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,13 @@ def check_pyaps_account_config(tropo_model):


###############################################################
def dload_grib_files(grib_files, tropo_model='ERA5', snwe=None):
def dload_grib_files(grib_files, tropo_model='ERA5', snwe=None, debug_mode=False):
"""Download weather re-analysis grib files using PyAPS
Parameters: grib_files : list of string of grib files
Returns: grib_files : list of string
Parameters: grib_files - list of string of grib files needed
tropo_model - str, global tropospheric model name
snwe - tuple(float), bounding box in latitude/longitude (for ERA5)
debug_mode - bool, enable the debug model while downloading via pyaps3
Returns: grib_files - list of string of grib files after downloading
"""
print('-'*50)
print('downloading weather model data using PyAPS ...')
Expand All @@ -495,33 +498,41 @@ def dload_grib_files(grib_files, tropo_model='ERA5', snwe=None):
# Check for non-empty account info in PyAPS config file
check_pyaps_account_config(tropo_model)

# try 3 times to download, then use whatever downloaded to calculate delay
i = 0
while i < 3:
i += 1
try:
if tropo_model in ['ERA5', 'ERAINT']:
pa.ECMWFdload(
date_list2dload,
hour,
grib_dir,
model=tropo_model,
snwe=snwe,
flist=grib_files2dload)

elif tropo_model == 'MERRA':
pa.MERRAdload(date_list2dload, hour, grib_dir)

elif tropo_model == 'NARR':
pa.NARRdload(date_list2dload, hour, grib_dir)
except:
if i < 3:
print(f'WARNING: the {i} attempt to download failed, retry it.\n')
else:
print('\n\n'+'*'*50)
print('WARNING: downloading failed for 3 times, stop trying and continue.')
print('*'*50+'\n\n')
pass
# call pyapd3 to download
kwargs = dict(model=tropo_model, snwe=snwe, flist=grib_files2dload)
if debug_mode:
# in the debug mode, if issue occurred, show the full error message and stop
if tropo_model in ['ERA5', 'ERAINT']:
pa.ECMWFdload(date_list2dload, hour, grib_dir, **kwargs)

elif tropo_model == 'MERRA':
pa.MERRAdload(date_list2dload, hour, grib_dir)

elif tropo_model == 'NARR':
pa.NARRdload(date_list2dload, hour, grib_dir)

else:
# in the operation mode, try to download 3 times, then use whatever downloaded and continue
i = 0
while i < 3:
i += 1
try:
if tropo_model in ['ERA5', 'ERAINT']:
pa.ECMWFdload(date_list2dload, hour, grib_dir, **kwargs)

elif tropo_model == 'MERRA':
pa.MERRAdload(date_list2dload, hour, grib_dir)

elif tropo_model == 'NARR':
pa.NARRdload(date_list2dload, hour, grib_dir)
except:
if i < 3:
print(f'WARNING: the {i} attempt to download failed, retry it.\n')
else:
print('\n\n'+'*'*50)
print('WARNING: downloading failed for 3 times, stop trying and continue.')
print('*'*50+'\n\n')
pass

# check potentially corrupted files
grib_files = check_exist_grib_file(grib_files, print_msg=False)
Expand Down Expand Up @@ -728,7 +739,9 @@ def run_tropo_pyaps3(inps):
inps.grib_files = dload_grib_files(
inps.grib_files,
tropo_model=inps.tropo_model,
snwe=inps.snwe)
snwe=inps.snwe,
debug_mode=inps.debug_mode,
)

## 2. calculate tropo delay and save to h5 file
if not inps.geom_file:
Expand Down

0 comments on commit 2dcccde

Please sign in to comment.