From 1ed328ca988902ff397f8df1f9925535e07c74b5 Mon Sep 17 00:00:00 2001 From: Janik Zikovsky Date: Tue, 15 Jun 2010 17:41:35 +0000 Subject: [PATCH] Fixes #167 --- gui/display_thread.py | 3 +++ gui/frame_qspace_view.py | 28 +++++++++++++++++++++++++++ gui/panel_reflections_view_options.py | 3 ++- gui/value_slider.py | 2 +- model/experiment.py | 23 ++++++++++++++++------ model/reflections.py | 13 +++++++++---- 6 files changed, 60 insertions(+), 12 deletions(-) diff --git a/gui/display_thread.py b/gui/display_thread.py index 41eec3f..dafcf6e 100644 --- a/gui/display_thread.py +++ b/gui/display_thread.py @@ -151,6 +151,9 @@ def check_for_changes(): 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 diff --git a/gui/frame_qspace_view.py b/gui/frame_qspace_view.py index e12dcf4..660a780 100644 --- a/gui/frame_qspace_view.py +++ b/gui/frame_qspace_view.py @@ -373,6 +373,9 @@ def init_view_objects(self, *args): self.points_module_surface.visible = False self.points_module_glyph.visible = False + #Get the color look-up table + self.points_lut = self.points_module_glyph.module_manager.scalar_lut_manager.lut.table.to_array() + self.points_lut_original = 1 * self.points_lut # ---- Simple outline for all of the data. ----- self.outline = Outline() @@ -445,6 +448,28 @@ def init_view_objects(self, *args): #Re-enable drawing self.scene.disable_render = False + #----------------------------------------------------------------------------------------------- + def set_points_lut(self, predicted): + """Set the look-up table (colormap). + Parameters: + predicted: bool, True for the "predicted" color map; measured otherwise""" + if not hasattr(self, 'points_lut'): + print "No LUT!" + return +# print "setting lut ", predicted + if predicted or True: + #Predicted style; copy the original + self.points_lut[:,:] = self.points_lut_original[:,:] + else: + #Measured style + self.points_lut[:,0] = 255-self.points_lut_original[:,0] + self.points_lut[:,1] = self.points_lut_original[:,1] + self.points_lut[:,2] = self.points_lut_original[:,2] +# self.points_lut[:,0] = np.arange(0,256,1) +# self.points_lut[:,1] = 0 #G +# self.points_lut[:,2] = 255 #B + self.points_lut[:,3] = 255 #alpha + #----------------------------------------------------------------------------------------------- def show_pipeline(self): @@ -632,6 +657,9 @@ def update_data_points(self, *args): #Generate a new data object to make self.point_data_src.data = self.make_point_data() + #Set the color map + self.set_points_lut(display.color_map == display.COLOR_BY_PREDICTED) + if self.in_pixel_mode(): # ------------ Pixel View ----------------------- self.pixel_view = True diff --git a/gui/panel_reflections_view_options.py b/gui/panel_reflections_view_options.py index d471d2b..df819a4 100644 --- a/gui/panel_reflections_view_options.py +++ b/gui/panel_reflections_view_options.py @@ -361,7 +361,7 @@ def _init_ctrls(self, prnt): self.radioPredicted.SetValue(True) self.staticTextThreshold = wx.StaticText(label=u'I/sigI threshold', parent=self, style=0) - self.textThreshold = wx.TextCtrl(value=u'2.0', parent=self, style=0) + self.textThreshold = wx.TextCtrl(value=u'2.0', parent=self, style=wx.TE_PROCESS_ENTER) self.textThreshold.Bind(wx.EVT_TEXT_ENTER, self.OntextThreshold) self.textThreshold.Bind(wx.EVT_KILL_FOCUS, self.OnChangeMaskingSettings) @@ -405,6 +405,7 @@ def OnCheckRealtimeSliceCheckbox(self, event): event.Skip() def OntextThreshold(self, event): + print "pressed enter>:?" self.controller.change_masking_settings() event.Skip() diff --git a/gui/value_slider.py b/gui/value_slider.py index 21edfe5..0a98204 100644 --- a/gui/value_slider.py +++ b/gui/value_slider.py @@ -110,7 +110,7 @@ def _init_ctrls(self, prnt): name=u'textValue', parent=self, pos=wx.Point(80, 0), size=wx.Size(80, 27), style=wx.TE_PROCESS_ENTER, value=u'0') self.textValue.Bind(wx.EVT_TEXT, self.OnTextValueText) - self.textValue.Bind(wx.EVT_TEXT_ENTER, self.OnTextEnter) + self.textValue.Bind(wx.EVT_TEXT_ENTER, self.OnTextEnter) #Don't forget the wx.TE_PROCESS_ENTER otherwise it doesn't work. self.textValue.Bind(wx.EVT_KILL_FOCUS, self.OnTextEnter) self.textValue.Bind(wx.EVT_KEY_UP, self.OnTextValueKeyUp) diff --git a/model/experiment.py b/model/experiment.py index dfbfe6d..758b475 100644 --- a/model/experiment.py +++ b/model/experiment.py @@ -670,11 +670,13 @@ def initialize_reflections(self): #Clear the list of reflection times measured self.get_reflections_times_measured(clear_list=True) + #And if you had any peaks files loaded, reload them. + self.reload_peaks_files() + #At this point, the reflections mask needs to be updated since the reflections changed. self.calculate_reflections_mask() - #And if you had any peaks files loaded, reload them. - self.reload_peaks_files() + #------------------------------------------------------------------------------- @@ -1007,9 +1009,7 @@ def recalculate_reflections(self, pos_param, calculation_callback=None): self.get_reflections_times_measured(None) #We make the array of how many times REALLY measured, for all the positions - refmask = self.params[PARAM_REFLECTION_MASKING] #@type refmask ParamReflectionMasking - if refmask is None: refmask = ParamReflectionMasking() - self.get_reflections_times_real_measured(refmask.threshold) + self.get_reflections_times_real_measured(None) #Continue on with masking self.calculate_reflections_mask() @@ -1154,8 +1154,16 @@ def get_reflections_times_real_measured(self, threshold): ----------- pos_param: a ParamPositions object holding which positions to keep in the calculation. None means use all of them (default). - threshold: I/sigI threshold to consider a peak "measured" + threshold: I/sigI threshold to consider a peak "measured". Set None to use the last + saved parameter. """ + + #Find the threshold if not specified. + if threshold is None: + refmask = self.params[PARAM_REFLECTION_MASKING] #@type refmask ParamReflectionMasking + if refmask is None: refmask = ParamReflectionMasking() + threshold = refmask.threshold + #Initialize the arrays rtm = np.zeros( (len(self.reflections), 1) ) rtme = np.zeros( (len(self.reflections), 1) ) @@ -2087,6 +2095,9 @@ def reload_peaks_files(self): else: self.load_peaks_file(filename, append=True) + #Now, redo the stats + self.get_reflections_times_real_measured(None) + #--------------------------------------------------------------------------------------------- def compare_to_peaks_file(self, filename): """Compare the contents of an ISAW .peaks file with the measurements in this experiment.""" diff --git a/model/reflections.py b/model/reflections.py index 003a48d..fd4cf17 100644 --- a/model/reflections.py +++ b/model/reflections.py @@ -161,10 +161,15 @@ def times_real_measured(self, threshold=-1.0, add_equivalent_ones=False): #@type rrm ReflectionRealMeasurement for rrm in ref.real_measurements: if not rrm is None: - #Don't divide by 0 - if rrm.sigI > 1e-8: - if (rrm.integrated / rrm.sigI) > threshold: - total += 1 + if threshold <= 0: + #A zero or lower threshold = take all comers + total += 1 + else: + #Check the I/sigI value. + #Avoid divide by 0 + if (rrm.sigI > 1e-8): + if (rrm.integrated / rrm.sigI) > threshold: + total += 1 return total