Esempio n. 1
0
    def _run_interface(self, runtime):
        # Get the mean EPI data and get it ready
        epinii = nb.load(self.inputs.in_epi)
        epidata = np.nan_to_num(epinii.get_data())
        epidata = epidata.astype(np.float32)
        epidata[epidata < 0] = 0

        # Get EPI data (with mc done) and get it ready
        hmcnii = nb.load(self.inputs.in_hmc)
        hmcdata = np.nan_to_num(hmcnii.get_data())
        hmcdata = hmcdata.astype(np.float32)
        hmcdata[hmcdata < 0] = 0

        # Get brain mask data
        msknii = nb.load(self.inputs.in_mask)
        mskdata = np.asanyarray(msknii.dataobj) > 0
        mskdata = mskdata.astype(np.uint8)
        if np.sum(mskdata) < 100:
            raise RuntimeError(
                "Detected less than 100 voxels belonging to the brain mask. "
                "MRIQC failed to process this dataset.")

        # Summary stats
        stats = summary_stats(epidata, mskdata, erode=True)
        self._results["summary"] = stats

        # SNR
        self._results["snr"] = snr(stats["fg"]["median"], stats["fg"]["stdv"],
                                   stats["fg"]["n"])
        # FBER
        self._results["fber"] = fber(epidata, mskdata)
        # EFC
        self._results["efc"] = efc(epidata)
        # GSR
        self._results["gsr"] = {}
        if self.inputs.direction == "all":
            epidir = ["x", "y"]
        else:
            epidir = [self.inputs.direction]

        for axis in epidir:
            self._results["gsr"][axis] = gsr(epidata, mskdata, direction=axis)

        # DVARS
        dvars_avg = np.loadtxt(self.inputs.in_dvars,
                               skiprows=1,
                               usecols=list(range(3))).mean(axis=0)
        dvars_col = ["std", "nstd", "vstd"]
        self._results["dvars"] = {
            key: float(val)
            for key, val in zip(dvars_col, dvars_avg)
        }

        # tSNR
        tsnr_data = nb.load(self.inputs.in_tsnr).get_data()
        self._results["tsnr"] = float(np.median(tsnr_data[mskdata > 0]))

        # FD
        fd_data = np.loadtxt(self.inputs.in_fd, skiprows=1)
        num_fd = np.float((fd_data > self.inputs.fd_thres).sum())
        self._results["fd"] = {
            "mean": float(fd_data.mean()),
            "num": int(num_fd),
            "perc": float(num_fd * 100 / (len(fd_data) + 1)),
        }

        # FWHM
        fwhm = np.array(self.inputs.in_fwhm[:3]) / np.array(
            hmcnii.header.get_zooms()[:3])
        self._results["fwhm"] = {
            "x": float(fwhm[0]),
            "y": float(fwhm[1]),
            "z": float(fwhm[2]),
            "avg": float(np.average(fwhm)),
        }

        # Image specs
        self._results["size"] = {
            "x": int(hmcdata.shape[0]),
            "y": int(hmcdata.shape[1]),
            "z": int(hmcdata.shape[2]),
        }
        self._results["spacing"] = {
            i: float(v)
            for i, v in zip(["x", "y", "z"],
                            hmcnii.header.get_zooms()[:3])
        }

        try:
            self._results["size"]["t"] = int(hmcdata.shape[3])
        except IndexError:
            pass

        try:
            self._results["spacing"]["tr"] = float(
                hmcnii.header.get_zooms()[3])
        except IndexError:
            pass

        self._results["out_qc"] = _flatten_dict(self._results)
        return runtime
Esempio n. 2
0
    def _run_interface(self, runtime):
        # Get the mean EPI data and get it ready
        epinii = nb.load(self.inputs.in_epi)
        epidata = np.nan_to_num(epinii.get_data())
        epidata = epidata.astype(np.float32)
        epidata[epidata < 0] = 0

        # Get EPI data (with mc done) and get it ready
        hmcnii = nb.load(self.inputs.in_hmc)
        hmcdata = np.nan_to_num(hmcnii.get_data())
        hmcdata = hmcdata.astype(np.float32)
        hmcdata[hmcdata < 0] = 0

        # Get EPI data (with mc done) and get it ready
        msknii = nb.load(self.inputs.in_mask)
        mskdata = np.nan_to_num(msknii.get_data())
        mskdata = mskdata.astype(np.uint8)
        mskdata[mskdata < 0] = 0
        mskdata[mskdata > 0] = 1

        # SNR
        self._results['snr'] = float(snr(epidata, mskdata, fglabel=1))
        # FBER
        self._results['fber'] = fber(epidata, mskdata)
        # EFC
        self._results['efc'] = efc(epidata)
        # GSR
        self._results['gsr'] = {}
        if self.inputs.direction == 'all':
            epidir = ['x', 'y']
        else:
            epidir = [self.inputs.direction]

        for axis in epidir:
            self._results['gsr'][axis] = gsr(epidata, mskdata, direction=axis)

        # Summary stats
        mean, stdv, p95, p05 = summary_stats(epidata, mskdata)
        self._results['summary'] = {'mean': mean,
                                    'stdv': stdv,
                                    'p95': p95,
                                    'p05': p05}

        # DVARS
        self._results['dvars'] = float(np.loadtxt(
            self.inputs.in_dvars).mean())

        # tSNR
        tsnr_data = nb.load(self.inputs.in_tsnr).get_data()
        self._results['m_tsnr'] = float(np.median(tsnr_data[mskdata > 0]))

        # GCOR
        self._results['gcor'] = gcor(hmcdata, mskdata)

        # FD
        self._results['fd_stats'] = summary_fd(self.inputs.fd_movpar)

        # Image specs
        self._results['size'] = {'x': int(hmcdata.shape[0]),
                                 'y': int(hmcdata.shape[1]),
                                 'z': int(hmcdata.shape[2])}
        self._results['spacing'] = {
            i: float(v) for i, v in zip(['x', 'y', 'z'],
                                        hmcnii.get_header().get_zooms()[:3])}

        try:
            self._results['size']['t'] = int(hmcdata.shape[3])
        except IndexError:
            pass

        try:
            self._results['spacing']['tr'] = float(hmcnii.get_header().get_zooms()[3])
        except IndexError:
            pass

        self._results['out_qc'] = _flatten_dict(self._results)
        return runtime
Esempio n. 3
0
    def _run_interface(self, runtime):
        # Get the mean EPI data and get it ready
        epinii = nb.load(self.inputs.in_epi)
        epidata = np.nan_to_num(epinii.get_data())
        epidata = epidata.astype(np.float32)
        epidata[epidata < 0] = 0

        # Get EPI data (with mc done) and get it ready
        hmcnii = nb.load(self.inputs.in_hmc)
        hmcdata = np.nan_to_num(hmcnii.get_data())
        hmcdata = hmcdata.astype(np.float32)
        hmcdata[hmcdata < 0] = 0

        # Get EPI data (with mc done) and get it ready
        msknii = nb.load(self.inputs.in_mask)
        mskdata = np.nan_to_num(msknii.get_data())
        mskdata = mskdata.astype(np.uint8)
        mskdata[mskdata < 0] = 0
        mskdata[mskdata > 0] = 1

        # SNR
        self._results['snr'] = float(snr(epidata, mskdata, fglabel=1))
        # FBER
        self._results['fber'] = fber(epidata, mskdata)
        # EFC
        self._results['efc'] = efc(epidata)
        # GSR
        self._results['gsr'] = {}
        if self.inputs.direction == 'all':
            epidir = ['x', 'y']
        else:
            epidir = [self.inputs.direction]

        for axis in epidir:
            self._results['gsr'][axis] = gsr(epidata, mskdata, direction=axis)

        # Summary stats
        self._results['summary'] = summary_stats(epidata, mskdata)

        # DVARS
        dvars_avg = np.loadtxt(self.inputs.in_dvars,
                               skiprows=1,
                               usecols=list(range(3))).mean(axis=0)
        dvars_col = ['std', 'nstd', 'vstd']
        self._results['dvars'] = {
            key: float(val)
            for key, val in zip(dvars_col, dvars_avg)
        }

        # tSNR
        tsnr_data = nb.load(self.inputs.in_tsnr).get_data()
        self._results['tsnr'] = float(np.median(tsnr_data[mskdata > 0]))

        # GCOR
        self._results['gcor'] = gcor(hmcdata, mskdata)

        # FD
        fd_data = np.loadtxt(self.inputs.in_fd, skiprows=1)
        num_fd = np.float((fd_data > self.inputs.fd_thres).sum())
        self._results['fd'] = {
            'mean': float(fd_data.mean()),
            'num': int(num_fd),
            'perc': float(num_fd * 100 / (len(fd_data) + 1))
        }

        # FWHM
        fwhm = np.array(self.inputs.in_fwhm[:3]) / np.array(
            hmcnii.get_header().get_zooms()[:3])
        self._results['fwhm'] = {
            'x': float(fwhm[0]),
            'y': float(fwhm[1]),
            'z': float(fwhm[2]),
            'avg': float(np.average(fwhm))
        }

        # Image specs
        self._results['size'] = {
            'x': int(hmcdata.shape[0]),
            'y': int(hmcdata.shape[1]),
            'z': int(hmcdata.shape[2])
        }
        self._results['spacing'] = {
            i: float(v)
            for i, v in zip(['x', 'y', 'z'],
                            hmcnii.get_header().get_zooms()[:3])
        }

        try:
            self._results['size']['t'] = int(hmcdata.shape[3])
        except IndexError:
            pass

        try:
            self._results['spacing']['tr'] = float(
                hmcnii.get_header().get_zooms()[3])
        except IndexError:
            pass

        self._results['out_qc'] = _flatten_dict(self._results)
        return runtime
Esempio n. 4
0
    def _run_interface(self, runtime):
        # Get the mean EPI data and get it ready
        epinii = nb.load(self.inputs.in_epi)
        epidata = np.nan_to_num(epinii.get_data())
        epidata = epidata.astype(np.float32)
        epidata[epidata < 0] = 0

        # Get EPI data (with mc done) and get it ready
        hmcnii = nb.load(self.inputs.in_hmc)
        hmcdata = np.nan_to_num(hmcnii.get_data())
        hmcdata = hmcdata.astype(np.float32)
        hmcdata[hmcdata < 0] = 0

        # Get EPI data (with mc done) and get it ready
        msknii = nb.load(self.inputs.in_mask)
        mskdata = np.nan_to_num(msknii.get_data())
        mskdata = mskdata.astype(np.uint8)
        mskdata[mskdata < 0] = 0
        mskdata[mskdata > 0] = 1

        # SNR
        self._results["snr"] = float(snr(epidata, mskdata, fglabel=1))
        # FBER
        self._results["fber"] = fber(epidata, mskdata)
        # EFC
        self._results["efc"] = efc(epidata)
        # GSR
        self._results["gsr"] = {}
        if self.inputs.direction == "all":
            epidir = ["x", "y"]
        else:
            epidir = [self.inputs.direction]

        for axis in epidir:
            self._results["gsr"][axis] = gsr(epidata, mskdata, direction=axis)

        # Summary stats
        mean, stdv, p95, p05 = summary_stats(epidata, mskdata)
        self._results["summary"] = {"mean": mean, "stdv": stdv, "p95": p95, "p05": p05}

        # DVARS
        dvars_avg = np.loadtxt(self.inputs.in_dvars).mean(axis=0)
        dvars_col = ["std", "nstd", "vstd"]
        self._results["dvars"] = {dvars_col[i]: float(val) for i, val in enumerate(dvars_avg)}

        # tSNR
        tsnr_data = nb.load(self.inputs.in_tsnr).get_data()
        self._results["m_tsnr"] = float(np.median(tsnr_data[mskdata > 0]))

        # GCOR
        self._results["gcor"] = gcor(hmcdata, mskdata)

        # FD
        fd_data = np.loadtxt(self.inputs.in_fd)
        num_fd = np.float((fd_data > self.inputs.fd_thres).sum())
        self._results["fd"] = {
            "mean": float(fd_data.mean()),
            "num": int(num_fd),
            "perc": float(num_fd * 100 / (len(fd_data) + 1)),
        }

        # Image specs
        self._results["size"] = {"x": int(hmcdata.shape[0]), "y": int(hmcdata.shape[1]), "z": int(hmcdata.shape[2])}
        self._results["spacing"] = {i: float(v) for i, v in zip(["x", "y", "z"], hmcnii.get_header().get_zooms()[:3])}

        try:
            self._results["size"]["t"] = int(hmcdata.shape[3])
        except IndexError:
            pass

        try:
            self._results["spacing"]["tr"] = float(hmcnii.get_header().get_zooms()[3])
        except IndexError:
            pass

        self._results["out_qc"] = _flatten_dict(self._results)
        return runtime