4Quant / LungStageAnnotator

The documentation and support for the LungStageAnnotator tool
http://4quant.com/LungStageAnnotator
2 stars 0 forks source link

JSON's produced of DICOM header are invalid #95

Closed kmader closed 7 years ago

kmader commented 7 years ago

The JSON files produced when including the dicom header are invalid due to a bug in the json library see https://www.na-mic.org/Bug/view.php?id=4342

import json
from dicom.tag import TupleTag
out_json_str = json.dumps(TupleTag((123,456))) # '(007b, 01c8)'
json.loads(out_json_str) # ValueError: No JSON object could be decoded
kmader commented 7 years ago

fixed by making a new 'robust' read function which automatically removes these lines

def patch_json(in_jsontxt):
    """
    Remove DICOM tags from a JSON file
    Created explicitly for the new data from files like
    /Volumes/USBData/LungStage_PET/AnnotationResults/slicer_data/day8/TNM_StagingD20170210T160708859006_by_Alex_of_ACC24479266/lsa.json
    :param in_jsontxt:
    :return:
    Examples
    >>> patch_json(_kill_tag_bad_json).strip()
    '{"ct_header": [[[24, 4096], "DeviceSerialNumber", [-1, "LO", 6, "31023 ", 1820, false, true]]], "name": "bob"}'
    """
    return re.sub('\([\w\n]{4}, [\w\n]{4}\)', '', in_jsontxt) # remove all dicom-like keys