Relocated def display_group_hierarchy_on_a_treemap(filename: str) to hdf5_vis.py
This commit is contained in:
@ -5,10 +5,7 @@ import os
|
|||||||
#from itertools import product
|
#from itertools import product
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
import plotly.express as px
|
|
||||||
import plotly.graph_objects as go
|
|
||||||
from plotly.subplots import make_subplots
|
|
||||||
|
|
||||||
#import g5505_file_reader
|
#import g5505_file_reader
|
||||||
import g5505_utils as utils
|
import g5505_utils as utils
|
||||||
@ -196,43 +193,6 @@ def format_group_names(names: list):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def display_group_hierarchy_on_a_treemap(filename: str):
|
|
||||||
|
|
||||||
with h5py.File(filename,'r') as file:
|
|
||||||
nodes, parents, values = get_parent_child_relationships(file)
|
|
||||||
|
|
||||||
metadata_list = []
|
|
||||||
metadata_dict={}
|
|
||||||
for key in file.attrs.keys():
|
|
||||||
if 'metadata' in key:
|
|
||||||
metadata_dict[key[key.find('_')+1::]]= file.attrs[key]
|
|
||||||
metadata_list.append(key[key.find('_')+1::]+':'+file.attrs[key])
|
|
||||||
metadata = '<br>'.join(['<br>'] + metadata_list)
|
|
||||||
|
|
||||||
customdata_series = pd.Series(nodes)
|
|
||||||
customdata_series[0] = metadata
|
|
||||||
|
|
||||||
fig = make_subplots(1, 1, specs=[[{"type": "domain"}]],)
|
|
||||||
fig.add_trace(go.Treemap(
|
|
||||||
labels=nodes, #formating_df['formated_names'][nodes],
|
|
||||||
parents=parents,#formating_df['formated_names'][parents],
|
|
||||||
values=values,
|
|
||||||
branchvalues='remainder',
|
|
||||||
customdata= customdata_series,
|
|
||||||
#marker=dict(
|
|
||||||
# colors=df_all_trees['color'],
|
|
||||||
# colorscale='RdBu',
|
|
||||||
# cmid=average_score),
|
|
||||||
#hovertemplate='<b>%{label} </b> <br> Number of files: %{value}<br> Success rate: %{color:.2f}',
|
|
||||||
hovertemplate='<b>%{label} </b> <br> Count: %{value} <br> Path: %{customdata}',
|
|
||||||
name='',
|
|
||||||
root_color="lightgrey"
|
|
||||||
))
|
|
||||||
fig.update_layout(width = 800, height= 600, margin = dict(t=50, l=25, r=25, b=25))
|
|
||||||
fig.show()
|
|
||||||
file_name, file_ext = os.path.splitext(filename)
|
|
||||||
fig.write_html(file_name + ".html")
|
|
||||||
|
|
||||||
def annotate_root_dir(filename,annotation_dict: dict):
|
def annotate_root_dir(filename,annotation_dict: dict):
|
||||||
with h5py.File(filename,'r+') as file:
|
with h5py.File(filename,'r+') as file:
|
||||||
for key in annotation_dict:
|
for key in annotation_dict:
|
||||||
@ -241,8 +201,9 @@ def annotate_root_dir(filename,annotation_dict: dict):
|
|||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
def create_hdf5_file_from_filesystem_path(ofilename : str, input_file_system_path :
|
def create_hdf5_file_from_filesystem_path(ofilename : str,
|
||||||
str, select_dir_keywords = [],
|
input_file_system_path : str,
|
||||||
|
select_dir_keywords = [],
|
||||||
select_file_keywords =[],
|
select_file_keywords =[],
|
||||||
top_sub_dir_mask : bool = True):
|
top_sub_dir_mask : bool = True):
|
||||||
|
|
||||||
@ -282,9 +243,7 @@ def create_hdf5_file_from_filesystem_path(ofilename : str, input_file_system_pat
|
|||||||
select_dir_keywords[i] = keyword.replace('/',os.sep)
|
select_dir_keywords[i] = keyword.replace('/',os.sep)
|
||||||
|
|
||||||
|
|
||||||
with h5py.File(ofilename, 'w') as h5file:
|
with h5py.File(ofilename, 'w') as h5file:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Visit each subdirectory from top to bottom, root directory defined by input_file_sytem_path to the lower
|
# Visit each subdirectory from top to bottom, root directory defined by input_file_sytem_path to the lower
|
||||||
# level directories.
|
# level directories.
|
||||||
@ -488,7 +447,7 @@ def main():
|
|||||||
|
|
||||||
output_filename_path = os.path.join(config_file.outputfile_dir,config_file.output_filename)
|
output_filename_path = os.path.join(config_file.outputfile_dir,config_file.output_filename)
|
||||||
create_hdf5_file_from_filesystem_path(output_filename_path,inputfile_dir,select_dir_keywords,select_file_keywords)
|
create_hdf5_file_from_filesystem_path(output_filename_path,inputfile_dir,select_dir_keywords,select_file_keywords)
|
||||||
display_group_hierarchy_on_a_treemap(output_filename_path)
|
#display_group_hierarchy_on_a_treemap(output_filename_path)
|
||||||
|
|
||||||
def main_mtable_h5_from_dataframe():
|
def main_mtable_h5_from_dataframe():
|
||||||
|
|
||||||
@ -530,7 +489,7 @@ def main_mtable_h5_from_dataframe():
|
|||||||
}
|
}
|
||||||
annotate_root_dir(output_filename_path, annotation_dict)
|
annotate_root_dir(output_filename_path, annotation_dict)
|
||||||
|
|
||||||
display_group_hierarchy_on_a_treemap(output_filename_path)
|
#display_group_hierarchy_on_a_treemap(output_filename_path)
|
||||||
|
|
||||||
print(':)')
|
print(':)')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user