예제 #1
0
    def pushSRI(self, H):
        """
        Generate an X-Midas header from the StreamSRI if the input_stream file
        does not exist.  If the file already exists, then it does not perform 
        any operation
        
        Input:
            <H>    The StreamSRI object containing the information required to
                   generate the header file
        """
        self.port_lock.acquire()
        try:
            # The header can be created only once as the size changes
            # when data is pushed
            if self.header == None:
                # the file is either type 1000 or 2000
                if H.subsize == 0:
                    data_type = 1000
                else:
                    data_type = 2000

                # scalar
                if H.mode == 0:
                    data_format = 'S'
                # complex
                else:
                    data_format = 'C'

                if self.port_type == BULKIO__POA.dataShort:
                    data_format = data_format + 'I'
                elif self.port_type == BULKIO__POA.dataUshort:
                    data_format = data_format + 'I'
                elif self.port_type == BULKIO__POA.dataFloat:
                    data_format = data_format + 'F'
                elif self.port_type == BULKIO__POA.dataDouble:
                    data_format = data_format + 'D'
                elif self.port_type == BULKIO__POA.dataChar:
                    data_format = data_format + 'B'
                elif self.port_type == BULKIO__POA.dataOctet:
                    data_format = data_format + 'B'
                elif self.port_type == BULKIO__POA.dataUlong:
                    data_format = data_format + 'L'
                elif self.port_type == BULKIO__POA.dataLong:
                    data_format = data_format + 'L'
                # default to double precision data
                else:
                    data_format = data_format + 'D'

                # generate the header and then create the file
                self.header = sri_to_hdr(H, data_type, data_format)
                bluefile.writeheader(self.outFile,
                                     self.header,
                                     keepopen=0,
                                     ext_header_type=list)
        finally:
            self.port_lock.release()
    def pushSRI(self, H):
        """
        Generate an X-Midas header from the StreamSRI if the input_stream file
        does not exist.  If the file already exists, then it does not perform 
        any operation
        
        Input:
            <H>    The StreamSRI object containing the information required to
                   generate the header file
        """
        self.port_lock.acquire()
        try:
            # The header can be created only once as the size changes
            # when data is pushed
            if self.header == None:
                # the file is either type 1000 or 2000
                if H.subsize == 0:
                    data_type = 1000
                else:
                    data_type = 2000

                # scalar 
                if H.mode == 0:
                    data_format = 'S'
                # complex 
                else:
                    data_format = 'C'

                if(str(self.port_type) == "bulkio.bulkioInterfaces.BULKIO__POA.dataShort"):
                    data_format = data_format + 'I'
                elif(str(self.port_type) == "bulkio.bulkioInterfaces.BULKIO__POA.dataUshort"):
                    data_format = data_format + 'I'
                elif(str(self.port_type) == "bulkio.bulkioInterfaces.BULKIO__POA.dataFloat"):
                    data_format = data_format + 'F'
                elif(str(self.port_type) == "bulkio.bulkioInterfaces.BULKIO__POA.dataDouble"):
                    data_format = data_format + 'D'
                elif(str(self.port_type) == "bulkio.bulkioInterfaces.BULKIO__POA.dataChar"):
                    data_format = data_format + 'B'
                elif(str(self.port_type) == "bulkio.bulkioInterfaces.BULKIO__POA.dataUlong"):
                    data_format = data_format + 'L'
                elif(str(self.port_type) == "bulkio.bulkioInterfaces.BULKIO__POA.dataLong"):
                    data_format = data_format + 'L'
                # default to double precision data
                else:
                    data_format = data_format + 'D'
                
                # generate the header and then create the file
                self.header = sri_to_hdr(H, data_type, data_format)
                bluefile.writeheader(self.outFile, self.header, 
                                     keepopen=0, ext_header_type=list)
        finally:
            self.port_lock.release()
예제 #3
0
    def pushPacket(self, data, ts, EOS, stream_id):
        """
        Pushes data to the file.
        
        Input:
            <data>        The actual data to write to the file
            <ts>          The timestamp
            <EOS>         Flag indicating if this is the End Of the Stream
            <stream_id>   The name of the file
        """
        self.port_lock.acquire()
        if EOS:
            self.gotEOS = True
            self.eos_cond.notifyAll()
        else:
            self.gotEOS = False
        try:
            # If the header doesn't already have meaningful timecode, update it
            # with the packet time and write it out to disk
            if self._firstPacket and self.header and ts.tcstatus == BULKIO.TCS_VALID:
                self.header['timecode'] = unix_to_j1950(ts.twsec + ts.tfsec)
                bluefile.writeheader(self.outFile, self.header)
            self._firstPacket = False

            if self.header and self.header['format'][1] == 'B':
                # convert back from string to array of 8-bit integers
                try:
                    data = numpy.fromstring(data, numpy.int8)
                except TypeError:
                    data = numpy.array(data, numpy.int8)

            # If complex data, need to convert data back from array of scalar values
            # to some form of complex values
            if self.header and self.header['format'][0] == 'C':
                # float and double are handled by numpy
                # each array element is a single complex value
                if self.header['format'][1] in ('F', 'D'):
                    data = bulkio_helpers.bulkioComplexToPythonComplexList(
                        data)
                # other data types are not handled by numpy
                # each element is two value array representing real and imaginary values
                # if data is also framed, wait to reshape everything at once
                elif self.header['subsize'] == 0:
                    # Need to rehape the data into complex value pairs
                    data = numpy.reshape(data, (-1, 2))

            # If framed data, need to frame the data according to subsize
            if self.header and self.header['subsize'] != 0:
                # If scalar or single complex values, just frame it
                if self.header['format'][0] != 'C' or self.header['format'][
                        1] in ('F', 'D'):
                    data = numpy.reshape(data,
                                         (-1, int(self.header['subsize'])))
                # otherwise, frame and pair as complex values
                else:
                    data = numpy.reshape(data,
                                         (-1, int(self.header['subsize']), 2))

            bluefile.write(self.outFile, hdr=None, data=data, append=1)
        finally:
            self.port_lock.release()