Exemplo n.º 1
0
    def test_effective_durations(self):
        deltat = 1e-4
        for stf in [
                gf.HalfSinusoidSTF(duration=2.0),
                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
Exemplo n.º 2
0
    def test_source_to_event(self):

        for S in gf.source_classes:
            stf = gf.TriangularSTF(effective_duration=2.0)
            s1 = S(lat=10.,
                   lon=20.,
                   depth=1000.,
                   north_shift=500.,
                   east_shift=500.,
                   stf=stf)
            ev = s1.pyrocko_event()
            s2 = S.from_pyrocko_event(ev)

            if not isinstance(s1, gf.DoubleDCSource):
                assert numeq([
                    s1.effective_lat, s1.effective_lon, s1.depth,
                    s1.stf.effective_duration
                ], [
                    s2.effective_lat, s2.effective_lon, s2.depth,
                    s2.stf.effective_duration
                ], 0.001)
            else:
                assert numeq([
                    s1.effective_lat, s1.effective_lon, s1.depth,
                    s1.stf.effective_duration
                ], [
                    s2.effective_lat, s2.effective_lon, s2.depth,
                    s2.stf1.effective_duration
                ], 0.001)
Exemplo n.º 3
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
     ]
Exemplo n.º 4
0
    def test_stf_triangular(self, plot=False):
        from matplotlib import pyplot as plt

        tref = 10.
        for duration in [0., 3.]:
            for peak_ratio in num.linspace(0., 1., 11):
                stf = gf.TriangularSTF(duration=duration,
                                       peak_ratio=peak_ratio,
                                       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()
Exemplo n.º 5
0
    def test_source_to_event(self):
        def stype(x):
            return x.__class__.__name__

        for S in gf.source_classes:
            if S is gf.CombiSource:
                continue

            stf = gf.TriangularSTF(effective_duration=2.0)
            s1 = S(lat=10.,
                   lon=20.,
                   depth=1000.,
                   north_shift=500.,
                   east_shift=500.,
                   stf=stf)
            ev = s1.pyrocko_event()

            try:
                s1_mag = s1.get_magnitude()
                mess = ''
            except (gf.DerivedMagnitudeError, NotImplementedError) as e:
                s1_mag = 'N/A'
                mess = '* %s *' % e

            if ev.magnitude is not None:
                ev_mag = ev.magnitude
            else:
                ev_mag = 'N/A'

            assert ev.lat == s1.lat
            assert ev.lon == s1.lon
            assert ev.north_shift == s1.north_shift
            assert ev.east_shift == s1.east_shift

            s2 = S.from_pyrocko_event(ev)

            assert ev.lat == s2.lat
            assert ev.lon == s2.lon
            assert ev.north_shift == s2.north_shift
            assert ev.east_shift == s2.east_shift

            if ev.moment_tensor:
                mt_mag = ev.moment_tensor.magnitude
            else:
                mt_mag = 'N/A'

            try:
                s2_mag = s2.get_magnitude()
                mess = ''
            except (gf.DerivedMagnitudeError, NotImplementedError) as e:
                s2_mag = 'N/A'
                mess = '* %s *' % e

            # print(
            #     stype(s1).ljust(32),
            #     s1_mag,
            #     ev.magnitude or 'N/A',
            #     mt_mag,
            #     s2_mag,
            #     mess)

            del mess

            def assert_mag_eq(mag1, mag2):
                if 'N/A' not in (mag1, mag2):
                    num.testing.assert_approx_equal(mag1, mag2)

            assert_mag_eq(s1_mag, ev_mag)
            assert_mag_eq(s1_mag, mt_mag)
            assert_mag_eq(s1_mag, s2_mag)

            if not isinstance(s1, gf.DoubleDCSource):
                assert numeq([
                    s1.effective_lat, s1.effective_lon, s1.depth,
                    s1.stf.effective_duration
                ], [
                    s2.effective_lat, s2.effective_lon, s2.depth,
                    s2.stf.effective_duration
                ], 0.001)
            else:
                assert numeq([
                    s1.effective_lat, s1.effective_lon, s1.depth,
                    s1.stf.effective_duration
                ], [
                    s2.effective_lat, s2.effective_lon, s2.depth,
                    s2.stf1.effective_duration
                ], 0.001)
save_dir = 'Experiment2'
if not os.path.exists(save_dir):
    os.makedirs(save_dir)
    
velocity_model = 'crust2_m5_hardtop_16Hz'

# create random moment tensors
print('Creating random moment tensors...')
moment_tensors = [createMT_DC(1) for i in range(n_seismograms)] 
source_mechanisms = n_seismograms*['DC']
 
#initialize source time functions 
durations = np.random.randint(1,11,n_eachstf)
stfs = [LognormalSTF(shape=2, duration=dur) for dur in durations] + \
       [gf.BoxcarSTF(duration=dur) for dur in durations] + \
       [gf.TriangularSTF(duration=dur) for dur in durations]

stftypes = n_eachstf*['lognorm'] + n_eachstf*['boxcar'] +n_eachstf*['triangle']

# uniform depth of 20 km / 20,000m
depths = n_seismograms*[20000] 

# seismometer target and the actual computation engine
target = gf.Target(
           quantity='displacement',
           lat=0, lon=long,
           store_id=velocity_model,
           codes=('NET', 'STA', 'LOC', 'E'),
           tmin=tmin, tmax=tmax)
engine = LocalEngine(store_dirs=[velocity_model])