Changeset 154
- Timestamp:
- 09/30/2009 05:10:27 PM (14 years ago)
- Location:
- SHX/trunk/src/SeismicHandler
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
SHX/trunk/src/SeismicHandler/core/modules/Trace.py
r153 r154 59 59 self.update(memblc=kwargs.get("memblc")) 60 60 61 # create new trace from numpy data 62 # additional information required - at least delta 63 if kwargs.has_key("data") and kwargs.has_key("delta"): 64 self._create(**kwargs) 65 61 66 def __len__(self): 62 67 """return number of samples""" … … 93 98 raise InfoEntryReadOnlyError(name.upper()) 94 99 95 self.__dict__["_info"][name ] = value100 self.__dict__["_info"][name.upper()] = value 96 101 shlib().setInfoEntry(self.address, name, value) 97 102 … … 173 178 self._info = info 174 179 # self.listInfo() 180 181 def _create(self, **kwargs): 182 slib = shlib().sh 183 slib.db_newlist() 184 185 slib.db_create.restype = C.POINTER(MEMBLC) 186 187 status = C.c_int(0) 188 memblc = slib.db_create(C.byref(status)) 189 190 slib.ml_inittrc.argtypes = [C.POINTER(MEMBLC), C.POINTER(C.c_float), C.c_int, C.c_float] 191 slib.ml_inittrc(memblc, kwargs["data"], len(kwargs["data"]), kwargs["delta"]) 192 193 self.address = C.addressof(memblc.contents) 194 self.update(memblc=memblc.contents) 175 195 176 196 class Traces(object): … … 278 298 from SeismicHandler.core.modules.Graphics import pylab 279 299 280 fig = pylab.figure( )300 fig = pylab.figure(figsize=(12,7)) 281 301 fig.canvas.set_window_title("SHX - plot of %u traces" % len(self)) 282 pylab.subplots_adjust(hspace=0.1, wspace=20, left=0.1, right=0.9 5, bottom=0.05, top=0.95)302 pylab.subplots_adjust(hspace=0.1, wspace=20, left=0.1, right=0.98, bottom=0.07, top=0.95) 283 303 284 304 fig.set_facecolor('w') 285 305 306 maxx = 0 286 307 for i, trc in enumerate(self): 287 308 # link x axis if more than one trace … … 297 318 ax.yaxis.set_major_locator(pylab.NullLocator()) 298 319 299 # build label from station ... 320 # build label from number... 321 label = "%u: " % (i+1,) 322 # ... station ... 300 323 if trc.station: 301 label = trc.station 324 label += trc.station 325 else: 326 label += "-?-" 302 327 # ... and component name 303 328 if trc.comp: 304 329 label += " " + trc.comp 330 else: 331 label += " -?-" 305 332 306 333 try: … … 314 341 else: 315 342 ax.xaxis.tick_bottom() 316 317 pylab.plot(np.arange(0, trc.delta * trc.length, trc.delta), trc.fetchData(), "k", linewidth=.5) 343 ax.set_xlabel("time in seconds") 344 345 duration = trc.delta * trc.length 346 pylab.plot(np.arange(0, duration, trc.delta), trc.fetchData(), "k", linewidth=.5) 347 348 maxx = duration > maxx and duration or maxx 318 349 319 350 # add some extra space around traces 320 351 limit = abs(max(pylab.ylim(), key=abs)) * 1.1 321 352 pylab.ylim(-limit, limit) 353 354 # set identical maximum x dimension for all traces 355 for i in fig.axes: 356 i.axis(xmax=maxx) 322 357 323 358 if save: … … 327 362 328 363 if __name__ == "__main__": 329 t = Traces()330 364 from SeismicHandler.core.commands import Run 331 365 332 MessageService.block(Message(MessageService.REDRAW)) 366 data = np.random.randn(1500).astype(np.float32) 367 x = Trace(data=(C.c_float*len(data)).from_address(data.ctypes.get_data()), delta=.05) 368 x.station = "testx".upper() 369 x.comp = "N" 370 x.chan1 = "B" 371 x.chan2 = "H" 372 373 data2 = np.random.randn(1800).astype(np.float32) 374 y = Trace(data=(C.c_float*len(data2)).from_address(data2.ctypes.get_data()), delta=.05) 375 333 376 # create 2 hours of synthetic data (100 Hz) 334 377 # position set by counter 335 378 for i in range(5): 336 Run("CREATE SHARP 0.05 100 1 . %u .1 .5" % (10+i*6))379 Run("CREATE SHARP 0.05 100 10. %u .1 .5" % (10+i*6)) 337 380 # Run("create sharp 0.1 7200 1 %u 0.005 .05" % 5**(i+1)) 338 381 339 382 Run("sum all") 340 MessageService.unblock(Message(MessageService.REDRAW)) 341 342 t.plot( True)383 384 t = Traces() 385 t.plot() -
SHX/trunk/src/SeismicHandler/core/shlib.py
r153 r154 81 81 82 82 # somewhat needless, since c lib doesn't deal which command line parameters 83 status = C.c_int()83 status = C.c_int() 84 84 CSTR_ARRAY = C.c_char_p * 1 85 85 argv = CSTR_ARRAY("") … … 144 144 "char": "db_setc", 145 145 "real": "db_setr", 146 "flag": "db_setf", # XXX 146 "flag": "db_setf", # XXX 147 147 "pointer": "db_setp", # XXX not needed (still unchangeable) 148 148 "time": "db_sett", … … 176 176 # self.call(StringIO("SHSTRTUP")) 177 177 # return 178 178 179 179 self.call(StringIO("wdw/dc=s/ic=s/main")) 180 180 self.call(StringIO("wdw/ic=s")) … … 228 228 except StopIteration: 229 229 break 230 231 # make changeable string (strings in python may no be altered!) 230 231 # make changeable string (strings in python may no be altered!) 232 232 cmdstr = C.create_string_buffer(cmdstr) 233 233 -
SHX/trunk/src/SeismicHandler/tests/test_traces.py
r153 r154 8 8 import unittest 9 9 10 class eventsTestCase(unittest.TestCase):10 class tracesTestCase(unittest.TestCase): 11 11 def setUp(self): 12 12 Run("cresharp") … … 192 192 193 193 def suite(): 194 return unittest.makeSuite( eventsTestCase, 'test')194 return unittest.makeSuite(tracesTestCase, 'test') 195 195 196 196 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.