Ejemplo n.º 1
0
    def testGlobalCMT(self):
        def is_the_haiti_event(ev):
            assert near(ev.magnitude, 7.0, 0.1)
            assert near(ev.lat, 18.61, 0.01)
            assert near(ev.lon, -72.62, 0.01)
            assert near(ev.depth, 12000., 1.)
            assert ev.region.lower() == 'haiti region'

        cat = catalog.GlobalCMT()

        tmin = util.str_to_time('2010-01-12 21:50:00')
        tmax = util.str_to_time('2010-01-13 03:17:00')

        names = cat.get_event_names(time_range=(tmin, tmax), magmin=5.)
        ident = None
        for name in names:
            ev = cat.get_event(name)
            if ev.magnitude > 7:
                is_the_haiti_event(ev)
                ident = ev.name

        assert ident is not None
        cat.flush()
        ev = cat.get_event(ident)
        is_the_haiti_event(ev)
Ejemplo n.º 2
0
def command_init(args):
    '''
    Execution of command init
    '''
    def setup(parser):

        parser.add_option('--force',
                          dest='force',
                          action='store_true',
                          help='overwrite existing project directory')

    parser, options, args = cl_parse('init', args, setup)

    if len(args) != 1:
        help_and_die(parser, 'missing argument')
    else:
        fn_config = args[0]

    if not os.path.isfile(fn_config):
        die('config file missing: %s' % fn_config)

    conf = load(filename=fn_config)
    config.check(conf)

    if ((not options.force) and (os.path.isdir(conf.project_dir))):
        die('project dir exists: %s; use force option' % conf.project_dir)
    else:
        if os.path.isdir(conf.project_dir):
            shutil.rmtree(conf.project_dir)
        os.mkdir(conf.project_dir)
        conf.dump(filename=os.path.join(conf.project_dir, 'seiscloud.config'))

        dst = os.path.join(conf.project_dir, 'catalog.pf')

        if conf.catalog_origin == 'file':
            src = conf.catalog_fn
            shutil.copyfile(src, dst)
        else:
            if conf.catalog_origin == 'globalcmt':
                orig_catalog = catalog.GlobalCMT()
            else:  # geofon
                orig_catalog = catalog.Geofon()
            events = orig_catalog.get_events(time_range=(util.str_to_time(
                conf.tmin), util.str_to_time(conf.tmax)),
                                             magmin=conf.magmin,
                                             latmin=conf.latmin,
                                             latmax=conf.latmax,
                                             lonmin=conf.lonmin,
                                             lonmax=conf.lonmax)

            selevents = [ev for ev in events if ev.magnitude <= conf.magmax]
            model.dump_events(selevents, dst)

        print('Project directory prepared "%s"' % conf.project_dir)
Ejemplo n.º 3
0
    def setup(self):

        self.catalogs = {
            'Geofon': catalog.Geofon(),
            'USGS/NEIC US': catalog.USGS('us'),
            'Global-CMT': catalog.GlobalCMT(),
            'Kinherd': catalog.Kinherd(),
            'Saxony (Uni-Leipzig)': catalog.Saxony(),
        }

        catkeys = sorted(self.catalogs.keys())
        self.set_name('Catalog Search')
        self.add_parameter(Choice('Catalog', 'catalog', catkeys[0], catkeys))
        self.add_parameter(Param('Min Magnitude', 'magmin', 0, 0, 10))
        self.set_live_update(False)
Ejemplo n.º 4
0
    def setup(self):

        self.catalogs = {
            'Geofon': catalog.Geofon(),
            'USGS/NEIC US': catalog.USGS('us'),
            'Global-CMT': catalog.GlobalCMT(),
            'Saxony (Uni-Leipzig)': catalog.Saxony(),
        }

        fdsn_has_events = ['ISC', 'SCEDC', 'NCEDC', 'IRIS', 'GEONET']

        catkeys = sorted(self.catalogs.keys())
        catkeys.extend(fdsn_has_events)

        self.set_name('Catalog Search')
        self.add_parameter(Choice('Catalog', 'catalog', catkeys[0], catkeys))
        self.add_parameter(Param('Min Magnitude', 'magmin', 0, 0, 10))
        self.set_live_update(False)
from pyrocko import util, model
from pyrocko.client import catalog

tmin = util.str_to_time('2011-01-01 00:00:00')  # beginning time of query
tmax = util.str_to_time('2011-12-31 23:59:59')

# create an instance of the global CMT catalog
global_cmt_catalog = catalog.GlobalCMT()

# query the catalog
events = global_cmt_catalog.get_events(time_range=(tmin, tmax),
                                       magmin=2.,
                                       latmin=-35.,
                                       latmax=-20.,
                                       lonmin=-76.,
                                       lonmax=-65.)

print('Downloaded %s events' % len(events))
print('The last one is:')
print(events[-1])

# dump events to catalog
model.dump_events(events, 'northern_chile_events.txt')
Ejemplo n.º 6
0
def seismic_noise_variance(traces, engine, source, targets, nwindows,
                           pre_event_noise_duration, check_events, phase_def):
    """
    Calculate variance of noise in a given time before P-Phase onset.

    Optionally check the gCMT earthquake catalogue for M>5 events interfering.

    Parameters
    ----------
    data_traces : list
        of :class:`pyrocko.trace.Trace` containing observed data
    engine : :class:`pyrocko.gf.seismosizer.LocalEngine`
        processing object for synthetics calculation
    source : :class:`pyrocko.gf.Source`
        reference source
    targets : list
        of :class:`pyrocko.gf.seismosizer.Targets`
    nwindows : integer
        number of windows in which the noise trace is split. If not 1, the
        variance is calculated for each window separately and a mean
        variance is returned. Else, the variance is calculated on the
        entire pre-event noise window.
    pre_event_noise_duration : Time before the first arrival to include in the
        noise analysis
    phase_def : :class:'pyrocko.gf.Timing'
    arrivals : list
        of :class'pyrocko.gf.Timing' arrivals of waveforms
        at station

    Returns
    -------
    :class:`numpy.ndarray`
    """

    var_ds = []
    global_cmt_catalog = catalog.GlobalCMT()
    var_ds = []
    ev_ws = []
    for tr, target in zip(traces, targets):
        stat_w = 1.

        if tr is None:
            var_ds.append(num.nan)
            ev_ws.append(num.nan)
        else:

            arrival_time = get_phase_arrival_time(engine=engine,
                                                  source=source,
                                                  target=target,
                                                  wavename=phase_def)
            if check_events:
                events = global_cmt_catalog.get_events(
                    time_range=(arrival_time - pre_event_noise_duration -
                                50. * 60., arrival_time),
                    magmin=5.,
                )
                for ev in events:
                    try:
                        arrival_time_pre = get_phase_arrival_time(
                            engine=engine,
                            source=ev,
                            target=target,
                            wavename=phase_def)

                        if arrival_time_pre > arrival_time \
                                - pre_event_noise_duration \
                                and arrival_time_pre < arrival_time:

                            stat_w = 0.
                            logger.info(
                                'Noise analyser found event "%s" phase onset '
                                'of "%s" for target "%s".' %
                                (ev.name, phase_def, target.name))

                        if arrival_time_pre > arrival_time-30.*60.\
                                and arrival_time_pre < arrival_time - \
                                pre_event_noise_duration:
                            stat_w *= 1.
                            logger.info(
                                'Noise analyser found event "%s" possibly '
                                'contaminating the noise.' % ev.name)

                            # this should be magnitude dependent
                    except Exception:
                        pass
            ev_ws.append(stat_w)

            if nwindows == 1:
                vtrace_var = num.nanvar(tr.ydata)
                var_ds.append(vtrace_var)
            else:
                win = arrival_time - (arrival_time - pre_event_noise_duration)
                win_len = win / nwindows
                v_traces_w = []
                for i in range(0, nwindows):
                    vtrace_w = tr.chop(tmin=win + win_len * i,
                                       tmax=arrival_time + win_len * i + 1,
                                       inplace=False)
                    v_traces_w.append(vtrace_w.ydata)
                v_traces_w = num.nanmean(v_traces_w)
                var_ds.append(v_traces_w)
    var_ds = num.array(var_ds, dtype=num.float)
    ev_ws = num.array(ev_ws, dtype=num.float)
    return var_ds, ev_ws
Ejemplo n.º 7
0
def main():
    if len(sys.argv) < 2:
        print(
            "input: asc_path dsc_path minlat minlon maxlat maxlon --workdir=name m"
        )
    try:
        x0 = float(sys.argv[3])
        y0 = float(sys.argv[4])
        x1 = float(sys.argv[5])
        y1 = float(sys.argv[6])
    except:
        x0 = "eins"
        y0 = "eins"
        x1 = "eins"
        y1 = "eins"

    sharp = False
    loading = False
    plot = True
    topo = False
    synthetic = False
    calc_statistics = False
    subsample = False
    dump_grid = False

    for argv in sys.argv:
        if argv == "--sharp":
            sharp = True
        if argv == "--basic":
            sharp = "basic"
        if argv == "--ss":
            sharp = "ss"
        if argv == "--loading=True":
            loading = True
        if argv == "--loading=true":
            loading = True
        if argv == "--plot=False":
            plot = False
        if argv[0:10] == "--workdir=":
            name = argv[10:]
        if argv == "--topography":
            topo = True
        if argv == "--synthetic":
            synthetic = True
        if argv == "--statistics":
            calc_statistics = True
        if argv == "--subsample":
            subsample = True
        if argv == "--grond_export":
            dump_grid = True

    strikes = []
    lengths = []
    widths = []

    if loading is False:

        img_asc, coh_asc, scene_asc, dates_asc = load(sys.argv[1],
                                                      kite_scene=True)

        try:
            os.mkdir('work-%s' % name)
        except:
            pass
        files = glob.glob('work-%s/*' % name)
        for f in files:
            os.remove(f)
        fname = 'work-%s/asc.mod.tif' % name
        writeout(img_asc, fname, sc=scene_asc)
        longs_asc, lats_asc = to_latlon(fname)

        try:
            global_cmt_catalog = catalog.GlobalCMT()

            events = global_cmt_catalog.get_events(
                time_range=(num.min(dates_asc), num.max(dates_asc)),
                magmin=2.,
                latmin=num.min(lats_asc),
                latmax=num.max(lats_asc),
                lonmin=num.min(longs_asc),
                lonmax=num.max(longs_asc))

            areas = []

            for ev in events:
                areas.append(num.cbrt(ev.moment_tensor.moment) / 1000)
            area = num.max(areas)
        except:
            area = 400

        fname = 'work-%s/asc-' % name

        img_asc = process(img_asc,
                          coh_asc,
                          longs_asc,
                          lats_asc,
                          scene_asc,
                          x0,
                          y0,
                          x1,
                          y1,
                          fname,
                          plot=plot,
                          mode=sharp,
                          loading=loading,
                          topo=topo,
                          synthetic=synthetic,
                          calc_statistics=calc_statistics,
                          subsample=subsample)
        fname = 'work-%s/asc.mod.tif' % name
        writeout(img_asc, fname, sc=scene_asc)
        db = 1
        dates = []
        img_asc, coh_asc, scene_asc, dates_asc = load(sys.argv[1],
                                                      kite_scene=True)
        dates.append(dates_asc)
        snr_asc = aoi_snr(img_asc, area)

        img_dsc, coh_dsc, scene_dsc, dates_dsc = load(sys.argv[2],
                                                      kite_scene=True)
        dates.append(dates_dsc)

        fname = 'work-%s/dsc.mod.tif' % name
        writeout(img_dsc, fname, sc=scene_dsc)
        longs_dsc, lats_dsc = to_latlon(fname)
        fname = 'work-%s/dsc-' % name
        img_dsc = process(img_dsc,
                          coh_dsc,
                          longs_dsc,
                          lats_dsc,
                          scene_dsc,
                          x0,
                          y0,
                          x1,
                          y1,
                          fname,
                          plot=plot,
                          mode=sharp,
                          loading=loading,
                          topo=topo,
                          synthetic=synthetic,
                          calc_statistics=calc_statistics,
                          subsample=subsample)
        fname = 'work-%s/dsc.mod.tif' % name
        writeout(img_dsc, fname, sc=scene_dsc)

        db = 1
        img_dsc, coh_dsc, scene_dsc, dates = load(sys.argv[2], kite_scene=True)
        snr_dsc = aoi_snr(img_dsc, area)

        minda = num.min(scene_asc.displacement)
        mindd = num.min(scene_dsc.displacement)
        mind = num.min([minda, mindd])
        maxa = num.max(scene_asc.displacement)
        maxdd = num.max(scene_dsc.displacement)
        maxd = num.max([maxa, maxdd])
        max_cum = num.max([abs(maxd), abs(mind)])
        minda = -max_cum
        mindd = -max_cum
        mind = -max_cum
        maxa = max_cum
        maxdd = max_cum
        maxd = max_cum

        if plot is True:
            fname = 'work-%s/asc' % name
            plot_on_map(db,
                        scene_asc,
                        longs_asc,
                        lats_asc,
                        x0,
                        y0,
                        x1,
                        y1,
                        minda,
                        maxa,
                        fname,
                        synthetic=synthetic,
                        topo=topo,
                        kite_scene=True)
            fname = 'work-%s/dsc' % name
            plot_on_map(db,
                        scene_dsc,
                        longs_dsc,
                        lats_dsc,
                        x0,
                        y0,
                        x1,
                        y1,
                        mindd,
                        maxdd,
                        fname,
                        synthetic=synthetic,
                        topo=topo,
                        kite_scene=True)

        fname = 'work-%s/asc.mod.tif' % name
        comb = rasterio.open(fname)
        longs_comb, lats_comb = to_latlon(fname)
        comb_img = comb.read(1)

        centers_bounding, coords_out, coords_box, strike, ellipses, max_bound = bounding_box(
            comb_img, 400, sharp)
        for st in strike:
            strikes.append(st)
        print("Strike(s) of moment weighted centerline(s) are :%s" % strike)

        if plot is True:
            fname = 'work-%s/asc-comb-' % name

            plot_on_kite_box(coords_box,
                             coords_out,
                             scene_asc,
                             longs_asc,
                             lats_asc,
                             longs_comb,
                             lats_comb,
                             x0,
                             y0,
                             x1,
                             y1,
                             name,
                             ellipses,
                             minda,
                             maxa,
                             fname,
                             synthetic=synthetic,
                             topo=topo)

        fname = 'work-%s/dsc.mod.tif' % name
        comb = rasterio.open(fname)
        longs_comb, lats_comb = to_latlon(fname)
        comb_img = comb.read(1)

        centers_bounding, coords_out, coords_box, strike, ellipses, max_bound = bounding_box(
            comb_img, 400, sharp)

        for st in strike:
            strikes.append(st)
        print("Strike(s) of moment weighted centerline(s) are :%s" % strike)

        if plot is True:
            fname = 'work-%s/dsc-comb-' % name

            plot_on_kite_box(coords_box,
                             coords_out,
                             scene_dsc,
                             longs_dsc,
                             lats_dsc,
                             longs_comb,
                             lats_comb,
                             x0,
                             y0,
                             x1,
                             y1,
                             name,
                             ellipses,
                             mindd,
                             maxdd,
                             fname,
                             synthetic=synthetic,
                             topo=topo)

        comb_img = combine('work-%s/asc.mod.tif' % name,
                           'work-%s/dsc.mod.tif' % name,
                           name,
                           weight_asc=snr_asc,
                           weight_dsc=snr_dsc,
                           plot=False)
        longs_comb, lats_comb = to_latlon("work-%s/merged.tiff" % name)

    else:
        fname = 'work-%s/merged.tiff' % name
        comb = rasterio.open(fname)
        longs, lats = to_latlon(fname)
        comb_img = comb.read(1)
        easts, norths = get_coords_from_geotiff(fname, comb_img)
        dE = easts[1] - easts[0]
        dN = norths[1] - norths[0]
        ll_long = num.min(longs)
        ll_lat = num.min(lats)
        dates = []
        img_asc, coh_asc, scene_asc, dates_asc = load(sys.argv[1],
                                                      kite_scene=True)
        img_dsc, coh_dsc, scene_dsc, dates_dsc = load(sys.argv[2],
                                                      kite_scene=True)

        minda = num.min(scene_asc.displacement)
        mindd = num.min(scene_dsc.displacement)
        mind = num.min([minda, mindd])
        maxa = num.max(scene_asc.displacement)
        maxdd = num.max(scene_dsc.displacement)
        maxd = num.max([maxa, maxdd])

        if plot is True:
            plt.figure(figsize=(sz1, sz2))
            plt.title('Loaded combined image')
            xr = plt.imshow(comb_img)
            plt.close()

        if subsample is True:
            # Define the scene's frame
            frame = FrameConfig(
                # Lower left geographical reference [deg]
                llLat=ll_lat,
                llLon=ll_long,
                # Pixel spacing [m] or [degrees]
                spacing='meter',
                dE=dE,
                dN=dN)

            displacement = comb_img
            # Look vectors
            # Theta is elevation angle from horizon
            theta = num.full_like(displacement, 48. * d2r)
            # Phi is azimuth towards the satellite, counter-clockwise from East
            phi = num.full_like(displacement, 23. * d2r)

            kite_comb_scene = Scene(displacement=displacement,
                                    phi=phi,
                                    theta=theta,
                                    frame=frame)
            kite_comb_scene.spool()

            # For convenience we set an abbreviation to the quadtree
            qt = kite_comb_scene.quadtree

            # Parametrisation of the quadtree
            qt.epsilon = 0.024  # Variance threshold
            qt.nan_allowed = 0.9  # Percentage of NaN values allowed per tile/leave

            qt.tile_size_max = 12000  # Maximum leave edge length in [m] or [deg]
            qt.tile_size_min = 250  # Minimum leave edge length in [m] or [deg]

            # We save the scene in kite's format
            # sc.save('kite_scene')

            # Or export the quadtree to CSV file
            # qt.export('/tmp/tree.csv')

    # statistical output
    # img_asc, coh_asc, scene_asc = load('muji_kite/asc', kite_scene=True)
    # comb_img = process(img_asc, coh_asc, plot=True)
    # use quadtree subsampling on gradient

    img_asc, coh_asc, scene_asc, dates = load(sys.argv[1], kite_scene=True)
    fname = 'work-%s/asc.mod.tif' % name
    longs_asc, lats_asc = to_latlon(fname)
    db = 1
    longs_comb, lats_comb = to_latlon("work-%s/merged.tiff" % name)
    mindc = num.min(comb_img)
    maxdc = num.max(comb_img)

    try:
        global_cmt_catalog = catalog.GlobalCMT()

        events = global_cmt_catalog.get_events(time_range=(num.min(dates),
                                                           num.max(dates)),
                                               magmin=2.,
                                               latmin=num.min(lats_comb),
                                               latmax=num.max(lats_comb),
                                               lonmin=num.min(longs_comb),
                                               lonmax=num.max(longs_comb))

        areas = []

        for ev in events:
            areas.append(num.cbrt(ev.moment_tensor.moment) / 1000)
        area = num.max(areas)
    except:
        area = 400

    if dump_grid is True:
        from scipy import signal
        es = longs_comb.flatten()
        es_resamp = signal.decimate(es, 20)

        ns = lats_comb.flatten()
        ns_resamp = signal.decimate(ns, 20)

        comb_img_grid = comb_img.flatten()
        comb_img_grid_resamp = signal.decimate(comb_img_grid, 20)
        fobj_cum = open(os.path.join('work-%s/grad_grid.ASC' % name), 'w')
        for x, y, sembcums in zip(es, ns, comb_img_grid.flatten()):
            fobj_cum.write('%.2f %.2f %.20f\n' % (x, y, sembcums))
        fobj_cum.close()

        fobj_cum = open(os.path.join('work-%s/grad_grid_resam.ASC' % name),
                        'w')
        for x, y, sembcums in zip(es_resamp, ns_resamp, comb_img_grid_resamp):
            fobj_cum.write('%.2f %.2f %.20f\n' % (x, y, sembcums))
        fobj_cum.close()

    if plot is True:
        fname = 'work-%s/comb-' % name

        plot_on_map(db,
                    comb_img.copy(),
                    longs_comb,
                    lats_comb,
                    x0,
                    y0,
                    x1,
                    y1,
                    mindc,
                    maxdc,
                    fname,
                    synthetic=synthetic,
                    topo=topo,
                    comb=True)

    centers_bounding, coords_out, coords_box, strike, ellipses, max_bound = bounding_box(
        comb_img, area, sharp)
    for st in strike:
        strikes.append(st)
    print("Strike(s) of moment weighted centerline(s) are :%s" % strike)

    if plot is True:
        fname = 'work-%s/comb-' % name

        lengths, widths = plot_on_kite_box(coords_box,
                                           coords_out,
                                           scene_asc,
                                           longs_asc,
                                           lats_asc,
                                           longs_comb,
                                           lats_comb,
                                           x0,
                                           y0,
                                           x1,
                                           y1,
                                           name,
                                           ellipses,
                                           mind,
                                           maxd,
                                           fname,
                                           synthetic=synthetic,
                                           topo=topo)

        fobj_cum = open(os.path.join('work-%s/priors.ASC' % name), 'w')
        for lens, wid in zip(lengths, widths):
            fobj_cum.write('%.2f %.2f\n' % (lens, wid))
        fobj_cum.close()

        fobj_cum = open(os.path.join('work-%s/priors_strike.ASC' % name), 'w')
        for st in zip(strikes):
            fobj_cum.write('%.2f\n' % (st))
        fobj_cum.close()

        plot_on_kite_line(coords_out,
                          scene_asc,
                          longs_asc,
                          lats_asc,
                          longs_comb,
                          lats_comb,
                          x0,
                          y0,
                          x1,
                          y1,
                          mind,
                          maxd,
                          fname,
                          synthetic=synthetic,
                          topo=topo)

    simp_fault, comp_fault = simplify(centers_bounding)

    db = dump_geojson(simp_fault, longs_comb, lats_comb, name)
    if plot is True:
        plot_on_kite_scatter(
            db,
            scene_asc,
            longs_asc,
            lats_asc,
            x0,
            y0,
            x1,
            y1,
            mind,
            maxd,
            fname,
            synthetic=synthetic,
            topo=topo,
        )

    img_dsc, coh_dsc, scene_dsc, dates = load(sys.argv[2], kite_scene=True)
    fname = 'work-%s/dsc.mod.tif' % name
    longs_dsc, lats_dsc = to_latlon(fname)

    fname = 'work-%s/comb-' % name
    if plot is True:
        plot_on_kite_scatter(
            db,
            scene_dsc,
            longs_dsc,
            lats_dsc,
            x0,
            y0,
            x1,
            y1,
            mind,
            maxd,
            fname,
            synthetic=synthetic,
            topo=topo,
        )

    centers = skelotonize(comb_img)
    simp_fault, comp_fault = simplify(centers)

    if calc_statistics is True:
        res_faults = rup_prop(db)
        y = l1tf_prep(res_faults)
        run_l1tf(y)
Ejemplo n.º 8
0
def seismic_noise_variance(traces, engine, event, stations, nwindows,
                           pre_event_noise_duration, check_events, phase_def,
                           store_id):
    '''
    Calculate variance of noise (half an hour) before P-Phase onset, and check
    for other events interfering

    Parameters
    ----------
    data_traces : list
        of :class:`pyrocko.trace.Trace` containing observed data
    engine : :class:`pyrocko.gf.seismosizer.LocalEngine`
        processing object for synthetics calculation
    event : :class:`pyrocko.meta.Event`
        reference event from catalog
    targets : list
        of :class:`pyrocko.gf.seismosizer.Targets`
    nwindows : integer
        if given, windowed analysis of noise, else
        variance is calculated on the entire pre-event
        noise
    phase_def : :class:'pyrocko.gf.Timing'

    Returns
    -------
    :class:`numpy.ndarray`
    '''

    var_ds = []
    global_cmt_catalog = catalog.GlobalCMT()
    var_ds = []
    ev_ws = []
    for tr, station in zip(traces, stations):
        stat_w = 1.
        if tr is None:
            var_ds.append(0.)
            ev_ws.append(0.)
        else:

            arrival_time = get_phase_arrival_time(engine=engine,
                                                  source=event,
                                                  station=station,
                                                  wavename=phase_def,
                                                  store_id=store_id)
            if check_events:
                events = global_cmt_catalog.get_events(
                    time_range=(arrival_time - pre_event_noise_duration -
                                50. * 60., arrival_time),
                    magmin=4.)
                ev_sum = 0.
                for ev in events:
                    ev_sum += ev.magnitude
                for ev in events:
                    try:
                        arrival_time_pre = get_phase_arrival_time(
                            engine=engine,
                            source=ev,
                            station=station,
                            wavename=phase_def,
                            store_id=store_id)
                        if arrival_time_pre > arrival_time \
                                - pre_event_noise_duration \
                                and arrival_time_pre < arrival_time:

                            stat_w = 0.
                            logger.info(
                                'Noise analyser found event %s phase onset of '
                                '%s for %s' % (ev.name, phase_def, station))

                        if arrival_time_pre > arrival_time-30.*60.\
                                and arrival_time_pre < arrival_time - \
                                pre_event_noise_duration:
                            stat_w *= 0.5 * (ev.magnitude / ev.sum)
                            logger.info(
                                'Noise analyser found event %s possibly '
                                'contaminating the noise' % ev.name)
                            # 0.5 arbitrary
                    except Exception:
                        pass
            ev_ws.append(stat_w)

            if nwindows == 1:
                vtrace_var = num.nanvar(tr.ydata)
                var_ds.append(vtrace_var)
            else:
                win = arrival_time - (arrival_time - pre_event_noise_duration)
                win_len = win / nwindows
                v_traces_w = []
                for i in range(0, nwindows):
                    vtrace_w = tr.chop(tmin=win + win_len * i,
                                       tmax=arrival_time + win_len * i + 1,
                                       inplace=False)
                    v_traces_w.append(vtrace_w.ydata)
                v_traces_w = num.nanmean(v_traces_w)
                var_ds.append(v_traces_w)
    var_ds = num.array(var_ds, dtype=num.float)
    ev_ws = num.array(ev_ws, dtype=num.float)
    return var_ds, ev_ws