def comp_ppsd(sta, debug=True):
    net = "IU"
    for chan in chans:
        print('On:' + sta + ' ' + chan)
        stime = UTCDateTime('2016-280T00:00:00')
        etime = UTCDateTime('2019-280T00:00:00')
        ctime = stime
        if sta == 'QSPA':
            sen = 3.43 * 10**9
        else:
            sen = 41.943
        paz = {'gain': 1., 'poles': [], 'zeros': [], 'sensitivity': sen}
        while ctime < etime:
            if debug:
                print(ctime)
            try:
                #if True:
                st = Stream()
                nctime = ctime
                for addday in range(5):
                    nctime = ctime + addday * 24 * 60 * 60
                    st += read('/msd/' + net + '_' + sta + '/' +
                               str(nctime.year) + '/' +
                               str(nctime.julday).zfill(3) + '/*' + chan + '*')
                if debug:
                    print(st)
            except:
                ctime += 5 * 24 * 60 * 60
                continue
            st.merge(fill_value=0)
            if 'ppsd' not in vars():
                ppsd = PPSD(st[0].stats,
                            paz,
                            db_bins=(-100, 100, 1.),
                            ppsd_length=2**14,
                            period_smoothing_width_octaves=0.50,
                            special_handling="ringlaser")
            ppsd.add(st)
            ctime += 5 * 24 * 60 * 60
        ppsd.save_npz('PDF_DATA_' + net + '_' + sta + '_' + chan + ".npz")
        ppsd.plot(filename='PPSD_' + net + '_' + sta + '_' + chan + '.PNG',
                  show_noise_models=False,
                  period_lim=(2., 1000.))
        del ppsd
    return
    def test_ppsd_add_npz(self):
        """
        Test PPSD.add_npz().
        """
        # set up a bogus PPSD, with fixed random psds but with real start times
        # of psd pieces, to facilitate testing the stack selection.
        ppsd = PPSD(stats=Stats(dict(sampling_rate=150)),
                    metadata=None,
                    db_bins=(-200, -50, 20.),
                    period_step_octaves=1.4)
        _times_processed = np.load(
            os.path.join(self.path, "ppsd_times_processed.npy")).tolist()
        # change data to nowadays used nanoseconds POSIX timestamp
        _times_processed = [UTCDateTime(t)._ns for t in _times_processed]
        np.random.seed(1234)
        _binned_psds = [
            arr for arr in np.random.uniform(-200, -50, (
                len(_times_processed), len(ppsd.period_bin_centers)))
        ]

        with NamedTemporaryFile(suffix=".npz") as tf1, \
                NamedTemporaryFile(suffix=".npz") as tf2, \
                NamedTemporaryFile(suffix=".npz") as tf3:
            # save data split up over three separate temporary files
            ppsd._times_processed = _times_processed[:200]
            ppsd._binned_psds = _binned_psds[:200]
            ppsd.save_npz(tf1.name)
            ppsd._times_processed = _times_processed[200:400]
            ppsd._binned_psds = _binned_psds[200:400]
            ppsd.save_npz(tf2.name)
            ppsd._times_processed = _times_processed[400:]
            ppsd._binned_psds = _binned_psds[400:]
            ppsd.matplotlib_version = "X.X.X"
            ppsd.save_npz(tf3.name)
            # now load these saved npz files and check if all data is present
            ppsd = PPSD.load_npz(tf1.name, metadata=None)
            ppsd.add_npz(tf2.name)
            # we changed a version number so this should emit a warning
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter('always')
                ppsd.add_npz(tf3.name)
                self.assertEqual(len(w), 1)
            np.testing.assert_array_equal(_binned_psds, ppsd._binned_psds)
            np.testing.assert_array_equal(_times_processed,
                                          ppsd._times_processed)
            # adding data already present should also emit a warning and the
            # PPSD should not be changed
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter('always')
                ppsd.add_npz(tf2.name)
                self.assertEqual(len(w), 1)
            np.testing.assert_array_equal(_binned_psds, ppsd._binned_psds)
            np.testing.assert_array_equal(_times_processed,
                                          ppsd._times_processed)
    def test_ppsd_add_npz(self):
        """
        Test PPSD.add_npz().
        """
        # set up a bogus PPSD, with fixed random psds but with real start times
        # of psd pieces, to facilitate testing the stack selection.
        ppsd = PPSD(stats=Stats(dict(sampling_rate=150)), metadata=None,
                    db_bins=(-200, -50, 20.), period_step_octaves=1.4)
        _times_processed = np.load(
            os.path.join(self.path, "ppsd_times_processed.npy")).tolist()
        # change data to nowadays used nanoseconds POSIX timestamp
        _times_processed = [UTCDateTime(t)._ns for t in _times_processed]
        np.random.seed(1234)
        _binned_psds = [
            arr for arr in np.random.uniform(
                -200, -50,
                (len(_times_processed), len(ppsd.period_bin_centers)))]

        with NamedTemporaryFile(suffix=".npz") as tf1, \
                NamedTemporaryFile(suffix=".npz") as tf2, \
                NamedTemporaryFile(suffix=".npz") as tf3:
            # save data split up over three separate temporary files
            ppsd._times_processed = _times_processed[:200]
            ppsd._binned_psds = _binned_psds[:200]
            ppsd.save_npz(tf1.name)
            ppsd._times_processed = _times_processed[200:400]
            ppsd._binned_psds = _binned_psds[200:400]
            ppsd.save_npz(tf2.name)
            ppsd._times_processed = _times_processed[400:]
            ppsd._binned_psds = _binned_psds[400:]
            ppsd.matplotlib_version = "X.X.X"
            ppsd.save_npz(tf3.name)
            # now load these saved npz files and check if all data is present
            ppsd = PPSD.load_npz(tf1.name, metadata=None)
            ppsd.add_npz(tf2.name)
            # we changed a version number so this should emit a warning
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter('always')
                ppsd.add_npz(tf3.name)
                self.assertEqual(len(w), 1)
            np.testing.assert_array_equal(_binned_psds, ppsd._binned_psds)
            np.testing.assert_array_equal(_times_processed,
                                          ppsd._times_processed)
            # adding data already present should also emit a warning and the
            # PPSD should not be changed
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter('always')
                ppsd.add_npz(tf2.name)
                self.assertEqual(len(w), 1)
            np.testing.assert_array_equal(_binned_psds, ppsd._binned_psds)
            np.testing.assert_array_equal(_times_processed,
                                          ppsd._times_processed)
Exemple #4
0
#st= read(curfile)
#if idx == 0:
#ppsd = PPSD(st[0].stats, paz)
#ppsd.add(st)
#ppsd.save_npz(st[0].id + 'PDF.npz')

debug = True
string = 'newdata/output_raw/2017/XX/FF'

pazNEW = corn_freq_2_paz(4.9, .96)
pazNEW['sensitivity'] = 75900.

chans = ['HHZ', 'HHE', 'HHN']
for idx, chan in enumerate(chans):
    st = Stream()
    for s in range(1, 9):

        if debug:
            print('On ' + str(s) + ' ' + chan)
        st += read(string + str(s) + '/' + chan + '.D/XX*')

    stime = UTCDateTime('2017-05-03T01:10:00.0')
    etime = UTCDateTime('2017-05-04T01:10:00.0')
    st.trim(starttime=stime, endtime=etime)
    st.decimate(4)
    st.decimate(2)
    print(st)
    ppsd = PPSD(st[0].stats, pazNEW)
    ppsd.add(st)
    ppsd.save_npz(st[0].id + 'PDF.npz')