コード例 #1
0
    def _process_chopped(self, chopped, degap, maxgap, maxlap, want_incomplete,
                         wmax, wmin, tpad):
        chopped.sort(lambda a, b: cmp(a.full_id, b.full_id))
        if degap:
            chopped = degapper(chopped, maxgap=maxgap, maxlap=maxlap)

        if not want_incomplete:
            wlen = (wmax + tpad) - (wmin - tpad)
            chopped_weeded = []
            for tr in chopped:
                emin = tr.tmin - (wmin - tpad)
                emax = tr.tmax + tr.deltat - (wmax + tpad)
                if (abs(emin) <= 0.5 * tr.deltat
                        and abs(emax) <= 0.5 * tr.deltat):
                    chopped_weeded.append(tr)
                elif degap:
                    if (0. < emin <= 5. * tr.deltat
                            and -5. * tr.deltat <= emax < 0.):
                        tr.extend(wmin - tpad,
                                  wmax + tpad - tr.deltat,
                                  fillmethod='repeat')
                        chopped_weeded.append(tr)

            chopped = chopped_weeded

        for tr in chopped:
            tr.wmin = wmin
            tr.wmax = wmax

        return chopped
コード例 #2
0
ファイル: pile.py プロジェクト: trokia/pyrocko
    def _process_chopped(self, chopped, degap, want_incomplete, wmax, wmin, tpad):
        chopped.sort(lambda a, b: cmp(a.full_id, b.full_id))
        if degap:
            chopped = degapper(chopped)

        if not want_incomplete:
            wlen = (wmax + tpad) - (wmin - tpad)
            chopped_weeded = []
            for tr in chopped:
                emin = tr.tmin - (wmin - tpad)
                emax = tr.tmax + tr.deltat - (wmax + tpad)
                if abs(emin) <= 0.5 * tr.deltat and abs(emax) <= 0.5 * tr.deltat:
                    chopped_weeded.append(tr)
                elif degap:
                    if 0.0 < emin <= 5.0 * tr.deltat and -5.0 * tr.deltat <= emax < 0.0:
                        tr.extend(wmin - tpad, wmax + tpad - tr.deltat, fillmethod="repeat")
                        chopped_weeded.append(tr)

            chopped = chopped_weeded

        for tr in chopped:
            tr.wmin = wmin
            tr.wmax = wmax

        return chopped
コード例 #3
0
ファイル: eventdata.py プロジェクト: carinaj/pyrocko
    def iter_displacement_traces( self, tfade, freqband, 
                                  deltat=None,
                                  rotations=None,
                                  projections=None,
                                  relative_event=None,
                                  maxdisplacement=None,
                                  extend=None,
                                  group_selector=None,
                                  trace_selector=None,
                                  allowed_methods=None,
                                  crop=True,
                                  out_stations=None,
                                  redundant_channel_priorities=None,
                                  restitution_off_hack=False,
                                  preprocess=None,
                                  progress='Processing traces'):
        
        stations = self.get_stations(relative_event=relative_event)
        if out_stations is not None:
            out_stations.clear()
        else:
            out_stations = {}

        for xtraces in self.get_pile().chopper_grouped(
                gather=lambda tr: (tr.network, tr.station, tr.location),
                group_selector=group_selector,
                trace_selector=trace_selector,
                progress=progress):
            
            xxtraces = []
            nslcs = set()
            for tr in xtraces:
                nsl = tr.network, tr.station, tr.location
                if nsl not in stations:
                    logger.warn('No station description for trace %s.%s.%s.%s' % tr.nslc_id) 
                    continue
                
                nslcs.add(tr.nslc_id)
                xxtraces.append(tr)
            
            to_delete = self._redundant_channel_weeder(redundant_channel_priorities, nslcs)
            traces = []
            for tr in xxtraces:
                if tr.nslc_id in to_delete:
                    logger.info('Skipping channel %s.%s.%s.%s due to redunancies.' % tr.nslc_id)
                    continue
                traces.append(tr)
                               
            traces.sort( lambda a,b: cmp(a.full_id, b.full_id) )
            
            traces = trace.degapper(traces)  # mainly to get rid if overlaps and duplicates
            if traces:
                nsl = traces[0].nslc_id[:3]
                station = stations[nsl] # all traces belong to the same station here
                
                displacements = []
                for tr in traces:
                   
                    if preprocess is not None:
                        preprocess(tr)

                    tr.ydata = tr.ydata - num.mean(tr.ydata)
                    
                    if deltat is not None:
                        try:
                            tr.downsample_to(deltat, snap=True, allow_upsample_max=5)
                        except util.UnavailableDecimation, e:
                            self.problems().add('cannot_downsample', tr.full_id)
                            logger.warn( 'Cannot downsample %s.%s.%s.%s: %s' % (tr.nslc_id + (e,)))
                            continue
                        
                    try:
                        trans = self.get_restitution(tr, allowed_methods)
                    except NoRestitution, e:
                        self.problems().add('no_response', tr.full_id)
                        logger.warn( 'Cannot restitute trace %s.%s.%s.%s: %s' % (tr.nslc_id + (e,)))
                        continue
                    
                    try:
                        if extend:
                            tr.extend(tr.tmin+extend[0], tr.tmax+extend[1], fillmethod='repeat')
                        if restitution_off_hack:
                            displacement = tr.copy()
                        else:
                            displacement = tr.transfer( tfade, freqband, transfer_function=trans, cut_off_fading=crop )
                        
                        amax = num.max(num.abs(displacement.get_ydata()))
                        if maxdisplacement is not None and amax > maxdisplacement:
                            self.problems().add('unrealistic_amplitude', tr.full_id)
                            logger.warn( 'Trace %s.%s.%s.%s has too large displacement: %g' % (tr.nslc_id + (amax,)) )
                            continue
                        
                        if not num.all(num.isfinite(displacement.get_ydata())):
                            self.problems().add('has_nan_or_inf', tr.full_id)
                            logger.warn( 'Trace %s.%s.%s.%s has NaNs or Infs' % tr.nslc_id )
                            continue
                            
                    except trace.TraceTooShort, e:
                        self.problems().add('gappy', tr.full_id)
                        logger.warn( '%s' % e )
                        continue
                    
                    displacements.append(displacement)
                    if nsl not in out_stations:
                        out_stations[nsl] = copy.deepcopy(station)
                        out_station = out_stations[nsl]
コード例 #4
0
ファイル: eventdata.py プロジェクト: carinaj/pyrocko
    def iter_displacement_traces(self,
                                 tfade,
                                 freqband,
                                 deltat=None,
                                 rotations=None,
                                 projections=None,
                                 relative_event=None,
                                 maxdisplacement=None,
                                 extend=None,
                                 group_selector=None,
                                 trace_selector=None,
                                 allowed_methods=None,
                                 crop=True,
                                 out_stations=None,
                                 redundant_channel_priorities=None,
                                 restitution_off_hack=False,
                                 preprocess=None,
                                 progress='Processing traces'):

        stations = self.get_stations(relative_event=relative_event)
        if out_stations is not None:
            out_stations.clear()
        else:
            out_stations = {}

        for xtraces in self.get_pile().chopper_grouped(
                gather=lambda tr: (tr.network, tr.station, tr.location),
                group_selector=group_selector,
                trace_selector=trace_selector,
                progress=progress):

            xxtraces = []
            nslcs = set()
            for tr in xtraces:
                nsl = tr.network, tr.station, tr.location
                if nsl not in stations:
                    logger.warn(
                        'No station description for trace %s.%s.%s.%s' %
                        tr.nslc_id)
                    continue

                nslcs.add(tr.nslc_id)
                xxtraces.append(tr)

            to_delete = self._redundant_channel_weeder(
                redundant_channel_priorities, nslcs)
            traces = []
            for tr in xxtraces:
                if tr.nslc_id in to_delete:
                    logger.info(
                        'Skipping channel %s.%s.%s.%s due to redunancies.' %
                        tr.nslc_id)
                    continue
                traces.append(tr)

            traces.sort(lambda a, b: cmp(a.full_id, b.full_id))

            traces = trace.degapper(
                traces)  # mainly to get rid if overlaps and duplicates
            if traces:
                nsl = traces[0].nslc_id[:3]
                station = stations[
                    nsl]  # all traces belong to the same station here

                displacements = []
                for tr in traces:

                    if preprocess is not None:
                        preprocess(tr)

                    tr.ydata = tr.ydata - num.mean(tr.ydata)

                    if deltat is not None:
                        try:
                            tr.downsample_to(deltat,
                                             snap=True,
                                             allow_upsample_max=5)
                        except util.UnavailableDecimation, e:
                            self.problems().add('cannot_downsample',
                                                tr.full_id)
                            logger.warn('Cannot downsample %s.%s.%s.%s: %s' %
                                        (tr.nslc_id + (e, )))
                            continue

                    try:
                        trans = self.get_restitution(tr, allowed_methods)
                    except NoRestitution, e:
                        self.problems().add('no_response', tr.full_id)
                        logger.warn('Cannot restitute trace %s.%s.%s.%s: %s' %
                                    (tr.nslc_id + (e, )))
                        continue

                    try:
                        if extend:
                            tr.extend(tr.tmin + extend[0],
                                      tr.tmax + extend[1],
                                      fillmethod='repeat')
                        if restitution_off_hack:
                            displacement = tr.copy()
                        else:
                            displacement = tr.transfer(tfade,
                                                       freqband,
                                                       transfer_function=trans,
                                                       cut_off_fading=crop)

                        amax = num.max(num.abs(displacement.get_ydata()))
                        if maxdisplacement is not None and amax > maxdisplacement:
                            self.problems().add('unrealistic_amplitude',
                                                tr.full_id)
                            logger.warn(
                                'Trace %s.%s.%s.%s has too large displacement: %g'
                                % (tr.nslc_id + (amax, )))
                            continue

                        if not num.all(num.isfinite(displacement.get_ydata())):
                            self.problems().add('has_nan_or_inf', tr.full_id)
                            logger.warn('Trace %s.%s.%s.%s has NaNs or Infs' %
                                        tr.nslc_id)
                            continue

                    except trace.TraceTooShort, e:
                        self.problems().add('gappy', tr.full_id)
                        logger.warn('%s' % e)
                        continue

                    displacements.append(displacement)
                    if nsl not in out_stations:
                        out_stations[nsl] = copy.deepcopy(station)
                        out_station = out_stations[nsl]