Changeset 829 for SHX/trunk


Ignore:
Timestamp:
11/07/12 12:08:39 (8 years ago)
Author:
marcus
Message:
  • added [ShRms] to core methods
Location:
SHX/trunk/SeismicHandler
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • SHX/trunk/SeismicHandler/commands/rms.py

    r732 r829  
    5656        t = trcs[0] 
    5757 
    58         if start is not None: 
    59             _start = t.stats.starttime + start 
    60             _end = t.stats.starttime + end 
    61             t = t.slice(_start, _end) 
     58        if self.qualifiers["SRS"]: 
     59            method = "SRS" 
     60        elif self.qualifiers["SAM"]: 
     61            method = "SAM" 
     62        else: 
     63            method = None 
    6264 
    63         if self.qualifiers["SRS"]: 
    64             rms = sum(t.data**2) 
    65         elif self.qualifiers["SAM"]: 
    66             rms = np.sqrt(sum(t.data**2)) / len(t) 
    67         else: 
    68             rms = np.sqrt(np.mean(t.data**2)) 
     65        rms = self.rms(t, start, end, method) 
    6966 
    7067        if trgt: 
     
    7370            print "   rms: %e" % rms 
    7471 
     72    @staticmethod 
     73    def rms(trace, start, end, method): 
     74        """ 
     75        Compute RMS/SRS/SAM value of trace. 
     76        """ 
     77        try: 
     78            method = method.upper() 
     79        except: 
     80            pass 
     81 
     82        if start is not None: 
     83            _start = trace.stats.starttime + start 
     84            _end = trace.stats.starttime + end 
     85            t = trace.slice(_start, _end) 
     86        else: 
     87            t = trace 
     88 
     89        if method == "SRS": 
     90            rms = sum(t.data**2) 
     91        elif method == "SAM": 
     92            rms = np.sqrt(sum(t.data**2)) / len(t) 
     93        else: 
     94            rms = np.sqrt(np.mean(t.data**2)) 
     95 
     96        return rms 
     97 
    7598 
    7699if __name__ == "__main__": 
  • SHX/trunk/SeismicHandler/core/__init__.py

    r827 r829  
    88__all__ = [ 
    99    "Traces", "Hidden", "Stations", 
    10     "readfile", "readq", "reads", "reada", "summation", "writeq", "writea" 
     10    "reada", "readfile", "readq", "reads", "rms", "summation", "writeq", 
     11    "writea" 
    1112] 
    1213 
    1314from SeismicHandler.basics import codes 
    14 from SeismicHandler.modules.traces import Traces as sh_traces 
     15from SeismicHandler.modules.traces import Traces as sh_traces, traces_from_list 
    1516from SeismicHandler.modules.stations import Stations as sh_stations 
    16  
    1717from obspy.core import read as obspy_read 
    1818 
     
    219219    """ 
    220220    from SeismicHandler.commands.sum_ import _sum 
    221     from SeismicHandler.modules.traces import traces_from_list 
    222     import pdb; pdb.set_trace() 
    223221    if isinstance(tracelist, basestring): 
    224222        traces = traces_from_list(tracelist) 
     
    230228 
    231229 
     230def rms(trace, start=None, stop=None, method=None): 
     231    """ 
     232    Method for calculation the RMS (root mean square) value for trace. 
     233 
     234    This method accepts the following arguments: 
     235 
     236    trace:  accepts number if trace (count starts at one) or trace object 
     237    start:  window start (relative offset in seconds) 
     238    stop:   window end (dito) 
     239    method: defaults to None, which will return the RMS value. Other values are 
     240            "SRS" (square root sum) or "SAM" (squared arithmetic mean) 
     241    """ 
     242    from SeismicHandler.commands.rms import rms 
     243    if isinstance(trace, int): 
     244        trace = str(trace) 
     245    if isinstance(trace, basestring): 
     246        trace = traces_from_list(trace)[0] 
     247    return rms.rms(trace, start, stop, method) 
     248 
     249 
    232250if __name__ == "__main__": 
    233251    import doctest 
  • SHX/trunk/SeismicHandler/patches/obspy_.py

    r772 r829  
    440440Stream.__shx_init__, Stream.__init__ = Stream.__init__, stream_auto_merge_init 
    441441 
    442 # monkey patching obspy trace class: add shx container and method for fast 
    443 # plotting 
     442# monkey patching obspy trace class 
    444443Trace.__shx_init__, Trace.__init__ = Trace.__init__, trace_init 
     444# additional methods 
    445445Trace.prepare_image_data = trace_prepare_image_data 
    446  
    447 # helper methods 
    448446Trace.get_info = trace_get_info 
    449447Trace.set_info = trace_set_info 
Note: See TracChangeset for help on using the changeset viewer.