-
Notifications
You must be signed in to change notification settings - Fork 42
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
[PY-645][externa] Improved tolerance for dots in filenames & test linting #746
Changes from 4 commits
5311289
73df08b
20428f3
120936f
8dd77e8
a84911e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,50 +137,28 @@ def check_for_error_and_return_imageid( | |
image_id : str | ||
|
||
""" | ||
# check if all item slots have the correct file-extension | ||
# Check if all item slots have the correct file-extension | ||
for slot in video_annotation.slots: | ||
for source_file in slot.source_files: | ||
filename = Path(source_file["file_name"]) | ||
|
||
try: | ||
suffixes = filename.suffixes[-2:] | ||
except IndexError: | ||
suffixes = filename.suffixes | ||
if len(suffixes) == 2: | ||
if suffixes[0] == ".nii" and suffixes[1] == ".gz": | ||
image_id = str(filename).rstrip("".join(suffixes)) | ||
else: | ||
return create_error_message_json( | ||
"Two suffixes found but not ending in .nii.gz", | ||
output_dir, | ||
str(filename), | ||
) | ||
elif len(suffixes) == 1: | ||
if suffixes[0] == ".nii" or suffixes[0] == ".dcm": | ||
image_id = filename.stem | ||
else: | ||
return create_error_message_json( | ||
"Misconfigured filename, not ending in .nii or .dcm. Are you sure this is medical data?", | ||
output_dir, | ||
str(filename), | ||
) | ||
else: | ||
if not ( | ||
filename.name.lower().endswith(".nii.gz") | ||
or filename.name.lower().endswith(".nii") | ||
or filename.name.lower().endswith(".dcm") | ||
): | ||
return create_error_message_json( | ||
"You are trying to export to nifti. Filename should contain either .nii, .nii.gz or .dcm extension." | ||
"Are you sure this is medical data?", | ||
"Misconfigured filename, not ending in .nii, .nii.gz or .dcm. Are you sure this is medical data?", | ||
output_dir, | ||
str(filename), | ||
) | ||
|
||
filename = Path(video_annotation.filename) | ||
try: | ||
suffixes = filename.suffixes[-2:] | ||
except IndexError: | ||
suffixes = filename.suffixes | ||
if len(suffixes) == 2: | ||
image_id = str(filename).rstrip("".join(suffixes)) | ||
elif len(suffixes) == 1: | ||
image_id = str(filename.stem) | ||
if filename.name.lower().endswith(".nii.gz"): | ||
image_id = str(filename).rstrip(".nii.gz") | ||
elif filename.name.lower().endswith(".nii"): | ||
image_id = str(filename).rstrip(".nii") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this work for case where we have upper cases? the condition will trigger, but the strip won't find the upper case extension, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. God I need to multitask less... Updated. Now we check the lowered version of the filename so we're guaranteed to pick up any of the 3 matches |
||
elif filename.name.lower().endswith(".dcm"): | ||
image_id = str(filename).rstrip(".dcm") | ||
else: | ||
image_id = str(filename) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little unsure about this. Currently, if
.nii.gz
then we include this in theimage_id
Otherwise, if
.dcm
or.nii
, we don't include this in theimage_id
. Why is this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that actually true?
image_id = str(filename).rstrip("".join(suffixes))
would strip out.nii.gz
🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually yes that is correct
Just tested and the behaviour now is:
.nii
,.dcm
, or.nii.gz
, the exporter fails (we want this)I believe this is correct