From 9013c4760fedd63d1337a57049a9bff2806aa035 Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Mon, 22 Jul 2024 16:26:23 +0100 Subject: [PATCH 1/2] SDK-controllable legacy NifTI import behaviour --- darwin/cli_functions.py | 1 + darwin/importer/importer.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/darwin/cli_functions.py b/darwin/cli_functions.py index 8f19d4c64..7c78769c3 100644 --- a/darwin/cli_functions.py +++ b/darwin/cli_functions.py @@ -935,6 +935,7 @@ def dataset_import( overwrite, use_multi_cpu, cpu_limit, + no_legacy=False if legacy else True, ) except ImporterNotFoundError: diff --git a/darwin/importer/importer.py b/darwin/importer/importer.py index 17da94b12..88860ba29 100644 --- a/darwin/importer/importer.py +++ b/darwin/importer/importer.py @@ -1,6 +1,7 @@ import concurrent.futures import uuid from collections import defaultdict +from functools import partial from logging import getLogger from multiprocessing import cpu_count from pathlib import Path @@ -677,6 +678,7 @@ def import_annotations( # noqa: C901 overwrite: bool = False, use_multi_cpu: bool = False, cpu_limit: Optional[int] = None, + no_legacy: Optional[bool] = False, ) -> None: """ Imports the given given Annotations into the given Dataset. @@ -718,6 +720,9 @@ def import_annotations( # noqa: C901 If ``cpu_limit`` is greater than the number of available CPU cores, it will be set to the number of available cores. If ``cpu_limit`` is less than 1, it will be set to CPU count - 2. If ``cpu_limit`` is omitted, it will be set to CPU count - 2. + no_legacy : bool, default: False + If ``True`` will not use the legacy isotropic transformation to resize annotations + If ``False`` will use the legacy isotropic transformation to resize annotations Raises ------- ValueError @@ -731,6 +736,9 @@ def import_annotations( # noqa: C901 console = Console(theme=_console_theme()) + if importer.__module__ == "darwin.importer.formats.nifti" and no_legacy: + importer = partial(importer, legacy=True) + if append and delete_for_empty: raise IncompatibleOptions( "The options 'append' and 'delete_for_empty' cannot be used together. Use only one of them." From c87198d012a6ab2421166430b1309d4828e361a0 Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Tue, 23 Jul 2024 14:47:32 +0100 Subject: [PATCH 2/2] Corrected no_legacy flag behaviour --- darwin/importer/importer.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/darwin/importer/importer.py b/darwin/importer/importer.py index 88860ba29..62acd78f2 100644 --- a/darwin/importer/importer.py +++ b/darwin/importer/importer.py @@ -736,8 +736,14 @@ def import_annotations( # noqa: C901 console = Console(theme=_console_theme()) - if importer.__module__ == "darwin.importer.formats.nifti" and no_legacy: - importer = partial(importer, legacy=True) + # The below try / except block is necessary, but temporary + # CLI-initiated imports will raise an AttributeError because of the partial function + # This block handles SDK-initiated imports + try: + if importer.__module__ == "darwin.importer.formats.nifti" and not no_legacy: + importer = partial(importer, legacy=True) + except AttributeError: + pass if append and delete_for_empty: raise IncompatibleOptions(