Enabled plotting of figures when called from terminal.

This commit is contained in:
Ludger Küperkoch 2017-08-08 16:38:29 +02:00
parent ab410b790c
commit 811f52c95c
4 changed files with 66 additions and 29 deletions

View File

@ -450,16 +450,13 @@ if __name__ == "__main__":
autoregressive prediction and AIC followed by locating the seismic events using autoregressive prediction and AIC followed by locating the seismic events using
NLLoc''') 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, parser.add_argument('-i', '-I', '--inputfile', type=str,
action='store', action='store',
help='''full path to the file containing the input help='''full path to the file containing the input
parameters for autoPyLoT''') 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, parser.add_argument('-f', '-F', '--fnames', type=str,
action='store', action='store',
help='''optional, list of data file names''') help='''optional, list of data file names''')
@ -472,12 +469,9 @@ if __name__ == "__main__":
parser.add_argument('-c', '-C', '--ncores', type=int, parser.add_argument('-c', '-C', '--ncores', type=int,
action='store', default=0, action='store', default=0,
help='''optional, number of CPU cores used for parallel processing (default: all available)''') 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() cla = parser.parse_args()
picks = autoPyLoT(inputfile=str(cla.inputfile), fnames=str(cla.fnames), picks = autoPyLoT(inputfile=str(cla.inputfile), fnames=str(cla.fnames),
eventid=str(cla.eventid), savepath=str(cla.spath), eventid=str(cla.eventid), savepath=str(cla.spath),
ncores=cla.ncores) ncores=cla.ncores, iplot=str(cla.iplot))

View File

@ -44,27 +44,27 @@ def autopickevent(data, param, iplot=0, fig_dict=None, ncores=0, metadata=None,
for station in stations: for station in stations:
topick = data.select(station=station) topick = data.select(station=station)
if not iplot: #if not iplot:
input_tuples.append((topick, param, apverbose, metadata, origin)) # input_tuples.append((topick, param, apverbose, metadata, origin))
if iplot > 0: #if iplot > 0:
all_onsets[station] = autopickstation(topick, param, verbose=apverbose, all_onsets[station] = autopickstation(topick, param, verbose=apverbose,
iplot=iplot, fig_dict=fig_dict, iplot=iplot, fig_dict=fig_dict,
metadata=metadata, origin=origin) metadata=metadata, origin=origin)
if iplot > 0: #if iplot > 0:
print('iPlot Flag active: NO MULTIPROCESSING possible.') # print('iPlot Flag active: NO MULTIPROCESSING possible.')
return all_onsets # return all_onsets
pool = gen_Pool(ncores) #pool = gen_Pool(ncores)
result = pool.map(call_autopickstation, input_tuples) #result = pool.map(call_autopickstation, input_tuples)
pool.close() #pool.close()
for pick in result: #for pick in result:
station = pick['station'] # station = pick['station']
pick.pop('station') # pick.pop('station')
all_onsets[station] = pick # all_onsets[station] = pick
return all_onsets #return all_onsets
# quality control # quality control
# median check and jackknife on P-onset times # median check and jackknife on P-onset times
@ -95,10 +95,9 @@ def autopickstation(wfstream, pickparam, verbose=False,
# declaring pickparam variables (only for convenience) # declaring pickparam variables (only for convenience)
# read your autoPyLoT.in for details! # read your autoPyLoT.in for details!
plt_flag = 0
# special parameters for P picking # special parameters for P picking
iplot = iplot
algoP = pickparam.get('algoP') algoP = pickparam.get('algoP')
pstart = pickparam.get('pstart') pstart = pickparam.get('pstart')
pstop = pickparam.get('pstop') pstop = pickparam.get('pstop')
@ -761,6 +760,7 @@ def autopickstation(wfstream, pickparam, verbose=False,
# plot vertical trace # plot vertical trace
if not fig_dict: if not fig_dict:
fig = plt.figure() fig = plt.figure()
plt_flag = 1
else: else:
fig = fig_dict['mainFig'] fig = fig_dict['mainFig']
ax1 = fig.add_subplot(311) 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_xlabel('Time [s] after %s' % tr_filt.stats.starttime)
ax3.set_ylabel('Normalized Counts') ax3.set_ylabel('Normalized Counts')
ax3.set_title(trH2_filt.stats.channel) ax3.set_title(trH2_filt.stats.channel)
if plt_flag == 1:
fig.show()
raw_input()
plt.close(fig)
########################################################################## ##########################################################################
# calculate "real" onset times # calculate "real" onset times
if lpickP is not None and lpickP == mpickP: if lpickP is not None and lpickP == mpickP:

View File

@ -154,6 +154,7 @@ class AICPicker(AutoPicker):
self.Pick = None self.Pick = None
self.slope = None self.slope = None
self.SNR = None self.SNR = None
plt_flag = 0
# find NaN's # find NaN's
nn = np.isnan(self.cf) nn = np.isnan(self.cf)
if len(nn) > 1: if len(nn) > 1:
@ -244,6 +245,7 @@ class AICPicker(AutoPicker):
if self.iplot > 1: if self.iplot > 1:
if not self.fig: if not self.fig:
fig = plt.figure() # self.iplot) ### WHY? MP MP fig = plt.figure() # self.iplot) ### WHY? MP MP
plt_flag = 1
else: else:
fig = self.fig fig = self.fig
ax = fig.add_subplot(111) 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_xlabel('Time [s] since %s' % self.Data[0].stats.starttime)
ax.set_yticks([]) ax.set_yticks([])
ax.set_title(self.Data[0].stats.station) ax.set_title(self.Data[0].stats.station)
if plt_flag == 1:
fig.show()
raw_input()
plt.close(fig)
return return
iislope = islope[0][0:imax] iislope = islope[0][0:imax]
dataslope = self.Data[0].data[iislope] dataslope = self.Data[0].data[iislope]
@ -273,6 +279,7 @@ class AICPicker(AutoPicker):
if self.iplot > 1: if self.iplot > 1:
if not self.fig: if not self.fig:
fig = plt.figure() # self.iplot) fig = plt.figure() # self.iplot)
plt_flag = 1
else: else:
fig = self.fig fig = self.fig
ax1 = fig.add_subplot(211) ax1 = fig.add_subplot(211)
@ -307,8 +314,16 @@ class AICPicker(AutoPicker):
ax2.set_ylabel('Counts') ax2.set_ylabel('Counts')
ax2.set_yticks([]) ax2.set_yticks([])
ax2.legend() ax2.legend()
if plt_flag == 1:
fig.show()
raw_input()
plt.close(fig)
else: else:
ax1.set_title(self.Data[0].stats.station) ax1.set_title(self.Data[0].stats.station)
if plt_flag == 1:
fig.show()
raw_input()
plt.close(fig)
if self.Pick == None: if self.Pick == None:
print('AICPicker: Could not find minimum, picking window too short?') print('AICPicker: Could not find minimum, picking window too short?')
@ -330,6 +345,7 @@ class PragPicker(AutoPicker):
self.SNR = None self.SNR = None
self.slope = None self.slope = None
pickflag = 0 pickflag = 0
plt_flag = 0
# smooth CF # smooth CF
ismooth = int(round(self.Tsmooth / self.dt)) ismooth = int(round(self.Tsmooth / self.dt))
cfsmooth = np.zeros(len(self.cf)) cfsmooth = np.zeros(len(self.cf))
@ -408,6 +424,7 @@ class PragPicker(AutoPicker):
if self.getiplot() > 1: if self.getiplot() > 1:
if not self.fig: if not self.fig:
fig = plt.figure() # self.getiplot()) fig = plt.figure() # self.getiplot())
plt_flag = 1
else: else:
fig = self.fig fig = self.fig
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
@ -419,6 +436,10 @@ class PragPicker(AutoPicker):
ax.set_yticks([]) ax.set_yticks([])
ax.set_title(self.Data[0].stats.station) ax.set_title(self.Data[0].stats.station)
ax.legend() ax.legend()
if plt_flag == 1:
fig.show()
raw_input()
plt.close(fig)
return return
else: else:

View File

@ -50,6 +50,7 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, verbosity=1, fig=None):
LPick = None LPick = None
EPick = None EPick = None
PickError = None PickError = None
plt_flag = 0
if verbosity: if verbosity:
print('earllatepicker: Get earliest and latest possible pick' print('earllatepicker: Get earliest and latest possible pick'
' relative to most likely 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 iplot > 1:
if not fig: if not fig:
fig = plt.figure() # iplot) fig = plt.figure() # iplot)
plt_flag = 1
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
ax.plot(t, x, 'k', label='Data') 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') 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' % 'Earliest-/Latest Possible/Most Likely Pick & Symmetric Pick Error, %s' %
X[0].stats.station) X[0].stats.station)
ax.legend() ax.legend()
if plt_flag == 1:
fig.show()
raw_input()
plt.close(fig)
return EPick, LPick, PickError return EPick, LPick, PickError
@ -167,6 +173,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None):
:type: int :type: int
''' '''
plt_flag = 0
warnings.simplefilter('ignore', np.RankWarning) warnings.simplefilter('ignore', np.RankWarning)
assert isinstance(Xraw, Stream), "%s is not a stream object" % str(Xraw) 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 iplot > 1:
if not fig: if not fig:
fig = plt.figure() # iplot) fig = plt.figure() # iplot)
plt_flag = 1
ax1 = fig.add_subplot(211) ax1 = fig.add_subplot(211)
ax1.plot(t, xraw, 'k') ax1.plot(t, xraw, 'k')
ax1.plot([Pick, Pick], [max(xraw), -max(xraw)], 'b', linewidth=2, label='Pick') 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.text(Pick + 0.02, max(xraw) / 2, '%s' % FM, fontsize=14)
ax2.set_xlabel('Time [s] since %s' % Xraw[0].stats.starttime) ax2.set_xlabel('Time [s] since %s' % Xraw[0].stats.starttime)
ax2.set_yticks([]) ax2.set_yticks([])
if plt_flag == 1:
fig.show()
raw_input()
plt.close(fig)
return FM return FM
@ -685,6 +697,7 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fi
: type: int : type: int
''' '''
plt_flag = 0
assert isinstance(X, Stream), "%s is not a stream object" % str(X) assert isinstance(X, Stream), "%s is not a stream object" % str(X)
print("Checking signal length ...") print("Checking signal length ...")
@ -729,6 +742,7 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fi
if iplot == 2: if iplot == 2:
if not fig: if not fig:
fig = plt.figure() # iplot) fig = plt.figure() # iplot)
plt_flag = 1
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
ax.plot(t, rms, 'k', label='RMS Data') 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') 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_ylabel('Counts')
ax.set_title('Check for Signal Length, Station %s' % X[0].stats.station) ax.set_title('Check for Signal Length, Station %s' % X[0].stats.station)
ax.set_yticks([]) ax.set_yticks([])
if plt_flag == 1:
fig.show()
raw_input()
plt.close(fig)
return returnflag return returnflag