def test_keywords_retrieval_long(self):
        filename = 'bf-kw-test.out'
        self._tempfiles.append(filename)
        bf = bluefile_helpers.BlueFileWriter(filename, 'dataLong')
        kdata = 2147483648L
        kws = props_from_dict({'TEST_KW': kdata})
        sid = 'streamID'
        srate = 5e6
        sri = bulkio.sri.create('test_stream', srate)
        sri.mode = False
        sri.blocking = False
        sri.keywords = kws
        bf.start()
        bf.pushSRI(sri)
        tmpData = range(0, 1024)
        bf.pushPacket(tmpData, bulkio.timestamp.now(), True, sid)

        # Read back the timecode from the output file
        hdr, data = bluefile.read(filename, ext_header_type=list)
        sri = bluefile_helpers.hdr_to_sri(hdr, sid)

        srid = ossie.properties.props_to_dict(sri.keywords)

        self.assertEqual(kdata, srid['TEST_KW'])
        self.assertEqual(type(kdata), type(srid['TEST_KW']))
    def _test_FileSink(self, format):
        filename = self._tempfileName('sink_%s' % format)

        complexData = format.startswith('C')
        typecode = format[1]
        dataFormat, dataType = self.TYPEMAP[typecode]
        indata = [dataType(x) for x in xrange(16)]

        source = sb.DataSource(dataFormat=dataFormat)
        sink = sb.FileSink(filename, midasFile=True)
        source.connect(sink)
        sb.start()
        source.push(indata, complexData=complexData, EOS=True)
        sink.waitForEOS()

        hdr, outdata = bluefile.read(filename)
        self.assertEqual(hdr['format'], format)
        if complexData:
            if dataFormat in ('double', 'float'):
                outdata = list(self._flatten(outdata))
            else:
                outdata = outdata.flatten()
        self.assertTrue(numpy.array_equal(indata, outdata), msg="Format '%s' %s != %s" % (format, indata, outdata))
    def _test_FileSinkOctet(self, format):
        filename = self._tempfileName('sink_octet_' + format.lower())

        source = sb.DataSource(dataFormat='octet')
        sink = sb.FileSink(filename, midasFile=True)
        source.connect(sink)
        sb.start()

        # Push a 256-element ramp (the maximum range of octet)
        indata = range(256)
        isComplex = bool(format[0] == 'C')
        source.push(indata, complexData=isComplex, EOS=True)
        sink.waitForEOS()

        # Check the BLUE file format matches
        hdr, data = bluefile.read(filename)
        self.assertEqual(format, hdr['format'])

        # Have to "cast" the data to unsigned 8-bit, since 'B' is a signed type
        # (as are all BLUE formats), and flattening the array re-interleaves
        # complex data
        outdata = data.view(numpy.uint8).reshape(-1)
        self.assertTrue(numpy.array_equal(indata, outdata),
                        msg="Format '%s' %s != %s" % (format, indata, outdata))
    def _test_FileSinkType2000(self, format, subsize):
        filename = self._tempfileName('sink_2000_%s' % format)

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

        sink = sb.FileSink(filename, midasFile=True)
        sb.start()

        # Manually create our own SRI, because DataSource doesn't support
        # setting the Y-axis fields
        sri = bulkio.sri.create('test_stream')
        if complexData:
            sri.mode = 1
        else:
            sri.mode = 0
        sri.subsize = subsize
        sri.ystart = subsize / -2.0
        sri.ydelta = 1.0
        sri.yunits = 3

        # Generate test data; unlike the type 1000 tests, we have to generate
        # input data compatible with CORBA because we're bypassing DataSource
        frames = 4
        samples = subsize * frames
        if complexData:
            samples *= 2
        if dataFormat == 'char':
            indata = numpy.arange(samples, dtype=numpy.int8)
            packet = indata.tostring()
        else:
            indata = [dataType(x) for x in xrange(samples)]
            packet = indata

        # Push the SRI and data directly to the sink's port
        port = sink.getPort(dataFormat + 'In')
        port.pushSRI(sri)
        port.pushPacket(packet, bulkio.timestamp.now(), True, sri.streamID)

        sink.waitForEOS()

        hdr, outdata = bluefile.read(filename)
        self.assertEqual(hdr['format'], format)
        self.assertEqual(hdr['subsize'], subsize)
        self.assertEqual(hdr['ystart'], sri.ystart)
        self.assertEqual(hdr['ydelta'], sri.ydelta)
        self.assertEqual(hdr['yunits'], sri.yunits)
        self.assertEqual(len(outdata), frames)

        if complexData:
            if dataFormat == 'float':
                indata = numpy.array(indata,
                                     dtype=numpy.float32).view(numpy.complex64)
                indata = numpy.reshape(indata, (-1, subsize))
            elif dataFormat == 'double':
                indata = numpy.array(indata, dtype=numpy.float64).view(
                    numpy.complex128)
                indata = numpy.reshape(indata, (-1, subsize))
            else:
                indata = numpy.reshape(indata, (-1, subsize, 2))
        else:
            indata = numpy.reshape(indata, (-1, subsize))

        self.assertTrue(numpy.array_equal(indata, outdata),
                        msg="Format '%s' %s != %s" % (format, indata, outdata))
Beispiel #5
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