def test_split_segments_data_3(self):
        '''Splits on both Engine and Heading parameters.'''
        hdf_path = os.path.join(test_data_path, "split_segments_3.hdf5")
        temp_path = copy_file(hdf_path)
        hdf = hdf_file(temp_path)

        segment_tuples = split_segments(hdf, {})

        #for a, e in zip(segment_tuples, expected):
        #print(a,e,a==e)

        self.assertEqual(segment_tuples, [
            ('START_AND_STOP', slice(0, 3989.0, None), 0),
            ('START_AND_STOP', slice(3989.0, 7049.0, None), 1),
            ('START_AND_STOP', slice(7049.0, 9569.0, None), 1),
            ('START_AND_STOP', slice(9569.0, 12889.0, None), 1),
            ('START_AND_STOP', slice(12889.0, 15867.0, None), 1),
            ('START_AND_STOP', slice(15867.0, 18526.0, None), 3),
            ('START_AND_STOP', slice(18526.0, 21726.0, None), 2),
            ('START_AND_STOP', slice(21726.0, 24209.0, None), 2),
            ('START_AND_STOP', slice(24209.0, 26607.0, None), 1),
            ('START_AND_STOP', slice(26607.0, 28534.0, None), 3),
            ('START_AND_STOP', slice(28534.0, 30875.0, None), 2),
            ('START_AND_STOP', slice(30875.0, 33488.0, None), 3),
            ('NO_MOVEMENT', slice(33488.0, 33680.0, None), 0),
        ])
    def test_split_segments_multiple_types(self, settings):
        '''
        Test data has multiple segments of differing segment types.
        Test data has already been validated
        '''
        # Overriding MINIMUM_FAST_DURATION.
        settings.AIRSPEED_THRESHOLD = 80
        settings.AIRSPEED_THRESHOLD_TIME = 3 * 60
        settings.HEADING_CHANGE_TAXI_THRESHOLD = 60
        settings.MINIMUM_SPLIT_DURATION = 100
        settings.MINIMUM_FAST_DURATION = 0
        settings.MINIMUM_SPLIT_PARAM_VALUE = 0.175
        settings.HEADING_RATE_SPLITTING_THRESHOLD = 0.1
        settings.MAX_TIMEBASE_AGE = 365 * 10
        settings.MIN_FAN_RUNNING = 10

        hdf_path = os.path.join(test_data_path,
                                "split_segments_multiple_types.hdf5")
        temp_path = copy_file(hdf_path)
        hdf = hdf_file(temp_path)
        self.maxDiff = None
        segment_tuples = split_segments(hdf, {})
        self.assertEqual(len(segment_tuples),
                         16,
                         msg="Unexpected number of segments detected")
        segment_types = tuple(x[0] for x in segment_tuples)
        self.assertEqual(
            segment_types,
            ('STOP_ONLY', 'START_ONLY', 'START_AND_STOP', 'START_AND_STOP',
             'START_AND_STOP', 'START_AND_STOP', 'STOP_ONLY', 'START_AND_STOP',
             'STOP_ONLY', 'START_ONLY', 'START_ONLY', 'START_AND_STOP',
             'START_ONLY', 'START_AND_STOP', 'START_AND_STOP', 'START_ONLY'))
    def test_split_segments_data_3(self):
        '''Splits on both Engine and Heading parameters.'''
        hdf_path = os.path.join(test_data_path, "split_segments_3.hdf5")
        temp_path = copy_file(hdf_path)
        hdf = hdf_file(temp_path)

        segment_tuples = split_segments(hdf, {})

        #for a, e in zip(segment_tuples, expected):
            #print(a,e,a==e)

        self.assertEqual(segment_tuples,
                         [('START_AND_STOP', slice(0, 3989.0, None), 0),
                          ('START_AND_STOP', slice(3989.0, 7049.0, None), 1),
                          ('START_AND_STOP', slice(7049.0, 9569.0, None), 1),
                          ('START_AND_STOP', slice(9569.0, 12889.0, None), 1),
                          ('START_AND_STOP', slice(12889.0, 15867.0, None), 1),
                          ('START_AND_STOP', slice(15867.0, 18526.0, None), 3),
                          ('START_AND_STOP', slice(18526.0, 21726.0, None), 2),
                          ('START_AND_STOP', slice(21726.0, 24209.0, None), 2),
                          ('START_AND_STOP', slice(24209.0, 26607.0, None), 1),
                          ('START_AND_STOP', slice(26607.0, 28534.0, None), 3),
                          ('START_AND_STOP', slice(28534.0, 30875.0, None), 2),
                          ('START_AND_STOP', slice(30875.0, 33488.0, None), 3),
                          ('NO_MOVEMENT', slice(33488.0, 33680.0, None), 0),])
 def test_split_segments_multiple_types(self):
     '''
     Test data has multiple segments of differing segment types.
     Test data has already been validated
     '''
     hdf_path = os.path.join(test_data_path, "split_segments_multiple_types.hdf5")
     temp_path = copy_file(hdf_path)
     hdf = hdf_file(temp_path)
     self.maxDiff = None
     segment_tuples = split_segments(hdf)
     self.assertEqual(len(segment_tuples), 16, msg="Unexpected number of segments detected")
     segment_types = tuple(x[0] for x in segment_tuples)
     self.assertEqual(segment_types,
                      ('STOP_ONLY',
                       'START_ONLY',
                       'START_AND_STOP',
                       'START_AND_STOP',
                       'START_AND_STOP',
                       'START_AND_STOP',
                       'STOP_ONLY',
                       'START_AND_STOP',
                       'STOP_ONLY',
                       'START_ONLY',
                       'START_ONLY',
                       'START_AND_STOP',
                       'START_ONLY',
                       'START_AND_STOP',
                       'START_AND_STOP',
                       'START_ONLY'))
def main():
    print 'FlightDataSplitter (c) Copyright 2013 Flight Data Services, Ltd.'
    print '  - Powered by POLARIS'
    print '  - http://www.flightdatacommunity.com'
    print ''
    import argparse
    import pprint
    import tempfile
    from flightdatautilities.filesystem_tools import copy_file
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)    
    
    parser = argparse.ArgumentParser(description="Process a flight.")
    parser.add_argument('file', type=str,
                        help='Path of file to process.')
    parser.add_argument('-tail', dest='tail_number', type=str, default='G-FDSL',
                        help='Aircraft Tail Number for processing.')
    args = parser.parse_args()    
    hdf_copy = copy_file(args.file, dest_dir=tempfile.gettempdir(), postfix='_split')
    logger.info("Working on copy: %s", hdf_copy)
    segs = split_hdf_to_segments(hdf_copy,
                                 {'Tail Number': args.tail_number,},
                                 fallback_dt=datetime(2012,12,12,12,12,12),
                                 draw=False)
    pprint.pprint(segs)
 def test_split_segments_data_1(self):
     '''Splits on both DFC Jump and Engine parameters.'''
     hdf_path = os.path.join(test_data_path, "split_segments_1.hdf5")
     temp_path = copy_file(hdf_path)
     hdf = hdf_file(temp_path)
     segment_tuples = split_segments(hdf, {})
     self.assertEqual(segment_tuples,
                      [('START_AND_STOP', slice(0, 9952.0, None), 0),
                       ('START_AND_STOP', slice(9952.0, 21799.0, None), 0),
                       ('START_AND_STOP', slice(21799.0, 24665.0, None), 3),
                       ('START_AND_STOP', slice(24665.0, 27898.0, None), 1),
                       ('START_AND_STOP', slice(27898.0, 31424.0, None), 2)])
 def test_split_segments_data_1(self):
     '''Splits on both DFC Jump and Engine parameters.'''
     hdf_path = os.path.join(test_data_path, "split_segments_1.hdf5")
     temp_path = copy_file(hdf_path)
     hdf = hdf_file(temp_path)
     segment_tuples = split_segments(hdf, {})
     self.assertEqual(segment_tuples,
                      [('START_AND_STOP', slice(0, 9952.0, None), 0),
                       ('START_AND_STOP', slice(9952.0, 21799.0, None), 0),
                       ('START_AND_STOP', slice(21799.0, 24665.0, None), 3),
                       ('START_AND_STOP', slice(24665.0, 27898.0, None), 1),
                       ('START_AND_STOP', slice(27898.0, 31424.0, None), 2)])
    def test_split_segments_data_2(self):
        '''Splits on both DFC Jump and Engine parameters.'''
        hdf_path = os.path.join(test_data_path, "split_segments_2.hdf5")
        temp_path = copy_file(hdf_path)
        hdf = hdf_file(temp_path)

        segment_tuples = split_segments(hdf, {})
        self.assertEqual(segment_tuples,
                         [('START_AND_STOP', slice(0, 3407.0, None)),
                          ('START_AND_STOP', slice(3407.0, 6362.0, None)),
                          ('START_AND_STOP', slice(6362.0, 9912.0, None)),
                          ('START_AND_STOP', slice(9912.0, 13064.0, None)),
                          ('START_AND_STOP', slice(13064.0, 16467.0, None)),
                          ('START_AND_STOP', slice(16467.0, 19200.0, None))])
Exemplo n.º 9
0
def concat_hdf(hdf_paths, dest=None):
    '''
    Takes in a list of HDF file paths and concatenates the parameter
    datasets which match the path 'series/<Param Name>/data'. The first file
    in the list of paths is the template for the output file, with only the
    'series/<Param Name>/data' datasets being replaced with the concatenated
    versions.

    :param hdf_paths: File paths.
    :type hdf_paths: list of strings
    :param dest: optional destination path, which will be the first path in
                 'paths'
    :type dest: dict
    :return: path to concatenated hdf file.
    :rtype: str
    '''
    # copy hdf to temp area to build upon
    hdf_master_path = copy_file(hdf_paths[0])

    with hdf_file(hdf_master_path) as hdf_master:
        master_keys = hdf_master.keys()
        for hdf_path in hdf_paths[1:]:
            with hdf_file(hdf_path) as hdf:
                # check that all parameters match (avoids mismatching array lengths)
                param_keys = hdf.keys()
                assert set(param_keys) == set(master_keys)
                logging.debug("Copying parameters from file %s", hdf_path)
                for param_name in param_keys:
                    param = hdf[param_name]
                    master_param = hdf_master[param_name]
                    assert param.frequency == master_param.frequency
                    assert param.offset == master_param.offset
                    assert param.units == master_param.units
                    # join arrays together
                    master_param.array = np.ma.concatenate(
                        (master_param.raw_array, param.raw_array))
                    # re-save parameter
                    hdf_master[param_name] = master_param
                # extend the master's duration
                hdf_master.duration += hdf.duration
            #endwith
            logging.debug("Completed extending parameters from %s", hdf_path)
        #endfor
    #endwith

    if dest:
        shutil.move(hdf_master_path, dest)
        return dest
    else:
        return hdf_master_path
Exemplo n.º 10
0
def concat_hdf(hdf_paths, dest=None):
    '''
    Takes in a list of HDF file paths and concatenates the parameter
    datasets which match the path 'series/<Param Name>/data'. The first file
    in the list of paths is the template for the output file, with only the
    'series/<Param Name>/data' datasets being replaced with the concatenated
    versions.

    :param hdf_paths: File paths.
    :type hdf_paths: list of strings
    :param dest: optional destination path, which will be the first path in
                 'paths'
    :type dest: dict
    :return: path to concatenated hdf file.
    :rtype: str
    '''
    # copy hdf to temp area to build upon
    hdf_master_path = copy_file(hdf_paths[0])

    with hdf_file(hdf_master_path) as hdf_master:
        master_keys = hdf_master.keys()
        for hdf_path in hdf_paths[1:]:
            with hdf_file(hdf_path) as hdf:
                # check that all parameters match (avoids mismatching array lengths)
                param_keys = hdf.keys()
                assert set(param_keys) == set(master_keys)
                logging.debug("Copying parameters from file %s", hdf_path)
                for param_name in param_keys:
                    param = hdf[param_name]
                    master_param = hdf_master[param_name]
                    assert param.frequency == master_param.frequency
                    assert param.offset == master_param.offset
                    assert param.units == master_param.units
                    # join arrays together
                    master_param.array = np.ma.concatenate(
                        (master_param.raw_array, param.raw_array))
                    # re-save parameter
                    hdf_master[param_name] = master_param
                # extend the master's duration
                hdf_master.duration += hdf.duration
            #endwith
            logging.debug("Completed extending parameters from %s", hdf_path)
        #endfor
    #endwith

    if dest:
        shutil.move(hdf_master_path, dest)
        return dest
    else:
        return hdf_master_path
 def test_split_segments_data_2(self):
     '''Splits on both DFC Jump and Engine parameters.'''
     hdf_path = os.path.join(test_data_path, "split_segments_2.hdf5")
     temp_path = copy_file(hdf_path)
     hdf = hdf_file(temp_path)
     
     segment_tuples = split_segments(hdf)
     self.assertEqual(segment_tuples,
                      [('START_AND_STOP', slice(0, 3583.0, None)),
                       ('START_AND_STOP', slice(3583.0, 6446.0, None)),
                       ('START_AND_STOP', slice(6446.0, 9912.0, None)),
                       ('START_AND_STOP', slice(9912.0, 13064.0, None)),
                       ('START_AND_STOP', slice(13064.0, 16467.0, None)),
                       ('START_AND_STOP', slice(16467.0, 19200.0, None))])
    def test_split_segments_data_2(self):
        '''Splits on both DFC Jump and Engine parameters.'''
        hdf_path = os.path.join(test_data_path, "split_segments_2.hdf5")
        temp_path = copy_file(hdf_path)
        hdf = hdf_file(temp_path)

        segment_tuples = split_segments(hdf, {})
        self.assertEqual(segment_tuples,
                         [('START_AND_STOP', slice(0, 3407.0, None), 0),
                          ('START_AND_STOP', slice(3407.0, 6362.0, None), 15),
                          ('START_AND_STOP', slice(6362.0, 9912.0, None), 26),
                          ('START_AND_STOP', slice(9912.0, 13064.0, None), 56),
                          ('START_AND_STOP', slice(13064.0, 16467.0, None), 8),
                          ('START_AND_STOP', slice(16467.0, 19065.0, None), 19),
                          ('GROUND_ONLY', slice(19065.0, 19200.0, None), 57)])
    def test_split_segments_data_3(self):
        '''Splits on both Engine and Heading parameters.'''
        hdf_path = os.path.join(test_data_path, "split_segments_3.hdf5")
        temp_path = copy_file(hdf_path)
        hdf = hdf_file(temp_path)

        segment_tuples = split_segments(hdf, {})
        self.assertEqual(segment_tuples,
                         [('START_AND_STOP', slice(0, 3989.0, None)),
                          ('START_AND_STOP', slice(3989.0, 7049.0, None)),
                          ('START_AND_STOP', slice(7049.0, 9569.0, None)),
                          ('START_AND_STOP', slice(9569.0, 12889.0, None)),
                          ('START_AND_STOP', slice(12889.0, 15867.0, None)),
                          ('START_AND_STOP', slice(15867.0, 18526.0, None)),
                          ('START_AND_STOP', slice(18526.0, 21726.0, None)),
                          ('START_AND_STOP', slice(21726.0, 24209.0, None)),
                          ('START_AND_STOP', slice(24209.0, 26607.0, None)),
                          ('START_AND_STOP', slice(26607.0, 28534.0, None)),
                          ('START_AND_STOP', slice(28534.0, 30875.0, None)),
                          ('START_AND_STOP', slice(30875.0, 33680.0, None))])
 def test_split_segments_data_3(self):
     '''Splits on both Engine and Heading parameters.'''
     hdf_path = os.path.join(test_data_path, "split_segments_3.hdf5")
     temp_path = copy_file(hdf_path)
     hdf = hdf_file(temp_path)
     
     segment_tuples = split_segments(hdf)
     self.assertEqual(segment_tuples,
                      [('START_AND_STOP', slice(0, 3987.0, None)),
                       ('START_AND_STOP', slice(3987.0, 7049.0, None)),
                       ('START_AND_STOP', slice(7049.0, 9563.0, None)),
                       ('START_AND_STOP', slice(9563.0, 12921.0, None)),
                       ('START_AND_STOP', slice(12921.0, 15858.0, None)),
                       ('START_AND_STOP', slice(15858.0, 18526.0, None)),
                       ('START_AND_STOP', slice(18526.0, 21728.0, None)),
                       ('START_AND_STOP', slice(21728.0, 24208.0, None)),
                       ('START_AND_STOP', slice(24208.0, 26607.0, None)),
                       ('START_AND_STOP', slice(26607.0, 28534.0, None)),
                       ('START_AND_STOP', slice(28534.0, 30875.0, None)),
                       ('START_AND_STOP', slice(30875.0, 33680.0, None))])
Exemplo n.º 15
0
def main():
    args, parser = parse_cmdline()

    if not args.quiet:
        print 'FlightDataSplitter (c) Copyright 2013 Flight Data Services, ' \
            'Ltd.'
        print '  - Powered by POLARIS'
        print '  - http://www.flightdatacommunity.com'
        print

    import os
    from analysis_engine.utils import get_aircraft_info
    from flightdatautilities.filesystem_tools import copy_file

    logger = logging.getLogger()
    logger.setLevel(args.log_level_number)

    ac_info = get_aircraft_info(args.tail_number)
    hdf_copy = copy_file(args.file, postfix='_split')
    logger.info("Working on copy: %s", hdf_copy)
    segments = split_hdf_to_segments(
        hdf_copy,
        ac_info,
        fallback_dt=args.fallback_datetime,
        validation_dt=args.validation_datetime,
        fallback_relative_to_start=False,
        draw=False)

    # Rename the segment filenames to be able to use glob()
    for segment in segments:
        dir, fn = os.path.split(segment.path)
        name, ext = os.path.splitext(fn)
        new_fn = '-'.join((name, 'SEGMENT', segment.type)) + ext
        new_path = os.path.join(dir, new_fn)
        os.rename(segment.path, new_path)
        segment.path = new_path

    if not args.quiet:
        import pprint
        pprint.pprint(segments)
    def test_split_segments_multiple_types(self, settings):
        '''
        Test data has multiple segments of differing segment types.
        Test data has already been validated
        '''
        # Overriding MINIMUM_FAST_DURATION.
        settings.AIRSPEED_THRESHOLD = 80
        settings.AIRSPEED_THRESHOLD_TIME = 3 * 60
        settings.HEADING_CHANGE_TAXI_THRESHOLD = 60
        settings.MINIMUM_SPLIT_DURATION = 100
        settings.MINIMUM_FAST_DURATION = 0
        settings.MINIMUM_SPLIT_PARAM_VALUE = 0.175
        settings.HEADING_RATE_SPLITTING_THRESHOLD = 0.1
        settings.MAX_TIMEBASE_AGE = 365 * 10
        settings.MIN_FAN_RUNNING = 10

        hdf_path = os.path.join(test_data_path, "split_segments_multiple_types.hdf5")
        temp_path = copy_file(hdf_path)
        hdf = hdf_file(temp_path)
        self.maxDiff = None
        segment_tuples = split_segments(hdf, {})
        self.assertEqual(len(segment_tuples), 16, msg="Unexpected number of segments detected")
        segment_types = tuple(x[0] for x in segment_tuples)
        self.assertEqual(segment_types,
                         ('STOP_ONLY',
                          'START_ONLY',
                          'START_AND_STOP',
                          'START_AND_STOP',
                          'START_AND_STOP',
                          'START_AND_STOP',
                          'STOP_ONLY',
                          'START_AND_STOP',
                          'STOP_ONLY',
                          'START_ONLY',
                          'START_ONLY',
                          'START_AND_STOP',
                          'START_ONLY',
                          'START_AND_STOP',
                          'START_AND_STOP',
                          'START_ONLY'))
def main():
    args, parser = parse_cmdline()

    if not args.quiet:
        print(
            'FlightDataSplitter (c) Copyright 2013 Flight Data Services, Ltd.')
        print('  - Powered by POLARIS')
        print('  - http://www.flightdatacommunity.com')
        print()

    import os
    from analysis_engine.utils import get_aircraft_info
    from flightdatautilities.filesystem_tools import copy_file

    logger = logging.getLogger()
    logger.setLevel(args.log_level_number)

    ac_info = get_aircraft_info(args.tail_number)
    hdf_copy = copy_file(args.file, postfix='_split')
    logger.info("Working on copy: %s", hdf_copy)
    segments = split_hdf_to_segments(hdf_copy,
                                     ac_info,
                                     fallback_dt=args.fallback_datetime,
                                     validation_dt=args.validation_datetime,
                                     fallback_relative_to_start=False,
                                     draw=False)

    # Rename the segment filenames to be able to use glob()
    for segment in segments:
        dir, fn = os.path.split(segment.path)
        name, ext = os.path.splitext(fn)
        new_fn = '-'.join((name, 'SEGMENT', segment.type)) + ext
        new_path = os.path.join(dir, new_fn)
        os.rename(segment.path, new_path)
        segment.path = new_path

    if not args.quiet:
        import pprint
        pprint.pprint(segments)
Exemplo n.º 18
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)
Exemplo n.º 19
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)
Exemplo n.º 20
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 = 'Write CSV of processing results. Set "False" to disable.'
    parser.add_argument('-csv', dest='write_csv', type=str, default='True', 
                        help=help)
    help = 'Write KML of flight track. Set "False" to disable.'
    parser.add_argument('-kml', dest='write_kml', type=str, default='True', 
                        help=help)
    parser.add_argument('-r', '--requested', type=str, nargs='+', dest='requested',
                        default=[], help='Requested nodes.')
    parser.add_argument('--required', type=str, nargs='+', dest='required',
                        default=[], help='Required nodes.')
    parser.add_argument('-tail', dest='tail_number',
                        default='G-FDSL', # as per flightdatacommunity file
                        help='Aircraft tail number.')
    
    # 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.')
    
    args = parser.parse_args()
    aircraft_info = {}
    if args.aircraft_model:
        aircraft_info['Model'] = args.aircraft_model
    if args.aircraft_family:
        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')
    res = process_flight(
        hdf_copy, args.tail_number, aircraft_info=aircraft_info,
        requested=args.requested, required=args.required)
    logger.info("Derived parameters stored in hdf: %s", hdf_copy)
    # Write CSV file
    if args.write_csv.lower() == 'true':
        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 args.write_kml.lower() == 'true':
        kml_dest = os.path.splitext(hdf_copy)[0] + '.kml'
        track_to_kml(hdf_copy, res['kti'], res['kpv'], res['approach'], 
                     plot_altitude='Altitude QNH', dest_path=kml_dest)
        logger.info("Flight Track with attributes writen to kml: %s", kml_dest)
 def setUp(self):
     hdf_path = os.path.join(DATA_PATH, 'Specimen_Flight.hdf5')
     tmp_path = os.path.join(DATA_PATH, 'temp')
     self.data_path = copy_file(hdf_path, dest_dir=tmp_path)
 def setUp(self):
     hdf_path = os.path.join(DATA_PATH, 'Specimen_Flight.hdf5')
     tmp_path = os.path.join(DATA_PATH, 'temp')
     self.data_path = copy_file(hdf_path, dest_dir=tmp_path)