Пример #1
0
def finder_csv(loci_excel, csv_name, h_excel, added_point, output_excel,
               output_fig):
    """
            Function returns dataframe with mapped values.
        """
    FILE_PTH_INPUT_1 = common.get_local_file_path_withfolder(
        file_name=loci_excel, folder_name='Excel')
    #FILE_PTH_INPUT_2 = common.get_local_file_path_withfolder(file_name=scan_excel, folder_name='dig_results')
    FILE_PTH_INPUT_3 = common.get_local_file_path_withfolder(
        file_name=h_excel, folder_name='Excel')
    FILE_PTH_OUTPUT_1 = common.get_local_file_path_withfolder(
        file_name=output_excel, folder_name='Output_excel')
    #FILE_PTH_OUTPUT_2 = common.get_local_file_path_withfolder(file_name=output_fig, folder_name='plots')

    loci_df = common.import_excel(FILE_PTH_INPUT_1)

    scan_df = CSV_reader_df_maker(
        csv_name=csv_name,
        csv_folder_name=constants.folder_file_names.dig_result_folder,
        object_name=constants.Digsilent.object_name,
        param_name_list=constants.Digsilent.param_name_list,
        header_list=constants.Digsilent.header_list,
        number_or_name=constants.Digsilent.number_or_name_toggle,
        param_number_list=constants.Digsilent.param_number_list)

    # csv_name, csv_folder_name, object_name, param_name_list, header_list

    #scan_df = common.import_excel(FILE_PTH_INPUT_2)
    h_df = common.import_excel(FILE_PTH_INPUT_3)

    h_df_len = len(h_df)
    loci_num = int((len(loci_df.columns)) / 2)
    df_list = list()
    range_list = list()

    # if h_df_len > 0:
    #     idx = (scan_df['H'].isin(h_df['H'].tolist()))  # filters the buses that have GSPs inside the given GSP list
    #     scan_df = scan_df.loc[idx == True, :]

    scan_df['Loci Range'] = np.nan
    scan_df['worst_V_R'] = np.nan
    scan_df['worst_V_L'] = np.nan
    scan_df['worst_V_X'] = np.nan
    scan_df['worst_I_R'] = np.nan
    scan_df['worst_I_L'] = np.nan
    scan_df['worst_I_X'] = np.nan

    for i in range(0, int(loci_num) * 2, 2):
        df = loci_df.iloc[1:, [i, i + 1]]
        df_list.append(df)
        range_list.append(df.columns)

    for i in range(1, len(scan_df) + 1):
        h = float(scan_df.loc[i, 'H'])
        for r in range(0, loci_num):
            cur_range = range_list[r]
            if h >= cur_range[0]:
                if h <= cur_range[1]:
                    scan_df.loc[i, 'Loci Range'] = r

    for i in range(1, len(scan_df) + 1):
        loci_cur = df_list[int(scan_df.loc[i, 'Loci Range'])]
        loci_cur_new = point_adder(loci=loci_cur, p_num=added_point)
        r_w = scan_df.loc[i, 'R']
        x_w = scan_df.loc[i, 'X']
        R_worst_v, X_worst_v, R_worst_i, X_worst_i = worst_point(
            loci=loci_cur_new, R=r_w, X=x_w)
        if constants.plotting.save_plot:
            fig_title = 'h=' + str(scan_df.loc[i, 'H'])
            plot_name = output_fig + str(
                scan_df.loc[i, 'H']) + constants.plotting.figure_type
            FILE_PTH_OUTPUT_2 = common.get_local_file_path_withfolder(
                file_name=plot_name, folder_name=constants.plotting.folder)

            plotter.loci_scatter_plotter(loci_df=loci_cur_new,
                                         R=r_w,
                                         X=x_w,
                                         R_V=R_worst_v,
                                         X_V=X_worst_v,
                                         R_I=R_worst_i,
                                         X_I=X_worst_i,
                                         save_o=constants.plotting.save_plot,
                                         p_show=constants.plotting.show_plot,
                                         fig_path=FILE_PTH_OUTPUT_2,
                                         fig_name=fig_title)
            k = 1

        scan_df.loc[i, 'worst_V_R'] = R_worst_v
        scan_df.loc[i, 'worst_V_X'] = X_worst_v
        scan_df.loc[i, 'worst_I_R'] = R_worst_i
        scan_df.loc[i, 'worst_I_X'] = X_worst_i
        scan_df.loc[
            i, 'worst_V_L'] = (X_worst_v /
                               (2 * math.pi * 60 * scan_df.loc[i, 'H'])) * 1000
        scan_df.loc[
            i, 'worst_I_L'] = (X_worst_i /
                               (2 * math.pi * 60 * scan_df.loc[i, 'H'])) * 1000

    if h_df_len > 0:
        idx = (scan_df['H'].isin(h_df['H'].tolist())
               )  # filters the buses that have GSPs inside the given GSP list
        scan_df = scan_df.loc[idx == True, :]

    scan_df.to_excel(FILE_PTH_OUTPUT_1)

    return scan_df
Пример #2
0
    #FILE_NAME_OUTPUT_1 = 'intact.xlsx'
    # FILE_PTH_INPUT_1 = common.get_local_file_path_withfolder(file_name=FILE_NAME_INPUT_1, folder_name='Excel')
    # FILE_PTH_INPUT_2 = common.get_local_file_path_withfolder(file_name=FILE_NAME_INPUT_2, folder_name='dig_results')
    FILE_PTH_INPUT_3 = common.get_local_file_path_withfolder(
        file_name=FILE_NAME_INPUT_3, folder_name='Excel')
    FILE_PTH_INPUT_4 = common.get_local_file_path_withfolder(
        file_name=FILE_NAME_INPUT_4, folder_name='dig_results')
    FILE_PTH_INPUT_6 = common.get_local_file_path_withfolder(
        file_name=FILE_NAME_INPUT_6, folder_name='dig_results')

    # FILE_PTH_OUTPUT_1 = common.get_local_file_path_withfolder(file_name=FILE_NAME_OUTPUT_1, folder_name='Output_excel')
    point_number = 20

    # loci_df = common.import_excel(FILE_PTH_INPUT_1)
    # scan_df = common.import_excel(FILE_PTH_INPUT_2)
    h_df = common.import_excel(FILE_PTH_INPUT_3)
    h_df_len = len(h_df)
    sc_df = common.import_excel(FILE_PTH_INPUT_4)
    sc_dig_df = common.import_excel(FILE_PTH_INPUT_6)

    scenario_list = list(sc_df['scenario'])
    scenario_dig_list = list(sc_dig_df['scenario'])

    if csv_or_excel:
        sc_num = len(sc_dig_df)
        output_fig_list = [
            '{}_{}'.format(x, constants.plotting.string_added)
            for x in scenario_dig_list
        ]
    else:
        sc_num = len(sc_df)
Пример #3
0
    if p_show==True:
        plt.show()

    plt.close()

    return



if __name__ == '__main__':

    FILE_NAME_INPUT_1 = 'loci_test.xlsx'
    FILE_NAME_INPUT_2='test_plot.png'
    #FILE_NAME_INPUT_2 = 'intact_scan.xlsx'
    r, x, r_v, x_v, r_i, x_i=13.320539,-73.3139,25,48,12.23809524,41.19047619
    plot_name='h=2'
    FILE_PTH_INPUT_1 = common.get_local_file_path_withfolder(file_name=FILE_NAME_INPUT_1, folder_name='Excel')
    FILE_PTH_INPUT_2 = common.get_local_file_path_withfolder(file_name=FILE_NAME_INPUT_2, folder_name='plots')
    loci=common.import_excel(FILE_PTH_INPUT_1)
    save=True
    figure_show=True

    loci_scatter_plotter(loci_df=loci,R=r,X=x,R_V=r_v,X_V=x_v,R_I=r_i,X_I=x_i,save_o=save,p_show=figure_show,fig_path=FILE_PTH_INPUT_2,
    fig_name='h=2')




    # scan_df_new=CSV_reader_df_maker(csv_name=FILE_NAME_INPUT_5,csv_folder_name=dig_results_folder,
    #                                 object_name=object_name_dig,param_name_list=param_name_list_dig,header_list=header_list_new)
Пример #4
0
    y_points = (random.sample(range(upper_limit), number_points))

    corners = find_convex_vertices(
        x_values=x_points,
        y_values=y_points,
        max_vertices=constants.LociInputs.unlimited_identifier)

    # Confirm all points lie within the Polygon returned by the vertices
    polygon = shapely.geometry.polygon.Polygon(list(zip(*corners)))
    rand_point = random.randint(0, number_points - 1)
    point = shapely.geometry.Point(x_points[rand_point], y_points[rand_point])

    if PLOT_FIGURES:
        matplotlib.pyplot.plot(x_points, y_points, 'o')

        matplotlib.pyplot.plot(corners[0], corners[1], 'r--')
        matplotlib.pyplot.show()

    FILE_PTH_INPUT_1 = common.get_local_file_path_withfolder(
        file_name=FILE_NAME_INPUT_1, folder_name='dig_results')
    sc_dig_df = common.import_excel(FILE_PTH_INPUT_1)
    scenario_dig_list = list(sc_dig_df['scenario'])
    output_excel_dig_list = [
        '{}_{}'.format(x, 'points.xlsx') for x in scenario_dig_list
    ]
    scenario_dig_list_V = ['{}_{}'.format(x, 'V') for x in scenario_dig_list]
    scenario_dig_list_I = ['{}_{}'.format(x, 'I') for x in scenario_dig_list]
    dig_scenarios = scenario_dig_list_V + scenario_dig_list_I

    pf_version = '2020'
Пример #5
0
def loader(scenario_list, project):
    """
            Function returns dataframe with mapped values.
        """
    sc_num = len(scenario_list)
    #import powerfactory
    app = powerfactory.GetApplication()

    print('PowerFactory Opened')

    # activate project
    project = app.ActivateProject(project)
    prj = app.GetActiveProject()

    for i in range(0, sc_num):
        scenario_name = scenario_list[i]
        size = len(scenario_name)
        # # Slice string to remove last 3 characters from string
        new_str = scenario_name[:size - 2]
        excel_file_name = new_str + '_points.xlsx'
        excel_file_path = common.get_local_file_path_withfolder(
            file_name=excel_file_name, folder_name='Output_excel')
        points_df = common.import_excel(excel_file_path)
        L_points_I = points_df.loc[:, 'worst_I_L']
        R_points_I = points_df.loc[:, 'worst_I_R']
        L_points_V = points_df.loc[:, 'worst_V_L']
        R_points_V = points_df.loc[:, 'worst_V_R']
        L_I = L_points_I.tolist()
        R_I = R_points_I.tolist()
        L_V = L_points_V.tolist()
        R_V = R_points_V.tolist()

        k = 1

        folders = prj.GetContents('*.IntPrjfolder')
        temp_filtered = filter(
            lambda folders: folders.loc_name == 'Study Cases', folders)
        studyCases_folder = list(temp_filtered)
        studyCases = studyCases_folder[0].GetContents('*.IntCase')
        temp_filtered = filter(lambda folders: folders.loc_name == 'Library',
                               folders)
        Library = list(temp_filtered)
        Library_temp = Library[0]
        Library_subfolders = Library_temp.GetContents('*.')
        temp_filtered = filter(
            lambda Library_subfolders: Library_subfolders.loc_name ==
            'Operational Library', Library_subfolders)
        oper_folder = list(temp_filtered)
        oper_temp = oper_folder[0]
        oper_subfolders = oper_temp.GetContents('*.')
        temp_filtered = filter(
            lambda oper_subfolders: oper_subfolders.loc_name ==
            'Characteristics', oper_subfolders)
        char_folder = list(temp_filtered)
        char_temp = char_folder[0]
        char_subfolders = char_temp.GetContents('*.')

        # temp_filtered = filter(lambda char_subfolders: char_subfolders.loc_name == 'Oyster Creek 800MW',
        #                        char_subfolders)

        temp_filtered = filter(
            lambda char_subfolders: char_subfolders.loc_name ==
            'BL England 400MW', char_subfolders)

        scen_folder = list(temp_filtered)
        scen_temp = scen_folder[0]
        scen_subfolders = scen_temp.GetContents('*.')
        temp_filtered = filter(
            lambda scen_subfolders: scen_subfolders.loc_name == scenario_name,
            scen_subfolders)
        scen_param_folder = list(temp_filtered)
        scen_param_temp = scen_param_folder[0]
        scen_param_subvalues = scen_param_temp.GetContents('*.')
        # studyCases = folders[4].GetContents('*.IntCase')
        temp_filtered_L = filter(
            lambda scen_param_subvalues: scen_param_subvalues.loc_name == 'L',
            scen_param_subvalues)
        temp_filtered_R = filter(
            lambda scen_param_subvalues: scen_param_subvalues.loc_name == 'R',
            scen_param_subvalues)
        L = list(temp_filtered_L)
        R = list(temp_filtered_R)
        if scenario_name.endswith('_V'):
            L[0].vector = L_V
            R[0].vector = R_V
        if scenario_name.endswith('_I'):
            L[0].vector = L_I
            R[0].vector = R_I
        k = 1

    k = 1

    return k