Example #1
0
    def plot_mask_image(self):

        m = Mosaic(self.inputs.orig_file, self.inputs.mask_file,
                   self.inputs.mask_file, show_mask=False, step=1)
        m.plot_mask()
        m.savefig("functional_mask.png")
        m.close()
Example #2
0
    def plot_mean_image(self):

        cmap = sns.cubehelix_palette(as_cmap=True, reverse=True, light=1, dark=0)
        m = Mosaic(self.inputs.mean_file, self.inputs.mean_file, self.inputs.mask_file, step=1)
        m.plot_overlay(vmin=0, cmap=cmap, fmt="%d")
        m.savefig("mean_func.png")
        m.close()
Example #3
0
 def write_tsnr_image(self):
     """Show the total subject SNR."""
     m = Mosaic(self.inputs.anatomy,
                self.inputs.tsnr_file,
                self.every_mask,
                step=self.step)
     m.plot_overlay("cube:1.9:.5", 0, alpha=1, fmt="%d")
     out_fname = op.abspath("tsnr.png")
     self.summary_files.append(out_fname)
     m.savefig(out_fname)
     m.close()
Example #4
0
 def write_r2_images(self):
     """Show the fixed effects model fit."""
     cmaps = ["cube:2:0", "cube:2.6:0"]
     for fname, cmap in zip(self.inputs.r2_files, cmaps):
         m = Mosaic(self.inputs.anatomy, fname,
                    self.every_mask, step=self.step)
         m.plot_overlay(cmap, 0, alpha=.85)
         out_fname = op.abspath(nii_to_png(fname))
         self.summary_files.append(out_fname)
         m.savefig(out_fname)
         m.close()
Example #5
0
    def plot_watershed(self, peaks):
        """Plot the watershed segmentation."""
        palette = sns.husl_palette(len(peaks))
        cmap = mpl.colors.ListedColormap(palette)

        m = Mosaic(stat=self.inputs.seg_file, mask=self.inputs.mask_file)
        m.plot_overlay(thresh=.5, cmap=cmap, vmin=1, vmax=len(peaks))
        out_fname = nii_to_png(self.inputs.seg_file)
        self.out_files.append(out_fname)
        m.savefig(out_fname)
        m.close()
Example #6
0
 def plot_mask(self):
     """Plot the analysis mask."""
     m = Mosaic(stat=self.inputs.mask_file)
     m.plot_mask()
     out_fname = nii_to_png(self.inputs.mask_file)
     self.out_files.append(out_fname)
     m.savefig(out_fname)
     m.close()
Example #7
0
 def plot_full_zstat(self):
     """Plot the unthresholded zstat."""
     m = Mosaic(stat=self.inputs.zstat_file, mask=self.inputs.mask_file)
     m.plot_overlay(cmap="coolwarm", center=True, alpha=.9)
     out_fname = nii_to_png(self.inputs.zstat_file)
     self.out_files.append(out_fname)
     m.savefig(out_fname)
     m.close()
Example #8
0
    def plot_peaks(self, peaks):
        """Plot the peaks."""
        palette = sns.husl_palette(len(peaks))
        cmap = mpl.colors.ListedColormap(palette)

        disk_img = self._peaks_to_disks(peaks)
        m = Mosaic(stat=disk_img, mask=self.inputs.mask_file)
        m.plot_overlay(thresh=.5, cmap=cmap, vmin=1, vmax=len(peaks))
        out_fname = nii_to_png(self.inputs.zstat_thresh_file, "_peaks")
        self.out_files.append(out_fname)
        m.savefig(out_fname)
        m.close()
Example #9
0
    def _run_interface(self, runtime):

        subjects_dir = os.environ["SUBJECTS_DIR"]
        wm_file = op.join(subjects_dir, self.inputs.subject_id, "mri/wm.mgz")
        wm_data = nib.load(wm_file).get_data().astype(bool).astype(int)

        m = Mosaic(self.inputs.in_file, wm_data, step=3)
        m.plot_contours(["#DD2222"])
        m.savefig("func2anat.png")
        m.close()

        return runtime
Example #10
0
 def plot_zstats(self):
     """Plot the positive and negative z stats with a low threshold."""
     for z_file in self.inputs.zstat_files:
         m = Mosaic(self.mean, z_file, self.mask, step=1)
         m.plot_activation(pos_cmap="Reds_r",
                           neg_cmap="Blues",
                           thresh=1.7,
                           alpha=.85)
         png_name = nii_to_png(z_file)
         m.savefig(png_name)
         m.close()
         self.out_files.append(png_name)
Example #11
0
    def _run_interface(self, runtime):

        target_brain = fsl.Info.standard_image("avg152T1_brain.nii.gz")
        m = Mosaic(self.inputs.in_file, target_brain)
        m.plot_contours("Reds", 2)
        m.savefig("warp_report.png")
        m.close()

        return runtime
Example #12
0
 def plot_thresh_zstat(self):
     """Plot the thresholded zstat."""
     m = Mosaic(stat=self.inputs.zstat_thresh_file,
                mask=self.inputs.mask_file)
     m.plot_activation(pos_cmap="OrRd_r", vfloor=3.3, alpha=.9)
     out_fname = nii_to_png(self.inputs.zstat_thresh_file)
     self.out_files.append(out_fname)
     m.savefig(out_fname)
     m.close()
Example #13
0
    def plot_tsnr(self):

        tsnr = self.inputs.tsnr_file
        m = Mosaic(self.mean, tsnr, self.mask, step=1)
        m.plot_overlay("cube:1.9:.5", 0, alpha=1, fmt="%d")
        png_name = nii_to_png(tsnr)
        m.savefig(png_name)
        m.close()
        self.out_files.append(png_name)
Example #14
0
 def plot_residuals(self):
     """Plot the variance of the model residuals across time."""
     ss = self.inputs.sigmasquareds_file
     m = Mosaic(self.mean, ss, self.mask, step=1)
     m.plot_overlay("cube:.8:.2", 0, alpha=.6, fmt="%d")
     png_name = nii_to_png(ss)
     m.savefig(png_name)
     m.close()
     self.out_files.append(png_name)
Example #15
0
 def write_zstat_images(self):
     """Show the fixed effects inference maps."""
     for fname in self.inputs.zstat_files:
         m = Mosaic(self.inputs.anatomy, fname,
                    self.every_mask, step=self.step)
         m.plot_activation(pos_cmap="Reds_r", neg_cmap="Blues",
                           thresh=2.3, alpha=.85)
         contrast = fname.split("/")[-2]
         os.mkdir(contrast)
         out_fname = op.join(contrast, "zstat1.png")
         self.zstat_files.append(op.abspath(contrast))
         m.savefig(out_fname)
         m.close()
Example #16
0
    def plot_mean_image(self):

        cmap = sns.cubehelix_palette(as_cmap=True,
                                     reverse=True,
                                     light=1,
                                     dark=0)
        m = Mosaic(self.inputs.mean_file,
                   self.inputs.mean_file,
                   self.inputs.mask_file,
                   step=1)
        m.plot_overlay(vmin=0, cmap=cmap, fmt="%d")
        m.savefig("mean_func.png")
        m.close()
Example #17
0
 def plot_rsquareds(self):
     """Plot the full, main, and confound R squared maps."""
     cmaps = ["cube:2:0", "cube:2.6:0", "cube:1.5:0"]
     for r2_file, cmap in zip(self.inputs.r2_files, cmaps):
         m = Mosaic(self.mean, r2_file, self.mask, step=1)
         m.plot_overlay(cmap, 0, alpha=.6)
         png_name = nii_to_png(r2_file)
         m.savefig(png_name)
         m.close()
         self.out_files.append(png_name)
Example #18
0
 def plot_zstats(self):
     """Plot the positive and negative z stats with a low threshold."""
     for z_file in self.inputs.zstat_files:
         m = Mosaic(self.mean, z_file, self.mask, step=1)
         m.plot_activation(pos_cmap="Reds_r", neg_cmap="Blues",
                           thresh=1.7, alpha=.85)
         png_name = nii_to_png(z_file)
         m.savefig(png_name)
         m.close()
         self.out_files.append(png_name)
Example #19
0
    def plot_watershed(self, peaks):
        """Plot the watershed segmentation."""
        palette = sns.husl_palette(len(peaks))
        cmap = mpl.colors.ListedColormap(palette)

        m = Mosaic(stat=self.inputs.seg_file, mask=self.inputs.mask_file)
        m.plot_overlay(thresh=.5, cmap=cmap, vmin=1, vmax=len(peaks))
        out_fname = nii_to_png(self.inputs.seg_file)
        self.out_files.append(out_fname)
        m.savefig(out_fname)
        m.close()
Example #20
0
 def write_tsnr_image(self):
     """Show the total subject SNR."""
     m = Mosaic(self.inputs.anatomy,
                self.inputs.tsnr_file,
                self.every_mask,
                step=self.step)
     m.plot_overlay("cube:1.9:.5", 0, alpha=1, fmt="%d")
     out_fname = op.abspath("tsnr.png")
     self.summary_files.append(out_fname)
     m.savefig(out_fname)
     m.close()
Example #21
0
 def write_r2_images(self):
     """Show the fixed effects model fit."""
     cmaps = ["cube:2:0", "cube:2.6:0"]
     for fname, cmap in zip(self.inputs.r2_files, cmaps):
         m = Mosaic(self.inputs.anatomy, fname,
                    self.every_mask, step=self.step)
         m.plot_overlay(cmap, 0, alpha=.85)
         out_fname = op.abspath(nii_to_png(fname))
         self.summary_files.append(out_fname)
         m.savefig(out_fname)
         m.close()
Example #22
0
    def write_mask_image(self):
        """Show the overlap of each run's mask."""
        mask_imgs = [nib.load(f) for f in self.inputs.masks]
        mask_data = [img.get_data()[..., np.newaxis] for img in mask_imgs]
        each_mask = np.concatenate(mask_data, axis=-1)
        any_mask = each_mask.max(axis=-1)
        self.every_mask = each_mask.min(axis=-1)

        m = Mosaic(self.inputs.anatomy, each_mask, any_mask,
                   step=self.step, show_mask=False)
        m.plot_mask_edges()
        out_fname = op.abspath("mask_overlap.png")
        self.summary_files.append(out_fname)
        m.savefig(out_fname)
        m.close()
Example #23
0
    def write_png(self):
        """Write a mosiac png showing the masked voxels."""
        slices_temp = op.join(self.data_dir, "%(subj)s/masks",
                              self.roi_name + ".png")

        for subj in self.subject_list:
            args = dict(subj=subj)
            m = Mosaic(self.epi_template % args,
                       self.out_template % args,
                       self.fov_template % args,
                       step=1, show_mask=False)
            cmap = mpl.colors.ListedColormap(["#C41E3A"])
            m.plot_overlay(cmap, thresh=.5, alpha=.9, colorbar=False)
            m.savefig(slices_temp % args)
            m.close()
Example #24
0
    def plot_peaks(self, peaks):
        """Plot the peaks."""
        palette = sns.husl_palette(len(peaks))
        cmap = mpl.colors.ListedColormap(palette)

        disk_img = self._peaks_to_disks(peaks)
        m = Mosaic(stat=disk_img, mask=self.inputs.mask_file)
        m.plot_overlay(thresh=.5, cmap=cmap, vmin=1, vmax=len(peaks))
        out_fname = nii_to_png(self.inputs.zstat_thresh_file, "_peaks")
        self.out_files.append(out_fname)
        m.savefig(out_fname)
        m.close()
Example #25
0
    def _run_interface(self, runtime):

        subjects_dir = os.environ["SUBJECTS_DIR"]
        wm_file = op.join(subjects_dir, self.inputs.subject_id, "mri/wm.mgz")
        wm_data = nib.load(wm_file).get_data().astype(bool).astype(int)

        m = Mosaic(self.inputs.in_file, wm_data, step=3)
        m.plot_contours(["#DD2222"])
        m.savefig("func2anat.png")
        m.close()

        return runtime
Example #26
0
 def write_zstat_images(self):
     """Show the fixed effects inference maps."""
     for fname in self.inputs.zstat_files:
         m = Mosaic(self.inputs.anatomy, fname,
                    self.every_mask, step=self.step)
         m.plot_activation(pos_cmap="Reds_r", neg_cmap="Blues",
                           thresh=2.3, alpha=.85)
         contrast = fname.split("/")[-2]
         os.mkdir(contrast)
         out_fname = op.join(contrast, "zstat1.png")
         self.zstat_files.append(op.abspath(contrast))
         m.savefig(out_fname)
         m.close()
Example #27
0
    def write_mask_image(self):
        """Show the overlap of each run's mask."""
        mask_imgs = [nib.load(f) for f in self.inputs.masks]
        mask_data = [img.get_data()[..., np.newaxis] for img in mask_imgs]
        each_mask = np.concatenate(mask_data, axis=-1)
        any_mask = each_mask.max(axis=-1)
        self.every_mask = each_mask.min(axis=-1)

        m = Mosaic(self.inputs.anatomy, each_mask, any_mask,
                   stat_interp="nearest", step=self.step, show_mask=False)
        m.plot_mask_edges()
        out_fname = op.abspath("mask_overlap.png")
        self.summary_files.append(out_fname)
        m.savefig(out_fname)
        m.close()
Example #28
0
    def write_png(self):
        """Write a mosiac png showing the masked voxels."""
        slices_temp = op.join(self.data_dir, "%(subj)s/masks", self.roi_name + ".png")

        for subj in self.subject_list:
            args = dict(subj=subj)
            m = Mosaic(
                self.epi_template % args,
                self.out_template % args,
                self.fov_template % args,
                step=1,
                show_mask=False,
                stat_interp="nearest",
            )
            cmap = mpl.colors.ListedColormap(["#C41E3A"])
            m.plot_overlay(cmap, thresh=0.5, alpha=0.9, colorbar=False)
            m.savefig(slices_temp % args)
            m.close()
Example #29
0
def volume_images(data_dir, subj):
    """Plot a mosiac of the brainmask and aseg volumes."""
    # Plot the volume slices
    brain_file = op.join(data_dir, subj, "mri/brainmask.mgz")

    # Load the cortical ribbon file and use same index for both hemis
    ribbon_file = op.join(data_dir, subj, "mri/ribbon.mgz")
    ribbon_data = nib.load(ribbon_file).get_data().astype(float)
    ribbon_data[ribbon_data == 3] = 1
    ribbon_data[ribbon_data == 42] = 1
    ribbon_data[ribbon_data != 1] = np.nan

    # Load the aseg file and use it to derive a FOV mask
    aseg_file = op.join(data_dir, subj, "mri/aseg.mgz")
    aseg_data = nib.load(aseg_file).get_data()
    aseg_data[aseg_data == 41] = 2
    mask_data = (aseg_data > 0).astype(int)

    # Load the lookup table for the aseg volume
    aseg_lut = np.genfromtxt(op.join(os.environ["FREESURFER_HOME"],
                                     "FreeSurferColorLUT.txt"))

    # Draw the brainmask and cortical ribbon
    m = Mosaic(brain_file, ribbon_data, mask_data, step=3)
    m.plot_mask("#C41E3A")
    m.savefig(op.join(data_dir, subj, "snapshots/volume.png"))
    m.close()

    # Draw the brainmask and cortical ribbon
    aseg_cmap = mpl.colors.ListedColormap(aseg_lut[:64, 2:5] / 255)
    m = Mosaic(brain_file, aseg_data, mask_data, step=3)
    m.plot_overlay(aseg_cmap, vmin=0, vmax=63, alpha=.75, colorbar=False)
    m.savefig(op.join(data_dir, subj, "snapshots/aseg.png"))
    m.close()
Example #30
0
 def plot_target(self):
     """Plot a mosaic of the motion correction target image."""
     m = Mosaic(self.inputs.target_file, step=1)
     return m
Example #31
0
def volume_images(data_dir, subj):
    """Plot a mosiac of the brainmask and aseg volumes."""
    # Plot the volume slices
    brain_file = op.join(data_dir, subj, "mri/brainmask.mgz")

    # Load the cortical ribbon file and use same index for both hemis
    ribbon_file = op.join(data_dir, subj, "mri/ribbon.mgz")
    ribbon_data = nib.load(ribbon_file).get_data().astype(float)
    ribbon_data[ribbon_data == 3] = 1
    ribbon_data[ribbon_data == 42] = 1
    ribbon_data[ribbon_data != 1] = np.nan

    # Load the aseg file and use it to derive a FOV mask
    aseg_file = op.join(data_dir, subj, "mri/aseg.mgz")
    aseg_data = nib.load(aseg_file).get_data()
    aseg_data[aseg_data == 41] = 2
    mask_data = (aseg_data > 0).astype(int)

    # Load the lookup table for the aseg volume
    aseg_lut = np.genfromtxt(
        op.join(os.environ["FREESURFER_HOME"], "FreeSurferColorLUT.txt"))

    # Draw the brainmask and cortical ribbon
    m = Mosaic(brain_file, ribbon_data, mask_data, step=3)
    m.plot_mask("#C41E3A")
    m.savefig(op.join(data_dir, subj, "snapshots/volume.png"))
    m.close()

    # Draw the brainmask and cortical ribbon
    aseg_cmap = mpl.colors.ListedColormap(aseg_lut[:64, 2:5] / 255)
    m = Mosaic(brain_file, aseg_data, mask_data, step=3)
    m.plot_overlay(aseg_cmap, vmin=0, vmax=63, alpha=.75, colorbar=False)
    m.savefig(op.join(data_dir, subj, "snapshots/aseg.png"))
    m.close()