-
Notifications
You must be signed in to change notification settings - Fork 4
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
addition of a more realistic, less nice, example signal #3
Conversation
…. Addition of discarding of timesteps based on selected valued in the figure, which is then automatically applied to the signal graph. TST graph is now also separated into a stationary range and discarded part. Addition of moving average in signal graph
…. Addition of discarding of timesteps based on selected valued in the figure, which is then automatically applied to the signal graph. TST graph is now also separated into a stationary range and discarded part. Addition of moving average in signal graph
pyTST/core.py
Outdated
|
||
moving_average : array of float | ||
moving average based on the used step size |
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.
moving_average is not a parameter for load_data_array, so this docstring shouldn't be there.
pyTST/core.py
Outdated
""" | ||
|
||
self.signal_array = signal_array | ||
if time_array is None: | ||
self.time_array = (np.array(range(len(self.signal_array)))+1)*tstep | ||
else: | ||
self.time_array = time_array | ||
self.moving_average = np.array(signal_array.size) |
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.
is this needed?
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.
You are right, it can be removed
pyTST/core.py
Outdated
@@ -170,7 +189,8 @@ def import_from_txt(self, filename): | |||
self.u95_array = timedata[:, 1] | |||
self.mean_array = timedata[:, 2] | |||
|
|||
def plot(self, filename=None, show_cursor=True): | |||
def plot(self, filename=None, fileFormat='.png',show_cursor=True,\ | |||
selectTimeDiscard=True,step_size=10): |
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.
try to be consistent with the naming convention, ie: here don't use camel case since everything else is snake case (see https://www.python.org/dev/peps/pep-0008)
and with this it is no longer a filename but only a prefix
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 never heard about the terms camel vs snake case. Good point
pyTST/core.py
Outdated
@@ -181,19 +201,23 @@ def plot(self, filename=None, show_cursor=True): | |||
if provided, the plot will be exported to filename | |||
|
|||
show_cursor : bool, optional | |||
True if a cursor is ploted. Double clicking on the plot will move it | |||
True if a cursor is plotted. Double clicking on the plot will move it | |||
selectTimeDiscard: bool, optional |
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.
add newline between comments here
pyTST/core.py
Outdated
ax0.loglog(self.step_time_array[:self.step_time_array.size - (self.step_time_array.size-index)], self.u95_array[:(self.step_time_array.size-index-1):-1], color='C0') | ||
ax0.loglog(self.step_time_array[self.step_time_array.size - (self.step_time_array.size-index):], self.u95_array[(self.step_time_array.size-index-1)::-1], color='C1') |
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.
these lines are too long and should have at least one line break.
also self.step_time_array.size is used a lot, storing it in a variable will make it easier to read
pyTST/core.py
Outdated
pyplot.draw() | ||
global indexGlobal |
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.
is a global variable really needed. These should be avoided, and are 90% of the time not useful. Here you can just use self.current_index and update that in the onclick function I think
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.
(and again camel case when it should be snake case
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.
In principle I completely agree! However I couldn't get it to work without it (I spend quite some time on it yesterday), but I'll try your suggestion
pyTST/core.py
Outdated
text.set_text('u95={:2e}\nt={}'.format(min_u95, discard_time)) | ||
print("t={}, mean={:e} ± {:e}".format(discard_time, self.mean_array[-index-1], min_u95)) | ||
print("t={}, mean={:e} ± {:e}".format(discard_time, self.mean_array[-index-1], min_u95)) | ||
return index |
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.
why do you return index?
pyTST/core.py
Outdated
# Plot input signal data | ||
fig1, ax1 = pyplot.subplots() | ||
|
||
if selectTimeDiscard: | ||
idx = (self.step_time_array.size-indexGlobal)*step_size | ||
else: | ||
idx = index | ||
|
||
ax1.axvline(self.time_array[idx], color='k', lw=0.8, ls='--', alpha=0.6) | ||
|
||
ax1.plot(self.time_array[0:idx], self.signal_array[0:idx], color='C1',linewidth=2,label='discarded time') | ||
ax1.plot(self.time_array[idx:], self.signal_array[idx:], color='C0',linewidth=2,label='stationary region') | ||
ax1.plot(self.time_array,self.moving_average, color='r',label='moving average') | ||
|
||
ax1.set_xlabel("$t / $s",fontsize=16) | ||
ax1.set_ylabel("$\phi$",fontsize=16) | ||
ax1.legend(fontsize=16) |
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 feel like this shouldn't be in pyTST but in the example script. Have self.plot() return the index (that should be called something else, my bad for picking a ugly variable name), and then this can be outside. As it is an example of how ppl can use the TST data to 'understand' their signal. But you don't always want/need to plot your input signal again. And also, you often want to have more freedom in plotting it (like changing the axis names, title etc.)
All in all, I think .plot() should return the index, and fig, ax variables. That way the user can edit the TST plot, and use index to plot the signal.
pyTST/core.py
Outdated
if filename is None: | ||
pyplot.show() | ||
else: | ||
pyplot.show() |
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.
shouldn't have .show() here. You want a way to export the tst plot without having any user interaction (for scripting etc.). Or show a user defined component independent of filename
pyTST/core.py
Outdated
def moving_average(y, n=10) : | ||
y_padded = np.pad(y, (n//2, n-1-n//2), mode='edge') | ||
y_smooth = np.convolve(y_padded, np.ones((n,))/n, mode='valid') | ||
return y_smooth |
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.
As discussed earlier, is it really useful considering self.mean_array already exist.
So ;) I think the end goal should be to have 2 different behaviours for the .plot function:
Right now, having the signal after the TST plot inside pyTST.plot, is a bit of a mix between the two, and I feel like it constrain too much the end user. |
has partially been implemented in master already, and #5 implements the rest. |
No description provided.