Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
starblade
Commits
994920a9
Commit
994920a9
authored
Jan 25, 2018
by
Jakob Knollmueller
Browse files
currently not working
parent
bad181a2
Changes
3
Hide whitespace changes
Inline
Side-by-side
gui_app.py
View file @
994920a9
import
matplotlib
matplotlib
.
use
(
'agg'
)
# matplotlib.use('agg')
matplotlib
.
use
(
'module://kivy.garden.matplotlib.backend_kivy'
)
from
point_separation
import
build_problem
,
problem_iteration
,
load_data
from
kivy.garden.matplotlib.backend_kivyagg
import
FigureCanvasKivyAgg
from
kivy.app
import
App
from
kivy.uix.widget
import
Widget
...
...
@@ -10,9 +14,10 @@ from kivy.properties import ObjectProperty, StringProperty, NumericProperty
from
kivy.uix.boxlayout
import
BoxLayout
from
kivy.clock
import
Clock
from
kivy.uix.textinput
import
TextInput
from
kivy.uix.screenmanager
import
ScreenManager
,
Screen
import
re
import
threading
from
point_separation
import
build_problem
,
problem_iteration
,
load_data
# from matplotlib import pyplot as plt
import
nifty2go
as
ift
import
matplotlib.pyplot
as
plt
...
...
@@ -30,37 +35,39 @@ class FloatInput(TextInput):
class
MyImage
(
BoxLayout
):
source
=
StringProperty
(
''
)
text
=
StringProperty
(
''
)
img
=
ObjectProperty
(
None
)
def
reload
(
self
):
self
.
img
.
reload
()
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
MyImage
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
set_plot
(
self
,
plot
):
self
.
figure
=
plot
self
.
add_widget
(
FigureCanvasKivyAgg
(
plot
))
class
MyAlphaWidget
(
BoxLayout
):
alpha
=
NumericProperty
(
None
)
pass
class
Store
ResultsWidget
(
BoxLayout
):
class
Results
Path
Widget
(
BoxLayout
):
pass
class
Load
DataWidget
(
BoxLayout
):
class
Data
Path
Widget
(
BoxLayout
):
pass
class
ImageWidget
(
BoxLayout
):
data_image
=
ObjectProperty
(
None
)
diffuse_image
=
ObjectProperty
(
None
)
point_image
=
ObjectProperty
(
None
)
power_image
=
ObjectProperty
(
None
)
def
reload_images
(
self
):
self
.
diffuse_image
.
reload
()
self
.
point_image
.
reload
()
self
.
power_image
.
reload
()
class
ImageWidget
(
ScreenManager
):
def
reload_plots
(
self
):
for
child
in
self
.
children
:
child
.
update
class
MenuWidget
(
BoxLayout
):
pass
class
SingleImageScreen
(
Screen
):
figure
=
ObjectProperty
(
None
)
pass
class
AllImageScreen
(
Screen
):
pass
class
AllImageWidget
(
BoxLayout
):
pass
class
MyWidget
(
BoxLayout
):
image_widget
=
ObjectProperty
(
None
)
menu_widget
=
ObjectProperty
(
None
)
...
...
@@ -68,50 +75,105 @@ class MyWidget(BoxLayout):
data_path
=
StringProperty
(
None
)
result_path
=
StringProperty
(
None
)
alpha
=
NumericProperty
(
None
)
class
ActionWidget
(
BoxLayout
):
pass
class
DisplayChoiceWidget
(
BoxLayout
):
pass
class
DisplayOptionWidget
(
BoxLayout
):
pass
class
SeparatorApp
(
App
):
data_path
=
StringProperty
(
None
)
result_path
=
StringProperty
(
None
)
alpha
=
NumericProperty
(
None
)
data_image
=
ObjectProperty
(
None
)
diffuse_image
=
ObjectProperty
(
None
)
points_image
=
ObjectProperty
(
None
)
power_image
=
ObjectProperty
(
None
)
def
reload_images
(
self
):
self
.
image_widget
.
reload_images
()
def
build
(
self
):
self
.
set_default
()
self
.
trigger
=
0
self
.
root
=
MyWidget
()
self
.
setup_plots
()
Clock
.
schedule_interval
(
self
.
update
,
1
)
return
self
.
root
def
set_default
(
self
):
self
.
data_path
=
'hst_05195_01_wfpc2_f702w_pc_sci.fits'
self
.
result_path
=
''
self
.
alpha
=
1.5
self
.
data_image
=
plt
.
figure
()
self
.
diffuse_image
=
plt
.
figure
()
self
.
points_image
=
plt
.
figure
()
self
.
power_image
=
plt
.
figure
()
def
update
(
self
,
*
args
):
self
.
trigger
+=
1
if
self
.
trigger
<
0
:
self
.
run_sep
(
self
.
trigger
==-
10
)
def
setup_plots
(
self
):
self
.
root
.
image_widget
.
all
.
all
.
points
.
set_plot
(
self
.
points_image
)
self
.
root
.
image_widget
.
all
.
all
.
diffuse
.
set_plot
(
self
.
diffuse_image
)
self
.
root
.
image_widget
.
all
.
all
.
data
.
set_plot
(
self
.
data_image
)
self
.
root
.
image_widget
.
all
.
all
.
power
.
set_plot
(
self
.
power_image
)
self
.
root
.
image_widget
.
power
.
img
.
set_plot
(
self
.
power_image
)
self
.
root
.
image_widget
.
diffuse
.
img
.
set_plot
(
self
.
diffuse_image
)
self
.
root
.
image_widget
.
points
.
img
.
set_plot
(
self
.
points_image
)
self
.
root
.
image_widget
.
data
.
img
.
set_plot
(
self
.
data_image
)
def
load_data
(
self
):
self
.
data
=
load_data
(
self
.
data_path
)
self
.
data_image
=
self
.
plot_array
(
self
.
data
,
self
.
data_image
)
pass
def
run_separation
(
self
):
self
.
trigger
=
-
11
def
save_results
(
self
):
pass
def
set_result_path
(
self
,
path
):
self
.
result_path
=
path
print
path
def
update_plots
(
self
):
self
.
root
.
image_widget
.
reload_images
()
def
set_data_path
(
self
,
path
):
self
.
data_path
=
path
data
=
load_data
(
self
.
data_path
)
self
.
myEnergy
=
build_problem
(
data
,
self
.
alpha
)
self
.
plotting
()
print
path
def
plot_array
(
self
,
array
,
plot
):
plot
.
clf
()
plt
.
figure
(
plot
.
number
)
plt
.
viridis
()
plt
.
imshow
(
array
)
plt
.
tight_layout
()
plt
.
axis
(
'off'
)
plot
.
canvas
.
draw_idle
()
return
plot
def
set_alpha
(
self
,
alpha
):
self
.
alpha
=
alpha
print
alpha
def
plotting
(
self
):
def
get_new_plots
(
self
):
pass
def
save_reconstruction
(
self
):
plt
.
viridis
()
plt
.
imsave
(
self
.
result_path
+
'points0.png'
,
self
.
myEnergy
.
u
.
val
)
plt
.
imsave
(
self
.
result_path
+
'maps0.png'
,
(
self
.
myEnergy
.
s
).
val
)
plt
.
imsave
(
self
.
result_path
+
'data0.png'
,
ift
.
log
(
self
.
myEnergy
.
d
).
val
)
self
.
reload_images
()
def
run_sep
aration
(
self
,
ini
):
def
run_sep
(
self
,
ini
):
if
ini
:
self
.
set_data_path
(
self
.
data_path
)
self
.
myEnergy
=
problem_iteration
(
self
.
myEnergy
)
self
.
plotting
()
class
SeparatorApp
(
App
):
def
build
(
self
):
self
.
trigger
=
0
self
.
root
=
MyWidget
()
Clock
.
schedule_interval
(
self
.
update
,
1
)
return
self
.
root
def
update
(
self
,
*
args
):
self
.
trigger
+=
1
if
self
.
trigger
<
0
:
self
.
root
.
run_separation
(
self
.
trigger
==-
10
)
if
__name__
==
'__main__'
:
...
...
point_separation.py
View file @
994920a9
...
...
@@ -41,7 +41,7 @@ def build_problem(data, alpha):
return
separationEnergy
def
problem_iteration
(
energy
):
controller
=
GradientNormController
(
verbose
=
True
,
tol_abs_gradnorm
=
0.00000001
,
iteration_limit
=
1
)
controller
=
GradientNormController
(
verbose
=
True
,
tol_abs_gradnorm
=
0.00000001
,
iteration_limit
=
3
)
minimizer
=
RelaxedNewton
(
controller
=
controller
)
energy
,
convergence
=
minimizer
(
energy
)
new_position
=
energy
.
position
...
...
separator.kv
View file @
994920a9
...
...
@@ -20,19 +20,6 @@ TextInput:
id: image_widget
size_hint: 1,1
<MyImage>:
img: img
source: self.source
text: self.text
orientation: 'vertical'
spacing: 10
Label:
text: self.parent.text
size_hint: 1,0.1
Image:
id: img
source: self.parent.source
size_hint: 1,1
<MyAlphaWidget>:
orientation: 'horizontal'
...
...
@@ -40,36 +27,47 @@ TextInput:
text: unichr(945)
FloatInput
text: '1.5'
on_text
_validate: app.root
.set_alpha(float(self.text))
on_text
: app
.set_alpha(float(self.text))
<
Store
ResultsWidget>:
<Results
Path
Widget>:
orientation:'horizontal'
Label:
text:'path to results'
TextInput:
text: ''
multiline: False
on_text
_validate: app.root
.set_result_path(self.text)
on_text
: app
.set_result_path(self.text)
<
Load
DataWidget>:
<Data
Path
Widget>:
orientation:'horizontal'
Label:
text: 'location of the data'
TextInput:
text: 'hst_05195_01_wfpc2_f702w_pc_sci.fits'
multiline: False
on_text
_validate: app.root
.set_data_path(self.text)
on_text
: app
.set_data_path(self.text)
<FloatInput>:
multiline: False
<ImageWidget>:
data_image: data
diffuse_image: diffuse
point_image: point
power_image: power
<MyImage>:
text: self.text
figure: self.figure
orientation: 'vertical'
spacing: 10
Label:
text: self.parent.text
size_hint: 1,0.1
<AllImageWidget>:
data: data
points: points
diffuse: diffuse
power:power
orientation: 'vertical'
spacing: 10
BoxLayout
...
...
@@ -77,41 +75,120 @@ TextInput:
orientation: 'horizontal'
MyImage:
id: data
source: 'data0.png'
text: 'data'
figure: app.data_image
MyImage:
id: diffuse
so
ur
c
e:
'maps0.png'
fig
ure:
app.diffuse_image
text: 'diffuse'
BoxLayout:
spacing: 10
orientation: 'horizontal'
MyImage:
id:
point
so
ur
c
e:
'
points
0.png'
id:point
s
fig
ure:
app.
points
_image
text: 'points'
MyImage:
id: power
so
ur
c
e:
'
power
.png'
fig
ure:
app.
power
_image
text: 'power'
<ImageWidget>
all: all
points: points
diffuse: diffuse
data:data
power:power
AllImageScreen:
id:all
name: 'all'
SingleImageScreen:
id:data
name: 'data'
text: 'data'
figure: app.data_image
SingleImageScreen:
id: diffuse
name: 'diffuse'
text: 'diffuse'
figure: app.diffuse_image
SingleImageScreen:
id: points
name: 'points'
text: 'points'
figure: app.points_image
SingleImageScreen:
id:power
name: 'power'
text: 'power'
figure: app.power_image
<SingleImageScreen>
img: img
name: ''
figure: self.figure
text: ''
MyImage
id: img
text: self.parent.text
figure: self.parent.figure
<AllImageScreen>
name: ''
all : all
AllImageWidget
id:all
<MenuWidget>:
orientation: 'vertical'
MyAlphaWidget:
size_hint: 1,0.1
Load
DataWidget:
Data
Path
Widget:
size_hint: 1,0.1
text: 'location of the data'
Store
ResultsWidget:
Results
Path
Widget:
size_hint: 1,0.1
text: 'path to results'
Button
text: 'run separation'
on_press: app.trigger = -11
DisplayOptionWidget
ActionWidget
<ActionWidget>:
orientation: 'horizontal'
Button:
text: 'load data'
on_press: app.load_data()
Button:
text: 'run separation'
on_press: app.run_separation()
Button:
text: 'save results'
on_press: app.save_results()
<DisplayChoiceWidget>:
orientation: 'horizontal'
Button:
text: 'all'
on_press: app.root.image_widget.current = 'all'
Button:
text: 'data'
on_press: app.root.image_widget.current = 'data'
Button:
text: 'diffuse'
on_press: app.root.image_widget.current = 'diffuse'
Button:
text: 'points'
on_press: app.root.image_widget.current = 'points'
Button:
text: 'power'
on_press: app.root.image_widget.current = 'power'
<DisplayOptionWidget>:
orientation: 'vertical'
Label:
text: 'display'
size_hint: 1,0.1
DisplayChoiceWidget
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment