Changeset 394
- Timestamp:
- 05/25/2011 06:12:40 PM (12 years ago)
- Location:
- SHX/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
SHX/trunk/SeismicHandler/patches/ObsPy.py
r388 r394 28 28 29 29 import numpy as np 30 import math 31 import wx 30 32 from obspy.core import Stream, Trace 31 33 #from obspy.core import UTCDateTime … … 70 72 width : total width of plotting window in pixels 71 73 height : hight of plotting window in pixels 72 zoom : global zoom factor 73 timescale : extension of current timescale ( min and max)74 norm : norm method: "window", "total" or value 74 zoom : global zoom factor (y extension) 75 timescale : extension of current timescale (tuple of min and max) 76 norm : norm method: "window", "total" or value (effects y extension) 75 77 """ 76 78 if not timescale: 77 # use trace's dimensions79 # use trace's total dimensions 78 80 windowstart, windowend = (self.stats.starttime, self.stats.endtime) 79 81 else: … … 91 93 92 94 # width of the total screen that is covered by trace data (pixels) 93 portion = duration_trace * width / duration_total 95 pixel_width = duration_trace * width / duration_total 96 self.shxPixelWidth = pixel_width 94 97 95 98 # data points per pixel 96 99 npts = pt.stats.npts 97 dpp = int(npts / p ortion)100 dpp = int(npts / pixel_width) 98 101 99 102 # get copy of data 100 self.shx _plotdata = pt.data.copy()103 self.shxPlotData = pt.data.copy() 101 104 102 105 # use minmax approach if more than 4 data points per pixel 106 # self.shx_plotdata will be changed 103 107 if dpp >= 4: 104 dimy = npts // dpp 105 shape = dpp * dimy 106 print "minmax", npts, dpp, dimy, shape 107 108 # do integer division since array shape values cannot be floats 109 dimx = npts // dpp 110 covered = dpp * dimx 108 111 109 print width, height, norm, duration_trace, duration_total, portion, dpp, type(self.shx_plotdata) 112 # get data for reshape operation 113 data = self.shxPlotData[:covered] 110 114 115 # extra treatment for remaining values 116 remaining = self.shxPlotData[covered:] 117 118 # reshape data and get min/max values 119 data.shape = dimx, dpp 120 _min = data.min(axis=1) 121 _max = data.max(axis=1) 122 # combine data 123 joined = np.append([_min], [_max], axis=0).T.flatten() 124 # handle remaining 125 if len(remaining): 126 joined = np.append(joined, [remaining.min(), remaining.max()]) 127 128 print "pixel_width", pixel_width, "minmax", "npts", npts, "dpp", dpp, "dimx", dimx, \ 129 "covered", covered, "len_rest", len(remaining), "data_len", \ 130 len(data), "joined", len(joined) 131 132 self.shxPlotData = joined 133 134 # At this stage the x-transformed data can be cached! If pixel_width doesn't 135 # change, the data can be reused to save time. 136 137 print width, height, norm, duration_trace, duration_total, pixel_width, dpp, type(self.shxPlotData) 138 139 # get basis for normation 111 140 if hasattr(norm, "lower"): 112 141 norm = norm.lower() … … 117 146 else: 118 147 raise ValueError("Invalid input for normation!") 119 else:120 norm = norm121 148 122 # traces in a stream are merge automatically 149 # Calculate y extension, leads to raw "image" data. 150 # Use a copy to save time if only y changes occur (e.g. zooming). 151 # Apply normation, calibration and total height factor 152 y = self.shxPlotData.copy() 153 y *= self.stats.calib / norm * height / 2 * zoom 154 155 print self.shxPlotData.min(), self.shxPlotData.max(), y.min(), y.max() 156 157 # factor for x stretching (trade-off between pixel_width and array shape) 158 stretch = pixel_width / len(y) 159 width = int(math.ceil(pixel_width)) 160 161 # calculate line data 162 # do not rely on framework axis' management -> shift/flip y-axis 163 offset = height // 2 164 lines = [] 165 oldx, oldy = 0, -y[0] + offset 166 167 for i in xrange(1, len(y)): 168 newx = i * stretch 169 newy = -y[i] + offset 170 lines.append([oldx, oldy, newx, newy]) 171 oldx, oldy = newx, newy 172 173 self.shxImageData = lines 174 175 def __traceX(parameters): 176 """ 177 Only the x axis is adopted here. Zoom, norm etc. regarding the y extension 178 is done ... 179 """ 180 pass 181 182 # monkey patching obspy stream class: traces are merge automatically if stream 183 # get's altered. 123 184 Stream.__shx_init__, Stream.__init__ = Stream.__init__, streamAutoMergeInit 124 185 Stream.__shx_append, Stream.append = Stream.append, streamAutoMergeAppend … … 128 189 129 190 # add method for faster plotting 130 Trace.shx _prepareImageData = tracePrepareDataForImage191 Trace.shxPrepareImageData = tracePrepareDataForImage 131 192 193 # just an indicator 132 194 patched = True -
SHX/trunk/sandbox/bc_example.py
r354 r394 152 152 pos=wx.DefaultPosition, 153 153 size=wx.DefaultSize, 154 style=wx.DEFAULT_FRAME_STYLE ):154 style=wx.DEFAULT_FRAME_STYLE | wx.FULL_REPAINT_ON_RESIZE): 155 155 156 156 wx.Frame.__init__(self, parent, ID, title, pos, size, style) -
SHX/trunk/sandbox/traceplotter.py
r383 r394 1 1 # -*- coding: utf-8 -*- 2 2 3 import wx 4 import wx.lib.scrolledpanel as SP 3 5 from SeismicHandler.core import read 4 #from obspy.core import UTCDateTime5 6 6 st = read() 7 tr = st[0] 7 class MyPanel(SP.ScrolledPanel): 8 def __init__(self, parent): 9 SP.ScrolledPanel.__init__(self, parent, style=wx.BORDER_SIMPLE) 10 self.Bind(wx.EVT_PAINT, self.OnPaint) 11 # self.Bind(wx.EVT_RESIZE, self.OnPaint) 12 self.Bind(wx.EVT_IDLE, self.OnIdle) 13 self.refresh = False 14 self.OnPaint(None) 8 15 9 start = tr.stats.starttime - 4 10 end = tr.stats.endtime + 4 16 st = read("/online4/2011/GR/BFO/BHZ.D/GR.BFO..BHZ.D.2011.124") 17 self.tr = st[0] 11 18 12 tr.shx_prepareImageData(700, 100, (start, end)) 19 def OnIdle(self, evt): 20 if self.refresh: 21 self.Paint() 22 self.refresh = False 23 24 def OnPaint(self, evt): 25 self.refresh = True 26 27 def Paint(self): 28 width, height = self.GetClientSize() 29 30 start = self.tr.stats.starttime - 4 31 end = self.tr.stats.endtime + 4 32 33 self.tr.shxPrepareImageData(width, height, (start, end)) 34 35 bitmap = wx.EmptyBitmap(width, height) 36 buffer = wx.MemoryDC(bitmap) 37 buffer.Clear() 38 # dc = wx.GCDC(buffer) 39 dc = buffer 40 dc.BeginDrawing() 41 dc.DrawLineList(self.tr.shxImageData) 42 dc.EndDrawing() 43 44 dc2 = wx.AutoBufferedPaintDCFactory(self) 45 dc2.Blit(0, 0, width, height, buffer, 0, 0, wx.COPY) 46 47 class MyFrame(wx.Frame): 48 def __init__(self, parent, title): 49 wx.Frame.__init__(self, parent, title=title, size=(640,480), style=wx.DEFAULT_FRAME_STYLE | wx.FULL_REPAINT_ON_RESIZE) 50 self.canvas = MyPanel(self) 51 self.Show() 52 53 def main(): 54 app = wx.App(False) 55 frame = MyFrame(None, 'Trace Plotter Test') 56 app.MainLoop() 57 58 if __name__ == '__main__': 59 main()
Note: See TracChangeset
for help on using the changeset viewer.