Skip to content

Commit

Permalink
Removed unnecessary method, smaller doc fixes and dangerous parameter…
Browse files Browse the repository at this point in the history
… defaults
  • Loading branch information
mdenker committed Oct 31, 2023
1 parent 3e521c6 commit a55e2e3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 91 deletions.
6 changes: 3 additions & 3 deletions doc/reference/trials.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
======================
Trials representations
======================
=====================
Trial representations
=====================

.. automodule:: elephant.trials
6 changes: 3 additions & 3 deletions elephant/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ def instantaneous_rate(spiketrains, sampling_period, kernel='auto',
if pool_trials:
list_of_lists_of_spiketrains = [
spiketrains.get_spiketrains_from_trial_as_list(
trial_number=trial_no)
trial_id=trial_no)
for trial_no in range(spiketrains.n_trials)]

spiketrains_cross_trials = (
Expand Down Expand Up @@ -868,13 +868,13 @@ def instantaneous_rate(spiketrains, sampling_period, kernel='auto',
if not pool_trials and not pool_spike_trains:
return [instantaneous_rate(
spiketrains.get_spiketrains_from_trial_as_list(
trial_number=trial_no), sampling_period, **kwargs)
trial_id=trial_no), sampling_period, **kwargs)
for trial_no in range(spiketrains.n_trials)]

if not pool_trials and pool_spike_trains:
rates = [instantaneous_rate(
spiketrains.get_spiketrains_from_trial_as_list(
trial_number=trial_no), sampling_period, **kwargs)
trial_id=trial_no), sampling_period, **kwargs)
for trial_no in range(spiketrains.n_trials)]

average_rates = (np.mean(rate, axis=1) for rate in rates)
Expand Down
20 changes: 0 additions & 20 deletions elephant/test/test_trials.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,6 @@ def test_trials_from_block_n_analogsignals_trial_by_trial(self) -> None:
[len(trial.analogsignals) for trial in
self.block.segments])

def test_trials_from_block_get_spiketrains_from_trial(self) -> None:
"""
Test get spiketrains from trial as SpikeTrainList
"""
self.assertIsInstance(self.trial_object.get_spiketrains_from_trial(0),
neo.core.spiketrainlist.SpikeTrainList)
self.assertIsInstance(
self.trial_object.get_spiketrains_from_trial_as_list(0)[0],
neo.core.SpikeTrain)

def test_trials_from_block_get_spiketrains_from_trial_as_list(self
) -> None:
"""
Expand Down Expand Up @@ -291,16 +281,6 @@ def test_trials_from_list_n_analogsignals_trial_by_trial(self) -> None:
neo.core.AnalogSignal),
trial)) for trial in self.trial_list])

def test_trials_from_list_get_spiketrains_from_trial(self) -> None:
"""
Test get spiketrains from trial as SpikeTrainList
"""
self.assertIsInstance(self.trial_object.get_spiketrains_from_trial(0),
neo.core.spiketrainlist.SpikeTrainList)
self.assertIsInstance(
self.trial_object.get_spiketrains_from_trial_as_list(0)[0],
neo.core.SpikeTrain)

def test_trials_from_list_get_spiketrains_from_trial_as_list(self) -> None:
"""
Test get spiketrains from trial as list
Expand Down
99 changes: 34 additions & 65 deletions elephant/trials.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ def n_analogsignals_trial_by_trial(self) -> List[int]:
pass

@abstractmethod
def get_trial_as_segment(self, trials_id: int) -> neo.core.Segment:
def get_trial_as_segment(self, trial_id: int) -> neo.core.Segment:
"""Get trial as segment.
Parameters
----------
trials_id : int
trial_id : int
Trial number to get (starting at trial ID 0).
Returns
Expand Down Expand Up @@ -162,38 +162,19 @@ def get_trials_as_list(self, trial_ids: List[int] = None
pass

@abstractmethod
def get_spiketrains_from_trial(self, trial_id: int
) -> List[
neo.core.spiketrainlist.SpikeTrainList]:
"""
Get all spike trains from a specific trial and return a list.
Parameters
----------
trial_id : int
Trial ID to get the spike trains from (starting at trial ID 0).
Returns
-------
list_of_spike_trains : class:`neo.SpikeTrainList`
List of all spike trains of the trial.
"""
pass

@abstractmethod
def get_spiketrains_from_trial_as_list(self, trial_number: int) -> (
def get_spiketrains_from_trial_as_list(self, trial_id: int) -> (
neo.core.spiketrainlist.SpikeTrainList):
"""
Get all spike trains from a specific trial and return a list.
Parameters
----------
trial_number : int
trial_id : int
Trial ID to get the spike trains from (starting at trial ID 0).
Returns
-------
list_of_spike_trains : list class:`neo.SpikeTrain`
list of :class:`neo.SpikeTrain`
List of all spike trains of the trial.
"""
pass
Expand All @@ -211,8 +192,7 @@ def get_spiketrains_from_trial_as_segment(self, trial_id: int
Returns
-------
segment_with_spiketrains : :class:`neo.Segment`
Segment containing all spike trains of the trial.
:class:`neo.Segment`: Segment containing all spike trains of the trial.
"""
pass

Expand All @@ -229,13 +209,13 @@ def get_analogsignals_from_trial_as_list(self, trial_id: int
Returns
-------
list_of_analogsignals : list of class`neo.AnalogSignal`
List of all analogsignal objects of the trial.
list of :class`neo.AnalogSignal`: list of all analogsignal objects of
the trial.
"""
pass

@abstractmethod
def get_analogsignals_from_trial_as_segment(self, trial_id: int = 0
def get_analogsignals_from_trial_as_segment(self, trial_id: int
) -> neo.core.Segment:
"""
Get all analogsignal objects from a specific trial and return a
Expand All @@ -248,8 +228,8 @@ def get_analogsignals_from_trial_as_segment(self, trial_id: int = 0
Returns
-------
segment_with_analogsignals : class:`neo.Segment`
Segment containing all analogsignal objects of the trial.
class:`neo.Segment`: segment containing all analogsignal objects of
the trial.
"""


Expand Down Expand Up @@ -277,9 +257,9 @@ def __init__(self, block: neo.core.block, **kwargs):
def __getitem__(self, trial_number: int) -> neo.core.segment:
return self.block.segments[trial_number]

def get_trial_as_segment(self, trials_id: int) -> neo.core.Segment:
def get_trial_as_segment(self, trial_id: int) -> neo.core.Segment:
# Get a specific trial by number as a segment
return self.__getitem__(trials_id)
return self.__getitem__(trial_id)

def get_trials_as_block(self, trial_ids: List[int] = None
) -> neo.core.Block:
Expand Down Expand Up @@ -314,34 +294,29 @@ def n_analogsignals_trial_by_trial(self) -> List[int]:
# Get the number of AnalogSignals instances in each trial.
return [len(trial.analogsignals) for trial in self.block.segments]

def get_spiketrains_from_trial(self, trial_id: int
) -> List[
neo.core.spiketrainlist.SpikeTrainList]:
return self.block.segments[trial_id].spiketrains

def get_spiketrains_from_trial_as_list(self, trial_number: int = 0) -> (
def get_spiketrains_from_trial_as_list(self, trial_id: int = 0) -> (
neo.core.spiketrainlist.SpikeTrainList):
# Return a list of all spiketrains from a trial
# Return a list of all spike trains from a trial
return SpikeTrainList(items=[spiketrain for spiketrain in
self.block.segments[trial_number].spiketrains])
self.block.segments[trial_id].spiketrains])

def get_spiketrains_from_trial_as_segment(self, trial_id: int = 0
) -> neo.core.Segment:
def get_spiketrains_from_trial_as_segment(self, trial_id: int) -> (
neo.core.Segment):
# Return a segment with all spiketrains from a trial
segment = neo.core.Segment()
for spiketrain in self.get_spiketrains_from_trial_as_list(trial_id
):
segment.spiketrains.append(spiketrain)
return segment

def get_analogsignals_from_trial_as_list(self, trial_id: int = 0
) -> List[neo.core.AnalogSignal]:
def get_analogsignals_from_trial_as_list(self, trial_id: int) -> (
List[neo.core.AnalogSignal]):
# Return a list of all analogsignals from a trial
return [analogsignal for analogsignal in
self.block.segments[trial_id].analogsignals]

def get_analogsignals_from_trial_as_segment(self, trial_id: int = 0
) -> neo.core.Segment:
def get_analogsignals_from_trial_as_segment(self, trial_id: int) -> (
neo.core.Segment):
# Return a segment with all analogsignals from a trial
segment = neo.core.Segment()
for analogsignal in self.get_analogsignals_from_trial_as_list(
Expand All @@ -358,7 +333,7 @@ class TrialsFromLists(Trials):
----------
list_of_trials : list of lists
A list of lists. Each list entry contains a list of neo.SpikeTrains
or neo.AnalogSignals.
and/or neo.AnalogSignals.
description : string, optional
A textual description of the set of trials. Can be accessed via the
class attribute `description`.
Expand All @@ -381,9 +356,9 @@ def __getitem__(self, trial_number: int) -> neo.core.Segment:
segment.analogsignals.append(element)
return segment

def get_trial_as_segment(self, trials_id: int) -> neo.core.Segment:
def get_trial_as_segment(self, trial_id: int) -> neo.core.Segment:
# Get a specific trial by number as a segment
return self.__getitem__(trials_id)
return self.__getitem__(trial_id)

def get_trials_as_block(self, trial_ids: List[int] = None
) -> neo.core.Block:
Expand Down Expand Up @@ -420,36 +395,30 @@ def n_analogsignals_trial_by_trial(self) -> List[int]:
return [sum(map(lambda x: isinstance(x, neo.core.AnalogSignal), trial))
for trial in self.list_of_trials]

def get_spiketrains_from_trial(self, trial_id: int
) -> neo.core.spiketrainlist.SpikeTrainList:
return neo.core.spiketrainlist.SpikeTrainList(
items=self.get_spiketrains_from_trial_as_list(trial_id))

def get_spiketrains_from_trial_as_list(self, trial_number: int = 0) -> (
def get_spiketrains_from_trial_as_list(self, trial_id: int = 0) -> (
neo.core.spiketrainlist.SpikeTrainList):
# Return a list of all spiketrains from a trial
return SpikeTrainList(items=[
spiketrain for spiketrain in self.list_of_trials[trial_number]
spiketrain for spiketrain in self.list_of_trials[trial_id]
if isinstance(spiketrain, neo.core.SpikeTrain)])

def get_spiketrains_from_trial_as_segment(self, trial_id: int = 0
) -> neo.core.Segment:
def get_spiketrains_from_trial_as_segment(self, trial_id: int) -> (
neo.core.Segment):
# Return a segment with all spiketrains from a trial
segment = neo.core.Segment()
for spiketrain in self.get_spiketrains_from_trial_as_list(trial_id
):
for spiketrain in self.get_spiketrains_from_trial_as_list(trial_id):
segment.spiketrains.append(spiketrain)
return segment

def get_analogsignals_from_trial_as_list(self, trial_id: int = 0
) -> List[neo.core.AnalogSignal]:
def get_analogsignals_from_trial_as_list(self, trial_id: int) -> (
List[neo.core.AnalogSignal]):
# Return a list of all analogsignals from a trial
return [analogsignal for analogsignal in
self.list_of_trials[trial_id]
if isinstance(analogsignal, neo.core.AnalogSignal)]

def get_analogsignals_from_trial_as_segment(self, trial_id: int = 0
) -> neo.core.Segment:
def get_analogsignals_from_trial_as_segment(self, trial_id: int) -> (
neo.core.Segment):
# Return a segment with all analogsignals from a trial
segment = neo.core.Segment()
for analogsignal in self.get_analogsignals_from_trial_as_list(
Expand Down

0 comments on commit a55e2e3

Please sign in to comment.