Exemple #1
0
    def apply(self, event, *args):
        """Apply the best results."""
        #TODO: Confirmation message box?
        positions = []

        # And add the fixed ones, if any
        if self.params.fixed_orientations:
            positions += self.params.fixed_orientations_list

        # Get the angles of the best one
        positions += model.optimization.get_angles(self.best)
            
        print "Applying best individual", self.best

        #This deletes everything in the list in the instrument
        del model.instrument.inst.positions[:]
        #Make sure to clear the parameters too, by giving it an empty dict() object.
        display_thread.clear_positions_selected()

        #This function does the calc. and shows a progress bar. Can be aborted too.
        gui_utils.do_calculation_with_progress_bar(positions)

        #GUI update
        model.messages.send_message(model.messages.MSG_POSITION_LIST_CHANGED)
        
        #Add it to the list of selected items
        if len(model.instrument.inst.angles) == 1:
	    model.instrument.inst.sort_positions_by(0)
        display_thread.select_position_coverage(model.instrument.inst.positions, update_gui=True)

        if not event is None: event.Skip()
    def changed(self):
        """Call when the checked list changes."""
        # We generate a dictionary of object, True/False
        pos_dict = dict()
        for i in range(len(model.instrument.inst.positions)):
            posCoverage = model.instrument.inst.positions[i]
            value = self.panel.checkListPositions.IsChecked(i)
            pos_dict[id(posCoverage)] = value

        # Save it as the parameter to change
        display_thread.select_position_coverage(pos_dict)
    def changed(self):
        """Call when the checked list changes."""
        #We generate a dictionary of object, True/False
        pos_dict = dict()
        for i in range(len(model.instrument.inst.positions)):
            posCoverage = model.instrument.inst.positions[i]
            value = self.panel.checkListPositions.IsChecked(i)
            pos_dict[id(posCoverage)] = value

        #Save it as the parameter to change
        display_thread.select_position_coverage(pos_dict)
    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 add_to_list(self):
     """Adds the last selected angle set to the main list of positions."""
     #Get the old try_position
     old = display_thread.get_try_position()
     if not old is None:
         if not old.try_position is None:
             #Do we have the same angles?
             if (self.angles == old.try_position.angles):
                 #Was it calculated?
                 if not old.try_position.coverage is None:
                     #Great! Add it to the main list.
                     #Make a copy
                     poscov = copy.copy(old.try_position)
                     model.instrument.inst.positions.append(poscov)
                     #Auto-select (check) that position we just added.
                     display_thread.select_position_coverage(poscov)
                     #Send out a message (for the GUI) saying that the list should be updated (to reflect the selection and the new item)
                     model.messages.send_message(model.messages.MSG_POSITION_LIST_CHANGED)
                     #and we're done
                     return
                 
     #If we reach here, something was missing
     wx.MessageDialog(None, "Sorry! There was a problem adding this sample orientation to the main list. Make sure it has been calculated and is shown in the coverage view before clicking this button.", 'Error', wx.OK | wx.ICON_ERROR).ShowModal()
Exemple #6
0
    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)
Exemple #7
0
    def delete_several(self, row_list):
        """Deletes several entries in the position list.

        Parameter:
            row_list: list of row numbers to delete.
        """
        #Get the current selection dictionary
        poscov_dict = display_thread.get_positions_dict().copy()
        #Delete entries, starting from the end
        row_list.sort()
        row_list.reverse()
        for index in row_list:
            #Remove from the selection list too
            poscov = model.instrument.inst.positions[index]
            if poscov_dict.has_key(id(poscov)):
                del poscov_dict[id(poscov)]
            #And from the data
            del model.instrument.inst.positions[index]

        #Remove the extra entries from the list
        display_thread.select_position_coverage(poscov_dict, update_gui=False)

        #Update the display.
        self.update_grid()
    def delete_several(self, row_list):
        """Deletes several entries in the position list.

        Parameter:
            row_list: list of row numbers to delete.
        """
        #Get the current selection dictionary
        poscov_dict = display_thread.get_positions_dict().copy()
        #Delete entries, starting from the end
        row_list.sort()
        row_list.reverse()
        for index in row_list:
            #Remove from the selection list too
            poscov = model.instrument.inst.positions[index]
            if poscov_dict.has_key(id(poscov)):
                del poscov_dict[id(poscov)]
            #And from the data
            del model.instrument.inst.positions[index]

        #Remove the extra entries from the list
        display_thread.select_position_coverage(poscov_dict, update_gui=False)

        #Update the display.
        self.update_grid()
Exemple #9
0
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