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

smallbaselineApp: replace workflow import w/ individual import #854

Merged
merged 3 commits into from
Sep 24, 2022
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
6 changes: 1 addition & 5 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,18 @@ assignees: ''

**Description of the problem**


<!-- Please be as detailed as you can when describing an issue. The more information we have, the easier it will be for us to track this down. -->


**Full script that generated the error**


```
PASTE CODE HERE
```


**Full error message**



```
PASTE ERROR MESSAGE HERE
```
Expand All @@ -34,5 +30,5 @@ PASTE ERROR MESSAGE HERE

* Operating system: <!-- macOS, Linux-CentOS, Linux-RedHat, Linux-Ubuntu, Windows, etc. -->
* Python environment: <!-- conda, macports, pip, manual, etc. -->
* Version of MintPy: <!-- output of `smallbaselineApp.py -v` -->
* MintPy version: <!-- output of `smallbaselineApp.py -v` -->
* Your custom / default template file (if the bug is related to a specific dataset): <!-- It helps the diagnose a lot if you could post the configurations you used. You can drag-and-drop them here directly. -->
1 change: 0 additions & 1 deletion mintpy/asc_desc2horz_vert.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ def run_asc_desc2horz_vert(inps):

## 2. read LOS data and geometry
num_file = len(inps.file)
num_pixel = length * width
dlos = np.zeros((num_file, length, width), dtype=np.float32)
if inps.geom_file:
los_inc_angle = np.zeros((num_file, length, width), dtype=np.float32)
Expand Down
2 changes: 1 addition & 1 deletion mintpy/cli/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def cmd_line_parse(iargs=None):
raise FileNotFoundError(inps.file)

# default: --compact option and max number of metadata to show
inps.max_meta_num = 200
inps.max_meta_num = 10000
if inps.compact:
inps.max_meta_num = 20

Expand Down
11 changes: 9 additions & 2 deletions mintpy/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def print_timseries_date_stat(dateList):
return


def print_date_list(fname, disp_ifgram='all', disp_num=False, print_msg=False):
def print_date_list(fname, disp_ifgram='all', disp_num=False, max_num=1e4, print_msg=False):
"""Print time/date info of file"""
k = readfile.read_attribute(fname)['FILE_TYPE']
dateList = None
Expand Down Expand Up @@ -135,8 +135,9 @@ def print_date_list(fname, disp_ifgram='all', disp_num=False, print_msg=False):
print(f'--date option can not be applied to {k} file, ignore it.')

# print list info
max_num = int(max_num)
if print_msg and dateList is not None:
for d in dateList:
for d in dateList[:max_num]:
if disp_num:
if k in ['ifgramStack']:
num = dateListAll.index(d)
Expand All @@ -146,6 +147,11 @@ def print_date_list(fname, disp_ifgram='all', disp_num=False, print_msg=False):
else:
msg = d
print(msg)

# add ... at the end if --compact
if max_num < len(dateList):
print('...\n')

return dateList


Expand Down Expand Up @@ -219,6 +225,7 @@ def print_info(inps):
inps.file,
disp_ifgram=inps.disp_ifgram,
disp_num=inps.disp_num,
max_num=inps.max_meta_num,
print_msg=True,
)
return
Expand Down
3 changes: 2 additions & 1 deletion mintpy/modify_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def onclick(event):
else:
print(date12+' is not existed in input file')
plt.draw()
cid = fig.canvas.mpl_connect('button_press_event', onclick)

fig.canvas.mpl_connect('button_press_event', onclick)
plt.show()

if not ut.yes_or_no('Proceed to drop the ifgrams/date12?'):
Expand Down
4 changes: 3 additions & 1 deletion mintpy/reference_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,11 @@ def onclick(event):
print('\nWARNING:')
print('The selectd pixel has NaN value in data.')
print('Try a difference location please.')
cid = fig.canvas.mpl_connect('button_press_event', onclick)

fig.canvas.mpl_connect('button_press_event', onclick)
plt.show()
print(f'y/x: {(inps.ref_y, inps.ref_x)}')

return inps


Expand Down
1 change: 0 additions & 1 deletion mintpy/simulation/iono.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import datetime as dt
import os
import re
import sys

import matplotlib.pyplot as plt
import numpy as np
Expand Down
2 changes: 0 additions & 2 deletions mintpy/simulation/variance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
# from mintpy.simulation import variance as var


import random

import numpy as np
import pyproj

Expand Down
45 changes: 36 additions & 9 deletions mintpy/smallbaselineApp.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
############################################################
# Project: MintPy #
# Purpose: Miami InSAR Time-series software in Python #
# Author: Zhang Yunjun, Heresh Fattahi #
# Created: July 2013 #
# Program is part of MintPy #
# Copyright (c) 2013, Zhang Yunjun, Heresh Fattahi #
# Author: Zhang Yunjun, Heresh Fattahi, Jul 2013 #
############################################################


Expand All @@ -15,10 +13,12 @@
import numpy as np

import mintpy
import mintpy.workflow # dynamic import of modules for smallbaselineApp
from mintpy.objects import RAMP_LIST, cluster, sensor
from mintpy.utils import readfile, utils as ut, writefile

# comment out the workflow import in favor of individual imports for speed and robustness
# import mintpy.workflow # dynamic import of modules for smallbaselineApp


##########################################################################
def get_the_latest_default_template_file(work_dir):
Expand Down Expand Up @@ -171,6 +171,7 @@ def run_load_data(self, step_name):

# run command line
print('\nload_data.py', ' '.join(iargs))
import mintpy.cli.load_data
mintpy.cli.load_data.main(iargs)

# come back to working directory
Expand Down Expand Up @@ -233,6 +234,7 @@ def run_network_modification(self, step_name):
# 2) modify network
iargs = [stack_file, '-t', self.templateFile]
print('\nmodify_network.py', ' '.join(iargs))
import mintpy.cli.modify_network
mintpy.cli.modify_network.main(iargs)

# 3) plot network
Expand All @@ -251,6 +253,7 @@ def run_network_modification(self, step_name):
if ut.run_or_skip(out_file=net_fig,
in_file=[stack_file, coh_txt, self.templateFile],
readable=False) == 'run':
import mintpy.cli.plot_network
mintpy.cli.plot_network.main(iargs)
else:
print('mintpy.plot is turned OFF, skip plotting network.')
Expand All @@ -268,6 +271,7 @@ def generate_ifgram_aux_file(self):
if any('phase' in i.lower() for i in dsNames):
iargs = [stack_file, '--nonzero', '-o', mask_file, '--update']
print('\ngenerate_mask.py', ' '.join(iargs))
import mintpy.cli.generate_mask
mintpy.cli.generate_mask.main(iargs)

# 2) generate average spatial coherence
Expand All @@ -276,6 +280,7 @@ def generate_ifgram_aux_file(self):
elif any('offset' in i.lower() for i in dsNames):
iargs = [stack_file, '--dataset', 'offsetSNR', '-o', snr_file, '--update']
print('\ntemporal_average.py', ' '.join(iargs))
import mintpy.cli.temporal_average
mintpy.cli.temporal_average.main(iargs)


Expand All @@ -296,6 +301,7 @@ def run_reference_point(self, step_name):
if lookup_file is not None:
iargs += ['--lookup', lookup_file]
print('\nreference_point.py', ' '.join(iargs))
import mintpy.cli.reference_point
mintpy.cli.reference_point.main(iargs)


Expand All @@ -312,12 +318,14 @@ def run_quick_overview(self, step_name):
pha_vel_file = os.path.join(self.workDir, 'avgPhaseVelocity.h5')
iargs = [stack_file, '--dataset', 'unwrapPhase', '-o', pha_vel_file, '--update']
print('\ntemporal_average.py', ' '.join(iargs))
import mintpy.cli.temporal_average
mintpy.cli.temporal_average.main(iargs)

# 2) calculate the number of interferogram triplets with non-zero integer ambiguity
water_mask_file = os.path.join(self.workDir, 'waterMask.h5')
iargs = [stack_file, '--water-mask', water_mask_file, '--action', 'calculate', '--update']
print('\nunwrap_error_phase_closure.py', ' '.join(iargs))
import mintpy.cli.unwrap_error_phase_closure
mintpy.cli.unwrap_error_phase_closure.main(iargs)


Expand All @@ -335,6 +343,8 @@ def run_unwrap_error_correction(self, step_name):
iargs_bridge = [stack_file, '--template', self.templateFile, '--update']
iargs_closure = iargs_bridge + ['--cc-mask', mask_file]

import mintpy.cli.unwrap_error_bridging
import mintpy.cli.unwrap_error_phase_closure
if method == 'bridging':
print('\nunwrap_error_bridging.py', ' '.join(iargs_bridge))
mintpy.cli.unwrap_error_bridging.main(iargs_bridge)
Expand Down Expand Up @@ -369,6 +379,7 @@ def run_network_inversion(self, step_name):
# 1) invert ifgramStack for time-series
iargs = [stack_file, '-t', self.templateFile, '--update']
print('\nifgram_inversion.py', ' '.join(iargs))
import mintpy.cli.ifgram_inversion
mintpy.cli.ifgram_inversion.main(iargs)

# 2) get reliable pixel mask: maskTempCoh.h5
Expand Down Expand Up @@ -409,7 +420,9 @@ def generate_temporal_coherence_mask(self):
print(f'run or skip: {flag}')

if flag == 'run':
import mintpy.cli.generate_mask
mintpy.cli.generate_mask.main(iargs)

# update config_keys
atr = {}
for key in config_keys:
Expand Down Expand Up @@ -540,6 +553,7 @@ def run_local_oscillator_drift_correction(self, step_name):
iargs = [in_file, geom_file, '-o', out_file]
print('\nlocal_oscilator_drift.py', ' '.join(iargs))
if ut.run_or_skip(out_file=out_file, in_file=in_file) == 'run':
import mintpy.cli.local_oscilator_drift
mintpy.cli.local_oscilator_drift.main(iargs)
else:
atr = readfile.read_attribute(in_file)
Expand All @@ -558,6 +572,7 @@ def run_solid_earth_tides_correction(self, step_name):
iargs = [in_file, '-g', geom_file, '-o', out_file, '--update']
print('\nsolid_earth_tides.py', ' '.join(iargs))
if ut.run_or_skip(out_file=out_file, in_file=in_file) == 'run':
import mintpy.cli.solid_earth_tides
mintpy.cli.solid_earth_tides.main(iargs)
else:
print('No solid Earth tides correction.')
Expand Down Expand Up @@ -595,6 +610,7 @@ def get_dataset_size(fname):
print('tropospheric delay correction with height-correlation approach')
print('\ntropo_phase_elevation.py', ' '.join(iargs))
if ut.run_or_skip(out_file=out_file, in_file=in_file) == 'run':
import mintpy.cli.tropo_phase_elevation
mintpy.cli.tropo_phase_elevation.main(iargs)

# Weather re-analysis data with iterative tropospheric decomposition (GACOS)
Expand All @@ -605,6 +621,7 @@ def get_dataset_size(fname):
print('tropospheric delay correction with gacos approach')
print('\ntropo_gacos.py', ' '.join(iargs))
if ut.run_or_skip(out_file=out_file, in_file=in_file) == 'run':
import mintpy.cli.tropo_gacos
mintpy.cli.tropo_gacos.main(iargs)

# Weather Re-analysis Data (Jolivet et al., 2011;2014)
Expand All @@ -620,15 +637,13 @@ def get_dataset_size(fname):
print('--------------------------------------------')
print(f'Use existed tropospheric delay file: {tropo_file}')
print('\ndiff.py', ' '.join(iargs))

# import again to avoid the error below. reason is unclear.
# UnboundLocalError: local variable 'mintpy' referenced before assignment
import mintpy.cli.diff
mintpy.cli.diff.main(iargs)

else:
if tropo_model in ['ERA5']:
print('\ntropo_pyaps3.py', ' '.join(iargs))
import mintpy.cli.tropo_pyaps3
mintpy.cli.tropo_pyaps3.main(iargs)

elif tropo_model in ['MERRA', 'NARR']:
Expand All @@ -655,6 +670,7 @@ def run_phase_deramping(self, step_name):
print(f'Remove for each acquisition a phase ramp: {method}')
iargs = [in_file, '-s', method, '-m', mask_file, '-o', out_file, '--update']
print('\nremove_ramp.py', ' '.join(iargs))
import mintpy.cli.remove_ramp
mintpy.cli.remove_ramp.main(iargs)
else:
print('No phase ramp removal.')
Expand All @@ -674,6 +690,7 @@ def run_topographic_residual_correction(self, step_name):
if self.template['mintpy.topographicResidual.pixelwiseGeometry']:
iargs += ['-g', geom_file]
print('\ndem_error.py', ' '.join(iargs))
import mintpy.cli.dem_error
mintpy.cli.dem_error.main(iargs)

else:
Expand All @@ -686,6 +703,7 @@ def run_residual_phase_rms(self, step_name):
if os.path.isfile(res_file):
iargs = [res_file, '-t', self.templateFile]
print('\ntimeseries_rms.py', ' '.join(iargs))
import mintpy.cli.timeseries_rms
mintpy.cli.timeseries_rms.main(iargs)
else:
print('No residual phase file found! Skip residual RMS analysis.')
Expand All @@ -699,6 +717,7 @@ def run_reference_date(self, step_name):
for in_file in in_files:
iargs += [in_file]
print('\nreference_date.py', ' '.join(iargs))
import mintpy.cli.reference_date
mintpy.cli.reference_date.main(iargs)
else:
print('No reference date change.')
Expand All @@ -711,6 +730,7 @@ def run_timeseries2velocity(self, step_name):

iargs = [ts_file, '-t', self.templateFile, '-o', vel_file, '--update']
print('\ntimeseries2velocity.py', ' '.join(iargs))
import mintpy.cli.timeseries2velocity
mintpy.cli.timeseries2velocity.main(iargs)

# Velocity from estimated tropospheric delays
Expand Down Expand Up @@ -743,6 +763,7 @@ def run_geocode(self, step_name):
in_files = [geom_file, 'temporalCoherence.h5', 'avgSpatialCoh.h5', ts_file, 'velocity.h5']
iargs = in_files + ['-l', lookup_file, '-t', self.templateFile, '--outdir', out_dir, '--update']
print('\ngeocode.py', ' '.join(iargs))
import mintpy.cli.geocode
mintpy.cli.geocode.main(iargs)

# 2. generate reliable pixel mask in geo coordinate
Expand All @@ -759,6 +780,7 @@ def run_geocode(self, step_name):
print('\ngenerate_mask.py', ' '.join(iargs))

if ut.run_or_skip(out_file=mask_file, in_file=tcoh_file) == 'run':
import mintpy.cli.generate_mask
mintpy.cli.generate_mask.main(iargs)

else:
Expand Down Expand Up @@ -789,6 +811,7 @@ def run_save2google_earth(self, step_name):
kmz_file = kmz_files[0] if len(kmz_files) > 0 else None

if ut.run_or_skip(out_file=kmz_file, in_file=vel_file, readable=False) == 'run':
import mintpy.cli.save_kmz
mintpy.cli.save_kmz.main(iargs)

else:
Expand Down Expand Up @@ -831,7 +854,10 @@ def run_save2hdfeos5(self, step_name):
hdfeos5_file = hdfeos5_files[0] if len(hdfeos5_files) > 0 else None

if ut.run_or_skip(out_file=hdfeos5_file,
in_file=[ts_file, tcoh_file, scoh_file, mask_file, geom_file]) == 'run':
in_file=[ts_file, tcoh_file,
scoh_file, mask_file,
geom_file]) == 'run':
import mintpy.cli.save_hdfeos5
mintpy.cli.save_hdfeos5.main(iargs)

else:
Expand Down Expand Up @@ -1024,6 +1050,7 @@ def plot_result(self, print_aux=True):
plot_memory = 1.5 if 2.0 < max_plot_memory <= 4.0 else 1.5 * (max_plot_memory / 4.0)
num_cores = min(num_cores, max(int(max_memory / plot_memory), 1))

import mintpy.cli.view
if run_parallel and num_cores > 1:
print(f"parallel processing using {num_cores} cores ...")
Parallel(n_jobs=num_cores)(delayed(mintpy.cli.view.main)(iargs) for iargs in iargs_list)
Expand Down
1 change: 0 additions & 1 deletion mintpy/utils/isce_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import glob
import logging
import os
import re
import shelve
import time

Expand Down
Loading