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

Automatic documentation with Sphinx and Read the Docs #104

Draft
wants to merge 64 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
cc19190
- update documentation with sphinx
PaulBautin Mar 12, 2021
4065a74
- add link to docs on README
PaulBautin Mar 12, 2021
a493021
add link to readthedocs
PaulBautin Mar 12, 2021
c912d98
- remove venv
PaulBautin Mar 13, 2021
f4ee0c3
Merge remote-tracking branch 'origin/docs' into docs
PaulBautin Mar 13, 2021
7dc4f2c
- update conf
PaulBautin Mar 17, 2021
0ba8b81
add jsonschema to requirements
PaulBautin Mar 18, 2021
628a244
- update documentation for both dataframes subject and rescale
PaulBautin Mar 18, 2021
cb33d65
- add between subject sample size
PaulBautin May 11, 2021
8e5796f
- test math markdown
PaulBautin May 11, 2021
90873c9
- add latex instruction for formula
PaulBautin May 11, 2021
2f6869e
- improve latex formula for indexing
PaulBautin May 12, 2021
462dcad
- change mean to latex \overline and STD to \sigma
PaulBautin May 12, 2021
f1e88b2
- minor change on SD of error
PaulBautin May 12, 2021
749db90
- improve math indexing for formulas
PaulBautin May 12, 2021
007f5d4
- add rescale dataframe file
PaulBautin May 12, 2021
ef30058
- add subject dataframe file and sample size
PaulBautin May 12, 2021
dfbe658
- remove redundancy in sections
PaulBautin May 12, 2021
f817094
- statistics page on main welcome page
PaulBautin May 12, 2021
86122bf
- sous section pour les stats
PaulBautin May 12, 2021
d9d6400
- update rescale dataframe formula
PaulBautin May 12, 2021
61e9ff3
- correct formulas for error
PaulBautin May 12, 2021
e1d0c5c
- add computation of for each section
PaulBautin May 12, 2021
9d0828e
- add blurb for doc presentation and image
PaulBautin May 17, 2021
62f4d4f
- test why image is not displayed
PaulBautin May 17, 2021
d4b25b5
- test why image is not displayed 2
PaulBautin May 17, 2021
30633db
- add image in docs to see if it is found
PaulBautin May 17, 2021
c44d5ef
- refactor an rearrange files
PaulBautin May 17, 2021
4e19603
- Replace index and file overview
PaulBautin May 17, 2021
1676be3
- remove rst extension in index file
PaulBautin May 17, 2021
3bc4242
- add files to git
PaulBautin May 17, 2021
c1df404
- regroup stats under one file
PaulBautin May 17, 2021
af53654
- add spacing in index
PaulBautin May 17, 2021
980f954
- Change Overview.rst to overview.rst
PaulBautin May 17, 2021
e812a23
- update title for overview
PaulBautin May 17, 2021
7e1955b
- remove build files
PaulBautin May 17, 2021
d7ebca7
- change master toctree test + remove rst (build fail)
PaulBautin May 17, 2021
68406a1
- replace index as master doc
PaulBautin May 17, 2021
1a35521
- test remove hidden
PaulBautin May 17, 2021
c4decbb
- add overview in index file
PaulBautin May 17, 2021
c01b87c
- remove overview file
PaulBautin May 17, 2021
eb20833
- test glob on toctree
PaulBautin May 17, 2021
7018e73
- change into to introduction
PaulBautin May 17, 2021
531d0a9
- index change back to hidden
PaulBautin May 17, 2021
ce9d6b1
- remove autofunction in sample size file
PaulBautin May 17, 2021
003c933
- remove autofunction in sample size file
PaulBautin May 20, 2021
c5671c2
- Change per subject to intra-subject and per scaling to inter-subject
PaulBautin May 20, 2021
70e9ff7
- Adjust text for each statistic
PaulBautin May 20, 2021
755fa88
- remove README from file doc
PaulBautin May 20, 2021
76fa102
- move quality control to RTD
PaulBautin May 27, 2021
3045ced
- move quality control to RTD
PaulBautin May 27, 2021
5b3dd4e
- update formula to match manuscript
PaulBautin Jun 1, 2021
c52875c
- add brace on formula
PaulBautin Jun 1, 2021
e0b973c
- add brace on formula for inter
PaulBautin Jun 1, 2021
71f963e
- add brace on formula 3
PaulBautin Jun 1, 2021
d61e75e
- move quality control in statistics
PaulBautin Jun 1, 2021
8de1066
- change toctree maxdepth to 2
PaulBautin Jun 1, 2021
588aadc
- reverse toctree maxdepth
PaulBautin Jun 1, 2021
7b62bac
- add how to run
PaulBautin Jun 1, 2021
5841424
- changer placement dans index.rst
PaulBautin Jun 1, 2021
2f6f80b
- changer placement dans index.rst
PaulBautin Jun 1, 2021
ae912c3
- add title to how to run
PaulBautin Jun 1, 2021
d33e825
- update link to spine generic
PaulBautin Jun 1, 2021
033688d
- remove plot results in README
PaulBautin Jun 1, 2021
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
55 changes: 3 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
![csa-atrophy](https://github.com/sct-pipeline/csa-atrophy/blob/master/csa_atrophy_scheme3.png)

[![Documentation Status](https://readthedocs.org/projects/sphinx/badge/?version=master)](https://csa-atrophy.readthedocs.io/en/latest/)

# csa-atrophy

Evaluate the sensitivity of atrophy detection with SCT. The algorithm works as follows:
- Consider subject I --> sI
- Applies a rescaling on the native image (e.g. 1, 0.95, 0.8) --> rX
- Applies random affine transformation --> tY
- Segment the cord
- Compute CSA --> CSA(sI, rX, tY)
The csa-atrophy framework aims to evaluate the robustness and the sensitivity of an automated analysis pipeline for detecting SC atrophy.

# How to run

Expand Down Expand Up @@ -45,50 +42,4 @@ To output statistics, run in Dataset
csa_rescale_stat -i csa_atrophy_results/results -o csa_atrophy_results -config config_script.yml -fig
~~~

# Quality Control

After running the analysis, check your Quality Control (QC) report by opening the file qc/index.html. Use the
“Search” feature of the QC report to quickly jump to segmentations or labeling results. If you spot issues
(wrong labeling), add their filenames in the 'config_correction.yml' file
(see https://spine-generic.rtfd.io/en/latest/analysis-pipeline.html for further indications). Then, manually create
labels in the cord at the level of inter-vertebral discs C1-C2, C2-C3, ..., C4-C5 with the command:
~~~
manual_correction -config config_correction.yml -path-in csa_atrophy_results/data_processed -path-out PATH_DATA
~~~
The bash script outputs all manual labelings to the derivatives directory in the dataset path defined in `path_data`.
It is now possible to re-run the whole process. With the command below labeling will use the manual corrections that
are present in the derivatives/ folder of the dataset, otherwise labeling will be done automatically.
~~~
sct_run_batch -config config_sct_run_batch.yml
~~~

# Statistics

After everything is done, compute stats:
Per-subject stat: Panda dataframe `df_sub`:
- intra-subject MEAN: MEAN[CSA(sI, rX, :)] --> MEAN_intra(sI, rX): `df_sub['mean']`
- intra-subject STD: STD[CSA(sI, rX, :)] --> STD_intra(sI, rX): `df_sub['std']`
- intra-subject COV: STD[CSA(sI, rX, :)] / MEAN[CSA(sI, rX, :)] --> COV_intra(sI, rX): `df_sub['cov']`
- rescale_estimated_subject MEAN: MEAN[CSA(sI, rX, :) / CSA(sI, 1, :)] --> MEAN_rescale_estimated_subject(sI, rX): `df_sub['rescale_estimated']`
- intra-subject error MEAN: MEAN[CSA(sI, rX, :)] - (rX^2 * MEAN[CSA(sI, 1, :)]) --> MEAN_error_intra(sI, rX): `df_sub['error']`
- intra-subject error in percentage MEAN: [MEAN[CSA(sI, rX, :)] - (rX^2 * MEAN[CSA(sI, 1, :)])] / MEAN[CSA(sI, rX, :)] --> MEAN_error_intra_perc(sI, rX): `df_sub['perc_error']`

Across-subject stats: Panda dataframe `df_rescale`
- intra-subject STD: MEAN[STD_intra(:, rX)] --> STD_intra(rX): `df_rescale['std_intra']`
- intra-subject COV: MEAN[COV_intra_sub(:, rX)] --> COV_intra(rX): `df_rescale['cov']`
- inter-subject STD: STD[MEAN_intra(:, rX)] --> STD_inter(rX): `df_rescale['std_inter']`
- rescale_estimated (across subjects) MEAN: MEAN[MEAN_rescale_estimated_subject(:, rX)] --> MEAN_rescale_estimated(rX): `df_rescale['mean_rescale_estimated']`
- rescale_estimated (across subjects) STD: STD[MEAN_rescale_estimated_subject(:, rX)] --> STD_rescale_estimated(rX): `df_rescale['std_rescale_estimated']`
- error in percentage (across subjects) MEAN: MEAN[MEAN_error_intra(:, rX)]
- error in percentage (across subjects) STD: STD[MEAN_error_intra(:, rX)]

Power analysis:
- sample size: [(z(uncertainty) + z(power))^2 * (2 * STD[MEAN(:, rX)]^2)] / [MEAN[CSA(sI, 1, :)] - MEAN[CSA(sI, rX, :)]]

Plot results:
- STD_intersub
- Mean and STD inter-subject error percentage in function of rescaling
- sample size: minimum number of patients to detect an atrophy of X with Y% power and Z% uncertainty
- CSA values boxplot in function of rescaling
- Error values boxplot in function of rescaling

20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS =
SPHINXBUILD = python -msphinx
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
69 changes: 69 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('../..'))
sys.path.insert(0, os.path.abspath('../../csa-atrophy/'))


# -- Project information -----------------------------------------------------

project = 'csa-atrophy'
copyright = '2021, Paul Bautin'
author = 'Paul Bautin'

# The full version, including alpha/beta/rc tags
release = 'v1.0'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.inheritance_diagram',
'sphinx.ext.intersphinx',
'sphinx.ext.autosectionlabel',
'sphinx-jsonschema',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# The master toctree document.
master_doc = 'index'
Binary file added docs/csa_atrophy_scheme3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions docs/how_to_run.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
How to run?
============

This code has been tested using Python 3.7.

Download (or git clone) this repository:

.. code-block:: python

git clone https://github.com/sct-pipeline/csa-atrophy.git
cd csa-atrophy


Installation:
csa-atrophy requires specific python packages for computing statistics and processing images. If not already present on the computer's python environment such packages will automatically be installed by running pip command:

.. code-block:: python

pip install -e .

Download the results file from Spine Generic Multi-Subject dataset: https://github.com/spine-generic/data-multi-subject/releases/tag/r20201130 .

Edit the file `config_sct_run_batch.yml` according to your setup. Notable flags include:

* `path_data`: If you downloaded the spine-generic data at another location, make sure to update the path;
* `include_list`: If you only want to run the script in a few subjects, list them here. Example:
`include_list: ['sub-unf04', 'sub-unf05']`

See `sct_run_batch -h` to look at the available options.

Run the analysis:

.. code-block:: python

sct_run_batch -config config_sct_run_batch.yml


note: desired subjects using flag -include and in parallel processing using flag -jobs.

To output statistics, run in Dataset

.. code-block:: python

csa_rescale_stat -i csa_atrophy_results/results -o csa_atrophy_results -config config_script.yml -fig

29 changes: 29 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CSA-atrophy
============
CSA-atrophy evaluates the robustness and the sensitivity of an automated analysis pipeline for detecting SC atrophy. Notably, the proposed framework utilizes image scaling and applies a random rigid transformation to mimic subject repositioning (scan-rescan). This enables the quantification of the accuracy and precision of the estimated CSA across various degrees of simulated atrophy. As presented in section statistics, statistics from these experiments such as power analyses and minimum sample sizes are derived.

.. image:: csa_atrophy_scheme3.png

.. toctree::
:hidden:
:maxdepth: 1
:caption: How to run

how_to_run.rst

.. toctree::
:hidden:
:maxdepth: 1
:caption: Statistics

statistics/introduction.rst
statistics/intra_subject.rst
statistics/inter_subject.rst
statistics/sample_size.rst

.. toctree::
:hidden:
:maxdepth: 1
:caption: Quality Control

statistics/quality_control.rst
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
88 changes: 88 additions & 0 deletions docs/statistics/inter_subject.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Inter-subject
=============

Inter-subject statistics. These statistics are gathered per scaling in the Panda dataframe ``df_rescale``

Mean intra-subject SD
"""""""""""""""""""""

Intra-subject SD averaged across subjects.

:math:`\mu_s \{ \sigma_t \{ CSA_{rX} \} \}`

.. literalinclude:: ../../csa_rescale_stat.py
:language: python
:lines: 422-439
:emphasize-lines: 9

Mean intra-subject COV
""""""""""""""""""""""

Intra-subject COV averaged across subjects.

:math:`\mu_s \{ COV_t \{ CSA_{rX} \} \}`

.. literalinclude:: ../../csa_rescale_stat.py
:language: python
:lines: 422-439
:emphasize-lines: 10

Inter-subject SD
""""""""""""""""

SD of intra-subject CSA across subjects.

:math:`\sigma_s \{ \mu_t \{ CSA_{rX} \} \}`

.. literalinclude:: ../../csa_rescale_stat.py
:language: python
:lines: 422-439
:emphasize-lines: 11

Mean rescale estimated (RE)
"""""""""""""""""""""""""""

rescale_estimated averaged across subjects.

:math:`\mu_s \left \{ \mu_t \left\{ \frac{CSA_{rX}}{CSA_{r1}} \right\}\right\}`

.. literalinclude:: ../../csa_rescale_stat.py
:language: python
:lines: 422-439
:emphasize-lines: 12

SD of rescale estimated
"""""""""""""""""""""""

SD of rescale_estimated across subjects.

:math:`\sigma_s \left\{\mu_t \left\{ \frac{CSA_{rX}}{CSA_{r1}} \right\}\right\}`

.. literalinclude:: ../../csa_rescale_stat.py
:language: python
:lines: 422-439
:emphasize-lines: 13

Mean error
""""""""""

error on the intra-subject CSA estimation averaged across subjects.

:math:`\mu_s \{ \mu_t \{ CSA_{rX} \} - \mu_t \{ CSA_{r1} \cdot (rX)^2 \} \}`

.. literalinclude:: ../../csa_rescale_stat.py
:language: python
:lines: 422-439
:emphasize-lines: 14

SD of error
"""""""""""

SD of error on intra-subject CSA estimation across subjects.

:math:`\sigma_s \{ \mu_t \{ CSA_{rX} \} - \mu_t \{ CSA_{r1} \cdot (rX)^2 \} \}`

.. literalinclude:: ../../csa_rescale_stat.py
:language: python
:lines: 422-439
:emphasize-lines: 15
Loading