Skip to content

Commit

Permalink
handling MPL deprecation to set fig window title
Browse files Browse the repository at this point in the history
  • Loading branch information
raamana committed Mar 30, 2022
1 parent 3cf7d0c commit f0b64e5
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 28 deletions.
8 changes: 4 additions & 4 deletions visualqc/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from visualqc.interfaces import BaseReviewInterface
from visualqc.utils import check_finite_int, check_id_list, check_input_dir_alignment, \
check_out_dir, check_outlier_params, check_views, get_axis, pick_slices, read_image, \
scale_0to1, check_time
scale_0to1, check_time, set_fig_window_title
from visualqc.workflows import BaseWorkflowVisualQC
from visualqc.image_utils import overlay_edges, mix_color, diff_image, mix_slices_in_checkers

Expand Down Expand Up @@ -345,9 +345,9 @@ def open_figure(self):
self.fig, self.axes = plt.subplots(self.num_rows, self.num_cols,
figsize=self.figsize)
self.axes = self.axes.flatten()

self.fig.canvas.set_window_title('VisualQC Alignment : {} {} {} '
''.format(self.in_dir, self.image1_name, self.image2_name))
set_fig_window_title(
self.fig, 'VisualQC Alignment : {} {} {} '
''.format(self.in_dir, self.image1_name, self.image2_name))

# vmin/vmax are controlled, because we rescale all to [0, 1]
self.display_params = dict(interpolation='none', aspect='equal', origin='lower',
Expand Down
12 changes: 6 additions & 6 deletions visualqc/defacing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
from visualqc import config as cfg
from visualqc.image_utils import rescale_without_outliers
from visualqc.interfaces import BaseReviewInterface
from visualqc.utils import (check_inputs_defacing, check_out_dir,
compute_cell_extents_grid, pixdim_nifti_header,
read_image, slice_aspect_ratio, check_event_in_axes)
from visualqc.utils import (check_event_in_axes, check_inputs_defacing,
check_out_dir, compute_cell_extents_grid,
pixdim_nifti_header, read_image, set_fig_window_title,
slice_aspect_ratio)
from visualqc.workflows import BaseWorkflowVisualQC


Expand Down Expand Up @@ -355,9 +356,8 @@ def init_layout(self,
bounding_rect=cfg.bbox_defacing_MRI_review,
figsize=self.figsize)
self.fig = self.collage.fig
self.fig.canvas.set_window_title('VisualQC defacing : {} {} '
''.format(self.in_dir,
self.defaced_name))
set_fig_window_title(
self.fig, f'VisualQC defacing : {self.in_dir} {self.defaced_name} ')

self.padding = padding

Expand Down
13 changes: 6 additions & 7 deletions visualqc/diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
import time
import warnings
from abc import ABC
from os.path import basename, join as pjoin
from textwrap import wrap

import nibabel as nib
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.widgets import CheckButtons, RadioButtons
from mrivis.utils import crop_image
from os.path import basename, join as pjoin

from visualqc import config as cfg
from visualqc.image_utils import dwi_overlay_edges
from visualqc.readers import diffusion_traverse_bids
from visualqc.t1_mri import T1MriInterface
from visualqc.utils import (check_bids_dir, check_finite_int, check_image_is_4d,
check_out_dir, check_outlier_params, check_time,
check_views, get_axis,
pick_slices,
scale_0to1)
check_views, get_axis, pick_slices, scale_0to1,
set_fig_window_title)
from visualqc.workflows import BaseWorkflowVisualQC


Expand Down Expand Up @@ -420,9 +420,8 @@ def open_figure(self):

# 1. main carpet, in the background
self.fig, self.ax_carpet = plt.subplots(1, 1, figsize=self.figsize)
self.fig.canvas.set_window_title('VisualQC Diffusion MRI :'
' {}'.format(self.in_dir))

set_fig_window_title(
self.fig, f'VisualQC Diffusion MRI : {self.in_dir} ')
self.ax_carpet.set_zorder(self.layer_order_carpet)
# vmin/vmax are controlled, because we rescale all to [0, 1]
self.imshow_params_carpet = dict(interpolation='none', aspect='auto',
Expand Down
7 changes: 4 additions & 3 deletions visualqc/freesurfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
check_out_dir, check_outlier_params, check_views,
freesurfer_vis_tool_installed, get_axis,
get_freesurfer_mri_path, get_label_set, pick_slices,
read_image, scale_0to1,
read_image, scale_0to1, set_fig_window_title,
void_subcortical_symmetrize_cortical)
from visualqc.workflows import BaseWorkflowVisualQC

Expand Down Expand Up @@ -407,8 +407,9 @@ def open_figure(self):
self.fig, self.axes = plt.subplots(self.num_rows_total, self.num_cols_final,
figsize=self.figsize)
self.axes = self.axes.flatten()
self.fig.canvas.set_window_title('VisualQC {} {} : {}'
' '.format(self.vis_type, self.seg_name, self.in_dir))
set_fig_window_title(self.fig,
'VisualQC {} {} : {} '
''.format(self.vis_type, self.seg_name, self.in_dir))

self.display_params_mri = dict(interpolation='none', aspect='equal',
origin='lower',
Expand Down
9 changes: 4 additions & 5 deletions visualqc/functional_mri.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
from visualqc.readers import func_mri_traverse_bids
from visualqc.t1_mri import T1MriInterface
from visualqc.utils import (check_bids_dir, check_event_in_axes, check_finite_int,
check_id_list_with_regex,
check_image_is_4d, check_out_dir, check_outlier_params,
check_views, get_axis, pick_slices, scale_0to1)
check_id_list_with_regex, check_image_is_4d,
check_out_dir, check_outlier_params, check_views,
get_axis, pick_slices, scale_0to1, set_fig_window_title)
from visualqc.workflows import BaseWorkflowVisualQC


Expand Down Expand Up @@ -393,8 +393,7 @@ def open_figure(self):

# 1. main carpet, in the background
self.fig, self.ax_carpet = plt.subplots(1, 1, figsize=self.figsize)
self.fig.canvas.set_window_title('VisualQC Functional MRI :'
' {}'.format(self.in_dir))
set_fig_window_title(self.fig, f'VisualQC Functional MRI : {self.in_dir}')

self.ax_carpet.set_zorder(self.layer_order_carpet)
# vmin/vmax are controlled, because we rescale all to [0, 1]
Expand Down
6 changes: 3 additions & 3 deletions visualqc/t1_mri.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from visualqc.utils import (check_bids_dir, check_finite_int, check_id_list,
check_input_dir_T1, check_out_dir, check_outlier_params,
check_views, read_image, saturate_brighter_intensities,
scale_0to1)
scale_0to1, set_fig_window_title)
from visualqc.workflows import BaseWorkflowVisualQC


Expand Down Expand Up @@ -377,8 +377,8 @@ def init_layout(self, views, num_rows_per_view,
bounding_rect=cfg.bounding_box_review,
figsize=self.figsize)
self.fig = self.collage.fig
self.fig.canvas.set_window_title('VisualQC T1 MRI : {} {} '
''.format(self.in_dir, self.mri_name))
set_fig_window_title(
self.fig, f'VisualQC T1w MRI : {self.in_dir} {self.mri_name}')

self.padding = padding

Expand Down
9 changes: 9 additions & 0 deletions visualqc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ def pixdim_nifti_header(header):
return header['pixdim'][1:4]


def set_fig_window_title(fig, text):
"""Sets the title of the given figure"""

try:
fig.canvas.manager.set_window_title(text)
except: # not all backends support this, so quietly ignoring it
pass


def slice_aspect_ratio(pixel_dim, axis):
"""computes aspect ratio for the cross-sectional slices of a given dimension"""

Expand Down

0 comments on commit f0b64e5

Please sign in to comment.