From 3b01eec573b07bad484ed9741fd75d7717ef9adc Mon Sep 17 00:00:00 2001 From: kasbaker Date: Wed, 22 Jul 2020 19:35:18 -0700 Subject: [PATCH 1/4] Added EPhysDataSet.sweep_numbers as @property to quickly get sweep numbers without generating sweep_table. --- ipfx/dataset/ephys_data_set.py | 69 ++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/ipfx/dataset/ephys_data_set.py b/ipfx/dataset/ephys_data_set.py index e49fcf79..c63ebe29 100644 --- a/ipfx/dataset/ephys_data_set.py +++ b/ipfx/dataset/ephys_data_set.py @@ -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. """ @@ -82,30 +82,35 @@ 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 a numpy.ndarray containing 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 @@ -148,16 +153,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)] @@ -198,7 +203,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 @@ -214,7 +219,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 @@ -235,8 +240,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, ) @@ -258,15 +263,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 @@ -328,12 +333,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 @@ -347,7 +352,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 @@ -357,14 +362,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 @@ -383,7 +388,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 @@ -396,11 +401,11 @@ 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 @@ -408,14 +413,14 @@ def _voltage_current( 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 From 2708d3bfa7cd4049ef73dd613d87e8a4c70e0a9f Mon Sep 17 00:00:00 2001 From: kasbaker Date: Wed, 22 Jul 2020 20:04:10 -0700 Subject: [PATCH 2/4] Wrote a more verbose docstring for sweep_numbers() --- ipfx/dataset/ephys_data_set.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ipfx/dataset/ephys_data_set.py b/ipfx/dataset/ephys_data_set.py index c63ebe29..6e6634b5 100644 --- a/ipfx/dataset/ephys_data_set.py +++ b/ipfx/dataset/ephys_data_set.py @@ -88,7 +88,14 @@ def sweep_info(self, value): @property def sweep_numbers(self): - """ Returns a numpy.ndarray containing the sweep numbers. """ + """ 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__( From 87b2397a302df3bc57f4a651bf4547a160c2ba48 Mon Sep 17 00:00:00 2001 From: kasbaker Date: Wed, 22 Jul 2020 20:22:53 -0700 Subject: [PATCH 3/4] Updated CHANGELOG.md --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 678769de..0faa0a64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. \ No newline at end of file +- numerous features, [documentation](https://ipfx.readthedocs.io/en/latest/) updates, and bugfixes have been incorporated into IPFX. From d2b1db7223023d294a0d1844a963bc7dc92dcc63 Mon Sep 17 00:00:00 2001 From: kasbaker Date: Wed, 22 Jul 2020 20:36:47 -0700 Subject: [PATCH 4/4] Updated version.txt --- ipfx/version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipfx/version.txt b/ipfx/version.txt index afaf360d..7dea76ed 100644 --- a/ipfx/version.txt +++ b/ipfx/version.txt @@ -1 +1 @@ -1.0.0 \ No newline at end of file +1.0.1