Changeset af6b53c in sasview for src/sas/perspectives
- Timestamp:
- Mar 4, 2015 11:50:03 AM (10 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:
- 76aed53
- Parents:
- 7cd87c2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/calculator/resolution_calculator_panel.py
r18d58a6e raf6b53c 1 # pylint: disable=attribute-defined-outside-init 1 2 """ 2 3 This software was developed by the University of Tennessee as part of the 3 4 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 project funded by the US National Science Foundation. 5 project funded by the US National Science Foundation. 5 6 6 7 See the license text in license.txt … … 13 14 import matplotlib 14 15 import math 16 import logging 15 17 #Use the WxAgg back end. The Wx one takes too long to render 16 18 matplotlib.use('WXAgg') … … 23 25 from matplotlib.figure import Figure 24 26 25 #from sas.guicomm.events import StatusEvent 26 from sas.calculator.resolution_calculator import ResolutionCalculator 27 from sas.guiframe.events import StatusEvent 27 #from sas.guicomm.events import StatusEvent 28 from sas.calculator.resolution_calculator import ResolutionCalculator 29 from sas.guiframe.events import StatusEvent 28 30 from sas.perspectives.calculator.calculator_widgets import OutputTextCtrl 29 31 from sas.perspectives.calculator.calculator_widgets import InputTextCtrl 30 32 from wx.lib.scrolledpanel import ScrolledPanel 31 33 from math import fabs 32 from sas.perspectives.calculator import calculator_widgets as widget 34 from sas.perspectives.calculator import calculator_widgets as widget 33 35 from sas.guiframe.documentation_window import DocumentationWindow 34 36 35 37 _BOX_WIDTH = 100 36 38 _Q_DEFAULT = 0.0 37 #Slit length panel size 39 #Slit length panel size 38 40 if sys.platform.count("win32") > 0: 39 41 PANEL_WIDTH = 525 … … 49 51 _SOURCE_MASS = {'Alpha':6.64465620E-24, 50 52 'Deuteron':3.34358320E-24, 51 'Neutron':1.67492729E-24, 53 'Neutron':1.67492729E-24, 52 54 'Photon': 0.0, 53 55 'Proton':1.67262137E-24, … … 64 66 ## Flag to tell the AUI manager to put this panel in the center pane 65 67 CENTER_PANE = True 66 67 def __init__(self, parent, 68 69 def __init__(self, parent, *args, **kwds): 68 70 kwds["size"] = (PANEL_WIDTH * 2, PANEL_HEIGHT) 69 71 kwds["style"] = wx.FULL_REPAINT_ON_RESIZE … … 71 73 self.SetupScrolling() 72 74 self.parent = parent 73 75 74 76 # input defaults 75 77 self.qx = [] … … 87 89 # results of sigmas 88 90 self.sigma_strings = ' ' 89 #Font size 91 #Font size 90 92 self.SetWindowVariant(variant=FONT_VARIANT) 91 93 # Object that receive status event … … 110 112 self.vertical_r_sizer = wx.StaticBoxSizer(self.vertical_r_frame, 111 113 wx.VERTICAL) 112 self.box_source = wx.StaticBox(self, -1, 113 str(self.window_caption)) 114 self.boxsizer_source = wx.StaticBoxSizer(self.box_source, 115 wx.VERTICAL) 114 self.box_source = wx.StaticBox(self, -1, str(self.window_caption)) 115 self.boxsizer_source = wx.StaticBoxSizer(self.box_source, wx.VERTICAL) 116 116 self.mass_sizer = wx.BoxSizer(wx.HORIZONTAL) 117 117 self.intensity_sizer = wx.BoxSizer(wx.HORIZONTAL) … … 125 125 self.detector_size_sizer = wx.BoxSizer(wx.HORIZONTAL) 126 126 self.detector_pix_size_sizer = wx.BoxSizer(wx.HORIZONTAL) 127 #self.detector_offset_sizer = wx.BoxSizer(wx.HORIZONTAL)128 127 self.input_sizer = wx.BoxSizer(wx.VERTICAL) 129 128 self.output_sizer = wx.BoxSizer(wx.VERTICAL) 130 129 self.hint_sizer = wx.BoxSizer(wx.HORIZONTAL) 131 130 self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) 132 131 133 132 def _layout_mass(self): 134 133 """ … … 137 136 # get the mass 138 137 mass_value = str(self.resolution.mass) 139 self.mass_txt = wx.StaticText(self, -1, 140 'Source: ') 141 self.mass_hint = "Mass of Neutrons m = %s [g]"\ 142 % str(self.resolution.mass) 138 self.mass_txt = wx.StaticText(self, -1, 'Source: ') 139 self.mass_hint = "Mass of Neutrons m = %s [g]" % str(self.resolution.mass) 143 140 self.source_cb = wx.ComboBox(self, -1, 144 style=wx.CB_READONLY,145 name = '%s'%mass_value)141 style=wx.CB_READONLY, 142 name='%s' % mass_value) 146 143 # Sort source name because wx2.9 on Mac does not support CB_SORT 147 144 # Custom sorting 148 145 source_list = [] 149 for key, valuein self.source_mass.iteritems():146 for key, _ in self.source_mass.iteritems(): 150 147 name_source = str(key) 151 148 source_list.append(name_source) … … 153 150 for idx in range(len(source_list)): 154 151 self.source_cb.Append(source_list[idx], idx) 155 self.source_cb.SetStringSelection("Neutron") 156 wx.EVT_COMBOBOX(self.source_cb, -1, self._on_source_selection) 157 152 self.source_cb.SetStringSelection("Neutron") 153 wx.EVT_COMBOBOX(self.source_cb, -1, self._on_source_selection) 154 158 155 # combo box for color 159 self.wave_color_cb = 160 style=wx.CB_READONLY,161 name ='color')156 self.wave_color_cb = wx.ComboBox(self, -1, 157 style=wx.CB_READONLY, 158 name='color') 162 159 # two choices 163 160 self.wave_color_cb.Append('Monochromatic') 164 161 self.wave_color_cb.Append('TOF') 165 self.wave_color_cb.SetStringSelection("Monochromatic") 166 wx.EVT_COMBOBOX(self.wave_color_cb, -1, self._on_source_color) 167 162 self.wave_color_cb.SetStringSelection("Monochromatic") 163 wx.EVT_COMBOBOX(self.wave_color_cb, -1, self._on_source_color) 164 168 165 source_hint = "Source Selection: Affect on" 169 166 source_hint += " the gravitational contribution.\n" … … 172 169 self.mass_txt.SetToolTipString(source_hint) 173 170 self.mass_sizer.AddMany([(self.mass_txt, 0, wx.LEFT, 15), 174 175 (self.wave_color_cb, 0, wx.LEFT, 15)])176 171 (self.source_cb, 0, wx.LEFT, 15), 172 (self.wave_color_cb, 0, wx.LEFT, 15)]) 173 177 174 def _layout_intensity(self): 178 175 """ … … 182 179 intensity_value = str(self.resolution.intensity) 183 180 intensity_unit_txt = wx.StaticText(self, -1, '[counts/s]') 184 intensity_txt = wx.StaticText(self, -1, 185 'Intensity: ') 186 self.intensity_tcl = InputTextCtrl(self, -1, 187 size=(_BOX_WIDTH,-1)) 181 intensity_txt = wx.StaticText(self, -1, 'Intensity: ') 182 self.intensity_tcl = InputTextCtrl(self, -1, 183 size=(_BOX_WIDTH, -1)) 188 184 intensity_hint = "Intensity of Neutrons" 189 185 self.intensity_tcl.SetValue(intensity_value) 190 186 self.intensity_tcl.SetToolTipString(intensity_hint) 191 187 self.intensity_sizer.AddMany([(intensity_txt, 0, wx.LEFT, 15), 192 (self.intensity_tcl, 0, wx.LEFT, 15),193 (intensity_unit_txt,0, wx.LEFT, 10)])194 195 188 (self.intensity_tcl, 0, wx.LEFT, 15), 189 (intensity_unit_txt, 0, wx.LEFT, 10)]) 190 191 196 192 def _layout_wavelength(self): 197 193 """ … … 201 197 wavelength_value = str(self.resolution.get_wavelength()) 202 198 wavelength_unit_txt = wx.StaticText(self, -1, '[A]') 203 wavelength_txt = wx.StaticText(self, -1, 204 'Wavelength: ') 205 self.wavelength_tcl = InputTextCtrl(self, -1, 206 size=(_BOX_WIDTH,-1)) 199 wavelength_txt = wx.StaticText(self, -1, 'Wavelength: ') 200 self.wavelength_tcl = InputTextCtrl(self, -1, 201 size=(_BOX_WIDTH, -1)) 207 202 wavelength_hint = "Wavelength of Neutrons" 208 203 self.wavelength_tcl.SetValue(wavelength_value) … … 213 208 self.spectrum_dic['Add new'] = '' 214 209 self.spectrum_dic['Flat'] = spectrum_value 215 216 self.spectrum_txt = wx.StaticText(self, -1, 217 'Spectrum: ') 210 211 self.spectrum_txt = wx.StaticText(self, -1, 'Spectrum: ') 218 212 self.spectrum_cb = wx.ComboBox(self, -1, 219 style=wx.CB_READONLY,220 size=(_BOX_WIDTH,-1),221 name ='spectrum')213 style=wx.CB_READONLY, 214 size=(_BOX_WIDTH, -1), 215 name='spectrum') 222 216 self.spectrum_cb.Append('Add new') 223 217 self.spectrum_cb.Append('Flat') 224 wx.EVT_COMBOBOX(self.spectrum_cb, -1, self._on_spectrum_cb) 218 wx.EVT_COMBOBOX(self.spectrum_cb, -1, self._on_spectrum_cb) 225 219 spectrum_hint = "Wavelength Spectrum: Intensity vs. wavelength" 226 #self.spectrum_cb.SetValue(spectrum_value) 227 self.spectrum_cb.SetStringSelection('Flat') 220 self.spectrum_cb.SetStringSelection('Flat') 228 221 self.spectrum_cb.SetToolTipString(spectrum_hint) 229 222 self.wavelength_sizer.AddMany([(wavelength_txt, 0, wx.LEFT, 15), 230 (self.wavelength_tcl, 0, wx.LEFT, 5),231 (wavelength_unit_txt,0, wx.LEFT, 5),232 (self.spectrum_txt, 0, wx.LEFT, 20),233 (self.spectrum_cb, 0, wx.LEFT, 5)])223 (self.wavelength_tcl, 0, wx.LEFT, 5), 224 (wavelength_unit_txt, 0, wx.LEFT, 5), 225 (self.spectrum_txt, 0, wx.LEFT, 20), 226 (self.spectrum_cb, 0, wx.LEFT, 5)]) 234 227 self.spectrum_txt.Show(False) 235 228 self.spectrum_cb.Show(False) 236 229 237 230 def _layout_wavelength_spread(self): 238 231 """ … … 242 235 wavelength_spread_value = str(self.resolution.get_wavelength_spread()) 243 236 wavelength_spread_unit_txt = wx.StaticText(self, -1, '') 244 wavelength_spread_txt = wx.StaticText(self, -1, 245 'Wavelength Spread: ') 246 self.wavelength_spread_tcl = InputTextCtrl(self, -1, 247 size=(_BOX_WIDTH,-1)) 237 wavelength_spread_txt = wx.StaticText(self, -1, 'Wavelength Spread: ') 238 self.wavelength_spread_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 248 239 wavelength_spread_hint = "Wavelength Spread of Neutrons" 249 240 self.wavelength_spread_tcl.SetValue(wavelength_spread_value) 250 241 self.wavelength_spread_tcl.SetToolTipString(wavelength_spread_hint) 251 self.wavelength_spread_sizer.AddMany([(wavelength_spread_txt, 0, 242 self.wavelength_spread_sizer.AddMany([(wavelength_spread_txt, 0, 252 243 wx.LEFT, 15), 253 (self.wavelength_spread_tcl, 0, wx.LEFT, 15),254 (wavelength_spread_unit_txt,0, wx.LEFT, 10)])255 256 244 (self.wavelength_spread_tcl, 0, wx.LEFT, 15), 245 (wavelength_spread_unit_txt, 0, wx.LEFT, 10)]) 246 247 257 248 def _layout_source_aperture(self): 258 249 """ … … 261 252 # get the wavelength 262 253 source_aperture_value = str(self.resolution.source_aperture_size[0]) 263 if len(self.resolution.source_aperture_size) >1:254 if len(self.resolution.source_aperture_size) > 1: 264 255 source_aperture_value += ", " 265 source_aperture_value += str(\ 266 self.resolution.source_aperture_size[1]) 256 source_aperture_value += str(self.resolution.source_aperture_size[1]) 267 257 source_aperture_unit_txt = wx.StaticText(self, -1, '[cm]') 268 source_aperture_txt = wx.StaticText(self, -1, 269 'Source Aperture Size: ') 270 self.source_aperture_tcl = InputTextCtrl(self, -1, 271 size=(_BOX_WIDTH,-1)) 258 source_aperture_txt = wx.StaticText(self, -1, 'Source Aperture Size: ') 259 self.source_aperture_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 272 260 source_aperture_hint = "Source Aperture Size" 273 261 self.source_aperture_tcl.SetValue(source_aperture_value) 274 262 self.source_aperture_tcl.SetToolTipString(source_aperture_hint) 275 self.source_aperture_sizer.AddMany([(source_aperture_txt, 0, 276 wx.LEFT, 15), 277 (self.source_aperture_tcl, 0, wx.LEFT, 15), 278 (source_aperture_unit_txt, 0, wx.LEFT, 10)]) 279 280 263 self.source_aperture_sizer.AddMany([(source_aperture_txt, 0, wx.LEFT, 15), 264 (self.source_aperture_tcl, 0, wx.LEFT, 15), 265 (source_aperture_unit_txt, 0, wx.LEFT, 10)]) 266 281 267 def _layout_sample_aperture(self): 282 268 """ … … 285 271 # get the wavelength 286 272 sample_aperture_value = str(self.resolution.sample_aperture_size[0]) 287 if len(self.resolution.sample_aperture_size) >1:273 if len(self.resolution.sample_aperture_size) > 1: 288 274 sample_aperture_value += ", " 289 sample_aperture_value += str(\ 290 self.resolution.sample_aperture_size[1]) 275 sample_aperture_value += str(self.resolution.sample_aperture_size[1]) 291 276 sample_aperture_unit_txt = wx.StaticText(self, -1, '[cm]') 292 sample_aperture_txt = wx.StaticText(self, -1, 293 'Sample Aperture Size: ') 294 self.sample_aperture_tcl = InputTextCtrl(self, -1, 295 size=(_BOX_WIDTH,-1)) 277 sample_aperture_txt = wx.StaticText(self, -1, 'Sample Aperture Size: ') 278 self.sample_aperture_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 296 279 sample_aperture_hint = "Sample Aperture Size" 297 280 self.sample_aperture_tcl.SetValue(sample_aperture_value) 298 281 self.sample_aperture_tcl.SetToolTipString(sample_aperture_hint) 299 self.sample_aperture_sizer.AddMany([(sample_aperture_txt, 0, 300 wx.LEFT, 15), 301 (self.sample_aperture_tcl, 0, wx.LEFT, 15), 302 (sample_aperture_unit_txt, 0, wx.LEFT, 10)]) 303 282 self.sample_aperture_sizer.AddMany([(sample_aperture_txt, 0, wx.LEFT, 15), 283 (self.sample_aperture_tcl, 0, wx.LEFT, 15), 284 (sample_aperture_unit_txt, 0, wx.LEFT, 10)]) 304 285 305 286 def _layout_source2sample_distance(self): … … 308 289 """ 309 290 # get the wavelength 310 source2sample_distance_value = str(\ 311 self.resolution.source2sample_distance[0]) 291 source2sample_distance_value = str(self.resolution.source2sample_distance[0]) 312 292 313 293 source2sample_distance_unit_txt = wx.StaticText(self, -1, '[cm]') 314 source2sample_distance_txt = wx.StaticText(self, -1, 315 'Source to Sample Aperture Distance: ') 316 self.source2sample_distance_tcl = InputTextCtrl(self, -1, 317 size=(_BOX_WIDTH,-1)) 294 source2sample_distance_txt = wx.StaticText(self, -1, 295 'Source to Sample Aperture Distance: ') 296 self.source2sample_distance_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 318 297 source2sample_distance_hint = "Source to Sample Aperture Distance" 319 298 self.source2sample_distance_tcl.SetValue(source2sample_distance_value) 320 self.source2sample_distance_tcl.SetToolTipString(\ 321 source2sample_distance_hint) 322 self.source2sample_distance_sizer.AddMany([(source2sample_distance_txt, 323 0, wx.LEFT, 15), 324 (self.source2sample_distance_tcl, 0, wx.LEFT, 15), 325 (source2sample_distance_unit_txt,0, wx.LEFT, 10)]) 299 self.source2sample_distance_tcl.SetToolTipString(source2sample_distance_hint) 300 self.source2sample_distance_sizer.AddMany([(source2sample_distance_txt, 0, wx.LEFT, 15), 301 (self.source2sample_distance_tcl, 0, wx.LEFT, 15), 302 (source2sample_distance_unit_txt, 0, wx.LEFT, 10)]) 326 303 327 304 def _layout_sample2sample_distance(self): … … 330 307 """ 331 308 # get the distance 332 sample2sample_distance_value = str(\ 333 self.resolution.sample2sample_distance[0]) 309 sample2sample_distance_value = str(self.resolution.sample2sample_distance[0]) 334 310 335 311 sample2sample_distance_unit_txt = wx.StaticText(self, -1, '[cm]') 336 sample2sample_distance_txt = wx.StaticText(self, -1, 337 'Sample Offset: ') 338 self.sample2sample_distance_tcl = InputTextCtrl(self, -1, 339 size=(_BOX_WIDTH,-1)) 312 sample2sample_distance_txt = wx.StaticText(self, -1, 'Sample Offset: ') 313 self.sample2sample_distance_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 340 314 sample2sample_distance_hint = "Sample Aperture to Sample Distance" 341 315 self.sample2sample_distance_tcl.SetValue(sample2sample_distance_value) 342 self.sample2sample_distance_tcl.SetToolTipString(\ 343 sample2sample_distance_hint) 344 self.sample2sample_distance_sizer.AddMany([(sample2sample_distance_txt, 345 0, wx.LEFT, 15), 346 (self.sample2sample_distance_tcl, 0, wx.LEFT, 15), 347 (sample2sample_distance_unit_txt,0, wx.LEFT, 10)]) 348 349 316 self.sample2sample_distance_tcl.SetToolTipString(sample2sample_distance_hint) 317 self.sample2sample_distance_sizer.AddMany([(sample2sample_distance_txt, 0, wx.LEFT, 15), 318 (self.sample2sample_distance_tcl, 0, wx.LEFT, 15), 319 (sample2sample_distance_unit_txt, 0, wx.LEFT, 10)]) 350 320 351 321 def _layout_sample2detector_distance(self): … … 354 324 """ 355 325 # get the wavelength 356 sample2detector_distance_value = str(\ 357 self.resolution.sample2detector_distance[0]) 326 sample2detector_distance_value = str(self.resolution.sample2detector_distance[0]) 358 327 359 328 sample2detector_distance_unit_txt = wx.StaticText(self, -1, '[cm]') 360 sample2detector_distance_txt = wx.StaticText(self, -1, 361 'Sample Aperture to Detector Distance: ') 362 self.sample2detector_distance_tcl = InputTextCtrl(self, -1, 363 size=(_BOX_WIDTH,-1)) 364 sample2detector_distance_hint = \ 365 "Sample Aperture to Detector Distance" 366 self.sample2detector_distance_tcl.SetValue(\ 367 sample2detector_distance_value) 368 self.sample2detector_distance_tcl.SetToolTipString(\ 369 sample2detector_distance_hint) 329 sample2detector_distance_txt = wx.StaticText(self, -1, 330 'Sample Aperture to Detector Distance: ') 331 self.sample2detector_distance_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 332 sample2detector_distance_hint = "Sample Aperture to Detector Distance" 333 self.sample2detector_distance_tcl.SetValue(sample2detector_distance_value) 334 self.sample2detector_distance_tcl.SetToolTipString(sample2detector_distance_hint) 370 335 self.sample2detector_distance_sizer.AddMany([\ 371 (sample2detector_distance_txt, 0, wx.LEFT, 15), 336 (sample2detector_distance_txt, 0, wx.LEFT, 15), 372 337 (self.sample2detector_distance_tcl, 0, wx.LEFT, 15), 373 (sample2detector_distance_unit_txt, 0, wx.LEFT, 10)])374 338 (sample2detector_distance_unit_txt, 0, wx.LEFT, 10)]) 339 375 340 def _layout_detector_size(self): 376 341 """ … … 379 344 # get the wavelength 380 345 detector_size_value = str(self.resolution.detector_size[0]) 381 if len(self.resolution.detector_size) >1:346 if len(self.resolution.detector_size) > 1: 382 347 detector_size_value += ", " 383 348 detector_size_value += str(self.resolution.detector_size[1]) 384 349 detector_size_unit_txt = wx.StaticText(self, -1, '') 385 detector_size_txt = wx.StaticText(self, -1, 386 'Number of Pixels on Detector: ') 387 self.detector_size_tcl = InputTextCtrl(self, -1, 388 size=(_BOX_WIDTH,-1)) 350 detector_size_txt = wx.StaticText(self, -1, 'Number of Pixels on Detector: ') 351 self.detector_size_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 389 352 detector_size_hint = "Number of Pixels on Detector" 390 353 self.detector_size_tcl.SetValue(detector_size_value) 391 354 self.detector_size_tcl.SetToolTipString(detector_size_hint) 392 self.detector_size_sizer.AddMany([(detector_size_txt, 0, 393 wx.LEFT, 15), 394 (self.detector_size_tcl, 0, wx.LEFT, 15), 395 (detector_size_unit_txt,0, wx.LEFT, 10)]) 396 397 355 self.detector_size_sizer.AddMany([(detector_size_txt, 0, wx.LEFT, 15), 356 (self.detector_size_tcl, 0, wx.LEFT, 15), 357 (detector_size_unit_txt, 0, wx.LEFT, 10)]) 358 398 359 def _layout_detector_pix_size(self): 399 360 """ … … 402 363 # get the detector_pix_size 403 364 detector_pix_size_value = str(self.resolution.detector_pix_size[0]) 404 if len(self.resolution.detector_pix_size) >1:365 if len(self.resolution.detector_pix_size) > 1: 405 366 detector_pix_size_value += ", " 406 367 detector_pix_size_value += str(self.resolution.detector_pix_size[1]) 407 368 detector_pix_size_unit_txt = wx.StaticText(self, -1, '[cm]') 408 detector_pix_size_txt = wx.StaticText(self, -1, 409 'Detector Pixel Size: ') 410 self.detector_pix_size_tcl = InputTextCtrl(self, -1, 411 size=(_BOX_WIDTH,-1)) 369 detector_pix_size_txt = wx.StaticText(self, -1, 'Detector Pixel Size: ') 370 self.detector_pix_size_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 412 371 detector_pix_size_hint = "Detector Pixel Size" 413 372 self.detector_pix_size_tcl.SetValue(detector_pix_size_value) 414 373 self.detector_pix_size_tcl.SetToolTipString(detector_pix_size_hint) 415 self.detector_pix_size_sizer.AddMany([(detector_pix_size_txt, 0, 416 wx.LEFT, 15), 417 (self.detector_pix_size_tcl, 0, wx.LEFT, 15), 418 (detector_pix_size_unit_txt,0, wx.LEFT, 10)]) 419 374 self.detector_pix_size_sizer.AddMany([(detector_pix_size_txt, 0, wx.LEFT, 15), 375 (self.detector_pix_size_tcl, 0, wx.LEFT, 15), 376 (detector_pix_size_unit_txt, 0, wx.LEFT, 10)]) 377 420 378 def _layout_input(self): 421 379 """ 422 380 Fill the sizer containing inputs; qx, qy 423 381 """ 424 425 q_title = wx.StaticText(self, -1, 426 "[Q Location of the Estimation]:") 382 383 q_title = wx.StaticText(self, -1, "[Q Location of the Estimation]:") 427 384 # sizers for inputs 428 385 inputQx_sizer = wx.BoxSizer(wx.HORIZONTAL) … … 433 390 qx_unit_txt = wx.StaticText(self, -1, '[1/A] ') 434 391 qy_unit_txt = wx.StaticText(self, -1, '[1/A] ') 435 qx_name_txt = wx.StaticText(self, -1, 436 'Qx: ') 437 qy_name_txt = wx.StaticText(self, -1, 438 'Qy: ') 439 self.qx_tcl = InputTextCtrl(self, -1, 440 size=(_BOX_WIDTH*3,-1)) 441 self.qy_tcl = InputTextCtrl(self, -1, 442 size=(_BOX_WIDTH*3,-1)) 392 qx_name_txt = wx.StaticText(self, -1, 'Qx: ') 393 qy_name_txt = wx.StaticText(self, -1, 'Qy: ') 394 self.qx_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH * 3, -1)) 395 self.qy_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH * 3, -1)) 443 396 qx_hint = "Type the Qx value." 444 397 qy_hint = "Type the Qy value." … … 448 401 self.qy_tcl.SetToolTipString(qy_hint) 449 402 inputQx_sizer.AddMany([(qx_name_txt, 0, wx.LEFT, 15), 450 451 403 (self.qx_tcl, 0, wx.LEFT, 15), 404 (qx_unit_txt, 0, wx.LEFT, 15)]) 452 405 inputQy_sizer.AddMany([(qy_name_txt, 0, wx.LEFT, 15), 453 (self.qy_tcl, 0, wx.LEFT, 15), 454 (qy_unit_txt, 0, wx.LEFT, 15)]) 455 self.input_sizer.AddMany([(q_title, 0, wx.LEFT, 15), 456 (inputQx_sizer, 0, 457 wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 458 (inputQy_sizer, 0, 459 wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) 460 #(self.compute_button, 0, wx.LEFT, 30)]) 461 406 (self.qy_tcl, 0, wx.LEFT, 15), 407 (qy_unit_txt, 0, wx.LEFT, 15)]) 408 self.input_sizer.AddMany([(q_title, 0, wx.LEFT, 15), 409 (inputQx_sizer, 0, 410 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 411 (inputQy_sizer, 0, 412 wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 413 462 414 def _layout_output(self): 463 415 """ 464 416 Fill the sizer containing dQ|| and dQ+ 465 417 """ 466 sigma_title = wx.StaticText(self, -1, 467 "[Standard Deviation of the Resolution Distribution]:")468 418 sigma_title = wx.StaticText(self, -1, 419 "[Standard Deviation of the Resolution Distribution]:") 420 # sizers for inputs 469 421 outputQxy_sizer = wx.BoxSizer(wx.HORIZONTAL) 470 422 outputQ_sizer = wx.BoxSizer(wx.HORIZONTAL) 471 sigma_unit = '['+'1/A' +']' 472 self.sigma_r_txt = wx.StaticText(self, -1, 473 'Sigma_x: ') 474 self.sigma_r_tcl = OutputTextCtrl(self, -1, 475 size=(_BOX_WIDTH*0.8,-1)) 476 self.sigma_phi_txt = wx.StaticText(self, -1, 477 'Sigma_y:') 478 self.sigma_phi_tcl = OutputTextCtrl(self, -1, 479 size=(_BOX_WIDTH*0.8,-1)) 480 self.sigma_lamd_txt = wx.StaticText(self, -1, 481 'Sigma_lamd:') 482 self.sigma_lamd_tcl = OutputTextCtrl(self, -1, 483 size=(_BOX_WIDTH*0.7,-1)) 423 sigma_unit = '[' + '1/A' + ']' 424 self.sigma_r_txt = wx.StaticText(self, -1, 'Sigma_x: ') 425 self.sigma_r_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH * 0.8, -1)) 426 self.sigma_phi_txt = wx.StaticText(self, -1, 'Sigma_y:') 427 self.sigma_phi_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH * 0.8, -1)) 428 self.sigma_lamd_txt = wx.StaticText(self, -1, 'Sigma_lamd:') 429 self.sigma_lamd_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH * 0.7, -1)) 484 430 sigma_1d_txt = wx.StaticText(self, -1, '( 1D: Sigma:') 485 self.sigma_1d_tcl = OutputTextCtrl(self, -1, 486 size=(_BOX_WIDTH*0.7,-1)) 431 self.sigma_1d_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH * 0.7, -1)) 487 432 sigmax_hint = " The x component of the geometric resolution," 488 sigmax_hint += 433 sigmax_hint += " excluding sigma_lamda." 489 434 sigmay_hint = " The y component of the geometric resolution," 490 sigmay_hint += 435 sigmay_hint += " excluding sigma_lamda." 491 436 sigma_hint_lamd = " The wavelength contribution in the radial direction" 492 437 sigma_hint_lamd += ".\n Note: The phi component is always zero." … … 499 444 sigma_phi_unit_txt = wx.StaticText(self, -1, sigma_unit) 500 445 sigma_lamd_unit_txt = wx.StaticText(self, -1, sigma_unit) 501 sigma_1d_unit_txt = wx.StaticText(self, -1, sigma_unit +' )')446 sigma_1d_unit_txt = wx.StaticText(self, -1, sigma_unit + ' )') 502 447 outputQxy_sizer.AddMany([(self.sigma_r_txt, 0, wx.LEFT, 15), 503 504 505 506 507 448 (self.sigma_r_tcl, 0, wx.LEFT, 15), 449 (sigma_r_unit_txt, 0, wx.LEFT, 15), 450 (self.sigma_phi_txt, 0, wx.LEFT, 15), 451 (self.sigma_phi_tcl, 0, wx.LEFT, 15), 452 (sigma_phi_unit_txt, 0, wx.LEFT, 15)]) 508 453 outputQ_sizer.AddMany([(self.sigma_lamd_txt, 0, wx.LEFT, 15), 509 (self.sigma_lamd_tcl, 0, wx.LEFT, 15), 510 (sigma_lamd_unit_txt, 0, wx.LEFT, 15), 511 (sigma_1d_txt, 0, wx.LEFT, 15), 512 (self.sigma_1d_tcl, 0, wx.LEFT, 15), 513 (sigma_1d_unit_txt, 0, wx.LEFT, 15)]) 514 self.output_sizer.AddMany([(sigma_title, 0, wx.LEFT, 15), 515 (outputQxy_sizer, 0, 516 wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 517 (outputQ_sizer, 0, 518 wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) 519 520 454 (self.sigma_lamd_tcl, 0, wx.LEFT, 15), 455 (sigma_lamd_unit_txt, 0, wx.LEFT, 15), 456 (sigma_1d_txt, 0, wx.LEFT, 15), 457 (self.sigma_1d_tcl, 0, wx.LEFT, 15), 458 (sigma_1d_unit_txt, 0, wx.LEFT, 15)]) 459 self.output_sizer.AddMany([(sigma_title, 0, wx.LEFT, 15), 460 (outputQxy_sizer, 0, 461 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 462 (outputQ_sizer, 0, 463 wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 464 521 465 def _layout_hint(self): 522 466 """ 523 Fill the sizer containing hint 467 Fill the sizer containing hint 524 468 """ 525 469 hint_msg = "" … … 529 473 self.hint_txt = wx.StaticText(self, -1, hint_msg) 530 474 self.hint_sizer.AddMany([(self.hint_txt, 0, wx.LEFT, 15)]) 531 532 def _layout_button(self): 475 476 def _layout_button(self): 533 477 """ 534 478 Do the layout for the button widgets 535 """ 536 537 id = wx.NewId()538 self.reset_button = wx.Button(self, id, "Reset")479 """ 480 481 wx_id = wx.NewId() 482 self.reset_button = wx.Button(self, wx_id, "Reset") 539 483 hint_on_reset = "..." 540 484 self.reset_button.SetToolTipString(hint_on_reset) 541 self.Bind(wx.EVT_BUTTON, self.on_reset, id= id)485 self.Bind(wx.EVT_BUTTON, self.on_reset, id=wx_id) 542 486 #compute button 543 id = wx.NewId()544 self.compute_button = wx.Button(self, id, "Compute")487 wx_id = wx.NewId() 488 self.compute_button = wx.Button(self, wx_id, "Compute") 545 489 hint_on_compute = "Compute... Please wait until finished." 546 490 self.compute_button.SetToolTipString(hint_on_compute) 547 self.Bind(wx.EVT_BUTTON, self.on_compute, id= id)491 self.Bind(wx.EVT_BUTTON, self.on_compute, id=wx_id) 548 492 #help button 549 id = wx.NewId()550 self.help_button = wx.Button(self, id, "HELP")493 wx_id = wx.NewId() 494 self.help_button = wx.Button(self, wx_id, "HELP") 551 495 hint_on_help = "Help on using the Resolution Calculator" 552 496 self.help_button.SetToolTipString(hint_on_help) 553 self.Bind(wx.EVT_BUTTON, self.on_help, id= id)497 self.Bind(wx.EVT_BUTTON, self.on_help, id=wx_id) 554 498 # close button 555 self.bt_close = wx.Button(self, wx.ID_CANCEL, 'Close')499 self.bt_close = wx.Button(self, wx.ID_CANCEL, 'Close') 556 500 self.bt_close.Bind(wx.EVT_BUTTON, self.on_close) 557 501 self.bt_close.SetToolTipString("Close this window.") … … 563 507 (self.bt_close, 0, wx.LEFT, 15)]) 564 508 self.compute_button.SetFocus() 565 509 566 510 def _layout_image(self): 567 511 """ 568 512 Layout for image plot 569 513 """ 570 color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND)571 572 514 # Contribution by James C. 573 515 # Instantiate a figure object that will contain our plots. 574 516 # Make the fig a little smaller than the default 575 self.figure = Figure(figsize=(6.5, 6), facecolor ='white')576 517 self.figure = Figure(figsize=(6.5, 6), facecolor='white') 518 577 519 # Initialize the figure canvas, mapping the figure object to the plot 578 520 # engine backend. … … 588 530 self.fm = FigureManagerBase(self.canvas, 1) 589 531 _pylab_helpers.Gcf.set_active(self.fm) 590 532 591 533 # Instantiate the matplotlib navigation toolbar and explicitly show it. 592 534 mpl_toolbar = Toolbar(self.canvas) … … 599 541 # Compute before adding the canvas to the sizer 600 542 self.on_compute() 601 543 602 544 # Fill up the sizer 603 545 if IS_WIN: … … 605 547 else: 606 548 gap = 13 607 self.vertical_r_sizer.Add(self.canvas, 0, 608 wx.ALL|wx.EXPAND, 2) 609 self.vertical_r_spacer.Add((0, gap)) 610 self.vertical_r_spacer.Add(self.vertical_r_sizer, 0, 611 wx.ALL|wx.EXPAND, 2) 612 self.vertical_r_spacer.Add((0, gap)) 613 self.vertical_r_spacer.Add(wx.StaticLine(self), 0, 614 wx.ALL|wx.EXPAND, 2) 615 self.vertical_r_spacer.Add(mpl_toolbar, 0, wx.ALL|wx.EXPAND, 2) 616 617 549 self.vertical_r_sizer.Add(self.canvas, 0, wx.ALL | wx.EXPAND, 2) 550 self.vertical_r_spacer.Add((0, gap)) 551 self.vertical_r_spacer.Add(self.vertical_r_sizer, 0, wx.ALL | wx.EXPAND, 2) 552 self.vertical_r_spacer.Add((0, gap)) 553 self.vertical_r_spacer.Add(wx.StaticLine(self), 0, wx.ALL | wx.EXPAND, 2) 554 self.vertical_r_spacer.Add(mpl_toolbar, 0, wx.ALL | wx.EXPAND, 2) 555 618 556 def _do_layout(self): 619 557 """ … … 621 559 """ 622 560 # Title of parameters 623 instrument_txt = wx.StaticText(self, -1, 624 '[Instrumental Parameters]:') 561 instrument_txt = wx.StaticText(self, -1, '[Instrumental Parameters]:') 625 562 # Build individual layouts 626 563 self._define_structure() 627 564 self._layout_mass() 628 #self._layout_intensity()629 565 self._layout_wavelength() 630 566 self._layout_wavelength_spread() … … 642 578 # Fill the sizers 643 579 self.boxsizer_source.AddMany([(instrument_txt, 0, 644 wx.EXPAND |wx.LEFT, 15),580 wx.EXPAND | wx.LEFT, 15), 645 581 (self.mass_sizer, 0, 646 wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 647 #(self.intensity_sizer, 0, 648 #wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 582 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 649 583 (self.wavelength_sizer, 0, 650 wx.EXPAND|wx.TOP|wx.BOTTOM, 5),584 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 651 585 (self.wavelength_spread_sizer, 0, 652 wx.EXPAND|wx.TOP|wx.BOTTOM, 5),586 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 653 587 (self.source_aperture_sizer, 0, 654 wx.EXPAND|wx.TOP|wx.BOTTOM, 5),588 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 655 589 (self.sample_aperture_sizer, 0, 656 wx.EXPAND|wx.TOP|wx.BOTTOM, 5),590 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 657 591 (self.source2sample_distance_sizer, 0, 658 wx.EXPAND|wx.TOP|wx.BOTTOM, 5),592 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 659 593 (self.sample2detector_distance_sizer, 0, 660 wx.EXPAND|wx.TOP|wx.BOTTOM, 5),594 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 661 595 (self.sample2sample_distance_sizer, 0, 662 wx.EXPAND|wx.TOP|wx.BOTTOM, 5),596 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 663 597 (self.detector_size_sizer, 0, 664 wx.EXPAND|wx.TOP|wx.BOTTOM, 5),598 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 665 599 (self.detector_pix_size_sizer, 0, 666 wx.EXPAND|wx.TOP|wx.BOTTOM, 5),667 (wx.StaticLine(self), 0, 668 wx.ALL |wx.EXPAND, 5),600 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 601 (wx.StaticLine(self), 0, 602 wx.ALL | wx.EXPAND, 5), 669 603 (self.input_sizer, 0, 670 wx.EXPAND|wx.TOP|wx.BOTTOM, 5),671 (wx.StaticLine(self), 0, 672 wx.ALL |wx.EXPAND, 5),604 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 605 (wx.StaticLine(self), 0, 606 wx.ALL | wx.EXPAND, 5), 673 607 (self.output_sizer, 0, 674 wx.EXPAND|wx.TOP|wx.BOTTOM, 5)])608 wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 675 609 self.vertical_l_sizer.AddMany([(self.boxsizer_source, 0, wx.ALL, 10), 676 (wx.StaticLine(self), 0, 677 wx.ALL|wx.EXPAND, 5),678 (self.button_sizer, 0,679 wx.EXPAND|wx.TOP|wx.BOTTOM, 5)])610 (wx.StaticLine(self), 0, 611 wx.ALL | wx.EXPAND, 5), 612 (self.button_sizer, 0, 613 wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 680 614 self.main_sizer.Add(self.vertical_l_sizer, 0, wx.ALL, 10) 681 682 # Build image plot layout 615 616 # Build image plot layout 683 617 self._layout_image() 684 618 # Add a vertical static line 685 self.main_sizer.Add( wx.StaticLine(self, -1, (2, 2),686 (2,PANEL_HEIGHT * 0.94), style =wx.LI_VERTICAL))619 self.main_sizer.Add(wx.StaticLine(self, -1, (2, 2), 620 (2, PANEL_HEIGHT * 0.94), style=wx.LI_VERTICAL)) 687 621 # Add the plot to main sizer 688 622 self.main_sizer.Add(self.vertical_r_spacer, 0, wx.ALL, 10) 689 623 self.SetSizer(self.main_sizer) 690 624 self.SetAutoLayout(True) 691 692 693 def on_help(self, event): 625 626 def on_help(self, event): 694 627 """ 695 628 Bring up the Resolution calculator Documentation whenever 696 the HELP button is clicked. 697 629 the HELP button is clicked. 630 698 631 Calls DocumentationWindow with the path of the location within the 699 documentation tree (after /doc/ ....". Note that when using old 700 versions of Wx (before 2.9) and thus not the release version of 701 installers, the help comes up at the top level of the file as 632 documentation tree (after /doc/ ....". Note that when using old 633 versions of Wx (before 2.9) and thus not the release version of 634 installers, the help comes up at the top level of the file as 702 635 webbrowser does not pass anything past the # to the browser when it is 703 636 running "file:///...." 704 637 705 638 :param evt: Triggers on clicking the help button 706 639 """ 707 640 708 641 _TreeLocation = "user/perspectives/calculator/resolution_calculator_help.html" 709 _doc_viewer = DocumentationWindow(self, -1, \710 _TreeLocation,"Resolution Calculator Help")642 _doc_viewer = DocumentationWindow(self, -1, 643 _TreeLocation, "Resolution Calculator Help") 711 644 712 645 def on_close(self, event): … … 724 657 # Close panel 725 658 self.parent.OnClose(None) 726 727 728 def on_compute(self, event = None): 659 660 def on_compute(self, event=None): 729 661 """ 730 662 Execute the computation of resolution 731 663 """ 732 664 wx.CallAfter(self.on_compute_call, event) 733 665 734 666 def on_compute_call(self, event=None): 735 667 """ … … 743 675 744 676 # message 745 status_type = 'progress' 677 status_type = 'progress' 746 678 msg = 'Calculating...' 747 679 self._status_info(msg, status_type) 748 680 749 status_type = 'stop' 681 status_type = 'stop' 750 682 # Q min max list default 751 qx_min = [] 752 qx_max = [] 753 qy_min = [] 754 qy_max = [] 683 qx_min = [] 684 qx_max = [] 685 qy_min = [] 686 qy_max = [] 755 687 # possible max qrange 756 688 self.resolution.qxmin_limit = 0 … … 773 705 if wave_input != None: 774 706 wavelength, wavelength_spread = wave_input 775 776 #self.resolution.set_wave(float(wavelength)) 707 777 708 self.resolution.set_wave(wavelength) 778 #self.resolution.set_wave_spread(float(wavelength_spread))779 709 self.resolution.set_wave_spread(wavelength_spread) 780 710 source_aperture_size = self.source_aperture_tcl.GetValue() … … 804 734 self.qx = self._string2inputlist(self.qx_tcl.GetValue()) 805 735 self.qy = self._string2inputlist(self.qy_tcl.GetValue()) 806 807 736 808 737 # Find min max of qs 809 738 xmin = min(self.qx) … … 825 754 if q_input != None: 826 755 self.qx, self.qy = q_input 827 756 828 757 # Make list of q min max for mapping 829 for lengthin range(len(self.qx)):758 for i in range(len(self.qx)): 830 759 qx_min.append(xmin) 831 760 qx_max.append(xmax) 832 for lengthin range(len(self.qy)):761 for i in range(len(self.qy)): 833 762 qy_min.append(ymin) 834 763 qy_max.append(ymax) 835 764 836 765 # Compute the resolution 837 766 if self.image != None: … … 845 774 # Compute and get the image plot 846 775 try: 847 from sas.perspectives.calculator.resolcal_thread \ 848 import CalcRes as thread 776 from sas.perspectives.calculator.resolcal_thread import CalcRes as thread 849 777 self.sigma_strings = '\nResolution: Computation is finished. \n' 850 cal_res = thread(func = self._map_func, 851 qx = self.qx, 852 qy = self.qy, 853 qx_min = qx_min, 854 qx_max = qx_max, 855 qy_min = qy_min, 856 qy_max = qy_max, 857 image = self.image, 858 completefn = self.complete) 859 #self.image = map(self._map_func, self.qx, self.qy, 860 # qx_min, qx_max, qy_min, qy_max)[0] 778 cal_res = thread(func=self._map_func, 779 qx=self.qx, 780 qy=self.qy, 781 qx_min=qx_min, 782 qx_max=qx_max, 783 qy_min=qy_min, 784 qy_max=qy_max, 785 image=self.image, 786 completefn=self.complete) 861 787 cal_res.queue() 862 788 msg = "Computation is in progress..." 863 #msg = "Finished the resolution computation..."864 789 status_type = 'progress' 865 790 self._status_info(msg, status_type) 866 791 except: 867 792 raise 868 793 869 794 def complete(self, image, elapsed=None): 870 795 """ 871 796 Callafter complete: wx call after needed for stable output 872 797 """ 873 wx.CallAfter(self.complete_cal, image, elapsed) 874 798 wx.CallAfter(self.complete_cal, image, elapsed) 799 875 800 def complete_cal(self, image, elapsed=None): 876 801 """ … … 881 806 wave_list, _ = self.resolution.get_wave_list() 882 807 if len(wave_list) > 1 and wave_list[-1] == max(wave_list): 883 # draw a green rectangle(limit for the longest wavelength 808 # draw a green rectangle(limit for the longest wavelength 884 809 # to be involved) for tof inputs 885 810 self._draw_lines(self.image, color='g') … … 887 812 # Draw image 888 813 self.image.draw() 889 #self.vertical_r_sizer.Layout() 890 891 # Get and format the sigmas 814 815 # Get and format the sigmas 892 816 sigma_r = self.format_number(self.resolution.sigma_1) 893 817 sigma_phi = self.format_number(self.resolution.sigma_2) 894 818 sigma_lamd = self.format_number(self.resolution.sigma_lamd) 895 sigma_1d = 896 897 # Set output values 819 sigma_1d = self.format_number(self.resolution.sigma_1d) 820 821 # Set output values 898 822 self.sigma_r_tcl.SetValue(str(sigma_r)) 899 823 self.sigma_phi_tcl.SetValue(str(sigma_phi)) … … 904 828 status_type = 'stop' 905 829 self._status_info(msg, status_type) 906 830 907 831 def _draw_lines(self, image=None, color='r'): 908 832 """ … … 935 859 # Draw zero axis lines 936 860 if qy_min < 0 and qy_max >= 0: 937 image.axhline(linewidth =1)861 image.axhline(linewidth=1) 938 862 if qx_min < 0 and qx_max >= 0: 939 image.axvline(linewidth =1)940 863 image.axvline(linewidth=1) 864 941 865 # Find x and y ratio values to draw the detector outline 942 866 x_min = fabs(detector_qx_min - qx_min) / (qx_max - qx_min) … … 947 871 # Draw Detector outline 948 872 if detector_qy_min >= qy_min: 949 image.axhline(y = detector_qy_min + 0.0002, 950 xmin = x_min, 951 xmax = x_max, 952 linewidth = 2, color=color) 873 image.axhline(y=detector_qy_min + 0.0002, 874 xmin=x_min, xmax=x_max, 875 linewidth=2, color=color) 953 876 if detector_qy_max <= qy_max: 954 image.axhline(y = detector_qy_max - 0.0002, 955 xmin = x_min, 956 xmax = x_max, 957 linewidth = 2, color=color) 877 image.axhline(y=detector_qy_max - 0.0002, 878 xmin=x_min, xmax=x_max, 879 linewidth=2, color=color) 958 880 if detector_qx_min >= qx_min: 959 image.axvline(x = detector_qx_min + 0.0002, 960 ymin = y_min, 961 ymax = y_max, 962 linewidth = 2, color=color) 881 image.axvline(x=detector_qx_min + 0.0002, 882 ymin=y_min, ymax=y_max, 883 linewidth=2, color=color) 963 884 if detector_qx_max <= qx_max: 964 image.axvline(x = detector_qx_max - 0.0002, 965 ymin = y_min, 966 ymax = y_max, 967 linewidth = 2, color=color) 885 image.axvline(x=detector_qx_max - 0.0002, 886 ymin=y_min, ymax=y_max, 887 linewidth=2, color=color) 968 888 xmin = min(self.qx) 969 889 xmax = max(self.qx) … … 974 894 ymin < detector_qy_min or ymax > detector_qy_max: 975 895 # message 976 status_type = 'stop' 896 status_type = 'stop' 977 897 msg = 'At least one q value located out side of\n' 978 898 msg += " the detector range (%s < qx < %s, %s < qy < %s),\n" % \ 979 (self.format_number(detector_qx_min), 899 (self.format_number(detector_qx_min), 980 900 self.format_number(detector_qx_max), 981 self.format_number(detector_qy_min), 901 self.format_number(detector_qy_min), 982 902 self.format_number(detector_qy_max)) 983 903 msg += " is ignored in computation.\n" 984 904 985 905 self._status_info(msg, status_type) 986 906 wx.MessageBox(msg, 'Warning') 987 988 def _map_func(self, qx, qy, qx_min, qx_max, qy_min, qy_max): 907 908 def _map_func(self, qx, qy, qx_min, qx_max, qy_min, qy_max): 989 909 """ 990 910 Prepare the Mapping for the computation 991 911 : params qx, qy, qx_min, qx_max, qy_min, qy_max: 992 912 993 913 : return: image (pylab) 994 914 """ … … 999 919 raise 1000 920 # calculate 2D resolution distribution image 1001 image = self.resolution.compute_and_plot(qx_value, qy_value, 1002 qx_min, qx_max, qy_min, qy_max,1003 self.det_coordinate)921 image = self.resolution.compute_and_plot(qx_value, qy_value, 922 qx_min, qx_max, qy_min, qy_max, 923 self.det_coordinate) 1004 924 # record sigmas 1005 self.sigma_strings += " At Qx = %s, Qy = %s; \n" % (qx_value, qy_value)925 self.sigma_strings += " At Qx = %s, Qy = %s; \n" % (qx_value, qy_value) 1006 926 self._sigma_strings() 1007 927 return image 928 1008 929 def _sigma_strings(self): 1009 930 """ … … 1013 934 sigma_phi = self.format_number(self.resolution.sigma_2) 1014 935 sigma_lamd = self.format_number(self.resolution.sigma_lamd) 1015 sigma_1d = 1016 # Set output values 1017 self.sigma_strings += " sigma_x = %s\n" % sigma_r1018 self.sigma_strings += " sigma_y = %s\n" % sigma_phi1019 self.sigma_strings += " sigma_lamd = %s\n" % sigma_lamd1020 self.sigma_strings += " sigma_1D = %s\n" % sigma_1d1021 1022 def _validate_q_input(self, qx, qy): 936 sigma_1d = self.format_number(self.resolution.sigma_1d) 937 # Set output values 938 self.sigma_strings += " sigma_x = %s\n" % sigma_r 939 self.sigma_strings += " sigma_y = %s\n" % sigma_phi 940 self.sigma_strings += " sigma_lamd = %s\n" % sigma_lamd 941 self.sigma_strings += " sigma_1D = %s\n" % sigma_1d 942 943 def _validate_q_input(self, qx, qy): 1023 944 """ 1024 945 Check if q inputs are valid 1025 946 : params qx: qx as a list 1026 947 : params qy: qy as a list 1027 948 1028 949 : return: True/False 1029 950 """ … … 1031 952 if qx.__class__.__name__ != 'list': 1032 953 return None 1033 if qy.__class__.__name__ != 'list' 954 if qy.__class__.__name__ != 'list': 1034 955 return None 1035 956 if len(qx) < 1: … … 1049 970 if qx == None or qy == None: 1050 971 return None 1051 return qx, qy 1052 972 return qx, qy 973 1053 974 def on_reset(self, event): 1054 975 """ … … 1057 978 # skip for another event 1058 979 if event != None: 1059 event.Skip() 980 event.Skip() 1060 981 # init resolution_calculator 1061 982 self.resolution = ResolutionCalculator() … … 1073 994 self.spectrum_cb.Show(False) 1074 995 source_aperture_value = str(self.resolution.source_aperture_size[0]) 1075 if len(self.resolution.source_aperture_size) >1:996 if len(self.resolution.source_aperture_size) > 1: 1076 997 source_aperture_value += ", " 1077 998 source_aperture_value += \ … … 1079 1000 self.source_aperture_tcl.SetValue(str(source_aperture_value)) 1080 1001 sample_aperture_value = str(self.resolution.sample_aperture_size[0]) 1081 if len(self.resolution.sample_aperture_size) >1:1002 if len(self.resolution.sample_aperture_size) > 1: 1082 1003 sample_aperture_value += ", " 1083 1004 sample_aperture_value += \ … … 1095 1016 sample2detector_distance_value) 1096 1017 detector_size_value = str(self.resolution.detector_size[0]) 1097 if len(self.resolution.detector_size) >1:1018 if len(self.resolution.detector_size) > 1: 1098 1019 detector_size_value += ", " 1099 1020 detector_size_value += str(self.resolution.detector_size[1]) 1100 1021 self.detector_size_tcl.SetValue(detector_size_value) 1101 1022 detector_pix_size_value = str(self.resolution.detector_pix_size[0]) 1102 if len(self.resolution.detector_pix_size) >1:1023 if len(self.resolution.detector_pix_size) > 1: 1103 1024 detector_pix_size_value += ", " 1104 1025 detector_pix_size_value += str(self.resolution.detector_pix_size[1]) … … 1120 1041 msg = " Finished the resetting..." 1121 1042 self._status_info(msg, 'stop') 1122 1043 1123 1044 def format_number(self, value=None): 1124 1045 """ 1125 Return a float in a standardized, human-readable formatted string 1126 """ 1127 try: 1046 Return a float in a standardized, human-readable formatted string 1047 """ 1048 try: 1128 1049 value = float(value) 1129 1050 except: … … 1132 1053 1133 1054 output = "%-7.4g" % value 1134 return output.lstrip().rstrip() 1135 1055 return output.lstrip().rstrip() 1056 1136 1057 def _string2list(self, string): 1137 1058 """ … … 1139 1060 """ 1140 1061 new_string = [] 1141 # check the number of floats 1062 # check the number of floats 1142 1063 try: 1143 1064 strg = float(string) 1144 1065 new_string.append(strg) 1145 #new_string.append(0)1146 1066 except: 1147 1067 string_split = string.split(',') … … 1160 1080 1161 1081 return new_string 1162 1082 1163 1083 def _string2inputlist(self, string): 1164 1084 """ 1165 1085 Change NNN, NNN,... to list,ie. [NNN, NNN,...] where NNN is a number 1166 1086 1167 1087 : return new_string: string like list 1168 1088 """ … … 1175 1095 new_string.append(value) 1176 1096 except: 1177 pass1178 1097 logging.error(sys.exc_value) 1098 1179 1099 return new_string 1180 1100 1181 1101 def _str2longlist(self, string): 1182 1102 """ 1183 1103 Change NNN, NNN,... to list, NNN - NNN ; NNN to list, or float to list 1184 1104 1185 1105 : return new_string: string like list 1186 1106 """ 1187 #new_string = []1188 1107 msg = "Wrong format of intputs." 1189 1108 try: … … 1196 1115 else: 1197 1116 try: 1198 # has a '-' 1117 # has a '-' 1199 1118 if string.count('-') > 0: 1200 1119 value = string.split('-') … … 1202 1121 # has a ';' 1203 1122 last_list = value[1].split(';') 1204 num = 1205 max = float(last_list[0])1123 num = math.ceil(float(last_list[1])) 1124 max_value = float(last_list[0]) 1206 1125 self.num_wave = num 1207 1126 else: 1208 1127 # default num 1209 1128 num = self.num_wave 1210 max = float(value[1])1211 min = float(value[0])1129 max_value = float(value[1]) 1130 min_value = float(value[0]) 1212 1131 # make a list 1213 bin_size = math.fabs(max - min) / (num - 1)1214 out = [min + bin_size * bnum for bnum in range(num)]1132 bin_size = math.fabs(max_value - min_value) / (num - 1) 1133 out = [min_value + bin_size * bnum for bnum in range(num)] 1215 1134 return out 1216 1135 if string.count(',') > 0: … … 1218 1137 return out 1219 1138 except: 1220 pass 1221 # wx.MessageBox(msg, 'Warning') 1139 logging.error(sys.exc_value) 1222 1140 1223 1141 def _on_xy_coordinate(self, event=None): … … 1226 1144 """ 1227 1145 if event != None: 1228 event.Skip() 1229 # Set the coordinate in Cartesian 1146 event.Skip() 1147 # Set the coordinate in Cartesian 1230 1148 self.det_coordinate = 'cartesian' 1231 1149 self.sigma_r_txt.SetLabel('Sigma_x:') 1232 1150 self.sigma_phi_txt.SetLabel('Sigma_y:') 1233 1151 self._onparamEnter() 1234 1152 1235 1153 def _on_rp_coordinate(self, event=None): 1236 1154 """ … … 1238 1156 """ 1239 1157 if event != None: 1240 event.Skip() 1241 # Set the coordinate in polar 1158 event.Skip() 1159 # Set the coordinate in polar 1242 1160 self.det_coordinate = 'polar' 1243 1161 self.sigma_r_txt.SetLabel('Sigma_r: ') 1244 1162 self.sigma_phi_txt.SetLabel('Sigma_phi:') 1245 1163 self._onparamEnter() 1246 1247 def _status_info(self, msg = '', type ="update"):1164 1165 def _status_info(self, msg='', type="update"): 1248 1166 """ 1249 1167 Status msg … … 1252 1170 label = "Compute" 1253 1171 able = True 1254 else: 1172 else: 1255 1173 label = "Wait..." 1256 1174 able = False … … 1259 1177 self.compute_button.SetToolTipString(label) 1260 1178 if self.parent.parent != None: 1261 wx.PostEvent(self.parent.parent, 1262 StatusEvent(status = msg, type = type))1263 1264 1265 def _onparamEnter(self, event =None):1179 wx.PostEvent(self.parent.parent, 1180 StatusEvent(status=msg, type=type)) 1181 1182 1183 def _onparamEnter(self, event=None): 1266 1184 """ 1267 1185 On Text_enter_callback, perform compute 1268 1186 """ 1269 1187 self.on_compute() 1270 1271 def _on_source_selection(self, event =None):1188 1189 def _on_source_selection(self, event=None): 1272 1190 """ 1273 1191 On source combobox selection … … 1280 1198 selection = combo.GetValue() 1281 1199 mass = self.source_mass[selection] 1282 self.resolution.set_neutron_mass(mass) 1200 self.resolution.set_neutron_mass(mass) 1283 1201 source_hint = "Source Selection: Affect on" 1284 1202 source_hint += " the gravitational contribution.\n" … … 1287 1205 #source_tip.SetTip(source_hint) 1288 1206 self.mass_txt.ToolTip.SetTip(source_hint) 1289 1290 def _on_source_color(self, event =None):1207 1208 def _on_source_color(self, event=None): 1291 1209 """ 1292 1210 On source color combobox selection … … 1314 1232 self.spectrum_txt.Show(True) 1315 1233 self.spectrum_cb.Show(True) 1316 1234 1317 1235 else: 1318 1236 wavelength = self.resolution.get_wavelength() … … 1323 1241 self.spectrum_txt.Show(False) 1324 1242 self.spectrum_cb.Show(False) 1325 self.wavelength_sizer.Layout() 1243 self.wavelength_sizer.Layout() 1326 1244 self.Layout() 1327 1245 1328 1246 def _on_spectrum_cb(self, event=None): 1329 1247 """ … … 1345 1263 return 1346 1264 try: 1347 basename 1265 basename = os.path.basename(path) 1348 1266 if basename not in self.spectrum_dic.keys(): 1349 1267 self.spectrum_cb.Append(basename) … … 1354 1272 except: 1355 1273 raise 1356 1274 1357 1275 self.resolution.set_spectrum(self.spectrum_dic[selection]) 1358 1276 1359 1277 def _selectDlg(self): 1360 1278 """ 1361 1279 open a dialog file to select a customized spectrum 1362 1280 """ 1363 dlg = wx.FileDialog(self, 1364 "Choose a wavelength spectrum file: Intensity vs. wavelength", 1365 self.parent.parent.get_save_location() , "", 1366 "*.*", wx.OPEN) 1281 dlg = wx.FileDialog(self, 1282 "Choose a wavelength spectrum file: Intensity vs. wavelength", 1283 self.parent.parent.get_save_location() , "", "*.*", wx.OPEN) 1367 1284 path = None 1368 1285 if dlg.ShowModal() == wx.ID_OK: … … 1370 1287 dlg.Destroy() 1371 1288 return path 1372 1289 1373 1290 def _read_file(self, path): 1374 1291 """ 1375 1292 Read two columns file as tuples of numpy array 1376 1293 1377 1294 :param path: the path to the file to read 1378 1295 1379 1296 """ 1380 1297 try: 1381 1298 if path == None: 1382 1299 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 1383 " Selected Distribution was not loaded: %s" %path))1300 " Selected Distribution was not loaded: %s" % path)) 1384 1301 return None, None 1385 1302 input_f = open(path, 'r') 1386 1303 buff = input_f.read() 1387 1304 lines = buff.split('\n') 1388 1305 1389 1306 wavelength = [] 1390 1307 intensity = [] … … 1398 1315 except: 1399 1316 # Skip non-data lines 1400 pass1401 1317 logging.error(sys.exc_value) 1318 1402 1319 return [wavelength, intensity] 1403 1320 except: 1404 raise 1405 1321 raise 1322 1406 1323 class ResolutionWindow(widget.CHILD_FRAME): 1407 1324 """ 1408 1325 Resolution Window 1409 1326 """ 1410 def __init__(self, parent = None, manager=None,1411 title ="SAS Resolution Estimator",1327 def __init__(self, parent=None, manager=None, 1328 title="SAS Resolution Estimator", 1412 1329 size=(PANEL_WIDTH * 2, PANEL_HEIGHT), *args, **kwds): 1413 1330 kwds['title'] = title … … 1420 1337 self.SetPosition((25, 10)) 1421 1338 self.Show(True) 1422 1423 def OnClose(self, event): 1339 1340 def OnClose(self, event): 1424 1341 """ 1425 1342 On close event … … 1428 1345 if self.manager != None: 1429 1346 self.manager.cal_res_frame = None 1430 self.Destroy() 1431 1432 1433 if __name__ == "__main__": 1347 self.Destroy() 1348 1349 1350 if __name__ == "__main__": 1434 1351 app = wx.PySimpleApp() 1435 1352 widget.CHILD_FRAME = wx.Frame 1436 frame = ResolutionWindow() 1353 frame = ResolutionWindow() 1437 1354 frame.Show(True) 1438 app.MainLoop() 1355 app.MainLoop()
Note: See TracChangeset
for help on using the changeset viewer.