Changeset 827 for SHX/trunk


Ignore:
Timestamp:
11/07/12 11:25:46 (8 years ago)
Author:
marcus
Message:
  • included [ShSum] into core methods
Location:
SHX/trunk/SeismicHandler
Files:
2 edited

Legend:

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

    r771 r827  
    4848        traces = traces_from_list(self.parameters[0]) 
    4949 
     50        # save count of traces, useful when using keyword "all" 
    5051        if len(self.parameters) == 4: 
    5152            self.symbols.set(self.parameters[3][1:], len(traces)) 
     
    5556            end = float(self.parameters[2]) 
    5657        except IndexError: 
    57             start, end = Screen.timewdw() 
     58            start = end = None 
    5859        except ValueError: 
    5960            # check for empty string 
    6061            if self.parameters[1] == '' and self.parameters[2] == '': 
    61                 start, end = Screen.timewdw() 
     62                start = end = None 
    6263            else: 
    6364                raise ShxError("float conversion error", status=1709) 
     65 
     66        norm = self.qualifiers["NONORM"] and 1. or len(traces) 
     67 
     68        sumtrace = self.summation(traces, start, end, norm) 
     69 
     70        result = "%d traces summed" % len(traces) 
     71        if Settings.swChatty: 
     72            print result 
     73        sumtrace.set_info("opinfo", result) 
     74 
     75        add_traces(sumtrace) 
     76 
     77    @staticmethod 
     78    def summation(traces, start, end, norm): 
     79        """ 
     80        Sum up traces. 
     81        """ 
     82        if start is None: 
     83            start, end = Screen.timewdw() 
    6484 
    6585        # check sample rates 
     
    97117                min_length = len(t.data) 
    98118 
    99         norm = self.qualifiers["NONORM"] and 1. or len(traces) 
    100  
    101119        # cut and weight data 
    102120        for i, d in enumerate(data): 
     
    115133            sumtrace.set_info("t-origin", start) 
    116134 
    117         result = "%d traces summed" % len(traces) 
    118         if Settings.swChatty: 
    119             print result 
    120         sumtrace.set_info("opinfo", result) 
    121  
    122135        # update station name 
    123136        sumtrace.stats.station = "SUM" 
    124137        sumtrace.stats.network = "" 
    125138        sumtrace.stats.location = "" 
    126         add_traces(sumtrace) 
     139 
     140        return sumtrace 
    127141 
    128142 
  • SHX/trunk/SeismicHandler/core/__init__.py

    r783 r827  
    88__all__ = [ 
    99    "Traces", "Hidden", "Stations", 
    10     "readfile", "readq", "reads", "reada", "writeq", "writea" 
     10    "readfile", "readq", "reads", "reada", "summation", "writeq", "writea" 
    1111] 
    1212 
     
    202202 
    203203 
     204def summation(tracelist, start=None, stop=None, norm=True): 
     205    """ 
     206    Method for summing up traces with respect to time offset, weight and recent 
     207    time window. 
     208 
     209    This method accepts the following arguments: 
     210 
     211    tracelist: accepts string input holding trace numbers (count start at one). 
     212               e.g. "1-3" or list of Trace objects 
     213    start:     window start (relative offset in seconds) 
     214    stop:      window end (dito) 
     215    norm:      If set to True (default), the resulting trace is normed to 
     216               the number of input traces. 
     217 
     218    Return trace object containing summation trace. 
     219    """ 
     220    from SeismicHandler.commands.sum_ import _sum 
     221    from SeismicHandler.modules.traces import traces_from_list 
     222    import pdb; pdb.set_trace() 
     223    if isinstance(tracelist, basestring): 
     224        traces = traces_from_list(tracelist) 
     225    else: 
     226        traces = tracelist 
     227 
     228    norm = norm and len(traces) or 1. 
     229    return _sum.summation(traces, start, stop, norm) 
     230 
     231 
    204232if __name__ == "__main__": 
    205233    import doctest 
Note: See TracChangeset for help on using the changeset viewer.