Skip to content

Commit

Permalink
Better docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ntolley committed Sep 21, 2023
1 parent 4956423 commit 3c0bccc
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions hnn_core/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ def __init__(self, net, ax=None, vmin=-100, vmax=50, bg_color='black',
self._time_idx = time_idx

# Get voltage data and corresponding colors
self.vsec_array = self.get_voltages()
self.vsec_array = self._get_voltages()
self.color_array = self.colormap(self.vsec_array)

# Create figure
Expand All @@ -1325,10 +1325,10 @@ def __init__(self, net, ax=None, vmin=-100, vmax=50, bg_color='black',
self.ax.set_facecolor(self._bg_color)
else:
self.fig = None
self.init_network_plot()
self._init_network_plot()
self._update_axes()

def get_voltages(self):
def _get_voltages(self):
vsec_list = list()
for cell_type in self.net.cell_types:
gid_range = self.net.gid_ranges[cell_type]
Expand All @@ -1350,7 +1350,7 @@ def update_section_voltages(self, t_idx):
for line, color in zip(self.ax.lines, color_list):
line.set_color(color)

def init_network_plot(self):
def _init_network_plot(self):
for cell_type in self.net.cell_types:
gid_range = self.net.gid_ranges[cell_type]
for gid_idx, gid in enumerate(gid_range):
Expand All @@ -1374,13 +1374,32 @@ def _update_axes(self):
def export_movie(self, fname, fps=30, dpi=300, decim=10,
interval=30, frame_start=0, frame_stop=None,
writer='ffmpeg'):
"""Export movie of network activity
fname : str
Filename of exported movie
fps : int
Frames per second, default: 30
dpi : int
Dots per inch, default: 300
decim : int
Decimation factor for frames, default: 10
interval : int
Delay between frames, default: 30
frame_start : int
Index of first frame, default: 0
frame_stop : int | None
Index of last frame, default: None
If None, entire simulation is animated
writer : str
Movie writer, default: 'ffmpeg'
"""
import matplotlib.animation as animation
if frame_stop is None:
frame_stop = len(self.times) - 1

frames = np.arange(frame_start, frame_stop, decim)
ani = animation.FuncAnimation(
self.fig, self.set_time_idx, frames, interval=interval)
self.fig, self._set_time_idx, frames, interval=interval)

writer = animation.writers[writer](fps=fps)
ani.save(fname, writer=writer, dpi=dpi)
Expand Down Expand Up @@ -1447,7 +1466,7 @@ def vmin(self):
def vmin(self, vmin):
_validate_type(vmin, (int, float), 'vmin')
self._vmin = vmin
self.vsec_array = self.get_voltages()
self.vsec_array = self._get_voltages()
self.color_array = self.colormap(self.vsec_array)

@property
Expand All @@ -1458,7 +1477,7 @@ def vmax(self):
def vmax(self, vmax):
_validate_type(vmax, (int, float), 'vmax')
self._vmax = vmax
self.vsec_array = self.get_voltages()
self.vsec_array = self._get_voltages()
self.color_array = self.colormap(self.vsec_array)

# Time and trial indices
Expand All @@ -1470,7 +1489,7 @@ def trial_idx(self):
def trial_idx(self, trial_idx):
_validate_type(trial_idx, int, 'trial_idx')
self._trial_idx = trial_idx
self.vsec_array = self.get_voltages()
self.vsec_array = self._get_voltages()
self.color_array = self.colormap(self.vsec_array)

@property
Expand All @@ -1483,8 +1502,8 @@ def time_idx(self, time_idx):
self._time_idx = time_idx
self.update_section_voltages(self._time_idx)

# Necessary for making animations
def set_time_idx(self, time_idx):
# Callable update function for making animations
def _set_time_idx(self, time_idx):
self.time_idx = time_idx

# Background color and voltage colormaps
Expand Down

0 comments on commit 3c0bccc

Please sign in to comment.