def compare_filterbank_fil_to_h5():
    """ Load Voyager dataset and test that both fil and hdf5 readers return same headers and data """

    print("Loading FIL and HDF5 data with Waterfall()..."),
    a = bl.Filterbank(voyager_h5)
    b = bl.Filterbank(voyager_fil)
    print("OK")

    print("Reading headers..")
    print("\nHDF5 file header:")
    pprint(a.header)
    print("\nFIL file header:")
    pprint(b.header)
    print("Headers are loading OK")

    print("\nChecking header values match..."),
    for key in b.header.keys():
        assert b.header[key] == a.header[key]
    print("OK")

    print("Checking datatype matches..."),
    assert a.data.dtype == b.data.dtype
    print("OK")

    print("Checking data matches..."),
    assert np.allclose(a.data, b.data)
    assert a.data.dtype == b.data.dtype
    print("OK")
Beispiel #2
0
def test_fil_write():
    try:
        a = bl.Filterbank(voyager_h5)
        b = bl.Filterbank(voyager_fil)

        a.write_to_fil('test.fil')
        b.write_to_fil('test2.fil')

        c = bl.Filterbank('test.fil')
        d = bl.Filterbank('test2.fil')

        for key in a.header.keys():
            if key != b'DIMENSION_LABELS':
                assert a.header[key] == c.header[key]
                assert key in c.header.keys()
                assert a.header[key] == d.header[key]
                assert key in d.header.keys()

        assert np.allclose(a.data, c.data)
        assert np.allclose(a.data, d.data)
    except AssertionError:
        print(key, a.header[key], b.header[key], c.header[key], d.header[key])
        raise

    finally:
        os.remove('test.fil')
        os.remove('test2.fil')
def test_filterbank_data_load_range_freq():
    ff = bl.Filterbank(voyager_fil, f_start=8419.24, f_stop=8419.35)
    hf = bl.Filterbank(voyager_h5, f_start=8419.24, f_stop=8419.35)

    print(ff.data.shape)
    print(hf.data.shape)
    print(ff.freqs.shape)
    print(hf.freqs.shape)

    print(ff.data[0].max(), ff.data[0].argmax())
    print(hf.data[0].max(), hf.data[0].argmax())
    print(ff.data[-1].max(), ff.data[-1].argmax())
    print(hf.data[-1].max(), hf.data[-1].argmax())

    # Assert data is loaded to the same shape and has same values
    assert ff.data.shape == hf.data.shape == (16, 1, 39371)
    assert np.allclose(ff.data, hf.data)

    # Check the Voyager carrier has the known amplitudes at first and last integration
    assert np.allclose(ff.data[0].max(), hf.data[0].max(), 3.09333e+11)
    assert np.allclose(ff.data[-1].max(), hf.data[-1].max(), 2.74257e+11)

    # Check the tone is in the same bin for both
    assert ff.data[0].argmax() == hf.data[0].argmax() == 18960
    assert ff.data[-1].argmax() == hf.data[-1].argmax() == 18997

    plt.subplot(2, 1, 1)
    ff.plot_spectrum()

    plt.subplot(2, 1, 2)
    hf.plot_spectrum()
    plt.tight_layout()
Beispiel #4
0
def test_plotting_doesnt_cause_exceptions():
    """ Try running the plotting routines. They should not raise expections even without X windows """
    a = bl.Filterbank('Voyager_data/Voyager1.single_coarse.fine_res.h5')
    b = bl.Filterbank('Voyager_data/Voyager1.single_coarse.fine_res.fil')

    a.plot_all()
    a.plot_kurtosis()
    a.plot_spectrum()
    a.plot_spectrum_min_max()
    a.plot_waterfall()
    a.plot_time_series()

    b.plot_all()
    b.plot_kurtosis()
    b.plot_spectrum()
    b.plot_spectrum_min_max()
    b.plot_waterfall()
    b.plot_time_series()
def test_plotting_doesnt_cause_exceptions():
    """ Try running the plotting routines. They should not raise expections even without X windows """
    a = bl.Filterbank(voyager_h5)
    b = bl.Filterbank(voyager_fil)

    a.plot_all()
    a.plot_kurtosis()
    a.plot_spectrum()
    a.plot_spectrum_min_max()
    a.plot_waterfall()
    a.plot_time_series()

    b.plot_all()
    b.plot_kurtosis()
    b.plot_spectrum()
    b.plot_spectrum_min_max()
    b.plot_waterfall()
    b.plot_time_series()
Beispiel #6
0
def test_grab_data_works_across_all_fil_h5():

    ff = bl.Filterbank('Voyager_data/Voyager1.single_coarse.fine_res.fil')
    hf = bl.Filterbank('Voyager_data/Voyager1.single_coarse.fine_res.h5')
    fw = bl.Waterfall('Voyager_data/Voyager1.single_coarse.fine_res.fil')
    hw = bl.Waterfall('Voyager_data/Voyager1.single_coarse.fine_res.h5')
    all_readers = [ff, hf, fw, hw]

    for ii, rr in enumerate(all_readers):
        f, d = rr.grab_data(f_start=8419.29, f_stop=8419.30)
        print(f.shape, d.shape)
        assert f.shape == (3580, )
        assert d.shape == (16, 3580)

    for ii, rr in enumerate(all_readers):
        f, d = rr.grab_data(f_start=8419.29685, f_stop=8419.2971)
        print(f.shape, d.shape)
        assert f.shape == (91, )
        assert d.shape == (16, 91)
Beispiel #7
0
def test_sigproc_generate_headers():
    """ Test if you can generate headers OK from files """
    a = bl.Filterbank(voyager_h5)
    b = bl.Filterbank(voyager_fil)
    sigproc.generate_sigproc_header(a)
    sigproc.generate_sigproc_header(b)
Beispiel #8
0
def test_sigproc_generate_headers():
    """ Test if you can generate headers OK from files """
    a = bl.Filterbank('Voyager_data/Voyager1.single_coarse.fine_res.h5')
    b = bl.Filterbank('Voyager_data/Voyager1.single_coarse.fine_res.fil')
    sigproc.generate_sigproc_header(a)
    sigproc.generate_sigproc_header(b)