phantom-mri-dicoms/code/reidentify.py

17 lines
457 B
Python
Executable file

import csv
import sys
mapping_file = sys.argv[1]
context_label = sys.argv[2]
identifier = sys.argv[3]
with open(mapping_file, mode='r', newline='', encoding='utf-8') as fp:
reader = csv.DictReader(fp, delimiter='\t')
for row in reader:
if row[context_label] == identifier:
print(row['source'])
sys.exit(0)
# fail, if we get here
print(f'unknown identifier {identifier!r} in context {context_label!r}')
sys.exit(1)