Skip to content

Commit

Permalink
merged from format and lint branch
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedNasser8 committed Jun 10, 2024
2 parents 1b6cc1d + 8350e3d commit 93155ca
Show file tree
Hide file tree
Showing 86 changed files with 1,211 additions and 960 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ✨ Idea [Feature request]
name: ✨ Idea [Feature request]
description: Tell us about the idea you have !
title: "[Feature] <title>"
labels: [idea]
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Docs
run-name: "Updating Docs as ${{ github.actor }} has pushed changes to main"
on:
push:
branches:
branches:
- main

jobs:
Expand Down Expand Up @@ -43,4 +43,3 @@ jobs:
force_orphan: true

- run: echo "Status of job = ${{ job.status }}."

23 changes: 23 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Lint and Auto-Fix Code

on:
push:
pull_request:
branches:
- main

jobs:

pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3

- name: Install pre-commit
run: pip install pre-commit

- name: Run pre-commit
run: pre-commit run --all-files
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea/
/.venv
dist
pytest_cache
src/osipi/__pycache__
tests/__pycache__
src/osipi/__pycache__
32 changes: 32 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.8 # Use the latest version
hooks:
- id: ruff
args: [--fix] # Optional: to enable lint fixes
- id: ruff-format
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
args:
- --exclude=venv,.git,__pycache__,.eggs,.mypy_cache,.pytest_cache
- --max-line-length=100
- --ignore=E203
- --per-file-ignores=__init__.py:F401
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml

- repo: https://github.com/rstcheck/rstcheck
rev: v6.1.2 # Use the latest version
hooks:
- id: rstcheck
entry: rstcheck --ignore-messages="(Hyperlink target .* is not referenced.|No directive entry for
.*|Unknown directive type .*|Duplicate explicit target name.*)"
args: [
"--ignore-roles", "ref",
]
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,11 @@ We welcome contributions to OSIPI! To contribute, follow these steps:
- `pip install poetry`
- `poetry install`
- `poetry shell`

- Make your changes and commit them with descriptive messages.
- Push your changes to your fork.
- Submit a pull request to the main OSIPI repository.
#### As mentioned before, this project is still in the early stages of development. If you'd like to contribute by adding functionality, we recommend opening an issue first to discuss your proposed functionality and the best ways to implement it.
#### As mentioned before, this project is still in the early stages of development. If you'd like to contribute by adding functionality, we recommend opening an issue first to discuss your proposed functionality and the best ways to implement it.

## Details
For more detail please see the [documentation](https://osipi.github.io/pypi/).









2 changes: 0 additions & 2 deletions docs/examples/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ Examples
########

Illustrating common use cases of osipi.


2 changes: 0 additions & 2 deletions docs/examples/aif/README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
************************
Arterial Input Functions
************************


40 changes: 21 additions & 19 deletions docs/examples/aif/plot_aif_parker.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
"""
======================================
The Parker AIF - a play with variables
======================================
"""======================================
The Parker AIF - a play with variables ====================================== Simulating a Parker
AIF with different settings.
Simulating a Parker AIF with different settings.
"""

import matplotlib.pyplot as plt

# %%
# Import necessary packages
import numpy as np
import matplotlib.pyplot as plt
import osipi

# %%
# Generate synthetic AIF with default settings and plot the result.

# Define time points in units of seconds - in this case we use a time resolution of 0.5 sec and a total duration of 6 minutes.
t = np.arange(0, 6*60, 0.5)
# Define time points in units of seconds - in this case we use a time
# resolution of 0.5 sec and a total duration of 6 minutes.
t = np.arange(0, 6 * 60, 0.5)

# Create an AIF with default settings
ca = osipi.aif_parker(t)

# Plot the AIF over the full range
plt.plot(t, ca, 'r-')
plt.plot(t, 0*t, 'k-')
plt.xlabel('Time (sec)')
plt.ylabel('Plasma concentration (mM)')
plt.plot(t, ca, "r-")
plt.plot(t, 0 * t, "k-")
plt.xlabel("Time (sec)")
plt.ylabel("Plasma concentration (mM)")
plt.show()

# %%
# The bolus arrival time (BAT) defaults to 0s. What happens if we change it? Let's try, by changing it in steps of 30s:
# The bolus arrival time (BAT) defaults to 0s. What happens if we
# change it? Let's try, by changing it in steps of 30s:

ca = osipi.aif_parker(t, BAT=0)
plt.plot(t, ca, 'b-', label='BAT = 0s')
plt.plot(t, ca, "b-", label="BAT = 0s")
ca = osipi.aif_parker(t, BAT=30)
plt.plot(t, ca, 'r-', label='BAT = 30s')
plt.plot(t, ca, "r-", label="BAT = 30s")
ca = osipi.aif_parker(t, BAT=60)
plt.plot(t, ca, 'g-', label='BAT = 60s')
plt.plot(t, ca, "g-", label="BAT = 60s")
ca = osipi.aif_parker(t, BAT=90)
plt.plot(t, ca, 'm-', label='BAT = 90s')
plt.xlabel('Time (sec)')
plt.ylabel('Plasma concentration (mM)')
plt.plot(t, ca, "m-", label="BAT = 90s")
plt.xlabel("Time (sec)")
plt.ylabel("Plasma concentration (mM)")
plt.legend()
plt.show()

Expand Down
33 changes: 18 additions & 15 deletions docs/examples/aif/plot_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,47 @@
A dummy script
==============
Dummy script to illustrate structure of examples folder
Dummy script to illustrate structure of examples folder
"""

import matplotlib.pyplot as plt

# %%
# Import necessary packages
import numpy as np
import matplotlib.pyplot as plt
import osipi

# %%
# Generate synthetic AIF with default settings and plot the result.

# Define time points in units of seconds - in this case we use a time resolution of 0.5 sec and a total duration of 6 minutes.
t = np.arange(0, 6*60, 0.5)
# Define time points in units of seconds - in this case we use a time
# resolution of 0.5 sec and a total duration of 6 minutes.
t = np.arange(0, 6 * 60, 0.5)

# Create an AIF with default settings
ca = osipi.aif_parker(t)

# Plot the AIF over the full range
plt.plot(t, ca, 'r-')
plt.plot(t, 0*t, 'k-')
plt.xlabel('Time (sec)')
plt.ylabel('Plasma concentration (mM)')
plt.plot(t, ca, "r-")
plt.plot(t, 0 * t, "k-")
plt.xlabel("Time (sec)")
plt.ylabel("Plasma concentration (mM)")
plt.show()

# %%
# The bolus arrival time (BAT) defaults to 30s. What happens if we change it? Let's try, by changing it in steps of 30s:
# The bolus arrival time (BAT) defaults to 30s. What happens if we
# change it? Let's try, by changing it in steps of 30s:

ca = osipi.aif_parker(t, BAT=0)
plt.plot(t, ca, 'b-', label='BAT = 0s')
plt.plot(t, ca, "b-", label="BAT = 0s")
ca = osipi.aif_parker(t, BAT=30)
plt.plot(t, ca, 'r-', label='BAT = 30s')
plt.plot(t, ca, "r-", label="BAT = 30s")
ca = osipi.aif_parker(t, BAT=60)
plt.plot(t, ca, 'g-', label='BAT = 60s')
plt.plot(t, ca, "g-", label="BAT = 60s")
ca = osipi.aif_parker(t, BAT=90)
plt.plot(t, ca, 'm-', label='BAT = 90s')
plt.xlabel('Time (sec)')
plt.ylabel('Plasma concentration (mM)')
plt.plot(t, ca, "m-", label="BAT = 90s")
plt.xlabel("Time (sec)")
plt.ylabel("Plasma concentration (mM)")
plt.legend()
plt.show()

Expand Down
2 changes: 0 additions & 2 deletions docs/examples/tissue/README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
*********************
Tissue concentrations
*********************


42 changes: 23 additions & 19 deletions docs/examples/tissue/plot_extended_tofts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,50 @@
Simulating tissue concentrations from extended Tofts model with different settings.
"""

import matplotlib.pyplot as plt

# %%
# Import necessary packages
import numpy as np
import matplotlib.pyplot as plt
import osipi

# %%
# Generate Parker AIF with default settings.

# Define time points in units of seconds - in this case we use a time resolution of 1 sec and a total duration of 6 minutes.
t = np.arange(0, 6*60, 1)
# Define time points in units of seconds - in this case we use a time
# resolution of 1 sec and a total duration of 6 minutes.
t = np.arange(0, 6 * 60, 1)

# Create an AIF with default settings
ca = osipi.aif_parker(t)

# %%
# Plot the tissue concentrations for an extracellular volume fraction of 0.2 and 3 different plasma volumes of 0.05, 0.2 and 0.6
Ktrans = 0.2 # in units of 1/min
# Plot the tissue concentrations for an extracellular volume fraction
# of 0.2 and 3 different plasma volumes of 0.05, 0.2 and 0.6
Ktrans = 0.2 # in units of 1/min
ve = 0.2 # volume fraction between 0 and 1
vp = [0.05, 0.2, 0.6] # volume fraction between 0 and 1
vp = [0.05, 0.2, 0.6] # volume fraction between 0 and 1
ct = osipi.extended_tofts(t, ca, Ktrans, ve, vp[0])
plt.plot(t, ct, 'b-', label=f'vp = {vp[0]}')
plt.plot(t, ct, "b-", label=f"vp = {vp[0]}")
ct = osipi.extended_tofts(t, ca, Ktrans, ve, vp[1])
plt.plot(t, ct, 'g-', label=f'vp = {vp[1]}')
plt.plot(t, ct, "g-", label=f"vp = {vp[1]}")
ct = osipi.extended_tofts(t, ca, Ktrans, ve, vp[2])
plt.plot(t, ct, 'm-', label=f'vp = {vp[2]}')
plt.xlabel('Time (sec)')
plt.ylabel('Tissue concentration (mM)')
plt.plot(t, ct, "m-", label=f"vp = {vp[2]}")
plt.xlabel("Time (sec)")
plt.ylabel("Tissue concentration (mM)")
plt.legend()
plt.show()

# %%
# Comparing different discretization methods for an extracellular volume fraction of 0.2, Ktrans of 0.2 /min and vp of 0.05
ct = osipi.extended_tofts(t, ca, Ktrans, ve, vp[0]) # Defaults to Convolution
plt.plot(t, ct, 'b-', label='Convolution')
ct = osipi.extended_tofts(t, ca, Ktrans, ve, vp[0], discretization_method='exp')
plt.plot(t, ct, 'g-', label='Exponential Convolution')
plt.title(f'Ktrans = {Ktrans} /min')
plt.xlabel('Time (sec)')
plt.ylabel('Tissue concentration (mM)')
# Comparing different discretization methods for an extracellular
# volume fraction of 0.2, Ktrans of 0.2 /min and vp of 0.05
ct = osipi.extended_tofts(t, ca, Ktrans, ve, vp[0]) # Defaults to Convolution
plt.plot(t, ct, "b-", label="Convolution")
ct = osipi.extended_tofts(t, ca, Ktrans, ve, vp[0], discretization_method="exp")
plt.plot(t, ct, "g-", label="Exponential Convolution")
plt.title(f"Ktrans = {Ktrans} /min")
plt.xlabel("Time (sec)")
plt.ylabel("Tissue concentration (mM)")
plt.legend()
plt.show()

Expand Down
39 changes: 22 additions & 17 deletions docs/examples/tissue/plot_tofts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,50 @@
Simulating tissue concentrations from Tofts model with different settings.
"""

import matplotlib.pyplot as plt

# %%
# Import necessary packages
import numpy as np
import matplotlib.pyplot as plt
import osipi

# %%
# Generate Parker AIF with default settings.

# Define time points in units of seconds - in this case we use a time resolution of 1 sec and a total duration of 6 minutes.
t = np.arange(0, 6*60, 1)
# Define time points in units of seconds - in this case we use a time
# resolution of 1 sec and a total duration of 6 minutes.
t = np.arange(0, 6 * 60, 1)

# Create an AIF with default settings
ca = osipi.aif_parker(t)

# %%
# Plot the tissue concentrations for an extracellular volume fraction of 0.2 and 3 different transfer rate constants of 0.05, 0.2 and 0.6 /min
# Plot the tissue concentrations for an extracellular volume fraction
# of 0.2 and 3 different transfer rate constants of 0.05, 0.2 and 0.6
# /min
Ktrans = [0.05, 0.2, 0.6] # in units of 1/min
ve = 0.2 # volume fraction between 0 and 1
ct = osipi.tofts(t, ca, Ktrans=Ktrans[0], ve=ve)
plt.plot(t, ct, 'b-', label=f'Ktrans = {Ktrans[0]} /min')
plt.plot(t, ct, "b-", label=f"Ktrans = {Ktrans[0]} /min")
ct = osipi.tofts(t, ca, Ktrans[1], ve)
plt.plot(t, ct, 'g-', label=f'Ktrans = {Ktrans[1]} /min')
plt.plot(t, ct, "g-", label=f"Ktrans = {Ktrans[1]} /min")
ct = osipi.tofts(t, ca, Ktrans[2], ve)
plt.plot(t, ct, 'm-', label=f'Ktrans = {Ktrans[2]} /min')
plt.xlabel('Time (sec)')
plt.ylabel('Tissue concentration (mM)')
plt.plot(t, ct, "m-", label=f"Ktrans = {Ktrans[2]} /min")
plt.xlabel("Time (sec)")
plt.ylabel("Tissue concentration (mM)")
plt.legend()
plt.show()

# %%
# Comparing different discretization methods for an extracellular volume fraction of 0.2 and Ktrans of 0.2 /min
ct = osipi.tofts(t, ca, Ktrans=Ktrans[1], ve=ve) # Defaults to Convolution
plt.plot(t, ct, 'b-', label='Convolution')
ct = osipi.tofts(t, ca, Ktrans=Ktrans[1], ve=ve, discretization_method='exp')
plt.plot(t, ct, 'g-', label='Exponential Convolution')
plt.title(f'Ktrans = {Ktrans[1]} /min')
plt.xlabel('Time (sec)')
plt.ylabel('Tissue concentration (mM)')
# Comparing different discretization methods for an extracellular
# volume fraction of 0.2 and Ktrans of 0.2 /min
ct = osipi.tofts(t, ca, Ktrans=Ktrans[1], ve=ve) # Defaults to Convolution
plt.plot(t, ct, "b-", label="Convolution")
ct = osipi.tofts(t, ca, Ktrans=Ktrans[1], ve=ve, discretization_method="exp")
plt.plot(t, ct, "g-", label="Exponential Convolution")
plt.title(f"Ktrans = {Ktrans[1]} /min")
plt.xlabel("Time (sec)")
plt.ylabel("Tissue concentration (mM)")
plt.legend()
plt.show()

Expand Down
Loading

0 comments on commit 93155ca

Please sign in to comment.