示例#1
0
    def test_function_tasks(self, task, sample_factor):
        """Test setting a channel to zero."""

        # Load baseband file and get reference intensities.
        ref_data = task(self.fh.read())

        ft = Task(self.fh,
                  task,
                  sample_rate=self.fh.sample_rate * sample_factor)

        assert ft.shape[0] == self.fh.shape[0] * sample_factor
        # Apply to everything.
        data1 = ft.read()
        assert ft.tell() == ft.shape[0]
        assert abs(ft.time - ft.start_time -
                   ft.shape[0] / ft.sample_rate) < 1 * u.ns
        assert ft.dtype is ref_data.dtype is data1.dtype
        assert np.allclose(ref_data, data1)

        # Seeking and selective zeroing.
        ft.seek(-3, 2)
        assert ft.tell() == ft.shape[0] - 3
        data2 = ft.read()
        assert data2.shape[0] == 3
        assert np.allclose(ref_data[-3:], data2)
        ft.close()
        assert ft.closed
        with pytest.raises(ValueError):
            ft.read(1)
示例#2
0
 def test_modulator_unbinned(self):
     nh = self.nh
     mt = Task(nh, self.block_profile, samples_per_frame=1)
     nh.seek(0)
     n1 = nh.read(10)
     m1 = mt.read(10)
     assert np.all(m1 == n1 * 0.125)
     nh.seek(0.5 * u.s)
     mt.seek(0.5 * u.s)
     n2 = nh.read(10)
     m2 = mt.read(10)
     assert np.all(m2 == n2)
     nh.seek(0)
     mt.seek(0)
     n = nh.read()
     m = mt.read()
     assert n.shape == m.shape == self.shape
     assert np.all(m[:450] == 0.125 * n[:450])
     assert np.all(m[450:550] == n[450:550])
     assert np.all(m[550:] == 0.125 * n[550:])