Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions DataProcessingTools/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
import os


class ExclusiveOptions():
def __init__(self, options, checked=None):
self.options = options
if checked is None:
self.checked = 0
else:
self.checked = checked

def select(self, option):
if option in self.options:
self.checked = self.options.index(option)

def selected(self):
return self.options[self.checked]

class DPObject():
argsList = []
filename = ""
Expand Down Expand Up @@ -66,13 +81,19 @@ def update_plotopts(self, plotopts, ax=None, splotopts=None):
ax = plt.gca()
replot = False
for (k, v) in plotopts.items():
if isinstance(v, dict):
if isinstance(splotopts[k], ExclusiveOptions):
for (kk, vv) in v.items():
if vv:
splotopts[k].select(kk)
replot = True
break
elif isinstance(v, dict):
self.update_plotopts(v, ax, self.plotopts[k])
else:
if v != splotopts[k]:
splotopts[k] = v
if k == "indexer":
self.upate_index(v)
self.update_index(v)
replot = True

if replot:
Expand Down
8 changes: 6 additions & 2 deletions tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ def __init__(self, *args, **kwargs):
DPT.objects.DPObject.__init__(self, *args, **kwargs)
for i in range(len(self.dirs)):
self.setidx.extend([i for j in range(3)])
self.plotopts = {"exponent": 1.0}
self.plotopts = {"exponent": 1.0,
"color": DPT.objects.ExclusiveOptions(["blue","red"], 0)}

def plot(self, i=None, ax=None):
if ax is None:
ax = plt.gca()
if not self.plotopts.get("overlay", False):
ax.clear()
color = self.plotopts["color"].selected()
x = np.array([0, 1, 2, 3])
y = x**self.plotopts["exponent"]
ax.plot(x, y)
ax.plot(x, y, color=color)

def test_plot():
cwd = "Pancake/20130923/session01/array01/channel001/cell01"
Expand All @@ -43,6 +45,8 @@ def test_plot():
obj.update_plotopts({"exponent": 2.0}, ax=ax)
xy = ax.lines[0].get_data()
assert np.allclose(xy[1], x**2.0)
obj.update_plotopts({"color": {"red": True}}, ax=ax)
assert ax.lines[0].get_color() == "red"

def test_append():
tempdir = tempfile.gettempdir()
Expand Down