Exemplo n.º 1
0
    def _check_FileSourceTimecode(self, hdr, data, framesize, delta):
        # Put a known timecode value into the header and write out the data
        start = bulkio.timestamp.now()
        hdr['timecode'] = bluefile_helpers.unix_to_j1950(start.twsec +
                                                         start.tfsec)
        filename = self._tempfileName('source_timecode_%d_%s' %
                                      (hdr['type'], hdr['format']))
        bluefile.write(filename, hdr, data)

        # Bytes per push is chosen specifically to require multiple packets
        source = sb.FileSource(filename,
                               bytesPerPush=2048,
                               midasFile=True,
                               dataFormat='float')
        sink = sb.DataSink()
        source.connect(sink)
        sb.start()

        # There should have been at least two push packets (plus one more for
        # the end-of-stream, but that's not strictly required)
        outdata, tstamps = sink.getData(eos_block=True, tstamps=True)
        self.assertTrue(len(tstamps) >= 2)

        # Check that the first timestamp (nearly) matches the timestamp created
        # above
        offset, ts = tstamps[0]
        self.assertAlmostEqual(start - ts, 0.0, 5)

        # Check that the synthesized timestamps match our expectations
        for offset, tnext in tstamps[1:]:
            # Offset is in samples, not frames (and/or complex pairs)
            offset /= float(framesize)
            self.assertAlmostEqual(tnext - ts, offset * delta, 5)
Exemplo n.º 2
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 = self._generateSourceData(format, 16)
        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.º 3
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.º 4
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.º 5
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
Exemplo n.º 6
0
    def testBlueShortPortSwapped(self):
        #######################################################################
        # Test Bluefile Swapped SHORT Functionality
        print "\n**TESTING BLUEFILE Swapped + SHORT PORT"

        #Define test files
        dataFileIn = './bluefile.in'
        dataFileInSwap = './bluefile.in.swap'

        #Create Test Data File if it doesn't exist
        if not os.path.isfile(dataFileIn):
            tmpSink = bluefile_helpers.BlueFileWriter(dataFileIn,
                                                      BULKIO__POA.dataShort)
            tmpSink.start()
            tmpSri = createSri('bluefileShortSwapped', 5000)
            #kwVal = 1234
            #kwSwap = swap([kwVal], 'long')[0]
            #tmpSri.keywords = props_from_dict({'TEST_KW':kwSwap})
            tmpSri.keywords = props_from_dict({'TEST_KW': 1234})
            tmpSink.pushSRI(tmpSri)
            tmpTs = createTs()
            #tmpSink.pushPacket(swap(range(1024),'short'), tmpTs, True, 'bluefileShortSwapped')
            tmpSink.pushPacket(range(1024), tmpTs, True,
                               'bluefileShortSwapped')

        #Read in Data from Test File, modify header, and rewrite
        hdr, d = bluefile.read(dataFileIn, dict)
        hdr['file_name'] = dataFileInSwap
        hdr['head_rep'] = 'IEEE'
        hdr['data_rep'] = 'IEEE'
        bluefile.write(dataFileInSwap, hdr, d)

        #Read in Data from Swapped Test File
        hdr, d = bluefile.read(dataFileInSwap, dict)
        data = list(d)
        keywords = hdr['ext_header']

        #Create Components and Connections
        comp = sb.launch('../FileReader.spd.xml')
        comp.source_uri = dataFileInSwap
        comp.file_format = 'BLUEFILE'

        sink = sb.DataSink()
        comp.connect(sink, usesPortName='dataShort_out')

        #Start Components & Push Data
        sb.start()
        comp.playback_state = 'PLAY'
        time.sleep(2)
        readData = sink.getData()
        readKeywords = props_to_dict(sink.sri().keywords)
        sb.stop()

        #Check that the input and output files are the same
        try:
            self.assertEqual(data, readData)
        except self.failureException as e:
            comp.releaseObject()
            sink.releaseObject()
            os.remove(dataFileIn)
            os.remove(dataFileInSwap)
            raise e

        #Check that the keywords are the same
        try:
            self.assertEqual(keywords, readKeywords)
        except self.failureException as e:
            comp.releaseObject()
            sink.releaseObject()
            os.remove(dataFileIn)
            os.remove(dataFileInSwap)
            raise e

        #Release the components and remove the generated files
        comp.releaseObject()
        sink.releaseObject()
        os.remove(dataFileIn)
        os.remove(dataFileInSwap)

        print "........ PASSED\n"
        return