Skip to content

Commit

Permalink
Added a simplified to correctly handle division with Compound Units (N…
Browse files Browse the repository at this point in the history
…euralEnsemble#270)

.magnitude -> .simplified.magnitude
  • Loading branch information
mdenker authored and dizcza committed Nov 8, 2019
1 parent 5dfa042 commit 092d2fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion elephant/phase_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def spike_triggered_phase(hilbert_transform, spiketrains, interpolate):
# Find index into signal for each spike
ind_at_spike = np.round(
(spiketrain[sttimeind] - hilbert_transform[phase_i].t_start) /
hilbert_transform[phase_i].sampling_period).magnitude.astype(int)
hilbert_transform[phase_i].sampling_period). \
simplified.magnitude.astype(int)

# Extract times for speed reasons
times = hilbert_transform[phase_i].times
Expand Down
16 changes: 16 additions & 0 deletions elephant/test/test_phase_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ def test_spike_later_than_hilbert(self):
interpolate=False)
self.assertEqual(len(phases_noint[0]), 1)

# This test handles the correct dealing with input signals that have
# different time units, including a CompoundUnit
def test_regression_269(self):
# This is a spike train on a 30KHz sampling, one spike at 1s, one just
# before the end of the signal
cu = pq.CompoundUnit("1/30000.*s")
st = SpikeTrain(
[30000., (self.anasig0.t_stop-1*pq.s).rescale(cu).magnitude],
units=pq.CompoundUnit("1/30000.*s"),
t_start=-1*pq.s, t_stop=300*pq.s)
phases_noint, _, _ = elephant.phase_analysis.spike_triggered_phase(
elephant.signal_processing.hilbert(self.anasig0),
st,
interpolate=False)
self.assertEqual(len(phases_noint[0]), 2)


if __name__ == '__main__':
unittest.main()

0 comments on commit 092d2fb

Please sign in to comment.