-
Notifications
You must be signed in to change notification settings - Fork 6
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
QT3Scope update to display rolling mean line in figure and acquired values as text, and fix animation-related warning. #117
base: main
Are you sure you want to change the base?
Conversation
…`oscilloscope.py`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for cleaning up some of the code! Formatting, adding type hints, and docstrings! That's amazing and great. Thank you so much for doing that!
I've added a handful of comments / questions inline.
src/applications/oscilloscope.py
Outdated
def get_new_rolling_mean_val(self): | ||
""" Calculates new rolling mean value. """ | ||
values_of_interest = list(self.ydata)[len(self.ydata) - 2 * self.half_window_size: | ||
len(self.ydata)] | ||
return np.mean(values_of_interest) | ||
|
||
def get_new_rolling_stdev_val(self): | ||
""" Calculates new rolling standard deviation. """ | ||
values_of_interest = list(self.ydata)[len(self.ydata) - 2 * self.half_window_size: | ||
len(self.ydata)] | ||
return np.std(values_of_interest) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vasilisniaouris I think this is more efficient (~2x as fast according to stack overflow -- although perhaps we won't see that much speedup since our deque is smaller than the one used in the measurement that I read)
import itertools
values_of_interest = list(itertools.islice(self.ydata, start, stop))
Also, if we added 'more_itertools' to the project, we could use islice_extended
which allows for negative values
values_of_interest = list(more_itertools.islice_extended(self.ydata, -2*self.half_window_size, 0))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh that looks good! I will implement it
src/applications/oscilloscope.py
Outdated
if self.show_rolling_mean: | ||
new_rm_value = self.update_rolling_mean() | ||
self.rolling_mean_line.set_ydata(self.rolling_mean) | ||
|
||
if self.show_reading_text: | ||
text = self._get_text_value(y) | ||
if self.show_rolling_mean: | ||
text = f'{text}\n {self._get_text_value(new_rm_value)}' | ||
measured_stdev = self.get_new_rolling_stdev_val() | ||
expected_stdev = np.sqrt(new_rm_value) | ||
text = f'{text}\n {self._get_text_value(measured_stdev)} ({self._get_text_value(expected_stdev)})' | ||
self.current_value_text.set_text(text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, instead of creating a list in memory for rolling mean and updating it every time, can we just use the scipy.uniform_filter1d here directly on self.ydata at each update to generate a full rolling mean? Or is that incredibly slow and why you chose not to use that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how slow it would be, I haven't tested it. At the time of writing, I thought it would be best to not call the filter, since it is a convolution function (if I remember correctly) and I believe they can get quite expensive.
rolling_mean[:self.half_window_size] = np.nan | ||
rolling_mean[len(self.ydata) - self.half_window_size:] = np.nan | ||
return rolling_mean | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See message above asking if we need to store a self.rolling_mean list in memory and perform this popleft / append step every time. It makes sense if using scipy to compute the full rolling mean is slow.
src/applications/oscilloscope.py
Outdated
# TODO: Put all axis preferences to .mplstyle and load through terminal or gui. | ||
self.ax.set_ylabel('Reading (counts / sec)') | ||
self.ax.ticklabel_format(style='sci', scilimits=(-3, 4), axis='y') | ||
self.ax.set_xlabel('Acquisition Number') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we could format the x-axis so it displays values of time..... Any other labels we could use here? "Time bin"? or "Time (arb. units)" until somebody does the work to convert the values to actual time values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am planning on implementing a different method on collecting data with the new device interface class, which will always include time stamps. For now, maybe we can multiply the index number with the acquisition period?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking into it, I realized that the ScopeFigure does not know anything about the update interval, so we should probably leave it that way for now. Updated it to "Time bin (arb. units)"
Just an update:
|
Hey @vasilisniaouris -- I totally forgot about this PR. I'm wondering if we can cherry pick some of the code in here after we've finished the interface. It will probably be difficult to merge them together at this point, unfortunately. |
Hello all. This is my attempt to tackle issues 54 and 93. I have tested this code on my own setup in the QDL lab. I am attaching two example pictures of how it looks like with random data and with real data.