示例#1
0
    def get_source(self, x):
        d = self.get_parameter_dict(x)
        p = {}
        for k in self.base_source.keys():
            if k in d:
                p[k] = float(
                    self.ranges[k].make_relative(self.base_source[k], d[k]))

        stf1 = gf.HalfSinusoidSTF(duration=float(d.duration1))
        stf2 = gf.HalfSinusoidSTF(duration=float(d.duration2))

        source = self.base_source.clone(stf1=stf1, stf2=stf2, **p)
        return source
示例#2
0
    def test_discretize_rect_source_stf(self):

        store = self.dummy_homogeneous_store()
        target = gf.Target(interpolation='nearest_neighbor')
        stf = gf.HalfSinusoidSTF(duration=3.)

        for source in [
                gf.RectangularSource(depth=10 * km,
                                     slip=0.5,
                                     width=5 * km,
                                     length=5 * km,
                                     stf=stf,
                                     stf_mode='pre'),
                gf.RectangularSource(depth=10 * km,
                                     magnitude=5.0,
                                     width=5 * km,
                                     length=5 * km,
                                     decimation_factor=2,
                                     stf=stf,
                                     stf_mode='pre')
        ]:

            dsource = source.discretize_basesource(store, target)
            amplitudes = source._discretize(store, target)[2]
            assert amplitudes[0] != amplitudes[1]

            m1 = source.get_moment(store, target)
            m2 = dsource.centroid().pyrocko_moment_tensor().scalar_moment()
            assert abs(m1 - m2) < abs(m1 + m2) * 1e-6
示例#3
0
    def test_effective_durations(self):
        deltat = 1e-4
        for stf in [
                gf.HalfSinusoidSTF(duration=2.0),
                gf.HalfSinusoidSTF(duration=2.0, exponent=2),
                gf.TriangularSTF(duration=2.0, peak_ratio=0.),
                gf.TriangularSTF(duration=2.0, peak_ratio=1.),
                gf.TriangularSTF(duration=2.0, peak_ratio=0.5),
                gf.BoxcarSTF(duration=2.0)
        ]:

            t, a = stf.discretize_t(deltat, 0.0)
            t0 = stf.centroid_time(0.0)

            edur = num.sqrt(num.sum((t - t0)**2 * a)) * 2. * num.sqrt(3.)
            assert abs(edur - stf.effective_duration) < 1e-3
示例#4
0
 def __init__(self):
     Snuffling.__init__(self)
     self.stf_types = ['half sin', 'triangular', 'boxcar', 'None']
     self.stf_instances = [
         gf.HalfSinusoidSTF(),
         gf.TriangularSTF(),
         gf.BoxcarSTF(), None
     ]
示例#5
0
    def get_source(self, x):
        d = self.get_parameter_dict(x)

        p = {
            k: float(self.ranges[k].make_relative(self.base_source[k], d[k]))
            for k in self.base_source.keys() if k in d
        }

        stf = None
        if self.has_waveforms:
            stf = gf.HalfSinusoidSTF(duration=float(d.duration))

        source = self.base_source.clone(stf=stf, **p)
        return source
示例#6
0
    def test_stf_half_sinusoid(self, plot=False):
        from matplotlib import pyplot as plt

        for duration in [0., 1., 2., 3.]:
            tref = 10.02
            stf = gf.HalfSinusoidSTF(duration=duration, anchor=0.)
            t, a = stf.discretize_t(deltat=0.1, tref=tref)
            assert numeq(stf.centroid_time(tref), tref, 1e-5)
            if plot:
                plt.plot(t, a)
                plt.plot(t, a, 'o')

        if plot:
            plt.show()
示例#7
0
    def get_source(self, x):
        d = self.get_parameter_dict(x)
        rm6 = num.array([d.rmnn, d.rmee, d.rmdd, d.rmne, d.rmnd, d.rmed],
                        dtype=num.float)

        m0 = mtm.magnitude_to_moment(d.magnitude)
        m6 = rm6 * m0

        p = {}
        for k in self.base_source.keys():
            if k in d:
                p[k] = float(self.ranges[k].make_relative(
                    self.base_source[k], d[k]))

        stf = gf.HalfSinusoidSTF(duration=float(d.duration))

        source = self.base_source.clone(m6=m6, stf=stf, **p)
        return source
示例#8
0
    def get_problem(self, event, target_groups, targets):
        if event.depth is None:
            event.depth = 0.

        base_source = gf.MTSource.from_pyrocko_event(event)
        base_source.stf = gf.HalfSinusoidSTF(duration=event.duration or 0.0)

        subs = dict(event_name=event.name,
                    event_time=util.time_to_str(event.time))

        problem = CMTProblem(name=expand_template(self.name_template, subs),
                             base_source=base_source,
                             target_groups=target_groups,
                             targets=targets,
                             ranges=self.ranges,
                             distance_min=self.distance_min,
                             mt_type=self.mt_type,
                             norm_exponent=self.norm_exponent)

        return problem
示例#9
0
def model(
        engine,
        store_id,
        magnitude_min, magnitude_max,
        moment_tensor,
        stress_drop_min, stress_drop_max,
        rupture_velocity_min, rupture_velocity_max,
        depth_min, depth_max,
        distance_min, distance_max,
        measures,
        nsources=400,
        nreceivers=1,
        apply_source_response_via_spectra=True,
        debug=True):

    d2r = math.pi / 180.

    components = set()
    for measure in measures:
        if not measure.components:
            raise Exception('no components given in measurement rule')

        for component in measure.components:
            components.add(component)

    components = list(components)

    data = []
    nerrors = 0
    traces_debug = []
    markers_debug = []
    for isource in xrange(nsources):
        magnitude = num.random.uniform(
            magnitude_min, magnitude_max)
        stress_drop = num.random.uniform(
            stress_drop_min, stress_drop_max)
        rupture_velocity = num.random.uniform(
            rupture_velocity_min, rupture_velocity_max)

        radius = (pmt.magnitude_to_moment(magnitude) * 7./16. /
                  stress_drop)**(1./3.)

        duration = 1.5 * radius / rupture_velocity

        if moment_tensor is None:
            mt = pmt.MomentTensor.random_dc(magnitude=magnitude)
        else:
            mt = copy.deepcopy(moment_tensor)
            mt.magnitude = magnitude

        depth = num.random.uniform(depth_min, depth_max)
        if apply_source_response_via_spectra:
            source = gf.MTSource(
                m6=mt.m6(),
                depth=depth)

            extra_responses = [
                wmeasure.BruneResponse(duration=duration)]
        else:
            source = gf.MTSource(
                m6=mt.m6(),
                depth=depth,
                stf=gf.HalfSinusoidSTF(effective_duration=duration))

            extra_responses = []

        for ireceiver in xrange(nreceivers):
            angle = num.random.uniform(0., 360.)
            distance = num.exp(num.random.uniform(
                math.log(distance_min), math.log(distance_max)))

            targets = []
            for comp in components:
                targets.append(gf.Target(
                    quantity='displacement',
                    codes=('', '%i_%i' % (isource, ireceiver), '', comp),
                    north_shift=distance*math.cos(d2r*angle),
                    east_shift=distance*math.sin(d2r*angle),
                    depth=0.,
                    store_id=store_id))

            resp = engine.process(source, targets)
            amps = []
            for measure in measures:
                comp_to_tt = {}
                for (source, target, tr) in resp.iter_results():
                    comp_to_tt[target.codes[-1]] = (target, tr)

                targets, trs = zip(*(
                    comp_to_tt[c] for c in measure.components))

                try:
                    result = wmeasure.evaluate(
                        engine, source, targets, trs,
                        extra_responses,
                        debug=debug)

                    if not debug:
                        amps.append(result)
                    else:
                        amp, trs, marker = result
                        amps.append(amp)
                        traces_debug.extend(trs)
                        markers_debug.append(marker)

                except wmeasure.AmplitudeMeasurementFailed:
                    nerrors += 1
                    amps.append(None)

            data.append([magnitude, duration, depth, distance] + amps)

    if debug:
        trace.snuffle(traces_debug, markers=markers_debug)

    return num.array(data, dtype=num.float)
示例#10
0
[stations, targets, event, data_traces] = inputf.load_seism_data(datadir)

engine = gf.LocalEngine(store_superdirs=storehomedir)

sources = [
    gf.RectangularSource(lat=29.124977942689519,
                         lon=34.871469702014863,
                         width=24 * km,
                         length=58 * km,
                         time=817013725.5571846,
                         depth=12 * km,
                         strike=206.3701904106799,
                         dip=73.0785305323845,
                         rake=-8.135103051434966,
                         magnitude=7.01,
                         stf=gf.HalfSinusoidSTF(duration=3., anchor=-1.))
]

## gf.RectangularSource(
##     lat=29.0,
##     lon=35.0,
##     width=4 * km,
##     length=5 * km,
##     time=817013720.5571846,
##     depth=5 * km,
##     strike=180.0,
##     dip=70.,
##     rake=-7.,
##     magnitude=4.01,
##     stf=gf.HalfSinusoidSTF(duration=2., anchor=-1.))]