Skip to content

Commit 4da6424

Browse files
committed
fixing issues with autodocs
1 parent 84f5bc0 commit 4da6424

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1863
-2672
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ language: python
33
matrix:
44
include:
55
- python: 3.6
6+
- python: 3.7
67

78
before_install:
89
- sudo apt-get update

bmtk/analyzer/cell_vars.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def _get_cell_report(config_file, report_name):
3838

3939

4040
def load_reports(config_file):
41+
""""""
4142
cfg = ConfigDict.from_json(config_file)
4243
reports = []
4344
for report_name, report in cfg.reports.items():

bmtk/analyzer/compartment.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,62 @@ def _find_nodes(population, config=None, nodes_file=None, node_types_file=None):
6262
raise ValueError('Could not find nodes file with node population "{}".'.format(population))
6363

6464

65-
def plot_traces(report_path=None, config_file=None, report_name=None, population=None, group_by=None,
65+
def plot_traces(config_file=None, report_name=None, population=None, report_path=None, group_by=None,
6666
group_excludes=None, nodes_file=None, node_types_file=None,
6767
node_ids=None, sections='origin', average=False, times=None, title=None,
6868
show_legend=None, show=True):
69+
"""Plot compartment variables (eg Membrane Voltage, Calcium conc.) traces from the output of simulation. Will
70+
attempt to look in the SONATA simulation configuration json "reports" sections for any matching "membrane_report"
71+
outputs with a matching report_name::
72+
73+
plot_traces(config_file='config.json', report_name='membrane_potential')
74+
75+
If the path the the report is different (or missing) than what's in the SONATA config then use the "report_path"
76+
option instead::
77+
78+
plot_traces(report_path='/my/path/to/membrane_potential.h5')
79+
80+
To display the traces of only a select number of nodes you can filter using the node_ids options::
81+
82+
plot_traces(config_file='config.json', node_ids=[10, 20, 30, 40, 50])
83+
84+
The average option will find the mean value of all the traces to display::
85+
86+
plot_traces(config_file='config.json', node_ids=range(50, 100), average=True)
87+
88+
You may also group together different subsets of nodes and display multiple averages based on certain attributes
89+
of the network, which can be done using the group_by key. The group_exlcudes option will exclude certain groups.
90+
For example if you want to plot the averaged membrane potential across each cortical "layer", exclude L1::
91+
92+
plot_traces(config_file='config.json', report='membrane_potential', group_by='layer', group_excludes='L1')
93+
94+
:param config_file: path to SONATA simulation configuration.
95+
:param report_name: name of the membrane_report "report" which will be plotted. If only one compartment report
96+
in the simulation config then function will find it automatically.
97+
:param population: string. If the report more than one population of nodes, use this to determine which nodes to
98+
plot. If only one population exists and population=None then the function will find it by default.
99+
:param report_path: Path to SONATA compartment report file. Do not use with "config_file" and "report_name" options.
100+
:param group_by: Attribute of the "nodes" file used to group and average subsets of nodes.
101+
:param group_excludes: list of strings or None. When using the "group_by", allows users to exclude certain groupings
102+
based on the attribute value.
103+
:param nodes_file: path to nodes hdf5 file containing "population". By default this will be resolved using the
104+
config.
105+
:param node_types_file: path to node-types csv file containing "population". By default this will be resolved using
106+
the config.
107+
:param node_ids: int or list of integers. Individual node to display the variable.
108+
:param sections: 'origin', 'all', or list of ids, Compartments/elements to display, By default will only show values
109+
at the soma.
110+
:param average: If true will display average of "node_ids". Default: False
111+
:param times: (float, float), start and stop times of simulation. By default will get values from simulation
112+
configs "run" section.
113+
:param title: str, adds a title to the plot. If None (default) then name will be automatically generated using the
114+
report_name.
115+
:param show_legend: Set True or False to determine if legend should be displayed on the plot. The default (None)
116+
function itself will guess if legend should be shown.
117+
:param show: bool to display or not display plot. default True.
118+
:return: matplotlib figure.Figure object
119+
"""
120+
69121
sonata_config = SonataConfig.from_json(config_file) if config_file else None
70122
report_name, cr = _get_report(report_path=report_path, config=sonata_config, report_name=report_name)
71123

bmtk/analyzer/spike_trains.py

Lines changed: 143 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,44 @@ def _plot_helper(plot_fnc, config_file=None, population=None, times=None, title=
142142
def plot_raster(config_file=None, population=None, with_histogram=True, times=None, title=None, show=True,
143143
group_by=None, group_excludes=None,
144144
spikes_file=None, nodes_file=None, node_types_file=None):
145-
145+
"""Create a raster plot (plus optional histogram) from the results of the simulation.
146+
147+
Will using the SONATA simulation configs "output" section to locate where the spike-trains file was created and
148+
display them::
149+
150+
plot_raster(config_file='config.json')
151+
152+
If the path the the report is different (or missing) than what's in the SONATA config then use the "spikes_file"
153+
option instead::
154+
155+
plot_raster(spikes_file='/my/path/to/membrane_potential.h5')
156+
157+
You may also group together different subsets of nodes using specific attributes of the network using the "group_by"
158+
option, and the "group_excludes" option to exclude specific subsets. For example to color and label different
159+
subsets of nodes based on their cortical "layer", but exlcude plotting the L1 nodes::
160+
161+
plot_raster(config_file='config.json', groupy_by='layer', group_excludes='L1')
162+
163+
:param config_file: path to SONATA simulation configuration.
164+
:param population: name of the membrane_report "report" which will be plotted. If only one compartment report
165+
in the simulation config then function will find it automatically.
166+
:param with_histogram: If True the a histogram will be shown as a small subplot below the scatter plot. Default
167+
True.
168+
:param times: (float, float), start and stop times of simulation. By default will get values from simulation
169+
configs "run" section.
170+
:param title: str, adds a title to the plot. If None (default) then name will be automatically generated using the
171+
report_name.
172+
:param show: bool to display or not display plot. default True.
173+
:param group_by: Attribute of the "nodes" file used to group and average subsets of nodes.
174+
:param group_excludes: list of strings or None. When using the "group_by", allows users to exclude certain groupings
175+
based on the attribute value.
176+
:param spikes_file: Path to SONATA spikes file. Do not use with "config_file" options.
177+
:param nodes_file: path to nodes hdf5 file containing "population". By default this will be resolved using the
178+
config.
179+
:param node_types_file: path to node-types csv file containing "population". By default this will be resolved using
180+
the config.
181+
:return: matplotlib figure.Figure object
182+
"""
146183
plot_fnc = partial(plotting.plot_raster, with_histogram=with_histogram)
147184
return _plot_helper(plot_fnc,
148185
config_file=config_file, population=population, times=times, title=title, show=show,
@@ -153,7 +190,47 @@ def plot_raster(config_file=None, population=None, with_histogram=True, times=No
153190

154191
def plot_rates(config_file=None, population=None, smoothing=False, smoothing_params=None, times=None, title=None,
155192
show=True, group_by=None, group_excludes=None, spikes_file=None, nodes_file=None, node_types_file=None):
156-
193+
"""Calculate and plot the rates of each node recorded during the simulation - averaged across the entirety of the
194+
simulation.
195+
196+
Will using the SONATA simulation configs "output" section to locate where the spike-trains file was created and
197+
display them::
198+
199+
plot_rates(config_file='config.json')
200+
201+
If the path the the report is different (or missing) than what's in the SONATA config then use the "spikes_file"
202+
option instead::
203+
204+
plot_rates(spikes_file='/my/path/to/membrane_potential.h5')
205+
206+
You may also group together different subsets of nodes using specific attributes of the network using the "group_by"
207+
option, and the "group_excludes" option to exclude specific subsets. For example to color and label different
208+
subsets of nodes based on their cortical "layer", but exlcude plotting the L1 nodes::
209+
210+
plot_rates(config_file='config.json', groupy_by='layer', group_excludes='L1')
211+
212+
213+
:param config_file: path to SONATA simulation configuration.
214+
:param population: name of the membrane_report "report" which will be plotted. If only one compartment report
215+
in the simulation config then function will find it automatically.
216+
:param smoothing: Bool or function. Used to smooth the data. By default (False) no smoothing will be done. If True
217+
will using a moving average smoothing function. Or use a function pointer.
218+
:param smoothing_params: dict, parameters when using a function pointer smoothing value.
219+
:param times: (float, float), start and stop times of simulation. By default will get values from simulation
220+
configs "run" section.
221+
:param title: str, adds a title to the plot. If None (default) then name will be automatically generated using the
222+
report_name.
223+
:param show: bool to display or not display plot. default True.
224+
:param group_by: Attribute of the "nodes" file used to group and average subsets of nodes.
225+
:param group_excludes: list of strings or None. When using the "group_by", allows users to exclude certain groupings
226+
based on the attribute value.
227+
:param spikes_file: Path to SONATA spikes file. Do not use with "config_file" options.
228+
:param nodes_file: Path to nodes hdf5 file containing "population". By default this will be resolved using the
229+
config.
230+
:param node_types_file: Path to node-types csv file containing "population". By default this will be resolved using
231+
the config.
232+
:return: matplotlib figure.Figure object
233+
"""
157234
plot_fnc = partial(plotting.plot_rates, smoothing=smoothing, smoothing_params=smoothing_params)
158235
return _plot_helper(plot_fnc,
159236
config_file=config_file, population=population, times=times, title=title, show=show,
@@ -165,7 +242,42 @@ def plot_rates(config_file=None, population=None, smoothing=False, smoothing_par
165242
def plot_rates_boxplot(config_file=None, population=None, times=None, title=None, show=True,
166243
group_by=None, group_excludes=None,
167244
spikes_file=None, nodes_file=None, node_types_file=None):
168-
245+
"""Creates a box plot of the firing rates taken from nodes recorded during the simulation.
246+
247+
Will using the SONATA simulation configs "output" section to locate where the spike-trains file was created and
248+
display them::
249+
250+
plot_rates_boxplot(config_file='config.json')
251+
252+
If the path the the report is different (or missing) than what's in the SONATA config then use the "spikes_file"
253+
option instead::
254+
255+
plot_rates_boxplot(spikes_file='/my/path/to/membrane_potential.h5')
256+
257+
You may also group together different subsets of nodes using specific attributes of the network using the "group_by"
258+
option, and the "group_excludes" option to exclude specific subsets. For example to color and label different
259+
subsets of nodes based on their cortical "layer", but exlcude plotting the L1 nodes::
260+
261+
plot_rates_boxplot(config_file='config.json', groupy_by='layer', group_excludes='L1')
262+
263+
:param config_file: path to SONATA simulation configuration.
264+
:param population: name of the membrane_report "report" which will be plotted. If only one compartment report
265+
in the simulation config then function will find it automatically.
266+
:param times: (float, float), start and stop times of simulation. By default will get values from simulation
267+
configs "run" section.
268+
:param title: str, adds a title to the plot. If None (default) then name will be automatically generated using the
269+
report_name.
270+
:param show: bool to display or not display plot. default True.
271+
:param group_by: Attribute of the "nodes" file used to group and average subsets of nodes.
272+
:param group_excludes: list of strings or None. When using the "group_by", allows users to exclude certain groupings
273+
based on the attribute value.
274+
:param spikes_file: Path to SONATA spikes file. Do not use with "config_file" options.
275+
:param nodes_file: Path to nodes hdf5 file containing "population". By default this will be resolved using the
276+
config.
277+
:param node_types_file: Path to node-types csv file containing "population". By default this will be resolved using
278+
the config.
279+
:return: matplotlib figure.Figure object
280+
"""
169281
plot_fnc = partial(plotting.plot_rates_boxplot)
170282
return _plot_helper(plot_fnc,
171283
config_file=config_file, population=population, times=times, title=title, show=show,
@@ -174,8 +286,24 @@ def plot_rates_boxplot(config_file=None, population=None, times=None, title=None
174286
)
175287

176288

177-
def spike_statistics(spikes_file, simulation=None, simulation_time=None, groupby=None, network=None, **filterparams):
178-
spike_trains = SpikeTrains.load(spikes_file)
289+
def spike_statistics(spikes_file, simulation=None, population=None, simulation_time=None, group_by=None, network=None,
290+
config_file=None, **filterparams):
291+
"""Get spike statistics (firing_rate, counts, inter-spike interval) of the nodes.
292+
293+
:param spikes_file: Path to SONATA spikes file. Do not use with "config_file" options.
294+
:param simulation:
295+
:param population:
296+
:param simulation_time:
297+
:param groupby:
298+
:param network:
299+
:param config_file:
300+
:param filterparams:
301+
:return: pandas dataframe
302+
"""
303+
304+
# TODO: Should be implemented in bmtk.utils.spike_trains.stats.py
305+
pop, spike_trains = _find_spikes(config_file=config_file, spikes_file=spikes_file, population=population)
306+
# spike_trains = SpikeTrains.load(spikes_file)
179307

180308
def calc_stats(r):
181309
d = {}
@@ -202,13 +330,22 @@ def calc_stats(r):
202330
vals_df = pd.merge(nodes_df, spike_counts_df, left_index=True, right_index=True, how='left')
203331
vals_df = vals_df.fillna({'count': 0.0, 'firing_rate': 0.0, 'isi': 0.0})
204332

205-
vals_df = vals_df.groupby(groupby)[['firing_rate', 'count', 'isi']].agg([np.mean, np.std])
333+
vals_df = vals_df.groupby(group_by)[['firing_rate', 'count', 'isi']].agg([np.mean, np.std])
206334
return vals_df
207335
else:
208336
return spike_counts_df
209337

210338

211339
def to_dataframe(config_file, spikes_file=None, population=None):
340+
"""
341+
342+
:param config_file:
343+
:param spikes_file:
344+
:param population:
345+
:return:
346+
"""
347+
348+
212349
# _, spike_trains = _find_spikes(config_file=config_file, spikes_file=spikes_file, population=population)
213350
pop, spike_trains = _find_spikes(config_file=config_file, spikes_file=spikes_file, population=population)
214351

0 commit comments

Comments
 (0)