Skip to content

Commit

Permalink
Merge branch 'created_repostatus/statistics' of https://github.com/ab…
Browse files Browse the repository at this point in the history
…hicodes369/TF2.4_IVIM-MRI_CodeCollection into created_repostatus/statistics
  • Loading branch information
abhicodes369 committed Apr 16, 2024
2 parents 4a148b8 + 06167e7 commit e17a3e7
Show file tree
Hide file tree
Showing 20 changed files with 3,173 additions and 92 deletions.
39 changes: 39 additions & 0 deletions .github/actions/download-artifact/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Download Artifact
description: Download artifact from the same or different workflow

inputs:
name:
description: Artifact to be downloaded
required: true
type: string

runs:
using: composite
steps:
- name: Download Artifact
uses: actions/github-script@v6
with:
script: |
var inputs = ${{ toJSON(inputs) }}
var artifactName = inputs['name']
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == artifactName
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifactName}.zip`, Buffer.from(download.data));
- name: 'Unzip artifact'
run: unzip ${{ inputs.name }}.zip
shell: bash
41 changes: 18 additions & 23 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: 'pip'
# - name: Cache virtualenv
# uses: actions/cache@v3
# with:
# key: venv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version}}-${{ hashFiles('requirements.txt') }}
# path: .venv
- name: Cache pip
uses: actions/cache@v3
id: pip-cache
with:
key: ${{ runner.os }}-${{ env.pythonLocation }}-pip-${{ hashFiles('**/requirements.txt') }}
path: ${{ env.pythonLocation }}
if: steps.pip-cache.outputs.cache-hit != 'true'

- name: Install dependencies
run: |
python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
python -m pip install pytest
pip install -r requirements.txt
- name: Read algorithms
id: algorithms
run: |
Expand Down Expand Up @@ -58,21 +58,16 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: 'pip'
# - name: Cache virtualenv
# uses: actions/cache@v3
# with:
# key: venv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version}}-${{ hashFiles('requirements.txt') }}
# path: .venv
- name: Install dependencies
run: |
python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
python -m pip install pytest
if: steps.pip-cache.outputs.cache-hit != 'true'
- name: Restore cache
id: python-cache
uses: actions/cache@v3
with:
key: ${{ runner.os }}-${{ env.pythonLocation }}-pip-${{ hashFiles('**/requirements.txt') }}
path: ${{ env.pythonLocation }}

- name: Generate fitting data
run: |
source .venv/bin/activate
python -m pytest -m slow --selectAlgorithm ${{ matrix.algorithm }} --saveFileName test_output_${{ matrix.algorithm }}_${{ matrix.SNR }}.csv --SNR ${{ matrix.SNR }} --fitCount 300 --saveDurationFileName test_duration_${{ matrix.algorithm }}_${{ matrix.SNR }}.csv
- name: Upload raw data
uses: actions/upload-artifact@v3
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build & Deploy Documentation

on:
workflow_run:
workflows: [Algorithm Analysis]
types:
- completed
permissions:
contents: read
pages: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Set up Python
id: setup_python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Cache pip
uses: actions/cache@v3
id: pip-cache
with:
key: ${{ runner.os }}-${{ env.pythonLocation }}-pip-${{ hashFiles('**/requirements.txt') }}
path: ${{ env.pythonLocation }}
if: steps.pip-cache.outputs.cache-hit != 'true'

- name: Install dependencies
run: |
pip install -r requirements.txt
# Action to download artifacts from a different workflow (analysis.yml)
- name: 'Download artifact'
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: ./.github/actions/download-artifact
with:
name: 'Figures'

- name: Build html
run: |
mkdir docs/_static
mv *.pdf docs/_static/
sphinx-apidoc -o docs src
cd docs/
make html
- name: Upload docs artifact
uses: actions/upload-pages-artifact@v3
with:
path: 'docs/_build/html'

deploy:
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ __pycache__/
*.mat
*.raw
bvals.txt
download
md5sums.txt
*.gz
*.zip
*.tmp

# Unit test / coverage reports
.tox/
.coverage
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ The **utils** folder contains various helpful tools.

## View Testing Reports
[![Unit tests](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/unit_test.yml/badge.svg?branch=main)](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/unit_test.yml)
[![Algorithm Analysis](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/analysis.yml/badge.svg?branch=main)](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/analysis.yml)
[![Algorithm Analysis](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/analysis.yml/badge.svg?branch=main)](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/analysis.yml)
[![Build & Deploy Documentation](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/documentation.yml/badge.svg?branch=main)](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/documentation.yml)
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 ?= sphinx-build
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)
36 changes: 36 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import os
import sys

sys.path.insert(0, os.path.abspath(".."))

project = 'TF2.4 IVIM MRI Code Collection'
copyright = '2024, OSIPI'
author = 'OSIPI team'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ["sphinx.ext.todo", "sphinx.ext.viewcode", "sphinx.ext.autodoc"]

templates_path = ['_templates']
exclude_patterns = ['Thumbs.db', '.DS_Store']

# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
html_show_sphinx = False

# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
html_show_copyright = False

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
45 changes: 45 additions & 0 deletions docs/figures.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Algorithm Analysis Figures
===========

.. raw:: html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Algorithm Analysis Figures</title>
<style>
embed {
width: 90%;
margin-bottom: 4rem;
height: 100vh;
}
</style>
</head>
<body>
<h4>Diffusion grid for limited algorithms:</h4>
<embed src="_static/D_limited.pdf" type="application/pdf" frameborder="0" scrolling="auto">
<h4>Diffusion grid for all algorithms:</h4>
<embed src="_static/D.pdf" type="application/pdf" frameborder="0" scrolling="auto">

<h4>Perfusion grid for limited algorithms:</h4>
<embed src="_static/Dp_limited.pdf" type="application/pdf" frameborder="0" scrolling="auto">
<h4>Perfusion grid for all algorithms:</h4>
<embed src="_static/Dp.pdf" type="application/pdf" frameborder="0" scrolling="auto">

<h4>Perfusion fraction grid for limited algorithms:</h4>
<embed src="_static/f_limited.pdf" type="application/pdf" frameborder="0" scrolling="auto">
<h4>Perfusion fraction grid for all algorithms:</h4>
<embed src="_static/f.pdf" type="application/pdf" frameborder="0" scrolling="auto">

<h4>Fitted curves:</h4>
<embed src="_static/fitted_curves.pdf" type="application/pdf" frameborder="0" scrolling="auto">
<h4>Curve plot:</h4>
<embed src="_static/curve_plot.pdf" type="application/pdf" frameborder="0" scrolling="auto">
<h4>Algorithm Fitting duration:</h4>
<embed src="_static/durations.pdf" type="application/pdf" frameborder="0" scrolling="auto">

</body>
</html>
19 changes: 19 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. TF2.4 IVIM MRI Code Collection documentation master file, created by
sphinx-quickstart on Wed Mar 6 00:06:13 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to TF2.4 IVIM MRI Code Collection's documentation!
==========================================================

.. toctree::
:maxdepth: 4
:caption: Contents:

figures
modules

Indices and tables
==================

* :ref:`modindex`
62 changes: 61 additions & 1 deletion phantoms/MR_XCAT_qMRI/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
# MR_XCAT_qMRI
# 4D IVIM Phantom Generator

A command-line tool for generating a 4D IVIM (Intravoxel Incoherent Motion) phantom as a NIfTI file.

## Usage

```sh
python sim_vim_sig.py [-h] [-b BVALUE [BVALUE ...] | -f FILE] [-n NOISE] [-m] [-i]
```

## Arguments

- `-b`, `--bvalue` : B values (list of numbers)
- `-f`, `--bvalues-file` : JSON file containing the B values (default: b_values.json)
- `-n`, `--noise` : Noise level (default: 0.0005)
- `-m`, `--motion` : Enable motion flag (default: False)
- `-i`, `--interleaved` : Enable interleaved flag (default: False)

**Note:** Either provide `--bvalue` or `--bvalues-file`, not both.

If neither `--bvalues-file` nor `--bvalue` is provided, the script will use the default `b_values.json` file.

## Customizing B Values

You can customize the B values by editing the `b_values.json` file. Here's an example of the default format:

```json
{
"original": [0.0, 1.0, 2.0, 5.0, 10.0, 20.0, 30.0, 50.0, 75.0, 100.0, 150.0, 250.0, 350.0, 400.0, 550.0, 700.0, 850.0, 1000.0],
"one": [0.0, 1.0, 2.0, 5.0, 10.0, 20.0, 30.0, 50.0, 75.0, 100.0, 150.0, 250.0, 350.0, 400.0, 550.0, 700.0, 850.0, 1000.0, 1100.0, 1200.0],
"two": [0.0, 1.0, 2.0, 5.0, 10.0, 20.0, 30.0, 50.0, 75.0, 100.0, 150.0, 250.0, 350.0, 400.0, 500.0, 700.0, 800.0, 1000.0, 1100.0, 1200.0],
"three": [0.0, 1.0, 2.0, 5.0, 10.0, 20.0, 30.0, 50.0, 75.0, 100.0, 150.0, 250.0, 350.0, 450.0, 550.0, 675.0, 800.0],
"four": [0.0, 1.0, 2.0, 5.0, 10.0, 20.0, 30.0, 50.0, 75.0, 100.0, 150.0, 250.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0]
}
```

You can add or remove values as needed for your simulation. Here are the effects of customizing the B values for each of the generic profiles (`generic.json`, `generic_one.json`, `generic_two.json`, `generic_three.json`, `generic_four.json`):

The default `generic_<custom_name>.json` file can be found in the following location:

```
TF2.4_IVIM-MRI_CodeCollection/tests/IVIMmodels/unit_tests
```

## Running the Script

To run the script, you can add the following line to your shell configuration file (e.g., `.bashrc` or `.zshrc`) to include the necessary directory in your `PYTHONPATH`:

```sh
export PYTHONPATH=$PYTHONPATH:~/TF2.4_IVIM-MRI_CodeCollection
```

Replace `~/TF2.4_IVIM-MRI_CodeCollection` with the actual path to the directory containing the script.

## Example

```sh
python sim_ivim_sig.py -n 0.0001 -m
```

This command will generate a 4D IVIM phantom using B values from the default `b_values.json` file, with a noise level of 0.0001 and motion enabled.
7 changes: 7 additions & 0 deletions phantoms/MR_XCAT_qMRI/b_values.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"original": [0.0, 1.0, 2.0, 5.0, 10.0, 20.0, 30.0, 50.0, 75.0, 100.0, 150.0, 250.0, 350.0, 400.0, 550.0, 700.0, 850.0, 1000.0],
"one": [0.0, 1.0, 2.0, 5.0, 10.0, 20.0, 30.0, 50.0, 75.0, 100.0, 150.0, 250.0, 350.0, 400.0, 550.0, 700.0, 850.0, 1000.0, 1100.0, 1200.0],
"two": [0.0, 1.0, 2.0, 5.0, 10.0, 20.0, 30.0, 50.0, 75.0, 100.0, 150.0, 250.0, 350.0, 400.0, 500.0, 700.0, 800.0, 1000.0, 1100.0, 1200.0],
"three": [0.0, 1.0, 2.0, 5.0, 10.0, 20.0, 30.0, 50.0, 75.0, 100.0, 150.0, 250.0, 350.0, 450.0, 550.0, 675.0, 800.0],
"four": [0.0, 1.0, 2.0, 5.0, 10.0, 20.0, 30.0, 50.0, 75.0, 100.0, 150.0, 250.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0]
}
Loading

0 comments on commit e17a3e7

Please sign in to comment.