Skip to content

Spiketrain behavior on rescale changed #613

Closed

Description

@mdenker

The behavior when rescaling a SpikeTrain changed in 0.7.0 proposed, and is now very counter-intuitive. The change surfaces in a number of tests in Elephant.

Behavior 0.5.2 (t_start and t_stop are rescaled accordingly):

In [1]: import quantities as pq
In [2]: import neo
In [3]: a=neo.SpikeTrain([1,2,3]*pq.ms,t_start=0*pq.s,t_stop=10*pq.h)
In [4]: b=a.rescale(pq.s)
In [5]: print b
[0.001 0.002 0.003] s
In [6]: print b.t_start
0.0 s
In [7]: print b.t_stop
36000.0 s

Behavior 0.7.0 (t_start and t_stop are rescaled to millisecond):

In [1]: import quantities as pq
In [2]: import neo
In [3]: a=neo.SpikeTrain([1,2,3]*pq.ms,t_start=0*pq.s,t_stop=10*pq.h)
In [4]: b=a.rescale(pq.s)
In [5]: print b
[0.001 0.002 0.003] s
In [6]: print b.t_start
0.0 ms
In [7]: print b.t_stop
36000000.0 ms

Activity

  1. added this to the 0.7.0 milestone on Nov 27, 2018
  2. mdenker commented on Nov 27, 2018

    @mdenker
    MemberAuthor
  3. mdenker commented on Nov 27, 2018

    @mdenker
    MemberAuthor

    Further investigation yields that in 0.7 when rescaling the spiketrain, this calls the __new__ of a new Spiketrain instance, which in turn uses the dimensionality of the times property of the original object to set that of t_start and t_stop, i.e., if the spike train a above would have times in hourse, t_start in the new object would be in hours.

    In 0.5.2, the rescale() method of Spiketrains has this code

    if self.dimensionality == pq.quantity.validate_dimensionality(units):
        return self.copy()
    spikes = self.view(pq.Quantity)
    obj = SpikeTrain(times=spikes, t_stop=self.t_stop, units=units,
                             sampling_rate=self.sampling_rate,
                             t_start=self.t_start, waveforms=self.waveforms,
                             left_sweep=self.left_sweep, name=self.name,
                             file_origin=self.file_origin,
                             description=self.description, **self.annotations)
    

    that is replaced in 0.7.0 by

    obj = super(SpikeTrain, self).rescale(units)
    

    The 0.7.0 version is simpler and nicer, but there must be something in the 0.5.2 version we should put back in -- I just don't see what yet...

  4. apdavison commented on Nov 27, 2018

    @apdavison
    Member

    see #614

  5. mdenker commented on Nov 27, 2018

    @mdenker
    MemberAuthor

    @apdavison Great, that is a simple solution to solve the issue, and also helps with Elephant's unit tests

  6. added a commit that references this issue on Nov 27, 2018
  7. samuelgarcia commented on Nov 27, 2018

    @samuelgarcia
    Contributor

    close by #614

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions