Exemple #1
0
    def chopper_grouped(self, gather, progress=None, *args, **kwargs):
        keys = self.gather_keys(gather)
        if len(keys) == 0: return
        outer_group_selector = None
        if 'group_selector' in kwargs:
            outer_group_selector = kwargs['group_selector']

        outer_trace_selector = None
        if 'trace_selector' in kwargs:
            outer_trace_selector = kwargs['trace_selector']

        # the use of this gather-cache makes it impossible to modify the pile
        # during chopping
        gather_cache = {}
        pbar = None
        progressbar = util.progressbar_module()
        if progress and progressbar and config.show_progress:
            widgets = [
                progress,
                ' ',
                progressbar.Bar(marker='-', left='[', right=']'),
                ' ',
                progressbar.Percentage(),
                ' ',
            ]

            pbar = progressbar.ProgressBar(widgets=widgets,
                                           maxval=len(keys)).start()

        for ikey, key in enumerate(keys):

            def tsel(tr):
                return gather(tr) == key and (outer_trace_selector is None
                                              or outer_trace_selector(tr))

            def gsel(gr):
                if gr not in gather_cache:
                    gather_cache[gr] = gr.gather_keys(gather)

                return key in gather_cache[gr] and (
                    outer_group_selector is None or outer_group_selector(gr))

            kwargs['trace_selector'] = tsel
            kwargs['group_selector'] = gsel

            for traces in self.chopper(*args, **kwargs):
                yield traces

            if pbar: pbar.update(ikey + 1)

        if pbar: pbar.finish()
Exemple #2
0
 def chopper_grouped(self, gather, progress=None, *args, **kwargs):
     keys = self.gather_keys(gather)
     if len(keys) == 0: return
     outer_group_selector = None
     if 'group_selector' in kwargs:
         outer_group_selector = kwargs['group_selector']
         
     outer_trace_selector = None
     if 'trace_selector' in kwargs:
         outer_trace_selector = kwargs['trace_selector']
     
     # the use of this gather-cache makes it impossible to modify the pile
     # during chopping
     gather_cache = {}
     pbar = None
     progressbar = util.progressbar_module()
     if progress and progressbar and config.show_progress:
         widgets = [progress, ' ',
                     progressbar.Bar(marker='-',left='[',right=']'), ' ',
                     progressbar.Percentage(), ' ',]
             
         pbar = progressbar.ProgressBar(widgets=widgets, maxval=len(keys)).start()
     
     for ikey, key in enumerate(keys):
         def tsel(tr):
             return gather(tr) == key and (outer_trace_selector is None or 
                                           outer_trace_selector(tr))
                 
         def gsel(gr):
             if gr not in gather_cache:
                 gather_cache[gr] = gr.gather_keys(gather)
                     
             return key in gather_cache[gr] and (outer_group_selector is None or
                                                 outer_group_selector(gr))
         
         kwargs['trace_selector'] = tsel
         kwargs['group_selector'] = gsel
         
         for traces in self.chopper(*args, **kwargs):
             yield traces
             
         if pbar: pbar.update(ikey+1)
     
     if pbar: pbar.finish()
Exemple #3
0
'''A pile contains subpiles which contain tracesfiles which contain traces.'''

import trace, io, util, config

import numpy as num
import os, pickle, logging, time, weakref, copy, re, sys
import cPickle as pickle
pjoin = os.path.join
logger = logging.getLogger('pyrocko.pile')

from util import reuse
from trace import degapper

progressbar = util.progressbar_module()


class TracesFileCache(object):
    '''Manages trace metainformation cache.
    
    For each directory with files containing traces, one cache file is 
    maintained to hold the trace metainformation of all files which are 
    contained in the directory.
    '''

    caches = {}

    def __init__(self, cachedir):
        '''Create new cache.
        
        :param cachedir: directory to hold the cache files.
          
Exemple #4
0
'''A pile contains subpiles which contain tracesfiles which contain traces.'''

import trace, io, util, config

import numpy as num
import os, pickle, logging, time, weakref, copy, re, sys
import cPickle as pickle
pjoin = os.path.join
logger = logging.getLogger('pyrocko.pile')

from util import reuse
from trace import degapper


progressbar = util.progressbar_module()

class TracesFileCache(object):
    '''Manages trace metainformation cache.
    
    For each directory with files containing traces, one cache file is 
    maintained to hold the trace metainformation of all files which are 
    contained in the directory.
    '''

    caches = {}

    def __init__(self, cachedir):
        '''Create new cache.
        
        :param cachedir: directory to hold the cache files.