Esempio n. 1
0
    def test_open_stream(self, tmpdir):
        # Check that we can use the baseband open command for HDF5 format.
        filename = str(tmpdir.join('copy.hdf5'))
        stream = self.fh
        # Writing always requires a format argument.
        with baseband.open(filename, 'w', format='hdf5',
                           template=stream) as f5w:
            assert isinstance(f5w, hdf5.base.HDF5StreamWriter)
            f5w.write(self.data)

        # Reading with a format argument should just work.
        with baseband.open(filename, 'r', format='hdf5') as f5r:
            assert isinstance(f5r, hdf5.base.HDF5StreamReader)
            self.check(stream, f5r)
            data = f5r.read()
            assert_array_equal(data, self.data)
            # Check that basic info works, since next step relies on it.
            assert f5r.info.format == 'hdf5'

        # Without a format argument we are relying on our info.
        with baseband.open(filename, 'r') as f5r:
            assert isinstance(f5r, hdf5.base.HDF5StreamReader)
            self.check(stream, f5r)
            data = f5r.read()
            assert_array_equal(data, self.data)
Esempio n. 2
0
 def setup(self):
     self.fh = baseband.open(baseband.data.SAMPLE_VDIF)
     self.data = self.fh.read()
     self.fh.seek(0)
     frequency = 311.25 * u.MHz + (np.arange(8.) // 2) * 16. * u.MHz
     sideband = np.tile([-1, +1], 4)
     self.wrapped = SetAttribute(self.fh,
                                 frequency=frequency,
                                 sideband=sideband)
Esempio n. 3
0
def waterfall_by_sec(filename,
                     seconds,
                     time_step=0.002 * u.s,
                     Output_name="output",
                     start_time=None):
    """Produce a waterfall given a from the baseband data
   === Parameters ===
   filename: Name of baseband data -> Code modelled after vdif format, hopefully should work fo
   mark5b too
   seconds: The number of seconds produced in the waterfall
   time_step: The length of each time bin in the waterfall: Defaults to 2 microseconds
   Output_name: The name of the Output waterfall: Defaults to output.npy
   Start: The start time for the waterfall. Defaults to the start of the scan
   """
    fh = baseband.open(filename)
    # Determine number of seconds in each time step
    dt = 0
    fh.seek(0)
    st = fh.time
    fn = fh.time
    while (time_step > fn - st):
        fh.read(512)
        fn = fh.time
        dt += 512
    print("Length of each time bin: ", fn - st)
    print("Number of bins in each time bin: ", dt)
    fh.seek(0)
    # Set start time:
    if start_time is None:
        start_time = fh.time
    fh.seek(start_time)
    print("Start time of waterfall; ", start_time)
    # Make one time bin at a time
    I = []
    while (seconds > fh.time - start_time):
        data = fh.read(dt)
        data = data.reshape(
            -1, 512
        )  # Not entirely confident about this line: Rebins nearby values
        ft = np.fft.rfft(data, axis=-1)
        ft = np.fft.fftshift(ft)
        spec = ft.sum(axis=0)
        I.append(spec)
    return np.savez(Output_name, I=np.array(I))