Commit 190b562c authored by Leon Pyka's avatar Leon Pyka
Browse files

updating plotting function

parent b57caef2
Loading
Loading
Loading
Loading
+15 −15
Original line number Diff line number Diff line
@@ -49,9 +49,9 @@ def get_vertical_edges_coordinates(edge_list, nx, ny):
        edges_coordinates_array.append(run_list)
    return edges_coordinates_array

def get_data_dict(filepaths_dict : dict[int, str]) -> dict[int, list]:
def get_data_dict(filepaths_dict : dict[str, str]) -> dict[str, list]:
    offset_data_dict = {}
    for offset, filepath in filepaths_dict.items():
    for realization, filepath in filepaths_dict.items():
        if isinstance(filepath, list):
            broken_edges = []
            for filepath_i in filepath:
@@ -59,7 +59,7 @@ def get_data_dict(filepaths_dict : dict[int, str]) -> dict[int, list]:
                broken_edges.append(*current_broken_edges)
        else:
            broken_edges = get_broken_edges(filepath)
        offset_data_dict[offset] = broken_edges
        offset_data_dict[realization] = broken_edges
    return offset_data_dict

def get_average_heights_dict(run_list : list[list[int]]):
@@ -109,13 +109,13 @@ def plot_distribution_of_height(edges_coordinates_dict : dict[int, list[list[int
    fig, axs = plt.subplots(depth,width)
    fig.tight_layout(pad=1.0)
    edges_coordinates_dict_flat = flatten_dict(edges_coordinates_dict)
    for i, (offset, edges_coordinates) in  enumerate(edges_coordinates_dict_flat.items()): 
    for i, (realization, edges_coordinates) in  enumerate(edges_coordinates_dict_flat.items()): 
        index = get_index(i, graph_num, width)
        z_list = [ min(edge[2], edge[5]) for edge in edges_coordinates]
        z_min = min(z_list)
        z_max = max(z_list)
        z_range = z_max - z_min
        axs[index].set_title(f"Offset {offset}")
        axs[index].set_title(f"{realization}")
        axs[index].hist(z_list, bins=z_range+1)
        axs[index].set_xlabel("z position")
        axs[index].set_ylabel("Broken edges")
@@ -126,14 +126,14 @@ def plot_average_per_height(average_heights_dict):
    fig, axs = plt.subplots(depth, width)
    
    fig.tight_layout(pad=1.0)
    for i, offset in enumerate(average_heights_dict.keys()):
    for i, realization in enumerate(average_heights_dict.keys()):
        index = get_index(i, graph_num, width)
        for height, subdict in average_heights_dict[offset].items():
        for height, subdict in average_heights_dict[realization].items():
            #axs[index].plot(int(height), subdict['avg'], "_")
            axs[index].errorbar(int(height), subdict['avg'], yerr = subdict['yerror'], fmt='o' ,color = 'black')
            axs[index].set_xlabel("Height")
            axs[index].set_ylabel("Average number of broken edges")
            axs[index].set_title(f"Offset {offset}")
            axs[index].set_title(f"{realization}")
    plt.show()
    fig.savefig("avg_broken_edges_at_height.png")

@@ -181,8 +181,8 @@ def plot_edges(edges_coordinates : [int, int, int, int, int, int] ):


if __name__ == "__main__":
    filepaths_dict = { 1 : [ "/5_precracked/a_80_old/RTS_FDB_PARSOL_SIRC-FCVC_SOG-IVCG_HFBA_CPC-NIC_-_{number}.h5".format(number=i) for i in range(1000,1010)],
                       2 : [ "/6_precrack_density_offset/a_80/RTS_FDB_PARSOL_SIRC-FCVC_SOG-IVCG_HFBA_CPC-NIC_-_{number}.h5".format(number=i) for i in range(1000,1010)],
    filepaths_dict = { "hierarchical" : [ "/5_precracked/a_80/RTS_FDB_PARSOL_SIRC-FCVC_SOG-IVCG_HFBA_CPC-NIC_-_{number}.h5".format(number=i) for i in range(1000,1050)],
                       "density reference" : [ "/6_precrack_density_offset/a_80/RTS_FDB_PARSOL_SIRC-FCVC_SOG-IVCG_HFBA_CPC-NIC_-_{number}.h5".format(number=i) for i in range(1000,1050)],
                    }
    os.chdir("/FASTTEMP/p7/lpyka/hierarchical_interface")
    data_dict = get_data_dict(filepaths_dict)
@@ -193,13 +193,13 @@ if __name__ == "__main__":
#    for filepath in filepaths:
#        current_broken_edges = get_broken_edges(filepath)
#        broken_edges.extend(current_broken_edges) 
    nx = 64
    ny = 64
    nx = 128
    ny = 128
    broken_edges_coordinates_dict = {}
    average_heights_dict = {}
    for offset, broken_edges in data_dict.items():
        broken_edges_coordinates_dict[offset] = get_vertical_edges_coordinates(broken_edges, nx, ny)
        average_heights_dict[offset] = get_average_heights_dict(broken_edges_coordinates_dict[offset])
    for realization, broken_edges in data_dict.items():
        broken_edges_coordinates_dict[realization] = get_vertical_edges_coordinates(broken_edges, nx, ny)
        average_heights_dict[realization] = get_average_heights_dict(broken_edges_coordinates_dict[realization])
    #plot_current_and_toughness(filepaths_dict)
    plot_average_per_height(average_heights_dict)