Changeset 6ef7ac5a in sasview for simview/perspectives/simulation/simulation.py
- Timestamp:
- Dec 31, 2009 6:26:14 PM (14 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.