Skip to content
This repository has been archived by the owner on Nov 5, 2020. It is now read-only.

Commit

Permalink
Do not draw isoelastics in contour plot if measurements have
Browse files Browse the repository at this point in the history
 different channel widths
  • Loading branch information
paulmueller committed Aug 16, 2018
1 parent 2a40f1c commit bc1e135
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
treatment (#224)
- Channel width not correctly identified for old tdms files
(dclab 0.6.2.dev7)
- Do not draw isoelastics in contour plot if measurements have
different channel widths
- Automatically identify treatment and repetition for mixed model
analysis (#222)
- Automated release to PyPI with appveyor
Expand Down
10 changes: 7 additions & 3 deletions shapeout/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
str_classes = str


class MultipleValuesError(BaseException):
pass


class Analysis(object):
"""Stores several RT-DC data sets and useful methods
Expand Down Expand Up @@ -302,7 +306,7 @@ def get_config_value(self, section, key):
Raises
------
ValueError if not all measurements share the same value
MultipleValuesError: if not all measurements share the same value
Notes
-----
Expand All @@ -312,11 +316,11 @@ def get_config_value(self, section, key):
values = []
for mm in self.measurements:
values.append(mm.config[section][key])
all_same = np.sum([v == values[0] for v in values]) == len(values)
all_same = np.all(np.array(values) == values[0])
if not all_same:
msg = "Multiple values encountered for [{}]: {}".format(section,
key)
raise ValueError(msg)
raise MultipleValuesError(msg)
return mm.config[section][key]

def GetCommonParameters(self, key):
Expand Down
38 changes: 22 additions & 16 deletions shapeout/gui/plot_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import numpy as np

from . import plot_common
from .. import analysis as ana


def contour_plot(measurements, levels=[0.5,0.95],
def contour_plot(analysis, levels=[0.5,0.95],
axContour=None, wxtext=False, square=True):
"""Plot contour for two axes of an RT-DC measurement
Expand All @@ -30,7 +31,7 @@ def contour_plot(measurements, levels=[0.5,0.95],
square : bool
The plot has square shape.
"""
mm = measurements[0]
mm = analysis[0]
xax = mm.config["plotting"]["axis x"].lower()
yax = mm.config["plotting"]["axis y"].lower()

Expand All @@ -45,22 +46,27 @@ def contour_plot(measurements, levels=[0.5,0.95],
scalex = mm.config["plotting"]["scale x"].lower()
scaley = mm.config["plotting"]["scale y"].lower()

## Add isoelastics
isoel = plot_common.get_isoelastics(mm)
if isoel:
for ii, data in enumerate(isoel):
x_key = 'isoel_x'+str(ii)
y_key = 'isoel_y'+str(ii)
pd.set_data(x_key, data[:,0])
pd.set_data(y_key, data[:,1])
contour_plot.plot((x_key, y_key), color="gray",
index_scale=scalex, value_scale=scaley)
# Add isoelastics only if all measurements have the same channel width
try:
analysis.get_config_value("setup", "channel width")
except ana.MultipleValuesError:
pass
else:
isoel = plot_common.get_isoelastics(mm)
if isoel:
for ii, data in enumerate(isoel):
x_key = 'isoel_x'+str(ii)
y_key = 'isoel_y'+str(ii)
pd.set_data(x_key, data[:,0])
pd.set_data(y_key, data[:,1])
contour_plot.plot((x_key, y_key), color="gray",
index_scale=scalex, value_scale=scaley)

#colors = [ "".join(map(chr, np.array(c[:3]*255,dtype=int))).encode('hex') for c in colors ]
if not isinstance(levels, list):
levels = [levels]

set_contour_data(contour_plot, measurements, levels=levels)
set_contour_data(contour_plot, analysis, levels=levels)

# Axes
left_axis = ca.PlotAxis(contour_plot, orientation='left',
Expand Down Expand Up @@ -103,10 +109,10 @@ def contour_plot(measurements, levels=[0.5,0.95],
return contour_plot


def set_contour_data(plot, measurements, levels=[0.5,0.95]):
def set_contour_data(plot, analysis, levels=[0.5,0.95]):
pd = plot.data
# Plotting area
mm = measurements[0]
mm = analysis[0]
xax = mm.config["plotting"]["axis x"].lower()
yax = mm.config["plotting"]["axis y"].lower()

Expand All @@ -118,7 +124,7 @@ def set_contour_data(plot, measurements, levels=[0.5,0.95]):
x0 = mm[xax]
y0 = mm[yax]

for ii, mm in enumerate(measurements):
for ii, mm in enumerate(analysis):
cname = "con_{}_{}".format(ii, mm.identifier)
if cname in plot.plots:
plot.delplot(cname)
Expand Down
2 changes: 1 addition & 1 deletion shapeout/gui/plot_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def Plot(self, anal=None):
#k = i + j*rows
if (i == cols-1 and j == 0 and lcc == 1):
# Contour plot in upper right corner
aplot = plot_contour.contour_plot(anal.measurements)
aplot = plot_contour.contour_plot(anal)
range_joined.append(aplot)
elif (i == cols-1 and j == 1 and lll == 1):
# Legend plot below contour plot
Expand Down
4 changes: 2 additions & 2 deletions tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ def test_get_config_value():
assert anal.get_config_value(section="filtering", key="deform min") == 0
try:
anal.get_config_value(section="filtering", key="deform max")
except ValueError:
except analysis.MultipleValuesError:
pass
else:
raise ValueError("different values should raise error")
assert False, "different values should raise error"


def test_data_size():
Expand Down

0 comments on commit bc1e135

Please sign in to comment.