From 9bd2c84ad20b10aa0fff542485826a390db5cec5 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Tue, 1 Oct 2024 21:27:53 +1000 Subject: [PATCH] fixed up datatype option for stage --- .pre-commit-config.yaml | 50 ++++++++++++++++++++-------------------- scripts/get_pet_tst.py | 23 ++++++++++++++++++ xnat_ingest/cli/stage.py | 2 +- xnat_ingest/session.py | 5 ++-- 4 files changed, 52 insertions(+), 28 deletions(-) create mode 100644 scripts/get_pet_tst.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7a881d3..3904cd4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,28 +1,28 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 - hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-yaml - - id: check-added-large-files -- repo: https://github.com/psf/black - rev: 22.3.0 - hooks: - - id: black - exclude: ^(arcana/_version\.py|versioneer\.py)$ - args: - - -l 88 -- repo: https://github.com/codespell-project/codespell - rev: v2.1.0 - hooks: - - id: codespell - exclude: ^(xnat_checks/_version\.py|versioneer\.py)$ - args: - - --ignore-words=.codespell-ignorewords -- repo: https://github.com/PyCQA/flake8 - rev: 4.0.1 - hooks: - - id: flake8 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black + exclude: ^(arcana/_version\.py|versioneer\.py)$ + args: + - -l 88 + - repo: https://github.com/codespell-project/codespell + rev: v2.1.0 + hooks: + - id: codespell + exclude: ^(xnat_checks/_version\.py|versioneer\.py)$ + args: + - --ignore-words=.codespell-ignorewords + - repo: https://github.com/PyCQA/flake8 + rev: 7.0.0 + hooks: + - id: flake8 diff --git a/scripts/get_pet_tst.py b/scripts/get_pet_tst.py new file mode 100644 index 0000000..b905798 --- /dev/null +++ b/scripts/get_pet_tst.py @@ -0,0 +1,23 @@ +import tempfile +from pathlib import Path +from fileformats.medimage import DicomSeries +from medimages4tests.dummy.dicom.pet.wholebody.siemens.biograph_vision.vr20b import ( # type: ignore[import-untyped] + get_image as get_pet_image, +) + + +tmp_path = Path(tempfile.mkdtemp()) + +series = DicomSeries( + get_pet_image( + tmp_path, + first_name="first", + last_name="last", + StudyInstanceUID="StudyInstanceUID", + PatientID="PatientID", + AccessionNumber="AccessionNumber", + StudyID="xnat_project", + ).iterdir() +) + +print(series.metadata["StudyID"]) diff --git a/xnat_ingest/cli/stage.py b/xnat_ingest/cli/stage.py index cddcc1f..ce11f53 100644 --- a/xnat_ingest/cli/stage.py +++ b/xnat_ingest/cli/stage.py @@ -287,7 +287,7 @@ def stage( additional_loggers=additional_loggers, ) datatypes: list[ty.Type[FileSet]] - if datatype is None: + if not datatype: datatypes = [DicomSeries] else: datatypes = [FileSet.from_mime(dt) for dt in datatype] # type: ignore[misc] diff --git a/xnat_ingest/session.py b/xnat_ingest/session.py index 4a516e6..2953237 100644 --- a/xnat_ingest/session.py +++ b/xnat_ingest/session.py @@ -357,8 +357,9 @@ def get_id(field_type: str, field_name: str) -> str: ) else: raise ImagingSessionParseError( - f"Did not find '{field_name}' field in {resource}, " - "cannot uniquely identify the resource" + f"Did not find '{field_name}' field in {resource!r}, " + "cannot uniquely identify the resource, found:\n" + + "\n".join(resource.metadata) ) if index is not None: value = value[index]