diff --git a/doc/conf.py b/doc/conf.py index dc723682f..98758abf5 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -117,7 +117,6 @@ ("Examples", "auto_examples/index"), ("GUI", "gui/index"), ("API", "api"), - ("Network File", "network_file_desc"), ("Glossary", "glossary"), ("What's new", "whats_new"), ("GitHub", "https://github.com/jonescompneurolab/hnn-core", True) diff --git a/doc/network_file_desc.rst b/doc/network_file_desc.rst index 97d14491d..3528c0be7 100644 --- a/doc/network_file_desc.rst +++ b/doc/network_file_desc.rst @@ -8,189 +8,193 @@ Network File Content File Content Description ------------------------ - - object_type : str - Type of object (Network) saved. - N_pyr_x : int - Nr of cells (x). - N_pyr_y : int - Nr of cells (y). - threshold : float - Firing threshold of all cells. - celsius : float - Temperature in degree celsius. - cell_types : dict of Cell Object - key : name of cell type. - value : Cell object. - gid_ranges : dict of dict - key : cell name or drive name. - value : dict. - pos_dict : dict - key : cell type name. - value : All co-ordintes of the cell types. - cell_response : Instance of Cell Response Object - The Cell Response object. - external_drives : dict of dict - key : external drive name. - value : dict. - external_biases : dict of dict - key : external bias name. - value : dict. - connectivity : list of dict - Contains connection info between cells and - cells and external drives. - rec_arrays : dict of Extracellular Arrays - key : extracellular array name. - value : Instance of Extracellular Array object. - delay : float - Synaptic delay in ms. +hdf5 is the file format used for storing the Network object. The network is stored in a layered format. The first layer consists of the network attributes. +The attributes of the network are then broken down until the network can be representated as a collection of key value pairs. For example - cell_types is a network +attribute therefore in the first layer. The description of each cell type is in layer 2. Each cell has various sections. The description of a section is in layer 3. +Below are the attributes of the network. + +object_type : str + Type of object (Network) saved. +N_pyr_x : int + Nr of cells (x). +N_pyr_y : int + Nr of cells (y). +threshold : float + Firing threshold of all cells. +celsius : float + Temperature in degree celsius. +cell_types : dict of Cell Object + key : name of cell type. + value : Cell object. +gid_ranges : dict of dict + key : cell name or drive name. + value : dict. +pos_dict : dict + key : cell type name. + value : All co-ordintes of the cell types. +cell_response : Instance of Cell Response Object + The Cell Response object. +external_drives : dict of dict + key : external drive name. + value : dict. +external_biases : dict of dict + key : external bias name. + value : dict. +connectivity : list of dict + Contains connection info between cells and + cells and external drives. +rec_arrays : dict of Extracellular Arrays + key : extracellular array name. + value : Instance of Extracellular Array object. +delay : float + Synaptic delay in ms. Cell Type Description --------------------- - cell_name : str - Name of the cell. - pos : tuple - The (x, y, z) coordinates. - sections : dict of Section - Dictionary with keys as section name. - synapses : dict of dict - Keys are name of synaptic mechanism. Each synaptic mechanism - has keys for parameters of the mechanism, e.g., 'e', 'tau1', - 'tau2'. - cell_tree : dict of list - Stores the tree representation of a cell. - sect_loc : dict of list - Can have keys 'proximal' or 'distal' each containing - names of section locations that are proximal or distal. - gid : int - GID of the cell in a network (or None if not yet assigned). - dipole_pp : list of h.Dipole() - The Dipole objects (see dipole.mod). - vsec : dict - Recording of section specific voltage. Must be enabled - by running simulate_dipole(net, record_vsec=True) or - simulate_dipole(net, record_vsoma=True). - isec : dict - Contains recording of section specific currents indexed - by synapse type (keys can be soma_gabaa, soma_gabab etc.). - Must be enabled by running simulate_dipole(net, record_isec=True) - or simulate_dipole(net, record_isoma=True). - tonic_biases : list of h.IClamp - The current clamps inserted at each section of the cell - for tonic biasing inputs. +cell_name : str + Name of the cell. +pos : tuple + The (x, y, z) coordinates. +sections : dict of Section + Dictionary with keys as section name. +synapses : dict of dict + Keys are name of synaptic mechanism. Each synaptic mechanism + has keys for parameters of the mechanism, e.g., 'e', 'tau1', + 'tau2'. +cell_tree : dict of list + Stores the tree representation of a cell. +sect_loc : dict of list + Can have keys 'proximal' or 'distal' each containing + names of section locations that are proximal or distal. +gid : int + GID of the cell in a network (or None if not yet assigned). +dipole_pp : list of h.Dipole() + The Dipole objects (see dipole.mod). +vsec : dict + Recording of section specific voltage. Must be enabled + by running simulate_dipole(net, record_vsec=True) or + simulate_dipole(net, record_vsoma=True). +isec : dict + Contains recording of section specific currents indexed + by synapse type (keys can be soma_gabaa, soma_gabab etc.). + Must be enabled by running simulate_dipole(net, record_isec=True) + or simulate_dipole(net, record_isoma=True). +tonic_biases : list of h.IClamp + The current clamps inserted at each section of the cell + for tonic biasing inputs. Section Description ------------------- - L : float - length of a section in microns. - diam : float - diameter of a section in microns. - cm : float - membrane capacitance in micro-Farads. - Ra : float - axial resistivity in ohm-cm. - end_pts : list of [x, y, z] - The start and stop points of the section. - syns : list of str - The synaptic mechanisms to add in this section. - mechs : dict - Mechanisms to insert in this section. The keys - are the names of the mechanisms and values - are the properties. +L : float + length of a section in microns. +diam : float + diameter of a section in microns. +cm : float + membrane capacitance in micro-Farads. +Ra : float + axial resistivity in ohm-cm. +end_pts : list of [x, y, z] + The start and stop points of the section. +syns : list of str + The synaptic mechanisms to add in this section. +mechs : dict + Mechanisms to insert in this section. The keys + are the names of the mechanisms and values + are the properties. Gid Range Description --------------------- - start : int - Start of the gid_range. - stop : int - End of the gid_range. +start : int + Start of the gid_range. +stop : int + End of the gid_range. External Drive Description -------------------------- - name : str - Unique name for the drive. - dynamics : dict - Parameters describing how the temporal dynamics of spike trains in the - drive. The keys are specific to the type of drive ('evoked', 'bursty', - etc.). - location : str - Target location of synapses. - cell_specific : bool - Whether each artifical drive cell has 1-to-1 (True, default) or - all-to-all (False) connection parameters. - weights_ampa : dict or None - Synaptic weights (in uS) of AMPA receptors on each targeted cell - type (dict keys). - weights_nmda : dict or None - Synaptic weights (in uS) of NMDA receptors on each targeted cell - type (dict keys). - probability : dict or float - Probability of connection between any src-target pair. - synaptic_delays : dict or float - Synaptic delay (in ms) at the column origin, dispersed laterally as - a function of the space_constant. If float, applies to all target - cell types. - event_seed : int - Optional initial seed for random number generator. - conn_seed : int - Optional initial seed for random number generator. - n_drive_cells : int | 'n_cells' - The number of drive cells that each contribute an independently - sampled synaptic spike to the network according to the Gaussian - time distribution (mu, sigma). - events : list - Contains the spike times of exogeneous inputs. +name : str + Unique name for the drive. +dynamics : dict + Parameters describing how the temporal dynamics of spike trains in the + drive. The keys are specific to the type of drive ('evoked', 'bursty', + etc.). +location : str + Target location of synapses. +cell_specific : bool + Whether each artifical drive cell has 1-to-1 (True, default) or + all-to-all (False) connection parameters. +weights_ampa : dict or None + Synaptic weights (in uS) of AMPA receptors on each targeted cell + type (dict keys). +weights_nmda : dict or None + Synaptic weights (in uS) of NMDA receptors on each targeted cell + type (dict keys). +probability : dict or float + Probability of connection between any src-target pair. +synaptic_delays : dict or float + Synaptic delay (in ms) at the column origin, dispersed laterally as + a function of the space_constant. If float, applies to all target + cell types. +event_seed : int + Optional initial seed for random number generator. +conn_seed : int + Optional initial seed for random number generator. +n_drive_cells : int | 'n_cells' + The number of drive cells that each contribute an independently + sampled synaptic spike to the network according to the Gaussian + time distribution (mu, sigma). +events : list + Contains the spike times of exogeneous inputs. External Bias Description ------------------------- - cell_type : str - The cell type whose cells will get the tonic input. - amplitude : float - The amplitude of the input. - t0 : float - The start time of tonic input (in ms). - tstop : float - The end time of tonic input (in ms). +cell_type : str + The cell type whose cells will get the tonic input. +amplitude : float + The amplitude of the input. +t0 : float + The start time of tonic input (in ms). +tstop : float + The end time of tonic input (in ms). Connection Description ---------------------- - target_types : str - Cell type of target gids. - target_gids : list of int - Identifer for targets of source cells. - num_targets : int - Number of unique target gids. - src_type : str - Cell type of source gids. - src_gids : list of int - Identifier for source cells. - num_srcs : int - Number of unique source gids. - gid_pairs : dict - dict indexed by src gids. - loc : str - Target location of synapses. - receptor : str - Synaptic receptor of connection. - nc_dict : dict - Contains information about delay, weight, lamtha etc. - allow_autapses : bool - If True, allow connecting neuron to itself. - probability : float - Probability of connection between any src-target pair. +target_types : str + Cell type of target gids. +target_gids : list of int + Identifer for targets of source cells. +num_targets : int + Number of unique target gids. +src_type : str + Cell type of source gids. +src_gids : list of int + Identifier for source cells. +num_srcs : int + Number of unique source gids. +gid_pairs : dict + dict indexed by src gids. +loc : str + Target location of synapses. +receptor : str + Synaptic receptor of connection. +nc_dict : dict + Contains information about delay, weight, lamtha etc. +allow_autapses : bool + If True, allow connecting neuron to itself. +probability : float + Probability of connection between any src-target pair. Extracellular Array Description ------------------------------- - positions : tuple | list of tuple - The (x, y, z) coordinates (in um) of the extracellular electrodes. - conductivity : float - Extracellular conductivity, in S/m. - method : str - Approximation to use. \ No newline at end of file +positions : tuple | list of tuple + The (x, y, z) coordinates (in um) of the extracellular electrodes. +conductivity : float + Extracellular conductivity, in S/m. +method : str + Approximation to use. \ No newline at end of file diff --git a/hnn_core/cell.py b/hnn_core/cell.py index fcce5c6ea..cd1ce35b8 100644 --- a/hnn_core/cell.py +++ b/hnn_core/cell.py @@ -254,6 +254,12 @@ def __eq__(self, other): return True def to_dict(self): + """Converts an object of Section class to a dictionary. + + Returns + ------- + dictionary form of an object of Section class. + """ section_data = dict() section_data['L'] = self.L section_data['diam'] = self.diam @@ -426,6 +432,12 @@ def __eq__(self, other): return True def to_dict(self): + """Converts an object of Cell class to a dictionary. + + Returns + ------- + dictionary form of an object of Cell class. + """ cell_data = dict() cell_data['name'] = self.name cell_data['pos'] = self.pos diff --git a/hnn_core/docs.py b/hnn_core/docs.py index e480680b8..8260f7cf7 100644 --- a/hnn_core/docs.py +++ b/hnn_core/docs.py @@ -26,526 +26,17 @@ """ docdict[ - "save_unsimulated" + "write_output" ] = """ -save_unsimulated : Boolean - True : Do not save the Network simulation output. - False : Save complete Network as provided in input. +write_output : Boolean + True : Save the Network simulation output. + False : Do not save the Network simulation output. """ docdict[ - "read_raw" + "read_output" ] = """ -read_raw : Boolean - True : Read unsimulated network. - False : Read simulated network. -""" - -docdict[ - "L" -] = """ -L : float - length of a section in microns. -""" - -docdict[ - "diam" -] = """ -diam : float - diameter of a section in microns. -""" - -docdict[ - "cm" -] = """ -cm : float - membrane capacitance in micro-Farads. -""" - -docdict[ - "Ra" -] = """ -Ra : float - axial resistivity in ohm-cm. -""" - -docdict[ - "end_pts" -] = """ -end_pts : list of [x, y, z] - The start and stop points of the section. -""" - -docdict[ - "syns" -] = """ -syns : list of str - The synaptic mechanisms to add in this section. -""" - -docdict[ - "mechs" -] = """ -mechs : dict - Mechanisms to insert in this section. The keys - are the names of the mechanisms and values - are the properties. -""" - -docdict[ - "cell_name" -] = """ -cell_name : str - Name of the cell. -""" - -docdict[ - "pos" -] = """ -pos : tuple - The (x, y, z) coordinates. -""" - -docdict[ - "sections" -] = """ -sections : dict of Section - Dictionary with keys as section name. -""" - -docdict[ - "synapses" -] = """ -synapses : dict of dict - Keys are name of synaptic mechanism. Each synaptic mechanism - has keys for parameters of the mechanism, e.g., 'e', 'tau1', - 'tau2'. -""" - -docdict[ - "cell_tree" -] = """ -cell_tree : dict of list - Stores the tree representation of a cell. -""" - -docdict[ - "sect_loc" -] = """ -sect_loc : dict of list - Can have keys 'proximal' or 'distal' each containing - names of section locations that are proximal or distal. -""" - -docdict[ - "gid" -] = """ -gid : int - GID of the cell in a network (or None if not yet assigned). -""" - -docdict[ - "dipole_pp" -] = """ -dipole_pp : list of h.Dipole() - The Dipole objects (see dipole.mod). -""" - -docdict[ - "vsec" -] = """ -vsec : dict - Recording of section specific voltage. Must be enabled - by running simulate_dipole(net, record_vsec=True) or - simulate_dipole(net, record_vsoma=True). -""" - -docdict[ - "isec" -] = """ -isec : dict - Contains recording of section specific currents indexed - by synapse type (keys can be soma_gabaa, soma_gabab etc.). - Must be enabled by running simulate_dipole(net, record_isec=True) - or simulate_dipole(net, record_isoma=True). -""" - -docdict[ - "tonic_biases" -] = """ -tonic_biases : list of h.IClamp - The current clamps inserted at each section of the cell - for tonic biasing inputs. -""" - -docdict[ - "start" -] = """ -start : int - Start of the gid_range. -""" - -docdict[ - "stop" -] = """ -stop : int - End of the gid_range. -""" - -docdict[ - "drive_name" -] = """ -name : str - Unique name for the drive. -""" - -docdict[ - "dynamics" -] = """ -dynamics : dict - Parameters describing how the temporal dynamics of spike trains in the - drive. The keys are specific to the type of drive ('evoked', 'bursty', - etc.). -""" - -docdict[ - "location" -] = """ -location : str - Target location of synapses. -""" - -docdict[ - "cell_specific" -] = """ -cell_specific : bool - Whether each artifical drive cell has 1-to-1 (True, default) or - all-to-all (False) connection parameters. -""" - -docdict[ - "weights_ampa" -] = """ -weights_ampa : dict or None - Synaptic weights (in uS) of AMPA receptors on each targeted cell - type (dict keys). -""" - -docdict[ - "weights_nmda" -] = """ -weights_nmda : dict or None - Synaptic weights (in uS) of NMDA receptors on each targeted cell - type (dict keys). -""" - -docdict[ - "probability" -] = """ -probability : dict or float - Probability of connection between any src-target pair. - Use dict to create probability->cell mapping. If float, applies to - all target cell types. -""" - -docdict[ - "synaptic_delays" -] = """ -synaptic_delays : dict or float - Synaptic delay (in ms) at the column origin, dispersed laterally as - a function of the space_constant. If float, applies to all target - cell types. -""" - -docdict[ - "event_seed" -] = """ -event_seed : int - Optional initial seed for random number generator. -""" - -docdict[ - "conn_seed" -] = """ -conn_seed : int - Optional initial seed for random number generator. -""" - -docdict[ - "n_drive_cells" -] = """ -n_drive_cells : int | 'n_cells' - The number of drive cells that each contribute an independently - sampled synaptic spike to the network according to the Gaussian - time distribution (mu, sigma). -""" - -docdict[ - "events" -] = """ -events : list - Contains the spike times of exogeneous inputs. -""" - -docdict[ - "cell_type" -] = """ -cell_type : str - The cell type whose cells will get the tonic input. -""" - -docdict[ - "amplitude" -] = """ -amplitude : float - The amplitude of the input. -""" - -docdict[ - "t0" -] = """ -t0 : float - The start time of tonic input (in ms). -""" - -docdict[ - "tstop" -] = """ -tstop : float - The end time of tonic input (in ms). -""" - -docdict[ - "target_types" -] = """ -target_types : str - Cell type of target gids. -""" - -docdict[ - "target_gids" -] = """ -target_gids : list of int - Identifer for targets of source cells. -""" - -docdict[ - "num_targets" -] = """ -num_targets : int - Number of unique target gids. -""" - -docdict[ - "src_type" -] = """ -src_type : str - Cell type of source gids. -""" - -docdict[ - "src_gids" -] = """ -src_gids : list of int - Identifier for source cells. -""" - -docdict[ - "num_srcs" -] = """ -num_srcs : int - Number of unique source gids. -""" - -docdict[ - "gid_pairs" -] = """ -gid_pairs : dict - dict indexed by src gids. -""" - -docdict[ - "loc" -] = """ -loc : str - Target location of synapses. -""" - -docdict[ - "receptor" -] = """ -receptor : str - Synaptic receptor of connection. -""" - -docdict[ - "nc_dict" -] = """ -nc_dict : dict - Contains information about delay, weight, lamtha etc. -""" - -docdict[ - "allow_autapses" -] = """ -allow_autapses : bool - If True, allow connecting neuron to itself. -""" - -docdict[ - "connection_probability" -] = """ -probability : float - Probability of connection between any src-target pair. -""" - -docdict[ - "positions" -] = """ -positions : tuple | list of tuple - The (x, y, z) coordinates (in um) of the extracellular electrodes. -""" - -docdict[ - "conductivity" -] = """ -conductivity : float - Extracellular conductivity, in S/m. -""" - -docdict[ - "method" -] = """ -method : str - Approximation to use. -""" - -docdict[ - "min_distance" -] = """ -min_distance : float - To avoid numerical errors in calculating potentials, apply a minimum - distance limit between the electrode contacts and the active neuronal - membrane elements that act as sources of current. -""" - -docdict[ - "times" -] = """ -times : array-like, shape (n_times,) | None - Optionally, provide precomputed voltage sampling times for electrodes - at `positions`. -""" - -docdict[ - "voltages" -] = """ -voltages : array-like, shape (n_trials, n_electrodes, n_times) | None - Optionally, provide precomputed voltages for electrodes at - ``positions``. -""" - -docdict[ - "object_type" -] = """ -object_type : str - Type of object (Network) saved. -""" - -docdict[ - "N_pyr_x" -] = """ -N_pyr_x : int - Nr of cells (x). -""" - -docdict[ - "N_pyr_y" -] = """ -N_pyr_y : int - Nr of cells (y). -""" - -docdict[ - "threshold" -] = """ -threshold : float - Firing threshold of all cells. -""" - -docdict[ - "celsius" -] = """ -celsius : float - Temperature in degree celsius. -""" - -docdict[ - "cell_types" -] = """ -cell_types : dict of Cell Object - key : name of cell type. - value : Cell object. -""" - -docdict[ - "gid_ranges" -] = """ -gid_ranges : dict of dict - key : cell name or drive name. - value : dict. -""" - -docdict[ - "pos_dict" -] = """ -pos_dict : dict - key : cell type name. - value : All co-ordintes of the cell types. -""" - -docdict[ - "cell_response" -] = """ -cell_response : Instance of Cell Response Object - The Cell Response object. -""" - -docdict[ - "external_drives" -] = """ -external_drives : dict of dict - key : external drive name. - value : dict. -""" - -docdict[ - "external_biases" -] = """ -external_biases : dict of dict - key : external bias name. - value : dict. -""" - -docdict[ - "connectivity" -] = """ -connectivity : list of dict - Contains connection info between cells and - cells and external drives. -""" - -docdict[ - "rec_arrays" -] = """ -rec_arrays : dict of Extracellular Arrays - key : extracellular array name. - value : Instance of Extracellular Array object. -""" - -docdict[ - "delay" -] = """ -delay : float - Synaptic delay in ms. +read_output : Boolean + True : Read network with simulation results. + False : Read network without simulation results. """ diff --git a/hnn_core/externals/mne.py b/hnn_core/externals/mne.py index f5f5e5fc9..864278431 100644 --- a/hnn_core/externals/mne.py +++ b/hnn_core/externals/mne.py @@ -867,148 +867,6 @@ def wrapper(func): return wrapper -def copy_function_doc_to_method_doc(source): - """Use the docstring from a function as docstring for a method. - - The docstring of the source function is prepepended to the docstring of the - function wrapped by this decorator. Additionally, the first parameter - specified in the docstring of the source function is removed in the new - docstring. - - This decorator is useful when implementing a method that just calls a - function. This pattern is prevalent in for example the plotting functions - of MNE. - - Parameters - ---------- - source : function - Function to copy the docstring from. - - Returns - ------- - wrapper : function - The decorated method. - - Notes - ----- - The parsing performed is very basic and will break easily on docstrings - that are not formatted exactly according to the ``numpydoc`` standard. - Always inspect the resulting docstring when using this decorator. - - Examples - -------- - >>> def plot_function(object, a, b): - ... '''Docstring for plotting function. - ... - ... Parameters - ... ---------- - ... object : instance of object - ... The object to plot - ... a : int - ... Some parameter - ... b : int - ... Some parameter - ... ''' - ... pass - ... - >>> class A: - ... @copy_function_doc_to_method_doc(plot_function) - ... def plot(self, a, b): - ... ''' - ... Notes - ... ----- - ... .. versionadded:: 0.13.0 - ... ''' - ... plot_function(self, a, b) - >>> print(A.plot.__doc__) - Docstring for plotting function. - - Parameters - ---------- - a : int - Some parameter - b : int - Some parameter - - Notes - ----- - .. versionadded:: 0.13.0 - - """ - - def wrapper(func): - doc = source.__doc__.split("\n") - if len(doc) == 1: - doc = doc[0] - if func.__doc__ is not None: - doc += func.__doc__ - func.__doc__ = doc - return func - - # Find parameter block - for line, text in enumerate(doc[:-2]): - if (text.strip() == "Parameters" and - doc[line + 1].strip() == "----------"): - parameter_block = line - break - else: - # No parameter block found - raise ValueError( - "Cannot copy function docstring: no parameter " - "block found. To simply copy the docstring, use " - "the @copy_doc decorator instead." - ) - - # Find first parameter - for line, text in enumerate(doc[parameter_block:], parameter_block): - if ":" in text: - first_parameter = line - parameter_indentation = len(text) - len(text.lstrip(" ")) - break - else: - raise ValueError( - "Cannot copy function docstring: no parameters " - "found. To simply copy the docstring, use the " - "@copy_doc decorator instead." - ) - - # Find end of first parameter - for line, text in enumerate(doc[first_parameter + 1:], - first_parameter + 1): - # Ignore empty lines - if len(text.strip()) == 0: - continue - - line_indentation = len(text) - len(text.lstrip(" ")) - if line_indentation <= parameter_indentation: - # Reach end of first parameter - first_parameter_end = line - - # Of only one parameter is defined, remove the Parameters - # heading as well - if ":" not in text: - first_parameter = parameter_block - - break - else: - # End of docstring reached - first_parameter_end = line - first_parameter = parameter_block - - # Copy the docstring, but remove the first parameter - doc = ( - "\n".join(doc[:first_parameter]) + - "\n" + - "\n".join(doc[first_parameter_end:]) - ) - if func.__doc__ is not None: - doc += func.__doc__ - func.__doc__ = doc - return func - - return wrapper - - def _indentcount_lines(lines): """Compute minimum indent for all lines in line list.""" indentno = sys.maxsize diff --git a/hnn_core/extracellular.py b/hnn_core/extracellular.py index 735ff8b3b..fc3fc9db1 100644 --- a/hnn_core/extracellular.py +++ b/hnn_core/extracellular.py @@ -538,6 +538,13 @@ def plot_csd(self, colorbar=True, ax=None, show=True): return fig def to_dict(self): + """Converts an object of ExtracellularArray class to a + dictionary. + + Returns + ------- + dictionary form of an object of ExtracellularArray class. + """ rec_array_data = dict() rec_array_data['positions'] = self.positions rec_array_data['conductivity'] = self.conductivity diff --git a/hnn_core/io.py b/hnn_core/io.py index 27c30b80d..bfac58745 100644 --- a/hnn_core/io.py +++ b/hnn_core/io.py @@ -12,7 +12,7 @@ from .externals.mne import fill_doc -def str_to_node(node_string): +def _str_to_node(node_string): node_tuple = node_string.split(',') node_tuple[1] = int(node_tuple[1]) node = (node_tuple[0], node_tuple[1]) @@ -20,7 +20,7 @@ def str_to_node(node_string): @fill_doc -def write_network(net, fname, overwrite=True, save_unsimulated=False): +def write_network(net, fname, overwrite=True, write_output=True): """Write network to a file. Parameters @@ -28,7 +28,7 @@ def write_network(net, fname, overwrite=True, save_unsimulated=False): %(net)s %(fname)s %(overwrite)s - %(save_unsimulated)s + %(write_output)s Yields ------ @@ -59,7 +59,7 @@ def write_network(net, fname, overwrite=True, save_unsimulated=False): pos_dict_data[key] = net.pos_dict[key] net_data['pos_dict'] = pos_dict_data # Write cell_response - if (not net.cell_response) or save_unsimulated: + if (not net.cell_response) or (not write_output): net_data['cell_response'] = None else: net_data['cell_response'] = net.cell_response.to_dict() @@ -68,7 +68,7 @@ def write_network(net, fname, overwrite=True, save_unsimulated=False): for key in net.external_drives.keys(): external_drives_data[key] = (_external_drive_to_dict (net.external_drives[key], - save_unsimulated)) + write_output)) net_data['external_drives'] = external_drives_data # Write External biases net_data['external_biases'] = net.external_biases @@ -78,7 +78,7 @@ def write_network(net, fname, overwrite=True, save_unsimulated=False): net_data['rec_arrays'] = dict() for key in net.rec_arrays.keys(): rec_array_copy = net.rec_arrays[key].copy() - if save_unsimulated: + if not write_output: rec_array_copy._reset() net_data['rec_arrays'][key] = rec_array_copy.to_dict() # Write threshold @@ -91,13 +91,13 @@ def write_network(net, fname, overwrite=True, save_unsimulated=False): @fill_doc -def read_network(fname, read_raw=False): +def read_network(fname, read_output=True, read_drives=True): """Read network from a file. Parameters ---------- %(fname)s - %(read_raw)s + %(read_output)s Yields ------ @@ -138,16 +138,17 @@ def read_network(fname, read_raw=False): net.pos_dict = net_data['pos_dict'] # Set cell_response net.cell_response = _read_cell_response(net_data['cell_response'], - read_raw) + read_output) # Set external drives for key in net_data['external_drives'].keys(): - _read_external_drive(net, net_data['external_drives'][key], read_raw) + _read_external_drive(net, net_data['external_drives'][key], + read_output, read_drives) # Set external biases net.external_biases = net_data['external_biases'] # Set connectivity _read_connectivity(net, net_data['connectivity']) # Set rec_arrays - _read_rec_arrays(net, net_data['rec_arrays'], read_raw) + _read_rec_arrays(net, net_data['rec_arrays'], read_output) # Set threshold net.threshold = net_data['threshold'] # Set delay @@ -178,7 +179,7 @@ def _write_connectivity(connectivity): return conns_data -def _external_drive_to_dict(drive, save_unsimulated): +def _external_drive_to_dict(drive, write_output): drive_data = dict() for key in drive.keys(): # Cannot store sets with hdf5 @@ -186,7 +187,7 @@ def _external_drive_to_dict(drive, save_unsimulated): drive_data[key] = list(drive[key]) else: drive_data[key] = drive[key] - if save_unsimulated: + if not write_output: drive_data['events'] = list() return drive_data @@ -212,10 +213,10 @@ def _read_cell_types(cell_types_data): if cell_data['cell_tree'] is not None: cell_tree = dict() for parent, children in cell_data['cell_tree'].items(): - key = str_to_node(parent) + key = _str_to_node(parent) value = list() for child in children: - value.append(str_to_node(child)) + value.append(_str_to_node(child)) cell_tree[key] = value cell_types[cell_name] = Cell(name=cell_data['name'], @@ -234,8 +235,8 @@ def _read_cell_types(cell_types_data): return cell_types -def _read_cell_response(cell_response_data, read_raw): - if (not cell_response_data) or read_raw: +def _read_cell_response(cell_response_data, read_output): + if (not cell_response_data) or (not read_output): return None cell_response = CellResponse(spike_times=cell_response_data['spike_times'], spike_gids=cell_response_data['spike_gids'], @@ -253,7 +254,9 @@ def _read_cell_response(cell_response_data, read_raw): return cell_response -def _read_external_drive(net, drive_data, read_raw): +def _read_external_drive(net, drive_data, read_output, read_drives): + if not read_drives: + return None if drive_data['type'] == 'evoked': # Skipped n_drive_cells here net.add_evoked_drive(name=drive_data['name'], @@ -303,7 +306,7 @@ def _read_external_drive(net, drive_data, read_raw): conn_seed=drive_data['conn_seed']) net.external_drives[drive_data['name']]['events'] = drive_data['events'] - if read_raw: + if not read_output: net.external_drives[drive_data['name']]['events'] = list() @@ -324,7 +327,7 @@ def _read_connectivity(net, conns_data): probability=conn_data['probability']) -def _read_rec_arrays(net, rec_arrays_data, read_raw): +def _read_rec_arrays(net, rec_arrays_data, read_output): for key in rec_arrays_data: rec_array = rec_arrays_data[key] net.add_electrode_array(name=key, @@ -334,5 +337,5 @@ def _read_rec_arrays(net, rec_arrays_data, read_raw): min_distance=rec_array['min_distance']) net.rec_arrays[key]._times = rec_array['times'] net.rec_arrays[key]._data = rec_array['voltages'] - if read_raw: + if not read_output: net.rec_arrays[key]._reset() diff --git a/hnn_core/network.py b/hnn_core/network.py index 4ff013a91..bc89f5746 100644 --- a/hnn_core/network.py +++ b/hnn_core/network.py @@ -1387,8 +1387,8 @@ def plot_cells(self, ax=None, show=True): return plot_cells(net=self, ax=ax, show=show) @copy_doc(write_network) - def write(self, fname, overwrite=True, save_unsimulated=False): - write_network(self, fname, overwrite, save_unsimulated) + def write(self, fname, overwrite=True, write_output=True): + write_network(self, fname, overwrite, write_output) class _Connectivity(dict): diff --git a/hnn_core/tests/test_cell.py b/hnn_core/tests/test_cell.py index e9a234cf1..c2ca9fb96 100644 --- a/hnn_core/tests/test_cell.py +++ b/hnn_core/tests/test_cell.py @@ -108,6 +108,13 @@ def test_cell(): # Testing update end pts using template cell cell1 = pyramidal(cell_name='L5Pyr') + + # Test other not NotImplemented for Cell Class + assert (cell1 == "cell") is False + + # Test other not NotImplemented for Section Class + assert (cell1.sections['soma'] == "section") is False + end_pts_original = list() end_pts_new = list() for sec_name in cell1.sections.keys(): diff --git a/hnn_core/tests/test_extracellular.py b/hnn_core/tests/test_extracellular.py index 708001776..7b61fa532 100644 --- a/hnn_core/tests/test_extracellular.py +++ b/hnn_core/tests/test_extracellular.py @@ -33,6 +33,9 @@ def test_extracellular_api(): assert len(net.rec_arrays) == 2 assert len(net.rec_arrays['arr1'].positions) == 2 + # Test other not NotImplemented for ExtracellularArray Class + assert (net.rec_arrays['arr1'] == "extArr") is False + # ensure unique names pytest.raises(ValueError, net.add_electrode_array, 'arr1', [(6, 6, 800)]) # all remaining input arguments checked by ExtracellularArray diff --git a/hnn_core/tests/test_io.py b/hnn_core/tests/test_io.py index c31390974..c475b4d6a 100644 --- a/hnn_core/tests/test_io.py +++ b/hnn_core/tests/test_io.py @@ -36,6 +36,9 @@ def test_network_io(tmp_path, network_model): net_copy = net.copy() assert net_copy == net + # Test other not NotImplemented for Network Class + assert (net == "net") is False + # Adding electrode arrays electrode_pos = (1, 2, 3) net.add_electrode_array('el1', electrode_pos) @@ -70,8 +73,8 @@ def test_network_io(tmp_path, network_model): # Smoke test net_sim.plot_cells(show=False) - # Checking Saving unsimulated network - net.write(tmp_path / 'net_unsim.hdf5', save_unsimulated=True) + # Checking Saving network without simulation results. + net.write(tmp_path / 'net_unsim.hdf5', write_output=False) net_unsim_read = read_network(tmp_path / 'net_unsim.hdf5') net_unsim = net.copy() net_unsim.cell_response = None @@ -91,7 +94,7 @@ def test_network_io(tmp_path, network_model): # Checking reading of raw network net_raw = read_network(tmp_path / 'net_sim.hdf5', - read_raw=True) + read_output=False) assert net_raw == net_unsim # Checking simulation correctness of read raw network dpls4 = simulate_dipole(net_raw, tstop=2, n_trials=1, dt=0.5) @@ -119,4 +122,9 @@ def test_network_io(tmp_path, network_model): match="The object should be of type Network."): read_network(tmp_path / 'not_net.hdf5') + # Checking read_drives=False + net_no_drives = read_network(tmp_path / 'net.hdf5', read_output=False, + read_drives=False) + assert len(net_no_drives.external_drives) == 0 + # Add test to check weights are equal in connections and drives (todo)