Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PK_Optimizer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tu, Ethan
PK_Optimizer
Commits
539e4c8d
Commit
539e4c8d
authored
5 years ago
by
Tu, Ethan
Browse files
Options
Downloads
Patches
Plain Diff
Replace pk1Comp.py
parent
88849c2f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pk_optimizer/pk1Comp.py
+19
-47
19 additions, 47 deletions
pk_optimizer/pk1Comp.py
with
19 additions
and
47 deletions
pk_optimizer/pk1Comp.py
+
19
−
47
View file @
539e4c8d
#!/usr/bin/env python
# coding: utf-8
# In[1]:
# Import commands
from
scipy.stats
import
gamma
import
numpy
as
np
...
...
@@ -16,7 +13,7 @@ class pk1Comp:
"""
The pk1Comp object is a one compartment PK model that outputs graphs of mass of tracer over time.
"""
def
__init__
(
self
,
numParam
=
4
,
Flow
=
1
,
V
p
=
0.1
,
Visf
=
0.5
,
PS
=
0.15
):
def
__init__
(
self
,
numParam
=
4
,
Flow
=
1
,
V
ol
=
0.5
,
PS
=
0.15
):
"""
Initializes the model with default parameter values for flow, Vp, Visf, and PS.
Parameters
...
...
@@ -36,24 +33,26 @@ class pk1Comp:
PS : double
PS is the permeability-surface area constant in mL/(g*min). Defaults to 0.15.
"""
if
numParam
<=
0
or
Flow
<=
0
or
Vol
<
0
or
PS
<
0
or
PS
>
10
or
Vol
>
10
:
raise
ValueError
(
"
Input values are incorrect.
"
)
# Declare Variables for initial conditions
self
.
numParam
=
numParam
self
.
Flow
=
Flow
self
.
Vp
=
Vp
self
.
Visf
=
Visf
self
.
Vol
=
Vol
self
.
PS
=
PS
C0
=
0
# Initial concentration of tracer in plasma
tmax
=
10
#Time in seconds
dt
=
0.
1
#Time step
a
=
2.
# Alpha for gamma distribution
rv
=
gamma
(
a
,
loc
=
2
,
scale
=
0.65
)
#input function
self
.
C0
=
0
# Initial concentration of tracer in plasma
self
.
tmax
=
10
#Time in seconds
self
.
dt
=
1
#Time step
self
.
a
=
2.
# Alpha for gamma distribution
self
.
rv
=
gamma
(
self
.
a
,
loc
=
2
,
scale
=
0.65
)
#input function
self
.
sol
=
[]
# Define the time array
time
=
np
.
arange
(
0
,
tmax
+
dt
,
dt
)
self
.
time
=
np
.
arange
(
0
,
self
.
tmax
+
self
.
dt
,
self
.
dt
)
# Derivative function
def
derivs
(
curr_vals
,
time
):
def
derivs
(
self
,
curr_vals
,
time
):
"""
Finds derivatives of ODEs.
Parameters
...
...
@@ -71,13 +70,13 @@ class pk1Comp:
"""
# Define value of input function Cin
Cin
=
rv
.
pdf
(
time
)
Cin
=
self
.
rv
.
pdf
(
time
)
# Unpack the current values of the variables we wish to "update" from the curr_vals list
C
=
curr_vals
# Right-hand side of odes, which are used to computer the derivative
dC_dt
=
f
low
*
(
Cin
-
C
)
/
Vol
dC_dt
=
self
.
F
low
*
(
Cin
-
C
)
/
self
.
Vol
#Cout = C
return
dC_dt
...
...
@@ -93,8 +92,8 @@ class pk1Comp:
# Plot the results using the values stored in the solution variable, "sol"
# Plot Cp using the "0" element from the solution
plt
.
figure
(
1
)
plt
.
plot
(
time
,
rv
.
pdf
(
time
),
color
=
'
blue
'
,
label
=
'
Input Function
'
)
plt
.
plot
(
time
,
sol
[:,
0
],
color
=
"
green
"
,
label
=
'
Cout
'
)
plt
.
plot
(
self
.
time
,
self
.
rv
.
pdf
(
self
.
time
),
color
=
'
blue
'
,
label
=
'
Input Function
'
)
plt
.
plot
(
self
.
time
,
self
.
sol
[:,
0
],
color
=
"
green
"
,
label
=
'
Cout
'
)
# Plot Cisf using the "1" element from the solution
#plt.plot(time, sol[:,1],color="purple", label = 'Cisf')
...
...
@@ -107,34 +106,7 @@ class pk1Comp:
"""
Main function to run and solve ODEs
"""
# Store the initial values in a list
init
=
[
C0
]
init
=
[
self
.
C0
]
# Solve the odes with odeint
sol
=
odeint
(
derivs
,
init
,
time
)
#Mass_plasma = Vp * sol[:,0] #mass of tracer in plasma
#Mass_isf = Visf * sol[:,1] #mass of tracer in isf
#Tp = Vp/(flow + PS) # mean transit time
#E = 1 - np.exp(-PS/flow) #extraction fraction
#Q = Mass_plasma + Mass_isf
#print('The mean transit time is ' + str(Tp))
#print('The extraction fraction is ' + str(E))
# Plot mass of tracer using the "2" element from the solution
#plt.figure(2)
#plt.plot(time, Mass_plasma,color="red", label = 'Plasma')
# Plot mass of tracer in tissue using the "3" element from the solution
#plt.plot(time, Mass_isf,color="black", label = 'Interstitial Space')
#plt.plot(time, Q, color="blue", label = 'Total mass')
#plt.xlabel('Time [s]')
#plt.ylabel('Mass [mg]')
#plt.legend(loc = 'best')
#plt.grid()
# In[ ]:
self
.
sol
=
odeint
(
self
.
derivs
,
init
,
self
.
time
).
round
(
4
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment