Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ jobs:
--log-errors
--latest
- name: Upload MRtrix3 install
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: MRtrix3
path: ${{ env.MRTRIX_INSTALL}}
- name: Upload auto-gen pydra
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: AutoGen
path: pydra/tasks/mrtrix3/${{ env.SUBPKG_NAME }}
- name: Write version file
run: echo $MRTRIX_VERSION > mrtrix3_version.txt
- name: Upload version file
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: VersionFile
path: mrtrix3_version.txt
Expand Down Expand Up @@ -352,7 +352,7 @@ jobs:
git tag -d ${{ steps.latest_tag.outputs.TAG }};
git tag -a ${{ steps.latest_tag.outputs.TAG }} -m"Tag used to create a pydra-mrtrix3 $MRTRIX_VERSION release";
- name: Set up Python 3.11
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: 3.11
- name: Install build tools
Expand All @@ -362,7 +362,7 @@ jobs:
- name: Check distributions
run: twine check dist/*
- name: Upload sdist
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: SDist
path: dist/*.tar.gz
Expand Down
8 changes: 5 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import typing as ty
import pytest
from pathlib import Path

Expand All @@ -22,9 +23,10 @@ def cli_parse_only():
if os.getenv("_PYTEST_RAISE", "0") != "0":

@pytest.hookimpl(tryfirst=True)
def pytest_exception_interact(call):
raise call.excinfo.value
def pytest_exception_interact(call: pytest.CallInfo[ty.Any]) -> None:
if call.excinfo is not None:
raise call.excinfo.value

@pytest.hookimpl(tryfirst=True)
def pytest_internalerror(excinfo):
def pytest_internalerror(excinfo: pytest.ExceptionInfo[BaseException]) -> None:
raise excinfo.value
8 changes: 5 additions & 3 deletions related-packages/fileformats-extras/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from pathlib import Path
import tempfile
import typing as ty
import pytest
from fileformats.medimage import DicomDir, Nifti

Expand All @@ -24,11 +25,12 @@
if os.getenv("_PYTEST_RAISE", "0") != "0":

@pytest.hookimpl(tryfirst=True)
def pytest_exception_interact(call):
raise call.excinfo.value
def pytest_exception_interact(call: pytest.CallInfo[ty.Any]) -> None:
if call.excinfo is not None:
raise call.excinfo.value

@pytest.hookimpl(tryfirst=True)
def pytest_internalerror(excinfo):
def pytest_internalerror(excinfo: pytest.ExceptionInfo[BaseException]) -> None:
raise excinfo.value


Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import numpy as np
import typing # noqa: F401
import numpy.typing
from fileformats.core import extra_implementation
from fileformats.medimage import DwiEncoding
from fileformats.medimage.diffusion import EncodingArrayType
from fileformats.medimage_mrtrix3 import BFile


@extra_implementation(DwiEncoding.read_array)
def bfile_read_array(bfile: BFile) -> np.ndarray:
return np.asarray(
def bfile_read_array(
bfile: BFile,
) -> EncodingArrayType:
return numpy.asarray(
[[float(x) for x in ln.split()] for ln in bfile.read_contents().splitlines()]
)
8 changes: 5 additions & 3 deletions related-packages/fileformats/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import logging
import typing as ty
from pathlib import Path
import tempfile
import pytest
Expand All @@ -23,11 +24,12 @@
if os.getenv("_PYTEST_RAISE", "0") != "0":

@pytest.hookimpl(tryfirst=True)
def pytest_exception_interact(call):
raise call.excinfo.value
def pytest_exception_interact(call: pytest.CallInfo[ty.Any]) -> None:
if call.excinfo is not None:
raise call.excinfo.value

@pytest.hookimpl(tryfirst=True)
def pytest_internalerror(excinfo):
def pytest_internalerror(excinfo: pytest.ExceptionInfo[BaseException]) -> None:
raise excinfo.value


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from fileformats.core import validated_property
from fileformats.core.mixin import WithAdjacentFiles
from fileformats.medimage import DwiEncoding, Nifti1, NiftiGz, NiftiX, NiftiGzX
from .image import ImageFormat, ImageHeader, ImageFormatGz
Expand All @@ -11,7 +12,7 @@ class BFile(DwiEncoding):

# NIfTI file format gzipped with BIDS side car
class WithBFile(WithAdjacentFiles):
@property
@validated_property
def encoding(self) -> BFile:
return BFile(self.select_by_ext(BFile))

Expand Down
20 changes: 9 additions & 11 deletions related-packages/fileformats/fileformats/medimage_mrtrix3/image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
import typing as ty
from fileformats.core import FileSet, extra_implementation
from fileformats.generic import File
from fileformats.core import FileSet, extra_implementation, validated_property
from fileformats.generic import BinaryFile
from fileformats.application.archive import BaseGzip
from fileformats.core.mixin import WithMagicNumber
from fileformats.core.exceptions import FormatMismatchError
Expand All @@ -12,12 +12,12 @@ class MultiLineMetadataValue(list):
pass


class BaseMrtrixImage(WithMagicNumber, fileformats.medimage.MedicalImage, File):
class BaseMrtrixImage(WithMagicNumber, fileformats.medimage.MedicalImage, BinaryFile):

magic_number = b"mrtrix image\n"
binary = True

@property
@validated_property
def data_fspath(self):
data_fspath = self.metadata["file"].split()[0]
if data_fspath == ".":
Expand Down Expand Up @@ -48,8 +48,8 @@ class ImageFormat(BaseMrtrixImage):
ext = ".mif"
iana_mime = "application/x-mrtrix-image-format"

@property
def check_data_file(self):
@validated_property
def _check_data_file(self):
if self.data_fspath != self.fspath:
raise FormatMismatchError(
f"Data file ('{self.data_fspath}') is not set to the same file as header "
Expand All @@ -73,7 +73,7 @@ class ImageHeader(BaseMrtrixImage):
ext = ".mih"
iana_mime = "application/x-mrtrix-image-header"

@property
@validated_property
def data_file(self):
return ImageDataFile(self.data_fspath)

Expand All @@ -84,14 +84,14 @@ def __attrs_post_init__(self):
super().__attrs_post_init__()


class ImageDataFile(File):
class ImageDataFile(BinaryFile):

ext = ".dat"


@extra_implementation(FileSet.read_metadata)
def mrtrix_read_metadata(
mif: BaseMrtrixImage, selected_keys: ty.Optional[ty.Collection[str]] = None
mif: BaseMrtrixImage, **kwargs: ty.Any
) -> ty.Mapping[str, ty.Any]:
metadata = {}
with open(mif.fspath, "rb") as f:
Expand Down Expand Up @@ -127,6 +127,4 @@ def mrtrix_read_metadata(
else:
metadata[key] = value
line = f.readline().decode("utf-8")
if selected_keys:
metadata = {k: v for k, v in metadata.items() if k in selected_keys}
return metadata
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from fileformats.generic import File
from fileformats.generic import BinaryFile
from fileformats.core.mixin import WithMagicNumber


class Tracks(WithMagicNumber, File):
class Tracks(WithMagicNumber, BinaryFile):

ext = ".tck"
magic_number = b"mrtrix tracks\n"
Expand Down
Loading