Skip to content

Commit 21c6901

Browse files
ENH Brain.save_image_sequence(): add option for montage specification
1 parent b10739c commit 21c6901

File tree

1 file changed

+50
-9
lines changed

1 file changed

+50
-9
lines changed

surfer/viz.py

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,26 @@ def set_data_time_index(self, time_idx):
15691569
self.update_text(data["time_label"] % time, "time_label")
15701570
self._toggle_render(True, views)
15711571

1572+
def get_data_time_index(self):
1573+
"""Retrieve the currently displayed data time index
1574+
1575+
Returns
1576+
-------
1577+
time_idx : int
1578+
Current time index.
1579+
1580+
Notes
1581+
-----
1582+
Raises a RuntimeError if the Brain instance has not data overlay.
1583+
"""
1584+
time_idx = None
1585+
for hemi in ['lh', 'rh']:
1586+
data = self.data_dict[hemi]
1587+
if data is not None:
1588+
time_idx = data["time_idx"]
1589+
return time_idx
1590+
raise RuntimeError("Brain instance has no data overlay")
1591+
15721592
@verbose
15731593
def set_data_smoothing_steps(self, smoothing_steps, verbose=None):
15741594
"""Set the number of smoothing steps
@@ -1879,7 +1899,8 @@ def save_imageset(self, prefix, views, filetype='png', colorbar='auto',
18791899
return images_written
18801900

18811901
def save_image_sequence(self, time_idx, fname_pattern, use_abs_idx=True,
1882-
row=-1, col=-1):
1902+
row=-1, col=-1, montage='single', orientation='h',
1903+
border_size=15, colorbar='auto'):
18831904
"""Save a temporal image sequence
18841905
18851906
The files saved are named "fname_pattern % (pos)" where "pos" is a
@@ -1888,30 +1909,50 @@ def save_image_sequence(self, time_idx, fname_pattern, use_abs_idx=True,
18881909
Parameters
18891910
----------
18901911
time_idx : array-like
1891-
time indices to save
1912+
Time indices to save.
18921913
fname_pattern : str
1893-
filename pattern, e.g. 'movie-frame_%0.4d.png'
1914+
Filename pattern, e.g. 'movie-frame_%0.4d.png'.
18941915
use_abs_idx : boolean
1895-
if True the indices given by "time_idx" are used in the filename
1916+
If True the indices given by "time_idx" are used in the filename
18961917
if False the index in the filename starts at zero and is
1897-
incremented by one for each image (Default: True)
1918+
incremented by one for each image (Default: True).
18981919
row : int
1899-
row index of the brain to use
1920+
Row index of the brain to use.
19001921
col : int
1901-
column index of the brain to use
1922+
Column index of the brain to use.
1923+
montage: 'current' | 'single' | list
1924+
Views to include in the images: 'current' uses the currently
1925+
displayed image; 'single' (default) uses a single view, specified
1926+
by the ``row`` and ``col`` parameters; a list can be used to
1927+
specify a complete montage (see :meth:`save_montage`).
1928+
orientation: {'h' | 'v'}
1929+
Montage image orientation (horizontal of vertical alignment; only
1930+
applies if ``montage`` is a flat list).
1931+
border_size: int
1932+
Size of image border (more or less space between images).
1933+
colorbar: None | 'auto' | [int], optional
1934+
If None no colorbar is visible. If 'auto' is given the colorbar
1935+
is only shown in the middle view. Otherwise on the listed
1936+
views when a list of int is passed.
19021937
19031938
Returns
19041939
-------
19051940
images_written: list
19061941
all filenames written
19071942
"""
1908-
current_time_idx = self.data["time_idx"]
1943+
current_time_idx = self.get_data_time_index()
19091944
images_written = list()
19101945
rel_pos = 0
19111946
for idx in time_idx:
19121947
self.set_data_time_index(idx)
19131948
fname = fname_pattern % (idx if use_abs_idx else rel_pos)
1914-
self.save_single_image(fname, row, col)
1949+
if montage == 'single':
1950+
self.save_single_image(fname, row, col)
1951+
elif montage == 'current':
1952+
self.save_image(fname)
1953+
else:
1954+
self.save_montage(fname, montage, orientation, border_size,
1955+
colorbar, row, col)
19151956
images_written.append(fname)
19161957
rel_pos += 1
19171958

0 commit comments

Comments
 (0)