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
b433d7a7
Commit
b433d7a7
authored
4 years ago
by
Tu, Ethan
Browse files
Options
Downloads
Patches
Plain Diff
made some modifications to gui
parent
9d236ffa
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/pk_gui.py
+52
-18
52 additions, 18 deletions
pk_optimizer/pk_gui.py
with
52 additions
and
18 deletions
pk_optimizer/pk_gui.py
+
52
−
18
View file @
b433d7a7
#!/usr/bin/env python
#!/usr/bin/env python
# coding: utf-8
# coding: utf-8
#!/usr/bin/env python
# coding: utf-8
"""
pk_GUI is a tool to compare, optimize, and visualize
"""
pk_GUI is a tool to compare, optimize, and visualize
two compartment models of perfusion kinetics
"""
two compartment models of perfusion kinetics
"""
### import everything
### import everything
...
@@ -181,8 +184,9 @@ class PkOptimize(tk.Toplevel):
...
@@ -181,8 +184,9 @@ class PkOptimize(tk.Toplevel):
# Creating blank canvas to plot input function on
# Creating blank canvas to plot input function on
self
.
fig1
=
plt
.
figure
(
figsize
=
(
4.5
,
4.5
),
dpi
=
100
)
self
.
fig1
=
plt
.
figure
(
figsize
=
(
4.5
,
4.5
),
dpi
=
100
)
plt
.
ylabel
(
"
Mass of Tracer (mg
)
"
)
plt
.
ylabel
(
"
Hounsfield Unit (Hu
)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
title
(
"
Input Function
"
)
self
.
canvas1
=
FigureCanvasTkAgg
(
self
.
fig1
,
master
=
self
.
frame2
)
self
.
canvas1
=
FigureCanvasTkAgg
(
self
.
fig1
,
master
=
self
.
frame2
)
self
.
canvas1
.
get_tk_widget
().
grid
(
row
=
0
,
column
=
0
)
self
.
canvas1
.
get_tk_widget
().
grid
(
row
=
0
,
column
=
0
)
...
@@ -190,8 +194,9 @@ class PkOptimize(tk.Toplevel):
...
@@ -190,8 +194,9 @@ class PkOptimize(tk.Toplevel):
# Creating blank canvas to plot output function on
# Creating blank canvas to plot output function on
self
.
fig2
=
plt
.
figure
(
figsize
=
(
4.5
,
4.5
),
dpi
=
100
)
self
.
fig2
=
plt
.
figure
(
figsize
=
(
4.5
,
4.5
),
dpi
=
100
)
plt
.
ylabel
(
"
Mass of Tracer (mg
)
"
)
plt
.
ylabel
(
"
Hounsfield Unit (Hu
)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
title
(
"
Output Function
"
)
self
.
canvas2
=
FigureCanvasTkAgg
(
self
.
fig2
,
master
=
self
.
frame4
)
self
.
canvas2
=
FigureCanvasTkAgg
(
self
.
fig2
,
master
=
self
.
frame4
)
self
.
canvas2
.
get_tk_widget
().
grid
(
row
=
0
,
column
=
0
)
self
.
canvas2
.
get_tk_widget
().
grid
(
row
=
0
,
column
=
0
)
...
@@ -275,13 +280,16 @@ class PkOptimize(tk.Toplevel):
...
@@ -275,13 +280,16 @@ class PkOptimize(tk.Toplevel):
self
.
pk
.
get_data
(
file
)
self
.
pk
.
get_data
(
file
)
self
.
fig1
.
add_subplot
(
111
).
plot
(
self
.
pk
.
time
,
self
.
pk
.
aorta
,
'
bo
'
)
self
.
fig1
.
add_subplot
(
111
).
plot
(
self
.
pk
.
time
,
self
.
pk
.
aorta
,
'
bo
'
)
plt
.
ylabel
(
"
Mass of Tracer (mg
)
"
)
plt
.
ylabel
(
"
Hounsfield Unit (Hu
)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
title
(
"
Input Function
"
)
self
.
fig1
.
canvas
.
draw
()
self
.
fig1
.
canvas
.
draw
()
self
.
fig2
.
add_subplot
(
111
).
plot
(
self
.
pk
.
time
,
self
.
pk
.
myo
,
'
ro
'
)
self
.
fig2
.
add_subplot
(
111
).
plot
(
self
.
pk
.
time
,
self
.
pk
.
myo
,
'
ro
'
)
plt
.
ylabel
(
"
Mass of Tracer (mg
)
"
)
plt
.
ylabel
(
"
Hounsfield (Hu
)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
title
(
"
Output Function
"
)
self
.
canvas2
.
draw_idle
()
self
.
canvas2
.
draw_idle
()
def
perform_opt
(
self
):
def
perform_opt
(
self
):
...
@@ -323,7 +331,7 @@ class PkOptimize(tk.Toplevel):
...
@@ -323,7 +331,7 @@ class PkOptimize(tk.Toplevel):
"""
Closes the optimize application and leads you to the start page
"""
"""
Closes the optimize application and leads you to the start page
"""
self
.
destroy
()
self
.
destroy
()
# ===============================================================================
class
PkCompare
(
tk
.
Toplevel
):
class
PkCompare
(
tk
.
Toplevel
):
"""
Initializes the pkCompare application GUI
"""
"""
Initializes the pkCompare application GUI
"""
def
__init__
(
self
,
parent
):
# , master_root):
def
__init__
(
self
,
parent
):
# , master_root):
...
@@ -384,8 +392,9 @@ class PkCompare(tk.Toplevel):
...
@@ -384,8 +392,9 @@ class PkCompare(tk.Toplevel):
# Creating blank canvas to plot input function on
# Creating blank canvas to plot input function on
self
.
fig1
=
plt
.
figure
(
figsize
=
(
4.5
,
4.5
),
dpi
=
100
)
self
.
fig1
=
plt
.
figure
(
figsize
=
(
4.5
,
4.5
),
dpi
=
100
)
plt
.
ylabel
(
"
Mass of Tracer (mg
)
"
)
plt
.
ylabel
(
"
Hounsfield Unit (Hu
)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
title
(
"
Input Function
"
)
self
.
canvas1
=
FigureCanvasTkAgg
(
self
.
fig1
,
master
=
self
.
frame2
)
self
.
canvas1
=
FigureCanvasTkAgg
(
self
.
fig1
,
master
=
self
.
frame2
)
self
.
canvas1
.
get_tk_widget
().
grid
(
row
=
0
,
column
=
0
)
self
.
canvas1
.
get_tk_widget
().
grid
(
row
=
0
,
column
=
0
)
...
@@ -395,8 +404,9 @@ class PkCompare(tk.Toplevel):
...
@@ -395,8 +404,9 @@ class PkCompare(tk.Toplevel):
# Creating blank canvas to plot output function on
# Creating blank canvas to plot output function on
self
.
fig2
=
plt
.
figure
(
figsize
=
(
4.5
,
4.5
),
dpi
=
100
)
self
.
fig2
=
plt
.
figure
(
figsize
=
(
4.5
,
4.5
),
dpi
=
100
)
plt
.
ylabel
(
"
Mass of Tracer (mg
)
"
)
plt
.
ylabel
(
"
Hounsfield Unit (Hu
)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
title
(
"
Output Function
"
)
self
.
canvas2
=
FigureCanvasTkAgg
(
self
.
fig2
,
master
=
self
.
frame4
)
self
.
canvas2
=
FigureCanvasTkAgg
(
self
.
fig2
,
master
=
self
.
frame4
)
self
.
canvas2
.
get_tk_widget
().
grid
(
row
=
0
,
column
=
0
)
self
.
canvas2
.
get_tk_widget
().
grid
(
row
=
0
,
column
=
0
)
...
@@ -430,12 +440,12 @@ class PkCompare(tk.Toplevel):
...
@@ -430,12 +440,12 @@ class PkCompare(tk.Toplevel):
self
.
pk
.
get_data
(
file
)
self
.
pk
.
get_data
(
file
)
self
.
fig1
.
add_subplot
(
111
).
plot
(
self
.
pk
.
time
,
self
.
pk
.
aorta
)
self
.
fig1
.
add_subplot
(
111
).
plot
(
self
.
pk
.
time
,
self
.
pk
.
aorta
)
plt
.
ylabel
(
"
Mass of Tracer (mg
)
"
)
plt
.
ylabel
(
"
Hounsfield Unit (Hu
)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
self
.
fig1
.
canvas
.
draw
()
self
.
fig1
.
canvas
.
draw
()
self
.
fig2
.
add_subplot
(
111
).
plot
(
self
.
pk
.
time
,
self
.
pk
.
myo
)
self
.
fig2
.
add_subplot
(
111
).
plot
(
self
.
pk
.
time
,
self
.
pk
.
myo
)
plt
.
ylabel
(
"
Mass of Tracer (mg
)
"
)
plt
.
ylabel
(
"
Hounsfield Unit (Hu
)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
self
.
canvas2
.
draw_idle
()
self
.
canvas2
.
draw_idle
()
...
@@ -458,7 +468,6 @@ class PkVisualize(tk.Toplevel):
...
@@ -458,7 +468,6 @@ class PkVisualize(tk.Toplevel):
Using the sliders to change parameter values will result in different
Using the sliders to change parameter values will result in different
Cin and Cout curves. You must hit plot after every change to see it.
Cin and Cout curves. You must hit plot after every change to see it.
"""
"""
super
().
__init__
(
name
=
'
pk Optimizer tool
'
)
super
().
__init__
(
name
=
'
pk Optimizer tool
'
)
self
.
parent
=
parent
self
.
parent
=
parent
...
@@ -507,13 +516,15 @@ class PkVisualize(tk.Toplevel):
...
@@ -507,13 +516,15 @@ class PkVisualize(tk.Toplevel):
# Creating blank canvas to plot input function on
# Creating blank canvas to plot input function on
self
.
fig1
=
plt
.
figure
(
figsize
=
(
4.5
,
4.5
),
dpi
=
100
)
self
.
fig1
=
plt
.
figure
(
figsize
=
(
4.5
,
4.5
),
dpi
=
100
)
plt
.
ylabel
(
"
Mass of Tracer (mg
)
"
)
plt
.
ylabel
(
"
Hounsfield Unit (Hu
)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
title
(
"
Input Function
"
)
# Creating blank canvas to plot output function on
# Creating blank canvas to plot output function on
self
.
fig2
=
plt
.
figure
(
figsize
=
(
4.5
,
4.5
),
dpi
=
100
)
self
.
fig2
=
plt
.
figure
(
figsize
=
(
4.5
,
4.5
),
dpi
=
100
)
plt
.
ylabel
(
"
Mass of Tracer (mg
)
"
)
plt
.
ylabel
(
"
Hounsfield Unit (Hu
)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
title
(
"
Output Function
"
)
self
.
canvas1
=
FigureCanvasTkAgg
(
self
.
fig1
,
master
=
self
.
frame2
)
self
.
canvas1
=
FigureCanvasTkAgg
(
self
.
fig1
,
master
=
self
.
frame2
)
self
.
canvas1
.
get_tk_widget
().
grid
(
row
=
0
,
column
=
0
)
self
.
canvas1
.
get_tk_widget
().
grid
(
row
=
0
,
column
=
0
)
...
@@ -631,25 +642,48 @@ class PkVisualize(tk.Toplevel):
...
@@ -631,25 +642,48 @@ class PkVisualize(tk.Toplevel):
self
.
pk
.
get_data
(
file
)
self
.
pk
.
get_data
(
file
)
self
.
fig1
.
add_subplot
(
111
).
plot
(
self
.
pk
.
time
,
self
.
pk
.
aorta
,
'
bo
'
)
self
.
fig1
.
add_subplot
(
111
).
plot
(
self
.
pk
.
time
,
self
.
pk
.
aorta
,
'
bo
'
)
plt
.
ylabel
(
"
Mass of Tracer (mg
)
"
)
plt
.
ylabel
(
"
Hounsfield Unit (Hu
)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
title
(
"
Input Function
"
)
self
.
fig1
.
canvas
.
draw
()
self
.
fig1
.
canvas
.
draw
()
self
.
fig2
.
add_subplot
(
111
).
plot
(
self
.
pk
.
time
,
self
.
pk
.
myo
,
'
ro
'
)
self
.
fig2
.
add_subplot
(
111
).
plot
(
self
.
pk
.
time
,
self
.
pk
.
myo
,
'
ro
'
)
plt
.
ylabel
(
"
Mass of Tracer (mg
)
"
)
plt
.
ylabel
(
"
Hounsfield Unit (Hu
)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
xlabel
(
"
Time (sec)
"
)
plt
.
title
(
"
Output Function
"
)
self
.
canvas2
.
draw_idle
()
self
.
canvas2
.
draw_idle
()
# Performs function fitting, outputs optimized parameters in opt
opt
=
self
.
pk
.
input_func_fit
([
self
.
ymax_slider
.
get
(),
self
.
tmax_slider
.
get
(),
self
.
alpha_slider
.
get
(),
self
.
delay_slider
.
get
()])
# Shows opt in new labels
self
.
ymax_slider
.
set
(
opt
[
0
])
self
.
tmax_slider
.
set
(
opt
[
1
])
self
.
alpha_slider
.
set
(
opt
[
2
])
self
.
delay_slider
.
set
(
opt
[
3
])
self
.
pk
.
ymax
=
opt
[
0
]
self
.
pk
.
tmax
=
opt
[
1
]
self
.
pk
.
alpha
=
opt
[
2
]
self
.
pk
.
delay
=
opt
[
3
]
# Performs function fitting, outputs optimized parameters in opt
opt2
=
self
.
pk
.
output_func_fit
([
self
.
flow_slider
.
get
(),
self
.
visf_slider
.
get
(),
self
.
baseline_slider
.
get
()])
# Shows opt in new labels
self
.
flow_slider
.
set
(
opt2
[
0
])
self
.
visf_slider
.
set
(
opt2
[
1
])
self
.
baseline_slider
.
set
(
opt2
[
2
])
def
go_back
(
self
):
def
go_back
(
self
):
"""
Exits the compare window and goes back to the start page.
"""
"""
Exits the compare window and goes back to the start page.
"""
self
.
destroy
()
self
.
destroy
()
# =================================================================================================
# =================================================================================================
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
MainWindow
=
Tk
()
MainWindow
=
Tk
()
gui
=
StartPage
(
MainWindow
)
gui
=
StartPage
(
MainWindow
)
MainWindow
.
mainloop
()
MainWindow
.
mainloop
()
# In[ ]:
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