예제 #1
0
파일: excel2task.py 프로젝트: kant/pycondor
def main(xls_filename, output, outdir, disp):
    basepath = os.path.dirname(__file__)
    #basepath = os.path.dirname(os.path.abspath(__file__))
    if outdir == '':
        outdir = os.path.join(basepath, 'out')
    xls_filename = xls_filename.format(**paths_default)
    outdir = outdir.format(**paths_default)
    for filename in glob.glob(xls_filename):
        print("Read '%s'" % filename)

        filename_base, filename_ext = os.path.splitext(
            os.path.basename(filename))

        df_task = pd.read_excel(filename)
        #print(df_task)
        #print(df_task.dtypes)
        d_convert = {
            "PosX": decimal.Decimal,
            "PosY": decimal.Decimal,
            "PosZ": decimal.Decimal,
            "Airport": int,
            "SectorType": int,
            "Radius": decimal.Decimal,
            "Angle": decimal.Decimal,
            "Altitude": decimal.Decimal,
            "Width": decimal.Decimal,
            "Height": decimal.Decimal,
            "Azimuth": decimal.Decimal,
        }
        for col, typ in d_convert.items():
            df_task[col] = df_task[col].astype(typ)

        settings_task = SettingsTask()

        df_task["Comment"] = ""
        df_task["Wpt_id"] = df_task.index.map(lambda i: "_" + str(i))

        df_task = add_distance_bearing(df_task)
        df_task = add_observation_zone(settings_task, df_task)

        if disp:
            print(df_task)
            print(df_task.dtypes)
            print("")

        output_task_from_df(df_task, filename_base, output, outdir, disp)
예제 #2
0
def main(xls_filename, output, outdir, disp):
    basepath = os.path.dirname(__file__)
    #basepath = os.path.dirname(os.path.abspath(__file__))
    if outdir=='':
        outdir = os.path.join(basepath, 'out')
    xls_filename = xls_filename.format(**paths_default)
    outdir = outdir.format(**paths_default)
    for filename in glob.glob(xls_filename):
        print("Read '%s'" % filename)

        filename_base, filename_ext = os.path.splitext(os.path.basename(filename))
    
        df_task = pd.read_excel(filename)
        #print(df_task)
        #print(df_task.dtypes)
        d_convert = {
            "PosX": decimal.Decimal,
            "PosY": decimal.Decimal,
            "PosZ": decimal.Decimal,
            "Airport": int,
            "SectorType": int,
            "Radius": decimal.Decimal,
            "Angle": decimal.Decimal,
            "Altitude": decimal.Decimal,
            "Width": decimal.Decimal,
            "Height": decimal.Decimal,
            "Azimuth": decimal.Decimal,
        }
        for col, typ in d_convert.items():
            df_task[col] = df_task[col].astype(typ)

        settings_task = SettingsTask()

        df_task["Comment"] = ""
        df_task["Wpt_id"] = df_task.index.map(lambda i: "_" + str(i))

        df_task = add_distance_bearing(df_task)
        df_task = add_observation_zone(settings_task, df_task)

        if disp:
            print(df_task)
            print(df_task.dtypes)
            print("")

        output_task_from_df(df_task, filename_base, output, outdir, disp)
예제 #3
0
def main(debug, fpl_filename, output, outdir, condor_path, landscape, disp,
         fixencoding, encoding_in, encoding_errors):
    basepath = os.path.dirname(__file__)
    #basepath = os.path.dirname(os.path.abspath(__file__))

    if outdir == '':
        outdir = os.path.join(basepath, 'out')
    if condor_path == '':
        condor_path = paths_default['Condor']

    # Translate path like {Condor} using paths_default
    d_name = paths_default.copy()
    d_name['output'] = output
    fpl_filename = fpl_filename.format(**d_name)
    outdir = outdir.format(**d_name)

    if not os.path.exists(outdir):
        print("Create directory %s" % outdir)
        os.makedirs(outdir)

    lst_errors = []
    d_landscapes = {}
    d_landscapes_missing = {}
    filenames = glob.glob(fpl_filename)
    N_filenames = len(filenames)
    #i = -1
    navicon_dll = NaviConDLL(condor_path)

    print("")
    print("=" * 20)
    print("")

    for i, filename in enumerate(filenames):
        try:
            logging.info("Read file %03d/%03d '%s'" %
                         (i + 1, N_filenames, filename))

            filename_base, filename_ext = os.path.splitext(
                os.path.basename(filename))
            if debug:
                assert filename_ext in supported_input_extensions, \
                "File extension of '%s' is '%s' but supported extension must be in %s" \
                % (filename, filename_ext, supported_input_extensions)

            config = configparser.ConfigParser()
            #with open(filename, 'r') as fd: # fix \xef\xbb[Version]\n
            config.read(filename)
            try:
                condor_version = config.get('Version', 'Condor version')
            except:
                logging.error("Can't get 'Version/Condor version'")
                condor_version = None
            if debug:
                assert condor_version in supported_versions, \
                    "[Version] Condor version '%s' is not a supported version - must be in %s" \
                    % (condor_version, supported_versions)

            print("Condor version: %s" % condor_version)

            if landscape == '':  # =landscape_forced
                fpl_landscape = config.get('Task', 'Landscape')
                if fpl_landscape not in d_landscapes.keys():
                    d_landscapes[fpl_landscape] = set()
                d_landscapes[fpl_landscape].add(filename_base)

            df_task = create_task_dataframe(config)

            try:
                navicon_dll.init(fpl_landscape)
            except:
                if fpl_landscape not in d_landscapes_missing.keys():
                    d_landscapes_missing[fpl_landscape] = set()
                d_landscapes_missing[fpl_landscape].add(filename_base)
                raise (Exception("Can't init %s" % fpl_landscape))

            max_x, max_y = navicon_dll.xy_max()

            if disp:
                print("MaxX: %f" % max_x)
                print("MaxY: %f" % max_y)

                (x, y) = (0, 0)
                (lat, lon) = navicon_dll.xy_to_lat_lon(x, y)
                print("XYToLat(%f,%f): %f" % (x, y, lat))
                print("XYToLon(%f,%f): %f" % (x, y, lon))

                (x, y) = (max_x, 0)
                (lat, lon) = navicon_dll.xy_to_lat_lon(x, y)
                print("XYToLat(%f,%f): %f" % (x, y, lat))
                print("XYToLon(%f,%f): %f" % (x, y, lon))

                (x, y) = (max_x, max_y)
                (lat, lon) = navicon_dll.xy_to_lat_lon(x, y)
                print("XYToLat(%f,%f): %f" % (x, y, lat))
                print("XYToLon(%f,%f): %f" % (x, y, lon))

                (x, y) = (0, max_y)
                (lat, lon) = navicon_dll.xy_to_lat_lon(x, y)
                print("XYToLat(%f,%f): %f" % (x, y, lat))
                print("XYToLon(%f,%f): %f" % (x, y, lon))

                print("")

            df_task["Lat"] = 0.0
            df_task["Lon"] = 0.0

            for j, tp in df_task.iterrows():
                pos_x, pos_y = tp['PosX'], tp['PosY']
                (lat, lon) = navicon_dll.xy_to_lat_lon(pos_x, pos_y)
                df_task.loc[j, 'Lat'] = lat
                df_task.loc[j, 'Lon'] = lon

            settings_task = SettingsTask()

            #df_task["Comment"] = ""
            #df_task["Wpt_id"] = df_task.index.map(lambda i: "_" + str(i))

            df_task = add_distance_bearing(df_task)
            df_task = add_observation_zone(settings_task, df_task)

            if fixencoding:
                df_task['Name'] = df_task['Name'].map(
                    lambda s: s.decode(encoding_in, errors=encoding_errors))

            if disp:
                print(df_task)
                #print(df_task.dtypes)
            print("Waypoints: %d" % len(df_task))

            output_task_from_df(df_task, filename_base, output, outdir, disp)

            plt.show()

        except:
            logging.error(traceback.format_exc())
            lst_errors.append(filename)

        print("")
        print("=" * 20)
        print("")

    #N_filenames = i + 1
    N_error = len(lst_errors)
    print("Convert %d files - %d errors" % (N_filenames, N_error))
    for i, filename_error in enumerate(lst_errors):
        print(" * %03d / %03d: %s" % (i + 1, N_error, filename_error))
    print("Landscapes (from fpl):")

    import pprint

    p = pprint.PrettyPrinter(indent=4)
    p.pprint(d_landscapes)

    print("")
    if len(d_landscapes_missing) > 0:
        print("Missing landscapes (from fpl):")
        p.pprint(d_landscapes_missing)
예제 #4
0
def main(debug, fpl_filename, output, outdir, condor_path,
        landscape, disp, fixencoding, encoding_in, encoding_errors):
    basepath = os.path.dirname(__file__)
    #basepath = os.path.dirname(os.path.abspath(__file__))
    
    if outdir=='':
        outdir = os.path.join(basepath, 'out')
    if condor_path=='':
        condor_path = paths_default['Condor']
    
    # Translate path like {Condor} using paths_default
    d_name = paths_default.copy()
    d_name['output'] = output
    fpl_filename = fpl_filename.format(**d_name)
    outdir = outdir.format(**d_name)
    
    if not os.path.exists(outdir):
        print("Create directory %s" % outdir)
        os.makedirs(outdir)
    
    lst_errors = []
    d_landscapes = {}
    d_landscapes_missing = {}
    filenames = glob.glob(fpl_filename)
    N_filenames = len(filenames)
    #i = -1
    navicon_dll = NaviConDLL(condor_path)

    print("")
    print("="*20)
    print("")    
    
    for i, filename in enumerate(filenames):
        try:
            logging.info("Read file %03d/%03d '%s'" % (i+1, N_filenames, filename))

            filename_base, filename_ext = os.path.splitext(os.path.basename(filename))
            if debug:        
                assert filename_ext in supported_input_extensions, \
                "File extension of '%s' is '%s' but supported extension must be in %s" \
                % (filename, filename_ext, supported_input_extensions)

            config = configparser.ConfigParser()
            #with open(filename, 'r') as fd: # fix \xef\xbb[Version]\n
            config.read(filename)
            try:
                condor_version = config.get('Version', 'Condor version')
            except:
                logging.error("Can't get 'Version/Condor version'")
                condor_version = None
            if debug:
                assert condor_version in supported_versions, \
                    "[Version] Condor version '%s' is not a supported version - must be in %s" \
                    % (condor_version, supported_versions)

            print("Condor version: %s" % condor_version)
        
            if landscape=='':  # =landscape_forced
                fpl_landscape = config.get('Task', 'Landscape')
                if fpl_landscape not in d_landscapes.keys():
                    d_landscapes[fpl_landscape] = set()
                d_landscapes[fpl_landscape].add(filename_base)

            df_task = create_task_dataframe(config)
        
            try:
                navicon_dll.init(fpl_landscape)
            except:
                if fpl_landscape not in d_landscapes_missing.keys():
                    d_landscapes_missing[fpl_landscape] = set()
                d_landscapes_missing[fpl_landscape].add(filename_base)
                raise(Exception("Can't init %s" % fpl_landscape))

            max_x, max_y = navicon_dll.xy_max()
        
            if disp:
                print("MaxX: %f" % max_x)
                print("MaxY: %f" % max_y)

                (x, y) = (0, 0)
                (lat, lon) = navicon_dll.xy_to_lat_lon(x, y)
                print("XYToLat(%f,%f): %f" % (x, y, lat))
                print("XYToLon(%f,%f): %f" % (x, y, lon))
            
                (x, y) = (max_x, 0)
                (lat, lon) = navicon_dll.xy_to_lat_lon(x, y)
                print("XYToLat(%f,%f): %f" % (x, y, lat))
                print("XYToLon(%f,%f): %f" % (x, y, lon))

                (x, y) = (max_x, max_y)
                (lat, lon) = navicon_dll.xy_to_lat_lon(x, y)
                print("XYToLat(%f,%f): %f" % (x, y, lat))
                print("XYToLon(%f,%f): %f" % (x, y, lon))

                (x, y) = (0, max_y)
                (lat, lon) = navicon_dll.xy_to_lat_lon(x, y)
                print("XYToLat(%f,%f): %f" % (x, y, lat))
                print("XYToLon(%f,%f): %f" % (x, y, lon))

                print("")
        
            df_task["Lat"] = 0.0
            df_task["Lon"] = 0.0
        
            for j, tp in df_task.iterrows():
                pos_x, pos_y = tp['PosX'], tp['PosY']
                (lat, lon) = navicon_dll.xy_to_lat_lon(pos_x, pos_y)
                df_task.loc[j,'Lat'] = lat
                df_task.loc[j,'Lon'] = lon
            
            settings_task = SettingsTask()

            #df_task["Comment"] = ""
            #df_task["Wpt_id"] = df_task.index.map(lambda i: "_" + str(i))

            df_task = add_distance_bearing(df_task)
            df_task = add_observation_zone(settings_task, df_task)
            
            if fixencoding:
                df_task['Name'] = df_task['Name'].map(lambda s: s.decode(encoding_in, errors=encoding_errors))
            
            if disp:
                print(df_task)
                #print(df_task.dtypes)
            print("Waypoints: %d" % len(df_task))
        
            output_task_from_df(df_task, filename_base, output, outdir, disp)

            plt.show()

        except:
            logging.error(traceback.format_exc())
            lst_errors.append(filename)

        print("")
        print("="*20)
        print("")
        
    #N_filenames = i + 1
    N_error = len(lst_errors)
    print("Convert %d files - %d errors" % (N_filenames, N_error))
    for i, filename_error in enumerate(lst_errors):
        print(" * %03d / %03d: %s" % (i+1, N_error, filename_error))
    print("Landscapes (from fpl):")

    import pprint
    
    p = pprint.PrettyPrinter(indent=4)
    p.pprint(d_landscapes)

    print("")
    if len(d_landscapes_missing) > 0:
        print("Missing landscapes (from fpl):")
        p.pprint(d_landscapes_missing)