Changeset 886 for SHX/trunk


Ignore:
Timestamp:
12/05/12 15:43:39 (8 years ago)
Author:
marcus
Message:
  • display now respects T-ORIGIN and STW setting
  • SHIFT, STW and DTW invalidate cache
  • clean-up test script
Location:
SHX/trunk/SeismicHandler
Files:
11 edited
1 moved

Legend:

Unmodified
Added
Removed
  • SHX/trunk/SeismicHandler

    • Property svn:ignore
      •  

        old new  
         1inventory.db 
        12*.pyc 
        23.project 
  • SHX/trunk/SeismicHandler/basics/codes.py

    r255 r886  
    11# -*- coding: utf-8 -*- 
    2 # 
    3 # Copyright (C) 2008-2010 Marcus Walther (walther@szgrf.bgr.de) 
    4 # 
    5 # This file is part of Seismic Handler eXtended (SHX) 
    6 # Full details can be found at project website http://www.seismic-handler.org/ 
    7 #  
    8 # SHX is free software; you can redistribute it and/or modify 
    9 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by 
    10 # the Free Software Foundation; either version 3 of the License, or 
    11 # (at your option) any later version. 
    12 # 
    13 # SHX is distributed in the hope that it will be useful, 
    14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 
    15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    16 # GNU Lesser General Public License for more details. 
    17 # 
    18 # You should have received a copy of the GNU Lesser General Public License 
    19 # along with SHX (see license.txt); if not, write to the Free Software 
    20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
     2 
     3#    This file is part of Seismic Handler eXtended (SHX). For terms of use and 
     4#    license information please see license.txt and visit 
     5#    http://www.seismic-handler.org/portal/wiki/Shx/LicenseTerms 
    216 
    227"""includes constants and other nearly static information""" 
    238 
    249LICENCE = """ 
    25 Seismic Handler eXtended version %s, Copyright by Klaus Stammler, Marcus  
    26 Walther, others and Federal Institute for Geosciences and Natural Resources  
    27 (http://www.bgr.bund.de/). 
     10Seismic Handler eXtended version %s, Copyright by Marcus Walther. C library 
     11code originates from Seismic Handler by Klaus Stammler and others. Software 
     12development was funded by Federal Institute for Geosciences and Natural 
     13Resources (http://www.bgr.bund.de/) and German Research Foundation (Deutsche 
     14Forschungsgemeinschaft - http://www.dfg.de/en/). 
    2815  
    29 Seismic Handler comes with ABSOLUTELY NO WARRANTY. This is free software 
    30 released under terms and conditions of LGPL. Full license text is available in 
    31 license.txt or online http://www.gnu.org/licenses/lgpl.html 
     16Seismic Handler eXtended comes with ABSOLUTELY NO WARRANTY. This is free 
     17software released under terms and conditions of LGPL. Full license text is 
     18available in license.txt or online http://www.gnu.org/licenses/lgpl.html 
    3219""" 
    3320 
    3421# man managed version number 
    35 VERSION = "0.1" 
     22VERSION = "0.2" 
    3623 
    3724SUCCESS = 1 
  • SHX/trunk/SeismicHandler/basics/messages.py

    r781 r886  
    104104    Simple event propagating method. 
    105105    """ 
    106     msgs.sendMessage("EVENT.%s" % name, payload=payload) 
     106    msgs.sendMessage("EVENT:%s" % name, payload=payload) 
    107107    log_message("debug.message", "Event '%s' sent." % name) 
     108 
     109def subscribe_event(method, event): 
     110    msgs.subscribe(method, "EVENT:%s" % event) 
    108111 
    109112def set_style(block, item=None, value=None): 
  • SHX/trunk/SeismicHandler/commands/dtw.py

    r722 r886  
    66 
    77from SeismicHandler.basics.command import BaseCommand 
    8 from SeismicHandler.basics.messages import set_runtime 
     8from SeismicHandler.basics.messages import set_runtime, send_event 
    99 
    1010 
     
    2222    def run(self): 
    2323        set_runtime("timewindow", (0., None)) 
     24        send_event("recache") 
    2425 
    2526 
  • SHX/trunk/SeismicHandler/commands/shift.py

    r841 r886  
    4646        for t, value in zip(lst, values): 
    4747            t.set_info("t-origin", t.get_info("t-origin") + value) 
     48            t.invalidate_cache() 
    4849 
    4950            msg = "trace %u shifted by %.2f seconds" % (t.index(True), value) 
  • SHX/trunk/SeismicHandler/commands/stw.py

    r722 r886  
    66 
    77from SeismicHandler.basics.command import BaseCommand 
    8 from SeismicHandler.basics.messages import set_runtime 
     8from SeismicHandler.basics.messages import set_runtime, send_event 
    99from SeismicHandler.basics.error import ShxError 
    1010 
     
    2424        try: 
    2525            set_runtime("timewindow", map(float, self.parameters)) 
     26            send_event("recache") 
    2627        except ValueError: 
    2728            raise ShxError("float conversion error", status=1108) 
  • SHX/trunk/SeismicHandler/config/runtime.py

    r843 r886  
    100100        "RUNTIME:q_datadir": ".", 
    101101        # normation type 
    102         "RUNTIME:normtype": "AF", 
     102        "RUNTIME:normtype": "AW", # SW, AT, ST (all, single; window, total) 
    103103        # correlation mode 
    104104        "RUNTIME:corrmode": 1, 
  • SHX/trunk/SeismicHandler/modules/screen.py

    r831 r886  
    1111import wx 
    1212from SeismicHandler.basics import Singleton 
    13 from SeismicHandler.basics.messages import msgs, set_runtime, log_message, \ 
    14                                                                     get_runtime 
     13from SeismicHandler.basics.messages import set_runtime, log_message, \ 
     14                                                   get_runtime, subscribe_event 
    1515from SeismicHandler.core import Traces 
    1616from SeismicHandler.basics.error import ShxError 
     
    2929 
    3030    def setup(self): 
    31         msgs.subscribe(self.redraw, 'EVENT.redraw') 
     31        subscribe_event(self.redraw, 'redraw') 
    3232        log_message("debug.screen", "init") 
    3333        self.__init = True 
     
    132132 
    133133        if auto_redraw: 
    134             msgs.subscribe(self.trigger_redraw, 'EVENT.redraw') 
     134            subscribe_event(self.trigger_redraw, 'redraw') 
    135135 
    136136        log_message("debug.traceplotter", "init") 
  • SHX/trunk/SeismicHandler/modules/traces.py

    r816 r886  
    88from obspy.core.util import AttribDict 
    99from SeismicHandler.basics import Singleton 
    10 from SeismicHandler.basics.messages import log_message, _set_runtime_var 
     10from SeismicHandler.basics.messages import log_message, _set_runtime_var, \ 
     11                                                                subscribe_event 
    1112from obspy.core.stream import Stream, Trace 
    1213from SeismicHandler.config import Settings 
     
    252253 
    253254 
     255def invalidate_all_traces(payload=None): 
     256    """ 
     257    Voids all trace caches. 
     258    """ 
     259    for t in Traces().visible: 
     260        t.invalidate_cache() 
     261subscribe_event(invalidate_all_traces, "recache") 
     262 
     263 
    254264if __name__ == "__main__": 
    255265    import doctest 
  • SHX/trunk/SeismicHandler/modules/wx_.py

    r817 r886  
    88import wx.lib.scrolledpanel as SP 
    99import time 
    10 from SeismicHandler.basics.messages import msgs, log_message 
     10from SeismicHandler.basics.messages import msgs, log_message, get_runtime 
    1111from SeismicHandler.core import Traces 
    1212from obspy.core import read, UTCDateTime 
     
    7575        msgs.subscribe(self.OnNotifyTraceOrder, 'GUI.traceorder') 
    7676        msgs.subscribe(self.OnNotifyTimeAxis, 'GUT.timeaxis') 
    77 #        msgs.subscribe(self._resetTimeRange, 'EVENT.redraw') 
    7877 
    7978        # init 
    80 #        self.load(fnames) 
    8179        self.OnPaint(None) 
    8280        self.SetFocus() 
     
    231229        """ 
    232230        if self.refresh: 
     231            self._timewindow = get_runtime("timewindow") 
     232            self._normtype = get_runtime("normtype") 
    233233            self._resetTimeRange() 
    234234            self._drawTraces() 
     
    552552        time scale. 
    553553        """ 
     554        # we cannot use the Screen module because of loop imports 
     555        if self._timewindow[1] is None: 
     556            timewindow = get_runtime("extend") 
     557        else: 
     558            timewindow = self._timewindow 
    554559        width, height = self.GetVirtualSize() 
    555560        numTraces = len(self.traces) 
     561        globalnorm = self._normtype.startswith("A") 
    556562 
    557563        if self.traceOrder in [0, 1]: 
     
    600606                end = start + self.maxDuration 
    601607 
    602             t.prepare_image_data(pltwidth, theight, (start, end), zoom=0.9) 
     608            norm = globalnorm and self.maxAmplitude or self._normtype[1] 
     609            t.prepare_image_data(pltwidth, theight, timewindow, zoom=0.9, norm=norm) 
    603610 
    604611            # make trace graphics sketch 
     
    616623            buffer.SetPen(wx.Pen((45,45,45), 1)) 
    617624 
     625            torig = t.get_info("t-origin") 
     626            if torig <= timewindow[0]: 
     627                _shift = 0 
     628            else: 
     629                _shift = torig - timewindow[0] 
     630 
    618631            # calculate offset to global time scale 
    619             plotStartSec = t.stats.starttime - start 
     632            plotStartSec = t.stats.starttime + _shift - start 
    620633            plotoffset = 0 
    621             if plotStartSec and not self.relativeAxis: 
     634            if plotStartSec or not self.relativeAxis: 
    622635                # re-calculate offset 
    623                 portion = plotStartSec / (end - start) 
     636                portion = plotStartSec / (timewindow[1] - timewindow[0]) 
    624637                plotoffset = portion * pltwidth 
    625638            t.shx.plotoffset = plotoffset 
     
    700713        canvas.SetPen(wx.Pen('Black', 1)) 
    701714        if self.relativeAxis: 
    702             end = end - start 
    703             start = 0 
     715            start, end = timewindow 
    704716 
    705717        if self.traceOrder in [0, 1]: 
     
    781793        dc2.Blit(0, 0, width, height, canvas, x, y) 
    782794 
    783     def _debug(self, *args): 
     795    @staticmethod 
     796    def _debug(*args): 
    784797        log_message('debug', " ".join([str(i) for i in args])) 
    785798 
    786799    def _resetTimeRange(self, **kwargs): 
    787800        """ 
    788         Gather information about traces. Called via message system. 
     801        Gather information about traces. Called on redraw (at idle state). 
    789802        """ 
    790803        min = UTCDateTime() # now 
    791804        max = UTCDateTime(0) # 1970 
     805        minrel = 1e20 
     806        maxrel = 0 
    792807        maxDuration = 0 
    793808        amplitude = 0 
    794809 
    795810        for t in self.traces: 
     811            s = t.get_info("relstart") 
     812            e = t.get_info("relend") 
     813            if s < minrel: 
     814                minrel = s 
     815            if e > maxrel: 
     816                maxrel = e 
    796817            if t.stats.starttime < min: 
    797818                min = t.stats.starttime 
     
    799820                max = t.stats.endtime 
    800821            # needed for relative time axis 
    801             l = t.stats.endtime - t.stats.starttime 
     822            l = e - s 
    802823            if l > maxDuration: 
    803824                maxDuration = l 
    804             # used for normation 
    805             t_ampl = abs(t.max() * t.stats.calib) 
     825            # normation 
     826            # no time window set or normtype forces full traces 
     827            if self._timewindow[1] is None or self._normtype.startswith("A"): 
     828                data = t.data 
     829            else: 
     830                data = t.get_datawindow(*timewindow) 
     831            t_ampl = abs(data.max()) 
    806832            if t_ampl > amplitude: 
    807833                amplitude = t_ampl 
    808834 
    809835        self.start = min 
     836        self.relstart = minrel 
    810837        self.end = max 
     838        self.relend = maxrel 
    811839        self.maxDuration = maxDuration 
    812840        self.maxAmplitude = amplitude 
     
    842870 
    843871    def redraw(self): 
    844 #        e = wx.PyEvent() 
    845 #        e.SetEventType=wx.EVT_PAINT 
    846 #        wx.PostEvent(self.canvas, e) 
    847872        self.canvas.OnPaint(None) 
  • SHX/trunk/SeismicHandler/patches/obspy_.py

    r841 r886  
    5151    _stream_auto_merge(self) 
    5252 
    53 def trace_prepare_image_data(self, width, height, timescale=None, zoom=1, norm="window"): 
     53def trace_prepare_image_data(self, width, height, timewindow=None, zoom=1, 
     54                                           norm="window", norm_amplitude=None): 
    5455    """ 
    5556    Preparing trace data for fast plotting. Using numpy's minmax feature - this 
    5657    will not just downsample the data! 
    5758 
    58     width : total width of plotting window in pixels 
    59     height : hight of plotting window in pixels 
    60     zoom : global zoom factor (y extension) 
    61     timescale : extension of current timescale (tuple of min and max) 
    62     norm : norm method: "window", "total" or value (effects y extension) 
     59    width:         total width of plotting window in pixels 
     60    height:        hight of plotting window in pixels 
     61    zoom:          global zoom factor (y extension) 
     62    timewindow:    current global time window (tuple of min and max) 
     63    norm:          norm method: "window", "total" or float value 
     64                   (effects y extension) 
     65    max_amplitude: maximum global amplitude. If set this values is used for 
     66                   normation 
    6367    """ 
    6468    log_message('debug.patches', "Preparing plotting data...", self.id) 
    6569 
    66     if not timescale: 
     70    if not timewindow: 
    6771        # use trace's total dimensions 
    68         windowstart, windowend = (self.stats.starttime, self.stats.endtime) 
    69     else: 
    70         windowstart, windowend = timescale 
     72        windowstart, windowend = (self.get_info("relstart"), 
     73                                                       self.get_info("relend")) 
     74    else: 
     75        windowstart, windowend = timewindow 
    7176 
    7277    # get slice for time window 
    73     pt = self.slice(windowstart, windowend) 
     78    pt = self.slice_relative(windowstart, windowend) 
    7479 
    7580    duration_total = windowend - windowstart 
     
    8186    # remember values for caching 
    8287    CacheTraceID = \ 
    83               (windowstart, windowend, "%.5f" % pixel_width, height, zoom, norm) 
     88             (windowstart, windowend, "%.5f" % pixel_width, height, zoom, norm) 
    8489    try: 
    8590        cachedX = CacheTraceID[:3] == self.shx.CacheTraceID[:3] 
     
    151156    # get basis for normation 
    152157    if hasattr(norm, "lower"): 
    153         norm = norm.lower() 
    154         if norm == "window": 
     158        norm = norm.upper()[0] 
     159        if norm == "W": 
    155160            norm = abs(pt.max()) 
    156         elif norm == "total": 
     161        elif norm == "T": 
    157162            norm = self.max() 
    158163        else: 
     
    205210def trace_invalidate_cache(self): 
    206211    """ 
    207     Mark the cached pixel data as dirty. Needed if data is alterd inplace. 
     212    Mark the cached pixel data as dirty. Needed if data is altered inplace. 
    208213    """ 
    209214    msg = "Pixel cache marked dirty for trace %u" % self.index() 
     
    262267        return self.stats.endtime - self.stats.starttime + \ 
    263268                                                   self.get_info("T-ORIGIN", 0) 
     269 
     270    # length in seconds 
     271    if name == "LENGTH_TIME": 
     272        return self.stats.endtime - self.stats.starttime 
    264273 
    265274    # inside additional headers 
Note: See TracChangeset for help on using the changeset viewer.