Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new CLI script to predict compression probability #4760

Merged
merged 55 commits into from
Jan 22, 2025
Merged
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
ff2fde2
Add script to detect spinal cord compression based on https://pubmed.…
valosekj Dec 28, 2024
6d3af70
Fix 'E302 expected 2 blank lines, found 1'
valosekj Dec 28, 2024
befbc92
handle edge case when torsion is None
valosekj Dec 30, 2024
48dbc5f
Add cut-offs also for moderate and low probability of compression.
valosekj Dec 31, 2024
d26ceaa
Rename 'CUT_OFF_MILD' to 'CUT_OFF_MODERATE'.
valosekj Dec 31, 2024
e4955ee
'C6/7' --> 'C6/C7' to be consistent with 'C3/C4'
valosekj Dec 31, 2024
90cbfa6
Use one slice above and below to process multiple slices around the d…
valosekj Jan 4, 2025
5355ad9
Swap slice order to make the slice numbering continuous in the output…
valosekj Jan 4, 2025
391577d
rename compression probability category values to from `high/moderate…
valosekj Jan 4, 2025
92d3ecd
Add detailed `printv` if `verbose == 2` for debugging
valosekj Jan 4, 2025
b4cd1f4
Merge branch 'master' into jv/add_sct_detect_compression
valosekj Jan 4, 2025
6155916
Swap 'possible' and 'yes' to give higher priority to 'yes'
valosekj Jan 4, 2025
8111fee
Name discs `C3/C4, C4/C5, C5/C6, C6/C7` instead of `4, 5, 6, 7`
valosekj Jan 4, 2025
c98d877
Merge branch 'master' into jv/add_sct_detect_compression
valosekj Jan 9, 2025
472b9d7
improve arg help formatting using `textwrap`
valosekj Jan 9, 2025
04296e7
rename variables to do not overwrite python `slice` class
valosekj Jan 9, 2025
cfea477
fix 'W291 trailing whitespace'
valosekj Jan 9, 2025
b7af562
Add '-num-of-slices' arg to specify number of slices above and below …
valosekj Jan 9, 2025
5d29bd0
Update CLI printing to be in line with the CSV table
valosekj Jan 9, 2025
eec4370
Add proper ref to the description
valosekj Jan 11, 2025
ea9f821
Simplify description and update args help
valosekj Jan 11, 2025
d0eb78e
Simplify printing to terminal -- always print the percentage
valosekj Jan 11, 2025
88004e7
Fix flake8 whitespace complaints
valosekj Jan 11, 2025
c5f0b19
Add 'sct_detect_compression' to 'setup.py'
valosekj Jan 11, 2025
771df06
Add '-o' arg to specify the output CSV file name
valosekj Jan 12, 2025
b81afe4
Check if the spinal cord segmentation file is empty
valosekj Jan 12, 2025
3e18293
Check if the disc file is empty and whether the disc file contains su…
valosekj Jan 12, 2025
fc9128e
Move 'get_disc_slices' before 'compute_shape_metrics'
valosekj Jan 12, 2025
dafce21
Add pytest unit tests for sct_detect_compression
valosekj Jan 12, 2025
a37fb82
fix E302 and W292 flake8 complains
valosekj Jan 12, 2025
af2a777
use pandas instead of csv
valosekj Jan 12, 2025
94d3ce7
Add test for the '-num-of-slices' flag
valosekj Jan 12, 2025
b591e07
'Slice (I->S)' --> 'Axial slice #' for now, as I haven't updated the …
valosekj Jan 12, 2025
a542b05
Improve '-discfile' arg help
valosekj Jan 13, 2025
a2ec910
Fix a bug in selecting a number of slices > 1
valosekj Jan 13, 2025
40cbc5b
Improve '-num-of-slices' arg help
valosekj Jan 13, 2025
2e21c76
Use "doi.org" ref formating instead of "pubmed"
valosekj Jan 13, 2025
63c82bb
Fix flake8's 'W391 blank line at end of file'
valosekj Jan 13, 2025
b05b6f9
simplify torsion calculation
valosekj Jan 13, 2025
36fc7da
expose cut-off values in the argparse help
valosekj Jan 14, 2025
d7795d8
fix line-breaking in arg help
valosekj Jan 16, 2025
cca5be8
simplify iteration across slices using
valosekj Jan 16, 2025
5223ca6
simplify pytest using `pytest.mark.parametrize`
valosekj Jan 16, 2025
34c6bf0
add doc entries for `sct_detect_compression`
valosekj Jan 16, 2025
53a09bb
Merge branch 'master' into jv/add_sct_detect_compression
valosekj Jan 16, 2025
c106bfd
fix short underline
valosekj Jan 16, 2025
7b276fb
add rst file for `sct_detect_compression`
valosekj Jan 16, 2025
aadd675
add `sct_detect_compression` to segmentation-analysis.rst toctree
valosekj Jan 16, 2025
3560f8c
remove underscore
valosekj Jan 16, 2025
3a4d8de
add extra empty line to fix list formatting when rendered on doc
valosekj Jan 16, 2025
262487f
improve arg help formatting to better render on our doc
valosekj Jan 16, 2025
b86ef6c
fix 'W293 blank line contains whitespace'
valosekj Jan 16, 2025
d29c00c
clarify `compute_torsion` docstring; include link to the supplementar…
valosekj Jan 16, 2025
de8251a
use 2 space indent to better format text blocks in the description
valosekj Jan 21, 2025
66378e4
Merge branch 'master' into jv/add_sct_detect_compression
valosekj Jan 22, 2025
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
Prev Previous commit
Next Next commit
Add cut-offs also for moderate and low probability of compression.
Use these cut-offs to determine compression probability category and include the category into the output CSV as a new column.
  • Loading branch information
valosekj committed Dec 31, 2024
commit 48dbc5fec3b78810343c55d0a2695cd3ef83aab8
19 changes: 13 additions & 6 deletions spinalcordtoolbox/scripts/sct_detect_compression.py
Original file line number Diff line number Diff line change
@@ -30,8 +30,12 @@

# Currently, the model works only for discs C3/C4 (4) to C6/7 (7)
SUPPORTED_DISCS = [4, 5, 6, 7]
# Cut-off to determine the presence of the compression
CUT_OFF = 0.451
# Compression cut-offs
# >0.451 high probability of compression
# 0.345-0.451 moderate probability of compression
# <0.345 low probability of compression
CUT_OFF_HIGH = 0.451
CUT_OFF_MILD = 0.345


def get_parser():
@@ -240,9 +244,12 @@ def process_compression(metrics_agg_merged, disc_slices):
torsion = metrics_agg_merged[slice,]['Torsion']
# Compute compression probability
probability = predict_compression_probability(cr, csa, solidity, torsion, disc)
compression_category = 'high' if probability > CUT_OFF_HIGH else \
'moderate' if probability > CUT_OFF_MILD else 'low'
compression_df = pd.concat([compression_df,
pd.DataFrame([{'Disc': disc, 'Axial slice #': slice,
'Compression probability': probability,
'Compression probability category': compression_category,
'Compression ratio (%)': cr, 'CSA (mm2)': csa,
'Solidity (%)': solidity, 'Torsion (degrees)': torsion}])],
ignore_index=True)
@@ -290,11 +297,11 @@ def main(argv: Sequence[str]):
compression_df.to_csv(fname_out, index=False)
printv(f"Results saved to: {fname_out}", verbose)

# Loop across compressions and print the results if the probability is above the cut-off
# Loop across discs and print results to terminal
for index, row in compression_df.iterrows():
if row['Compression probability'] > CUT_OFF:
printv(f"Disc {int(row['Disc'])} at axial slice {int(row['Axial slice #'])} has a high probability "
f"of compression: {row['Compression probability'] * 100:.2f}%. ", verbose)
printv(f"Disc {int(row['Disc'])} at axial slice {int(row['Axial slice #'])} has a "
f"{row['Compression probability category']} probability of compression: "
f"{row['Compression probability'] * 100:.2f}%. ", verbose)


if __name__ == "__main__":
Loading