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
15 changes: 7 additions & 8 deletions darwin/cli_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,8 @@ def dataset_import(
If ``True`` it will bypass a warning that the import will overwrite the current annotations if any are present.
If ``False`` this warning will be skipped and the import will overwrite the current annotations without warning.
legacy : bool, default: False
If ``True`` it will not resize the annotations to be isotropic.
If ``False`` it will resize the annotations to be isotropic.
If ``True`` it will resize the annotations to be isotropic.
If ``False`` it will not resize the annotations to be isotropic.
use_multi_cpu : bool, default: False
If ``True`` it will use all multiple CPUs to speed up the import process.
cpu_limit : Optional[int], default: Core count - 2
Expand All @@ -931,7 +931,6 @@ def dataset_import(

try:
importer: ImportParser = get_importer(format)

if format == "nifti" and legacy:
importer = partial(importer, legacy=True)

Expand All @@ -954,7 +953,7 @@ def dataset_import(
overwrite,
use_multi_cpu,
cpu_limit,
no_legacy=False if legacy else True,
legacy,
)

except ImporterNotFoundError:
Expand Down Expand Up @@ -1228,8 +1227,8 @@ def dataset_convert(
annotations folder of the dataset under 'other_formats/{format}'.
legacy : bool, default: False
This flag is only for the nifti format.
If True, it will not export the annotations using legacy calculations.
If False, it will resize the annotations using the new calculation by dividing with pixdims.
If True, it will resize the annotations by dividing by pixdims.
If False, it will not export the annotations using legacy calculations
"""
identifier: DatasetIdentifier = DatasetIdentifier.parse(dataset_identifier)
client: Client = _load_client(team_slug=identifier.team_slug)
Expand Down Expand Up @@ -1286,8 +1285,8 @@ def convert(
Folder where the exported annotations will be placed.
legacy: bool, default: False
This flag is only for the nifti format.
If True, it will not export the annotations using legacy calculations.
If False, it will resize the annotations using the new calculation by dividing with pixdims.
If True, it will resize the annotations by dividing by pixdims
If False, it will not export the annotations using legacy calculations.
"""
try:
parser: ExportParser = get_exporter(format)
Expand Down
10 changes: 5 additions & 5 deletions darwin/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ def import_annotations( # noqa: C901
overwrite: bool = False,
use_multi_cpu: bool = False,
cpu_limit: Optional[int] = None,
no_legacy: Optional[bool] = False,
legacy: Optional[bool] = False,
) -> None:
"""
Imports the given given Annotations into the given Dataset.
Expand Down Expand Up @@ -1134,9 +1134,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
legacy : bool, default: False
If ``True`` will use the legacy isotropic transformation to resize annotations
If ``False`` will not use the legacy isotropic transformation to resize annotations
Raises
-------
ValueError
Expand All @@ -1154,7 +1154,7 @@ def import_annotations( # noqa: C901
# 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:
if importer.__module__ == "darwin.importer.formats.nifti" and legacy:
importer = partial(importer, legacy=True)
except AttributeError:
pass
Expand Down
21 changes: 11 additions & 10 deletions darwin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def __init__(self) -> None:
help="Annotation files (or folders) to convert.",
)
parser_convert.add_argument(
"--no-legacy",
action="store_false",
dest="legacy",
help="Do not convert annotation using legacy process (isotropic transformation).",
"--legacy",
action="store_true",
default=False,
help="Import annotation files using legacy process (isotropic transformation).",
)
parser_convert.add_argument(
"output_dir", type=str, help="Where to store output files."
Expand Down Expand Up @@ -375,10 +375,10 @@ def __init__(self) -> None:
help="Bypass warnings about overwiting existing annotations.",
)
parser_import.add_argument(
"--no-legacy",
action="store_false",
dest="legacy",
help="Do not importing annotation files using legacy process (isotropic transformation).",
"--legacy",
action="store_true",
default=False,
help="Import annotation files using legacy process (isotropic transformation).",
)

# Cpu limit for multiprocessing tasks
Expand Down Expand Up @@ -410,9 +410,10 @@ def cpu_default_types(input: Any) -> Optional[int]: # type: ignore
"format", type=str, help="Annotation format to convert to."
)
parser_convert.add_argument(
"legacy",
"--legacy",
action="store_true",
help="Convert annotation using legacy process (isotropic transformation).",
default=False,
help="Import annotation files using legacy process (isotropic transformation).",
)
parser_convert.add_argument(
"-o", "--output_dir", type=str, help="Where to store output files."
Expand Down
Binary file added tests/darwin/data/nifti/BRAINIX_NIFTI_ROI.nii.gz
Binary file not shown.
44 changes: 44 additions & 0 deletions tests/darwin/data/nifti/legacy/.v7/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"version": "1.0",
"schema_ref": "https://darwin-public.s3.eu-west-1.amazonaws.com/darwin_json/metadata/1.0/schema.json",
"classes": [
{
"name": "Reference_sBAT",
"type": "polygon",
"description": null,
"color": "rgba(0,255,170,1.0)",
"sub_types": [
"text",
"inference"
],
"properties": [],
"sub_types_settings": {
"inference": {},
"text": {}
}
}
],
"properties": [
{
"name": "item-level-ss",
"type": "single_select",
"description": "What is this?",
"required": false,
"property_values": [
{
"value": "1",
"color": "rgba(238,240,241,1.0)"
},
{
"value": "2",
"color": "rgba(255,0,214,1.0)"
},
{
"value": "3",
"color": "rgba(173,255,0,1.0)"
}
],
"granularity": "item"
}
]
}
Loading