Exemplo n.º 1
0
    def _test_FileSource(self, format):
        filename = self._tempfileName('source_%s' % format)

        complexData = format.startswith('C')
        typecode = format[1]
        dataFormat, dataType = self.TYPEMAP[typecode]

        indata = [dataType(x) for x in xrange(16)]
        if complexData:
            if dataFormat in ('float', 'double'):
                indata = [complex(x) for x in indata]
            else:
                indata = numpy.reshape(indata, (8,2))
        hdr = bluefile.header(1000, format)
        bluefile.write(filename, hdr, indata)

        source = sb.FileSource(filename, midasFile=True, dataFormat=dataFormat)
        sink = sb.DataSink()
        source.connect(sink)
        sb.start()
        outdata = sink.getData(eos_block=True)
        if complexData:
            self.assertEqual(sink.sri().mode, 1)
            if dataFormat in ('float', 'double'):
                outdata = bulkio_helpers.bulkioComplexToPythonComplexList(outdata)
            else:
                outdata = numpy.reshape(outdata, (len(outdata)/2,2))
        else:
            self.assertEqual(sink.sri().mode, 0)
        self.assertTrue(numpy.array_equal(indata, outdata), msg='%s != %s' % (indata, outdata))
Exemplo n.º 2
0
    def test_FileSourceTimecodeType2000(self):
        # Create a test file with frequency on the X-axis and time on the
        # Y-axis (as one might see from an FFT)
        subsize = 256
        xdelta = 1.0 / subsize
        ydelta = 0.25
        hdr = bluefile.header(2000, 'SF', subsize=subsize)
        hdr['xstart'] = 0
        hdr['xdelta'] = xdelta
        hdr['xunits'] = 3  # frequency
        hdr['ydelta'] = ydelta
        hdr['yunits'] = 1  # time
        data = numpy.arange(1024, dtype=numpy.float32).reshape((-1, subsize))

        self._check_FileSourceTimecode(hdr, data, subsize, ydelta)
Exemplo n.º 3
0
    def _test_FileSourceType2000(self, format, subsize):
        filename = self._tempfileName('source_2000_%s' % format)

        complexData = format.startswith('C')
        typecode = format[1]
        dataFormat, dataType = self.TYPEMAP[typecode]

        frames = 4
        indata = [
            self._generateSourceData(format, subsize) for x in xrange(frames)
        ]
        hdr = bluefile.header(2000, format, subsize=subsize)
        bluefile.write(filename, hdr, indata)

        source = sb.FileSource(filename, midasFile=True, dataFormat=dataFormat)
        sink = sb.DataSink()
        source.connect(sink)
        sb.start()
        outdata = sink.getData(eos_block=True)
        if complexData:
            if format == 'CF':
                outdata = numpy.array(outdata, dtype=numpy.float32).view(
                    numpy.complex64)
                outdata = numpy.reshape(outdata, (-1, subsize))
            elif format == 'CD':
                outdata = numpy.array(outdata, dtype=numpy.float64).view(
                    numpy.complex128)
                outdata = numpy.reshape(outdata, (-1, subsize))
            else:
                outdata = numpy.reshape(outdata, (-1, subsize, 2))
            self.assertEqual(sink.sri().mode, 1)
        else:
            self.assertEqual(sink.sri().mode, 0)

        self.assertTrue(numpy.array_equal(indata, outdata),
                        msg="Format '%s' %s != %s" % (format, indata, outdata))
Exemplo n.º 4
0
    def _createtempfile(self, name):
        #Populate hdr (header) and data
        filename = 'test_bluefile_%s.tmp' % name
        self._tempfiles.append(filename)

        #filename = self._tempfileName(name)
        data = numpy.arange(1024)
        hdr = bluefile.header(1000, 'SI')
        bluefile.write(filename, hdr, data)

        #populate ext (extended header)
        mkdata = 3
        mykw = props_from_dict({'mykeyword': mkdata})
        bf = bluefile_helpers.BlueFileWriter(filename, 'dataLong')
        srate = 5e6
        sri = bulkio.sri.create('test_stream', srate)
        sri.mode = False
        sri.blocking = False
        sri.keywords = mykw
        bf.start()
        bf.pushSRI(sri)
        tmpData = range(0, 1024)
        srid = ossie.properties.props_to_dict(sri.keywords)
        return filename