From 63649ef80189a50c4ec4199c3100e0fdf99e4870 Mon Sep 17 00:00:00 2001 From: Aritra Sinha Date: Sat, 4 Mar 2023 20:39:23 +0530 Subject: [PATCH 1/6] ENH: Add time range to different plots --- hnn_core/viz.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/hnn_core/viz.py b/hnn_core/viz.py index 16e3e8c54..9f1f86b65 100644 --- a/hnn_core/viz.py +++ b/hnn_core/viz.py @@ -484,7 +484,8 @@ def plot_spikes_hist(cell_response, trial_idx=None, ax=None, spike_types=None, return ax.get_figure() -def plot_spikes_raster(cell_response, trial_idx=None, ax=None, show=True): +def plot_spikes_raster(cell_response, trial_idx=None, tmin=None, tmax=None, + ax=None, show=True): """Plot the aggregate spiking activity according to cell type. Parameters @@ -493,6 +494,10 @@ def plot_spikes_raster(cell_response, trial_idx=None, ax=None, show=True): The CellResponse object from net.cell_response trial_idx : int | list of int | None Index of trials to be plotted. If None, all trials plotted + tmin : float or None + Start time of plot in milliseconds. If None, plot entire simulation. + tmax : float or None + End time of plot in milliseconds. If None, plot entire simulation. ax : instance of matplotlib axis | None An axis object from matplotlib. If None, a new figure is created. show : bool @@ -540,6 +545,7 @@ def plot_spikes_raster(cell_response, trial_idx=None, ax=None, show=True): cell_type_times, cell_type_ypos = [], [] for gid in cell_type_gids: gid_time = spike_times[spike_gids == gid] + _, gid_time = _get_plot_data_trange(gid_time, gid_time, tmin, tmax) cell_type_times.append(gid_time) cell_type_ypos.append(ypos) ypos = ypos - 1 @@ -1185,8 +1191,8 @@ def _onclick(event): return ax.get_figure() -def plot_laminar_csd(times, data, contact_labels, ax=None, colorbar=True, - show=True): +def plot_laminar_csd(times, data, contact_labels, tmin=None, tmax=None, + ax=None, colorbar=True, show=True): """Plot laminar current source density (CSD) estimation from LFP array. Parameters @@ -1195,6 +1201,9 @@ def plot_laminar_csd(times, data, contact_labels, ax=None, colorbar=True, Sampling times (in ms). data : array-like, shape (n_channels, n_times) CSD data, channels x time. + tmin : float | None + Start time of plot in milliseconds. If None, plot entire simulation. + tmax : float | None ax : instance of matplotlib figure | None The matplotlib axis. colorbar : bool @@ -1213,7 +1222,9 @@ def plot_laminar_csd(times, data, contact_labels, ax=None, colorbar=True, import matplotlib.pyplot as plt if ax is None: _, ax = plt.subplots(1, 1, constrained_layout=True) - + times, data = _get_plot_data_trange(times, data, tmin, tmax) + _, contact_labels = _get_plot_data_trange( + times, contact_labels, tmin, tmax) im = ax.pcolormesh(times, contact_labels, np.array(data), cmap="jet_r", shading='auto') ax.set_title("CSD") From c81fe2f3f64da302e3237deb3764da0c8ec961f2 Mon Sep 17 00:00:00 2001 From: Tianqi Cheng Date: Wed, 25 Oct 2023 14:15:39 -0400 Subject: [PATCH 2/6] set_tstop_oct25 --- hnn_core/dipole.py | 11 +++-------- hnn_core/extracellular.py | 14 +++++--------- hnn_core/viz.py | 37 ++++++++++++++++--------------------- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/hnn_core/dipole.py b/hnn_core/dipole.py index 2ae172c5e..c140358b1 100644 --- a/hnn_core/dipole.py +++ b/hnn_core/dipole.py @@ -468,16 +468,11 @@ def savgol_filter(self, h_freq): self.sfreq) return self - def plot(self, tmin=None, tmax=None, layer='agg', decim=None, ax=None, - color='k', show=True): + def plot(self, layer='agg', decim=None, ax=None, color='k', show=True): """Simple layer-specific plot function. Parameters ---------- - tmin : float or None - Start time of plot (in ms). If None, plot entire simulation. - tmax : float or None - End time of plot (in ms). If None, plot entire simulation. layer : str The layer to plot. Can be one of 'agg', 'L2', and 'L5' decimate : int @@ -494,8 +489,8 @@ def plot(self, tmin=None, tmax=None, layer='agg', decim=None, ax=None, fig : instance of plt.fig The matplotlib figure handle. """ - return plot_dipole(self, tmin=tmin, tmax=tmax, ax=ax, layer=layer, - decim=decim, color=color, show=show) + return plot_dipole(self, ax=ax, layer=layer, decim=decim, color=color, + show=show) def plot_psd(self, fmin=0, fmax=None, tmin=None, tmax=None, layer='agg', color=None, label=None, ax=None, show=True): diff --git a/hnn_core/extracellular.py b/hnn_core/extracellular.py index 1515865b5..db8015ed7 100644 --- a/hnn_core/extracellular.py +++ b/hnn_core/extracellular.py @@ -443,9 +443,9 @@ def smooth(self, window_len): return self - def plot_lfp(self, *, trial_no=None, contact_no=None, tmin=None, tmax=None, - ax=None, decim=None, color='cividis', voltage_offset=50, - voltage_scalebar=200, show=True): + def plot_lfp(self, *, trial_no=None, contact_no=None, ax=None, decim=None, + color='cividis', voltage_offset=50, voltage_scalebar=200, + show=True): """Plot laminar local field potential time series. One plot is created for each trial. Multiple trials can be overlaid @@ -457,11 +457,6 @@ def plot_lfp(self, *, trial_no=None, contact_no=None, tmin=None, tmax=None, Trial number(s) to plot contact_no : int | list of int | slice Electrode contact number(s) to plot - tmin : float | None - Start time of plot in milliseconds. If None, plot entire - simulation. - tmax : float | None - End time of plot in milliseconds. If None, plot entire simulation. ax : instance of matplotlib figure | None The matplotlib axis decim : int | list of int | None (default) @@ -508,7 +503,7 @@ def plot_lfp(self, *, trial_no=None, contact_no=None, tmin=None, tmax=None, for trial_data in plot_data: fig = plot_laminar_lfp( - self.times, trial_data, tmin=tmin, tmax=tmax, ax=ax, + self.times, trial_data, ax=ax, decim=decim, color=color, voltage_offset=voltage_offset, voltage_scalebar=voltage_scalebar, @@ -574,6 +569,7 @@ class _ExtracellularArrayBuilder(object): The instance of :class:`hnn_core.extracellular.ExtracellularArray` to build in NEURON-Python """ + def __init__(self, array): self.array = array self.n_contacts = array.n_contacts diff --git a/hnn_core/viz.py b/hnn_core/viz.py index 9f1f86b65..a5b9a3977 100644 --- a/hnn_core/viz.py +++ b/hnn_core/viz.py @@ -78,9 +78,9 @@ def plt_show(show=True, fig=None, **kwargs): (fig or plt).show(**kwargs) -def plot_laminar_lfp(times, data, contact_labels, tmin=None, tmax=None, - ax=None, decim=None, color='cividis', - voltage_offset=50, voltage_scalebar=200, show=True): +def plot_laminar_lfp(times, data, contact_labels, ax=None, decim=None, + color='cividis', voltage_offset=50, voltage_scalebar=200, + show=True): """Plot laminar extracellular electrode array voltage time series. Parameters @@ -89,10 +89,6 @@ def plot_laminar_lfp(times, data, contact_labels, tmin=None, tmax=None, Sampling times (in ms). data : Two-dimensional Numpy array The extracellular voltages as an (n_contacts, n_times) array. - tmin : float | None - Start time of plot in milliseconds. If None, plot entire simulation. - tmax : float | None - End time of plot in milliseconds. If None, plot entire simulation. ax : instance of matplotlib figure | None The matplotlib axis decim : int | list of int | None (default) @@ -168,11 +164,11 @@ def plot_laminar_lfp(times, data, contact_labels, tmin=None, tmax=None, trace_offsets = np.arange(n_offsets)[:, np.newaxis] * voltage_offset for contact_no, trace in enumerate(np.atleast_2d(data)): - plot_data, plot_times = _get_plot_data_trange(times, trace, tmin, tmax) + plot_data = trace + plot_times = times if decim is not None: - plot_data, plot_times = _decimate_plot_data(decim, plot_data, - plot_times) + plot_data, plot_times = _decimate_plot_data(decim, trace, times) if isinstance(color, np.ndarray): col = color[contact_no] @@ -182,6 +178,7 @@ def plot_laminar_lfp(times, data, contact_labels, tmin=None, tmax=None, col = color ax.plot(plot_times, plot_data + trace_offsets[contact_no], label=f'C{contact_no}', color=col) + ax.set_xlim(right=plot_times[-1]) if voltage_offset is not None: ax.set_ylim(-voltage_offset, n_offsets * voltage_offset) @@ -220,7 +217,7 @@ def plot_laminar_lfp(times, data, contact_labels, tmin=None, tmax=None, return ax.get_figure() -def plot_dipole(dpl, tmin=None, tmax=None, ax=None, layer='agg', decim=None, +def plot_dipole(dpl, ax=None, layer='agg', decim=None, color='k', label="average", average=False, show=True): """Simple layer-specific plot function. @@ -228,10 +225,6 @@ def plot_dipole(dpl, tmin=None, tmax=None, ax=None, layer='agg', decim=None, ---------- dpl : instance of Dipole | list of Dipole instances The Dipole object. - tmin : float or None - Start time of plot in milliseconds. If None, plot entire simulation. - tmax : float or None - End time of plot in milliseconds. If None, plot entire simulation. ax : instance of matplotlib figure | None The matplotlib axis layer : str @@ -288,11 +281,11 @@ def plot_dipole(dpl, tmin=None, tmax=None, ax=None, layer='agg', decim=None, if layer in dpl_trial.data.keys(): # extract scaled data and times - data, times = _get_plot_data_trange(dpl_trial.times, - dpl_trial.data[layer], - tmin, tmax) + data = dpl_trial.data[layer] + times = dpl_trial.times if decim is not None: - data, times = _decimate_plot_data(decim, data, times) + data, times = _decimate_plot_data( + decim, dpl_trial.data[layer], dpl_trial.times) if idx == len(dpl) - 1 and average: # the average dpl ax.plot(times, data, color=color, label=label, lw=1.5) @@ -300,7 +293,7 @@ def plot_dipole(dpl, tmin=None, tmax=None, ax=None, layer='agg', decim=None, alpha = 0.5 if average else 1. ax.plot(times, data, color=_lighten_color(color, 0.5), alpha=alpha, lw=1.) - + ax.set_xlim(right=dpl_trial.times[-1]) if average: ax.legend() @@ -479,6 +472,7 @@ def plot_spikes_hist(cell_response, trial_idx=None, ax=None, spike_types=None, ax.set_ylabel("Counts") ax.legend() + ax.set_xlim(right=cell_response.times[-1]) plt_show(show) return ax.get_figure() @@ -560,7 +554,7 @@ def plot_spikes_raster(cell_response, trial_idx=None, tmin=None, tmax=None, ax.set_facecolor('k') ax.set_xlabel('Time (ms)') ax.get_yaxis().set_visible(False) - ax.set_xlim(left=0) + ax.set_xlim(left=0, right=cell_response.times[-1]) plt_show(show) return ax.get_figure() @@ -1235,6 +1229,7 @@ def plot_laminar_csd(times, data, contact_labels, tmin=None, tmax=None, ax.set_xlabel('Time (ms)') ax.set_ylabel('Electrode depth') + ax.set_xlim(right=times[-1]) plt.tight_layout() plt_show(show) From bc9ea72dc82c598169efcb6550c8711c33308fc0 Mon Sep 17 00:00:00 2001 From: tianqi-cheng <113143982+tianqi-cheng@users.noreply.github.com> Date: Wed, 1 Nov 2023 14:39:59 -0400 Subject: [PATCH 3/6] Update hnn_core/viz.py Co-authored-by: Ryan Thorpe --- hnn_core/viz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hnn_core/viz.py b/hnn_core/viz.py index a5b9a3977..3e8472ef0 100644 --- a/hnn_core/viz.py +++ b/hnn_core/viz.py @@ -178,7 +178,7 @@ def plot_laminar_lfp(times, data, contact_labels, ax=None, decim=None, col = color ax.plot(plot_times, plot_data + trace_offsets[contact_no], label=f'C{contact_no}', color=col) - ax.set_xlim(right=plot_times[-1]) + ax.set_xlim(right=times[-1]) if voltage_offset is not None: ax.set_ylim(-voltage_offset, n_offsets * voltage_offset) From 1981892a0f88f0a45ec1bf8f1377f9211a477e19 Mon Sep 17 00:00:00 2001 From: Tianqi Cheng Date: Wed, 1 Nov 2023 14:52:57 -0400 Subject: [PATCH 4/6] update_nov1 --- hnn_core/viz.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/hnn_core/viz.py b/hnn_core/viz.py index 3e8472ef0..44069955e 100644 --- a/hnn_core/viz.py +++ b/hnn_core/viz.py @@ -478,7 +478,7 @@ def plot_spikes_hist(cell_response, trial_idx=None, ax=None, spike_types=None, return ax.get_figure() -def plot_spikes_raster(cell_response, trial_idx=None, tmin=None, tmax=None, +def plot_spikes_raster(cell_response, trial_idx=None, ax=None, show=True): """Plot the aggregate spiking activity according to cell type. @@ -488,10 +488,6 @@ def plot_spikes_raster(cell_response, trial_idx=None, tmin=None, tmax=None, The CellResponse object from net.cell_response trial_idx : int | list of int | None Index of trials to be plotted. If None, all trials plotted - tmin : float or None - Start time of plot in milliseconds. If None, plot entire simulation. - tmax : float or None - End time of plot in milliseconds. If None, plot entire simulation. ax : instance of matplotlib axis | None An axis object from matplotlib. If None, a new figure is created. show : bool @@ -539,7 +535,9 @@ def plot_spikes_raster(cell_response, trial_idx=None, tmin=None, tmax=None, cell_type_times, cell_type_ypos = [], [] for gid in cell_type_gids: gid_time = spike_times[spike_gids == gid] - _, gid_time = _get_plot_data_trange(gid_time, gid_time, tmin, tmax) + _, gid_time = _get_plot_data_trange( + gid_time, gid_time, cell_response.times[0], + cell_response.times[-1]) cell_type_times.append(gid_time) cell_type_ypos.append(ypos) ypos = ypos - 1 @@ -1185,7 +1183,7 @@ def _onclick(event): return ax.get_figure() -def plot_laminar_csd(times, data, contact_labels, tmin=None, tmax=None, +def plot_laminar_csd(times, data, contact_labels, ax=None, colorbar=True, show=True): """Plot laminar current source density (CSD) estimation from LFP array. @@ -1195,9 +1193,6 @@ def plot_laminar_csd(times, data, contact_labels, tmin=None, tmax=None, Sampling times (in ms). data : array-like, shape (n_channels, n_times) CSD data, channels x time. - tmin : float | None - Start time of plot in milliseconds. If None, plot entire simulation. - tmax : float | None ax : instance of matplotlib figure | None The matplotlib axis. colorbar : bool @@ -1216,9 +1211,9 @@ def plot_laminar_csd(times, data, contact_labels, tmin=None, tmax=None, import matplotlib.pyplot as plt if ax is None: _, ax = plt.subplots(1, 1, constrained_layout=True) - times, data = _get_plot_data_trange(times, data, tmin, tmax) + times, data = _get_plot_data_trange(times, data, times[0], times[-1]) _, contact_labels = _get_plot_data_trange( - times, contact_labels, tmin, tmax) + times, contact_labels, times[0], times[-1]) im = ax.pcolormesh(times, contact_labels, np.array(data), cmap="jet_r", shading='auto') ax.set_title("CSD") From fdc6335c8b07a6240131e6bc59da57e388b4a9b2 Mon Sep 17 00:00:00 2001 From: tianqi-cheng <113143982+tianqi-cheng@users.noreply.github.com> Date: Wed, 29 Nov 2023 13:02:56 -0500 Subject: [PATCH 5/6] Update hnn_core/viz.py Co-authored-by: Ryan Thorpe --- hnn_core/viz.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hnn_core/viz.py b/hnn_core/viz.py index 44069955e..854b65800 100644 --- a/hnn_core/viz.py +++ b/hnn_core/viz.py @@ -284,8 +284,7 @@ def plot_dipole(dpl, ax=None, layer='agg', decim=None, data = dpl_trial.data[layer] times = dpl_trial.times if decim is not None: - data, times = _decimate_plot_data( - decim, dpl_trial.data[layer], dpl_trial.times) + data, times = _decimate_plot_data(decim, data, times) if idx == len(dpl) - 1 and average: # the average dpl ax.plot(times, data, color=color, label=label, lw=1.5) From 89042b7c106b642b755d4902a977f42708974df5 Mon Sep 17 00:00:00 2001 From: katduecker Date: Fri, 10 May 2024 14:53:31 -0400 Subject: [PATCH 6/6] add deprecation cycle tmin/tmax --- hnn_core/dipole.py | 40 ++++++++++++++++++----------- hnn_core/extracellular.py | 16 ++++++++---- hnn_core/viz.py | 53 ++++++++++++++++++++++++++++++--------- 3 files changed, 78 insertions(+), 31 deletions(-) diff --git a/hnn_core/dipole.py b/hnn_core/dipole.py index c140358b1..56f2bba82 100644 --- a/hnn_core/dipole.py +++ b/hnn_core/dipole.py @@ -14,7 +14,6 @@ from .viz import plot_dipole, plot_psd, plot_tfr_morlet - def simulate_dipole(net, tstop, dt=0.025, n_trials=None, record_vsec=False, record_isec=False, postproc=False): """Simulate a dipole given the experiment parameters. @@ -106,25 +105,20 @@ def simulate_dipole(net, tstop, dt=0.025, n_trials=None, record_vsec=False, return dpls -def _read_dipole_txt(fname, extension='.txt'): +def _read_dipole_txt(fname): """Read dipole values from a txt file and create a Dipole instance. Parameters ---------- - fname : str or io.StringIO - Full path to the input file (.txt or .csv) or - Content of file in memory as a StringIO + fname : str + Full path to the input file (.txt) + Returns ------- dpl : Dipole The instance of Dipole class """ - if extension == '.csv': - # read from a csv file ignoring the headers - dpl_data = np.genfromtxt(fname, delimiter=',', - skip_header=1, dtype=float) - else: - dpl_data = np.loadtxt(fname, dtype=float) + dpl_data = np.loadtxt(fname, dtype=float) ncols = dpl_data.shape[1] if ncols not in (2, 4): raise ValueError( @@ -179,6 +173,10 @@ def read_dipole(fname): The instance of Dipole class """ + # For supporting tests in test_gui.py + if isinstance(fname, StringIO): + return _read_dipole_txt(fname) + fname = str(fname) if not os.path.exists(fname): raise FileNotFoundError('File not found at path %s.' % (fname,)) @@ -468,11 +466,18 @@ def savgol_filter(self, h_freq): self.sfreq) return self - def plot(self, layer='agg', decim=None, ax=None, color='k', show=True): + def plot(self, tmin=None, tmax=None, layer='agg', decim=None, ax=None, + color='k', show=True): """Simple layer-specific plot function. Parameters ---------- + tmin : float | None [deprecated] + Start time of plot in milliseconds. + If None, plot entire simulation. + tmax : float | None [deprecated] + End time of plot in milliseconds. + If None, plot entire simulation. layer : str The layer to plot. Can be one of 'agg', 'L2', and 'L5' decimate : int @@ -484,13 +489,20 @@ def plot(self, layer='agg', decim=None, ax=None, color='k', show=True): show : bool If True, show the figure + (tmin and tmax are deprecated) + tmin : float or None + Start time of plot (in ms). If None, plot entire simulation. + tmax : float or None + End time of plot (in ms). If None, plot entire simulation. + Returns ------- fig : instance of plt.fig The matplotlib figure handle. """ - return plot_dipole(self, ax=ax, layer=layer, decim=decim, color=color, - show=show) + + return plot_dipole(self, tmin=tmin, tmax=tmax, ax=ax, layer=layer, + decim=decim, color=color, show=show) def plot_psd(self, fmin=0, fmax=None, tmin=None, tmax=None, layer='agg', color=None, label=None, ax=None, show=True): diff --git a/hnn_core/extracellular.py b/hnn_core/extracellular.py index db8015ed7..f5b864334 100644 --- a/hnn_core/extracellular.py +++ b/hnn_core/extracellular.py @@ -27,7 +27,6 @@ from .externals.mne import _validate_type, _check_option - def calculate_csd2d(lfp_data, delta=1): """Current source density (CSD) estimation @@ -443,9 +442,9 @@ def smooth(self, window_len): return self - def plot_lfp(self, *, trial_no=None, contact_no=None, ax=None, decim=None, - color='cividis', voltage_offset=50, voltage_scalebar=200, - show=True): + def plot_lfp(self, *, trial_no=None, contact_no=None, tmin=None, tmax=None, + ax=None, decim=None, color='cividis', voltage_offset=50, + voltage_scalebar=200, show=True): """Plot laminar local field potential time series. One plot is created for each trial. Multiple trials can be overlaid @@ -457,6 +456,12 @@ def plot_lfp(self, *, trial_no=None, contact_no=None, ax=None, decim=None, Trial number(s) to plot contact_no : int | list of int | slice Electrode contact number(s) to plot + tmin : float | None [deprecated] + Start time of plot in milliseconds. + If None, plot entire simulation. + tmax : float | None [deprecated] + End time of plot in milliseconds. + If None, plot entire simulation. ax : instance of matplotlib figure | None The matplotlib axis decim : int | list of int | None (default) @@ -503,7 +508,7 @@ def plot_lfp(self, *, trial_no=None, contact_no=None, ax=None, decim=None, for trial_data in plot_data: fig = plot_laminar_lfp( - self.times, trial_data, ax=ax, + self.times, trial_data, tmin=tmin, tmax=tmax, ax=ax, decim=decim, color=color, voltage_offset=voltage_offset, voltage_scalebar=voltage_scalebar, @@ -714,3 +719,4 @@ def _get_nrn_times(self): return self._nrn_times.to_python() else: raise RuntimeError('Simulation not yet run!') + diff --git a/hnn_core/viz.py b/hnn_core/viz.py index 854b65800..0c865b955 100644 --- a/hnn_core/viz.py +++ b/hnn_core/viz.py @@ -7,10 +7,10 @@ import numpy as np from itertools import cycle import colorsys +import warnings from .externals.mne import _validate_type - def _lighten_color(color, amount=0.5): import matplotlib.colors as mc try: @@ -21,7 +21,7 @@ def _lighten_color(color, amount=0.5): return colorsys.hls_to_rgb(c[0], 1 - amount * (1 - c[1]), c[2]) -def _get_plot_data_trange(times, data, tmin, tmax): +def _get_plot_data_trange(times, data, tmin=None, tmax=None): """Get slices of times and data based on tmin and tmax""" if isinstance(times, list): times = np.array(times) @@ -78,9 +78,9 @@ def plt_show(show=True, fig=None, **kwargs): (fig or plt).show(**kwargs) -def plot_laminar_lfp(times, data, contact_labels, ax=None, decim=None, - color='cividis', voltage_offset=50, voltage_scalebar=200, - show=True): +def plot_laminar_lfp(times, data, contact_labels, tmin=None, tmax=None, + ax=None, decim=None, color='cividis', voltage_offset=50, + voltage_scalebar=200, show=True): """Plot laminar extracellular electrode array voltage time series. Parameters @@ -89,6 +89,11 @@ def plot_laminar_lfp(times, data, contact_labels, ax=None, decim=None, Sampling times (in ms). data : Two-dimensional Numpy array The extracellular voltages as an (n_contacts, n_times) array. + tmin : float | None [deprecated] + Start time of plot in milliseconds. If None, plot entire simulation. + tmax : float | None [deprecated] + End time of plot in milliseconds. If None, plot entire simulation. + ax : instance of matplotlib figure | None The matplotlib axis decim : int | list of int | None (default) @@ -178,7 +183,14 @@ def plot_laminar_lfp(times, data, contact_labels, ax=None, decim=None, col = color ax.plot(plot_times, plot_data + trace_offsets[contact_no], label=f'C{contact_no}', color=col) - ax.set_xlim(right=times[-1]) + + # To be removed after deprecation cycle + if tmin is not None or tmax is not None: + ax.set_xlim(left=tmin, right=tmax) + warnings.warn('tmin and tmax are deprecated and will be removed in future releases of hnn-core.' + 'By default, dipoles and laminar LFPs are now plotted from 0 to tstop.', DeprecationWarning) + else: + ax.set_xlim(right=times[-1]) if voltage_offset is not None: ax.set_ylim(-voltage_offset, n_offsets * voltage_offset) @@ -217,7 +229,7 @@ def plot_laminar_lfp(times, data, contact_labels, ax=None, decim=None, return ax.get_figure() -def plot_dipole(dpl, ax=None, layer='agg', decim=None, +def plot_dipole(dpl, tmin=None, tmax=None, ax=None, layer='agg', decim=None, color='k', label="average", average=False, show=True): """Simple layer-specific plot function. @@ -225,6 +237,10 @@ def plot_dipole(dpl, ax=None, layer='agg', decim=None, ---------- dpl : instance of Dipole | list of Dipole instances The Dipole object. + tmin : float | None [deprecated] + Start time of plot in milliseconds. If None, plot entire simulation. + tmax : float | None [deprecated] + End time of plot in milliseconds. If None, plot entire simulation. ax : instance of matplotlib figure | None The matplotlib axis layer : str @@ -283,6 +299,12 @@ def plot_dipole(dpl, ax=None, layer='agg', decim=None, # extract scaled data and times data = dpl_trial.data[layer] times = dpl_trial.times + + # to be removed after deprecation cycle + if tmin is not None: + data, times = _get_plot_data_trange(dpl_trial.times, + dpl_trial.data[layer]) + if decim is not None: data, times = _decimate_plot_data(decim, data, times) if idx == len(dpl) - 1 and average: @@ -292,7 +314,14 @@ def plot_dipole(dpl, ax=None, layer='agg', decim=None, alpha = 0.5 if average else 1. ax.plot(times, data, color=_lighten_color(color, 0.5), alpha=alpha, lw=1.) - ax.set_xlim(right=dpl_trial.times[-1]) + # To be removed after deprecation cycle + if tmin is not None or tmax is not None: + ax.set_xlim(left=tmin, right=tmax) + warnings.warn('tmin and tmax are deprecated and will be removed in future releases of hnn-core.' + 'By default, dipoles and laminar LFPs are now plotted from 0 to tstop.', DeprecationWarning) + + else: + ax.set_xlim(right=times[-1]) if average: ax.legend() @@ -322,6 +351,7 @@ def plot_spikes_hist(cell_response, trial_idx=None, ax=None, spike_types=None, ---------- cell_response : instance of CellResponse The CellResponse object from net.cell_response + End time of plot in milliseconds. If None, plot entire simulation. trial_idx : int | list of int | None Index of trials to be plotted. If None, all trials plotted. ax : instance of matplotlib axis | None @@ -471,7 +501,8 @@ def plot_spikes_hist(cell_response, trial_idx=None, ax=None, spike_types=None, ax.set_ylabel("Counts") ax.legend() - ax.set_xlim(right=cell_response.times[-1]) + + ax.set_xlim(left=0, right=cell_response.times[-1]) plt_show(show) return ax.get_figure() @@ -1210,9 +1241,7 @@ def plot_laminar_csd(times, data, contact_labels, import matplotlib.pyplot as plt if ax is None: _, ax = plt.subplots(1, 1, constrained_layout=True) - times, data = _get_plot_data_trange(times, data, times[0], times[-1]) - _, contact_labels = _get_plot_data_trange( - times, contact_labels, times[0], times[-1]) + im = ax.pcolormesh(times, contact_labels, np.array(data), cmap="jet_r", shading='auto') ax.set_title("CSD")