refresh plot for plotAllPicks by replotting

This commit is contained in:
Marcel Paffrath 2015-10-12 14:39:40 +02:00
parent a19cdc4fee
commit 34abad46e2

View File

@ -18,6 +18,7 @@ class Survey(object):
self.setParametersForShots() self.setParametersForShots()
self._removeAllEmptyTraces() self._removeAllEmptyTraces()
self._updateShots() self._updateShots()
self.setArtificialPick(0, 0) # artificial pick at source origin
def _generateSurvey(self): def _generateSurvey(self):
from obspy.core import read from obspy.core import read
@ -33,17 +34,23 @@ class Survey(object):
shot_dict[shotnumber] = seismicshot.SeismicShot(obsfile) shot_dict[shotnumber] = seismicshot.SeismicShot(obsfile)
shot_dict[shotnumber].setParameters('shotnumber', shotnumber) shot_dict[shotnumber].setParameters('shotnumber', shotnumber)
self.setArtificialPick(0, 0) # artificial pick at source origin
self.data = shot_dict self.data = shot_dict
print ("Generated Survey object for %d shots" % len(shotlist)) print ("Generated Survey object for %d shots" % len(shotlist))
print ("Total number of traces: %d \n" %self.countAllTraces()) print ("Total number of traces: %d \n" %self.countAllTraces())
def setArtificialPick(self, traceID, pick):
'''
Sets an artificial pick for a traceID of all shots in the survey object.
(This can be used to create a pick with t = 0 at the source origin)
'''
for shot in self.data.values():
shot.setPick(traceID, pick)
def setParametersForShots(self, cutwindow = (0, 0.2), tmovwind = 0.3, tsignal = 0.03, tgap = 0.0007): def setParametersForShots(self, cutwindow = (0, 0.2), tmovwind = 0.3, tsignal = 0.03, tgap = 0.0007):
if (cutwindow == (0, 0.2) and tmovwind == 0.3 and if (cutwindow == (0, 0.2) and tmovwind == 0.3 and
tsignal == 0.03 and tgap == 0.0007): tsignal == 0.03 and tgap == 0.0007):
print ("Warning: Standard values used for " print ("Warning: Standard values used for "
"setParamters. This may not be clever.") "setParamters. This might not be clever.")
# CHANGE this later. Parameters only needed for survey, not for each shot. # CHANGE this later. Parameters only needed for survey, not for each shot.
for shot in self.data.values(): for shot in self.data.values():
shot.setCut(cutwindow) shot.setCut(cutwindow)
@ -120,14 +127,13 @@ class Survey(object):
shot.setPickwindow(traceID, pickwin_used) shot.setPickwindow(traceID, pickwin_used)
shot.pickTraces(traceID, windowsize, folm, HosAic) # picker shot.pickTraces(traceID, windowsize, folm, HosAic) # picker
# ++ TEST: set and check SNR before adding to distance bin ############################
shot.setSNR(traceID) shot.setSNR(traceID)
#if shot.getSNR(traceID)[0] < snrthreshold: #if shot.getSNR(traceID)[0] < snrthreshold:
if shot.getSNR(traceID)[0] < shot.getSNRthreshold(traceID): if shot.getSNR(traceID)[0] < shot.getSNRthreshold(traceID):
shot.removePick(traceID) shot.removePick(traceID)
# -- TEST: set and check SNR before adding to distance bin ############################
if shot.getFlag(traceID) is not 0: # set epp and lpp if SNR > 1 (else earllatepicker cant set values)
if shot.getSNR(traceID)[0] > 1:
shot.setEarllatepick(traceID) shot.setEarllatepick(traceID)
tpicksum += (datetime.now() - tstartpick); tpick = tpicksum/count tpicksum += (datetime.now() - tstartpick); tpick = tpicksum/count
@ -137,6 +143,22 @@ class Survey(object):
self._update_progress(shot.getShotname(), tend, progress) self._update_progress(shot.getShotname(), tend, progress)
print('\npickAllShots: Finished\n') print('\npickAllShots: Finished\n')
def recover(self):
'''
Recovers all (accidently) removed picks. Still regards SNR threshold.
'''
print('Recovering survey...')
numpicks = 0
for shot in self.data.values():
for traceID in shot.getTraceIDlist():
if shot.getFlag(traceID) == 0:
shot.setFlag(traceID, 1)
if shot.getSNR(traceID)[0] < shot.getSNRthreshold(traceID):
shot.removePick(traceID)
else:
numpicks += 1
print('Recovered %d picks'%numpicks)
def setArtificialPick(self, traceID, pick): def setArtificialPick(self, traceID, pick):
for shot in self.data.values(): for shot in self.data.values():
shot.setPick(traceID, pick) shot.setPick(traceID, pick)
@ -256,49 +278,127 @@ class Survey(object):
count += 1 count += 1
return count return count
def plotAllPicks(self, plotDeleted = False): def countAllPickedTraces(self):
count = 0
for shot in self.data.values():
for traceID in shot.getTraceIDlist():
if shot.getFlag(traceID) is not 0:
count += 1
return count
def plotAllPicks(self, plotRemoved = False, ax = None):
''' '''
Plots all picks over the distance between source and receiver. Returns (ax, region) Plots all picks over the distance between source and receiver. Returns (ax, region).
Picks can be checked and removed by using region class.
Examples:
region.chooseRectangles():
- lets the user choose several rectangular regions in the plot
region.plotTracesInRegions():
- creates plots (shot.plot_traces) for all traces in the active regions (i.e. chosen by e.g. chooseRectangles)
region.setActiveRegionsForDeletion():
- highlights all shots in a the active regions for deletion
region.deleteMarkedPicks():
- deletes the picks (pick flag set to 0) for all shots set for deletion
region.deselectSelection(number):
- deselects the region of number = number
''' '''
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import math import math
plt.interactive(True) plt.interactive(True)
from pylot.core.active.surveyPlotTools import regions from pylot.core.active.surveyPlotTools import regions
refreshPlot = False
if ax is not None: refreshPlot = True
dist = [] dist = []
pick = [] pick = []
snrloglist = [] snrloglist = []
for shot in self.data.values(): for shot in self.data.values():
for traceID in shot.getTraceIDlist(): for traceID in shot.getTraceIDlist():
if plotDeleted == False: if plotRemoved == False:
if shot.getFlag(traceID) is not 0: if shot.getFlag(traceID) is not 0:
dist.append(shot.getDistance(traceID)) dist.append(shot.getDistance(traceID))
pick.append(shot.getPick(traceID)) pick.append(shot.getPick(traceID))
snrloglist.append(math.log10(shot.getSNR(traceID)[0])) snrloglist.append(math.log10(shot.getSNR(traceID)[0]))
elif plotDeleted == True: elif plotRemoved == True:
dist.append(shot.getDistance(traceID)) dist.append(shot.getDistance(traceID))
pick.append(shot.getPick(traceID)) pick.append(shot.getPickIncludeRemoved(traceID))
snrloglist.append(math.log10(shot.getSNR(traceID)[0])) snrloglist.append(math.log10(shot.getSNR(traceID)[0]))
ax = self.createPlot(dist, pick, snrloglist, label = 'log10(SNR)') if refreshPlot is False:
region = regions(ax, self.data) ax = self.createPlot(dist, pick, snrloglist, label = 'log10(SNR)')
ax.legend() region = regions(ax, self)
ax.legend()
return ax, region
elif refreshPlot is True:
ax = self.createPlot(dist, pick, snrloglist, label = 'log10(SNR)', ax = ax)
ax.legend()
return ax
return ax, region def plotAllShots(self, rows = 3, columns = 4):
'''
Plots all shots as Matrices with the color corresponding to the traveltime for each receiver.
NOTE: Topography (z - coordinate) is not considered in the diagrams!
'''
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
plt.interactive(True)
def createPlot(self, dist, pick, inkByVal, label): fig = plt.figure()
ax = fig.add_subplot(111)
figPerSubplot = columns * rows
index = 1
#shotnames = []
#shotnumbers = []
# for shot in self.data.values():
# shotnames.append(shot.getShotname())
# shotnumbers.append(shot.getShotnumber())
# shotnumbers = [shotnumbers for (shotnumbers, shotnames) in sorted(zip(shotnumbers, shotnames))]
for shotnumber in self.getShotlist():
if index <= figPerSubplot:
#ax = fig.add_subplot(3,3,i, projection = '3d', title = 'shot:'
#+str(shot_dict[shotnumber].getShotnumber()), xlabel = 'X', ylabel = 'Y', zlabel = 'traveltime')
#shot_dict[shotnumber].plot3dttc(ax = ax, plotpicks = True)
ax = fig.add_subplot(3, 4, index)
self.getShot(shotnumber).matshow(ax = ax, colorbar = False, annotations = True)
index += 1
if index > figPerSubplot:
fig.subplots_adjust(left = 0, bottom = 0, right = 1, top = 1, wspace = 0, hspace = 0)
fig = plt.figure()
index = 1
fig.subplots_adjust(left = 0, bottom = 0, right = 1, top = 1, wspace = 0, hspace = 0)
def createPlot(self, dist, pick, inkByVal, label, ax = None):
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
plt.interactive(True) plt.interactive(True)
cm = plt.cm.jet cm = plt.cm.jet
fig = plt.figure() if ax is None:
ax = fig.add_subplot(111) print('Generating new plot...')
fig = ax.scatter(dist, pick, cmap = cm, c = inkByVal, s = 5, edgecolors = 'none', label = label) fig = plt.figure()
cbar = plt.colorbar(fig, fraction = 0.05) ax = fig.add_subplot(111)
cbar.set_label(label) fig = ax.scatter(dist, pick, cmap = cm, c = inkByVal, s = 5, edgecolors = 'none', label = label)
plt.title('Plot of all Picks') cbar = plt.colorbar(fig, fraction = 0.05)
plt.xlabel('Distance [m]') cbar.set_label(label)
plt.ylabel('Time [s]') plt.title('Plot of all Picks')
plt.xlabel('Distance [m]')
plt.ylabel('Time [s]')
else:
print('Refreshing plot...')
ax.scatter(dist, pick, cmap = cm, c = inkByVal, s = 5, edgecolors = 'none', label = label)
return ax return ax