- Timestamp:
- Dec 31, 2009 6:26:14 PM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 6bbcbd9
- Parents:
- 7e8601f
- Location:
- simview/perspectives/simulation
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
simview/perspectives/simulation/ShapeParameters.py
rcb78690 r6ef7ac5a 14 14 import SimCanvas 15 15 16 17 16 (CreateShapeEvent, EVT_ADD_SHAPE) = wx.lib.newevent.NewEvent() 18 17 (EditShapeEvent, EVT_EDIT_SHAPE) = wx.lib.newevent.NewEvent() 19 (DelShapeEvent, EVT_DEL_SHAPE) = wx.lib.newevent.NewEvent() 18 (DelShapeEvent, EVT_DEL_SHAPE) = wx.lib.newevent.NewEvent() 19 (QRangeEvent, EVT_Q_RANGE) = wx.lib.newevent.NewEvent() 20 (PtDensityEvent, EVT_PT_DENSITY) = wx.lib.newevent.NewEvent() 20 21 21 22 class ShapeParameterPanel(wx.Panel): … … 24 25 CENTER_PANE = True 25 26 26 def __init__(self, parent, *args, **kwargs):27 def __init__(self, parent, q_min=0.001, q_max=0.5, q_npts=10, pt_density=0.1, *args, **kwargs): 27 28 wx.Panel.__init__(self, parent, *args, **kwargs) 28 29 … … 62 63 63 64 self.model_combo = wx.ComboBox(self, -1, value=value_list[0], choices=value_list, style=wx.CB_READONLY) 64 self.model_combo.SetToolTip(wx.ToolTip(" select a geometric shape from the drop-down list"))65 self.model_combo.SetToolTip(wx.ToolTip("Select a geometric shape from the drop-down list")) 65 66 66 67 ny+=1 … … 78 79 self.bck.Add(point_density_text, (ny,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 79 80 self.point_density_ctrl = wx.TextCtrl(self, -1, size=(40,20), style=wx.TE_PROCESS_ENTER) 80 self.point_density_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_parameter_changed) 81 self.point_density_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_parameter_changed) 81 self.point_density_ctrl.SetValue(str(pt_density)) 82 self.point_density_ctrl.SetToolTip(wx.ToolTip("Enter the number of real-space points per Angstrom cube")) 83 self.point_density_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_density_changed) 84 self.point_density_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_density_changed) 82 85 self.bck.Add(self.point_density_ctrl, (ny,1), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 83 86 … … 87 90 self.bck.Add(q_min_text, (ny,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 88 91 self.q_min_ctrl = wx.TextCtrl(self, -1, size=(40,20), style=wx.TE_PROCESS_ENTER) 89 self.q_min_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_parameter_changed) 90 self.q_min_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_parameter_changed) 92 self.q_min_ctrl.SetValue(str(q_min)) 93 self.q_min_ctrl.SetToolTip(wx.ToolTip("Enter the minimum Q value to be simulated")) 94 self.q_min_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_q_range_changed) 95 self.q_min_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_q_range_changed) 91 96 self.bck.Add(self.q_min_ctrl, (ny,1), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 92 97 … … 94 99 self.bck.Add(q_max_text, (ny,2), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 95 100 self.q_max_ctrl = wx.TextCtrl(self, -1, size=(40,20), style=wx.TE_PROCESS_ENTER) 96 self.q_max_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_parameter_changed) 97 self.q_max_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_parameter_changed) 101 self.q_max_ctrl.SetValue(str(q_max)) 102 self.q_min_ctrl.SetToolTip(wx.ToolTip("Enter the maximum Q value to be simulated")) 103 self.q_max_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_q_range_changed) 104 self.q_max_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_q_range_changed) 98 105 self.bck.Add(self.q_max_ctrl, (ny,3), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 106 107 q_npts_text = wx.StaticText(self, -1, "No. of Q pts", style=wx.ALIGN_LEFT) 108 self.bck.Add(q_npts_text, (ny,4), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 109 self.q_npts_ctrl = wx.TextCtrl(self, -1, size=(40,20), style=wx.TE_PROCESS_ENTER) 110 self.q_npts_ctrl.SetValue(str(q_npts)) 111 self.q_min_ctrl.SetToolTip(wx.ToolTip("Enter the number of Q points to be simulated")) 112 self.q_npts_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_q_range_changed) 113 self.q_npts_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_q_range_changed) 114 self.bck.Add(self.q_npts_ctrl, (ny,5), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 99 115 100 116 # Shape List … … 132 148 self.editShape(shape) 133 149 134 def _on_ parameter_changed(self, event):150 def _on_density_changed(self, event): 135 151 """ 136 152 Process event that might mean a change of the simulation point density 137 153 """ 138 event_obj = event.GetEventObject() 139 if event_obj.IsModified(): 140 event_obj.SetModified(False) 141 self._simulation_update() 142 143 def _simulation_update(self): 144 """ 145 Process an update of the simulation parameters 146 """ 147 #TODO: create an event to pass the parameters to the simulation plug-in for processing 148 print "TODO: Simulation update" 149 pass 150 154 npts = self._readCtrlFloat(self.point_density_ctrl) 155 if npts is not None: 156 event = PtDensityEvent(npts=npts) 157 wx.PostEvent(self.parent, event) 158 159 def _on_q_range_changed(self, event): 160 """ 161 Process event that might mean a change in Q range 162 @param event: EVT_Q_RANGE event 163 """ 164 q_min = self._readCtrlFloat(self.q_min_ctrl) 165 q_max = self._readCtrlFloat(self.q_max_ctrl) 166 npts = self._readCtrlInt(self.q_npts_ctrl) 167 if q_min is not None or q_max is not None or npts is not None: 168 event = QRangeEvent(q_min=q_min, q_max=q_max, npts=npts) 169 wx.PostEvent(self.parent, event) 170 151 171 def _onEditShape(self, evt): 152 172 """ … … 295 315 296 316 def _readCtrlFloat(self, ctrl): 317 """ 318 Parses a TextCtrl for a float value. 319 Returns None is the value hasn't changed or the value is not a float. 320 The control background turns pink if the value is not a float. 321 322 @param ctrl: TextCtrl object 323 """ 297 324 if ctrl.IsModified(): 325 ctrl.SetModified(False) 298 326 str_value = ctrl.GetValue().lstrip().rstrip() 299 327 try: … … 303 331 ctrl.Refresh() 304 332 return flt_value 333 except: 334 ctrl.SetBackgroundColour("pink") 335 ctrl.Refresh() 336 return None 337 338 def _readCtrlInt(self, ctrl): 339 """ 340 Parses a TextCtrl for a float value. 341 Returns None is the value hasn't changed or the value is not a float. 342 The control background turns pink if the value is not a float. 343 344 @param ctrl: TextCtrl object 345 """ 346 if ctrl.IsModified(): 347 ctrl.SetModified(False) 348 str_value = ctrl.GetValue().lstrip().rstrip() 349 try: 350 int_value = int(str_value) 351 ctrl.SetBackgroundColour( 352 wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)) 353 ctrl.Refresh() 354 return int_value 305 355 except: 306 356 ctrl.SetBackgroundColour("pink") -
simview/perspectives/simulation/requirements.txt
reaeb13e r6ef7ac5a 1 1 UI requirements 2 - Allow user to modify q range from main panel 2 - Allow user to modify q range from main panel [DONE] 3 3 - Move list of shapes from top menu to central simulation panel 4 - Popup P(r) plot and update for each simulation 4 - Popup P(r) plot and update for each simulation [DONE] 5 5 - Allow user to choose whether he wants the simulation to be run automatically with each parameter change 6 6 or whether he wants to hit 'simulate' himself when he's done. -
simview/perspectives/simulation/simulation.py
rcb78690 r6ef7ac5a 71 71 ## Default number of q point for simulation output 72 72 DEFAULT_Q_NPTS = 10 73 ## Default number of real-space points per Angstrom cube 74 DEFAULT_PT_DENSITY = 0.1 73 75 74 76 class Plugin: … … 105 107 106 108 # Central simulation panel 107 self.paramPanel = ShapeParameters.ShapeParameterPanel(self.parent, style=wx.RAISED_BORDER) 109 self.paramPanel = ShapeParameters.ShapeParameterPanel(self.parent, 110 q_min = self.q_min, 111 q_max = self.q_max, 112 q_npts = self.q_npts, 113 pt_density = DEFAULT_PT_DENSITY, 114 style=wx.RAISED_BORDER) 108 115 109 116 # Simulation 110 117 self.volCanvas = VolumeCanvas.VolumeCanvas() 111 self.volCanvas.setParam('lores_density', 0.1)118 self.volCanvas.setParam('lores_density', DEFAULT_PT_DENSITY) 112 119 self.adapter = ShapeAdapter.ShapeVisitor() 113 120 self._data_1D = None … … 128 135 self.parent.Bind(ShapeParameters.EVT_ADD_SHAPE, self._onAddShape) 129 136 self.parent.Bind(ShapeParameters.EVT_DEL_SHAPE, self._onDelShape) 137 self.parent.Bind(ShapeParameters.EVT_Q_RANGE, self._on_q_range_changed) 138 self.parent.Bind(ShapeParameters.EVT_PT_DENSITY, self._on_pt_density_changed) 130 139 131 140 return [self.plotPanel, self.paramPanel] … … 166 175 # Refresh the 3D viewer 167 176 self._refresh_3D_viewer() 177 178 def _on_q_range_changed(self, evt): 179 """ 180 Modify the Q range of the simulation output 181 """ 182 if evt.q_min is not None: 183 self.q_min = evt.q_min 184 if evt.q_max is not None: 185 self.q_max = evt.q_max 186 if evt.npts is not None: 187 self.q_npts = evt.npts 188 189 # Q-values for plotting simulated I(Q) 190 step = (self.q_max-self.q_min)/(self.q_npts-1) 191 self.x = numpy.arange(self.q_min, self.q_max+step*0.01, step) 192 193 # Compute the simulated I(Q) 194 self._simulate_Iq() 195 196 def _on_pt_density_changed(self, evt): 197 """ 198 Modify the Q range of the simulation output 199 """ 200 if evt.npts is not None: 201 self.volCanvas.setParam('lores_density', evt.npts) 202 203 # Compute the simulated I(Q) 204 self._simulate_Iq() 168 205 169 206 def _simulate_Iq(self): … … 212 249 # Create the plotting event to pop up the I(Q) plot. 213 250 new_plot = Data1D(x=self.x, y=output, dy=error) 214 new_plot.name = " Simulation"251 new_plot.name = "I(Q) Simulation" 215 252 new_plot.group_id = "simulation_output" 216 253 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 217 254 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 218 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Simulation output")) 255 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Simulation I(Q)")) 256 257 # Create the plotting event to pop up the P(r) plot. 258 r, pr = self.volCanvas.getPrData() 259 new_plot = Data1D(x=r, y=pr, dy=[0]*len(r)) 260 new_plot.name = "P(r) Simulation" 261 new_plot.group_id = "simulated_pr" 262 new_plot.xaxis("\\rm{r}", 'A') 263 new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 264 265 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Simulated P(r)")) 266 219 267 220 268 # Notify the user of the simlation time and update the basic … … 235 283 def populate_menu(self, id, owner): 236 284 """ 237 -- TEMPORARY --238 285 Create a menu for the plug-in 239 240 #TODO: remove this method once: 241 1- P(r) is plotted with the I(q) simulation result 242 """ 243 # Shapes 244 shapes = wx.Menu() 245 246 #TODO: Save P(r) should be replaced by plotting P(r) for each simulation 247 id = wx.NewId() 248 shapes.Append(id, '&Save P(r) output') 249 wx.EVT_MENU(self.parent, id, self._onSavePr) 250 251 return [(id+1, shapes, "Save P(r)")] 286 """ 287 return [] 252 288 253 289 def _change_point_density(self, point_density): … … 257 293 """ 258 294 self.volCanvas.setParam('lores_density', point_density) 259 260 def _onSavePr(self, evt):261 """262 Save the current P(r) output to a file263 TODO: refactor this away once P(r) is plotted264 """265 path = None266 dlg = wx.FileDialog(None, "Choose a file", self._default_save_location, "", "*.txt", wx.SAVE)267 if dlg.ShowModal() == wx.ID_OK:268 path = dlg.GetPath()269 self._default_save_location = os.path.dirname(path)270 dlg.Destroy()271 272 if not path == None:273 self.volCanvas.write_pr(path)274 295 275 296 def help(self, evt):
Note: See TracChangeset
for help on using the changeset viewer.