Enabled plotting of figures when called from terminal.
This commit is contained in:
parent
ab410b790c
commit
811f52c95c
14
autoPyLoT.py
14
autoPyLoT.py
@ -450,16 +450,13 @@ if __name__ == "__main__":
|
||||
autoregressive prediction and AIC followed by locating the seismic events using
|
||||
NLLoc''')
|
||||
|
||||
# parser.add_argument('-d', '-D', '--input_dict', type=str,
|
||||
# action='store',
|
||||
# help='''optional, dictionary containing processing parameters''')
|
||||
# parser.add_argument('-p', '-P', '--parameter', type=str,
|
||||
# action='store',
|
||||
# help='''parameter file, default=None''')
|
||||
parser.add_argument('-i', '-I', '--inputfile', type=str,
|
||||
action='store',
|
||||
help='''full path to the file containing the input
|
||||
parameters for autoPyLoT''')
|
||||
parser.add_argument('-p', '-P', '--iplot', type=int,
|
||||
action='store',
|
||||
help='''Boolean flag for plotting: 0=none, 1=partial, 2=all''')
|
||||
parser.add_argument('-f', '-F', '--fnames', type=str,
|
||||
action='store',
|
||||
help='''optional, list of data file names''')
|
||||
@ -472,12 +469,9 @@ if __name__ == "__main__":
|
||||
parser.add_argument('-c', '-C', '--ncores', type=int,
|
||||
action='store', default=0,
|
||||
help='''optional, number of CPU cores used for parallel processing (default: all available)''')
|
||||
# parser.add_argument('-v', '-V', '--version', action='version',
|
||||
# version='autoPyLoT ' + __version__,
|
||||
# help='show version information and exit')
|
||||
|
||||
cla = parser.parse_args()
|
||||
|
||||
picks = autoPyLoT(inputfile=str(cla.inputfile), fnames=str(cla.fnames),
|
||||
eventid=str(cla.eventid), savepath=str(cla.spath),
|
||||
ncores=cla.ncores)
|
||||
ncores=cla.ncores, iplot=str(cla.iplot))
|
||||
|
@ -44,27 +44,27 @@ def autopickevent(data, param, iplot=0, fig_dict=None, ncores=0, metadata=None,
|
||||
for station in stations:
|
||||
topick = data.select(station=station)
|
||||
|
||||
if not iplot:
|
||||
input_tuples.append((topick, param, apverbose, metadata, origin))
|
||||
if iplot > 0:
|
||||
all_onsets[station] = autopickstation(topick, param, verbose=apverbose,
|
||||
iplot=iplot, fig_dict=fig_dict,
|
||||
metadata=metadata, origin=origin)
|
||||
#if not iplot:
|
||||
# input_tuples.append((topick, param, apverbose, metadata, origin))
|
||||
#if iplot > 0:
|
||||
all_onsets[station] = autopickstation(topick, param, verbose=apverbose,
|
||||
iplot=iplot, fig_dict=fig_dict,
|
||||
metadata=metadata, origin=origin)
|
||||
|
||||
if iplot > 0:
|
||||
print('iPlot Flag active: NO MULTIPROCESSING possible.')
|
||||
return all_onsets
|
||||
#if iplot > 0:
|
||||
# print('iPlot Flag active: NO MULTIPROCESSING possible.')
|
||||
# return all_onsets
|
||||
|
||||
pool = gen_Pool(ncores)
|
||||
result = pool.map(call_autopickstation, input_tuples)
|
||||
pool.close()
|
||||
#pool = gen_Pool(ncores)
|
||||
#result = pool.map(call_autopickstation, input_tuples)
|
||||
#pool.close()
|
||||
|
||||
for pick in result:
|
||||
station = pick['station']
|
||||
pick.pop('station')
|
||||
all_onsets[station] = pick
|
||||
#for pick in result:
|
||||
# station = pick['station']
|
||||
# pick.pop('station')
|
||||
# all_onsets[station] = pick
|
||||
|
||||
return all_onsets
|
||||
#return all_onsets
|
||||
|
||||
# quality control
|
||||
# median check and jackknife on P-onset times
|
||||
@ -95,10 +95,9 @@ def autopickstation(wfstream, pickparam, verbose=False,
|
||||
|
||||
# declaring pickparam variables (only for convenience)
|
||||
# read your autoPyLoT.in for details!
|
||||
plt_flag = 0
|
||||
|
||||
# special parameters for P picking
|
||||
iplot = iplot
|
||||
|
||||
algoP = pickparam.get('algoP')
|
||||
pstart = pickparam.get('pstart')
|
||||
pstop = pickparam.get('pstop')
|
||||
@ -761,6 +760,7 @@ def autopickstation(wfstream, pickparam, verbose=False,
|
||||
# plot vertical trace
|
||||
if not fig_dict:
|
||||
fig = plt.figure()
|
||||
plt_flag = 1
|
||||
else:
|
||||
fig = fig_dict['mainFig']
|
||||
ax1 = fig.add_subplot(311)
|
||||
@ -905,6 +905,10 @@ def autopickstation(wfstream, pickparam, verbose=False,
|
||||
ax3.set_xlabel('Time [s] after %s' % tr_filt.stats.starttime)
|
||||
ax3.set_ylabel('Normalized Counts')
|
||||
ax3.set_title(trH2_filt.stats.channel)
|
||||
if plt_flag == 1:
|
||||
fig.show()
|
||||
raw_input()
|
||||
plt.close(fig)
|
||||
##########################################################################
|
||||
# calculate "real" onset times
|
||||
if lpickP is not None and lpickP == mpickP:
|
||||
|
@ -154,6 +154,7 @@ class AICPicker(AutoPicker):
|
||||
self.Pick = None
|
||||
self.slope = None
|
||||
self.SNR = None
|
||||
plt_flag = 0
|
||||
# find NaN's
|
||||
nn = np.isnan(self.cf)
|
||||
if len(nn) > 1:
|
||||
@ -244,6 +245,7 @@ class AICPicker(AutoPicker):
|
||||
if self.iplot > 1:
|
||||
if not self.fig:
|
||||
fig = plt.figure() # self.iplot) ### WHY? MP MP
|
||||
plt_flag = 1
|
||||
else:
|
||||
fig = self.fig
|
||||
ax = fig.add_subplot(111)
|
||||
@ -254,6 +256,10 @@ class AICPicker(AutoPicker):
|
||||
ax.set_xlabel('Time [s] since %s' % self.Data[0].stats.starttime)
|
||||
ax.set_yticks([])
|
||||
ax.set_title(self.Data[0].stats.station)
|
||||
if plt_flag == 1:
|
||||
fig.show()
|
||||
raw_input()
|
||||
plt.close(fig)
|
||||
return
|
||||
iislope = islope[0][0:imax]
|
||||
dataslope = self.Data[0].data[iislope]
|
||||
@ -273,6 +279,7 @@ class AICPicker(AutoPicker):
|
||||
if self.iplot > 1:
|
||||
if not self.fig:
|
||||
fig = plt.figure() # self.iplot)
|
||||
plt_flag = 1
|
||||
else:
|
||||
fig = self.fig
|
||||
ax1 = fig.add_subplot(211)
|
||||
@ -307,8 +314,16 @@ class AICPicker(AutoPicker):
|
||||
ax2.set_ylabel('Counts')
|
||||
ax2.set_yticks([])
|
||||
ax2.legend()
|
||||
if plt_flag == 1:
|
||||
fig.show()
|
||||
raw_input()
|
||||
plt.close(fig)
|
||||
else:
|
||||
ax1.set_title(self.Data[0].stats.station)
|
||||
if plt_flag == 1:
|
||||
fig.show()
|
||||
raw_input()
|
||||
plt.close(fig)
|
||||
|
||||
if self.Pick == None:
|
||||
print('AICPicker: Could not find minimum, picking window too short?')
|
||||
@ -330,6 +345,7 @@ class PragPicker(AutoPicker):
|
||||
self.SNR = None
|
||||
self.slope = None
|
||||
pickflag = 0
|
||||
plt_flag = 0
|
||||
# smooth CF
|
||||
ismooth = int(round(self.Tsmooth / self.dt))
|
||||
cfsmooth = np.zeros(len(self.cf))
|
||||
@ -408,6 +424,7 @@ class PragPicker(AutoPicker):
|
||||
if self.getiplot() > 1:
|
||||
if not self.fig:
|
||||
fig = plt.figure() # self.getiplot())
|
||||
plt_flag = 1
|
||||
else:
|
||||
fig = self.fig
|
||||
ax = fig.add_subplot(111)
|
||||
@ -419,6 +436,10 @@ class PragPicker(AutoPicker):
|
||||
ax.set_yticks([])
|
||||
ax.set_title(self.Data[0].stats.station)
|
||||
ax.legend()
|
||||
if plt_flag == 1:
|
||||
fig.show()
|
||||
raw_input()
|
||||
plt.close(fig)
|
||||
return
|
||||
|
||||
else:
|
||||
|
@ -50,6 +50,7 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, verbosity=1, fig=None):
|
||||
LPick = None
|
||||
EPick = None
|
||||
PickError = None
|
||||
plt_flag = 0
|
||||
if verbosity:
|
||||
print('earllatepicker: Get earliest and latest possible pick'
|
||||
' relative to most likely pick ...')
|
||||
@ -120,6 +121,7 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, verbosity=1, fig=None):
|
||||
if iplot > 1:
|
||||
if not fig:
|
||||
fig = plt.figure() # iplot)
|
||||
plt_flag = 1
|
||||
ax = fig.add_subplot(111)
|
||||
ax.plot(t, x, 'k', label='Data')
|
||||
ax.axvspan(t[inoise[0]], t[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
|
||||
@ -141,6 +143,10 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, verbosity=1, fig=None):
|
||||
'Earliest-/Latest Possible/Most Likely Pick & Symmetric Pick Error, %s' %
|
||||
X[0].stats.station)
|
||||
ax.legend()
|
||||
if plt_flag == 1:
|
||||
fig.show()
|
||||
raw_input()
|
||||
plt.close(fig)
|
||||
|
||||
return EPick, LPick, PickError
|
||||
|
||||
@ -167,6 +173,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None):
|
||||
:type: int
|
||||
'''
|
||||
|
||||
plt_flag = 0
|
||||
warnings.simplefilter('ignore', np.RankWarning)
|
||||
|
||||
assert isinstance(Xraw, Stream), "%s is not a stream object" % str(Xraw)
|
||||
@ -292,6 +299,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None):
|
||||
if iplot > 1:
|
||||
if not fig:
|
||||
fig = plt.figure() # iplot)
|
||||
plt_flag = 1
|
||||
ax1 = fig.add_subplot(211)
|
||||
ax1.plot(t, xraw, 'k')
|
||||
ax1.plot([Pick, Pick], [max(xraw), -max(xraw)], 'b', linewidth=2, label='Pick')
|
||||
@ -317,6 +325,10 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None):
|
||||
ax2.text(Pick + 0.02, max(xraw) / 2, '%s' % FM, fontsize=14)
|
||||
ax2.set_xlabel('Time [s] since %s' % Xraw[0].stats.starttime)
|
||||
ax2.set_yticks([])
|
||||
if plt_flag == 1:
|
||||
fig.show()
|
||||
raw_input()
|
||||
plt.close(fig)
|
||||
|
||||
return FM
|
||||
|
||||
@ -685,6 +697,7 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fi
|
||||
: type: int
|
||||
'''
|
||||
|
||||
plt_flag = 0
|
||||
assert isinstance(X, Stream), "%s is not a stream object" % str(X)
|
||||
|
||||
print("Checking signal length ...")
|
||||
@ -729,6 +742,7 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fi
|
||||
if iplot == 2:
|
||||
if not fig:
|
||||
fig = plt.figure() # iplot)
|
||||
plt_flag = 1
|
||||
ax = fig.add_subplot(111)
|
||||
ax.plot(t, rms, 'k', label='RMS Data')
|
||||
ax.axvspan(t[inoise[0]], t[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
|
||||
@ -741,6 +755,10 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fi
|
||||
ax.set_ylabel('Counts')
|
||||
ax.set_title('Check for Signal Length, Station %s' % X[0].stats.station)
|
||||
ax.set_yticks([])
|
||||
if plt_flag == 1:
|
||||
fig.show()
|
||||
raw_input()
|
||||
plt.close(fig)
|
||||
|
||||
return returnflag
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user