def test_complex_stream(self, tmpdir): filename = str(tmpdir.join('copy.hdf5')) with baseband.vdif.open(baseband.data.SAMPLE_AROCHIME_VDIF, 'rs', sample_rate=800 * u.MHz / 2048) as fh: wrapped = SetAttribute(fh) data = wrapped.read() wrapped.seek(0) with hdf5.open(filename, 'w', template=wrapped) as f5w: assert f5w.complex_data assert f5w.header0.encoded_dtype == 'c8' wrapped.read(out=f5w) with hdf5.open(filename, 'r') as f5r: self.check(wrapped, f5r, ('sample_shape', 'dtype', 'sample_rate', 'time')) assert f5r.header0.encoded_dtype == 'c8' recovered = f5r.read() # Cannot recover exactly, given scaling, but should be within # tolerance for float16. assert_array_equal(recovered, data)
def test_complex_stream_as_c4(self, tmpdir): filename = str(tmpdir.join('copy.hdf5')) with baseband.vdif.open(baseband.data.SAMPLE_AROCHIME_VDIF, 'rs', sample_rate=800 * u.MHz / 2048) as fh: wrapped = SetAttribute(fh) data = wrapped.read() wrapped.seek(0) with hdf5.open(filename, 'w', template=wrapped, encoded_dtype='c4') as f5w: assert f5w.complex_data assert f5w.header0.encoded_dtype == hdf5.payload.DTYPE_C4 wrapped.read(out=f5w) with hdf5.open(filename, 'r') as f5r: self.check(wrapped, f5r, ('sample_shape', 'dtype', 'sample_rate', 'time')) assert f5r.header0.encoded_dtype == hdf5.payload.DTYPE_C4 recovered = f5r.read() # Cannot recover exactly, given scaling, but should be within # tolerance for float16. assert np.allclose(recovered, data, atol=0, rtol=np.finfo('f2').eps)
def test_set_start_time(self): expected = self.fh.read() offset = 0.1 * u.s sa = SetAttribute(self.fh, start_time=self.fh.start_time + offset) assert sa.start_time == self.fh.start_time + offset for attr in ('sample_rate', 'samples_per_frame', 'shape', 'dtype'): assert getattr(sa, attr) == getattr(self.fh, attr) data = sa.read() assert np.all(data == expected) sa.seek(10) data2 = sa.read(10) assert np.all(data2 == expected[10:20]) sa.seek(10 / sa.sample_rate) data3 = sa.read(10) assert np.all(data3 == expected[10:20]) sa.seek(sa.start_time + 10 / self.fh.sample_rate) data4 = sa.read(10) assert np.all(data4 == expected[10:20]) for attr in ('frequency', 'sideband', 'polarization'): with pytest.raises(AttributeError): getattr(sa, attr) sa.close()