-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Support for python 3.12, pyproject.toml, minor naming cleanups #57
Changes from 8 commits
8d95a5c
b780a0d
a9c099d
248bb2e
1566f76
10d1bba
6630fed
d2b6ab4
b3dc158
e88b70e
b4ec767
6af543b
772ebf6
7b05007
738967b
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Ignore Pipfile.lock to allow support across multiple Python and operating system versions. | ||
Pipfile.lock |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[packages] | ||
# dicom-anonymizer = "*" # For 'released' version | ||
dicom-anonymizer = {file = ".."} # For local version | ||
pydicom = "*" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#DicomAnonymizer Examples | ||
|
||
This folder contains the following examples: | ||
- `anonymize_dataset.py`: Anonymize dicom tags for a dataset | ||
- `anonymize_extra_rules.py`: Anonymize dicom tags for a file with extra rules | ||
|
||
The supporting files are: | ||
- `Pipfile`: The [pipenv](https://packaging.python.org/en/latest/tutorials/managing-dependencies/) file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from dicomanonymizer import anonymize_dataset | ||
from pydicom.data import get_testdata_file | ||
from pydicom import dcmread | ||
|
||
def main(): | ||
original_ds = dcmread(get_testdata_file("CT_small.dcm")) | ||
data_ds = original_ds.copy() | ||
anonymize_dataset(data_ds, delete_private_tags=True) # Anonymization is done in-place | ||
print("Examples of original -> anonymized values:") | ||
for tt in ["PatientName", "PatientID", "StudyDate"]: | ||
print(f" {tt}: '{original_ds[tt].value}' -> '{data_ds[tt].value}'") | ||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import argparse | ||
from dicomanonymizer import ALL_TAGS, anonymize, keep | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(add_help=True) | ||
parser.add_argument('input', help='Path to the input dicom file or input directory which contains dicom files') | ||
parser.add_argument('output', help='Path to the output dicom file or output directory which will contains dicom files') | ||
parser.add_argument('--suffix', action='store', help='Suffix that will be added at the end of series description') | ||
args = parser.parse_args() | ||
|
||
input_dicom_path = args.input | ||
output_dicom_path = args.output | ||
|
||
extra_anonymization_rules = {} | ||
|
||
def setup_series_description(dataset, tag): | ||
element = dataset.get(tag) | ||
if element is not None: | ||
element.value = f'{element.value}-{args.suffix}' | ||
|
||
# ALL_TAGS variable is defined on file dicomfields.py | ||
# the 'keep' method is already defined into the dicom-anonymizer | ||
# It will overrides the default behaviour | ||
for i in ALL_TAGS: | ||
extra_anonymization_rules[i] = keep | ||
|
||
if args.suffix: | ||
extra_anonymization_rules[(0x0008, 0x103E)] = setup_series_description | ||
|
||
# Launch the anonymization | ||
anonymize(input_dicom_path, output_dicom_path, extra_anonymization_rules, delete_private_tags=False) | ||
|
||
if __name__ == '__main__': | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[project] | ||
name = "dicom_anonymizer" | ||
version = "1.0.11" | ||
authors = [ | ||
{ name="Laurenn Lam", email="[email protected]" }, | ||
] | ||
description = "Program to anonymize dicom files with default and custom rules" | ||
readme = "README.md" | ||
requires-python = ">=3.10" | ||
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. Why restrict to 3.10 and higher ? I tested with Python 3.9 and 3.8 and it seems to work 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. That was my confusion. Per importlib.metadata documentation, it was "provisional" until 3.10, so I thought it was not available for versions 3.8 and 3.9. Since these worked, I will update this minimum requirement to 3.8. Thank you for testing! 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. Fixed in commit b3dc158 |
||
classifiers = [ | ||
"Development Status :: 3 - Alpha", | ||
"Intended Audience :: Science/Research", | ||
"Topic :: Software Development :: Build Tools", | ||
"License :: OSI Approved :: BSD License", | ||
"Natural Language :: English", | ||
"Programming Language :: Python" | ||
] | ||
keywords = ["dicom", "anonymizer" , "medical"] | ||
|
||
dependencies = [ | ||
"pydicom", | ||
"tqdm", | ||
] | ||
|
||
[project.optional-dependencies] | ||
dev = [ | ||
"pytest", | ||
"setuptools", # Needed to load pydicom's test files | ||
] | ||
|
||
[project.scripts] | ||
dicom-anonymizer = "dicomanonymizer.anonymizer:main" | ||
|
||
[project.urls] | ||
"Homepage" = "https://github.com/KitwareMedical/dicom-anonymizer" | ||
"Bug Tracker" = "https://github.com/KitwareMedical/dicom-anonymizer/issues" | ||
|
||
[tool.setuptools.packages] | ||
find = {} # Scanning implicit namespaces is active by default | ||
|
This file was deleted.
This file was deleted.
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.
Why did you delete this example ? This can be useful.
Why not moving it in the examples folder you created ?
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 tried this example and could not get it to work. I can fix the first warning about 'bar' not being valid for
TM
, but have no idea how to fix the error of missingfile_meta
for the dataset. I took the easier route of using an existing DICOM data file!Here is the output:
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.
That should be fixed with #61
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.
Thank you! I will pull in the changes into my branch and that should clean up this PR.
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 have restored the example in
README.md
(actually, I copy-pasted your code, so the white-space differences are showing up!). Please re-review.