Skip to content
Snippets Groups Projects
Commit c56bebc2 authored by felix's avatar felix
Browse files

update edge coloring methods

parent bfae18ce
No related branches found
No related tags found
No related merge requests found
......@@ -70,6 +70,7 @@ class circuit:
{
'conductivity':[],
'flow_rate':[],
'label':[],
}
)
self.set_graph_containers()
......@@ -109,7 +110,7 @@ class circuit:
self.nodes[k]=np.zeros(n)
for k in self.edges:
self.edges[k]=np.ones(e)
self.edges[k]=np.zeros(e)
self.set_network_attributes()
print('circuit(): initialized and ready for (some) action :)')
......@@ -260,24 +261,31 @@ class circuit:
self.graph=new_parameters
# output
def plot_circuit(self):
def plot_circuit(self,*args,**kwargs):
self.set_pos()
E=self.get_edges_data()
V=self.get_nodes_data()
# fig=dx.plot_networkx( self.G, edge_list=self.list_graph_edges, node_list=self.list_graph_nodes )
fig=dx.plot_networkx( self.G, edge_list=self.list_graph_edges, node_list=self.list_graph_nodes, edge_data=E, node_data=V )
E=self.get_edges_data(*args)
V=self.get_nodes_data(*args)
fig=dx.plot_networkx( self.G, edge_list=self.list_graph_edges, node_list=self.list_graph_nodes, edge_data=E, node_data=V ,**kwargs)
return fig
def get_nodes_data(self):
def get_nodes_data(self, *args ):
dn=pd.DataFrame(self.nodes[['source','label']])
# dn=pd.DataFrame(self.nodes[['label']])
cols=['label']
cols+=[a for a in args if a in self.nodes.columns]
dn=pd.DataFrame(self.nodes[cols])
return dn
def get_edges_data(self):
def get_edges_data(self, *args ):
cols=['label']
cols+=[a for a in args if a in self.edges.columns]
de=pd.DataFrame(self.edges[['conductivity','flow_rate']])
de=pd.DataFrame(self.edges[cols])
return de
......@@ -18,8 +18,10 @@ def plot_networkx(input_graph,**kwargs):
options={
'network_id':0,
'color_nodes':['#a845b5'],
'color_edges':['#c762d4']
'color_edges':['#c762d4'],
'markersize': [2]
}
node_data=pd.DataFrame()
edge_data=pd.DataFrame()
......@@ -46,7 +48,8 @@ def plot_networkx_dual(dual_graph,**kwargs):
options={
'network_id':0,
'color_nodes':['#6aa84f','#a845b5'],
'color_edges':['#2BDF94','#c762d4']
'color_edges':['#2BDF94','#c762d4'],
'markersize': [2,2]
}
for k,v in kwargs.items():
......@@ -84,7 +87,8 @@ def add_traces_edges(fig, options, input_graph,extra_data):
def add_traces_nodes(fig, options, input_graph,extra_data):
idx=options['network_id']
node_trace=get_node_trace(input_graph,extra_data,color=options['color_nodes'][idx])
node_trace=get_node_trace( input_graph, extra_data, color = options['color_nodes'][idx], markersize = options['markersize'][idx] )
fig.add_trace( node_trace)
#auxillary functions generating traces for nodes and edges
......@@ -92,23 +96,24 @@ def get_edge_mid_trace(input_graph,extra_data, **kwargs):
options={
'color':'#888',
'dim':3
# 'dim':3
}
dim=3
for k,v in kwargs.items():
if k in options:
options[k]=v
pos=nx.get_node_attributes(input_graph,'pos')
if len(list(pos.values())[0]) != options['dim']:
options['dim']=len(list(pos.values())[0])
if len(list(pos.values())[0]) != dim:
dim=len(list(pos.values())[0])
E=input_graph.edges()
if 'edge_list' in options:
E=options['edge_list']
middle_node_trace=get_hover_scatter_from_template(options)
middle_node_trace=get_hover_scatter_from_template(dim,options)
XYZ= [[] for i in range(options['dim'])]
XYZ= [[] for i in range(dim)]
for j,edge in enumerate(E):
XYZ_0 =pos[edge[0]]
......@@ -136,9 +141,9 @@ def set_hover_info(trace,XYZ,extra_data):
else:
trace['hoverinfo']='none'
def get_hover_scatter_from_template(options):
def get_hover_scatter_from_template(dim,options):
if options['dim']==3:
if dim==3:
middle_node_trace = go.Scatter3d(
x=[],
y=[],
......@@ -147,7 +152,8 @@ def get_hover_scatter_from_template(options):
mode='markers',
hoverinfo='text',
opacity=0,
marker=dict(color=options['color'])
marker=dict(**options)
# marker=dict(color=options['color'])
)
else:
middle_node_trace = go.Scatter(
......@@ -156,10 +162,15 @@ def get_hover_scatter_from_template(options):
text=[],
mode='markers',
hoverinfo='text',
# marker=go.scatter.Marker(
# opacity=0,
# color=options['color']
# )
marker=go.scatter.Marker(
opacity=0,
color=options['color']
**options
)
)
return middle_node_trace
......@@ -168,31 +179,45 @@ def get_edge_invd_traces(input_graph,extra_data, **kwargs):
options={
'color':'#888',
'dim':3
# 'dim':3
}
dim=3
for k,v in kwargs.items():
if k in options:
options[k]=v
# handle exceptions and new containers
colorful=False
if type(options['color'])!=str:
colorful=True
options['colorscale']='plasma'
options['cmin']=np.min(options['color'])
options['cmax']=np.max(options['color'])
pos=nx.get_node_attributes(input_graph,'pos')
if len(list(pos.values())[0]) != options['dim']:
options['dim']=len(list(pos.values())[0])
if len(list(pos.values())[0]) != dim:
dim=len(list(pos.values())[0])
E=input_graph.edges()
if 'edge_list' in options:
E=options['edge_list']
# if 'edge_list' in options:
# E=options['edge_list']
trace_list = []
# add new traces
trace_list = []
aux_option=dict(options)
for i,edge in enumerate(E):
options['weight']=5.
aux_option['width']=5.
if 'weight' in extra_data:
options['weight']=extra_data['weight'][i]
aux_option['width']=extra_data['weight'][i]
if colorful:
aux_option['color']=[options['color'][i] for j in range(2)]
trace=get_line_from_template(options)
trace=get_line_from_template(dim,aux_option)
XYZ_0 = input_graph.nodes[edge[0]]['pos']
XYZ_1 = input_graph.nodes[edge[1]]['pos']
......@@ -206,19 +231,21 @@ def set_edge_info(trace,XYZ_0,XYZ_1):
tags=['x','y','z']
if len(XYZ_0)<3:
tags=['x','y']
for i,t in enumerate(tags):
trace[t]=[XYZ_0[i], XYZ_1[i], None]
def get_line_from_template(options):
def get_line_from_template(dim,options):
if options['dim']==3:
if dim==3:
trace=go.Scatter3d(
x=[],
y=[],
z=[],
mode='lines',
line=dict(color=options['color'], width=options['weight']),
# line=dict(color=options['color'], width=options['weight'], cmin=options['cmin'], cmax=options['cmax']),
line=dict(**options),
hoverinfo='none'
)
......@@ -228,12 +255,32 @@ def get_line_from_template(options):
x=[],
y=[],
mode='lines',
line=dict(color=options['color'], width=options['weight']),
# line=dict(color=options['color'], width=options['weight'], cmin=options['cmin'], cmax=options['cmax']),
line=dict(**options),
hoverinfo='none'
)
return trace
def get_node_trace(input_graph,extra_data,**kwargs):
options={
'color':'#888',
'dim':3,
'markersize':2
}
for k,v in kwargs.items():
if k in options:
options[k]=v
node_xyz=get_node_coords(input_graph,options)
node_trace = get_node_scatter(node_xyz,extra_data,options)
return node_trace
def get_node_coords(input_graph,options):
pos=nx.get_node_attributes(input_graph,'pos')
......@@ -273,10 +320,10 @@ def get_node_scatter(node_xyz,extra_data,options):
hoverinfo=mode,
hovertext=hover,
marker=dict(
size=2,
size=options['markersize'],
line_width=2,
color=options['color'])
)
)
else:
node_trace = go.Scatter(
x=node_xyz[0], y=node_xyz[1],
......@@ -284,29 +331,13 @@ def get_node_scatter(node_xyz,extra_data,options):
hoverinfo=mode,
hovertext=hover,
marker=dict(
size=2,
size=options['markersize'],
line_width=2,
color=options['color'])
)
return node_trace
def get_node_trace(input_graph,extra_data,**kwargs):
options={
'color':'#888',
'dim':3
}
for k,v in kwargs.items():
if k in options:
options[k]=v
node_xyz=get_node_coords(input_graph,options)
node_trace = get_node_scatter(node_xyz,extra_data,options)
return node_trace
def create_tag(vals,columns):
tag=f''
......
......@@ -12,6 +12,7 @@ import numpy as np
def init_graph_from_crystal(crystal_type,periods):
choose_constructor_option={
'default': networkx_simple,
'simple': networkx_simple,
'chain': networkx_chain,
......@@ -22,7 +23,8 @@ def init_graph_from_crystal(crystal_type,periods):
'trigonal_stack': networkx_trigonal_stack,
'square': networkx_square,
'hexagonal':networkx_hexagonal,
'trigonal_planar':networkx_trigonal_planar
'trigonal_planar':networkx_trigonal_planar,
}
if crystal_type in choose_constructor_option:
......
......@@ -19,6 +19,7 @@ def init_dual_minsurf_graphs(dual_type,num_periods):
'simple': networkx_dual_simple,
'diamond':networkx_dual_diamond,
'laves':networkx_dual_laves,
'catenation':networkx_dual_catenation,
}
......@@ -384,3 +385,36 @@ class networkx_dual_laves(networkx_dual,object):
counter_e+=1
return G
class networkx_dual_catenation(networkx_dual,object):
def __init__(self,num_periods):
super(networkx_dual_catenation,self).__init__()
self.lattice_constant=1
self.translation_length=1
self.dual_ladder(num_periods)
def dual_ladder(self,num_periods):
np1=[num_periods,1]
np2=[num_periods+1,1]
N=[np1,np2]
ic=init_crystal.networkx_square
G1,G2=[ nx.Graph(ic(i).G) for i in N]
theta=np.pi/2.
rot_mat=np.array(( (1,0,0) , (0, np.cos(theta), -np.sin(theta)),
(0, np.sin(theta), np.cos(theta)) ))
for n in G1.nodes():
# x=G1.nodes[n]['pos'][0]
# y=G1.nodes[n]['pos'][1]
# z=G1.nodes[n]['pos'][2]
G1.nodes[n]['pos']=self.lattice_constant *np.array((0.5,0.5,-0.5)) + np.dot(rot_mat,G1.nodes[n]['pos'])
self.layer=[G1,G2]
......@@ -13,7 +13,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
setuptools.setup(
name="kirchhoff", # Replace with your own username
version="0.1.4",
version="0.1.5",
author="felixk1990",
author_email="felixuwekramer@protonmail.com",
description="Collection of routines for creation and manipulation of Kirchhoff circuits based on resistor-only networks, together with 2D/3D spatial embeddings. ",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment