From 5a1c2d0e2d6d81219994830f06fa8975d48621d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaquier=20Aur=C3=A9lien=20Tristan?= Date: Fri, 21 Jun 2024 16:07:30 +0200 Subject: [PATCH] Fix warnings in sphinx and enforce tox to fail on warnings --- bluepyefe/ecode/DeHyperPol.py | 50 ++++----- bluepyefe/ecode/HyperDePol.py | 30 +++--- bluepyefe/ecode/SpikeRec.py | 24 ++--- bluepyefe/ecode/negCheops.py | 38 +++---- bluepyefe/ecode/posCheops.py | 38 +++---- bluepyefe/ecode/ramp.py | 34 +++---- bluepyefe/ecode/sAHP.py | 26 ++--- bluepyefe/ecode/step.py | 26 ++--- bluepyefe/extract.py | 185 +++++++++++++++++++++------------- bluepyefe/reader.py | 98 ++++++++++-------- bluepyefe/recording.py | 2 +- bluepyefe/rheobase.py | 5 +- docs/source/conf.py | 14 ++- 13 files changed, 321 insertions(+), 249 deletions(-) diff --git a/bluepyefe/ecode/DeHyperPol.py b/bluepyefe/ecode/DeHyperPol.py index 75280e9..0fa8d02 100644 --- a/bluepyefe/ecode/DeHyperPol.py +++ b/bluepyefe/ecode/DeHyperPol.py @@ -3,20 +3,20 @@ """ Copyright (c) 2022, EPFL/Blue Brain Project - This file is part of BluePyEfe +This file is part of BluePyEfe - This library is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License version 3.0 as published - by the Free Software Foundation. +This library is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License version 3.0 as published +by the Free Software Foundation. - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. +This library is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +details. - You should have received a copy of the GNU Lesser General Public License - along with this library; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +You should have received a copy of the GNU Lesser General Public License +along with this library; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ import logging import numpy @@ -34,20 +34,20 @@ class DeHyperPol(Recording): The hyperpolarizing step is usually fixed at 150% of rheobase, and the hyperpolarizing step can usually vary from -40% to -160% of rheobase. - hypamp hypamp+amp hypamp+amp2 hypamp - : : : : - : _________________ : : - : | | : : - : | | : : - |_______________| | : ___________ - ^ ^ | : | ^ - : : | : | : - : : | : | : - : : |____________| : - : : ^ ^ : - : : : : : - : : : : : - t=0 ton tmid toff tend + `` hypamp hypamp+amp hypamp+amp2 hypamp `` + `` : : : : `` + `` : _________________ : : `` + `` : | | : : `` + `` : | | : : `` + ``|_______________| | : ___________ `` + ``^ ^ | : | ^ `` + ``: : | : | : `` + ``: : | : | : `` + ``: : |____________| : `` + ``: : ^ ^ : `` + ``: : : : : `` + ``: : : : : `` + ``t=0 ton tmid toff tend`` """ def __init__( diff --git a/bluepyefe/ecode/HyperDePol.py b/bluepyefe/ecode/HyperDePol.py index 18bfb3e..c3f0aa3 100644 --- a/bluepyefe/ecode/HyperDePol.py +++ b/bluepyefe/ecode/HyperDePol.py @@ -35,21 +35,21 @@ class HyperDePol(Recording): can usually vary from -40% to -160% of rheobase. - hypamp hypamp+amp hypamp+amp2 hypamp - : : : : - : : _____________________ : - : : | | : - : : | | : - : : | | : - : : | | : - : : | | : - |_______________ : | |___________ - ^ | : | ^ ^ - : |___________________| : : - : ^ ^ : : - : : : : : - : : : : : - t=0 ton tmid toff tend + `` hypamp hypamp+amp hypamp+amp2 hypamp `` + `` : : : : `` + `` : : _____________________ : `` + `` : : | | : `` + `` : : | | : `` + `` : : | | : `` + `` : : | | : `` + `` : : | | : `` + ``|_______________ : | |___________ `` + ``^ | : | ^ ^ `` + ``: |___________________| : : `` + ``: ^ ^ : : `` + ``: : : : : `` + ``: : : : : `` + ``t=0 ton tmid toff tend`` """ def __init__( diff --git a/bluepyefe/ecode/SpikeRec.py b/bluepyefe/ecode/SpikeRec.py index 9ff7f4b..36f9521 100644 --- a/bluepyefe/ecode/SpikeRec.py +++ b/bluepyefe/ecode/SpikeRec.py @@ -76,18 +76,18 @@ class SpikeRec(Recording): """SpikeRec current stimulus - hypamp hypamp+amp hypamp hypamp+amp . . . - : : : : - : _________________ : _________________ _________________ - : | | : | | | | - : | | : | | * len(tspike) | | - : | | : | | . . . | | - : | | : | | | | - |_______________| |__________| |__ __| |___ - : : : : : ^ - : : : : : : - : : : : : : - <--tspike[0]--><-spike_duration-><- delta -><-spike_duration-> . . . tend + `` hypamp hypamp+amp hypamp hypamp+amp . . . `` + `` : : : : `` + `` : _________________ : _________________ _________________ `` + `` : | | : | | | | `` + `` : | | : | | * len(tspike) | | `` + `` : | | : | | . . . | | `` + `` : | | : | | | | `` + ``|_______________| |__________| |__ __| |___ `` + ``: : : : : ^ `` + ``: : : : : : `` + ``: : : : : : `` + `` <--tspike[0]--><-spike_duration-><- delta -><-spike_duration-> . . . tend`` """ diff --git a/bluepyefe/ecode/negCheops.py b/bluepyefe/ecode/negCheops.py index 52aa54e..8656ce5 100644 --- a/bluepyefe/ecode/negCheops.py +++ b/bluepyefe/ecode/negCheops.py @@ -34,25 +34,25 @@ class NegCheops(Recording): """NegCheops current stimulus - hypamp hypamp+amp hypamp hypamp+amp hypamp hypamp+amp hypamp - : : : : : : : - : : : : : : : - |__________ : ____________ : ____________ : ____________ - : :\ : /: :\ : /: :\ : /: ^ - : : \ : / : : \ : / : : \ : / : : - : : \ : / : : \ : / : : \ : / : : - : : \ : / : : \ : / : : \ : / : : - : : \ : / : : \ : / : : \ : / : : - : : \ : / : : \ : / : : \ : / : : - : : \ : / : : \ : / : : \ : / : : - : : \ : / : : \ : / : : \ : / : : - : : \ : / : : \ : / : : \ : / : : - : : \ : / : : \ : / : : \ : / : : - : : \ : / : : \ : / : : \ : / : : - : : \ / : : \ / : : \ / : : - : : ' : : ' : : ' : : - : : : : : : : : - t=0 ton t1 t2 t3 t4 toff tend + `` hypamp hypamp+amp hypamp hypamp+amp hypamp hypamp+amp hypamp `` + `` : : : : : : : `` + `` : : : : : : : `` + ``|__________ : ____________ : ____________ : ____________ `` + ``: :\ : /: :\ : /: :\ : /: ^ `` + ``: : \ : / : : \ : / : : \ : / : : `` + ``: : \ : / : : \ : / : : \ : / : : `` + ``: : \ : / : : \ : / : : \ : / : : `` + ``: : \ : / : : \ : / : : \ : / : : `` + ``: : \ : / : : \ : / : : \ : / : : `` + ``: : \ : / : : \ : / : : \ : / : : `` + ``: : \ : / : : \ : / : : \ : / : : `` + ``: : \ : / : : \ : / : : \ : / : : `` + ``: : \ : / : : \ : / : : \ : / : : `` + ``: : \ : / : : \ : / : : \ : / : : `` + ``: : \ / : : \ / : : \ / : : `` + ``: : ' : : ' : : ' : : `` + ``: : : : : : : : `` + ``t=0 ton t1 t2 t3 t4 toff tend`` """ def __init__( diff --git a/bluepyefe/ecode/posCheops.py b/bluepyefe/ecode/posCheops.py index fa3f90d..8f5247d 100644 --- a/bluepyefe/ecode/posCheops.py +++ b/bluepyefe/ecode/posCheops.py @@ -33,25 +33,25 @@ class PosCheops(Recording): """PosCheops current stimulus - hypamp hypamp+amp hypamp hypamp+amp hypamp hypamp+amp hypamp - : : : : : : : - : . : . : . : - : / \ : / \ : / \ : - : / \ : / \ : / \ : - : / \ : / \ : / \ : - : / \ : / \ : / \ : - : / \ : / \ : / \ : - : / \ : / \ : / \ : - : / \ : / \ : / \ : - : / \ : / \ : / \ : - : / \ : / \ : / \ : - : / \ : / \ : / \ : - : / \ : / \ : / \ : - |__________ / \ __________ / \ __________ / \ __________ - : : : : : : : ^ - : : : : : : : : - : : : : : : : : - t=0 ton t1 t2 t3 t4 toff tend + `` hypamp hypamp+amp hypamp hypamp+amp hypamp hypamp+amp hypamp `` + `` : : : : : : : `` + `` : . : . : . : `` + `` : / \ : / \ : / \ : `` + `` : / \ : / \ : / \ : `` + `` : / \ : / \ : / \ : `` + `` : / \ : / \ : / \ : `` + `` : / \ : / \ : / \ : `` + `` : / \ : / \ : / \ : `` + `` : / \ : / \ : / \ : `` + `` : / \ : / \ : / \ : `` + `` : / \ : / \ : / \ : `` + `` : / \ : / \ : / \ : `` + `` : / \ : / \ : / \ : `` + ``|__________ / \ __________ / \ __________ / \ __________ `` + ``: : : : : : : ^ `` + ``: : : : : : : : `` + ``: : : : : : : : `` + ``t=0 ton t1 t2 t3 t4 toff tend`` """ def __init__( diff --git a/bluepyefe/ecode/ramp.py b/bluepyefe/ecode/ramp.py index 8295b87..3cd523e 100644 --- a/bluepyefe/ecode/ramp.py +++ b/bluepyefe/ecode/ramp.py @@ -33,23 +33,23 @@ class Ramp(Recording): """Ramp current stimulus - hypamp hypamp+amp hypamp - : : : - : : : - : /| : - : / | : - : / | : - : / | : - : / | : - : / | : - : / | : - : / | : - : / | : - |___________ / |__________________________ - ^ ^ ^ ^ - : : : : - : : : : - t=0 ton toff tend + `` hypamp hypamp+amp hypamp `` + `` : : : `` + `` : : : `` + `` : /| : `` + `` : / | : `` + `` : / | : `` + `` : / | : `` + `` : / | : `` + `` : / | : `` + `` : / | : `` + `` : / | : `` + `` : / | : `` + ``|___________ / |__________________________ `` + ``^ ^ ^ ^ `` + ``: : : : `` + ``: : : : `` + ``t=0 ton toff tend`` """ def __init__( diff --git a/bluepyefe/ecode/sAHP.py b/bluepyefe/ecode/sAHP.py index 1095687..073c9f4 100644 --- a/bluepyefe/ecode/sAHP.py +++ b/bluepyefe/ecode/sAHP.py @@ -36,19 +36,19 @@ class SAHP(Recording): can usually vary from 150% to 300% of rheobase. - hypamp hypamp+amp hypamp+amp2 hypamp+amp hypamp - : : : : : - : : ______________ : : - : : | | : : - : ____________________| |____________________ : - : | ^ ^ | : - : | : : | : - |__________| : : |__________________ - ^ ^ : : ^ ^ - : : : : : : - : : : : : : - t=0 ton tmid tmid2 toff tend - + `` hypamp hypamp+amp hypamp+amp2 hypamp+amp hypamp `` + `` : : : : : `` + `` : : ______________ : : `` + `` : : | | : : `` + `` : : | | : : `` + `` : ____________________ ____________________ : `` + `` : | ^ ^ | : `` + `` : | : : | : `` + ``|__________| : : |__________________ `` + ``^ ^ : : ^ ^ `` + ``: : : : : : `` + ``: : : : : : `` + ``t=0 ton tmid tmid2 toff tend`` """ def __init__( diff --git a/bluepyefe/ecode/step.py b/bluepyefe/ecode/step.py index ca0f21f..16f0345 100644 --- a/bluepyefe/ecode/step.py +++ b/bluepyefe/ecode/step.py @@ -32,19 +32,19 @@ class Step(Recording): """Step current stimulus - hypamp hypamp+amp hypamp - : : : - : : : - : ______________________ : - : | | : - : | | : - : | | : - : | | : - |__________________| |______________________ - ^ ^ ^ ^ - : : : : - : : : : - t=0 ton toff tend + `` hypamp hypamp+amp hypamp `` + `` : : : `` + `` : : : `` + `` : ______________________ : `` + `` : | | : `` + `` : | | : `` + `` : | | : `` + `` : | | : `` + ``|__________________| |______________________ `` + ``^ ^ ^ ^ `` + ``: : : : `` + ``: : : : `` + ``t=0 ton toff tend`` """ def __init__( diff --git a/bluepyefe/extract.py b/bluepyefe/extract.py index 5ab7299..6b2d859 100644 --- a/bluepyefe/extract.py +++ b/bluepyefe/extract.py @@ -173,11 +173,18 @@ def read_recordings( Args: files_metadata (dict): define for which cell and protocol each file has to be used. Of the form: - { - cell_id: { - protocol_name: [{file_metadata1}, {file_metadata1}] - } - } + + .. code-block:: python + + { + cell_id: { + protocol_name: [ + {file_metadata1}, + {file_metadata1} + ] + } + } + A same file path might be present in the file metadata for different protocols. The entries required in the file_metadata are specific to each @@ -225,17 +232,21 @@ def extract_efeatures_at_targets( targets (dict): define the efeatures to extract as well as which protocols and current amplitude they should be extracted for. Of the form: - [{ - "efeature": "AP_amplitude", - "protocol": "IDRest", - "amplitude": 150., - "tolerance": 10., - "efel_settings": { - 'stim_start': 200., - 'stim_end': 500., - 'Threshold': -10. - } - }] + + .. code-block:: python + + [{ + "efeature": "AP_amplitude", + "protocol": "IDRest", + "amplitude": 150., + "tolerance": 10., + "efel_settings": { + "stim_start": 200., + "stim_end": 500., + "Threshold": -10. + } + }] + map_function (function): Function used to map (parallelize) the feature extraction operations. Note: the parallelization is done across cells an not across efeatures. @@ -373,17 +384,21 @@ def group_efeatures( targets (dict): define the efeatures to extract as well as which protocols and current amplitude they should be extracted for. Of the form: - [{ - "efeature": "AP_amplitude", - "protocol": "IDRest", - "amplitude": 150., - "tolerance": 10., - "efel_settings": { - 'stim_start': 200., - 'stim_end': 500., - 'Threshold': -10. - } - }] + + .. code-block:: python + + [{ + "efeature": "AP_amplitude", + "protocol": "IDRest", + "amplitude": 150., + "tolerance": 10., + "efel_settings": { + "stim_start": 200., + "stim_end": 500., + "Threshold": -10. + } + }] + absolute_amplitude (bool): if True, will use the absolute amplitude instead of the relative amplitudes of the recordings when checking if a recording has to be used for a given target. @@ -624,26 +639,32 @@ def _read_extract_low_memory( def convert_legacy_targets(targets): - """Convert targets of the form: - protocol_name: { + """Convert targets of the form:: + + .. code-block:: python + + protocol_name: { "amplitudes": [50, 100], "tolerances": [10, 10], "efeatures": {"Spikecount": {'Threshold': -10.}}, "location": "soma" } - } - To ones of the form: - [{ - "efeature": "AP_amplitude", - "protocol": "IDRest", - "amplitude": 150., - "tolerance": 10., - "efel_settings": { - 'stim_start': 200., - 'stim_end': 500., - 'Threshold': -10. - } - }] + + To ones of the form:: + + .. code-block:: python + + [{ + "efeature": "AP_amplitude", + "protocol": "IDRest", + "amplitude": 150., + "tolerance": 10., + "efel_settings": { + "stim_start": 200., + "stim_end": 500., + "Threshold": -10. + } + }] """ formatted_targets = [] @@ -852,12 +873,19 @@ def extract_efeatures( output_directory (str): path to the output directory files_metadata (dict): define from files to read the data as well as the name of the cells and protocols to which these data are - related. Of the form: - { - cell_id: { - protocol_name: [{file_metadata1}, {file_metadata1}] - } - } + related. Of the form:: + + .. code-block:: python + + { + cell_id: { + protocol_name: [ + {file_metadata1}, + {file_metadata1} + ] + } + } + The entries required in the file_metadata are specific to each recording_reader (see bluepyemodel/reader.py to know which one are needed for your recording_reader). @@ -869,18 +897,22 @@ def extract_efeatures( rheobase if absolute_amplitude if False or in nA if absolute_amplitude is True) they should be extracted. If targets are not provided, automatic targets will be used. - Of the form: - [{ - "efeature": "AP_amplitude", - "protocol": "IDRest", - "amplitude": 150., - "tolerance": 10., - "efel_settings": { - 'stim_start': 200., - 'stim_end': 500., - 'Threshold': -10. - } - }] + Of the form:: + + .. code-block:: python + + [{ + "efeature": "AP_amplitude", + "protocol": "IDRest", + "amplitude": 150., + "tolerance": 10., + "efel_settings": { + "stim_start": 200., + "stim_end": 500., + "Threshold": -10. + } + }] + threshold_nvalue_save (int): minimum number of values needed for an efeatures to be averaged and returned in the output. protocols_rheobase (list): names of the protocols that will be @@ -905,12 +937,16 @@ def extract_efeatures( efel_settings (dict): eFEL settings in the form {setting_name: setting_value}. If settings are also informed in the targets per efeature, the latter will have priority. If - None, will be set to: - { - 'strict_stiminterval': True, - 'Threshold': -20., - 'interp_step': 0.025 - } + None, will be set to:: + + .. code-block:: python + + { + "strict_stiminterval": True, + "Threshold": -20., + "interp_step": 0.025 + } + extract_per_cell (bool): if True, also generates the features.json and protocol.json for each individual cells. rheobase_strategy (str): function used to compute the rheobase. Can be @@ -1041,11 +1077,18 @@ def plot_recordings( Args: files_metadata (dict): define for which cell and protocol each file has to be used. Of the form: - { - cell_id: { - protocol_name: [{file_metadata1}, {file_metadata1}] - } - } + + .. code-block:: python + + { + cell_id: { + protocol_name: [ + {file_metadata1}, + {file_metadata1} + ] + } + } + A same file path might be present in the file metadata for different protocols. The entries required in the file_metadata are specific to each diff --git a/bluepyefe/reader.py b/bluepyefe/reader.py index 2c34234..e791f3a 100644 --- a/bluepyefe/reader.py +++ b/bluepyefe/reader.py @@ -47,14 +47,18 @@ def _check_metadata(metadata, reader_name, required_entries=[]): def axon_reader(in_data): """Reader to read .abf + Args: in_data (dict): of the format - { - "filepath": "./XXX.abf", - "i_unit": "pA", - "t_unit": "s", - "v_unit": "mV", - } + + .. code-block:: python + + { + "filepath": "./XXX.abf", + "i_unit": "pA", + "t_unit": "s", + "v_unit": "mV" + } """ fp = in_data["filepath"] @@ -91,13 +95,16 @@ def igor_reader(in_data): Args: in_data (dict): of the format - { - 'i_file': './XXX.ibw', - 'v_file': './XXX.ibw', - 'v_unit': 'V', - 't_unit': 's', - 'i_unit': 'A' - } + + .. code-block:: python + + { + 'i_file': './XXX.ibw', + 'v_file': './XXX.ibw', + 'v_unit': 'V', + 't_unit': 's', + 'i_unit': 'A' + } """ _check_metadata( @@ -134,14 +141,17 @@ def read_matlab(in_data): Args: in_data (dict): of the format - { - 'filepath': './161214_AL_113_CC.mat', - 'ton': 2000, - 'toff': 2500, - 'v_unit': 'V', - 't_unit': 's', - 'i_unit': 'A' - } + + .. code-block:: python + + { + 'filepath': './161214_AL_113_CC.mat', + 'ton': 2000, + 'toff': 2500, + 'v_unit': 'V', + 't_unit': 's', + 'i_unit': 'A' + } """ _check_metadata( @@ -170,13 +180,17 @@ def read_matlab(in_data): def nwb_reader(in_data): """Reader for .nwb + Args: in_data (dict): of the format - { - 'filepath': './XXX.nwb', - "protocol_name": "IV", - "repetition": 1 (or [1, 3, ...]) # Optional - } + + .. code-block:: python + + { + 'filepath': './XXX.nwb', + "protocol_name": "IV", + "repetition": 1 (or [1, 3, ...]) # Optional + } """ _check_metadata( @@ -209,21 +223,25 @@ def nwb_reader(in_data): def csv_lccr_reader(in_data): """Reader to read .txt (csv_lccr) + Args: - in_data (dict): of the format - { - 'filepath': "./XXX.txt", - 'dt': 0.1, - 'ton': 2000, - 'toff': 2500, - 'ljp': 14.0, - 'amplitudes': [10 -10 20 -20 30 -30 40 -40 50 -50], - 'hypamp': -20 # (units should match 'amplitudes'), - 'remove_last_100ms': True, - 'v_unit': 'mV', - 't_unit': 'ms', - 'i_unit': 'pA' # current unit for 'amplitudes' and 'hypamp' - } + in_data (dict): of the format: + + .. code-block:: python + + { + 'filepath': "./XXX.txt", + 'dt': 0.1, + 'ton': 2000, + 'toff': 2500, + 'ljp': 14.0, + 'amplitudes': [10 -10 20 -20 30 -30 40 -40 50 -50], + 'hypamp': -20 # (units should match 'amplitudes'), + 'remove_last_100ms': True, + 'v_unit': 'mV', + 't_unit': 'ms', + 'i_unit': 'pA' # current unit for 'amplitudes' and 'hypamp' + } """ _check_metadata( in_data, diff --git a/bluepyefe/recording.py b/bluepyefe/recording.py index e86366d..7affb15 100644 --- a/bluepyefe/recording.py +++ b/bluepyefe/recording.py @@ -169,7 +169,7 @@ def in_target(self, target, tolerance): def standardize_trace(self, config_data, reader_data): """Standardize the units of the current and voltage times series. If some metadata are present both in the file itself and the file_metadata - dictionary, the latter is used.""" + dictionary, the latter is used.""" # Create the time series t = numpy.arange(len(reader_data["voltage"])) diff --git a/bluepyefe/rheobase.py b/bluepyefe/rheobase.py index 5490e47..c508bae 100644 --- a/bluepyefe/rheobase.py +++ b/bluepyefe/rheobase.py @@ -74,11 +74,14 @@ def compute_rheobase_absolute(cell, protocols_rheobase, spike_threshold=1): def compute_rheobase_flush(cell, protocols_rheobase, flush_length=1, upper_bound_spikecount=None): - """ Compute the rheobase by finding the smallest current amplitude that: + """ Compute the rheobase by finding the smallest current amplitude that:: + 1. Triggered at least one spike 2. Is followed by flush_length other traces that also trigger spikes. + The advantage of this strategy is that it ignores traces showing spurious spikes at low amplitudes. + Args: cell (Cell): cell for which to compute the rheobase protocols_rheobase (list): names of the protocols that will be diff --git a/docs/source/conf.py b/docs/source/conf.py index f65f9a4..5e5eef9 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -95,10 +95,18 @@ # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] +# autosummary settings autosummary_generate = True -autodoc_default_flags = ['show-inheritance'] -autoclass_content = 'both' -tolerate_sphinx_warnings = True + +# autodoc settings +autodoc_typehints = "signature" +autodoc_default_options = { + "members": True, + "show-inheritance": True, +} +autoclass_content = "both" + +add_module_names = False # -- Options for HTML output ---------------------------------------------