spycon utilities#
- class spycon.spycon_inference.SpikeConnectivityInference(params: dict = {<class 'str'>: <class 'object'>})#
Bases:
object
Base class for spike connectivity inference. It will infer a fully connected graph.
- Parameters:
params (dict) – Dictionary with necessary parameters as keywords. Keys should be strings.
- infer_connectivity(times: ndarray, ids: ndarray, pairs: ndarray | None = None, parallel: bool = False, **kwargs) SpikeConnectivityResult #
Full connectivity inference.
- Parameters:
times (numpy.ndarray) – Spike times in seconds.
ids (numpy.ndarray) – Unit IDs corresponding to spike times.
pairs (numpy.ndarray) – Array of [pre, post] pair node IDs, for which inference will be done.
parallel (bool) – Whether the parallel version is used, if implemented.
- Returns:
Connectivity result object.
- Return type:
- burst_detection(T, C, N=None, ISI_N=0.1)#
Burst detection algorithm. Credits to Adrian Bertagnoli.
[Citation needed]
- burst_removal(T, C, N=None, ISI_N=0.1)#
- class spycon.spycon_result.SpikeConnectivityResult(method: str, params: dict, nodes: ndarray, all_weights: ndarray, stats: ndarray, threshold: float, runtime: float)#
Bases:
object
Class to store the results of a connectivity inference algorithm.
- Parameters:
method (str) – Name of the method that was used to obtain the result.
params (dict) – Dictionary with the corresponding parameters.
nodes (numpy.ndarray) – An array of node labels with shape [number_of_nodes].
weights (numpy.ndarray) – An array of graded strengths of edges with shape [number_of_edges].
stats (numpy.ndarray) – A 2D array representing a fully connected graph with shape [number_of_edges, 3]. The columns are as follows: - The first column represents outgoing nodes. - The second column represents incoming nodes. - The third column contains the statistic used to decide whether it is an edge or not. A higher value indicates that an edge is more probable.
threshold (float) – Thresholding the stats, where a connection is defined as those where stats > threshold.
runtime (float) – Runtime of the inference algorithm.
- set_threshold(new_threshold: float)#
Set threshold for the stats.
- Parameters:
threshold (float) – Thresholding the stats, where a connection is defined as those where stats > threshold.
- create_nx_graph(graph_type: str = 'binary') DiGraph #
Create a NetworkX graph from the results.
- Parameters:
graph_type (str) – Type of the graph to create: - ‘binary’: Creates an unweighted graph with the inferred connections. - ‘stats’: Creates a fully connected graph, with the decision stats as edge weights. - ‘weighted’: Creates a weighted graph, where weights are the inferred strengths. (Default)
- Returns:
A NetworkX directed graph representing the connectivity.
- Return type:
nx.DiGraph
- draw_graph(graph_type: str = 'binary', ax: Axes | None = None, cax: Axes | None = None)#
Draw a NetworkX graph from the results.
- Parameters:
graph_type (str) – Type of the graph to create: - ‘binary’: Creates an unweighted graph with the inferred connections. (Default) - ‘stats’: Creates a fully connected graph, with the decision stats as edge weights. - ‘weighted’: Creates a weighted graph, where weights are the inferred strengths.
ax (pyplot.Axes, optional) – Matplotlib axis in which the graph should be plotted. Default is None.
cax (pyplot.Axes, optional) – Matplotlib axis in which the colorbar should be plotted. Default is None.
- Returns:
A NetworkX directed graph representing the connectivity.
- Return type:
nx.DiGraph
- create_connectivity_matrix(conn_type: str = 'stats') ndarray #
Create the connectivity matrix from the edges.
- Parameters:
conn_type (str) – Type of the connectivity matrix to create: - ‘binary’: Creates a binary connectivity matrix with the inferred connections. (Default) - ‘stats’: Creates a connectivity matrix, with the decision stats as edge weights. - ‘weighted’: Creates a weighted connectivity matrix, where weights are the inferred strengths.
- Returns:
The connectivity matrix with shape [num_of_nodes, num_of_nodes].
- Return type:
numpy.ndarray
- save(name: str, path: str = '')#
Save the results object.
- Parameters:
name (str) – Name of the result object.
path (str, optional) – Path to the saving location. Default is an empty string (‘’).
- spycon.spycon_result.load_connectivity_result(name: str, path: str = '') SpikeConnectivityResult #
Loads a result object.
- Parameters:
name (str) – Name of the result object.
path (str, optional) – Path to where the result object is saved. Default is an empty string (‘’).
- Returns:
The loaded result object.
- Return type: