Skip to content
Open
Changes from all commits
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
18 changes: 12 additions & 6 deletions manual_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ def get_parser():
}\n
"""),
)
parser.add_argument(
'-task-name', type=str, required=False, default='Manual',
help=
"R|The name of the task being done, which will be added in the json file. It must be added between \"\"."
" For example: \"Manual correction of lesions generated from model XXX\" Default: \"Manual\"g.",
Copy link
Member

Choose a reason for hiding this comment

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

To track such workflow (automatic segmentation by a model + manual correction), we add two entries into the JSON file (one for the model, the second for the rater). See here.

{
    "SpatialReference": "orig",
    "GeneratedBy": [
        {
            "Name": "sct_deepseg_sc",
            "Version": "SCT v6.1"
        },
        {
            "Name": "Manual",
            "Author": "Nathan Molinier",
            "Date": "2023-07-14 13:43:10"
        }
    ]
}

Copy link
Member

@valosekj valosekj Nov 30, 2024

Choose a reason for hiding this comment

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

You can specify the model's details using the -json-metadata arg; see L246-L260
@plbenveniste, can you please try -json-metadata arg on some of your corrections? I believe the output JSON sidecars will contain all the information you want to track.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with Jan, sometimes we want to add multiple information to the sidecar and I believe the -json-metadata flag accomplish that already

)
parser.add_argument(
'-change-orient',
type=str,
Expand Down Expand Up @@ -530,7 +536,7 @@ def load_custom_json(fname):
sys.exit("ERROR: The file {} is not a valid JSON file.".format(fname))


def update_json(fname_nifti, name_rater, json_metadata):
def update_json(fname_nifti, name_rater, json_metadata, task_name):
"""
Create/update JSON sidecar with meta information
:param fname_nifti: str: File name of the nifti image to associate with the JSON sidecar
Expand All @@ -540,8 +546,8 @@ def update_json(fname_nifti, name_rater, json_metadata):
"""
fname_json = fname_nifti.replace('.gz', '').replace('.nii', '.json')

# Check if the json file already exists, if so, open it
if os.path.exists(fname_json):
# Check if the json file already exists and is not empty, open it
if os.path.exists(fname_json) and os.path.getsize(fname_json) != 0:
# Read already existing json file
with open(fname_json, "r") as outfile: # r to read
json_dict = json.load(outfile)
Expand All @@ -563,7 +569,7 @@ def update_json(fname_nifti, name_rater, json_metadata):
json_dict['GeneratedBy'].append(json_metadata)

# If the label was modified or just checked, add "Name": "Manual" to the JSON sidecar
json_dict['GeneratedBy'].append({'Name': 'Manual',
json_dict['GeneratedBy'].append({'Name': task_name,
'Author': name_rater,
'Date': time.strftime('%Y-%m-%d %H:%M:%S')})

Expand Down Expand Up @@ -936,10 +942,10 @@ def main():
if args.add_seg_only:
# We use update_json because we are adding a new segmentation, and we want to create
# a JSON file
update_json(fname_out, name_rater, json_metadata)
update_json(fname_out, name_rater, json_metadata, args.task_name)
# Generate QC report
else:
update_json(fname_out, name_rater, json_metadata)
update_json(fname_out, name_rater, json_metadata, args.task_name)
# Generate QC report
generate_qc(fname, fname_out, task, fname_qc, subject, args.config, args.qc_lesion_plane, suffix_dict)

Expand Down
Loading