Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quickly get sweep numbers without generating sweep table #463

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Change Log
All notable changes to this project will be documented in this file.

## [1.0.1] = 2020-07-22

- Added sweep_numbers as a property of EphysDataSet

## [1.0.0] = 2020-06-30

1.0.0 is the first public release of IPFX. As of this version:
- IPFX is now [on pypi](https://pypi.org/project/IPFX/)! You can install
- IPFX is now [on pypi](https://pypi.org/project/IPFX/)! You can install
- IPFX now supports [NeurodataWithoutBorders](https://www.nwb.org) version 2 in place of version 1.
- IPFX supports Python 3 in place of Python 2.
- numerous features, [documentation](https://ipfx.readthedocs.io/en/latest/) updates, and bugfixes have been incorporated into IPFX.
- numerous features, [documentation](https://ipfx.readthedocs.io/en/latest/) updates, and bugfixes have been incorporated into IPFX.
76 changes: 44 additions & 32 deletions ipfx/dataset/ephys_data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ class EphysDataSet(object):

@property
def ontology(self) -> StimulusOntology:
"""The stimulus ontology maps codified description of the stimulus type
"""The stimulus ontology maps codified description of the stimulus type
to the human-readable descriptions.
"""
return self._data.ontology

@property
def sweep_table(self) -> pd.DataFrame:
"""Each row of the sweep table contains the metadata for a single
sweep. In particular details of the stimulus presented and the clamp
"""Each row of the sweep table contains the metadata for a single
sweep. In particular details of the stimulus presented and the clamp
mode. See EphysDataInterface.get_sweep_metadata for more information.

"""
Expand Down Expand Up @@ -82,30 +82,42 @@ def sweep_info(self, value):
self._sweep_info[sweep["sweep_number"]] = sweep
else:
self._sweep_info = value

if hasattr(self, "_sweep_table"):
del self._sweep_table

@property
def sweep_numbers(self):
""" Returns array containing all sweep numbers in this data set.

Returns
-------
sweep_numbers : numpy.ndarray
Array containing all the sweep numbers

"""
return self._data.sweep_numbers

def __init__(
self,
data: EphysDataInterface,
sweep_info: Optional[List[Dict]] = None
):
"""EphysDataSet is the preferred interface for running analyses or
"""EphysDataSet is the preferred interface for running analyses or
pipeline code.

Parameters
----------
data : This object must implement the EphysDataInterface. It will
handle any loading of data from external sources (such as NWB2
data : This object must implement the EphysDataInterface. It will
handle any loading of data from external sources (such as NWB2
files)
"""
self._data: EphysDataInterface = data
self.sweep_info = sweep_info or []

def _setup_stimulus_repeat_lookup(self):
"""Each sweep contains the ith repetition of some stimulus (from 1 ->
the number of times that stimulus was presented). Find i for each
"""Each sweep contains the ith repetition of some stimulus (from 1 ->
the number of times that stimulus was presented). Find i for each
sweep.

Notes
Expand Down Expand Up @@ -148,16 +160,16 @@ def filtered_sweep_table(

if stimuli:
mask = st[self.STIMULUS_CODE].apply(
self.ontology.stimulus_has_any_tags,
args=(stimuli,),
self.ontology.stimulus_has_any_tags,
args=(stimuli,),
tag_type="code"
)
st = st[mask.astype(bool)]

if stimuli_exclude:
mask = ~st[self.STIMULUS_CODE].apply(
self.ontology.stimulus_has_any_tags,
args=(stimuli_exclude,),
self.ontology.stimulus_has_any_tags,
args=(stimuli_exclude,),
tag_type="code"
)
st = st[mask.astype(bool)]
Expand Down Expand Up @@ -198,7 +210,7 @@ def get_sweep_number(
stimuli: Collection[str],
clamp_mode: Optional[str] = None
) -> int:
"""Convenience for getting the integer identifier of the temporally
"""Convenience for getting the integer identifier of the temporally
latest sweep matching argued criteria.

Parameters
Expand All @@ -214,7 +226,7 @@ def get_sweep_number(

def sweep(self, sweep_number: int) -> Sweep:
"""
Create an instance of the Sweep class with the data loaded from the
Create an instance of the Sweep class with the data loaded from the
from a file

Parameters
Expand All @@ -235,8 +247,8 @@ def sweep(self, sweep_number: int) -> Sweep:

voltage, current = type(self)._voltage_current(
sweep_data["stimulus"],
sweep_data["response"],
sweep_metadata["clamp_mode"],
sweep_data["response"],
sweep_metadata["clamp_mode"],
enforce_equal_length=True,
)

Expand All @@ -258,15 +270,15 @@ def sweep(self, sweep_number: int) -> Sweep:
return sweep

def sweep_set(
self,
self,
sweep_numbers: Union[Sequence[int], int, None] = None
) -> SweepSet:
"""Construct a SweepSet object, which offers convenient access to an
"""Construct a SweepSet object, which offers convenient access to an
ordered collection of sweeps.

Parameters
----------
sweep_numbers : Identifiers for the sweeps which will make up this set.
sweep_numbers : Identifiers for the sweeps which will make up this set.
If None, use all available sweeps.

Returns
Expand Down Expand Up @@ -328,12 +340,12 @@ def get_sweep_data(self, sweep_number: int) -> Dict:
return sweep_data

def get_clamp_mode(self, sweep_number: int) -> str:
"""Obtain the clamp mode of a given sweep. Should be one of
"""Obtain the clamp mode of a given sweep. Should be one of
EphysDataSet.VOLTAGE_CLAMP or EphysDataSet.CURRENT_CLAMP

Parameters
----------
sweep_number : identifier for the sweep whose clamp mode will be
sweep_number : identifier for the sweep whose clamp mode will be
returned

Returns
Expand All @@ -347,7 +359,7 @@ def get_stimulus_code(self, sweep_number: int) -> str:

Parameters
----------
sweep_number : identifier for the sweep whose stimulus code will be
sweep_number : identifier for the sweep whose stimulus code will be
returned

Returns
Expand All @@ -357,14 +369,14 @@ def get_stimulus_code(self, sweep_number: int) -> str:
return self._data.get_stimulus_code(sweep_number)

def get_stimulus_code_ext(self, sweep_number: int) -> str:
"""Obtain the extended stimulus code for a sweep. This is the stimulus
code for that sweep augmented with an integer counter describing the
number of presentations of that stimulus up to and including the
"""Obtain the extended stimulus code for a sweep. This is the stimulus
code for that sweep augmented with an integer counter describing the
number of presentations of that stimulus up to and including the
requested sweep.

Parameters
----------
sweep_number : identifies the sweep whose extended stimulus code will
sweep_number : identifies the sweep whose extended stimulus code will
be returned

Returns
Expand All @@ -383,7 +395,7 @@ def get_stimulus_units(self, sweep_number: int) -> str:

Parameters
----------
sweep_number : identifies the sweep whose stimulus unit will be
sweep_number : identifies the sweep whose stimulus unit will be
returned

Returns
Expand All @@ -396,26 +408,26 @@ def get_stimulus_units(self, sweep_number: int) -> str:
def _voltage_current(
cls,
stimulus: np.ndarray,
response: np.ndarray,
response: np.ndarray,
clamp_mode: str,
enforce_equal_length: bool = True
) -> Tuple[np.array, np.array]:
"""Resolve the stimulus and response arrays from a sweep's data into
"""Resolve the stimulus and response arrays from a sweep's data into
voltage and current, using the clamp mode as a guide

Parameters
----------
stimulus : stimulus trace
response : response trace
clamp_mode : Used to map stimulus and response to voltage and current
enforce_equal_length : Raise a ValueError if the stimulus and
enforce_equal_length : Raise a ValueError if the stimulus and
response arrays have uneven numbers of samples

Returns
-------
The voltage and current traces.

"""
"""

if clamp_mode == cls.VOLTAGE_CLAMP:
voltage = stimulus
Expand Down
2 changes: 1 addition & 1 deletion ipfx/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.0.1