Пример #1
0
    def validate_and_fix_input_data(self, path: Path) -> Tuple[Path, bool]:
        """
        Validate the provided data path and creates an unzipped version if
        required.

        Parameters
        ----------
        path : Path
            Path to input data

        Returns
        -------
        Tuple[Path, bool]
            Fixed input data path, whether is was unzipped or not
        """

        path = self.nifti_validator.validate_and_fix(path)

        # If the input is zipped, check for an existing unzipped version or
        # create one.
        if path.suffix == ".gz":
            # In case un unzipped version exists already, return the unzipped
            # version and 'False' for having created it.
            if path.with_suffix("").is_file():
                return path.with_suffix(""), False

            # Otherwise, create an unzipped version and return 'True' for
            # having created it.
            return uncompress(path), True
        return path, False
Пример #2
0
    def validate_and_fix_input_data(self, scans: List[Path]) -> List[Path]:
        """
        Validate the provided data path and creates an unzipped version if
        required.

        Parameters
        ----------
        path : List[Path]
            List of T1-weighted scan paths

        Returns
        -------
        List[tuple]
            List of tuples with shape (path string, created)
        """

        scans = [self.nifti_validator.validate_and_fix(path) for path in scans]

        results = []
        for path in scans:
            # If the input is zipped, check for an existing unzipped version or
            # create one.
            if path.suffix == ".gz":
                # In case un unzipped version exists already, return the
                # unzipped version and 'False' for having created it.
                if path.with_suffix("").is_file():
                    results.append((path.with_suffix(""), False))
                # Otherwise, create an unzipped version and return 'True' for
                # having created it.
                results.append(uncompress(path), True)
            else:
                results.append((path, False))
        return results
Пример #3
0
 def uncompress(self, keep_source: bool = False) -> Path:
     if self.is_compressed:
         compressed_path = Path(self.path)
         uncompressed_path = uncompress(compressed_path,
                                        keep_source=keep_source)
         self.path = str(uncompressed_path)
         self.save()
     return Path(self.path)
Пример #4
0
    def validate_and_fix_input_data(self, path: Path) -> tuple:
        # Validate configuration
        self.check_resampling_type()

        path = self.nifti_validator.validate_and_fix(path)

        # If the input is zipped, check for an existing unzipped version or create one
        if path.suffix == ".gz":
            # In case un unzipped version exists already, return the unzipped version
            # and 'False' for having created it
            if path.with_suffix("").is_file():
                return path.with_suffix(""), False

            # Otherwise, create an unzipped version and return 'True' for having created it
            return uncompress(path), True
        return path, False
Пример #5
0
    def uncompress(self, keep_source: bool = False) -> Path:
        """
        Uncompress the associated *.nii* using gzip, if it isn't already
        uncompressed.

        Parameters
        ----------
        keep_source : bool, optional
            Whether to keep a copy of the compressed file, by default False

        Returns
        -------
        Path
            Path of the uncompressed (*.nii*) file
        """
        if self.is_compressed:
            compressed_path = Path(self.path)
            uncompressed_path = uncompress(compressed_path,
                                           keep_source=keep_source)
            self.path = str(uncompressed_path)
            self.save()
        return Path(self.path)