Esempio n. 1
0
 def major_data(self, inval):
     """
     read in and add major data to the class
     """
     inval = FIREdata.hex2int(inval)
     dt = FIREdata.dat2time(inval[0:8])
     d1 = FIREdata.dat2time(inval[ majorTimelen:])
     self.dat['Epoch'] = dm.dmarray.append(self.dat['Epoch'], dt)
     self.dat['Time'] = dm.dmarray.append(self.dat['Time'], d1)
Esempio n. 2
0
 def majorStamps(self):
     """
     return the major time stamps
     """
     major = []
     for v in self:
         if v.pktnum == '01': # this is a major stamp
             major.append(v)
     stamps = []
     for v in major:
         stamps.append(FIREdata.dat2time(FIREdata.hex2int(v.data[:8])))
     return stamps
Esempio n. 3
0
    def __init__(self, inpage, h):
        len1 = datalen+majorTimelen
        len2 = datalen+minorTimelen
        dat = FIREdata.hex2int(inpage)

        if len(inpage) == len1: # major
            try:
                self.t0 = FIREdata.dat2time(dat[0:8])
                self.major_data(dat)
            except ValueError:
                return
            print("\tData at time {0} decoded".format(self[-1][0].isoformat()))
        elif len(inpage) == len2: # minor
            try:
                self.minor_data(dat, h)
            except ValueError:
                return
Esempio n. 4
0
 def __init__(self, inpage):
     len1 = datalen+majorTimelen
     len2 = datalen+minorTimelen
     dat = FIREdata.hex2int(inpage)
     try:
         self.t0 = FIREdata.dat2time(dat[0:8])
     except ValueError:
         return
     self.major_data(dat[0:datalen+majorTimelen])
     start = datalen+majorTimelen
     # the index of the start of each FIRE data
     for ii in range(start, len(dat), datalen+minorTimelen):
         stop = ii+datalen+majorTimelen
         try:
             self.minor_data(dat[ii:stop])
         except IndexError: # malformed data for some reason, skip it
             print("Skipping malformed context: {0}".format(dat[ii:stop]))
     # sort the data
     self = sorted(self, key = lambda x: x[0])
Esempio n. 5
0
    def read(self, filename):
        # need to have pages and packet information
        packets = packet.BIRDpackets(filename)

        """
        data times is at most one page
        """

        previous_packet = None # holds the last packet
        dataBuffer = [] # this holds the data form a packet as measurement may roll onto
                        #   the next packet
        firstPacket = False
        for packet_ in packets:
            """
            options in here:
            1) new page starting with packet 01
            2) new page with missing packet 01
            3) current page with next packet
            4) current page with missing packet
            5) last packet of page at 13
            6) last packet of a page with missing 13
            """
            if packet_.pktnum == '01':
                firstPacket = True

            ### option 2 ###
            ### option 1 ###
            if previous_packet is None: # new page starting
                dataBuffer = [] # clear the dataBuffer as we are starting a new page
                previous_packet = packet_ # hang on to the last packet
                print packet_
                # this is a decodable page, start now
                dataBuffer.extend(packet_.data) # grab the data out
                # since p.pktnum == 01 this is a major time stamp, decode it.
            else:
                while len(dataBuffer) > 0:
                    if FIREdata.validDate(FIREdata.hex2int(dataBuffer[:majorTimelen])):
                        pass
                    else:
                        dataBuffer.pop(0)
            ### option 3 ###
            ### option 4 ###

            """
            regardless of the packet if there is more data in the buffer we should
            decode it and add it to the arrays
            """
            while len(dataBuffer) >= minorLen:
                tmp = [dataBuffer.pop(0) for v in range(majorLen)]
                self.major_data(tmp)

        # go through and remove duplicate times and data
        print("Looking for duplicate measurements")

        arr, dt_ind, return_inverse = np.unique(self.dat['Epoch'], return_index=True, return_inverse=True) # this is unique an sort
        print("Found {0} duplicates of {1}".format(len(return_inverse)-len(dt_ind), len(return_inverse)))

        self.dat['Epoch'] = arr
        self.dat['Time'] = self.dat['Time'][dt_ind]
        # populate Duration and Mode
        self.dat['Mode'] = dm.dmarray.append(self.dat['Mode'], np.zeros(len(self.dat['Epoch']), dtype=int))
        if firstPacket:
            self.dat['Mode'][::2] = 1
        dur = [FIREdata.total_seconds(v2 - v1) for v1, v2 in itertools.izip(self.dat['Epoch'], self.dat['Time'])]
        self.dat['Duration'] = dm.dmarray.append(self.dat['Duration'], dur)


        return self