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

dcm2mha preprocessing #5

Merged
merged 9 commits into from
May 25, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Cleanup
joeranbosma committed May 25, 2022
commit c46409fd577093b2cda72b1874fab644ef1bf6ac
17 changes: 9 additions & 8 deletions src/picai_prep/dcm2mha.py
Original file line number Diff line number Diff line change
@@ -199,21 +199,22 @@ def _extract_metadata(self):

self.info(f"Collected {plural(total, 'DICOM file')} from {self.valid_items_str()}.", self.get_history_report())

@staticmethod
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Only one usage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stacked functions make it difficult to follow what's going on, so it there is no benefit, better to keep it simple.

def maps_to(mapping, metadata):
"""metadata maps to 'mapping' if any value in each key match"""
for key, values in mapping.items():
if not any(v in metadata[key] for v in values):
return False
return True

def _apply_mappings(self):
self.info(f"Applying mappings to {self.valid_items_str()} using extracted metadata.")

# metadata maps to 'mapping' if any value in each key match
def maps_to(mapping, metadata):
for key, values in mapping.items():
if not any(v in metadata[key] for v in values):
return False
return True

total = 0
for item in self.valid_items:
item['mappings'] = []
for name, mapping in self.mappings.items():
if maps_to(mapping, item['metadata']):
if self.maps_to(mapping, item['metadata']):
item['mappings'].append(name)
total += 1