Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from seaborn import color_palette
from .. import NIWORKFLOWS_LOG
from . import report_base as nrc
class _BETInputSpecRPT(nrc._SVGReportCapableInputSpec, fsl.preprocess.BETInputSpec):
pass
class _BETOutputSpecRPT(
reporting.ReportCapableOutputSpec, fsl.preprocess.BETOutputSpec
):
pass
class BETRPT(nrc.SegmentationRC, fsl.BET):
input_spec = _BETInputSpecRPT
output_spec = _BETOutputSpecRPT
def _run_interface(self, runtime):
if self.generate_report:
self.inputs.mask = True
return super(BETRPT, self)._run_interface(runtime)
def _post_run_hook(self, runtime):
""" generates a report showing slices from each axis of an arbitrary
volume of in_file, with the resulting binary brain mask overlaid """
self._anat_file = self.inputs.in_file
self._mask_file = self.aggregate_outputs(runtime=runtime).mask_file
self._seg_files = [self._mask_file]
from nipype.interfaces.mixins import reporting
from . import report_base as nrc
from .. import NIWORKFLOWS_LOG
class _FASTInputSpecRPT(nrc._SVGReportCapableInputSpec, fsl.preprocess.FASTInputSpec):
pass
class _FASTOutputSpecRPT(
reporting.ReportCapableOutputSpec, fsl.preprocess.FASTOutputSpec
):
pass
class FASTRPT(nrc.SegmentationRC, fsl.FAST):
input_spec = _FASTInputSpecRPT
output_spec = _FASTOutputSpecRPT
def _run_interface(self, runtime):
if self.generate_report:
self.inputs.segments = True
return super(FASTRPT, self)._run_interface(runtime)
def _post_run_hook(self, runtime):
""" generates a report showing nine slices, three per axis, of an
arbitrary volume of `in_files`, with the resulting segmentation
overlaid """
self._anat_file = self.inputs.in_files[0]
outputs = self.aggregate_outputs(runtime=runtime)
self._mask_file = outputs.tissue_class_map
)
return super(BrainExtractionRPT, self)._post_run_hook(runtime)
# TODO: move this interface to nipype.interfaces.nilearn
class _ComputeEPIMaskInputSpec(nrc._SVGReportCapableInputSpec, BaseInterfaceInputSpec):
in_file = File(exists=True, desc="3D or 4D EPI file")
dilation = traits.Int(desc="binary dilation on the nilearn output")
class _ComputeEPIMaskOutputSpec(reporting.ReportCapableOutputSpec):
mask_file = File(exists=True, desc="Binary brain mask")
class ComputeEPIMask(nrc.SegmentationRC):
input_spec = _ComputeEPIMaskInputSpec
output_spec = _ComputeEPIMaskOutputSpec
def _run_interface(self, runtime):
orig_file_nii = nb.load(self.inputs.in_file)
in_file_data = orig_file_nii.get_fdata()
# pad the data to avoid the mask estimation running into edge effects
in_file_data_padded = np.pad(
in_file_data, (1, 1), "constant", constant_values=(0, 0)
)
padded_nii = nb.Nifti1Image(
in_file_data_padded, orig_file_nii.affine, orig_file_nii.header
)
return super(ACompCorRPT, self)._post_run_hook(runtime)
class _TCompCorInputSpecRPT(
nrc._SVGReportCapableInputSpec, confounds.TCompCorInputSpec
):
pass
class _TCompCorOutputSpecRPT(
reporting.ReportCapableOutputSpec, confounds.TCompCorOutputSpec
):
pass
class TCompCorRPT(nrc.SegmentationRC, confounds.TCompCor):
input_spec = _TCompCorInputSpecRPT
output_spec = _TCompCorOutputSpecRPT
def _post_run_hook(self, runtime):
""" generates a report showing slices from each axis """
high_variance_masks = self.aggregate_outputs(
runtime=runtime
).high_variance_masks
if isinstance(high_variance_masks, list):
raise ValueError(
"TCompCorRPT only supports a single output high variance mask. "
"A list %s was found." % high_variance_masks
)
self._anat_file = self.inputs.realigned_file
return super(BETRPT, self)._post_run_hook(runtime)
class _BrainExtractionInputSpecRPT(
nrc._SVGReportCapableInputSpec, ants.segmentation.BrainExtractionInputSpec
):
pass
class _BrainExtractionOutputSpecRPT(
reporting.ReportCapableOutputSpec, ants.segmentation.BrainExtractionOutputSpec
):
pass
class BrainExtractionRPT(nrc.SegmentationRC, ants.segmentation.BrainExtraction):
input_spec = _BrainExtractionInputSpecRPT
output_spec = _BrainExtractionOutputSpecRPT
def _post_run_hook(self, runtime):
""" generates a report showing slices from each axis """
brain_extraction_mask = self.aggregate_outputs(
runtime=runtime
).BrainExtractionMask
if (
isdefined(self.inputs.keep_temporary_files)
and self.inputs.keep_temporary_files == 1
):
self._anat_file = self.aggregate_outputs(runtime=runtime).N4Corrected0
else:
)
return super(ComputeEPIMask, self)._post_run_hook(runtime)
class _ACompCorInputSpecRPT(nrc._SVGReportCapableInputSpec, confounds.CompCorInputSpec):
pass
class _ACompCorOutputSpecRPT(
reporting.ReportCapableOutputSpec, confounds.CompCorOutputSpec
):
pass
class ACompCorRPT(nrc.SegmentationRC, confounds.ACompCor):
input_spec = _ACompCorInputSpecRPT
output_spec = _ACompCorOutputSpecRPT
def _post_run_hook(self, runtime):
""" generates a report showing slices from each axis """
if len(self.inputs.mask_files) != 1:
raise ValueError(
"ACompCorRPT only supports a single input mask. "
"A list %s was found." % self.inputs.mask_files
)
self._anat_file = self.inputs.realigned_file
self._mask_file = self.inputs.mask_files[0]
self._seg_files = self.inputs.mask_files
self._masked = False
NIWORKFLOWS_LOG.info(
'Generating report for tCompCor. file "%s", mask "%s"',
self.inputs.realigned_file,
self.aggregate_outputs(runtime=runtime).high_variance_masks,
)
return super(TCompCorRPT, self)._post_run_hook(runtime)
class _SimpleShowMaskInputSpec(nrc._SVGReportCapableInputSpec):
background_file = File(exists=True, mandatory=True, desc="file before")
mask_file = File(exists=True, mandatory=True, desc="file before")
class SimpleShowMaskRPT(nrc.SegmentationRC, nrc.ReportingInterface):
input_spec = _SimpleShowMaskInputSpec
def _post_run_hook(self, runtime):
self._anat_file = self.inputs.background_file
self._mask_file = self.inputs.mask_file
self._seg_files = [self.inputs.mask_file]
self._masked = True
return super(SimpleShowMaskRPT, self)._post_run_hook(runtime)
class _ROIsPlotInputSpecRPT(nrc._SVGReportCapableInputSpec):
in_file = File(
exists=True, mandatory=True, desc="the volume where ROIs are defined"
)
in_rois = InputMultiPath(