Skip to content

Conversation

jonathanduperrier
Copy link

add to_epoch method in Event class: Transform Events into an array of Epoch

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 49.749% when pulling f667671 on jonathanduperrier:master into 1e8ddf9 on NeuralEnsemble:master.

print("self.label : " + str(self.labels))
i = 0
duration = []
for t in self.times:
Copy link
Member

Choose a reason for hiding this comment

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

variable t is never used. Maybe it would be better to use 'for i in range(len(self.times)):'?

if i==0 :
duration.append(self.times[i])
else :
duration.append(self.times[i] - self.times[i-1])
Copy link
Member

Choose a reason for hiding this comment

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

for a better performace you could use np.diff(self.times) to calculate the durations instead of looping.

@JuliaSprenger
Copy link
Member

It looks as if you are generating epochs with starting at the times of the events, but having a duration corresponding to the time difference since the previous event. I would have rather expected epochs spanning the time between the events. Is this intended and under which conditions is it useful?
It would also help to add some documentation clarifying this as well as a unittest.
I am also not sure if a function like this should be a method of Events or rather should be available in an extended fashion as a general helper function. @apdavison: Any opinions on that?

@NeuralEnsemble NeuralEnsemble deleted a comment from coveralls Sep 29, 2017
@apdavison
Copy link
Member

@JuliaSprenger yes, I think the indexing is off by one.

We discussed in Lausanne the question of whether to make this a method or a helper function. There are arguments for both. In the end, I think having it as a method gives better discoverability - it is attached to the Event class, which I think makes it easier to find if you already have an Event object, compared to having to search through a potentially long list of helper functions. Of course we could have both, where the helper function calls the method or vice versa.

@jonathanduperrier I think the top priority now is to add some unit tests (in the file neo/test/coretest/test_event.py). The example given in #388 would be a good starting point.

@apdavison apdavison added this to the 0.6.0 milestone Sep 29, 2017
@coveralls
Copy link

coveralls commented Sep 29, 2017

Coverage Status

Coverage increased (+0.05%) to 49.817% when pulling e9e13a0 on jonathanduperrier:master into 1e8ddf9 on NeuralEnsemble:master.

@samuelgarcia
Copy link
Contributor

This looks also very strange to me.

I add in mind that to_epoch would be:

Epoch(time=event.times[:-1], durations=np.diff(event.times), labels=event.labels[:-1])

Here, in thisimplementation, the duration is with the previsous event. I don't get the use case.

@JuliaSprenger
Copy link
Member

I agree with @samuelgarcia, this should be the default behaviour of the function. However, do you think it would make sense to introduce the option to provide durations in case you don't want to cover the whole recording time with the epochs but only specific time windows after the events?

def to_epoch(durations=None):
    if durations is None:
        times = self.times[:-1]
        durations = np.diff(self.times)[:-1]
        labels = self.labels[:-1]
    else:
        times = self.times
        labels = self.labels
    return Epoch(time=times, durations=durations, labels=labels)

@pep8speaks
Copy link

pep8speaks commented Mar 1, 2018

Hello @jonathanduperrier! Thanks for updating the PR.

Line 21:1: E302 expected 2 blank lines, found 1
Line 21:34: E251 unexpected spaces around keyword / parameter equals
Line 21:36: E251 unexpected spaces around keyword / parameter equals
Line 21:78: W291 trailing whitespace
Line 26:70: W291 trailing whitespace
Line 28:100: E501 line too long (105 > 99 characters)
Line 29:18: E127 continuation line over-indented for visual indent
Line 33:1: E302 expected 2 blank lines, found 1
Line 110:5: E301 expected 1 blank line, found 0
Line 227:50: W291 trailing whitespace
Line 249:1: W293 blank line contains whitespace
Line 253:100: E501 line too long (104 > 99 characters)

Line 22:16: E271 multiple spaces after keyword
Line 118:25: E211 whitespace before '('
Line 126:1: W293 blank line contains whitespace
Line 127:23: E201 whitespace after '['
Line 127:37: E202 whitespace before ']'
Line 128:56: E202 whitespace before ')'
Line 145:44: W291 trailing whitespace
Line 148:60: E202 whitespace before ')'
Line 165:60: E202 whitespace before ')'
Line 167:1: W293 blank line contains whitespace
Line 182:46: W291 trailing whitespace
Line 183:23: E201 whitespace after '['
Line 183:47: E202 whitespace before ']'
Line 185:1: W293 blank line contains whitespace
Line 197:1: W293 blank line contains whitespace
Line 206:1: W293 blank line contains whitespace
Line 219:1: W293 blank line contains whitespace
Line 227:1: W293 blank line contains whitespace
Line 228:46: W291 trailing whitespace
Line 241:46: W291 trailing whitespace
Line 247:44: W291 trailing whitespace
Line 248:46: W291 trailing whitespace
Line 250:23: E201 whitespace after '['
Line 250:32: E202 whitespace before ']'
Line 251:21: E128 continuation line under-indented for visual indent
Line 252:21: E128 continuation line under-indented for visual indent
Line 253:21: E128 continuation line under-indented for visual indent
Line 254:45: W291 trailing whitespace
Line 255:47: W291 trailing whitespace
Line 256:1: W293 blank line contains whitespace
Line 440:100: E501 line too long (115 > 99 characters)
Line 441:100: E501 line too long (113 > 99 characters)
Line 451:1: E305 expected 2 blank lines after class or function definition, found 1

Comment last updated on March 02, 2018 at 09:26 Hours UTC

.travis.yml Outdated
# command to run tests, e.g. python setup.py test
script:
nosetests --with-coverage --cover-package=neo
assert_array_equal(epoch.magnitude, np.array([7.0, 11.0, 22.0]))
Copy link
Member

Choose a reason for hiding this comment

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

I suppose you meant to put this line in test_epoch.py?

Copy link
Member

Choose a reason for hiding this comment

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

sorry, I meant test_event.py

@samuelgarcia
Copy link
Contributor

I propose to postpone thie PR for 0.7.

@JuliaSprenger JuliaSprenger modified the milestones: 0.6.0, 0.7.0 Mar 21, 2018
apdavison added a commit to apdavison/python-neo that referenced this pull request Oct 22, 2018
@apdavison
Copy link
Member

Since this now has conflicts, I have updated @jonathanduperrier's code and made a new PR: #586

apdavison added a commit to apdavison/python-neo that referenced this pull request Oct 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants