<commit_before>from __future__ import division

'''
Preproc Nipype Interfaces
=========================

Classes for various nipype interfaces

'''

__all__ = ['Plot_Coregistration_Montage', 'Plot_Realignment_Parameters', 'Create_Covariates', 'Down_Sample_Precision','Low_Pass_Filter']
__author__ = ["<NAME>"]
__license__ = "MIT"

import matplotlib
matplotlib.use('Agg')
import pandas as pd
import numpy as np
#import pylab as plt
import os
import nibabel as nib
from nipype.interfaces.base import isdefined, BaseInterface, TraitedSpec, File, traits
from nilearn import plotting, image
#from nltools.data import Brain_Data

class Plot_Coregistration_Montage_InputSpec(TraitedSpec):
    wra_img = File(exists=True, mandatory=True)
    canonical_img = File(exists=True, mandatory=True)
    title = traits.Str("Normalized Functional Check", usedefault=True)

class Plot_Coregistration_Montage_OutputSpec(TraitedSpec):
    plot = File(exists=True)

class Plot_Coregistration_Montage(BaseInterface):
    # This function creates an axial montage of the average normalized functional data
    # and overlays outline of the normalized single subject overlay.
    # Could probably pick a better overlay later.

    input_spec = Plot_Coregistration_Montage_InputSpec
    output_spec = Plot_Coregistration_Montage_OutputSpec

    def _run_interface(self, runtime):
    	import matplotlib
    	matplotlib.use('Agg')
    	import pylab as plt

    	wra_img = nib.load(self.inputs.wra_img)
    	canonical_img = nib.load(self.inputs.canonical_img)
    	title = self.inputs.title
    	mean_wraimg = image.mean_img(wra_img)

    	if title != "":
    		filename = title.replace(" ", "_")+".pdf"
    	else:
    		filename = "plot.pdf"

    	# fig = plotting.plot_anat(mean_wraimg, title="wrafunc & canonical single subject", cut_coords=range(-40, 40, 10), display_mode='z')
    	# fig.add_edges(canonical_img)
    	# fig.savefig(filename)
    	# fig.close()

    	#JC: Added Saggital slice plotting
    	f, (ax1, ax2) = plt.subplots(2,figsize=(15,8))
    	fig = plotting.plot_anat(mean_wraimg, title="sag: wrafunc & canonical single subject", cut_coords=range(-30, 20, 8), display_mode='x',axes=ax1)
    	fig.add_edges(canonical_img)
    	fig = plotting.plot_anat(mean_wraimg, title="axial: wrafunc & canonical single subject", cut_coords=range(-40, 40, 10), display_mode='z',axes=ax2)
    	fig.add_edges(canonical_img)
    	f.savefig(filename)
    	plt.close(f) #f.close()
    	plt.close()
    	del f
    	self._plot = filename
    	runtime.returncode=0
    	return runtime

    def _list_outputs(self):
    	outputs = self._outputs().get()
    	outputs["plot"] = os.path.abspath(self._plot)
    	return outputs
<commit_msg>added coronal slice to coreg/norm check plot+more slices<commit_after>from __future__ import division

'''
Preproc Nipype Interfaces
=========================

Classes for various nipype interfaces

'''

__all__ = ['Plot_Coregistration_Montage', 'Plot_Realignment_Parameters', 'Create_Covariates', 'Down_Sample_Precision','Low_Pass_Filter']
__author__ = ["<NAME>"]
__license__ = "MIT"

import matplotlib
matplotlib.use('Agg')
import pandas as pd
import numpy as np
#import pylab as plt
import os
import nibabel as nib
from nipype.interfaces.base import isdefined, BaseInterface, TraitedSpec, File, traits
from nilearn import plotting, image
#from nltools.data import Brain_Data

class Plot_Coregistration_Montage_InputSpec(TraitedSpec):
    wra_img = File(exists=True, mandatory=True)
    canonical_img = File(exists=True, mandatory=True)
    title = traits.Str("Normalized Functional Check", usedefault=True)

class Plot_Coregistration_Montage_OutputSpec(TraitedSpec):
    plot = File(exists=True)

class Plot_Coregistration_Montage(BaseInterface):
    # This function creates an axial montage of the average normalized functional data
    # and overlays outline of the normalized single subject overlay.
    # Could probably pick a better overlay later.

    input_spec = Plot_Coregistration_Montage_InputSpec
    output_spec = Plot_Coregistration_Montage_OutputSpec

    def _run_interface(self, runtime):
    	import matplotlib
    	matplotlib.use('Agg')
    	import pylab as plt

    	wra_img = nib.load(self.inputs.wra_img)
    	canonical_img = nib.load(self.inputs.canonical_img)
    	title = self.inputs.title
    	mean_wraimg = image.mean_img(wra_img)

    	if title != "":
    		filename = title.replace(" ", "_")+".pdf"
    	else:
    		filename = "plot.pdf"

    	# fig = plotting.plot_anat(mean_wraimg, title="wrafunc & canonical single subject", cut_coords=range(-40, 40, 10), display_mode='z')
    	# fig.add_edges(canonical_img)
    	# fig.savefig(filename)
    	# fig.close()

    	#JC: Added Saggital slice plotting
        f, axes = plt.subplots(6,figsize=(15,20))
        titles = ["sag: wrafunc & canonical single subject","sag: wrafunc & canonical single subject",
        "axial: wrafunc & canonical single subject","axial: wrafunc & canonical single subject",
        "coronal: wrafunc & canonical single subject","coronal: wrafunc & canonical single subject"
        ]
        cut_coords = [range(-50, 0, 10), range(0, 51, 10),range(-30, 15, 9),range(0, 61, 10), range(-60, 0, 12), range(0, 31, 6)  ]
        display_modes = ['x','x','z','z','y','y']
        for i, ax in enumerate(axes): 
            fig = plotting.plot_anat(mean_wraimg, title = titles[i], cut_coords = cut_coords[i], display_mode =display_modes[i],axes = ax)
            fig.add_edges(canonical_img)
    	# f, (ax1, ax2) = plt.subplots(2,figsize=(15,8))        
    	# fig = plotting.plot_anat(mean_wraimg, title="sag: wrafunc & canonical single subject", cut_coords=range(-30, 20, 8), display_mode='x',axes=ax1)
    	# fig.add_edges(canonical_img)
    	# fig = plotting.plot_anat(mean_wraimg, title="axial: wrafunc & canonical single subject", cut_coords=range(-40, 40, 10), display_mode='z',axes=ax2)
    	# fig.add_edges(canonical_img)
    	f.savefig(filename)
    	plt.close(f) #f.close()
    	plt.close()
    	del f
    	self._plot = filename
    	runtime.returncode=0
    	return runtime

    def _list_outputs(self):
    	outputs = self._outputs().get()
    	outputs["plot"] = os.path.abspath(self._plot)
    	return outputs

{'fraction_non_alphanumeric': 0.11826059050064185, 'fraction_numerical': 0.0137997432605905, 'mean_word_length': 4.215899581589958, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3602928', 'n_tokens_mistral': 2201, 'n_tokens_neox': 2039, 'n_words': 474}