Beispiel #1
0
def get_esns(flight):
    try:
        with hdf_file(flight.segment.file, read_only=True) as hdf:
            e1esn = most_common_value(hdf['Eng (1) ESN'].array)
            e2esn = most_common_value(hdf['Eng (2) ESN'].array)
        return e1esn, e2esn
    except:
        import traceback
        traceback.print_exc()
        return '', ''
Beispiel #2
0
    def derive(self, num=P('Flight Number')):
        # Q: Should we validate the flight number?
        if num.array.dtype.type is np.string_:
            value = most_common_value(num.array, threshold=0.45)
            if value is not None:
                self.set_flight_attr(value)

            return

        # Values of 0 are invalid flight numbers
        array = np.ma.masked_less_equal(num.array, 0)
        # Ignore masked values
        compressed_array = array.compressed()
        _, minvalue = min_value(compressed_array)
        if minvalue < 0:
            self.warning(
                "'%s' only supports unsigned (positive) values > 0, "
                "but none were found. Cannot determine flight number",
                self.name)
            self.set_flight_attr(None)
            return

        # note reverse of value, index from max_value due to bincount usage.
        value, count = max_value(
            np.bincount(compressed_array.astype(np.integer)))
        if count > len(compressed_array) * 0.45:
            # this value accounts for at least 45% of the values in the array
            self.set_flight_attr(str(int(value)))
        else:
            self.warning(
                "Only %d out of %d flight numbers were the same."
                " Flight Number attribute will be set as None.", count or 0,
                len(num.array))
            self.set_flight_attr(None)
            return
Beispiel #3
0
    def derive(self,
               dest=P('Destination'),
               afr_dest=A('AFR Destination Airport')):
        '''
        Requires an ASCII destination parameter recording either the airport's
        ICAO or IATA code.
        '''
        if not dest or dest.array.dtype.type is not np.string_:
            if afr_dest:
                self.set_flight_attr(afr_dest.value)
            return

        value = most_common_value(dest.array, threshold=0.45)
        if value is None or not value.isalpha():
            return

        handler = api.get_handler(settings.API_HANDLER)
        try:
            airport = handler.get_airport(value)
        except api.NotFoundError:
            self.warning('No destination airport found for %s.', value)
            return

        self.debug('Detected destination airport: %s', airport)
        self.set_flight_attr(airport)
Beispiel #4
0
    def _determine_pilot(self, pilot_flying, pitch_capt, pitch_fo, roll_capt,
                         roll_fo, cc_capt, cc_fo, phase, ap1, ap2):

        if pilot_flying:
            # this is the most reliable measurement, use this and no other
            pf = pilot_flying.array[phase.slice]
            pf[pf == '-'] = np.ma.masked
            return most_common_value(pf)

        #FIXME: Skip over the Pitch and Control Column parts!
        # 1. Check for change in pitch and roll controls during the phase:
        if all((pitch_capt, pitch_fo, roll_capt, roll_fo, phase)):
            pilot = self._controls_in_use(pitch_capt.array, pitch_fo.array,
                                          roll_capt.array, roll_fo.array,
                                          phase)
            if pilot:
                return pilot

        # 1. Check for changes in control column during the phase:
        if all((cc_capt, cc_fo, phase)):
            pilot = self._control_column_in_use(cc_capt.array, cc_fo.array,
                                                phase)
            if pilot:
                return pilot

        # 2. Check which autopilot is engaged:
        if all((ap1, ap2)):
            pilot = self._autopilot_engaged(ap1, ap2)
            if pilot:
                return pilot

        return None
    def derive(self, num=P('Flight Number')):
        # Q: Should we validate the flight number?
        if num.array.dtype.type is np.string_:
            value = most_common_value(num.array, threshold=0.45)
            if value is not None:
                self.set_flight_attr(value)

            return

        # Values of 0 are invalid flight numbers
        array = np.ma.masked_less_equal(num.array, 0)
        # Ignore masked values
        compressed_array = array.compressed()
        _, minvalue = min_value(compressed_array)
        if minvalue < 0:
            self.warning(
                "'%s' only supports unsigned (positive) values > 0, "
                "but none were found. Cannot determine flight number",
                self.name)
            self.set_flight_attr(None)
            return

        # note reverse of value, index from max_value due to bincount usage.
        value, count = max_value(
            np.bincount(compressed_array.astype(np.integer)))
        if count > len(compressed_array) * 0.45:
            # this value accounts for at least 45% of the values in the array
            self.set_flight_attr(str(int(value)))
        else:
            self.warning("Only %d out of %d flight numbers were the same."
                         " Flight Number attribute will be set as None.",
                         count or 0, len(num.array))
            self.set_flight_attr(None)
            return
    def _determine_pilot(self, pilot_flying, pitch_capt, pitch_fo, roll_capt,
                         roll_fo, cc_capt, cc_fo, phase, ap1, ap2):

        if pilot_flying:
            # this is the most reliable measurement, use this and no other
            pf = pilot_flying.array[phase.slice]
            pf[pf == '-'] = np.ma.masked
            return most_common_value(pf)

        #FIXME: Skip over the Pitch and Control Column parts!
        # 1. Check for change in pitch and roll controls during the phase:
        if all((pitch_capt, pitch_fo, roll_capt, roll_fo, phase)):
            pilot = self._controls_in_use(
                pitch_capt.array, pitch_fo.array, roll_capt.array,
                roll_fo.array, phase)
            if pilot:
                return pilot

        # 1. Check for changes in control column during the phase:
        if all((cc_capt, cc_fo, phase)):
            pilot = self._control_column_in_use(cc_capt.array, cc_fo.array,
                                                phase)
            if pilot:
                return pilot

        # 2. Check which autopilot is engaged:
        if all((ap1, ap2)):
            pilot = self._autopilot_engaged(ap1, ap2)
            if pilot:
                return pilot

        return None
    def derive(self,
               num=P('Flight Number'),
               mobiles=S('Mobile')):

        # Limit to Mobile sections
        num_array = mask_outside_slices(num.array, mobiles.get_slices())
        # Q: Should we validate the flight number?
        if num.array.dtype.type is np.string_:
            value = most_common_value(num_array, threshold=0.45)
            if value is not None:
                # Only parse valid ASCII characters
                try:
                    self.set_flight_attr(re.sub(r'[^\x00-\x7f]', r'', value.decode()))
                except UnicodeDecodeError:
                    self.set_flight_attr(None)
            return

        # Values of 0 are invalid flight numbers
        array = np.ma.masked_less_equal(num_array, 0)
        # Ignore masked values
        compressed_array = array.compressed()
        _, minvalue = min_value(compressed_array)
        if minvalue is None or minvalue < 0:
            self.warning(
                "'%s' only supports unsigned (positive) values > 0, "
                "but none were found. Cannot determine flight number",
                self.name)
            self.set_flight_attr(None)
            return

        # note reverse of value, index from max_value due to bincount usage.
        value, count = max_value(
            np.bincount(compressed_array.astype(np.integer)))
        if count > len(compressed_array) * 0.45:
            # this value accounts for at least 45% of the values in the array
            self.set_flight_attr(str(int(value)))
        else:
            self.warning("Only %d out of %d flight numbers were the same."
                         " Flight Number attribute will be set as None.",
                         count or 0, len(num.array))
            self.set_flight_attr(None)
            return
    def derive(self, dest=P('Destination'),
               afr_dest=A('AFR Destination Airport')):
        '''
        Requires an ASCII destination parameter recording either the airport's
        ICAO or IATA code.
        '''
        if not dest or dest.array.dtype.type is not np.string_:
            if afr_dest:
                self.set_flight_attr(afr_dest.value)
            return

        value = most_common_value(dest.array, threshold=0.45)
        if value is None or not value.isalpha():
            return

        api = get_api_handler(settings.API_HANDLER)
        try:
            airport = api.get_airport(value)
        except NotFoundError:
            self.warning('No destination airport found for %s.', value)
            return

        self.debug('Detected destination airport: %s', airport)
        self.set_flight_attr(airport)
Beispiel #9
0
 def derive(self, num=P('Eng (1) ESN')):
     value = most_common_value(num.array, threshold=0.5)
     if value is not None:
         self.set_flight_attr(value)
 def derive(self, num=P('Eng (4) ESN')):
     value = most_common_value(num.array, threshold=0.5)
     if value is not None:
         self.set_flight_attr(value)