Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for normalizing data in waterfall plot #31

Merged
merged 4 commits into from
Oct 3, 2016
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
26 changes: 18 additions & 8 deletions xpdView/waterfall_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, key_list, data_dict, fig, canvas):
self.data_dict = data_dict
self.key_list = key_list
self.fig = fig
self.normalized = False
self.canvas = canvas
self.ax = self.fig.add_subplot(111)
self.x_offset = 0
Expand All @@ -50,16 +51,25 @@ def generate_waterfall(self):
None
"""
self.ax.cla()
# self.ax.hold(True)
for i in range(0, len(self.key_list)):
temp_x = self.normalized_data[self.key_list[i]][0].copy()
temp_y = self.normalized_data[self.key_list[i]][1].copy()
temp_x += self.x_offset * i
temp_y += self.y_offset * i
self.ax.plot(temp_x, temp_y)
title = 'Data not normalized'
if self.normalized:
data = self.normalized_data
title = 'Data Normalized'
else:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might compress this into two chunks, the part which does the normalizeation (or not) and the part which does the ax.autoscale() andcanvas.draw() since those are shared

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could compress this even more, since the temp_x = blob logic is the same. Maybe something like this:

if self.is_normalized:
    data = norm_blob
else:
    data = blob
# Now put your temp_x, temp_y logic

data = self.data_dict
list_data = (data[k] for k in self.key_list) # you can do a list comp here too
for i, (x, y) in enumerate(list_data):
self.ax.plot(x + self.x_offset * i, y + self.y_offset * i)
self.ax.set_title(title)
self.ax.autoscale()
self.canvas.draw()

def is_normalized(self):
return self.normalized

def set_normalized(self, state):
self.normalized = state

def normalize_data(self):
"""This method normalizes data for plotting

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that you could do this with -= and /= for more compactness

Copy link

@CJ-Wright CJ-Wright Aug 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also you might look into using np.nanmax and its associated min, that way you ignore potential nan problems

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the normalize_data code.


Expand All @@ -72,4 +82,4 @@ def normalize_data(self):
temp = self.data_dict[key].copy()
temp[1] = temp[1] - temp[1].min()
temp[1] = temp[1] / (temp[1].max() - temp[1].min())
self.normalized_data[key] = temp
self.normalized_data[key] = temp
26 changes: 17 additions & 9 deletions xpdView/xpd_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,21 +519,29 @@ def twod_plot_settings(self):
x_offset_slider.setMinimum(0)
x_offset_slider.setMaximum(20)
x_offset_slider.valueChanged.connect(self.set_x_offset)

normalize_option_label = QtGui.QLabel()
normalize_option_label.setText("Normalize data:")
normalize_option_box = QtGui.QCheckBox()
# data is normalized by default
normalize_option_box.setChecked(self.water.is_normalized())
normalize_option_box.stateChanged.connect(self.set_normalization)
layout = QtGui.QHBoxLayout()
layout.addStretch()
layout.addWidget(y_offset_label)
layout.addStretch()
layout.addWidget(y_offset_slider)
layout.addStretch()
layout.addWidget(x_offset_label)
layout.addStretch()
layout.addWidget(x_offset_slider)
for widget in [y_offset_label, y_offset_slider, x_offset_label, x_offset_slider, normalize_option_label, normalize_option_box]:
layout.addStretch()
layout.addWidget(widget)

settings_window.setLayout(layout)
settings_window.show()
settings_window.exec_()

def set_normalization(self, state):
if state == 2:
self.water.set_normalized(True)
else:
self.water.set_normalized(False)

self.water.generate_waterfall()

def set_x_offset(self, value):
self.water.x_offset = value
self.water.generate_waterfall()
Expand Down