Пример #1
0
 def test_dechannelizetask_complex(self):
     """Test dechannelization round-tripping."""
     fh = dada.open(SAMPLE_DADA)
     # Add frequency information by hand for now.
     fh.frequency = fh.header0['FREQ'] * u.MHz
     fh.sideband = np.where(fh.header0.sideband, 1, -1)
     raw_data = fh.read()
     ct = Channelize(fh, self.n)
     dt = Dechannelize(ct)
     nrec = (fh.shape[0] // self.n) * self.n
     assert dt.shape == (nrec,) + fh.shape[1:]
     data = dt.read()
     # Note: round-trip is not perfect due to rounding errors.
     assert np.allclose(data, raw_data[:nrec], atol=1.e-5)
     assert np.all(dt.frequency == fh.frequency)
     assert np.all(dt.sideband == fh.sideband)
     # Check class method
     dt2 = ct.inverse(ct)
     data2 = dt2.read()
     assert np.all(data2 == data)
     # Check inverse inverse as well.
     ct2 = dt2.inverse(fh)
     ct.seek(0)
     ft = ct.read()
     ft2 = ct2.read()
     assert np.all(ft == ft2)
     dt2.close()
Пример #2
0
 def test_polarization_propagation(self):
     fh = dada.open(SAMPLE_DADA)
     # Add frequency and sideband information by hand.
     # (Note: sideband is incorrect; just for testing purposes)
     fh.polarization = np.array(['L', 'R'])
     pt = Power(fh)
     assert np.all(pt.polarization == np.array(['LL', 'RR', 'LR', 'RL']))
Пример #3
0
 def test_wrong_polarization_data(self):
     with dada.open(SAMPLE_DADA) as fh:
         with pytest.raises(ValueError):  # Only one.
             Power(fh, polarization=['L'])
         with pytest.raises(
                 ValueError):  # Duplication (same error as above)
             Power(fh, polarization=['L', 'L'])
         with pytest.raises(ValueError):  # Wrong axis.
             Power(fh, polarization=[['L'], ['R']])
Пример #4
0
 def test_polarization_propagation(self):
     fh = dada.open(SAMPLE_DADA)
     # Add polarization information by hand.
     fh.polarization = np.array(['L', 'R'])
     pt = Power(fh)
     assert np.all(pt.polarization == np.array(['LL', 'RR', 'LR', 'RL']))
     # Swap order.
     fh.polarization = np.array(['R', 'L'])
     pt = Power(fh)
     assert np.all(pt.polarization == np.array(['RR', 'LL', 'RL', 'LR']))
     pt.close()
Пример #5
0
    def test_wrong_polarization(self):
        fh = dada.open(SAMPLE_DADA)
        with pytest.raises(ValueError):
            Power(fh, polarization=['L'])
        with pytest.raises(ValueError):
            Power(fh, polarization=[['L'], ['R']])
        with pytest.raises(ValueError):
            Power(fh, polarization=[['L'], ['L']])

        fh = vdif.open(SAMPLE_VDIF)
        with pytest.raises(ValueError):
            Power(fh)
Пример #6
0
    def test_power(self):
        # Load baseband file and get reference intensities.
        fh = dada.open(SAMPLE_DADA)
        ref_data = fh.read()
        r0, i0, r1, i1 = ref_data.view('f4').T
        ref_data = np.stack((r0 * r0 + i0 * i0,
                             r1 * r1 + i1 * i1,
                             r0 * r1 + i0 * i1,
                             i0 * r1 - r0 * i1), axis=1)

        pt = Power(fh, polarization=['L', 'R'])
        assert np.all(pt.polarization == np.array(['LL', 'RR', 'LR', 'RL']))

        # Square everything.
        data1 = pt.read()
        assert (pt.time - fh.start_time -
                fh.shape[0] / fh.sample_rate) < 1*u.ns
        assert pt.dtype is ref_data.dtype is data1.dtype
        assert np.allclose(ref_data, data1)
Пример #7
0
    def test_channelize_frequency_complex(self):
        """Test frequency calculation."""

        fh = dada.open(SAMPLE_DADA)
        # Add frequency information by hand for now.
        fh.frequency = fh.header0['FREQ'] * u.MHz
        fh.sideband = np.where(fh.header0.sideband, 1, -1)

        ct = Channelize(fh, self.n)

        ref_frequency = (320. * u.MHz +
                         np.fft.fftfreq(self.n, 1. / fh.sample_rate))
        assert np.all(ct.sideband == fh.sideband)
        assert np.all(ct.frequency == ref_frequency[:, np.newaxis])

        fh.sideband = -fh.sideband
        ct = Channelize(fh, self.n)
        ref_frequency = (320. * u.MHz -
                         np.fft.fftfreq(self.n, 1. / fh.sample_rate))
        assert np.all(ct.sideband == fh.sideband)
        assert np.all(ct.frequency == ref_frequency[:, np.newaxis])
        ct.close()
    def test_convolve(self, convolve_task):
        # Load baseband file and get reference intensities.
        fh = dada.open(SAMPLE_DADA)
        ref_data = fh.read()
        expected = ref_data[:-2] + ref_data[1:-1] + ref_data[2:]

        # Have 16000 - 2 useful samples -> can use 842, but add 2 for response.
        ct = convolve_task(fh, self.response, samples_per_frame=844)
        # Convolve everything.
        data1 = ct.read()
        assert ct.tell() == ct.shape[0] == fh.shape[0] - 2
        assert abs(ct.start_time - fh.start_time -
                   2 / fh.sample_rate) < 1. * u.ns
        assert abs(ct.stop_time - fh.stop_time) < 1. * u.ns
        assert np.allclose(expected, data1, atol=1.e-4)

        # Seeking and selective convolution.
        ct.seek(-3, 2)
        assert ct.tell() == ct.shape[0] - 3
        data2 = ct.read()
        assert data2.shape[0] == 3
        assert np.allclose(expected[-3:], data2, atol=1.e-4)

        ct.close()
Пример #9
0
    def test_square(self):
        # Load baseband file and get reference intensities.
        fh = dada.open(SAMPLE_DADA)
        ref_data = fh.read()
        ref_data = np.real(ref_data * np.conj(ref_data))

        st = Square(fh)

        # Square everything.
        data1 = st.read()
        assert st.tell() == st.shape[0]
        assert (st.time - st.start_time -
                st.shape[0] / st.sample_rate) < 1*u.ns
        assert st.dtype is ref_data.dtype is data1.dtype
        assert np.allclose(ref_data, data1)

        # Seeking and selective squaring.
        st.seek(-3, 2)
        assert st.tell() == st.shape[0] - 3
        data2 = st.read()
        assert data2.shape[0] == 3
        assert np.allclose(ref_data[-3:], data2)

        st.close()
Пример #10
0
 def setup(self):
     self.fh = dada.open(SAMPLE_DADA)
Пример #11
0
 def test_missing_polarization(self):
     fh = dada.open(SAMPLE_DADA)
     with pytest.raises(AttributeError):
         Power(fh)