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 1 commit
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
32 changes: 23 additions & 9 deletions xpdView/waterfall_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self, key_list, data_dict, fig, canvas):
self.x_offset = 0
self.y_offset = 0
self.normalized_data = dict()
self.is_normalized = True

def generate_waterfall(self):
"""This method handles the plotting of the 2d waterfall
Expand All @@ -50,15 +51,28 @@ 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)
self.ax.autoscale()
self.canvas.draw()
if self.is_normalized:
print("normy")
for i in range(0, len(self.key_list)):

Choose a reason for hiding this comment

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

you can just write range(len(...))

Choose a reason for hiding this comment

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

or even better

for i, k in enumerate(self.key_list):
    temp_x = blob[k][0].copy()

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.

for even more compactness:

blob = your_data # normalized or not
sub_blob = [blob[k] for k in self.key_list]
for i, (x, y) in enumerate(sub_blob):
    self.ax.plot(x + i * offsetx, y + i * offsety)

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.

Actually, you might not need the sub_blob. Do you allow the number of data sets to not equal the number of keys? If not then just skip the sub_blob line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, you can only get the data if there is a key for it. There should never be a time there is not a key for the data.

Choose a reason for hiding this comment

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

Great than you can just do a two liner

Copy link

Choose a reason for hiding this comment

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

Also, you don't need 0 in the range call.

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)
self.ax.title("Data Normalized")
self.ax.autoscale()
self.canvas.draw()
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

print("4chan")
for i in range(0, len(self.key_list)):
Copy link

Choose a reason for hiding this comment

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

This can just be range(len(self.key_list))

temp_x = self.data_dict[self.key_list[i]][0].copy()
temp_y = self.data_dict[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)
self.ax.title("Data not normalized")
self.ax.autoscale()
self.canvas.draw()

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 Down
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(True)
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.is_normalized = True
else:
self.water.is_normalized = False

self.water.generate_waterfall()

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