|
@@ -3,6 +3,7 @@
|
|
|
import os
|
|
|
import re
|
|
|
import json
|
|
|
+import glob
|
|
|
import shlex
|
|
|
import collections
|
|
|
import datetime
|
|
@@ -45,6 +46,16 @@ def extract_motor_positions(id19_header):
|
|
|
return {k: float(v) for (k, v) in zip(names, values)}
|
|
|
|
|
|
|
|
|
+def have_flats(path):
|
|
|
+ large = os.path.join(path, 'fc')
|
|
|
+ small = os.path.join(path, 'fc-small')
|
|
|
+
|
|
|
+ return (os.path.exists(large) and
|
|
|
+ os.path.exists(small) and
|
|
|
+ glob.glob(os.path.join(large, '*.tif')) and
|
|
|
+ glob.glob(os.path.join(small, '*.tif')))
|
|
|
+
|
|
|
+
|
|
|
class Configuration(object):
|
|
|
|
|
|
def __init__(self, source, destination):
|
|
@@ -279,8 +290,6 @@ class Application(object):
|
|
|
info = self.read_info()
|
|
|
axis = (float(info['Col_end']) + 1) / 2.0
|
|
|
axis_step = 0.25
|
|
|
- axis_start = axis - slices_per_device * axis_step
|
|
|
- axis_stop = axis + slices_per_device * axis_step
|
|
|
|
|
|
fname = os.path.join(self.config.destination, '{}0000.edf'.format(self.prefix))
|
|
|
header = read_edf_id19_header(fname)
|
|
@@ -300,8 +309,12 @@ class Application(object):
|
|
|
x_region /= 2
|
|
|
y_region /= 2
|
|
|
axis /= 2
|
|
|
+ axis_step /= 2
|
|
|
fc_path = '{prefix}/fc-small'.format(prefix=self.prefix)
|
|
|
|
|
|
+ axis_start = axis - slices_per_device * axis_step
|
|
|
+ axis_stop = axis + slices_per_device * axis_step
|
|
|
+
|
|
|
self.log.info(" Using theta = {}, inclination angle = {}".format(theta, inclination_angle))
|
|
|
self.log.info(" Scanning lamino angle within [{}:{}:{}]".format(angle_start, angle_stop, angle_step))
|
|
|
self.log.info(" Scanning x axis within [{}:{}:{}]".format(axis_start, axis_stop, axis_step))
|
|
@@ -325,8 +338,8 @@ class Application(object):
|
|
|
' {fc_path}'
|
|
|
' {opt_params}'
|
|
|
' --reco-params "{params}"'
|
|
|
- ' --params-filename params.json'
|
|
|
- .format(opt_params=opt_params, params=params, fc_path=fc_path))
|
|
|
+ ' --params-filename {prefix}/params.json'
|
|
|
+ .format(opt_params=opt_params, params=params, fc_path=fc_path, prefix=self.prefix))
|
|
|
|
|
|
return self.run_command(cmd)
|
|
|
|
|
@@ -373,7 +386,7 @@ class Application(object):
|
|
|
self.log.highlight("Quick optimization ...")
|
|
|
|
|
|
if self.optimize(True):
|
|
|
- with open('params.json') as f:
|
|
|
+ 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'] * 2.0))
|
|
@@ -386,7 +399,7 @@ class Application(object):
|
|
|
self.log.highlight("Optimizing ...")
|
|
|
|
|
|
if self.optimize(False):
|
|
|
- with open('params.json') as f:
|
|
|
+ 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']))
|
|
@@ -419,25 +432,19 @@ class Application(object):
|
|
|
|
|
|
quit = Action('e', 'Exit', self.on_quit, machine.QUIT)
|
|
|
sync = Action('s', 'Sync', self.on_sync, machine.SYNC)
|
|
|
- flatcorrect = Action('f', 'Flat correct', self.on_flat_correct, machine.FLATCORRECT)
|
|
|
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)
|
|
|
|
|
|
machine.add_action(machine.START, sync)
|
|
|
- machine.add_action(machine.START, flatcorrect)
|
|
|
machine.add_action(machine.START, quick_optimize)
|
|
|
machine.add_action(machine.START, optimize)
|
|
|
machine.add_action(machine.START, quit)
|
|
|
|
|
|
- machine.add_action(machine.SYNC, flatcorrect)
|
|
|
machine.add_action(machine.SYNC, quit)
|
|
|
|
|
|
- machine.add_action(machine.FLATCORRECT, quick_optimize)
|
|
|
- machine.add_action(machine.FLATCORRECT, optimize)
|
|
|
- machine.add_action(machine.FLATCORRECT, quit)
|
|
|
-
|
|
|
machine.add_action(machine.QUICK_OPTIMIZE, sync)
|
|
|
+ machine.add_action(machine.QUICK_OPTIMIZE, optimize)
|
|
|
machine.add_action(machine.QUICK_OPTIMIZE, quit)
|
|
|
|
|
|
machine.add_action(machine.OPTIMIZE, sync)
|
|
@@ -446,6 +453,14 @@ class Application(object):
|
|
|
machine.add_action(machine.CLEAN, sync)
|
|
|
machine.add_action(machine.CLEAN, quit)
|
|
|
|
|
|
+ if not have_flats(self.config.destination):
|
|
|
+ flatcorrect = Action('f', 'Flat correct', self.on_flat_correct, machine.FLATCORRECT)
|
|
|
+ machine.add_action(machine.START, flatcorrect)
|
|
|
+ machine.add_action(machine.SYNC, flatcorrect)
|
|
|
+ machine.add_action(machine.FLATCORRECT, quick_optimize)
|
|
|
+ machine.add_action(machine.FLATCORRECT, optimize)
|
|
|
+ machine.add_action(machine.FLATCORRECT, quit)
|
|
|
+
|
|
|
cmd_window.set_actions(machine.actions)
|
|
|
|
|
|
self.log = LogList(right_pane, colors)
|