예제 #1
0
    def test_tutorial_codanorm(self):
        plot = self.all_tests
#        freq = np.array([0.375, 0.75, 1.5, 3.0, 6.0])
#        b = np.array([0.012, 0.019, 0.029, 0.038, 0.047])
        freq = np.array([3.0, 6.0])
        b = np.array([0.038, 0.047])
        kwargs = {
            "freqs": {"width": 1, "cfreqs": list(freq)},
            "coda_normalization": [180, 200],
            "seismic_moment_method": None,
            'plot_energies': plot, 'plot_fits': plot,
            'plot_eventresult': plot, 'plot_eventsites': plot,
            'plot_results': plot,
            'plot_sites': plot, 'plot_sds': plot, 'plot_mags': plot,
        }
        if self.njobs:
            kwargs['njobs'] = int(self.njobs)
        if self.verbose:
            kwargs['verbose'] = 3
        tempdirname = 'qopen_test4' if self.permanent_tempdir else None
        with tempdir(tempdirname, self.delete):
            run(create_config='conf.json', tutorial=True)
            events = read_events('example_events.xml', 'QUAKEML')[:2]
            result = run(conf='conf.json', events=events, **kwargs)
            if plot:
                plot_comparison(result['freq'], freq, None, None,
                                result['b'], b)
                # 3 * 2 * 2 energies, fits, optimization
                # 2 * 2 eventresults, eventsites
                self.check_num_images('plots/*.png', 16)
                self.check_num_images('plots/*.pdf', 3)
        np.testing.assert_equal(result['freq'], freq)
        np.testing.assert_array_less(np.abs(np.log10(result['b'] / b)), 0.5)
예제 #2
0
파일: test_core.py 프로젝트: mlaaten/qopen
 def test_tutorial_codaQ(self):
     if not self.all_tests:
         raise unittest.SkipTest('save time')
     plot = self.all_tests
     freq = np.array([0.375, 0.75, 1.5, 3.0, 6.0])
     b = np.array([0.012, 0.019, 0.029, 0.038, 0.047])
     kwargs = {
         "optimize": False,
         "bulkwindow": None,
         "G_plugin": "qopen.rt : G_diffapprox3d",
         'plot_energies': plot, 'plot_fits': plot,
         'plot_eventresult': plot, 'plot_eventsites': plot,
         'plot_results': plot,
         'plot_sites': plot, 'plot_sds': plot, 'plot_mags': plot,
     }
     if self.njobs:
         kwargs['njobs'] = int(self.njobs)
     if self.verbose:
         kwargs['verbose'] = 3
     tempdirname = 'qopen_test3' if self.permanent_tempdir else None
     with tempdir(tempdirname, self.delete):
         run(create_config='conf.json', tutorial=True)
         result = run(conf='conf.json', **kwargs)
         if plot:
             plot_comparison(result['freq'], freq, None, None,
                             result['b'], b)
     np.testing.assert_equal(result['freq'], freq)
     np.testing.assert_array_less(np.abs(np.log10(result['b'] / b)), 0.5)
예제 #3
0
    def test_results_of_tutorial(self):
        """Test against publication of Sens-Schoenfelder and Wegler (2006)"""
        plot = PLOT
        freq = [0.1875, 0.375, 0.75, 1.5, 3.0, 6.0, 12.0, 24.0]  # page 1365
        g0 = [2e-6, 2e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1.5e-6, 2e-6]  # fig 4
        Qi = [2e-3, 2e-3, 1.8e-3, 2e-3, 1.5e-3, 1e-3, 5e-4, 2e-4]  # fig 5
        freq = np.array(freq)
        g0 = np.array(g0)
        b = np.array(Qi) * (2 * np.pi * np.array(freq))
        M0 = {'20010623': 5.4e14, '20020722': 4.1e15, '20030222': 1.5e16,
              '20030322': 8.8e14, '20041205': 6.8e15}  # table 1
        kwargs = {
            'plot_energies': plot, 'plot_optimization': plot,
            'plot_fits': plot, 'plot_eventresult': plot,
            'plot_eventsites': plot, 'plot_results': plot,
            'plot_sites': plot, 'plot_sds': plot, 'plot_mags': plot
        }
        ind = np.logical_and(freq > 0.3, freq < 10)
        freq = freq[ind]
        g0 = np.array(g0)[ind]
        b = np.array(b)[ind]
        with tempdir(delete=not plot):
            run(create_config='conf.json', tutorial=True)
            result = run(conf='conf.json', **kwargs)
            if plot:
                plot_comparison(result['freq'], freq, result['g0'], g0,
                                result['b'], b)
        M0_qopen = {evid.split('_')[0]: r.get('M0')
                    for evid, r in result['events'].items()}
        temp = [(M0_qopen[evid], M0[evid]) for evid in sorted(M0)]
        M0_qopen, M0 = zip(*temp)
        M0 = np.array(M0) / 2 ** 0.5  # wrong surface correction in paper
        # There seems to be a wrong factor of around 1e4 in the observed
        # envelopes (fig. 3). the error could be in the paper or the script.
        # Therefore M0 should be different by a factor of 1e2,
        # but actually they differ by a factor of 10. This corresponds to
        # a magnitude differenc of 0.67. The magnitude comparison mags.pdf
        # suggests that the determined M0s by the script are ok.
        M0 = 10 * M0

#        np.set_printoptions(formatter={'all':lambda x: '%.2g' % x})
#        print('g0 test vs paper')
#        print(np.array(result['g0']))
#        print(g0)
#        print('b test vs paper')
#        print(np.array(result['b']))
#        print(b)
#        print('M0 test vs paper')
#        print(np.array(M0_qopen))
#        print(M0)
#        plot_comparison(result['freq'], freq, result['g0'], g0, result['b'],b)

        np.testing.assert_equal(result['freq'], freq)
#        print(np.log10(result['g0'] / g0))
#        print(np.log10(result['b'] / b))
#        print(np.log10(M0_qopen / M0))
        np.testing.assert_array_less(np.abs(np.log10(result['g0'] / g0)), 0.5)
        np.testing.assert_array_less(np.abs(np.log10(result['b'] / b)), 0.5)
        np.testing.assert_array_less(np.abs(np.log10(M0_qopen / M0)), 0.51)
예제 #4
0
    def test_results_of_tutorial(self):
        """Test against publication of Sens-Schoenfelder and Wegler (2006)"""
        plot = PLOT
        freq = [0.1875, 0.375, 0.75, 1.5, 3.0, 6.0, 12.0, 24.0]  # page 1365
        g0 = [2e-6, 2e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1.5e-6, 2e-6]  # fig 4
        Qi = [2e-3, 2e-3, 1.8e-3, 2e-3, 1.5e-3, 1e-3, 5e-4, 2e-4]  # fig 5
        freq = np.array(freq)
        g0 = np.array(g0)
        b = np.array(Qi) * (2 * np.pi * np.array(freq))
        M0 = {'20010623': 5.4e14, '20020722': 4.1e15, '20030222': 1.5e16,
              '20030322': 8.8e14, '20041205': 6.8e15}  # table 1
        kwargs = {
            'plot_energies': plot, 'plot_optimization': plot,
            'plot_fits': plot, 'plot_eventresult': plot,
            'plot_eventsites': plot, 'plot_results': plot,
            'plot_sites': plot, 'plot_sds': plot, 'plot_mags': plot
        }
        ind = np.logical_and(freq > 0.3, freq < 10)
        freq = freq[ind]
        g0 = np.array(g0)[ind]
        b = np.array(b)[ind]
        with tempdir(delete=not plot):
            run(create_config='conf.json', tutorial=True)
            result = run(conf='conf.json', **kwargs)
            if plot:
                plot_comparison(result['freq'], freq, result['g0'], g0,
                                result['b'], b)
        M0_qopen = {evid.split('_')[0]: r.get('M0')
                    for evid, r in result['events'].items()}
        temp = [(M0_qopen[evid], M0[evid]) for evid in sorted(M0)]
        M0_qopen, M0 = zip(*temp)
        M0 = np.array(M0) / 2 ** 0.5  # wrong surface correction in paper
        # There seems to be a wrong factor of around 1e4 in the observed
        # envelopes (fig. 3). the error could be in the paper or the script.
        # Therefore M0 should be different by a factor of 1e2,
        # but actually they differ by a factor of 10. This corresponds to
        # a magnitude differenc of 0.67. The magnitude comparison mags.pdf
        # suggests that the determined M0s by the script are ok.
        M0 = 10 * M0

#        np.set_printoptions(formatter={'all':lambda x: '%.2g' % x})
#        print('g0 test vs paper')
#        print(np.array(result['g0']))
#        print(g0)
#        print('b test vs paper')
#        print(np.array(result['b']))
#        print(b)
#        print('M0 test vs paper')
#        print(np.array(M0_qopen))
#        print(M0)
#        plot_comparison(result['freq'], freq, result['g0'], g0, result['b'], b)

        np.testing.assert_equal(result['freq'], freq)
#        print(np.log10(result['g0'] / g0))
#        print(np.log10(result['b'] / b))
#        print(np.log10(M0_qopen / M0))
        np.testing.assert_array_less(np.abs(np.log10(result['g0'] / g0)), 0.5)
        np.testing.assert_array_less(np.abs(np.log10(result['b'] / b)), 0.5)
        np.testing.assert_array_less(np.abs(np.log10(M0_qopen / M0)), 0.51)
예제 #5
0
def calc_stuff(conf, eventids=None, sh=None):
    get_waveforms = waveform_cache(CACHE_PATH,
                                   CACHE_WIN,
                                   request_again=CACHE_REQUEST_AGAIN)(
                                       Client().get_waveforms)
    stations = read_inventory(STATIONS_FNAME, 'STATIONXML')
    print('warm up finished')
    if eventids is None:
        fnames = sorted(glob(EVENT_GLOB))
    else:
        fnames = [EVENT_FNAME % eid for eid in eventids]
    for fname in fnames:
        eventid = fname.split('/')[-1].replace('.xml', '')
        if sh is not None and eventid in sh:
            continue
        print('processing event %s...' % eventid)
        event = read_events(fname, 'QUAKEML')
        results = run(events=event,
                      inventory=stations,
                      get_waveforms=get_waveforms,
                      **conf)
        if sh is None:
            continue
        if results is None:
            sh[eventid] = None
            continue
        res = list(results['events'].values())[0]
        if res is None or all([g0 is None for g0 in res['g0']]):
            sh[eventid] = None
            continue
        for st in tuple(res['R'].keys()):
            if all([r is None for r in res['R'][st]]):
                res['R'].pop(st)
        sh[eventid] = res