|
@@ -56,10 +56,6 @@ def have_flats(path):
|
|
|
glob.glob(os.path.join(small, '*.tif')))
|
|
|
|
|
|
|
|
|
-def have_params(path):
|
|
|
- return os.path.exists(os.path.join(path, 'params.json'))
|
|
|
-
|
|
|
-
|
|
|
class Configuration(object):
|
|
|
|
|
|
def __init__(self, source, destination):
|
|
@@ -195,11 +191,10 @@ class CommandList(LineList):
|
|
|
self.add_character('')
|
|
|
|
|
|
def set_actions(self, actions):
|
|
|
- self.line_list.update_last(attr=self.normal)
|
|
|
self.current = ''
|
|
|
|
|
|
- message = ' | '.join(('[{}] {}'.format(a.key, a.note) for a in actions.values()))
|
|
|
- self.line_list.add_line(message, self.highlight)
|
|
|
+ for a in actions.values():
|
|
|
+ self.line_list.add_line('[{}] {}'.format(a.key, a.note), self.highlight)
|
|
|
|
|
|
|
|
|
class Action(object):
|
|
@@ -253,6 +248,13 @@ class StateMachine(object):
|
|
|
return key in (k for k in self.transitions[self.current].keys())
|
|
|
|
|
|
|
|
|
+class Parameters(object):
|
|
|
+
|
|
|
+ def __init__(self, axis, angle):
|
|
|
+ self.axis = axis
|
|
|
+ self.angle = angle
|
|
|
+
|
|
|
+
|
|
|
class Application(object):
|
|
|
def __init__(self, config):
|
|
|
self.config = config
|
|
@@ -286,10 +288,19 @@ class Application(object):
|
|
|
def prefix(self):
|
|
|
return os.path.basename(self.config.destination)
|
|
|
|
|
|
+ @property
|
|
|
+ def params_name(self):
|
|
|
+ return '{}params.json'.format(self.prefix)
|
|
|
+
|
|
|
def read_info(self):
|
|
|
info_file = os.path.join(self.config.destination, '{}.info'.format(self.prefix))
|
|
|
return read_info_file(info_file)
|
|
|
|
|
|
+ def read_optimal_params(self, scale=1.0):
|
|
|
+ with open(self.params_name) as f:
|
|
|
+ opt = json.load(f)
|
|
|
+ return Parameters(opt['x-center']['value'], opt['lamino-angle']['value'] * scale)
|
|
|
+
|
|
|
def optimize(self, resize):
|
|
|
slices_per_device = 100
|
|
|
half_range = 1.0
|
|
@@ -347,8 +358,9 @@ class Application(object):
|
|
|
' {fc_path}'
|
|
|
' {opt_params}'
|
|
|
' --reco-params "{params}"'
|
|
|
- ' --params-filename {prefix}/params.json'
|
|
|
- .format(opt_params=opt_params, params=params, fc_path=fc_path, prefix=self.prefix))
|
|
|
+ ' --params-filename {params_name}'
|
|
|
+ .format(opt_params=opt_params, params=params, params_name=self.params_name,
|
|
|
+ fc_path=fc_path, prefix=self.prefix))
|
|
|
|
|
|
return self.run_command(cmd)
|
|
|
|
|
@@ -427,11 +439,16 @@ class Application(object):
|
|
|
self.log.highlight("Quick optimization ...")
|
|
|
|
|
|
if self.optimize(True):
|
|
|
- with open(os.path.join(self.prefix, 'params.json')) as f:
|
|
|
+ with open(self.params_name) as f:
|
|
|
opt = json.load(f)
|
|
|
- self.log.highlight(" Optimal axis: {}".format(opt['lamino-angle']['value']))
|
|
|
- self.log.highlight(" Optimal center: {}".format(opt['x-center']['value'] * 2.0))
|
|
|
+ opt['x-center']['value'] *= 2.0
|
|
|
|
|
|
+ with open(self.params_name, 'w') as f:
|
|
|
+ json.dump(opt, f)
|
|
|
+
|
|
|
+ params = self.read_optimal_params()
|
|
|
+ self.log.highlight(" Optimal axis: {}".format(params.angle))
|
|
|
+ self.log.highlight(" Optimal center: {}".format(params.axis))
|
|
|
return True
|
|
|
|
|
|
return False
|
|
@@ -440,11 +457,9 @@ class Application(object):
|
|
|
self.log.highlight("Optimizing ...")
|
|
|
|
|
|
if self.optimize(False):
|
|
|
- with open(os.path.join(self.prefix, 'params.json')) as f:
|
|
|
- opt = json.load(f)
|
|
|
- self.log.highlight(" Optimal axis: {}".format(opt['lamino-angle']['value']))
|
|
|
- self.log.highlight(" Optimal center: {}".format(opt['x-center']['value']))
|
|
|
-
|
|
|
+ params = self.read_optimal_params()
|
|
|
+ self.log.highlight(" Optimal axis: {}".format(params.angle))
|
|
|
+ self.log.highlight(" Optimal center: {}".format(params.axis))
|
|
|
return True
|
|
|
|
|
|
return False
|
|
@@ -461,8 +476,8 @@ class Application(object):
|
|
|
top_pane = screen.subwin(1, width, 0, 0)
|
|
|
bottom_pane = screen.subwin(height - 1, width, 1, 0)
|
|
|
|
|
|
- left_pane = bottom_pane.subwin(height - 1, width / 3, 1, 0)
|
|
|
- right_pane = bottom_pane.subwin(height - 1, 2 * width / 3, 1, width / 3)
|
|
|
+ left_pane = bottom_pane.subwin(height - 1, width / 4, 1, 0)
|
|
|
+ right_pane = bottom_pane.subwin(height - 1, 2 * width / 4, 1, width / 4)
|
|
|
|
|
|
status_bar = StatusBar(top_pane, colors)
|
|
|
status_bar.update('Cockpit')
|
|
@@ -474,8 +489,8 @@ class Application(object):
|
|
|
quit = Action('e', 'Exit', self.on_quit, machine.QUIT)
|
|
|
sync = Action('s', 'Sync', self.on_sync, machine.SYNC)
|
|
|
clean = Action('c', 'Clean', self.on_clean, machine.CLEAN)
|
|
|
- quick_optimize = Action('q', 'Quick', self.on_quick_optimize, machine.QUICK_OPTIMIZE)
|
|
|
- optimize = Action('o', 'Optimize', self.on_optimize, machine.OPTIMIZE)
|
|
|
+ quick_optimize = Action('q', 'Quick optimization', self.on_quick_optimize, machine.QUICK_OPTIMIZE)
|
|
|
+ optimize = Action('o', 'Optimization', self.on_optimize, machine.OPTIMIZE)
|
|
|
reconstruct = Action('r', 'Reconstruct', self.on_reconstruct, machine.RECONSTRUCT)
|
|
|
|
|
|
machine.add_action(machine.START, sync)
|
|
@@ -496,7 +511,7 @@ class Application(object):
|
|
|
machine.add_action(machine.CLEAN, sync)
|
|
|
machine.add_action(machine.CLEAN, quit)
|
|
|
|
|
|
- if have_params(self.config.destination):
|
|
|
+ if os.path.exists(self.params_name):
|
|
|
machine.add_action(machine.START, reconstruct)
|
|
|
|
|
|
if not have_flats(self.config.destination):
|