def __init__(self, img, index=None, termfile=None, paramfile=None, output_file=None, output_dir=None, backend='dials', action_code='spotfind', min_bragg=10, n_processors=1, verbose=False ): self.img = img self.backend = backend self.paramfile = paramfile self.termfile = termfile self.n_processors = n_processors self.index = index self.verbose = verbose self.min_bragg = min_bragg if output_file is not None: if output_dir is not None: self.output = os.path.join(os.path.abspath(output_dir), output_file) else: self.output = os.path.abspath(output_file) else: self.output = None Thread.__init__(self) # Determine which processes will be included if action_code == 'spotfind': self.run_indexing = False self.run_integration = False elif action_code == 'index': self.run_indexing = True self.run_integration = False elif action_code == 'integrate': self.run_indexing = True self.run_integration = True # Initialize IOTA DIALS Processor if self.backend.lower() == 'dials': if self.paramfile is not None: with open(self.paramfile, 'r') as phil_file: phil_string = phil_file.read() user_phil = ip.parse(phil_string) self.dials_phil = phil_scope.fetch(source=user_phil) else: self.dials_phil = phil_scope self.params = self.dials_phil.extract() if self.backend == 'dials': self.processor = IOTADialsProcessor(params=self.params)
def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size=(1500, 600)) self.parent = parent self.term_file = os.path.join(os.curdir, '.terminate_image_tracker') self.spf_backend = 'mosflm' self.reset_spotfinder() # Status bar self.sb = self.CreateStatusBar() self.sb.SetFieldsCount(2) self.sb.SetStatusWidths([100, -1]) # Setup main sizer self.main_sizer = wx.BoxSizer(wx.VERTICAL) # Setup toolbar self.toolbar = self.CreateToolBar(style=wx.TB_3DBUTTONS | wx.TB_TEXT) quit_bmp = bitmaps.fetch_icon_bitmap('actions', 'exit') self.tb_btn_quit = self.toolbar.AddLabelTool( wx.ID_EXIT, label='Quit', bitmap=quit_bmp, shortHelp='Quit', longHelp='Quit image tracker') self.toolbar.AddSeparator() pref_bmp = bitmaps.fetch_icon_bitmap('apps', 'advancedsettings') self.tb_btn_prefs = self.toolbar.AddLabelTool( wx.ID_ANY, label='Preferences', bitmap=pref_bmp, shortHelp='Preferences', longHelp='IOTA image tracker preferences') self.toolbar.AddSeparator() open_bmp = bitmaps.fetch_icon_bitmap('actions', 'open') self.tb_btn_open = self.toolbar.AddLabelTool(wx.ID_ANY, label='Open', bitmap=open_bmp, shortHelp='Open', longHelp='Open folder') run_bmp = bitmaps.fetch_icon_bitmap('actions', 'run') self.tb_btn_run = self.toolbar.AddLabelTool(wx.ID_ANY, label='Run', bitmap=run_bmp, shortHelp='Run', longHelp='Run Spotfinding') stop_bmp = bitmaps.fetch_icon_bitmap('actions', 'stop') self.tb_btn_stop = self.toolbar.AddLabelTool( wx.ID_ANY, label='Stop', bitmap=stop_bmp, shortHelp='Stop', longHelp='Stop Spotfinding') self.toolbar.AddSeparator() span_view = bitmaps.fetch_custom_icon_bitmap('zoom_list') self.tb_btn_view = self.toolbar.AddLabelTool( wx.ID_ANY, label='View', bitmap=span_view, kind=wx.ITEM_RADIO, shortHelp='Select to View', longHelp='Select images to view') span_zoom = bitmaps.fetch_custom_icon_bitmap('zoom_view') self.tb_btn_zoom = self.toolbar.AddLabelTool( wx.ID_ANY, label='Zoom In', bitmap=span_zoom, kind=wx.ITEM_RADIO, shortHelp='Zoom In', longHelp='Zoom in on chart') self.toolbar.ToggleTool(self.tb_btn_zoom.GetId(), True) self.toolbar.EnableTool(self.tb_btn_run.GetId(), False) self.toolbar.EnableTool(self.tb_btn_stop.GetId(), False) self.toolbar.Realize() # Setup timers self.spf_timer = wx.Timer(self) self.uc_timer = wx.Timer(self) self.ff_timer = wx.Timer(self) self.tracker_panel = TrackerPanel(self) self.data_dict = self.tracker_panel.image_list.image_list.ctr.data.copy( ) self.img_list_initialized = False self.main_sizer.Add(self.tracker_panel, 1, wx.EXPAND) # Generate default DIALS PHIL file default_phil = ip.parse(default_target) self.phil = phil_scope.fetch(source=default_phil) self.params = self.phil.extract() self.params.output.strong_filename = None self.phil = self.phil.format(python_object=self.params) # Bindings self.Bind(wx.EVT_TOOL, self.onQuit, self.tb_btn_quit) self.Bind(wx.EVT_TOOL, self.onGetImages, self.tb_btn_open) self.Bind(wx.EVT_TOOL, self.onRunSpotfinding, self.tb_btn_run) self.Bind(wx.EVT_TOOL, self.onStop, self.tb_btn_stop) self.Bind(wx.EVT_BUTTON, self.onSelView, self.tracker_panel.btn_view_sel) self.Bind(wx.EVT_BUTTON, self.onWrtFile, self.tracker_panel.btn_wrt_file) self.Bind(wx.EVT_BUTTON, self.onAllView, self.tracker_panel.btn_view_all) self.Bind(wx.EVT_TOOL, self.onZoom, self.tb_btn_zoom) self.Bind(wx.EVT_TOOL, self.onList, self.tb_btn_view) # Spotfinder / timer bindings self.Bind(thr.EVT_SPFDONE, self.onSpfOneDone) self.Bind(thr.EVT_SPFALLDONE, self.onSpfAllDone) self.Bind(thr.EVT_SPFTERM, self.onSpfTerminated) self.Bind(wx.EVT_TIMER, self.onSpfTimer, id=self.spf_timer.GetId()) self.Bind(wx.EVT_TIMER, self.onUCTimer, id=self.uc_timer.GetId()) self.Bind(wx.EVT_TIMER, self.onPlotOnlyTimer, id=self.ff_timer.GetId()) # Settings bindings #self.Bind(wx.EVT_BUTTON, self.onSpfOptions, self.tracker_panel.spf_options) self.Bind(wx.EVT_SPINCTRL, self.onMinBragg, self.tracker_panel.min_bragg.ctr) self.Bind(wx.EVT_SPINCTRL, self.onChartRange, self.tracker_panel.chart_window.ctr) # Read arguments if any self.args, self.phil_args = parse_command_args('').parse_known_args() self.spf_backend = self.args.backend self.tracker_panel.min_bragg.ctr.SetValue(self.args.bragg) if self.args.file is not None: self.results_file = self.args.file self.start_spotfinding(from_file=True) elif self.args.path is not None: path = os.path.abspath(self.args.path) self.open_images_and_get_ready(path=path) if self.args.start: print 'IMAGE_TRACKER: STARTING FROM FIRST RECORDED IMAGE' self.start_spotfinding() elif self.args.proceed: print 'IMAGE_TRACKER: STARTING FROM IMAGE RECORDED 1 MIN AGO' self.start_spotfinding(min_back=-1) elif self.args.time > 0: min_back = -self.args.time[0] print 'IMAGE_TRACKER: STARTING FROM IMAGE RECORDED {} MIN AGO' \ ''.format(min_back) self.start_spotfinding(min_back=min_back)
def __init__(self, img, index=None, termfile=None, paramfile=None, output_file=None, output_dir=None, backend='dials', action_code='spotfind', min_bragg=10, n_processors=1, verbose=False ): self.img = img self.backend = backend self.paramfile = paramfile self.termfile = termfile self.n_processors = n_processors self.index = index self.verbose = verbose self.min_bragg = min_bragg if output_file is not None: if output_dir is not None: self.output = os.path.join(os.path.abspath(output_dir), output_file) else: self.output = os.path.abspath(output_file) else: self.output = None Thread.__init__(self) # Determine which processes will be included if action_code == 'spotfind': self.run_indexing = False self.run_integration = False elif action_code == 'index': self.run_indexing = True self.run_integration = False elif action_code == 'integrate': self.run_indexing = True self.run_integration = True # Initialize IOTA DIALS Processor if self.backend.lower() == 'dials': if self.paramfile is not None: with open(self.paramfile, 'r') as phil_file: phil_string = phil_file.read() user_phil = ip.parse(phil_string) self.dials_phil = phil_scope.fetch(source=user_phil) else: default_params, _ = write_defaults(method='dials', write_target_file=False, write_param_file=False) default_phil_string = '\n'.join(default_params) default_phil = ip.parse(default_phil_string) self.dials_phil = phil_scope.fetch(source=default_phil) self.params = self.dials_phil.extract() # Modify default DIALS parameters # These parameters will be set no matter what self.params.output.datablock_filename = None self.params.output.indexed_filename = None self.params.output.strong_filename = None self.params.output.refined_experiments_filename = None self.params.output.integrated_filename = None self.params.output.integrated_experiments_filename = None self.params.output.profile_filename = None self.params.output.integration_pickle = None # These parameters will be set only if there's no script if self.paramfile is None: self.params.indexing.stills.method_list = ['fft3d'] if self.backend == 'dials': self.processor = IOTADialsProcessor(params=self.params, write_pickle=False)
def initialize_spotfinder(self): self.done_list = [] self.data_list = [] self.spotfinding_info = [] self.plot_idx = 0 self.bookmark = 0 self.all_info = [] self.current_min_bragg = 0 self.waiting = False self.submit_new_images = False self.terminated = False # Read arguments if any self.args, self.phil_args = parse_command_args('').parse_known_args() # Generate DIALS PHIL file if self.args.paramfile is None: default_phil = ip.parse(default_target) self.phil = phil_scope.fetch(source=default_phil) else: with open(self.args.paramfile, 'r') as phil_file: phil_string = phil_file.read() user_phil = ip.parse(phil_string) self.phil = phil_scope.fetch(source=user_phil) self.params = self.phil.extract() # Set backend self.spf_backend = self.args.backend # Determine how far the DIALS processing will go if 'index' in self.args.action: self.run_indexing = True elif 'int' in self.args.action: self.run_indexing = True self.run_integration = True self.tracker_panel.min_bragg.ctr.SetValue(self.args.bragg) # Determine how the tracker will track images: from file output by # iota.single_image, or by turning over actual files. If the latter, # determine at what point the tracker will start the tracking auto_start = True min_back = None if self.args.file is not None: self.results_file = self.args.file elif self.args.path is not None: path = os.path.abspath(self.args.path) self.open_images_and_get_ready(path=path) if self.args.start: print 'IMAGE_TRACKER: STARTING FROM FIRST RECORDED IMAGE' elif self.args.proceed: print 'IMAGE_TRACKER: STARTING FROM IMAGE RECORDED 1 MIN AGO' min_back = -1 elif self.args.time > 0: min_back = -self.args.time[0] print 'IMAGE_TRACKER: STARTING FROM IMAGE RECORDED {} MIN AGO' \ ''.format(min_back) else: auto_start = False # Initialize processing thread if self.args.file is None: self.proc_thread = thr.InterceptorThread( self, data_folder=self.data_folder, term_file=self.term_file, proc_params=self.params, backend=self.args.backend, n_proc=self.args.nproc, min_back=min_back, run_indexing=self.run_indexing, run_integration=self.run_integration) else: self.proc_thread = thr.InterceptorFileThread( self, results_file=self.args.file, reorder=self.args.reorder) if auto_start: self.start_spotfinding()