Ejemplo n.º 1
0
    def decode_ensemble(self, ensStart):
        """
        Decode the raw ensemble data.  This will check the checksum and verify it is correct,
        then decode each datasets.  Then remove the data from the buffer.
        :param ensStart: Stare of the ensemble in the buffer.
        """

        # Check Ensemble number
        ensNum = struct.unpack("I", self.buffer[ensStart + 16:ensStart + 20])
        #logger.debug(print(ensNum[0]))
        #print(self.ones_complement(ensNumInv[0]))

        # Check ensemble size
        payloadSize = struct.unpack("I",
                                    self.buffer[ensStart + 24:ensStart + 28])
        #print(payloadSize[0])
        #payloadSizeInv = struct.unpack("I", self.buffer[ensStart+28:ensStart+32])
        #print(self.ones_complement(payloadSizeInv[0]))

        # Ensure the entire ensemble is in the buffer
        if len(self.buffer) >= ensStart + Ensemble(
        ).HeaderSize + payloadSize[0] + Ensemble().ChecksumSize:
            # Check checksum
            checksumLoc = ensStart + Ensemble().HeaderSize + payloadSize[0]
            checksum = struct.unpack(
                "I",
                self.buffer[checksumLoc:checksumLoc + Ensemble().ChecksumSize])

            # Calculate Checksum
            # Use only the payload for the checksum
            ens = self.buffer[ensStart + Ensemble().HeaderSize:ensStart +
                              Ensemble().HeaderSize + payloadSize[0]]
            calcChecksum = CRCCCITT().calculate(input_data=bytes(ens))
            #print("Calc Checksum: ", calcChecksum)
            #print("Checksum: ", checksum[0])
            #print("Checksum good: ", calcChecksum == checksum[0])

            if checksum[0] == calcChecksum:
                logger.debug(ensNum[0])
                try:
                    # Decode data
                    ensemble = self.decode_data_sets(
                        self.buffer[ensStart:ensStart + Ensemble().HeaderSize +
                                    payloadSize[0]])

                    # ************************
                    self.process_ensemble(ensemble)
                except Exception as e:
                    logger.error("Error decoding ensemble. ", e)

            # Remove ensemble from buffer
            ensEnd = ensStart + Ensemble(
            ).HeaderSize + payloadSize[0] + Ensemble().ChecksumSize
            del self.buffer[0:ensEnd]
Ejemplo n.º 2
0
    def decode(self, data):
        """
        Take the data bytearray.  Decode the data to populate
        the velocities.
        :param data: Bytearray for the dataset.
        """
        packet_pointer = Ensemble.GetBaseDataSize(self.name_len)

        for beam in range(self.element_multiplier):
            for bin_num in range(self.num_elements):
                self.GoodEarth[bin_num][beam] = Ensemble.GetInt32(
                    packet_pointer,
                    Ensemble().BytesInInt32, data)
                packet_pointer += Ensemble().BytesInInt32

        logger.debug(self.GoodEarth)
Ejemplo n.º 3
0
    def on_ens_json_data(self, data):
        """
        Called when JSON Ensemble data is received from WAMP.
        :param data: JSON object containing serial data.
        :return:
        """
        json_data = json.loads(data)  # convert to JSON
        self.amp = json_data['Amplitude']
        #print(self.amp['Amplitude'])
        ampBin1 = json_data['Amplitude']['Amplitude']
        #print(ampBin1[0])
        ampNP = np.array(json_data['Amplitude']['Amplitude'])
        #print(ampNP)
        # Set up data
        #x = np.zeros(4,30)

        bins = []
        ampB0 = []
        ampB1 = []
        velB2 = []
        velB3 = []
        for bin in range(json_data['EnsembleData']["NumBins"]):
            bins.append(bin)
            if Ensemble().is_float_close(
                    json_data['Amplitude']['Amplitude'][bin][0],
                    Ensemble().BadVelocity):
                ampB0.append(json_data['Amplitude']['Amplitude'][bin][0])
            else:
                ampB0.append(0.0)
            if Ensemble().is_float_close(
                    json_data['Amplitude']['Amplitude'][bin][1],
                    Ensemble().BadVelocity):
                ampB1.append(json_data['Amplitude']['Amplitude'][bin][1])
            else:
                ampB1.append(0.0)
            velB2.append(json_data['Amplitude']['Amplitude'][bin][2])
            velB3.append(json_data['Amplitude']['Amplitude'][bin][3])

        new_data = dict(AmpB0=ampB0, AmpB1=ampB1, bins=bins)
        self.source.stream(new_data, 100)
        print(ampB0)
Ejemplo n.º 4
0
    def find_ensemble(self):
        """
        Find the start of an ensemble.  Then find the end of the ensemble.
        Then remove the ensemble from the buffer and process the raw data.
        :return:
        """

        # Look for first 16 bytes of header
        delimiter = b'\x80' * 16
        ens_start = self.buffer.find(delimiter)

        if ens_start >= 0 and len(
                self.buffer) > Ensemble().HeaderSize + ens_start:
            # Decode the Ensemble
            self.decode_ensemble(ens_start)
Ejemplo n.º 5
0
    def __init__(self, num_elements, element_multiplier):
        self.ds_type = 10
        self.num_elements = num_elements
        self.element_multiplier = element_multiplier
        self.image = 0
        self.name_len = 8
        self.Name = "E000003"
        self.Velocities = []
        # Create enough entries for all the (bins x beams)
        # Initialize with bad values
        for bins in range(num_elements):
            bins = []
            for beams in range(element_multiplier):
                bins.append([Ensemble().BadVelocity])

            self.Velocities.append(bins)
Ejemplo n.º 6
0
    def decode(self, data):
        """
        Take the data bytearray.  Decode the data to populate
        the NMEA data.
        :param data: Bytearray for the dataset.
        """
        packet_pointer = Ensemble.GetBaseDataSize(self.name_len)

        nmea_str = str(data[packet_pointer:], "UTF-8")

        self.nmea_sentences = nmea_str.split()

        for msg in self.nmea_sentences:
            try:
                # Parse the NMEA data
                nmea_msg = pynmea2.parse(msg)

                if isinstance(nmea_msg, pynmea2.types.talker.GGA):
                    self.GPGGA = nmea_msg
                    self.latitude = nmea_msg.latitude
                    self.longitude = nmea_msg.longitude
                    self.datetime = nmea_msg.timestamp
                if isinstance(nmea_msg, pynmea2.types.talker.VTG):
                    self.GPVTG = nmea_msg
                    self.speed_knots = nmea_msg.spd_over_grnd_kts
                if isinstance(nmea_msg, pynmea2.types.talker.RMC):
                    self.GPRMC = nmea_msg
                if isinstance(nmea_msg, pynmea2.types.talker.RMF):
                    self.GPRMF = nmea_msg
                if isinstance(nmea_msg, pynmea2.types.talker.GLL):
                    self.GPGLL = nmea_msg
                if isinstance(nmea_msg, pynmea2.types.talker.GSV):
                    self.GPGSV = nmea_msg
                if isinstance(nmea_msg, pynmea2.types.talker.GSA):
                    self.GPGSA = nmea_msg
                if isinstance(nmea_msg, pynmea2.types.talker.HDT):
                    self.GPHDT = nmea_msg
                    self.heading = nmea_msg.heading
                if isinstance(nmea_msg, pynmea2.types.talker.HDG):
                    self.GPHDG = nmea_msg

            except Exception:
                logger.debug("Error decoding NMEA msg")

        logger.debug(nmea_str)
        logger.debug(self.nmea_sentences)
Ejemplo n.º 7
0
    def __init__(self, num_elements, element_multiplier):
        self.ds_type = 10
        self.num_elements = num_elements
        self.element_multiplier = element_multiplier
        self.image = 0
        self.name_len = 8
        self.Name = "E000004"
        self.Amplitude = []

        #self.EnsembleNumber = ensemble_number
        #self.SerialNumber = serial_number
        #self.DateTime = date_time

        # Create enough entries for all the (bins x beams)
        # Initialize with bad values
        for bins in range(num_elements):
            bins = []
            for beams in range(element_multiplier):
                bins.append([Ensemble().BadVelocity])

            self.Amplitude.append(bins)
Ejemplo n.º 8
0
    def decode_data_sets(self, ens):
        """
        Decode the datasets in the ensemble.
        :param ens: Ensemble data.  Decode the dataset.
        :return: Return the decoded ensemble.
        """
        #print(ens)
        packetPointer = Ensemble().HeaderSize
        type = 0
        numElements = 0
        elementMultiplier = 0
        imag = 0
        nameLen = 0
        name = ""
        dataSetSize = 0

        # Create the ensemble
        ensemble = Ensemble()

        # Add the raw data to the ensemble
        #ensemble.AddRawData(ens)

        # Decode the ensemble datasets
        for x in range(Ensemble().MaxNumDataSets):
            # Check if we are at the end of the payload
            if packetPointer >= len(ens):
                break

            # Get the dataset info
            ds_type = Ensemble.GetInt32(
                packetPointer + (Ensemble.BytesInInt32 * 0),
                Ensemble().BytesInInt32, ens)
            num_elements = Ensemble.GetInt32(
                packetPointer + (Ensemble.BytesInInt32 * 1),
                Ensemble().BytesInInt32, ens)
            element_multiplier = Ensemble.GetInt32(
                packetPointer + (Ensemble.BytesInInt32 * 2),
                Ensemble().BytesInInt32, ens)
            image = Ensemble.GetInt32(
                packetPointer + (Ensemble.BytesInInt32 * 3),
                Ensemble().BytesInInt32, ens)
            name_len = Ensemble.GetInt32(
                packetPointer + (Ensemble.BytesInInt32 * 4),
                Ensemble().BytesInInt32, ens)
            name = str(
                ens[packetPointer + (Ensemble.BytesInInt32 * 5):packetPointer +
                    (Ensemble.BytesInInt32 * 5) + 8], 'UTF-8')

            # Calculate the dataset size
            data_set_size = Ensemble.GetDataSetSize(ds_type, name_len,
                                                    num_elements,
                                                    element_multiplier)

            # Beam Velocity
            if "E000001" in name:
                logger.debug(name)
                bv = BeamVelocity(num_elements, element_multiplier)
                bv.decode(ens[packetPointer:packetPointer + data_set_size])
                ensemble.AddBeamVelocity(bv)

            # Instrument Velocity
            if "E000002" in name:
                logger.debug(name)
                iv = InstrumentVelocity(num_elements, element_multiplier)
                iv.decode(ens[packetPointer:packetPointer + data_set_size])
                ensemble.AddInstrumentVelocity(iv)

            # Earth Velocity
            if "E000003" in name:
                logger.debug(name)
                ev = EarthVelocity(num_elements, element_multiplier)
                ev.decode(ens[packetPointer:packetPointer + data_set_size])
                ensemble.AddEarthVelocity(ev)

            # Amplitude
            if "E000004" in name:
                logger.debug(name)
                amp = Amplitude(num_elements, element_multiplier)
                amp.decode(ens[packetPointer:packetPointer + data_set_size])
                ensemble.AddAmplitude(amp)

            # Correlation
            if "E000005" in name:
                logger.debug(name)
                corr = Correlation(num_elements, element_multiplier)
                corr.decode(ens[packetPointer:packetPointer + data_set_size])
                ensemble.AddCorrelation(corr)

            # Good Beam
            if "E000006" in name:
                logger.debug(name)
                gb = GoodBeam(num_elements, element_multiplier)
                gb.decode(ens[packetPointer:packetPointer + data_set_size])
                ensemble.AddGoodBeam(gb)

            # Good Earth
            if "E000007" in name:
                logger.debug(name)
                ge = GoodEarth(num_elements, element_multiplier)
                ge.decode(ens[packetPointer:packetPointer + data_set_size])
                ensemble.AddGoodEarth(ge)

            # Ensemble Data
            if "E000008" in name:
                logger.debug(name)
                ed = EnsembleData(num_elements, element_multiplier)
                ed.decode(ens[packetPointer:packetPointer + data_set_size])
                ensemble.AddEnsembleData(ed)

            # Ancillary Data
            if "E000009" in name:
                logger.debug(name)
                ad = AncillaryData(num_elements, element_multiplier)
                ad.decode(ens[packetPointer:packetPointer + data_set_size])
                ensemble.AddAncillaryData(ad)

            # Bottom Track
            if "E000010" in name:
                logger.debug(name)
                bt = BottomTrack(num_elements, element_multiplier)
                bt.decode(ens[packetPointer:packetPointer + data_set_size])
                ensemble.AddBottomTrack(bt)

            # NMEA data
            if "E000011" in name:
                logger.debug(name)
                nd = NmeaData(num_elements, element_multiplier)
                nd.decode(ens[packetPointer:packetPointer + data_set_size])
                ensemble.AddNmeaData(nd)

            # System Setup
            if "E000014" in name:
                logger.debug(name)
                ss = SystemSetup(num_elements, element_multiplier)
                ss.decode(ens[packetPointer:packetPointer + data_set_size])
                ensemble.AddSystemSetup(ss)

            # Range Tracking
            if "E000015" in name:
                logger.debug(name)
                rt = RangeTracking(num_elements, element_multiplier)
                rt.decode(ens[packetPointer:packetPointer + data_set_size])
                ensemble.AddRangeTracking(rt)

            # Move to the next dataset
            packetPointer += data_set_size

        return ensemble
Ejemplo n.º 9
0
    def decode(self, data):
        """
        Take the data bytearray.  Decode the data to populate
        the values.
        :param data: Bytearray for the dataset.
        """
        packet_pointer = Ensemble.GetBaseDataSize(self.name_len)

        self.FirstBinRange = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 0,
            Ensemble().BytesInFloat, data)
        self.BinSize = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 1,
            Ensemble().BytesInFloat, data)
        self.FirstPingTime = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 2,
            Ensemble().BytesInFloat, data)
        self.LastPingTime = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 3,
            Ensemble().BytesInFloat, data)
        self.Heading = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 4,
            Ensemble().BytesInFloat, data)
        self.Pitch = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 5,
            Ensemble().BytesInFloat, data)
        self.Roll = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 6,
            Ensemble().BytesInFloat, data)
        self.WaterTemp = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 7,
            Ensemble().BytesInFloat, data)
        self.SystemTemp = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 8,
            Ensemble().BytesInFloat, data)
        self.Salinity = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 9,
            Ensemble().BytesInFloat, data)
        self.Pressure = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 10,
            Ensemble().BytesInFloat, data)
        self.TransducerDepth = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 11,
            Ensemble().BytesInFloat, data)
        self.SpeedOfSound = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 12,
            Ensemble().BytesInFloat, data)

        if self.num_elements > 13:
            self.RawMagFieldStrength = Ensemble.GetFloat(
                packet_pointer + Ensemble().BytesInFloat * 13,
                Ensemble().BytesInFloat, data)
            self.PitchGravityVector = Ensemble.GetFloat(
                packet_pointer + Ensemble().BytesInFloat * 14,
                Ensemble().BytesInFloat, data)
            self.RollGravityVector = Ensemble.GetFloat(
                packet_pointer + Ensemble().BytesInFloat * 15,
                Ensemble().BytesInFloat, data)
            self.VerticalGravityVector = Ensemble.GetFloat(
                packet_pointer + Ensemble().BytesInFloat * 16,
                Ensemble().BytesInFloat, data)

        logger.debug(self.FirstBinRange)
        logger.debug(self.BinSize)
        logger.debug(self.Heading)
        logger.debug(self.Pitch)
        logger.debug(self.Roll)
        logger.debug(self.Salinity)
        logger.debug(self.SpeedOfSound)
Ejemplo n.º 10
0
    def decode(self, data):
        """
        Take the data bytearray.  Decode the data to populate
        the values.
        :param data: Bytearray for the dataset.
        """
        packet_pointer = Ensemble.GetBaseDataSize(self.name_len)

        self.BtSamplesPerSecond = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 0,
            Ensemble().BytesInFloat, data)
        self.BtSystemFreqHz = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 1,
            Ensemble().BytesInFloat, data)
        self.BtCPCE = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 2,
            Ensemble().BytesInFloat, data)
        self.BtNCE = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 3,
            Ensemble().BytesInFloat, data)
        self.BtRepeatN = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 4,
            Ensemble().BytesInFloat, data)
        self.WpSamplesPerSecond = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 5,
            Ensemble().BytesInFloat, data)
        self.WpSystemFreqHz = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 6,
            Ensemble().BytesInFloat, data)
        self.WpCPCE = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 7,
            Ensemble().BytesInFloat, data)
        self.WpNCE = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 8,
            Ensemble().BytesInFloat, data)
        self.WpRepeatN = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 9,
            Ensemble().BytesInFloat, data)
        self.WpLagSamples = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 10,
            Ensemble().BytesInFloat, data)
        self.Voltage = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 11,
            Ensemble().BytesInFloat, data)

        if self.num_elements > 12:
            self.XmtVoltage = Ensemble.GetFloat(
                packet_pointer + Ensemble().BytesInFloat * 12,
                Ensemble().BytesInFloat, data)
            self.BtBroadband = Ensemble.GetFloat(
                packet_pointer + Ensemble().BytesInFloat * 13,
                Ensemble().BytesInFloat, data)
            self.BtLagLength = Ensemble.GetFloat(
                packet_pointer + Ensemble().BytesInFloat * 14,
                Ensemble().BytesInFloat, data)
            self.BtNarrowband = Ensemble.GetFloat(
                packet_pointer + Ensemble().BytesInFloat * 15,
                Ensemble().BytesInFloat, data)
            self.BtBeamMux = Ensemble.GetFloat(
                packet_pointer + Ensemble().BytesInFloat * 16,
                Ensemble().BytesInFloat, data)
            self.WpBroadband = Ensemble.GetFloat(
                packet_pointer + Ensemble().BytesInFloat * 17,
                Ensemble().BytesInFloat, data)
            self.WpLagLength = Ensemble.GetFloat(
                packet_pointer + Ensemble().BytesInFloat * 18,
                Ensemble().BytesInFloat, data)
            self.WpTransmitBandwidth = Ensemble.GetFloat(
                packet_pointer + Ensemble().BytesInFloat * 19,
                Ensemble().BytesInFloat, data)
            self.WpReceiveBandwidth = Ensemble.GetFloat(
                packet_pointer + Ensemble().BytesInFloat * 20,
                Ensemble().BytesInFloat, data)

        logger.debug(self.BtSamplesPerSecond)
        logger.debug(self.BtSystemFreqHz)
        logger.debug(self.BtCPCE)
        logger.debug(self.BtNCE)
        logger.debug(self.BtRepeatN)
        logger.debug(self.WpSamplesPerSecond)
        logger.debug(self.WpSystemFreqHz)
        logger.debug(self.WpCPCE)
        logger.debug(self.WpNCE)
        logger.debug(self.WpRepeatN)
        logger.debug(self.WpLagSamples)
        logger.debug(self.Voltage)
        logger.debug(self.XmtVoltage)
        logger.debug(self.BtBroadband)
        logger.debug(self.BtLagLength)
        logger.debug(self.BtNarrowband)
        logger.debug(self.BtBeamMux)
        logger.debug(self.WpBroadband)
        logger.debug(self.WpLagLength)
        logger.debug(self.WpTransmitBandwidth)
        logger.debug(self.WpReceiveBandwidth)
Ejemplo n.º 11
0
    def decode(self, data):
        """
        Take the data bytearray.  Decode the data to populate
        the values.
        :param data: Bytearray for the dataset.
        """
        packet_pointer = Ensemble.GetBaseDataSize(self.name_len)

        self.NumBeams = Ensemble.GetFloat(
            packet_pointer + Ensemble().BytesInFloat * 0,
            Ensemble().BytesInFloat, data)

        if self.NumBeams == 4.0:
            self.SNR.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 1,
                                  Ensemble().BytesInFloat, data))
            self.SNR.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 2,
                                  Ensemble().BytesInFloat, data))
            self.SNR.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 3,
                                  Ensemble().BytesInFloat, data))
            self.SNR.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 4,
                                  Ensemble().BytesInFloat, data))

            self.Range.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 5,
                                  Ensemble().BytesInFloat, data))
            self.Range.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 6,
                                  Ensemble().BytesInFloat, data))
            self.Range.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 7,
                                  Ensemble().BytesInFloat, data))
            self.Range.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 8,
                                  Ensemble().BytesInFloat, data))

            self.Pings.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 9,
                                  Ensemble().BytesInFloat, data))
            self.Pings.append(
                Ensemble.GetFloat(
                    packet_pointer + Ensemble().BytesInFloat * 10,
                    Ensemble().BytesInFloat, data))
            self.Pings.append(
                Ensemble.GetFloat(
                    packet_pointer + Ensemble().BytesInFloat * 11,
                    Ensemble().BytesInFloat, data))
            self.Pings.append(
                Ensemble.GetFloat(
                    packet_pointer + Ensemble().BytesInFloat * 12,
                    Ensemble().BytesInFloat, data))

            if len(data) > 80:
                self.Amplitude.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 13,
                        Ensemble().BytesInFloat, data))
                self.Amplitude.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 14,
                        Ensemble().BytesInFloat, data))
                self.Amplitude.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 15,
                        Ensemble().BytesInFloat, data))
                self.Amplitude.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 16,
                        Ensemble().BytesInFloat, data))

                self.Correlation.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 17,
                        Ensemble().BytesInFloat, data))
                self.Correlation.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 18,
                        Ensemble().BytesInFloat, data))
                self.Correlation.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 19,
                        Ensemble().BytesInFloat, data))
                self.Correlation.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 20,
                        Ensemble().BytesInFloat, data))

                self.BeamVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 21,
                        Ensemble().BytesInFloat, data))
                self.BeamVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 22,
                        Ensemble().BytesInFloat, data))
                self.BeamVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 23,
                        Ensemble().BytesInFloat, data))
                self.BeamVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 24,
                        Ensemble().BytesInFloat, data))

                self.InstrumentVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 25,
                        Ensemble().BytesInFloat, data))
                self.InstrumentVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 26,
                        Ensemble().BytesInFloat, data))
                self.InstrumentVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 27,
                        Ensemble().BytesInFloat, data))
                self.InstrumentVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 28,
                        Ensemble().BytesInFloat, data))

                self.EarthVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 29,
                        Ensemble().BytesInFloat, data))
                self.EarthVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 30,
                        Ensemble().BytesInFloat, data))
                self.EarthVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 31,
                        Ensemble().BytesInFloat, data))
                self.EarthVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 32,
                        Ensemble().BytesInFloat, data))

        elif self.NumBeams == 3.0:
            self.SNR.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 1,
                                  Ensemble().BytesInFloat, data))
            self.SNR.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 2,
                                  Ensemble().BytesInFloat, data))
            self.SNR.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 3,
                                  Ensemble().BytesInFloat, data))

            self.Range.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 4,
                                  Ensemble().BytesInFloat, data))
            self.Range.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 5,
                                  Ensemble().BytesInFloat, data))
            self.Range.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 6,
                                  Ensemble().BytesInFloat, data))

            self.Pings.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 7,
                                  Ensemble().BytesInFloat, data))
            self.Pings.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 8,
                                  Ensemble().BytesInFloat, data))
            self.Pings.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 9,
                                  Ensemble().BytesInFloat, data))

            if len(data) > 68:
                self.Amplitude.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 10,
                        Ensemble().BytesInFloat, data))
                self.Amplitude.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 11,
                        Ensemble().BytesInFloat, data))
                self.Amplitude.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 12,
                        Ensemble().BytesInFloat, data))

                self.Correlation.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 13,
                        Ensemble().BytesInFloat, data))
                self.Correlation.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 14,
                        Ensemble().BytesInFloat, data))
                self.Correlation.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 15,
                        Ensemble().BytesInFloat, data))

                self.BeamVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 16,
                        Ensemble().BytesInFloat, data))
                self.BeamVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 17,
                        Ensemble().BytesInFloat, data))
                self.BeamVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 18,
                        Ensemble().BytesInFloat, data))

                self.InstrumentVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 19,
                        Ensemble().BytesInFloat, data))
                self.InstrumentVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 20,
                        Ensemble().BytesInFloat, data))
                self.InstrumentVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 21,
                        Ensemble().BytesInFloat, data))

                self.EarthVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 22,
                        Ensemble().BytesInFloat, data))
                self.EarthVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 23,
                        Ensemble().BytesInFloat, data))
                self.EarthVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 24,
                        Ensemble().BytesInFloat, data))

        elif self.NumBeams == 2.0:
            self.SNR.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 1,
                                  Ensemble().BytesInFloat, data))
            self.SNR.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 2,
                                  Ensemble().BytesInFloat, data))

            self.Range.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 3,
                                  Ensemble().BytesInFloat, data))
            self.Range.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 4,
                                  Ensemble().BytesInFloat, data))

            self.Pings.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 5,
                                  Ensemble().BytesInFloat, data))
            self.Pings.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 6,
                                  Ensemble().BytesInFloat, data))

            if len(data) > 56:
                self.Amplitude.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 7,
                        Ensemble().BytesInFloat, data))
                self.Amplitude.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 8,
                        Ensemble().BytesInFloat, data))

                self.Correlation.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 9,
                        Ensemble().BytesInFloat, data))
                self.Correlation.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 10,
                        Ensemble().BytesInFloat, data))

                self.BeamVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 11,
                        Ensemble().BytesInFloat, data))
                self.BeamVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 12,
                        Ensemble().BytesInFloat, data))

                self.InstrumentVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 13,
                        Ensemble().BytesInFloat, data))
                self.InstrumentVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 14,
                        Ensemble().BytesInFloat, data))

                self.EarthVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 15,
                        Ensemble().BytesInFloat, data))
                self.EarthVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 16,
                        Ensemble().BytesInFloat, data))

        elif self.NumBeams == 1.0:
            self.SNR.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 1,
                                  Ensemble().BytesInFloat, data))
            self.Range.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 2,
                                  Ensemble().BytesInFloat, data))
            self.Pings.append(
                Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 3,
                                  Ensemble().BytesInFloat, data))

            if len(data) > 44:
                self.Amplitude.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 4,
                        Ensemble().BytesInFloat, data))
                self.Correlation.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 5,
                        Ensemble().BytesInFloat, data))
                self.BeamVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 6,
                        Ensemble().BytesInFloat, data))
                self.InstrumentVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 7,
                        Ensemble().BytesInFloat, data))
                self.EarthVelocity.append(
                    Ensemble.GetFloat(
                        packet_pointer + Ensemble().BytesInFloat * 8,
                        Ensemble().BytesInFloat, data))

        logger.debug(self.NumBeams)
        logger.debug(self.SNR)
        logger.debug(self.Range)
        logger.debug(self.Pings)
        logger.debug(self.Amplitude)
        logger.debug(self.Correlation)
        logger.debug(self.BeamVelocity)
        logger.debug(self.InstrumentVelocity)
        logger.debug(self.EarthVelocity)
Ejemplo n.º 12
0
    def decode_ensemble(self, ens):
        """
        Decode the ensemble.
        :param ens: Ensemble byte array.
        """
        # Ensure enough data is present to check the header
        if len(ens) < Ensemble().HeaderSize:
            self.NumIncompleteEnsembles += 1
            return

        self.NumEnsembles += 1

        # Check Ensemble number
        ens_num = struct.unpack("I", ens[16:20])
        ens_num_inv = struct.unpack("I", ens[20:24])
        logger.debug("Ensemble Number: " + str(ens_num[0]))
        logger.debug("Ensemble Number 1sComp: " + str(ens_num_inv[0]))

        if len(ens_num_inv) != 0:
            ens_num_1s_comp = Ensemble.ones_complement(ens_num_inv[0])

            if ens_num[0] != ens_num_1s_comp:
                self.NumBadEnsNum += 1
        else:
            self.NumBadEnsNum += 1

        # Check if ensemble numbers started over
        if self.prevEnsNum > ens_num[0]:
            self.ContainsMultipleRuns = True

        # Check for missing ensembles
        if self.prevEnsNum != 0 and ens_num[0] != self.prevEnsNum + 1:
            logger.info("Cur ENS Num: " + str(ens_num[0]))
            logger.info("Prev ENS Num: " + str(self.prevEnsNum))
            print("Cur ENS Num: " + str(ens_num[0]))
            print("Prev ENS Num: " + str(self.prevEnsNum))

            self.IsMissingEnsembles = True
            self.NumMissingEnsembles += (ens_num[0] - self.prevEnsNum - 1)
            for x in range(self.prevEnsNum + 1, ens_num[0]):
                self.MissingEnsembles.append(x)

        # Set Previous Ensemble
        self.prevEnsNum = ens_num[0]

        # Check ensemble size
        payload_size = struct.unpack("I", ens[24:28])
        payload_size_inv = struct.unpack("I", ens[28:32])
        payload_size_1s_comp = Ensemble.ones_complement(payload_size_inv[0])

        if payload_size[0] != payload_size_1s_comp:
            self.NumBadPayloadSize += 1

        # Set first and last ensemble number
        if self.FirstEnsembleNum == 0:
            self.FirstEnsembleNum = ens_num[0]

        self.LastEnsembleNum = ens_num[0]

        self.printVerbose("EnsNum: " + str(ens_num[0]) + " : " +
                          str(ens_num_1s_comp))
        self.printVerbose("Payload Size: " + str(payload_size[0]) + " : " +
                          str(payload_size_1s_comp))

        # Ensure the entire ensemble is in the buffer
        if len(ens) >= Ensemble().HeaderSize + payload_size[0] + Ensemble(
        ).ChecksumSize:
            # Get checksum
            checksumLoc = Ensemble().HeaderSize + payload_size[0]
            checksum = struct.unpack(
                "I", ens[checksumLoc:checksumLoc + Ensemble().ChecksumSize])

            # Calculate Checksum
            # Use only the payload for the checksum
            ens_payload = ens[Ensemble().HeaderSize:Ensemble().HeaderSize +
                              payload_size[0]]
            calcChecksum = CRCCCITT().calculate(input_data=bytes(ens_payload))
            self.printVerbose("Checksum: " + str(checksum[0]) + " : " +
                              str(calcChecksum))

            # Check the checksum
            if checksum[0] != calcChecksum:
                self.NumBadChecksum += 1
            else:
                self.NumGoodEnsembles += 1
        else:
            # Not a complete ensemble
            self.NumIncompleteEnsembles += 1
Ejemplo n.º 13
0
    def decode(self, data):
        """
        Take the data bytearray.  Decode the data to populate
        the values.
        :param data: Bytearray for the dataset.
        """
        packet_pointer = Ensemble.GetBaseDataSize(self.name_len)

        self.EnsembleNumber = Ensemble.GetInt32(
            packet_pointer + Ensemble().BytesInInt32 * 0,
            Ensemble().BytesInInt32, data)
        self.NumBins = Ensemble.GetInt32(
            packet_pointer + Ensemble().BytesInInt32 * 1,
            Ensemble().BytesInInt32, data)
        self.NumBeams = Ensemble.GetInt32(
            packet_pointer + Ensemble().BytesInInt32 * 2,
            Ensemble().BytesInInt32, data)
        self.DesiredPingCount = Ensemble.GetInt32(
            packet_pointer + Ensemble().BytesInInt32 * 3,
            Ensemble().BytesInInt32, data)
        self.ActualPingCount = Ensemble.GetInt32(
            packet_pointer + Ensemble().BytesInInt32 * 4,
            Ensemble().BytesInInt32, data)
        self.Status = Ensemble.GetInt32(
            packet_pointer + Ensemble().BytesInInt32 * 5,
            Ensemble().BytesInInt32, data)
        self.Year = Ensemble.GetInt32(
            packet_pointer + Ensemble().BytesInInt32 * 6,
            Ensemble().BytesInInt32, data)
        self.Month = Ensemble.GetInt32(
            packet_pointer + Ensemble().BytesInInt32 * 7,
            Ensemble().BytesInInt32, data)
        self.Day = Ensemble.GetInt32(
            packet_pointer + Ensemble().BytesInInt32 * 8,
            Ensemble().BytesInInt32, data)
        self.Hour = Ensemble.GetInt32(
            packet_pointer + Ensemble().BytesInInt32 * 9,
            Ensemble().BytesInInt32, data)
        self.Minute = Ensemble.GetInt32(
            packet_pointer + Ensemble().BytesInInt32 * 10,
            Ensemble().BytesInInt32, data)
        self.Second = Ensemble.GetInt32(
            packet_pointer + Ensemble().BytesInInt32 * 11,
            Ensemble().BytesInInt32, data)
        self.HSec = Ensemble.GetInt32(
            packet_pointer + Ensemble().BytesInInt32 * 12,
            Ensemble().BytesInInt32, data)

        self.SerialNumber = str(
            data[packet_pointer + Ensemble().BytesInInt32 * 13:packet_pointer +
                 Ensemble().BytesInInt32 * 21], "UTF-8")
        self.SysFirmwareRevision = struct.unpack(
            "B", data[packet_pointer + Ensemble().BytesInInt32 * 21 +
                      0:packet_pointer + Ensemble().BytesInInt32 * 21 + 1])[0]
        self.SysFirmwareMinor = struct.unpack(
            "B", data[packet_pointer + Ensemble().BytesInInt32 * 21 +
                      1:packet_pointer + Ensemble().BytesInInt32 * 21 + 2])[0]
        self.SysFirmwareMajor = struct.unpack(
            "B", data[packet_pointer + Ensemble().BytesInInt32 * 21 +
                      2:packet_pointer + Ensemble().BytesInInt32 * 21 + 3])[0]
        self.SysFirmwareSubsystemCode = str(
            data[packet_pointer + Ensemble().BytesInInt32 * 21 +
                 3:packet_pointer + Ensemble().BytesInInt32 * 21 + 4], "UTF-8")

        self.SubsystemConfig = struct.unpack(
            "B", data[packet_pointer + Ensemble().BytesInInt32 * 22 +
                      3:packet_pointer + Ensemble().BytesInInt32 * 22 + 4])[0]

        logger.debug(self.EnsembleNumber)
        logger.debug(
            str(self.Month) + "/" + str(self.Day) + "/" + str(self.Year) +
            "  " + str(self.Hour) + ":" + str(self.Minute) + ":" +
            str(self.Second) + "." + str(self.HSec))
        logger.debug(self.SerialNumber)
        logger.debug(
            str(self.SysFirmwareMajor) + "." + str(self.SysFirmwareMinor) +
            "." + str(self.SysFirmwareRevision) + "-" +
            str(self.SysFirmwareSubsystemCode))
        logger.debug(self.SubsystemConfig)
Ejemplo n.º 14
0
    def decode(self, data):
        """
        Take the data bytearray.  Decode the data to populate
        the velocities.
        :param data: Bytearray for the dataset.
        """
        packet_pointer = Ensemble.GetBaseDataSize(self.name_len)

        self.FirstPingTime = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 0, Ensemble().BytesInFloat, data)
        self.LastPingTime = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 1, Ensemble().BytesInFloat, data)
        self.Heading = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 2, Ensemble().BytesInFloat, data)
        self.Pitch = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 3, Ensemble().BytesInFloat, data)
        self.Roll = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 4, Ensemble().BytesInFloat, data)
        self.WaterTemp = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 5, Ensemble().BytesInFloat, data)
        self.SystemTemp = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 6, Ensemble().BytesInFloat, data)
        self.Salinity = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 7, Ensemble().BytesInFloat, data)
        self.Pressure = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 8, Ensemble().BytesInFloat, data)
        self.TransducerDepth = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 9, Ensemble().BytesInFloat, data)
        self.SpeedOfSound = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 10, Ensemble().BytesInFloat, data)
        self.Status = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 11, Ensemble().BytesInFloat, data)
        self.NumBeams = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 12, Ensemble().BytesInFloat, data)
        self.ActualPingCount = Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * 13, Ensemble().BytesInFloat, data)

        index = 14
        numBeam = int(self.NumBeams)
        for beams in range(numBeam):
            self.Range.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
            index += 1

        for beams in range(numBeam):
            self.SNR.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
            index += 1

        for beams in range(numBeam):
            self.Amplitude.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
            index += 1

        for beams in range(numBeam):
            self.Correlation.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
            index += 1

        for beams in range(numBeam):
            self.BeamVelocity.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
            index += 1

        for beams in range(numBeam):
            self.BeamGood.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
            index += 1

        for beams in range(numBeam):
            self.InstrumentVelocity.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
            index += 1

        for beams in range(numBeam):
            self.InstrumentGood.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
            index += 1

        for beams in range(numBeam):
            self.EarthVelocity.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
            index += 1

        for beams in range(numBeam):
            self.EarthGood.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
            index += 1

        if self.num_elements > 54:
            for beams in range(numBeam):
                self.SNR_PulseCoherent.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
                index += 1

            for beams in range(numBeam):
                self.Amp_PulseCoherent.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
                index += 1

            for beams in range(numBeam):
                self.Vel_PulseCoherent.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
                index += 1

            for beams in range(numBeam):
                self.Noise_PulseCoherent.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
                index += 1

            for beams in range(numBeam):
                self.Corr_PulseCoherent.append(Ensemble.GetFloat(packet_pointer + Ensemble().BytesInFloat * index, Ensemble().BytesInFloat, data))
                index += 1
        else:
            # Fill in with 0.0
            for beams in range(numBeam):
                self.SNR_PulseCoherent.append(0.0)

            for beams in range(numBeam):
                self.Amp_PulseCoherent.append(0.0)

            for beams in range(numBeam):
                self.Vel_PulseCoherent.append(0.0)

            for beams in range(numBeam):
                self.Noise_PulseCoherent.append(0.0)

            for beams in range(numBeam):
                self.Corr_PulseCoherent.append(0.0)


        logger.debug(self.FirstPingTime)
        logger.debug(self.LastPingTime)
        logger.debug(self.Heading)
        logger.debug(self.Pitch)
        logger.debug(self.Roll)
        logger.debug(self.Salinity)
        logger.debug(self.SpeedOfSound)
        logger.debug(self.EarthVelocity)
Ejemplo n.º 15
0
                            test_part_start=test_part_array[i],
                            test_part_end=test_part_array[i + 1],
                            times=30)
                        accuracy, profit, origin_profit, predictions, _ = so.predict_rate(
                            basic_path=basic_path,
                            data_file=choose_stock_folder + input_file,
                            model_folder=choose_stock_folder + model_folder,
                            folder_extra=folder_extra,
                            reduce_num=reduce_num,
                            test_part_start=test_part_array[i],
                            test_part_end=test_part_array[i + 1])
                        num = len(predictions)

                    elif choose_model == 8:

                        ens = Ensemble()
                        is_train and ens.train(
                            basic_path=basic_path,
                            input_file=input_file,
                            model_folder=choose_stock_folder + model_folder,
                            folder_extra=folder_extra,
                            batch_size=10,
                            reduce_num=reduce_num,
                            test_part_start=test_part_array[i],
                            test_part_end=test_part_array[i + 1],
                            times=1)
                        accuracy, profit, origin_profit, predictions, _ = ens.predict(
                            basic_path=basic_path,
                            input_file=input_file,
                            model_folder=choose_stock_folder + model_folder,
                            folder_extra=folder_extra,
Ejemplo n.º 16
0
all_data.loc[:, 'Cabin'] = all_data['Cabin'].map(lambda x: 'U'
                                                 if pd.isnull(x) else x[0])
all_data.Cabin.replace(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'T', 'U'],
                       [0, 0, 0, 0, 0, 0, 0, 0, 1],
                       inplace=True)

all_data = tp.preprocessing(all_data)
to_predict = all_data[survived_data.shape[0]:]

train_x, test_x, train_y, test_y = train_test_split(
    all_data[0:survived_data.shape[0]], survived_data, test_size=0.4)

with open('error.log', 'w+') as err_log:
    try:
        ensemble = Ensemble(train_x, train_y, test_x)

        # ensemble.add_predictor(Predictor("DecisionTreeRegressor"))
        # ensemble.add_predictor(Predictor("SVR"))

        # ensemble.add_predictor(Predictor("SVC"))
        # ensemble.add_predictor(Predictor("LogisticRegression"))
        # ensemble.add_predictor(Predictor("K-NN"))
        # ensemble.add_predictor(Predictor("GaussianNB"))
        # ensemble.add_predictor(Predictor("RandomForestClassifier"))
        # ensemble.add_predictor(Predictor("Perceptron"))
        # ensemble.add_predictor(Predictor("LinearSVC"))
        # ensemble.add_predictor(Predictor("SGDClassifier"))
        ensemble.add_predictor(Predictor("AdaBoostClassifier"))
        # ensemble.add_predictor(Predictor("GradientBoostingClassifier"))
        # ensemble.add_predictor(Predictor("ExtraTreesClassifier"))
Ejemplo n.º 17
0
    def stream_data(self, ens):
        """
        Stream the data to the UDP port.
        When converting the dataset to JSON, a newline will be added
        to end of the JSON string.  This will allow the user to separate
        the JSON strings.
        :param ens: Ensemble data to stream.
        """
        serial_number = ""
        ensemble_number = 0
        date_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")

        if ens.IsEnsembleData:
            # Get the serial number, ensemble number and the date and time to share with all the data
            serial_number = ens.EnsembleData.SerialNumber
            ensemble_number = ens.EnsembleData.EnsembleNumber
            if ens.EnsembleData.Month > 0:
                date_time = datetime.datetime(
                    year=ens.EnsembleData.Year,
                    month=ens.EnsembleData.Month,
                    day=ens.EnsembleData.Day,
                    hour=ens.EnsembleData.Hour,
                    minute=ens.EnsembleData.Minute,
                    second=ens.EnsembleData.Second,
                    microsecond=round(ens.EnsembleData.HSec *
                                      10000)).strftime("%Y-%m-%d %H:%M:%S.%f")

                # Stream the data
                ens.EnsembleData.DateTime = date_time
            else:
                logger.error("BAD Date and Time: " + str(ensemble_number))

            ens.EnsembleData.Meta = self.Meta
            self.send_udp(Ensemble().toJSON(ens.EnsembleData).encode())

        if ens.IsBeamVelocity:
            ens.BeamVelocity.EnsembleNumber = ensemble_number
            ens.BeamVelocity.SerialNumber = serial_number
            ens.BeamVelocity.DateTime = date_time
            ens.BeamVelocity.Meta = self.Meta
            self.send_udp(Ensemble().toJSON(ens.BeamVelocity).encode())

        if ens.IsInstrumentVelocity:
            ens.InstrumentVelocity.EnsembleNumber = ensemble_number
            ens.InstrumentVelocity.SerialNumber = serial_number
            ens.InstrumentVelocity.DateTime = date_time
            ens.InstrumentVelocity.Meta = self.Meta
            self.send_udp(Ensemble().toJSON(ens.InstrumentVelocity).encode())

        if ens.IsEarthVelocity:
            ens.EarthVelocity.EnsembleNumber = ensemble_number
            ens.EarthVelocity.SerialNumber = serial_number
            ens.EarthVelocity.DateTime = date_time
            ens.EarthVelocity.Meta = self.Meta
            self.send_udp(Ensemble().toJSON(ens.EarthVelocity).encode())

        if ens.IsAmplitude:
            ens.Amplitude.EnsembleNumber = ensemble_number
            ens.Amplitude.SerialNumber = serial_number
            ens.Amplitude.DateTime = date_time
            ens.Amplitude.Meta = self.Meta
            self.send_udp(Ensemble().toJSON(ens.Amplitude).encode())

        if ens.IsCorrelation:
            ens.Correlation.EnsembleNumber = ensemble_number
            ens.Correlation.SerialNumber = serial_number
            ens.Correlation.DateTime = date_time
            ens.Correlation.Meta = self.Meta
            self.send_udp(Ensemble().toJSON(ens.Correlation).encode())

        if ens.IsGoodBeam:
            ens.GoodBeam.EnsembleNumber = ensemble_number
            ens.GoodBeam.SerialNumber = serial_number
            ens.GoodBeam.DateTime = date_time
            ens.GoodBeam.Meta = self.Meta
            self.send_udp(Ensemble().toJSON(ens.GoodBeam).encode())

        if ens.IsGoodEarth:
            ens.GoodEarth.EnsembleNumber = ensemble_number
            ens.GoodEarth.SerialNumber = serial_number
            ens.GoodEarth.DateTime = date_time
            ens.GoodEarth.Meta = self.Meta
            self.send_udp(Ensemble().toJSON(ens.GoodEarth).encode())

        if ens.IsAncillaryData:
            ens.AncillaryData.EnsembleNumber = ensemble_number
            ens.AncillaryData.SerialNumber = serial_number
            ens.AncillaryData.DateTime = date_time
            ens.AncillaryData.Meta = self.Meta
            self.send_udp(Ensemble().toJSON(ens.AncillaryData).encode())

        if ens.IsBottomTrack:
            ens.BottomTrack.EnsembleNumber = ensemble_number
            ens.BottomTrack.SerialNumber = serial_number
            ens.BottomTrack.DateTime = date_time
            ens.BottomTrack.Meta = self.Meta
            self.send_udp(Ensemble().toJSON(ens.BottomTrack).encode())

        if ens.IsRangeTracking:
            ens.RangeTracking.EnsembleNumber = ensemble_number
            ens.RangeTracking.SerialNumber = serial_number
            ens.RangeTracking.DateTime = date_time
            ens.RangeTracking.Meta = self.Meta
            self.send_udp(Ensemble().toJSON(ens.RangeTracking).encode())