Skip to content

Conversation

@valosekj
Copy link
Member

@valosekj valosekj commented Jan 6, 2025

Description

This PR removes redundant nested GeneratedBy key in the output JSON sidecar.

main:

{
    "SpatialReference": "orig",
    "GeneratedBy": [
        {
            "GeneratedBy": [
                {
                    "Name": "spinalcordtoolbox: sct_deepseg -task seg_sc_contrast_agnostic -i sub-05_T2w.nii.gz -qc qc -qc-subject sub-05",
                    "Version": "git-master-64f55fdf022659db5d5c779f01c605d91ca7d052",
                    "CodeURL": "https://github.com/spinalcordtoolbox/spinalcordtoolbox/blob/64f55fdf022659db5d5c779f01c605d91ca7d052/spinalcordtoolbox/scripts/sct_deepseg.py",
                    "ModelURL": "https://github.com/sct-pipeline/contrast-agnostic-softseg-spinalcord/releases/download/v2.5/model_contrast-agnostic_20240930-1002.zip"
                }
            ]
        },
        {
            "Name": "Manual",
            "Author": "Jan Valosek",
            "Date": "2024-12-10 18:05:31"
        }
    ]
}

This branch:

{
    "SpatialReference": "orig",
    "GeneratedBy": [
        {
            "Name": "spinalcordtoolbox: sct_deepseg -task seg_sc_contrast_agnostic -i sub-05_T2w.nii.gz -qc qc -qc-subject sub-05",
            "Version": "git-master-64f55fdf022659db5d5c779f01c605d91ca7d052",
            "CodeURL": "https://github.com/spinalcordtoolbox/spinalcordtoolbox/blob/64f55fdf022659db5d5c779f01c605d91ca7d052/spinalcordtoolbox/scripts/sct_deepseg.py",
            "ModelURL": "https://github.com/sct-pipeline/contrast-agnostic-softseg-spinalcord/releases/download/v2.5/model_contrast-agnostic_20240930-1002.zip"    
        },
        {
            "Name": "Manual",
            "Author": "Jan Valosek",
            "Date": "2024-12-10 18:05:31"
        }
    ]
}

How to test this PR

cd ~/code/manual-correction
git fetch
git checkout jv/108-fix_nested_GeneratedBy_key_in_JSON_sidecar
sct_download_data -d sct_course_data -o sct_course_data_2024
cd sct_course_data_2024/multi_subject
chmod +x process_data.sh
sct_run_batch -script process_data.sh -config config.yml -jobs 3
# Note: you can add `exit` to line 115 to run only the contrast-agnostic model on T2w to save time

$SCT_DIR/python/envs/venv_sct/bin/python ~/code/manual-correction/manual_correction.py -config qc_fail.yml -path-img output/data_processed/ -path-label output/data_processed -path-out data/derivatives/labels

cat data/derivatives/labels/sub-05/anat/sub-05_T2w_seg.json

Resolves: #108

@NathanMolinier
Copy link
Contributor

NathanMolinier commented Jan 7, 2025

Don't miss this #108 (comment) or maybe this is already what you suggested

@NathanMolinier
Copy link
Contributor

I tested it and I only get this output:
Screenshot 2025-01-07 at 11 51 08

Is the aim of the PR #105 to automatically fetch the metadata without supplying the flag -json-metadata ?

@valosekj
Copy link
Member Author

valosekj commented Jan 7, 2025

Thanks for testing the PR, @NathanMolinier!

It's weird; the script is supposed to automatically read (no need for the -json-metadata arg) the JSON created by SCT by these lines and include its content into the output JSON. The output should look like this:

{
    "SpatialReference": "orig",
    "GeneratedBy": [
        {
            "Name": "spinalcordtoolbox: sct_deepseg -task seg_sc_contrast_agnostic -i sub-05_T2w.nii.gz -qc qc -qc-subject sub-05",
            "Version": "git-master-64f55fdf022659db5d5c779f01c605d91ca7d052",
            "CodeURL": "https://github.com/spinalcordtoolbox/spinalcordtoolbox/blob/64f55fdf022659db5d5c779f01c605d91ca7d052/spinalcordtoolbox/scripts/sct_deepseg.py",
            "ModelURL": "https://github.com/sct-pipeline/contrast-agnostic-softseg-spinalcord/releases/download/v2.5/model_contrast-agnostic_20240930-1002.zip"    
        },
        {
            "Name": "Manual",
            "Author": "Jan Valosek",
            "Date": "2024-12-10 18:05:31"
        }
    ]
}

@NathanMolinier
Copy link
Contributor

NathanMolinier commented Jan 8, 2025

I removed the folders and redo the commands and it worked, maybe I did something wrong previously:

{
    "SpatialReference": "orig",
    "GeneratedBy": [
        {
            "Name": "spinalcordtoolbox: sct_deepseg -task seg_sc_contrast_agnostic -i sub-05_T2w.nii.gz -qc qc -qc-subject sub-05",
            "Version": "git-master-1671e1ff4a54f0228743feb621f68bc84a80024e",
            "CodeURL": "https://github.com/spinalcordtoolbox/spinalcordtoolbox/blob/1671e1ff4a54f0228743feb621f68bc84a80024e/spinalcordtoolbox/scripts/sct_deepseg.py",
            "ModelURL": "https://github.com/sct-pipeline/contrast-agnostic-softseg-spinalcord/releases/download/v2.5/model_contrast-agnostic_20240930-1002.zip"
        },
        {
            "Name": "Manual",
            "Author": "Nathan",
            "Date": "2025-01-08 09:03:47"
        }
    ]
} 

Copy link
Contributor

@NathanMolinier NathanMolinier left a comment

Choose a reason for hiding this comment

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

Not a lot of modification, seems to work great. Thank @valosekj for the PR !

@valosekj
Copy link
Member Author

valosekj commented Jan 8, 2025

Thank you for your review, @NathanMolinier!

@valosekj valosekj merged commit 03620ee into main Jan 8, 2025
1 check passed
@valosekj valosekj deleted the jv/108-fix_nested_GeneratedBy_key_in_JSON_sidecar branch January 8, 2025 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redundant nested GeneratedBy key in JSON sidecar

2 participants