add --json option to output JSON formatted string to stdout
Currently,fslstats
outputs a long string of values given a set of options supplied by the user. For example, the command:
fslstats ~/Downloads/z.nii.gz -r -R -e -E -v -V -m -M -s -S -w -x -X -c -C -p 50 -P 50
will output:
0.000000 7538.456055 0.000000 8339.000000 0.303472 0.875461 1805258 14442064.000000 456906 3655248.000000 1514.165541 5982.542265 2665.618383 1158.446353 9 72 10 90 1 76 0 2 55 88 33 0 0 0 0.607792 -21.150661 10.631672 44.696104 52.424670 41.315836 0.000000 6061.000000
This can be difficult to decipher, especially when that output string is meant to populate a data table in a GUI.
I propose that we add a --json
option to fslstats
that allows the user to output a JSON string with keys matching the input option flags.
example output for the command: fslstats ~/Downloads/z.nii.gz -r -R -e -E -v -V -m -M -s -S -w -x -X -c -C -p 50 -P 50
could look like this:
{
"volumes": [{
"indices": [{
"-r": "0.000000 7538.456055",
"-R": "0.000000 8339.000000",
"-e": "0.303472",
"-E": "0.875461",
"-v": "1805258 14442064.000000",
"-V": "456906 3655248.000000",
"-m": "1514.165541",
"-M": "5982.542265",
"-s": "2665.618383",
"-S": "1158.446353",
"-w": "9 72 10 90 1 76 0 2",
"-x": "55 88 33",
"-X": "0 0 0",
"-c": "0.607792 -21.150661 10.631672",
"-C": "44.696104 52.424670 41.315836",
"-p": "0.000000",
"-P": "6061.000000"
}]
}]
}
Note that there are two keys volumes
and indices
that are not set by fslstats
option flags. These keys contain arrays of objects. volumes
contains an array of indices for each volume in the input NIFTI file. If no indices mask image is given then indices will have only one object corresponding to the whole volume of the input NIFTI file. If a mask is provided (pre option -K
) then indices will contain an array of objects that report the requested values at each index location in the mask image.
An example output using a mask image with pre option -K and -t time series mode would look like this:
./fslstats -K $FSLDIR/data/atlases/Thalamus/Thalamus-maxprob-thr50-2mm.nii.gz -t ~/Downloads/z.nii.gz -r -R -e -E -v -V -m -M -s -S -w -x -X -c -C -p 50 -P 50 --json > a.json
{
"volumes": [{
"indices": [{
"-r": "6250.298828 6952.701172",
"-R": "6251.000000 6952.000000",
"-e": "0.469683",
"-E": "0.469683",
"-v": "33 264.000000",
"-V": "33 264.000000",
"-m": "6669.575758",
"-M": "6669.575758",
"-s": "202.774356",
"-S": "202.774356",
"-w": "34 22 51 4 35 9 0 1",
"-x": "34 54 41",
"-X": "51 51 36",
"-c": "-9.425605 -20.620902 5.250745",
"-C": "49.712803 52.689549 38.625373",
"-p": "6665.000000",
"-P": "6665.000000"
}, {
"-r": "6445.285156 7161.714844",
"-R": "6446.000000 7161.000000",
"-e": "0.465616",
"-E": "0.465616",
"-v": "30 240.000000",
"-V": "30 240.000000",
"-m": "6777.900000",
"-M": "6777.900000",
"-s": "180.822136",
"-S": "180.822136",
"-w": "33 24 51 3 35 7 0 1",
"-x": "33 52 40",
"-X": "52 51 36",
"-c": "6.663598 -21.920172 3.193831",
"-C": "41.668201 52.039914 37.596915",
"-p": "6761.000000",
"-P": "6761.000000"
}, {
"-r": "6216.140137 7077.859863",
"-R": "6217.000000 7077.000000",
"-e": "0.371314",
"-E": "0.371314",
"-v": "13 104.000000",
"-V": "13 104.000000",
"-m": "6734.461538",
"-M": "6734.461538",
"-s": "280.064461",
"-S": "280.064461",
"-w": "53 5 46 3 35 5 0 1",
"-x": "57 48 35",
"-X": "53 47 39",
"-c": "-21.631791 -31.677228 0.428108",
"-C": "55.815895 47.161386 36.214054",
"-p": "6762.000000",
"-P": "6762.000000"
}, {
"-r": "5033.087891 7058.454102",
"-R": "3146.000000 7213.000000",
"-e": "0.872017",
"-E": "0.872017",
"-v": "903 7224.000000",
"-V": "903 7224.000000",
"-m": "6252.355482",
"-M": "6252.355482",
"-s": "484.970549",
"-S": "484.970549",
"-w": "36 19 48 15 35 11 0 1",
"-x": "52 60 38",
"-X": "47 49 37",
"-c": "-0.131469 -13.483868 6.267752",
"-C": "45.065734 56.258066 39.133876",
"-p": "6335.000000",
"-P": "6335.000000"
}, {
"-r": "6417.959961 7050.660156",
"-R": "6378.000000 7118.000000",
"-e": "0.697888",
"-E": "0.697888",
"-v": "153 1224.000000",
"-V": "153 1224.000000",
"-m": "6724.725490",
"-M": "6724.725490",
"-s": "168.321795",
"-S": "168.321795",
"-w": "34 22 53 5 35 10 0 1",
"-x": "54 57 39",
"-X": "39 53 35",
"-c": "-0.013236 -16.384446 6.923837",
"-C": "45.006618 54.807777 39.461918",
"-p": "6724.000000",
"-P": "6724.000000"
}, {
"-r": "5861.761230 7421.087891",
"-R": "5639.000000 7480.000000",
"-e": "0.812382",
"-E": "0.812382",
"-v": "387 3096.000000",
"-V": "387 3096.000000",
"-m": "6716.914729",
"-M": "6716.914729",
"-s": "389.656180",
"-S": "389.656180",
"-w": "32 26 47 6 33 12 0 1",
"-x": "32 50 41",
"-X": "50 49 36",
"-c": "0.421521 -26.784062 3.714033",
"-C": "44.789239 49.607969 37.857016",
"-p": "6740.000000",
"-P": "6740.000000"
}, {
"-r": "4224.733887 6694.685059",
"-R": "3437.000000 7118.000000",
"-e": "0.838632",
"-E": "0.838632",
"-v": "520 4160.000000",
"-V": "520 4160.000000",
"-m": "5702.148077",
"-M": "5702.148077",
"-s": "567.146316",
"-S": "567.146316",
"-w": "33 25 45 18 34 12 0 1",
"-x": "33 47 37",
"-X": "42 50 42",
"-c": "2.078453 -21.364169 10.099275",
"-C": "43.960774 52.317915 41.049638",
"-p": "5767.000000",
"-P": "5767.000000"
}]
}, {
"indices": [{
"-r": "6250.298828 6952.701172",
"-R": "6251.000000 6952.000000",
"-e": "0.469683",
"-E": "0.469683",
"-v": "33 264.000000",
"-V": "33 264.000000",
"-m": "6669.575758",
"-M": "6669.575758",
"-s": "202.774356",
"-S": "202.774356",
"-w": "34 22 51 4 35 9 0 1",
"-x": "34 54 41",
"-X": "51 51 36",
"-c": "-9.425605 -20.620902 5.250745",
"-C": "49.712803 52.689549 38.625373",
"-p": "6665.000000",
"-P": "6665.000000"
}, {
"-r": "6445.285156 7161.714844",
"-R": "6446.000000 7161.000000",
"-e": "0.465616",
"-E": "0.465616",
"-v": "30 240.000000",
"-V": "30 240.000000",
"-m": "6777.900000",
"-M": "6777.900000",
"-s": "180.822136",
"-S": "180.822136",
"-w": "33 24 51 3 35 7 0 1",
"-x": "33 52 40",
"-X": "52 51 36",
"-c": "6.663598 -21.920172 3.193831",
"-C": "41.668201 52.039914 37.596915",
"-p": "6761.000000",
"-P": "6761.000000"
}, {
"-r": "6216.140137 7077.859863",
"-R": "6217.000000 7077.000000",
"-e": "0.371314",
"-E": "0.371314",
"-v": "13 104.000000",
"-V": "13 104.000000",
"-m": "6734.461538",
"-M": "6734.461538",
"-s": "280.064461",
"-S": "280.064461",
"-w": "53 5 46 3 35 5 0 1",
"-x": "57 48 35",
"-X": "53 47 39",
"-c": "-21.631791 -31.677228 0.428108",
"-C": "55.815895 47.161386 36.214054",
"-p": "6762.000000",
"-P": "6762.000000"
}, {
"-r": "5033.087891 7058.454102",
"-R": "3146.000000 7213.000000",
"-e": "0.872017",
"-E": "0.872017",
"-v": "903 7224.000000",
"-V": "903 7224.000000",
"-m": "6252.355482",
"-M": "6252.355482",
"-s": "484.970549",
"-S": "484.970549",
"-w": "36 19 48 15 35 11 0 1",
"-x": "52 60 38",
"-X": "47 49 37",
"-c": "-0.131469 -13.483868 6.267752",
"-C": "45.065734 56.258066 39.133876",
"-p": "6335.000000",
"-P": "6335.000000"
}, {
"-r": "6417.959961 7050.660156",
"-R": "6378.000000 7118.000000",
"-e": "0.697888",
"-E": "0.697888",
"-v": "153 1224.000000",
"-V": "153 1224.000000",
"-m": "6724.725490",
"-M": "6724.725490",
"-s": "168.321795",
"-S": "168.321795",
"-w": "34 22 53 5 35 10 0 1",
"-x": "54 57 39",
"-X": "39 53 35",
"-c": "-0.013236 -16.384446 6.923837",
"-C": "45.006618 54.807777 39.461918",
"-p": "6724.000000",
"-P": "6724.000000"
}, {
"-r": "5861.761230 7421.087891",
"-R": "5639.000000 7480.000000",
"-e": "0.812382",
"-E": "0.812382",
"-v": "387 3096.000000",
"-V": "387 3096.000000",
"-m": "6716.914729",
"-M": "6716.914729",
"-s": "389.656180",
"-S": "389.656180",
"-w": "32 26 47 6 33 12 0 1",
"-x": "32 50 41",
"-X": "50 49 36",
"-c": "0.421521 -26.784062 3.714033",
"-C": "44.789239 49.607969 37.857016",
"-p": "6740.000000",
"-P": "6740.000000"
}, {
"-r": "4224.733887 6694.685059",
"-R": "3437.000000 7118.000000",
"-e": "0.838632",
"-E": "0.838632",
"-v": "520 4160.000000",
"-V": "520 4160.000000",
"-m": "5702.148077",
"-M": "5702.148077",
"-s": "567.146316",
"-S": "567.146316",
"-w": "33 25 45 18 34 12 0 1",
"-x": "33 47 37",
"-X": "42 50 42",
"-c": "2.078453 -21.364169 10.099275",
"-C": "43.960774 52.317915 41.049638",
"-p": "5767.000000",
"-P": "5767.000000"
}]
}]
}
If the --json option is omitted, the behaviour should be identical to the current fslstats
.