Beispiel #1
0
def get_local_magnitude(st,
                        stations,
                        stlons,
                        stlats,
                        evtime,
                        evlon,
                        evlat,
                        evdep,
                        freqmin=1,
                        freqmax=10,
                        max_epicenter_dist=100):

    allmags = []
    for station in stations:
        st1 = st.copy().select(station=station)
        for tr in st1:
            try:
                tr.detrend('demean')
                tr.detrend('linear')
                tr.taper(max_percentage=0.005, type='hann')
                tr.filter("bandpass",
                          freqmin=freqmin,
                          freqmax=freqmax,
                          corners=2)

                amp_min = tr.data.min()
                amp_max = tr.data.max()
                ind1 = np.where(amp_min == tr.data)[0][0]
                ind2 = np.where(amp_max == tr.data)[0][0]
                amplitude = abs(amp_max) + abs(amp_min)
                timespan = tr.times("utcdatetime")[ind2] - tr.times(
                    "utcdatetime")[ind1]

                ind = np.where(station == stations)[0][0]
                h_dist = calc_vincenty_inverse(evlat, evlon, stlats[ind],
                                               stlons[ind])[0] / 1000.

                PYGEMA_PATH = "%s/pygema" % (site.getsitepackages()[0])
                dataless_file = glob.glob(
                    "%s/src/dataless/%s_%s.dataless" %
                    (PYGEMA_PATH, tr.stats.network, tr.stats.station))[0]
                parser = Parser(dataless_file)
                paz = parser.get_paz(tr.id)

                mag = estimate_magnitude(paz, amplitude, timespan, h_dist)
                if h_dist <= max_epicenter_dist:
                    allmags.append(mag)

            except:
                continue

    # calculate mean of magnitudes
    if len(allmags) > 0:
        evmag = np.nanmean(allmags)
    else:
        evmag = 0.0

    return evmag
Beispiel #2
0
    def test_estimate_magnitude(self):
        """
        Tests against PITSA. Note that PITSA displays microvolt, that is
        the amplitude values must be computed back into counts (for this
        stations .596microvolt/count was used). Pitsa internally calculates
        with the sensitivity 2800 of the WA. Using this we get for the
        following for event 2009-07-19 23:03::

            RTSH PITSA 2.263 ObsPy 2.294
            RTBE PITSA 1.325 ObsPy 1.363
            RMOA PITSA 1.629 ObsPy 1.675
        """
        paz = {'poles': [-4.444 + 4.444j, -4.444 - 4.444j, -1.083 + 0j],
               'zeros': [0 + 0j, 0 + 0j, 0 + 0j],
               'gain': 1.0,
               'sensitivity': 671140000.0}
        mag_rtsh = estimate_magnitude(paz, 3.34e6, 0.065, 0.255)
        self.assertAlmostEqual(mag_rtsh, 2.1328727151723488)
        mag_rtbe = estimate_magnitude(paz, 3.61e4, 0.08, 2.197)
        self.assertAlmostEqual(mag_rtbe, 1.1962687721890191)
        mag_rnon = estimate_magnitude(paz, 6.78e4, 0.125, 1.538)
        self.assertAlmostEqual(mag_rnon, 1.4995311686507182)
Beispiel #3
0
    def test_estimate_magnitude(self):
        """
        Tests against PITSA. Note that PITSA displays microvolt, that is
        the amplitude values must be computed back into counts (for this
        stations .596microvolt/count was used). Pitsa internally calculates
        with the sensitivity 2800 of the WA. Using this we get for the
        following for event 2009-07-19 23:03::

            RTSH PITSA 2.263 ObsPy 2.294
            RTBE PITSA 1.325 ObsPy 1.363
            RMOA PITSA 1.629 ObsPy 1.675
        """
        paz = {
            'poles': [-4.444 + 4.444j, -4.444 - 4.444j, -1.083 + 0j],
            'zeros': [0 + 0j, 0 + 0j, 0 + 0j],
            'gain': 1.0,
            'sensitivity': 671140000.0
        }
        mag_rtsh = estimate_magnitude(paz, 3.34e6, 0.065, 0.255)
        self.assertAlmostEqual(mag_rtsh, 2.1328727151723488)
        mag_rtbe = estimate_magnitude(paz, 3.61e4, 0.08, 2.197)
        self.assertAlmostEqual(mag_rtbe, 1.1962687721890191)
        mag_rnon = estimate_magnitude(paz, 6.78e4, 0.125, 1.538)
        self.assertAlmostEqual(mag_rnon, 1.4995311686507182)
def mag_approx(peak_value, frequency, hypo_dist=20):
    """
    Give peak value of raw data for a very crude and simple magnitude estimation.

    For simplicity, this is done assuming hypocentral location, peak frequency, etc.
    To keep it simple for now the response information is entered manually here
    (it is the same for all instruments used here).
    """
    poles = [-1.48600E-01  + 1.48600E-01j,
             -1.48600E-01  - 1.48600E-01j,
             -4.14690E+02  + 0.00000E+00j,
             -9.99027E+02  + 9.99027E+02j,
             -9.99027E+02  - 9.99027E+02j]
    zeros = [0.0 + 0.0j,
             0.0 + 0.0j,
             1.1875E+03 + 0.0j]
    norm_factor = 7.49898E+08
    sensitivity = 6.97095E+05
    paz = {'poles': poles, 'zeros': zeros, 'gain': norm_factor,
           'sensitivity': sensitivity}
    ml = estimate_magnitude(paz, peak_value, 0.5 / frequency, hypo_dist)
    return ml
Beispiel #5
0
    def test_estimate_magnitude(self):
        """
        Tests against PITSA. Note that PITSA displays microvolt, that is
        the amplitude values must be computed back into counts (for this
        stations .596microvolt/count was used). Pitsa internally calculates
        with the sensitivity 2800 of the WA. Using this we get for the
        following for event 2009-07-19 23:03::

            RTSH PITSA 2.263 ObsPy 2.294
            RTBE PITSA 1.325 ObsPy 1.363
            RMOA PITSA 1.629 ObsPy 1.675
        """
        # the poles/zeros are the same for all three stations but the overall
        # sensitivity differs, this was probably not taken into account when
        # implementing this test (the specified 'sensitivity' is for RTSH), so
        # below we use the response for station RTSH for the test
        paz = {
            'poles': [-4.444 + 4.444j, -4.444 - 4.444j, -1.083 + 0j],
            'zeros': [0 + 0j, 0 + 0j, 0 + 0j],
            'gain': 1.0,
            'sensitivity': 671140000.0
        }
        mag_rtsh = estimate_magnitude(paz, 3.34e6, 0.065, 0.255)
        self.assertAlmostEqual(mag_rtsh, 2.1328727151723488)
        mag_rtbe = estimate_magnitude(paz, 3.61e4, 0.08, 2.197)
        self.assertAlmostEqual(mag_rtbe, 1.1962687721890191)
        mag_rnon = estimate_magnitude(paz, 6.78e4, 0.125, 1.538)
        self.assertAlmostEqual(mag_rnon, 1.4995311686507182)

        # now also test using Response object to calculate amplitude
        # (use RTSH response for all three measurements, see above comment)
        # response calculated using all stages is slightly different from the
        # PAZ + overall sensitivity used above, so we get slightly different
        # values here..
        response = read_inventory(os.path.join(self.path, 'BW_RTSH.xml'),
                                  format='STATIONXML')[0][0][0].response
        mag_rtsh = estimate_magnitude(response, 3.34e6, 0.065, 0.255)
        self.assertAlmostEqual(mag_rtsh, 2.1179529876187635)
        mag_rtbe = estimate_magnitude(response, 3.61e4, 0.08, 2.197)
        self.assertAlmostEqual(mag_rtbe, 1.1832677953138184)
        mag_rnon = estimate_magnitude(response, 6.78e4, 0.125, 1.538)
        self.assertAlmostEqual(mag_rnon, 1.4895395665022975)
Beispiel #6
0
    def test_estimate_magnitude(self):
        """
        Tests against PITSA. Note that PITSA displays microvolt, that is
        the amplitude values must be computed back into counts (for this
        stations .596microvolt/count was used). Pitsa internally calculates
        with the sensitivity 2800 of the WA. Using this we get for the
        following for event 2009-07-19 23:03::

            RTSH PITSA 2.263 ObsPy 2.294
            RTBE PITSA 1.325 ObsPy 1.363
            RMOA PITSA 1.629 ObsPy 1.675
        """
        # the poles/zeros are the same for all three stations but the overall
        # sensitivity differs, this was probably not taken into account when
        # implementing this test (the specified 'sensitivity' is for RTSH), so
        # below we use the response for station RTSH for the test
        paz = {
            "poles": [-4.444 + 4.444j, -4.444 - 4.444j, -1.083 + 0j],
            "zeros": [0 + 0j, 0 + 0j, 0 + 0j],
            "gain": 1.0,
            "sensitivity": 671140000.0,
        }
        mag_rtsh = estimate_magnitude(paz, 3.34e6, 0.065, 0.255)
        self.assertAlmostEqual(mag_rtsh, 2.1328727151723488)
        mag_rtbe = estimate_magnitude(paz, 3.61e4, 0.08, 2.197)
        self.assertAlmostEqual(mag_rtbe, 1.1962687721890191)
        mag_rnon = estimate_magnitude(paz, 6.78e4, 0.125, 1.538)
        self.assertAlmostEqual(mag_rnon, 1.4995311686507182)

        # now also test using Response object to calculate amplitude
        # (use RTSH response for all three measurements, see above comment)
        # response calculated using all stages is slightly different from the
        # PAZ + overall sensitivity used above, so we get slightly different
        # values here..
        response = read_inventory(os.path.join(self.path, "BW_RTSH.xml"), format="STATIONXML")[0][0][0].response
        mag_rtsh = estimate_magnitude(response, 3.34e6, 0.065, 0.255)
        self.assertAlmostEqual(mag_rtsh, 2.1179529876187635)
        mag_rtbe = estimate_magnitude(response, 3.61e4, 0.08, 2.197)
        self.assertAlmostEqual(mag_rtbe, 1.1832677953138184)
        mag_rnon = estimate_magnitude(response, 6.78e4, 0.125, 1.538)
        self.assertAlmostEqual(mag_rnon, 1.4895395665022975)