Exemple #1
0
    def __init__(self, parent):
        self._init_ctrls(parent)
        #Create the view/controller
        self.controller = QspaceOptionsController(self)

        #Continue by adding the custom slicer control
        self.sliceControl = SliceControl(
            parent=self.panel_to_hold_slice_control,
            use_slice=False,
            apply_slice_method=self.controller.apply_slice,
            id=wx.NewId(),
            name=u'panel_to_hold_slice_control',
            pos=wx.Point(8, 16),
            size=wx.Size(664, 100))

        self.sizerSlices = wx.BoxSizer(orient=wx.VERTICAL)
        self.sizerSlices.Add(self.sliceControl, 1, wx.EXPAND)
        self.panel_to_hold_slice_control.SetSizer(self.sizerSlices)

        #Finish up
        if gui_utils.inelastic_mode():
            self._init_inelastic()

        #Show the initial data
        self.controller.update_data(None)
    def __init__(self, parent):
        self._init_ctrls(parent)
        #Create the view/controller
        self.controller = QspaceOptionsController(self)

        #Continue by adding the custom slicer control
        self.sliceControl = SliceControl(parent=self.panel_to_hold_slice_control,
                use_slice=False, apply_slice_method=self.controller.apply_slice,
                id=wx.NewId(), name=u'panel_to_hold_slice_control', pos=wx.Point(8, 16),
                size=wx.Size(664, 100))

        self.sizerSlices = wx.BoxSizer(orient=wx.VERTICAL)
        self.sizerSlices.Add(self.sliceControl, 1, wx.EXPAND)
        self.panel_to_hold_slice_control.SetSizer(self.sizerSlices)

        #Finish up
        if gui_utils.inelastic_mode():
            self._init_inelastic()

        #Show the initial data
        self.controller.update_data(None)
    def update_data(self, argument):
        """Called when a message is received saying that the q-space calculation has changed. 
        Will update the graphical display.
            argument: ignored; was necessary for the pubsub message passing system."""
        #print "SliceController.update_data"
        
        #Also do the coverage plot
        (data_x, data_y) = model.experiment.exp.get_coverage_stats_data()
        self.panel.sliceControl.SetData(data_x, data_y)
        #And redraw it
        self.panel.sliceControl.Refresh()

        if gui_utils.inelastic_mode():
            #Now do the energy slice data
            #TODO: Un-fake data
            data_x = np.arange(-50, 20, 1)
            #data_y = [(1.0, 0., 0., 0., 0.) for x in data_x]
            data_y = []
            for i in xrange(4):
                data_y.append( data_x*0 )
            self.panel.sliceEnergy.SetData(data_x, data_y)
            self.panel.sliceEnergy.Refresh()
Exemple #4
0
    def update_data(self, argument):
        """Called when a message is received saying that the q-space calculation has changed. 
        Will update the graphical display.
            argument: ignored; was necessary for the pubsub message passing system."""
        #print "SliceController.update_data"

        #Also do the coverage plot
        (data_x, data_y) = model.experiment.exp.get_coverage_stats_data()
        self.panel.sliceControl.SetData(data_x, data_y)
        #And redraw it
        self.panel.sliceControl.Refresh()

        if gui_utils.inelastic_mode():
            #Now do the energy slice data
            #TODO: Un-fake data
            data_x = np.arange(-50, 20, 1)
            #data_y = [(1.0, 0., 0., 0., 0.) for x in data_x]
            data_y = []
            for i in xrange(4):
                data_y.append(data_x * 0)
            self.panel.sliceEnergy.SetData(data_x, data_y)
            self.panel.sliceEnergy.Refresh()
Exemple #5
0
def check_for_changes():
    """Checks if any of the parameters have changed, requiring a graphical update.
    Performs the update if needed."""
    if any(NextParams.values()):
        #At least one of the entries is not None
#        print "DisplayThread: NextParams was set."
        ChangedParams = ParamsDict()

        for key in NextParams.keys():
            value = NextParams[key]
            if not (value is None):
#                print key, "has been set."
#                if key == "PARAM_POSITIONS":
#                    print "now is", value.positions
#                    if not LatestParams[key] is None: print "was", LatestParams[key].positions
                    
                #Compare current and older value, and check if an update is needed
                if not ( LatestParams[key] == value ):
                    #This part needs to update. Save it for later.
                    ChangedParams[key] = value
                    model.experiment.exp.params[key] = value
                    #Debuggy output
                    # print key, "has changed.",

        #Now we clear the "Next" parameters because we will have calculated them by the time this loop is done.
        for key in NextParams.keys():
            NextParams[key] = None

        #Now we calculate the coverage map by doing the stuff in ChangedParams
        pos = ChangedParams[model.experiment.PARAM_POSITIONS]
        trypos = ChangedParams[model.experiment.PARAM_TRY_POSITION]
        det = ChangedParams[model.experiment.PARAM_DETECTORS]
        symmetry = ChangedParams[model.experiment.PARAM_SYMMETRY]
        invert = ChangedParams[model.experiment.PARAM_INVERT]
        energy_slice = ChangedParams[model.experiment.PARAM_ENERGY_SLICE]
        slice = ChangedParams[model.experiment.PARAM_SLICE]
        display = ChangedParams[model.experiment.PARAM_DISPLAY]
        refls = ChangedParams[model.experiment.PARAM_REFLECTIONS]
        ref_mask = ChangedParams[model.experiment.PARAM_REFLECTION_MASKING]
        ref_display = ChangedParams[model.experiment.PARAM_REFLECTION_DISPLAY]

        #Keep track of what changed
        reflections_changed = False
        reflections_recalculated = False
        qspace_changed = False

        #--- Trial position ---
        changed_trypos = False
        if not trypos is None:
            #Do we need to calculate the trial position?
            poscov = trypos.try_position
            if poscov is None: #this shouldn't happen
                changed_trypos = False
            else:
                changed_trypos = True
                if trypos.use_trial and (poscov.coverage is None):
                    #We are using the trial position, and...
                    #The coverage is not calculated, we need to do it now.
                    print "Recalculating trial position with angles ", np.rad2deg(poscov.angles)
                    poscov.coverage = model.experiment.exp.inst.calculate_coverage(model.experiment.exp.inst.detectors, poscov.angles, sample_U_matrix=poscov.sample_U_matrix)

        if not gui_utils.inelastic_mode():
            #--- Reflections changing? ELASTIC MODE ONLY! ----
            if not (refls is None) or not (det is None):
                #The reflections need recalculating
                model.experiment.exp.recalculate_reflections(pos)
                reflections_changed = True
                reflections_recalculated = True
            elif not (ref_mask is None):
                #Just the mask is changing
                # The I/sigI threshold might be different
                model.experiment.exp.get_reflections_times_real_measured(ref_mask.threshold)
                #Now do the mask
                model.experiment.exp.calculate_reflections_mask()
                reflections_changed = True

            if not (ref_display is None):
                #Just reflection display options
                reflections_changed = True


        #--- Changes to qspace (volume) calcs ----
        if not (pos is None) or not (trypos is None) or not (det is None) or not (energy_slice is None):
            #The whole calculation needs to be done
            model.experiment.exp.calculate_coverage()
            qspace_changed = True
            #The reflections weren't recalculated already?
            if not reflections_recalculated and not gui_utils.inelastic_mode():
                model.experiment.exp.recalculate_reflections(pos)
                reflections_changed = True
                reflections_recalculated = True
                
        elif not (symmetry is None):
            #Just the symmetry - no need to recalc reflections
            model.experiment.exp.calculate_coverage()
            qspace_changed = True
            
        elif not (invert is None) or not (slice is None):
            #Invert gets redone (which then does the slice)
            model.experiment.exp.invert_coverage()
            qspace_changed = True

        #The display parameter does not require recalculationg, but it does require updating
        if not display is None:
            qspace_changed = True

        #Update the latest parameters array to what was last displayed
        for key in ChangedParams.keys():
            value = ChangedParams[key]
            if not value is None:
                LatestParams[key] = value

        #If anything was changed, make the UI update as needed.
        if qspace_changed or changed_trypos:
            model.messages.send_message(model.messages.MSG_EXPERIMENT_QSPACE_CHANGED)

        if reflections_changed or changed_trypos:
            model.messages.send_message(model.messages.MSG_EXPERIMENT_REFLECTIONS_CHANGED)

        return True
    else:
        return False