Commit 99266015 authored by Jakob Knollmueller's avatar Jakob Knollmueller

code running, display switching working, and stuff

parent 994920a9
......@@ -3,7 +3,6 @@ import matplotlib
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
......@@ -12,15 +11,17 @@ from kivy.uix.label import Label
from kivy.uix.image import Image
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
from kivy.clock import Clock, mainthread
from kivy.uix.textinput import TextInput
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
import numpy as np
import re
import threading
# from matplotlib import pyplot as plt
import nifty2go as ift
import matplotlib.pyplot as plt
import time
class FloatInput(TextInput):
......@@ -36,14 +37,10 @@ class FloatInput(TextInput):
class MyImage(BoxLayout):
text = StringProperty('')
source = StringProperty('')
def __init__(self, *args,**kwargs):
super(MyImage, self).__init__(*args,**kwargs)
def set_plot(self, plot):
self.figure = plot
self.add_widget(FigureCanvasKivyAgg(plot))
def reload(self):
self.img.reload()
class MyAlphaWidget(BoxLayout):
alpha = NumericProperty(None)
......@@ -56,25 +53,29 @@ class DataPathWidget(BoxLayout):
pass
class ImageWidget(ScreenManager):
def reload_plots(self):
def reload(self):
for child in self.children:
child.update
child.reload()
class MenuWidget(BoxLayout):
pass
class SingleImageScreen(Screen):
figure = ObjectProperty(None)
source = StringProperty('')
def reload(self):
self.img.reload()
pass
class AllImageScreen(Screen):
def reload(self):
self.all.reload()
pass
class AllImageWidget(BoxLayout):
def reload(self):
self.data.reload()
self.points.reload()
self.diffuse.reload()
self.power.reload()
pass
class MyWidget(BoxLayout):
image_widget = ObjectProperty(None)
menu_widget = ObjectProperty(None)
data_path = StringProperty(None)
result_path = StringProperty(None)
alpha = NumericProperty(None)
class ActionWidget(BoxLayout):
pass
class DisplayChoiceWidget(BoxLayout):
......@@ -82,99 +83,106 @@ class DisplayChoiceWidget(BoxLayout):
class DisplayOptionWidget(BoxLayout):
pass
class MyWidget(BoxLayout):
image_widget = ObjectProperty(None)
menu_widget = ObjectProperty(None)
data_path = StringProperty(None)
result_path = StringProperty(None)
alpha = NumericProperty(None)
class SeparatorApp(App):
stop = threading.Event()
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)
data_image = StringProperty(None)
diffuse_image = StringProperty(None)
points_image = StringProperty(None)
power_image = StringProperty(None)
vmin = None
vmax = None
iterations = 5
def build(self):
self.set_default()
self.trigger = 0
self.root = MyWidget()
self.setup_plots()
Clock.schedule_interval(self.update, 1)
self.root.image_widget.transition = NoTransition()
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.path = ''
self.data_image = self.path + 'placeholder.png'
self.diffuse_image = self.path + 'placeholder.png'
self.points_image = self.path + 'placeholder.png'
self.power_image = self.path + 'placeholder.png'
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):
threading.Thread(target=self.load_data_thread).start()
def load_data_thread(self):
self.data = load_data(self.data_path)
self.data_image = self.plot_array(self.data, self.data_image)
pass
self.vmin = np.log(self.data.min())
self.max = np.log(self.data.max())
self.plot_array(np.log(self.data), 'data.png')
self.set_data_image()
self.update_plots()
def run_separation(self):
self.trigger = -11
threading.Thread(target= self.run_separation_thread).start()
def run_separation_thread(self):
self.myEnergy = build_problem(self.data, self.alpha)
self.plot_array(self.myEnergy.u.val, 'points.png')
self.plot_array(self.myEnergy.s.val, 'diffuse.png')
self.set_image_paths()
self.update_plots()
for i in range(self.iterations):
self.myEnergy = problem_iteration(self.myEnergy)
self.plot_array(self.myEnergy.u.val, 'points.png')
self.plot_array(self.myEnergy.s.val, 'diffuse.png')
self.update_plots()
def save_results(self):
pass
def set_result_path(self, path):
self.result_path = path
print path
@mainthread
def update_plots(self):
self.root.image_widget.reload_images()
self.root.image_widget.reload()
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
@mainthread
def set_data_image(self):
def plot_array(self, array, plot):
plot.clf()
plt.figure(plot.number)
plt.viridis()
plt.imshow(array)
plt.tight_layout()
self.data_image = self.result_path + 'data.png'
@mainthread
def set_image_paths(self):
self.points_image = self.result_path + 'points.png'
self.diffuse_image = self.result_path + 'diffuse.png'
def plot_array(self, array, path):
plt.imsave(path, np.exp(array), vmin=self.vmin, vmax=self.vmax)
plt.axis('off')
plot.canvas.draw_idle()
return plot
def set_alpha(self, alpha):
self.alpha = alpha
print alpha
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)
def run_sep(self, ini):
if ini:
self.set_data_path(self.data_path)
self.myEnergy = problem_iteration(self.myEnergy)
self.plotting()
def on_stop(self):
self.stop.set()
if __name__ == '__main__':
plt.viridis()
SeparatorApp().run()
......@@ -54,15 +54,17 @@ TextInput:
<MyImage>:
text: self.text
figure: self.figure
source: self.source
img: img
orientation: 'vertical'
spacing: 10
Label:
text: self.parent.text
size_hint: 1,0.1
Image:
id: img
source: self.parent.source
<AllImageWidget>:
data: data
points: points
......@@ -76,61 +78,71 @@ TextInput:
MyImage:
id: data
text: 'data'
figure: app.data_image
source: app.data_image
MyImage:
id: diffuse
figure: app.diffuse_image
source: app.diffuse_image
text: 'diffuse'
BoxLayout:
spacing: 10
orientation: 'horizontal'
MyImage:
id:points
figure: app.points_image
source: app.points_image
text: 'points'
MyImage:
id: power
figure: app.power_image
source: app.power_image
text: 'power'
<ImageWidget>
all: all
points: points
diffuse: diffuse
data:data
power:power
data: data
power: power
AllImageScreen:
id:all
name: 'all'
on_pre_enter: self.reload()
SingleImageScreen:
id:data
name: 'data'
text: 'data'
figure: app.data_image
source: app.data_image
on_pre_enter: self.reload()
SingleImageScreen:
id: diffuse
name: 'diffuse'
text: 'diffuse'
figure: app.diffuse_image
source: app.diffuse_image
on_pre_enter: self.reload()
SingleImageScreen:
id: points
name: 'points'
text: 'points'
figure: app.points_image
source: app.points_image
on_pre_enter: self.reload()
SingleImageScreen:
id:power
name: 'power'
text: 'power'
figure: app.power_image
source: app.power_image
on_pre_enter: self.reload()
<SingleImageScreen>
img: img
name: ''
figure: self.figure
source: self.source
text: ''
MyImage
id: img
text: self.parent.text
figure: self.parent.figure
source: self.parent.source
<AllImageScreen>
name: ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment