def load_detector_file(self, filename): """Load detectors from a file.""" #Load if it exists if not os.path.exists(filename): wx.MessageDialog(self, "File '%s' was not found!" % filename, 'Error', wx.OK | wx.ICON_ERROR).ShowModal() else: old_detectors = model.instrument.inst.detectors try: model.instrument.inst.load_detectors_file(filename) #Save as the next default model.config.cfg.default_detector_filename = filename #Send a message saying that the detector list has changed model.messages.send_message(model.messages.MSG_DETECTOR_LIST_CHANGED) #Recalculate everything! gui_utils.do_recalculation_with_progress_bar(new_sample_U_matrix=None) #Update displays display_thread.handle_change_of_qspace() if not self.panel.frame3d is None: pass #The 3D view is open, update that by closing and re-opening wx.CallAfter(self.panel.frame3d.Close) # #Open a new one! # wx.CallAfter(self.panel.OnButton_view_detectorsButton, None) # #self.panel.frame3d.update(reset_view=False) except: #Go back to the old list model.instrument.inst.detectors = old_detectors #Re-raise the error raise
def OnReturningFromEditCrystal(self, old_U): """Call when changing the crystal, either from the button or from loading a UB file. Model.exp.crystal needs to have changed before calling """ #Whenever the crystal changes, you need a new symmetry map. model.experiment.exp.initialize_volume_symmetry_map() #User clicked okay, something (proably) changed new_U = model.experiment.exp.crystal.get_u_matrix() if not np.allclose(old_U, new_U): #The sample mounting U changed, so we need to recalc all the 3D volume coverage gui_utils.do_recalculation_with_progress_bar(new_U) #Send message signaling a redraw of volume plots display_thread.handle_change_of_qspace(changed_sample_U_matrix=new_U) #Now handle the reflections, and warn if the auto-range is huge... (b,n) = self.range_settings.is_too_many() if b: dlg = wx.MessageDialog(self, "The number of reflections given by this range, %s, is very large. Are you sure?\nIf you click no, a default range of -5 to +5 HKL will be used instead, but you can increase the range later." % gui_utils.print_large_number(n), "Too Many Reflections", wx.YES_NO | wx.ICON_INFORMATION) res = dlg.ShowModal() dlg.Destroy() if res != wx.ID_YES: #Disable automatic if its on; put on smaller numbers. self.range_settings.automatic = False self.range_settings.h_range = np.array( [-5,5] ).reshape(1,2) self.range_settings.k_range = np.array( [-5,5] ).reshape(1,2) self.range_settings.l_range = np.array( [-5,5] ).reshape(1,2) #Update the hkl range settings, especially for automatic settings self.apply_crystal_range()
def load_ldm_file_dialog(self, parent): """Opens a dialog asking the user where to load the .ldm file.""" filters = 'Lauegen .ldm file (*.ldm)|*.ldm|All files (*)|*|' (path, filename) = os.path.split(self.last_ldm_path) dialog = wx.FileDialog(parent, defaultFile=filename, defaultDir=path, message='Load an Lauegen .ldm file', wildcard=filters, style=wx.OPEN) if dialog.ShowModal() == wx.ID_OK: filename = dialog.GetPath() self.last_ldm_path = filename dialog.Destroy() else: #'Nothing was selected. dialog.Destroy() return None model.experiment.exp.inst = model.instrument.Instrument( os.path.join(os.path.dirname(__file__), "../instruments/IMAGINE_detectors.csv")) model.experiment.exp.inst.set_goniometer( model.goniometer.ImagineGoniometer()) #The old U matrix, before messing with it. old_U = model.experiment.exp.crystal.get_u_matrix() #Load the file (d_min, wl_min, wl_max) = model.experiment.exp.crystal.read_LDM_file(filename) if d_min > 0: model.experiment.exp.inst.d_min = d_min import numpy as np model.experiment.exp.inst.wl_min = wl_min model.experiment.exp.inst.wl_max = wl_max model.experiment.exp.inst.make_qspace() #Now this handles updating all the gui etc. self.tab_sample.OnReturningFromEditCrystal(old_U) #Now we need to fix a lot of stuff model.instrument.inst = model.experiment.exp.inst #This hopefully redraws everything display_thread.handle_change_of_qspace() #Make sure we select it all, by default. display_thread.select_position_coverage( poscov_list=model.instrument.inst.positions, update_gui=True)
def apply(self): """Apply changes now.""" #This sets up the new size q-space model.instrument.inst.change_qspace_size(self.get_params_dictionary()) #Whenever the q-space changes, you need a new symmetry map. model.experiment.exp.initialize_volume_symmetry_map() #Always re-initialize the reflections model.experiment.exp.initialize_reflections() #This recalcs the volumes and reflections gui_utils.do_recalculation_with_progress_bar(new_sample_U_matrix=None) #Ensure that the q-space viewer refreshes properly. display_thread.handle_change_of_qspace() #Save the points goal par = self.frame.params #@type par StartupParameters par.points_goal = par.points
def load_ldm_file_dialog(self, parent): """Opens a dialog asking the user where to load the .ldm file.""" filters = 'Lauegen .ldm file (*.ldm)|*.ldm|All files (*)|*|' (path, filename) = os.path.split(self.last_ldm_path) dialog = wx.FileDialog ( parent, defaultFile=filename, defaultDir=path, message='Load an Lauegen .ldm file', wildcard=filters, style=wx.OPEN ) if dialog.ShowModal() == wx.ID_OK: filename = dialog.GetPath() self.last_ldm_path = filename dialog.Destroy() else: #'Nothing was selected. dialog.Destroy() return None model.experiment.exp.inst = model.instrument.Instrument(os.path.join(os.path.dirname(__file__), "../instruments/IMAGINE_detectors.csv")) model.experiment.exp.inst.set_goniometer(model.goniometer.ImagineGoniometer()) #The old U matrix, before messing with it. old_U = model.experiment.exp.crystal.get_u_matrix() #Load the file (d_min,wl_min,wl_max) = model.experiment.exp.crystal.read_LDM_file(filename) if d_min > 0: model.experiment.exp.inst.d_min = d_min import numpy as np model.experiment.exp.inst.wl_min = wl_min model.experiment.exp.inst.wl_max = wl_max model.experiment.exp.inst.make_qspace() #Now this handles updating all the gui etc. self.tab_sample.OnReturningFromEditCrystal(old_U) #Now we need to fix a lot of stuff model.instrument.inst = model.experiment.exp.inst #This hopefully redraws everything display_thread.handle_change_of_qspace() #Make sure we select it all, by default. display_thread.select_position_coverage(poscov_list=model.instrument.inst.positions, update_gui=True)
def load_HFIR_int_file_dialog(parent): """Opens a dialog asking the user where to load the int file.""" filters = 'HFIR .int files (*.int)|*.int|All files (*)|*|' if is_mac(): filters = '' #Filters tend to crash on mac global last_hfir_int_path (path, filename) = os.path.split(last_hfir_int_path) dialog = wx.FileDialog ( parent, defaultFile=filename, defaultDir=path, message='Load a HFIR .int file', wildcard=filters, style=wx.OPEN ) if dialog.ShowModal() == wx.ID_OK: filename = dialog.GetPath() last_hfir_int_path = filename dialog.Destroy() else: #'Nothing was selected. dialog.Destroy() return None #Now, ask if the file peaks should be appended res = wx.MessageDialog(parent, "Do you wish to REPLACE the peaks to the current list of measured peaks?\nClick NO to append to the list.", "Replace Measured Peaks List?", wx.YES_NO | wx.YES_DEFAULT).ShowModal() do_append = (res == wx.ID_NO) print "do_append", do_append #Load it model.experiment.exp.load_HFIR_peaks_file(filename, append=do_append) #This hopefully redraws everything display_thread.handle_change_of_qspace() return filename
def load_experiment_file_dialog(parent): """Opens a dialog asking the user where to load the experiment.""" filters = 'CrystalPlan Experiment files (*.exp)|*.exp|All files (*)|*|' if is_mac(): filters = '' #Filters tend to crash on mac global last_experiment_path (path, filename) = os.path.split(last_experiment_path) dialog = wx.FileDialog ( parent, defaultFile=filename, defaultDir=path, message='Load an experiment plan from an EXP file', wildcard=filters, style=wx.OPEN ) if dialog.ShowModal() == wx.ID_OK: filename = dialog.GetPath() last_experiment_path = filename dialog.Destroy() else: #'Nothing was selected. dialog.Destroy() return None #Load it model.experiment.exp = model.experiment.load_from_file(filename) #Now we need to fix a lot of stuff model.instrument.inst = model.experiment.exp.inst #This hopefully redraws everything display_thread.handle_change_of_qspace() #Make sure we select it all, by default. display_thread.select_position_coverage(poscov_list=model.instrument.inst.positions, update_gui=True) return filename