Skip to content

Conversation

@Moritz-Alexander-Kern
Copy link
Member

@Moritz-Alexander-Kern Moritz-Alexander-Kern commented Nov 19, 2024

This pull request addresses issue #648 by updating the statistics.time_histogram function to accept a single neo.SpikeTrain object as input.

Previously, the function was limited to handling lists of spike trains, which led to incorrect results when a single spike train was provided. This enhancement ensures that the function now correctly computes the time histogram for both single and multiple spike trains.

Changes

  • Modified the time_histogram function to handle a single neo.SpikeTrain input.
  • The documentation has been updated to reflect this new capability. It now clearly states that the function can accept both a list of spike trains and a single spike train.
  • Added a regression test to ensure that the functionality works as intended for both single and multiple spike trains.
  • Added type hints to time_histogram
  • Removed copy parameter when creating pq.Quantity object

@Moritz-Alexander-Kern Moritz-Alexander-Kern added the enhancement Editing an existing module, improving something label Nov 19, 2024
@coveralls
Copy link
Collaborator

coveralls commented Nov 19, 2024

Coverage Status

coverage: 88.262%. remained the same
when pulling aeb3603 on INM-6:fix/time_histogram_648
into bb0a394 on NeuralEnsemble:master.

@Moritz-Alexander-Kern Moritz-Alexander-Kern added this to the v1.2.0 milestone Nov 19, 2024
Copy link
Member Author

@Moritz-Alexander-Kern Moritz-Alexander-Kern left a comment

Choose a reason for hiding this comment

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

build wheels

Copy link
Collaborator

@kohlerca kohlerca left a comment

Choose a reason for hiding this comment

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

Overall, the proposed changes look good, and the code works as expected. I made small suggestions for improvement and to fix errors in the docstring.

spiketrain = neo.SpikeTrain([0.1, 0.5, 1.0, 1.5, 2.0] * pq.s, t_stop=3.0 * pq.s)

# Run time_histogram with spiketrain directly and observe the incorrect result
histogram_direct = statistics.time_histogram(spiketrain, output='rate', bin_size=0.5 * pq.s)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be more complete to include the three possible output formats, not only 'rate,' to fully cover the changes and ensure correctness.

neo.AnalogSignal
A `neo.AnalogSignal` object containing the histogram values.
`neo.AnalogSignal[j]` is the histogram computed between
A :class:`neo.core.SpikeTrain` object containing the histogram values.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The return is a Neo AnalogSignal object (line 1205)

# 'mean': mean spike counts per spike train.
return pq.Quantity(bin_hist / len(spiketrains),
units=pq.dimensionless, copy=False)
return pq.Quantity(bin_hist / binned_spiketrain.shape[0],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not covered in the additional unit test.

between `t_start` and `t_stop` (both included) are considered in the
histogram.
If None, the maximum `t_start` of all `neo.SpikeTrain`s is used as
If None, the maximum `t_start` of all :class:`neo.core.SpikeTrain`s is used as
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not formatted correctly in ReadTheDocs. A solution is to use

:class:`neo.core.SpikeTrain` objects

as the plural s seems to break the formatting.

between `t_start` and `t_stop` (both included) are considered in the
histogram.
If None, the minimum `t_stop` of all `neo.SpikeTrain`s is used as
If None, the minimum `t_stop` of all :class:`neo.core.SpikeTrain` s is used as
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same suggestion for formatting as above in t_start. This is formatted as expected, but with the link to the class documentation, it is unreadable.

If True, indicates whether all :class:`neo.core.SpikeTrain` objects should first
be binned to a binary representation (using the
`conversion.BinnedSpikeTrain` class) and the calculation of the
[:class:`elephant.conversion.BinnedSpikeTrain` class] and the calculation of the
Copy link
Collaborator

Choose a reason for hiding this comment

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

With the enhancement provided by the class link, the brackets [ ... ] are not needed, and there is the missing closing parenthesis ).

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

Labels

enhancement Editing an existing module, improving something

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Incorrect Output in time_histogram for Single Unit Spike Train with output='rate'

3 participants