@@ -142,7 +142,44 @@ def _plot_helper(plot_fnc, config_file=None, population=None, times=None, title=
142142def 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
154191def 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
165242def 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
211339def 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