Skip to content

Commit

Permalink
Added suport to sequences of curves
Browse files Browse the repository at this point in the history
  • Loading branch information
denphi committed May 29, 2019
1 parent 0201d0a commit 790e7e1
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 29 deletions.
2 changes: 1 addition & 1 deletion nanohubtools/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
# Daniel Mejia (denphi), Purdue University (denphi@denphi.com)


version_info = (0, 1, 8)
version_info = (0, 1, 9)
__version__ = ".".join(map(str, version_info))

157 changes: 129 additions & 28 deletions nanohubtools/rappturetool.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from .nanohubtools import Nanohubtool, setInterval
from .plotlywidget import FigureWidget
from ipywidgets import Output, Tab, Button, Accordion, GridBox, Layout, ButtonStyle, Label, HBox, VBox, Textarea
from ipywidgets import Output, Tab, Button, Accordion, GridBox, Layout, ButtonStyle, Label, HBox, VBox, Textarea, SelectionSlider, Play
import numpy as np
import xml.etree.ElementTree as ET
from floatview import Floatview
Expand Down Expand Up @@ -193,6 +193,8 @@ def displayExperiment(self, experiment):

if (experiment['complete']):
out_curves = VBox(layout=Layout(width='99%', height='100%'))
out_plots = VBox(layout=Layout(width='99%', height='100%'))
out_sequences = VBox(layout=Layout(width='99%', height='100%'))
out_volumes = VBox(layout=Layout(width='99%', height='100%'))
out_tables = VBox(layout=Layout(width='99%', height='100%'))
out_logs = VBox(layout=Layout(width='99%', height='100%'))
Expand Down Expand Up @@ -229,25 +231,57 @@ def displayExperiment(self, experiment):
else:
groups[g.text] = [el]

header = False
for k,g in groups.items():
if len(g) > 1:
if header == False:
but = Button(description="Grouped", layout=Layout(width='auto'),style=ButtonStyle(button_color='lightblue'))
header = True
oc_children.append(but)
but = Button(description=k, icon='check', disable=False, layout=layout)
but.on_click(lambda a, b=self, c=g,d=experiment['modal'] : Rappturetool.plotXY(b,c,d))
oc_children.append(but)
out_curves.children = oc_children
if len(oc_children) > 0:
acc_item = acc_item+1
acc_children.append(out_curves)
acc_titles.append('Curves')
except:
pass;

op_children = []
try:
for k,g in groups.items():
but = Button(description=k, icon='check', disable=False, layout=layout)
but.on_click(lambda a, b=self, c=g,d=experiment['modal'] : Rappturetool.plotXY(b,c,d))
op_children.append(but)
out_plots.children = op_children
if len(op_children) > 0:
acc_item = acc_item+1
acc_children.append(out_plots)
acc_titles.append('Plots')
except:
pass;


os_children = []
try:
sequences = experiment['results'].findall('sequence')
groups = {}
for i in range(len(sequences)):
el = sequences[i]
but = Button(description=self.getText(el, ["about","label"]), icon='check', disable=False, layout=layout)
but.on_click(lambda a, b=self, c=sequences[i],d=experiment['modal'] : Rappturetool.plotSequence(b,c,d))
os_children.append(but)
out_sequences.children = os_children
if len(os_children) > 0:
acc_item = acc_item+1
acc_children.append(out_sequences)
acc_titles.append('Sequences')
except:
pass;


ot_children = []
try:
tables = experiment['results'].findall('table')
Expand Down Expand Up @@ -404,7 +438,6 @@ def plotVTK( self, title, componentv, out ):
opacity = 1.0
fill = 1.0
id = component_id[ii]
#print (id)
if id == 'shape':
ncontours = 1
colorscale = "Greens"
Expand Down Expand Up @@ -531,16 +564,93 @@ def plotLog(self, field, out):
text = text[hlen:-1]
text = b64decode(text)
text = zlib.decompress(text, zlib.MAX_WBITS | 32)
print (text)

if out == None:
out = Floatview(title=title, mode = 'split-bottom')
out.clear_output()
with out:
display(Textarea(value=text, layout=Layout(width='auto', height='400px')))

def updateFrame(self, change, frames, fig, play, sl):
if change["new"] in frames:
frame = frames[change["new"]]
indexes = []
changes = {'x':[], 'y':[]}
for i, trace in enumerate(frame):
changes['x'].append(trace['x'].tolist())
changes['y'].append(trace['y'].tolist())
indexes.append(i)
play.value = list(frames.keys()).index(change["new"])
sl.value = change["new"]
fig.plotly_restyle(changes, indexes)


def plotSequence(self, sequence, out, labels=None):
traces = []
layout = {}
frames = {}
options = []
elements = sequence.findall('element')
label = self.getText(sequence, ["index", "label"])
for seq in elements:
curves = seq.findall('curve')
oc_children = []
groups = {}
for i in range(len(curves)):
el = curves[i]
ab = el.find('about')
if ab is not None:
for g in ab.findall("group"):
if g.text in groups:
groups[g.text].append(el)
else:
groups[g.text] = [el]
if(len(groups)>0):
index = self.getText(seq, ["index"])
options.append(index)
tr, lay = self.buiildXYPlotly(groups[list(groups.keys())[0]])
if len(traces) == 0:
layout = lay
traces = tr
frames[index] = tr

fig = FigureWidget({
'data': traces,
'layout': layout
})

sl = SelectionSlider(options=options, value=options[0], description=label)
play = Play(interval=1000, value=0, min=0, max=len(frames), description=label )
sl.observe(lambda change, this=self, f=frames, g=fig, p=play, s=sl: Rappturetool.updateFrame(this, change, f, g, p, sl), "value")
play.observe(lambda change, this=self, f=frames, g=fig, p=play, s=sl: setattr(sl, 'value', list(f.keys())[change['new']]), "value")
sl.layout.width='99%'
container = VBox([fig,play,sl], layout=layout)


if out == None:
out = Floatview(title=title, mode = 'split-bottom')
out.clear_output()
with out:
display(container)
return fig

def plotXY(self, fields, out, labels=None):
traces, layout = self.buiildXYPlotly(fields, labels)
fig = FigureWidget({
'data': traces,
'layout': layout
})
if out == None:
out = Floatview(title=title, mode = 'split-bottom')
out.clear_output()
but = Button(description="Compare Data", icon='check', disable=False, layout=layout)
but.on_click(lambda a, b=self, c=fields[0], d=out : Rappturetool.compareXY(b,c,d))
with out:
display(fig)
display(but)
return fig

def buiildXYPlotly(self, fields, labels=None):
traces = []
for i, field in enumerate(fields):
component = self.getXY(field, 'component')
Expand All @@ -562,8 +672,9 @@ def plotXY(self, fields, out, labels=None):
xy = obj.strip()
xy = np.array(xy.splitlines())
xy = xy[(xy != '')]
xy = [np.fromstring(xy[i], dtype=float, sep=" ") for i in range(len(xy))]
xy = [np.fromstring(xy[i].replace("--", ""), dtype=float, sep=" ") for i in range(len(xy))]
xy = np.concatenate(xy)
#xy = xy[0:int(len(xy)/2)*2]
xy = xy.reshape(int(len(xy)/2),2)
trace1 = {
'type' : 'scatter',
Expand All @@ -590,19 +701,9 @@ def plotXY(self, fields, out, labels=None):
},
'legend' : { 'orientation' : 'h', 'x':0.1, 'y':1.1 },
}
fig = FigureWidget({
'data': traces,
'layout': layout
})
if out == None:
out = Floatview(title=title, mode = 'split-bottom')
out.clear_output()
but = Button(description="Compare Data", icon='check', disable=False, layout=layout)
but.on_click(lambda a, b=self, c=fields[0], d=out : Rappturetool.compareXY(b,c,d))
with out:
display(fig)
display(but)
return fig
return traces, layout




def updateRender(self):
Expand Down Expand Up @@ -797,4 +898,4 @@ def getResults(self, session_id, run_file):
}
if (self.authenticated):
return load_results(results_json, self.headers)
return ''
return ''

0 comments on commit 790e7e1

Please sign in to comment.