def test_json_to_process_flight(self):
     process_flight_json = deepcopy(PROCESS_FLIGHT_JSON)
     self.assertEqual(json_to_process_flight(simplejson.dumps(process_flight_json)), PROCESS_FLIGHT)
     # incompatible or missing version does not load
     process_flight_json["version"] = "0.4"
     self.assertEqual(json_to_process_flight(simplejson.dumps(process_flight_json)), {})
     del process_flight_json["version"]
     self.assertEqual(json_to_process_flight(simplejson.dumps(process_flight_json)), {})
 def test_json_to_process_flight(self):
     process_flight_json = deepcopy(PROCESS_FLIGHT_JSON)
     self.assertEqual(
         json_to_process_flight(simplejson.dumps(process_flight_json)),
         PROCESS_FLIGHT)
     # incompatible or missing version does not load
     process_flight_json['version'] = '0.4'
     self.assertEqual(
         json_to_process_flight(simplejson.dumps(process_flight_json)), {})
     del process_flight_json['version']
     self.assertEqual(
         json_to_process_flight(simplejson.dumps(process_flight_json)), {})
Пример #3
0
def main():
    print('FlightDataAnalyzer (c) Copyright 2013 Flight Data Services, Ltd.')
    print('  - Powered by POLARIS')
    print('  - http://www.flightdatacommunity.com')
    print()
    from analysis_engine.plot_flight import csv_flight_details, track_to_kml
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    logger.addHandler(logging.StreamHandler(stream=sys.stdout))
    parser = argparse.ArgumentParser(description="Process a flight.")
    parser.add_argument('file', type=str, help='Path of file to process.')
    help = 'Disable writing a CSV of the processing results.'
    parser.add_argument('-disable-csv',
                        dest='disable_csv',
                        action='store_true',
                        help=help)
    help = 'Disable writing a KML of the flight track.'
    parser.add_argument('-disable-kml',
                        dest='disable_kml',
                        action='store_true',
                        help=help)
    parser.add_argument('-r',
                        '--requested',
                        type=str,
                        nargs='+',
                        dest='requested',
                        default=[],
                        help='Requested nodes.')
    parser.add_argument('-R',
                        '--required',
                        type=str,
                        nargs='+',
                        dest='required',
                        default=[],
                        help='Required nodes.')
    parser.add_argument(
        '-tail',
        '--tail',
        dest='tail_number',
        default='G-FDSL',  # as per flightdatacommunity file
        help='Aircraft tail number.')
    parser.add_argument(
        '-segment-type',
        dest='segment_type',
        default='START_AND_STOP',  # as per flightdatacommunity file
        help='Type of segment.')
    parser.add_argument('--strip',
                        default=False,
                        action='store_true',
                        help='Strip the HDF5 file to only the LFL parameters')
    parser.add_argument('-v',
                        '--verbose',
                        dest='verbose',
                        action='store_true',
                        help='Verbose logging')

    # Aircraft info
    parser.add_argument('-aircraft-family',
                        dest='aircraft_family',
                        type=str,
                        help='Aircraft family.')
    parser.add_argument('-aircraft-series',
                        dest='aircraft_series',
                        type=str,
                        help='Aircraft series.')
    parser.add_argument('-aircraft-model',
                        dest='aircraft_model',
                        type=str,
                        help='Aircraft model.')
    parser.add_argument('-aircraft-manufacturer',
                        dest='aircraft_manufacturer',
                        type=str,
                        help='Aircraft manufacturer.')
    help = 'Whether or not the aircraft records precise positioning ' \
        'parameters.'
    parser.add_argument('-precise-positioning',
                        dest='precise_positioning',
                        type=str,
                        help=help)
    parser.add_argument('-frame',
                        dest='frame',
                        type=str,
                        help='Data frame name.')
    parser.add_argument('-frame-qualifier',
                        dest='frame_qualifier',
                        type=str,
                        help='Data frame qualifier.')
    parser.add_argument('-identifier',
                        dest='identifier',
                        type=str,
                        help='Aircraft identifier.')
    parser.add_argument('-manufacturer-serial-number',
                        dest='manufacturer_serial_number',
                        type=str,
                        help="Manufacturer's serial number of the aircraft.")
    parser.add_argument('-qar-serial-number',
                        dest='qar_serial_number',
                        type=str,
                        help='QAR serial number.')
    help = 'Main gear to radio altimeter antenna in metres.'
    parser.add_argument('-main-gear-to-radio-altimeter-antenna',
                        dest='main_gear_to_alt_rad',
                        type=float,
                        help=help)
    help = 'Main gear to lowest point of tail in metres.'
    parser.add_argument('-main-gear-to-lowest-point-of-tail',
                        dest='main_gear_to_tail',
                        type=float,
                        help=help)
    help = 'Ground to lowest point of tail in metres.'
    parser.add_argument('-ground-to-lowest-point-of-tail',
                        dest='ground_to_tail',
                        type=float,
                        help=help)
    parser.add_argument('-engine-count',
                        dest='engine_count',
                        type=int,
                        help='Number of engines.')
    parser.add_argument('-engine-manufacturer',
                        dest='engine_manufacturer',
                        type=str,
                        help='Engine manufacturer.')
    parser.add_argument('-engine-series',
                        dest='engine_series',
                        type=str,
                        help='Engine series.')
    parser.add_argument('-engine-type',
                        dest='engine_type',
                        type=str,
                        help='Engine type.')

    parser.add_argument('-initial',
                        dest='initial',
                        type=str,
                        help='Path to initial nodes in json format.')

    args = parser.parse_args()

    if args.verbose:
        logger.setLevel(logging.DEBUG)

    aircraft_info = {}
    if args.aircraft_model:
        aircraft_info['Model'] = args.aircraft_model
    if args.aircraft_family:
        aircraft_info['Family'] = args.aircraft_family
    if args.aircraft_series:
        aircraft_info['Series'] = args.aircraft_series
    if args.aircraft_manufacturer:
        aircraft_info['Manufacturer'] = args.aircraft_manufacturer
    if args.precise_positioning:
        aircraft_info['Precise Positioning'] = args.precise_positioning
    if args.frame:
        aircraft_info['Frame'] = args.frame
    if args.frame_qualifier:
        aircraft_info['Frame Qualifier'] = args.frame_qualifier
    if args.identifier:
        aircraft_info['Identifier'] = args.identifier
    if args.manufacturer_serial_number:
        aircraft_info['Manufacturer Serial Number'] = \
            args.manufacturer_serial_number
    if args.qar_serial_number:
        aircraft_info['QAR Serial Number'] = args.qar_serial_number
    if args.main_gear_to_alt_rad:
        aircraft_info['Main Gear To Radio Altimeter Antenna'] = \
            args.main_gear_to_alt_rad
    if args.main_gear_to_tail:
        aircraft_info['Main Gear To Lowest Point Of Tail'] = \
            args.main_gear_to_tail
    if args.ground_to_tail:
        aircraft_info['Ground To Lowest Point Of Tail'] = args.ground_to_tail
    if args.engine_count:
        aircraft_info['Engine Count'] = args.engine_count
    if args.engine_series:
        aircraft_info['Engine Series'] = args.engine_series
    if args.engine_manufacturer:
        aircraft_info['Engine Manufacturer'] = args.engine_manufacturer
    if args.engine_series:
        aircraft_info['Engine Series'] = args.engine_series
    if args.engine_type:
        aircraft_info['Engine Type'] = args.engine_type

    # Derive parameters to new HDF
    hdf_copy = copy_file(args.file, postfix='_process')
    if args.strip:
        with hdf_file(hdf_copy) as hdf:
            hdf.delete_params(hdf.derived_keys())

    if args.initial:
        if not os.path.exists(args.initial):
            parser.error('Path for initial json data not found: %s' %
                         args.initial)
        initial = json_to_process_flight(open(args.initial, 'rb').read())
    else:
        initial = {}

    segment_info = {
        'File': hdf_copy,
        'Segment Type': args.segment_type,
    }
    res = process_flight(
        segment_info,
        args.tail_number,
        aircraft_info=aircraft_info,
        requested=args.requested,
        required=args.required,
        initial=initial,
        include_flight_attributes=False,
    )
    # Flatten results.
    res = {
        k: list(itertools.chain.from_iterable(six.itervalues(v)))
        for k, v in six.iteritems(res)
    }

    logger.info("Derived parameters stored in hdf: %s", hdf_copy)
    # Write CSV file
    if not args.disable_csv:
        csv_dest = os.path.splitext(hdf_copy)[0] + '.csv'
        csv_flight_details(hdf_copy,
                           res['kti'],
                           res['kpv'],
                           res['phases'],
                           dest_path=csv_dest)
        logger.info("KPV, KTI and Phases writen to csv: %s", csv_dest)
    # Write KML file
    if not args.disable_kml:
        kml_dest = os.path.splitext(hdf_copy)[0] + '.kml'
        dest = track_to_kml(hdf_copy,
                            res['kti'],
                            res['kpv'],
                            res['approach'],
                            dest_path=kml_dest)
        if dest:
            logger.info("Flight Track with attributes writen to kml: %s", dest)
Пример #4
0
def main():
    print 'FlightDataAnalyzer (c) Copyright 2013 Flight Data Services, Ltd.'
    print '  - Powered by POLARIS'
    print '  - http://www.flightdatacommunity.com'
    print ''
    from analysis_engine.plot_flight import csv_flight_details, track_to_kml
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    logger.addHandler(logging.StreamHandler(stream=sys.stdout))
    parser = argparse.ArgumentParser(description="Process a flight.")
    parser.add_argument('file', type=str,
                        help='Path of file to process.')
    help = 'Disable writing a CSV of the processing results.'
    parser.add_argument('-disable-csv', dest='disable_csv',
                        action='store_true', help=help)
    help = 'Disable writing a KML of the flight track.'
    parser.add_argument('-disable-kml', dest='disable_kml',
                        action='store_true', help=help)
    parser.add_argument('-r', '--requested', type=str, nargs='+',
                        dest='requested', default=[], help='Requested nodes.')
    parser.add_argument('-R', '--required', type=str, nargs='+', dest='required',
                        default=[], help='Required nodes.')
    parser.add_argument('-tail', '--tail', dest='tail_number',
                        default='G-FDSL',  # as per flightdatacommunity file
                        help='Aircraft tail number.')
    parser.add_argument('-segment-type', dest='segment_type',
                        default='START_AND_STOP',  # as per flightdatacommunity file
                        help='Type of segment.')
    parser.add_argument('--strip', default=False, action='store_true',
                        help='Strip the HDF5 file to only the LFL parameters')
    parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
                        help='Verbose logging')

    # Aircraft info
    parser.add_argument('-aircraft-family', dest='aircraft_family', type=str,
                        help='Aircraft family.')
    parser.add_argument('-aircraft-series', dest='aircraft_series', type=str,
                        help='Aircraft series.')
    parser.add_argument('-aircraft-model', dest='aircraft_model', type=str,
                        help='Aircraft model.')
    parser.add_argument('-aircraft-manufacturer', dest='aircraft_manufacturer',
                        type=str, help='Aircraft manufacturer.')
    help = 'Whether or not the aircraft records precise positioning ' \
        'parameters.'
    parser.add_argument('-precise-positioning', dest='precise_positioning',
                        type=str, help=help)
    parser.add_argument('-frame', dest='frame', type=str,
                        help='Data frame name.')
    parser.add_argument('-frame-qualifier', dest='frame_qualifier', type=str,
                        help='Data frame qualifier.')
    parser.add_argument('-identifier', dest='identifier', type=str,
                        help='Aircraft identifier.')
    parser.add_argument('-manufacturer-serial-number',
                        dest='manufacturer_serial_number', type=str,
                        help="Manufacturer's serial number of the aircraft.")
    parser.add_argument('-qar-serial-number', dest='qar_serial_number',
                        type=str, help='QAR serial number.')
    help = 'Main gear to radio altimeter antenna in metres.'
    parser.add_argument('-main-gear-to-radio-altimeter-antenna',
                        dest='main_gear_to_alt_rad',
                        type=float, help=help)
    help = 'Main gear to lowest point of tail in metres.'
    parser.add_argument('-main-gear-to-lowest-point-of-tail',
                        dest='main_gear_to_tail',
                        type=float, help=help)
    help = 'Ground to lowest point of tail in metres.'
    parser.add_argument('-ground-to-lowest-point-of-tail',
                        dest='ground_to_tail',
                        type=float, help=help)
    parser.add_argument('-engine-count', dest='engine_count',
                        type=int, help='Number of engines.')
    parser.add_argument('-engine-manufacturer', dest='engine_manufacturer',
                        type=str, help='Engine manufacturer.')
    parser.add_argument('-engine-series', dest='engine_series', type=str,
                        help='Engine series.')
    parser.add_argument('-engine-type', dest='engine_type', type=str,
                        help='Engine type.')
    
    parser.add_argument('-initial', dest='initial', type=str,
                        help='Path to initial nodes in json format.')
    

    args = parser.parse_args()

    if args.verbose:
        logger.setLevel(logging.DEBUG)

    aircraft_info = {}
    if args.aircraft_model:
        aircraft_info['Model'] = args.aircraft_model
    if args.aircraft_family:
        aircraft_info['Family'] = args.aircraft_family
    if args.aircraft_series:
        aircraft_info['Series'] = args.aircraft_series
    if args.aircraft_manufacturer:
        aircraft_info['Manufacturer'] = args.aircraft_manufacturer
    if args.precise_positioning:
        aircraft_info['Precise Positioning'] = args.precise_positioning
    if args.frame:
        aircraft_info['Frame'] = args.frame
    if args.frame_qualifier:
        aircraft_info['Frame Qualifier'] = args.frame_qualifier
    if args.identifier:
        aircraft_info['Identifier'] = args.identifier
    if args.manufacturer_serial_number:
        aircraft_info['Manufacturer Serial Number'] = \
            args.manufacturer_serial_number
    if args.qar_serial_number:
        aircraft_info['QAR Serial Number'] = args.qar_serial_number
    if args.main_gear_to_alt_rad:
        aircraft_info['Main Gear To Radio Altimeter Antenna'] = \
            args.main_gear_to_alt_rad
    if args.main_gear_to_tail:
        aircraft_info['Main Gear To Lowest Point Of Tail'] = \
            args.main_gear_to_tail
    if args.ground_to_tail:
        aircraft_info['Ground To Lowest Point Of Tail'] = args.ground_to_tail
    if args.engine_count:
        aircraft_info['Engine Count'] = args.engine_count
    if args.engine_series:
        aircraft_info['Engine Series'] = args.engine_series
    if args.engine_manufacturer:
        aircraft_info['Engine Manufacturer'] = args.engine_manufacturer
    if args.engine_series:
        aircraft_info['Engine Series'] = args.engine_series
    if args.engine_type:
        aircraft_info['Engine Type'] = args.engine_type

    # Derive parameters to new HDF
    hdf_copy = copy_file(args.file, postfix='_process')
    if args.strip:
        with hdf_file(hdf_copy) as hdf:
            hdf.delete_params(hdf.derived_keys())
    
    if args.initial:
        if not os.path.exists(args.initial):
            parser.error('Path for initial json data not found: %s' % args.initial)
        initial = json_to_process_flight(open(args.initial, 'rb').read())
    else:
        initial = {}

    segment_info = {
        'File': hdf_copy,
        'Segment Type': args.segment_type,
    }
    res = process_flight(
        segment_info, args.tail_number, aircraft_info=aircraft_info,
        requested=args.requested, required=args.required,
        additional_modules=['flightdataprofiles.fcp.kpvs'],
        initial=initial,
    )
    # Flatten results.
    res = {k: list(itertools.chain.from_iterable(v.itervalues()))
           for k, v in res.iteritems()}
    
    logger.info("Derived parameters stored in hdf: %s", hdf_copy)
    # Write CSV file
    if not args.disable_csv:
        csv_dest = os.path.splitext(hdf_copy)[0] + '.csv'
        csv_flight_details(hdf_copy, res['kti'], res['kpv'], res['phases'],
                           dest_path=csv_dest)
        logger.info("KPV, KTI and Phases writen to csv: %s", csv_dest)
    # Write KML file
    if not args.disable_kml:
        kml_dest = os.path.splitext(hdf_copy)[0] + '.kml'
        dest = track_to_kml(
            hdf_copy, res['kti'], res['kpv'], res['approach'],
            dest_path=kml_dest)
        if dest:
            logger.info("Flight Track with attributes writen to kml: %s", dest)