How to use the niworkflows.NIWORKFLOWS_LOG.warning function in niworkflows

To help you get started, we’ve selected a few niworkflows examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github poldracklab / niworkflows / niworkflows / viz / utils.py View on Github external
current_palette = sns.color_palette()
    in_nii = nb.load(in_file)
    if not tr:
        tr = in_nii.header.get_zooms()[3]
        units = in_nii.header.get_xyzt_units()
        if units:
            if units[-1] == "msec":
                tr = tr / 1000.0
            elif units[-1] == "usec":
                tr = tr / 1000000.0
            elif units[-1] != "sec":
                NIWORKFLOWS_LOG.warning(
                    "Unknown repetition time units " "specified - assuming seconds"
                )
        else:
            NIWORKFLOWS_LOG.warning(
                "Repetition time units not specified - assuming seconds"
            )

    from nilearn.input_data import NiftiMasker
    from nilearn.plotting import cm

    if not report_mask:
        nifti_masker = NiftiMasker(mask_strategy="epi")
        nifti_masker.fit(index_img(in_nii, range(2)))
        mask_img = nifti_masker.mask_img_
    else:
        mask_img = nb.load(report_mask)

    mask_sl = []
    for j in range(3):
        mask_sl.append(transform_to_2d(mask_img.get_fdata(), j))
github poldracklab / niworkflows / niworkflows / viz / utils.py View on Github external
from matplotlib.gridspec import GridSpec
    import os

    sns.set_style("white")
    current_palette = sns.color_palette()
    in_nii = nb.load(in_file)
    if not tr:
        tr = in_nii.header.get_zooms()[3]
        units = in_nii.header.get_xyzt_units()
        if units:
            if units[-1] == "msec":
                tr = tr / 1000.0
            elif units[-1] == "usec":
                tr = tr / 1000000.0
            elif units[-1] != "sec":
                NIWORKFLOWS_LOG.warning(
                    "Unknown repetition time units " "specified - assuming seconds"
                )
        else:
            NIWORKFLOWS_LOG.warning(
                "Repetition time units not specified - assuming seconds"
            )

    from nilearn.input_data import NiftiMasker
    from nilearn.plotting import cm

    if not report_mask:
        nifti_masker = NiftiMasker(mask_strategy="epi")
        nifti_masker.fit(index_img(in_nii, range(2)))
        mask_img = nifti_masker.mask_img_
    else:
        mask_img = nb.load(report_mask)
github poldracklab / niworkflows / niworkflows / interfaces / mni.py View on Github external
NIWORKFLOWS_LOG.info("Retry #%d, commandline: \n%s", self.retry, cmd)
            self.norm.ignore_exception = True
            with open("command.txt", "w") as cmdfile:
                print(cmd + "\n", file=cmdfile)

            # Try running registration.
            interface_result = self.norm.run()

            if interface_result.runtime.returncode != 0:
                NIWORKFLOWS_LOG.warning("Retry #%d failed.", self.retry)
                # Save outputs (if available)
                term_out = _write_outputs(
                    interface_result.runtime, ".nipype-%04d" % self.retry
                )
                if term_out:
                    NIWORKFLOWS_LOG.warning(
                        "Log of failed retry saved (%s).", ", ".join(term_out)
                    )
            else:
                runtime.returncode = 0
                # Note this in the log.
                NIWORKFLOWS_LOG.info(
                    "Successful spatial normalization (retry #%d).", self.retry
                )
                # Break out of the retry loop.
                return runtime

            self.retry += 1

        # If all tries fail, raise an error.
        raise RuntimeError(
            "Robust spatial normalization failed after %d retries." % (self.retry - 1)
github poldracklab / niworkflows / niworkflows / interfaces / segmentation.py View on Github external
NIWORKFLOWS_LOG.info("Generating report for MELODIC.")
        _melodic_dir = runtime.cwd
        if isdefined(self.inputs.out_dir):
            _melodic_dir = self.inputs.out_dir
        self._melodic_dir = os.path.abspath(_melodic_dir)

        self._out_report = self.inputs.out_report
        if not os.path.isabs(self._out_report):
            self._out_report = os.path.abspath(
                os.path.join(runtime.cwd, self._out_report)
            )

        mix = os.path.join(self._melodic_dir, "melodic_mix")
        if not os.path.exists(mix):
            NIWORKFLOWS_LOG.warning(
                "MELODIC outputs not found, assuming it didn't converge."
            )
            self._out_report = self._out_report.replace(".svg", ".html")
            snippet = "<h4>MELODIC did not converge, no output</h4>"
            with open(self._out_report, "w") as fobj:
                fobj.write(snippet)
            return runtime

        self._generate_report()
        return runtime
github poldracklab / niworkflows / niworkflows / interfaces / mni.py View on Github external
if self.inputs.orientation == "LAS":
                raise NotImplementedError

            template_spec = (
                self.inputs.template_spec
                if isdefined(self.inputs.template_spec)
                else {}
            )

            default_resolution = {"precise": 1, "fast": 2, "testing": 2}[
                self.inputs.flavor
            ]

            # Set the template resolution.
            if isdefined(self.inputs.template_resolution):
                NIWORKFLOWS_LOG.warning(
                    "The use of ``template_resolution`` is deprecated"
                )
                template_spec["res"] = self.inputs.template_resolution

            template_spec["suffix"] = self.inputs.reference
            template_spec["desc"] = None
            ref_template, template_spec = get_template_specs(
                self.inputs.template,
                template_spec=template_spec,
                default_resolution=default_resolution,
            )

            # Set reference image
            self._reference_image = ref_template
            if not op.isfile(self._reference_image):
                raise ValueError(
github poldracklab / niworkflows / niworkflows / interfaces / mni.py View on Github external
self.norm = Registration(from_file=ants_settings, **ants_args)
            self.norm.resource_monitor = False
            self.norm.terminal_output = self.terminal_output

            cmd = self.norm.cmdline
            # Print the retry number and command line call to the log.
            NIWORKFLOWS_LOG.info("Retry #%d, commandline: \n%s", self.retry, cmd)
            self.norm.ignore_exception = True
            with open("command.txt", "w") as cmdfile:
                print(cmd + "\n", file=cmdfile)

            # Try running registration.
            interface_result = self.norm.run()

            if interface_result.runtime.returncode != 0:
                NIWORKFLOWS_LOG.warning("Retry #%d failed.", self.retry)
                # Save outputs (if available)
                term_out = _write_outputs(
                    interface_result.runtime, ".nipype-%04d" % self.retry
                )
                if term_out:
                    NIWORKFLOWS_LOG.warning(
                        "Log of failed retry saved (%s).", ", ".join(term_out)
                    )
            else:
                runtime.returncode = 0
                # Note this in the log.
                NIWORKFLOWS_LOG.info(
                    "Successful spatial normalization (retry #%d).", self.retry
                )
                # Break out of the retry loop.
                return runtime
github poldracklab / niworkflows / niworkflows / interfaces / mni.py View on Github external
in_file and lesion_mask must be in the same
    image space and have the same dimensions

    """
    import os
    import numpy as np
    import nibabel as nb
    from nipype.utils.filemanip import fname_presuffix

    if out_path is None:
        out_path = fname_presuffix(in_file, suffix="_cfm", newpath=os.getcwd())
    else:
        out_path = os.path.abspath(out_path)

    if not global_mask and not lesion_mask:
        NIWORKFLOWS_LOG.warning(
            "No lesion mask was provided and global_mask not requested, "
            "therefore the original mask will not be modified."
        )

    # Load the input image
    in_img = nb.load(in_file)

    # If we want a global mask, create one based on the input image.
    data = (
        np.ones(in_img.shape, dtype=np.uint8)
        if global_mask
        else np.asanyarray(in_img.dataobj)
    )
    if set(np.unique(data)) - {0, 1}:
        raise ValueError("`global_mask` must be true if `in_file` is not a binary mask")