Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DAR-3111][External] CLI-controllable legacy NifTI import behaviour #889

Merged
merged 2 commits into from
Jul 23, 2024
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
1 change: 1 addition & 0 deletions darwin/cli_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ def dataset_import(
overwrite,
use_multi_cpu,
cpu_limit,
no_legacy=False if legacy else True,
)

except ImporterNotFoundError:
Expand Down
14 changes: 14 additions & 0 deletions darwin/importer/importer.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -731,6 +736,15 @@ def import_annotations( # noqa: C901

console = Console(theme=_console_theme())

# 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(
"The options 'append' and 'delete_for_empty' cannot be used together. Use only one of them."
Expand Down