generated from SABS-R3/software-engineering-projects-pk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bbdcc21
Showing
15 changed files
with
456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[flake8] | ||
exclude= | ||
./.git, | ||
./pkmodel.egg-info, | ||
ignore= | ||
# Block comment should start with '# ' | ||
# Not if it's a commented out line | ||
E265, | ||
|
||
# "Do not assign a labmda expression, use a def". | ||
# This is a silly rule | ||
E731, | ||
|
||
# Ambiguous variable names | ||
# It's absolutely fine to have i and I | ||
E741, | ||
|
||
# List comprehension redefines variable | ||
# Re-using throw-away variables like `i`, `x`, etc. is a Good Idea | ||
F812, | ||
|
||
# Undefined name | ||
# Good rule, but the check doesn't support dynamically created variables | ||
F821, | ||
|
||
# Blank line at end of file | ||
# These can increase readability (in many editors) | ||
W391, | ||
|
||
# Binary operator on new line | ||
# This is now advised in pep8 | ||
W503, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# vim | ||
.vim/ | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 SABS-R3 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 2020-software-engineering-projects-pk | ||
starter pk modelling repository |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"""pkmodel is a Pharmokinetic modelling library. | ||
It contains functionality for creating, solving, and visualising the solution | ||
of Parmokinetic (PK) models | ||
""" | ||
# Import version info | ||
from .version_info import VERSION_INT, VERSION # noqa | ||
|
||
# Import main classes | ||
from .model import Model # noqa | ||
from .protocol import Protocol # noqa | ||
from .solution import Solution # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Model class | ||
# | ||
|
||
class Model: | ||
"""A Pharmokinetic (PK) model | ||
Parameters | ||
---------- | ||
value: numeric, optional | ||
an example paramter | ||
""" | ||
def __init__(self, value=42): | ||
self.value = value | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Protocol class | ||
# | ||
|
||
class Protocol: | ||
"""A Pharmokinetic (PK) protocol | ||
Parameters | ||
---------- | ||
value: numeric, optional | ||
an example paramter | ||
""" | ||
def __init__(self, value=43): | ||
self.value = value | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Solution class | ||
# | ||
|
||
class Solution: | ||
"""A Pharmokinetic (PK) model solution | ||
Parameters | ||
---------- | ||
value: numeric, optional | ||
an example paramter | ||
""" | ||
def __init__(self, value=44): | ||
self.value = value | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# | ||
# Test module for pkmodel. | ||
# | ||
# To run all tests, use ``python -m unittest discover``. | ||
# | ||
# To run a particular test, use e.g. | ||
# ``python -m unittest pkmodel.tests.test_model``. | ||
# | ||
# For this project, we chose to place the tests inside the code directory. See | ||
# https://stackoverflow.com/questions/61151/where-do-the-python-unit-tests-go | ||
# for an extended discussion. | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import unittest | ||
import pkmodel as pk | ||
|
||
|
||
class ModelTest(unittest.TestCase): | ||
""" | ||
Tests the :class:`Model` class. | ||
""" | ||
def test_create(self): | ||
""" | ||
Tests Model creation. | ||
""" | ||
model = pk.Model() | ||
self.assertEqual(model.value, 42) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import unittest | ||
import pkmodel as pk | ||
|
||
|
||
class ProtocolTest(unittest.TestCase): | ||
""" | ||
Tests the :class:`Protocol` class. | ||
""" | ||
def test_create(self): | ||
""" | ||
Tests Protocol creation. | ||
""" | ||
model = pk.Protocol() | ||
self.assertEqual(model.value, 43) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import unittest | ||
import pkmodel as pk | ||
|
||
|
||
class SolutionTest(unittest.TestCase): | ||
""" | ||
Tests the :class:`Solution` class. | ||
""" | ||
def test_create(self): | ||
""" | ||
Tests Solution creation. | ||
""" | ||
model = pk.Solution() | ||
self.assertEqual(model.value, 44) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# | ||
# Version information for pkmodel. | ||
# | ||
# See: https://packaging.python.org/guides/single-sourcing-package-version/ | ||
# | ||
# Version as a tuple (major, minor, revision) | ||
# - Changes to major are rare | ||
# - Changes to minor indicate new features, possible slight backwards | ||
# incompatibility | ||
# - Changes to revision indicate bugfixes, tiny new features | ||
VERSION_INT = 1, 0, 0 | ||
|
||
# String version of the version number | ||
VERSION = '.'.join([str(x) for x in VERSION_INT]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import matplotlib.pylab as plt | ||
import numpy as np | ||
import scipy.integrate | ||
|
||
def dose(t, X): | ||
return X | ||
|
||
def rhs(t, y, Q_p1, V_c, V_p1, CL, X): | ||
q_c, q_p1 = y | ||
transition = Q_p1 * (q_c / V_c - q_p1 / V_p1) | ||
dqc_dt = dose(t, X) - q_c / V_c * CL - transition | ||
dqp1_dt = transition | ||
return [dqc_dt, dqp1_dt] | ||
|
||
model1_args = { | ||
'name': 'model1', | ||
'Q_p1': 1.0, | ||
'V_c': 1.0, | ||
'V_p1': 1.0, | ||
'CL': 1.0, | ||
'X': 1.0, | ||
} | ||
|
||
model2_args = { | ||
'name': 'model2', | ||
'Q_p1': 2.0, | ||
'V_c': 1.0, | ||
'V_p1': 1.0, | ||
'CL': 1.0, | ||
'X': 1.0, | ||
} | ||
|
||
t_eval = np.linspace(0, 1, 1000) | ||
y0 = np.array([0.0, 0.0]) | ||
|
||
fig = plt.figure() | ||
for model in [model1_args, model2_args]: | ||
args = [ | ||
model['Q_p1'], model['V_c'], model['V_p1'], model['CL'], model['X'] | ||
] | ||
sol = scipy.integrate.solve_ivp( | ||
fun=lambda t, y: rhs(t, y, *args), | ||
t_span=[t_eval[0], t_eval[-1]], | ||
y0=y0, t_eval=t_eval | ||
) | ||
plt.plot(sol.t, sol.y[0, :], label=model['name'] + '- q_c') | ||
plt.plot(sol.t, sol.y[1, :], label=model['name'] + '- q_p1') | ||
|
||
plt.legend() | ||
plt.ylabel('drug mass [ng]') | ||
plt.xlabel('time [h]') | ||
plt.show() |
Oops, something went wrong.