Synch with remote repo
This commit is contained in:
@ -1,69 +1,69 @@
|
||||
import sys
|
||||
import os
|
||||
root_dir = os.path.abspath(os.curdir)
|
||||
sys.path.append(root_dir)
|
||||
|
||||
import h5py
|
||||
import yaml
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
from plotly.subplots import make_subplots
|
||||
import plotly.graph_objects as go
|
||||
import plotly.express as px
|
||||
#import plotly.io as pio
|
||||
from src.hdf5_ops import get_parent_child_relationships
|
||||
|
||||
|
||||
|
||||
def display_group_hierarchy_on_a_treemap(filename: str):
|
||||
|
||||
"""
|
||||
filename (str): hdf5 file's filename"""
|
||||
|
||||
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:
|
||||
if isinstance(file.attrs[key], str): # Check if the attribute is a string
|
||||
metadata_key = key[key.find('_') + 1:]
|
||||
metadata_value = file.attrs[key]
|
||||
metadata_dict[metadata_key] = metadata_value
|
||||
metadata_list.append(f'{metadata_key}: {metadata_value}')
|
||||
|
||||
#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")
|
||||
|
||||
#pio.write_image(fig,file_name + ".png",width=800,height=600,format='png')
|
||||
|
||||
#
|
||||
import sys
|
||||
import os
|
||||
root_dir = os.path.abspath(os.curdir)
|
||||
sys.path.append(root_dir)
|
||||
|
||||
import h5py
|
||||
import yaml
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
from plotly.subplots import make_subplots
|
||||
import plotly.graph_objects as go
|
||||
import plotly.express as px
|
||||
#import plotly.io as pio
|
||||
from src.hdf5_ops import get_parent_child_relationships
|
||||
|
||||
|
||||
|
||||
def display_group_hierarchy_on_a_treemap(filename: str):
|
||||
|
||||
"""
|
||||
filename (str): hdf5 file's filename"""
|
||||
|
||||
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:
|
||||
if isinstance(file.attrs[key], str): # Check if the attribute is a string
|
||||
metadata_key = key[key.find('_') + 1:]
|
||||
metadata_value = file.attrs[key]
|
||||
metadata_dict[metadata_key] = metadata_value
|
||||
metadata_list.append(f'{metadata_key}: {metadata_value}')
|
||||
|
||||
#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")
|
||||
|
||||
#pio.write_image(fig,file_name + ".png",width=800,height=600,format='png')
|
||||
|
||||
#
|
||||
|
@ -1,54 +1,54 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def plot_image(dataframe,filter):
|
||||
|
||||
for meas_idx in dataframe.loc[filter,:].index:
|
||||
meas = dataframe.loc[meas_idx,:] # pandas Series
|
||||
fig = plt.figure()
|
||||
ax = plt.gca()
|
||||
rows, cols = meas['image'].shape
|
||||
scientaEkin_eV = meas['scientaEkin_eV'].flatten()
|
||||
x_min, x_max = np.min(scientaEkin_eV), np.max(scientaEkin_eV)
|
||||
y_min, y_max = 0, rows
|
||||
ax.imshow(meas['image'],extent = [x_min,x_max,y_min,y_max])
|
||||
ax.set_xlabel('scientaEkin_eV')
|
||||
ax.set_ylabel('Replicates')
|
||||
ax.set_title(meas['name'][0] + '\n' + meas['sample'][0]+ '\n' + meas['lastModifiedDatestr'][0])
|
||||
|
||||
def plot_spectra(dataframe,filter):
|
||||
|
||||
""" plot_spectra plots XPS spectra associated to 'dataframe' after row reduced by 'filter'.
|
||||
When more than one row are specified by the 'filter' input, indivial spectrum are superimposed
|
||||
on the same plot.
|
||||
|
||||
Parameters:
|
||||
dataframe (pandas.DataFrame): table with heterogenous entries obtained by read_hdf5_as_dataframe.py.
|
||||
filter (binaray array): binary indexing array with same number of entries as rows in dataframe.
|
||||
|
||||
"""
|
||||
fig = plt.figure()
|
||||
ax = plt.gca()
|
||||
|
||||
for meas_idx in dataframe.loc[filter,:].index:
|
||||
meas = dataframe.loc[meas_idx,:] # pandas Series
|
||||
|
||||
rows, cols = meas['image'].shape
|
||||
bindingEnergy_eV = meas['bindingEnergy_eV'].flatten()
|
||||
spectrum_countsPerSecond = meas['spectrum_countsPerSecond'].flatten()
|
||||
x_min, x_max = np.min(bindingEnergy_eV), np.max(bindingEnergy_eV)
|
||||
y_min, y_max = 0, rows
|
||||
#for i in range(cols):
|
||||
#ax.plot(bindingEnergy_eV, spectrum_countsPerSecond,label = meas['name'][0])
|
||||
ax.plot(bindingEnergy_eV, spectrum_countsPerSecond,label = meas['name'])
|
||||
|
||||
ax.set_xlabel('bindingEnergy_eV')
|
||||
ax.set_ylabel('counts Per Second')
|
||||
ax.set_title('\n'+meas['sample']+ '\n' + 'PE spectra')
|
||||
#ax.set_title('\n'+meas['sample'][0]+ '\n' + 'PE spectra')
|
||||
#ax.set_title(meas['name'][0] + '\n'+meas['sample'][0]+ '\n' + meas['lastModifiedDatestr'][0])
|
||||
ax.legend()
|
||||
|
||||
|
||||
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def plot_image(dataframe,filter):
|
||||
|
||||
for meas_idx in dataframe.loc[filter,:].index:
|
||||
meas = dataframe.loc[meas_idx,:] # pandas Series
|
||||
fig = plt.figure()
|
||||
ax = plt.gca()
|
||||
rows, cols = meas['image'].shape
|
||||
scientaEkin_eV = meas['scientaEkin_eV'].flatten()
|
||||
x_min, x_max = np.min(scientaEkin_eV), np.max(scientaEkin_eV)
|
||||
y_min, y_max = 0, rows
|
||||
ax.imshow(meas['image'],extent = [x_min,x_max,y_min,y_max])
|
||||
ax.set_xlabel('scientaEkin_eV')
|
||||
ax.set_ylabel('Replicates')
|
||||
ax.set_title(meas['name'][0] + '\n' + meas['sample'][0]+ '\n' + meas['lastModifiedDatestr'][0])
|
||||
|
||||
def plot_spectra(dataframe,filter):
|
||||
|
||||
""" plot_spectra plots XPS spectra associated to 'dataframe' after row reduced by 'filter'.
|
||||
When more than one row are specified by the 'filter' input, indivial spectrum are superimposed
|
||||
on the same plot.
|
||||
|
||||
Parameters:
|
||||
dataframe (pandas.DataFrame): table with heterogenous entries obtained by read_hdf5_as_dataframe.py.
|
||||
filter (binaray array): binary indexing array with same number of entries as rows in dataframe.
|
||||
|
||||
"""
|
||||
fig = plt.figure()
|
||||
ax = plt.gca()
|
||||
|
||||
for meas_idx in dataframe.loc[filter,:].index:
|
||||
meas = dataframe.loc[meas_idx,:] # pandas Series
|
||||
|
||||
rows, cols = meas['image'].shape
|
||||
bindingEnergy_eV = meas['bindingEnergy_eV'].flatten()
|
||||
spectrum_countsPerSecond = meas['spectrum_countsPerSecond'].flatten()
|
||||
x_min, x_max = np.min(bindingEnergy_eV), np.max(bindingEnergy_eV)
|
||||
y_min, y_max = 0, rows
|
||||
#for i in range(cols):
|
||||
#ax.plot(bindingEnergy_eV, spectrum_countsPerSecond,label = meas['name'][0])
|
||||
ax.plot(bindingEnergy_eV, spectrum_countsPerSecond,label = meas['name'])
|
||||
|
||||
ax.set_xlabel('bindingEnergy_eV')
|
||||
ax.set_ylabel('counts Per Second')
|
||||
ax.set_title('\n'+meas['sample']+ '\n' + 'PE spectra')
|
||||
#ax.set_title('\n'+meas['sample'][0]+ '\n' + 'PE spectra')
|
||||
#ax.set_title(meas['name'][0] + '\n'+meas['sample'][0]+ '\n' + meas['lastModifiedDatestr'][0])
|
||||
ax.legend()
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user