- Timestamp:
- Jun 27, 2017 12:18:33 PM (7 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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 251ef684
- Parents:
- 65f3930
- Location:
- src/sas
- Files:
-
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/fit/AbstractFitEngine.py
ra1b8fee r50fcb09 137 137 that will smear the theory data (slit smearing or resolution 138 138 smearing) when set. 139 139 140 140 The proper way to set the smearing object would be to 141 141 do the following: :: 142 143 from sas.sascalc. data_util.qsmearing import smear_selection142 143 from sas.sascalc.fit.qsmearing import smear_selection 144 144 smearer = smear_selection(some_data) 145 145 fitdata1d = FitData1D( x= [1,3,..,], … … 147 147 dx=None, 148 148 dy=[1,2...], smearer= smearer) 149 149 150 150 :Note: that some_data _HAS_ to be of 151 151 class DataLoader.data_info.Data1D 152 152 Setting it back to None will turn smearing off. 153 153 154 154 """ 155 155 Data1D.__init__(self, x=x, y=y, dx=dx, dy=dy, lam=lam, dlam=dlam) … … 176 176 ## Max Q-value 177 177 self.qmax = max(self.x) 178 178 179 179 # Range used for input to smearing 180 180 self._qmin_unsmeared = self.qmin … … 184 184 self.idx_unsmeared = (self.x >= self._qmin_unsmeared) \ 185 185 & (self.x <= self._qmax_unsmeared) 186 186 187 187 def set_fit_range(self, qmin=None, qmax=None): 188 188 """ to set the fit range""" … … 199 199 self._qmin_unsmeared = self.qmin 200 200 self._qmax_unsmeared = self.qmax 201 201 202 202 self._first_unsmeared_bin = 0 203 203 self._last_unsmeared_bin = len(self.x) - 1 204 204 205 205 if self.smearer is not None: 206 206 self._first_unsmeared_bin, self._last_unsmeared_bin = \ … … 208 208 self._qmin_unsmeared = self.x[self._first_unsmeared_bin] 209 209 self._qmax_unsmeared = self.x[self._last_unsmeared_bin] 210 210 211 211 # Identify the bin range for the unsmeared and smeared spaces 212 212 self.idx = (self.x >= self.qmin) & (self.x <= self.qmax) … … 231 231 """ 232 232 Compute residuals. 233 233 234 234 If self.smearer has been set, use if to smear 235 235 the data before computing chi squared. 236 236 237 237 :param fn: function that return model value 238 238 239 239 :return: residuals 240 240 """ … … 242 242 fx = np.zeros(len(self.x)) 243 243 fx[self.idx_unsmeared] = fn(self.x[self.idx_unsmeared]) 244 244 245 245 ## Smear theory data 246 246 if self.smearer is not None: … … 253 253 raise RuntimeError, msg 254 254 return (self.y[self.idx] - fx[self.idx]) / self.dy[self.idx], fx[self.idx] 255 255 256 256 def residuals_deriv(self, model, pars=[]): 257 257 """ 258 258 :return: residuals derivatives . 259 260 :note: in this case just return empty array 259 260 :note: in this case just return empty array 261 261 """ 262 262 return [] … … 293 293 x_max = max(math.fabs(sas_data2d.xmin), math.fabs(sas_data2d.xmax)) 294 294 y_max = max(math.fabs(sas_data2d.ymin), math.fabs(sas_data2d.ymax)) 295 295 296 296 ## fitting range 297 297 if qmin is None: … … 305 305 self.res_err_data = copy.deepcopy(self.err_data) 306 306 #self.res_err_data[self.res_err_data==0]=1 307 307 308 308 self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) 309 309 310 310 # Note: mask = True: for MASK while mask = False for NOT to mask 311 311 self.idx = ((self.qmin <= self.radius) &\ … … 368 368 369 369 return res, gn 370 370 371 371 def residuals_deriv(self, model, pars=[]): 372 372 """ 373 373 :return: residuals derivatives . 374 374 375 375 :note: in this case just return empty array 376 376 377 377 """ 378 378 return [] 379 380 379 380 381 381 class FitAbort(Exception): 382 382 """ … … 396 396 self.fit_arrange_dict = {} 397 397 self.fitter_id = None 398 398 399 399 def set_model(self, model, id, pars=[], constraints=[], data=None): 400 400 """ 401 401 set a model on a given in the fit engine. 402 403 :param model: sas.models type 402 403 :param model: sas.models type 404 404 :param id: is the key of the fitArrange dictionary where model is saved as a value 405 :param pars: the list of parameters to fit 406 :param constraints: list of 405 :param pars: the list of parameters to fit 406 :param constraints: list of 407 407 tuple (name of parameter, value of parameters) 408 408 the value of parameter must be a string to constraint 2 different 409 409 parameters. 410 Example: 410 Example: 411 411 we want to fit 2 model M1 and M2 both have parameters A and B. 412 412 constraints can be ``constraints = [(M1.A, M2.B+2), (M1.B= M2.A *5),...,]`` 413 414 413 414 415 415 :note: pars must contains only name of existing model's parameters 416 416 417 417 """ 418 418 if not pars: … … 445 445 in a FitArrange object and adds that object in a dictionary 446 446 with key id. 447 447 448 448 :param data: data added 449 449 :param id: unique key corresponding to a fitArrange object with data … … 456 456 dx=data.dx, dy=data.dy, smearer=smearer) 457 457 fitdata.sas_data = data 458 458 459 459 fitdata.set_fit_range(qmin=qmin, qmax=qmax) 460 460 #A fitArrange is already created but contains model only at id … … 466 466 fitproblem.add_data(fitdata) 467 467 self.fit_arrange_dict[id] = fitproblem 468 468 469 469 def get_model(self, id): 470 470 """ 471 471 :param id: id is key in the dictionary containing the model to return 472 472 473 473 :return: a model at this id or None if no FitArrange element was 474 474 created with this id … … 478 478 else: 479 479 return None 480 480 481 481 def remove_fit_problem(self, id): 482 482 """remove fitarrange in id""" 483 483 if id in self.fit_arrange_dict: 484 484 del self.fit_arrange_dict[id] 485 485 486 486 def select_problem_for_fit(self, id, value): 487 487 """ 488 488 select a couple of model and data at the id position in dictionary 489 489 and set in self.selected value to value 490 490 491 491 :param value: the value to allow fitting. 492 492 can only have the value one or zero … … 494 494 if id in self.fit_arrange_dict: 495 495 self.fit_arrange_dict[id].set_to_fit(value) 496 496 497 497 def get_problem_to_fit(self, id): 498 498 """ 499 499 return the self.selected value of the fit problem of id 500 500 501 501 :param id: the id of the problem 502 502 """ 503 503 if id in self.fit_arrange_dict: 504 504 self.fit_arrange_dict[id].get_to_fit() 505 506 505 506 507 507 class FitArrange: 508 508 def __init__(self): … … 511 511 to perform the Fit.FitArrange must contain exactly one model 512 512 and at least one data for the fit to be performed. 513 513 514 514 model: the model selected by the user 515 515 Ldata: a list of data what the user wants to fit 516 516 517 517 """ 518 518 self.model = None … … 525 525 """ 526 526 set_model save a copy of the model 527 527 528 528 :param model: the model being set 529 529 """ 530 530 self.model = model 531 531 532 532 def add_data(self, data): 533 533 """ 534 534 add_data fill a self.data_list with data to fit 535 535 536 536 :param data: Data to add in the list 537 537 """ 538 538 if not data in self.data_list: 539 539 self.data_list.append(data) 540 540 541 541 def get_model(self): 542 542 """ … … 544 544 """ 545 545 return self.model 546 546 547 547 def get_data(self): 548 548 """ … … 550 550 """ 551 551 return self.data_list[0] 552 552 553 553 def remove_data(self, data): 554 554 """ 555 555 Remove one element from the list 556 556 557 557 :param data: Data to remove from data_list 558 558 """ 559 559 if data in self.data_list: 560 560 self.data_list.remove(data) 561 561 562 562 def set_to_fit(self, value=0): 563 563 """ 564 564 set self.selected to 0 or 1 for other values raise an exception 565 565 566 566 :param value: integer between 0 or 1 567 567 """ 568 568 self.selected = value 569 569 570 570 def get_to_fit(self): 571 571 """ … … 599 599 if self.model is not None and self.data is not None: 600 600 self.inputs = [(self.model, self.data)] 601 601 602 602 def set_model(self, model): 603 603 """ 604 604 """ 605 605 self.model = model 606 606 607 607 def set_fitness(self, fitness): 608 608 """ 609 609 """ 610 610 self.fitness = fitness 611 611 612 612 def __str__(self): 613 613 """ … … 624 624 msg = [msg1, msg3] + msg2 625 625 return "\n".join(msg) 626 626 627 627 def print_summary(self): 628 628 """ -
src/sas/sascalc/fit/qsmearing.py
r8938502 r50fcb09 5 5 #This software was developed by the University of Tennessee as part of the 6 6 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 7 #project funded by the US National Science Foundation. 7 #project funded by the US National Science Foundation. 8 8 #See the license text in license.txt 9 9 #copyright 2008, University of Tennessee … … 19 19 from sasmodels.sesans import SesansTransform 20 20 from sasmodels.resolution2d import Pinhole2D 21 from .nxsunit import Converter 21 22 from sas.sascalc.data_util.nxsunit import Converter 22 23 23 24 def smear_selection(data, model = None): -
src/sas/sascalc/pr/fit/AbstractFitEngine.py
ra1b8fee r50fcb09 137 137 that will smear the theory data (slit smearing or resolution 138 138 smearing) when set. 139 139 140 140 The proper way to set the smearing object would be to 141 141 do the following: :: 142 143 from sas.sascalc. data_util.qsmearing import smear_selection142 143 from sas.sascalc.fit.qsmearing import smear_selection 144 144 smearer = smear_selection(some_data) 145 145 fitdata1d = FitData1D( x= [1,3,..,], … … 147 147 dx=None, 148 148 dy=[1,2...], smearer= smearer) 149 149 150 150 :Note: that some_data _HAS_ to be of 151 151 class DataLoader.data_info.Data1D 152 152 Setting it back to None will turn smearing off. 153 153 154 154 """ 155 155 Data1D.__init__(self, x=x, y=y, dx=dx, dy=dy) … … 176 176 ## Max Q-value 177 177 self.qmax = max(self.x) 178 178 179 179 # Range used for input to smearing 180 180 self._qmin_unsmeared = self.qmin … … 184 184 self.idx_unsmeared = (self.x >= self._qmin_unsmeared) \ 185 185 & (self.x <= self._qmax_unsmeared) 186 186 187 187 def set_fit_range(self, qmin=None, qmax=None): 188 188 """ to set the fit range""" … … 199 199 self._qmin_unsmeared = self.qmin 200 200 self._qmax_unsmeared = self.qmax 201 201 202 202 self._first_unsmeared_bin = 0 203 203 self._last_unsmeared_bin = len(self.x) - 1 204 204 205 205 if self.smearer is not None: 206 206 self._first_unsmeared_bin, self._last_unsmeared_bin = \ … … 208 208 self._qmin_unsmeared = self.x[self._first_unsmeared_bin] 209 209 self._qmax_unsmeared = self.x[self._last_unsmeared_bin] 210 210 211 211 # Identify the bin range for the unsmeared and smeared spaces 212 212 self.idx = (self.x >= self.qmin) & (self.x <= self.qmax) … … 231 231 """ 232 232 Compute residuals. 233 233 234 234 If self.smearer has been set, use if to smear 235 235 the data before computing chi squared. 236 236 237 237 :param fn: function that return model value 238 238 239 239 :return: residuals 240 240 """ … … 242 242 fx = np.zeros(len(self.x)) 243 243 fx[self.idx_unsmeared] = fn(self.x[self.idx_unsmeared]) 244 244 245 245 ## Smear theory data 246 246 if self.smearer is not None: … … 253 253 raise RuntimeError, msg 254 254 return (self.y[self.idx] - fx[self.idx]) / self.dy[self.idx], fx[self.idx] 255 255 256 256 def residuals_deriv(self, model, pars=[]): 257 257 """ 258 258 :return: residuals derivatives . 259 260 :note: in this case just return empty array 259 260 :note: in this case just return empty array 261 261 """ 262 262 return [] … … 293 293 x_max = max(math.fabs(sas_data2d.xmin), math.fabs(sas_data2d.xmax)) 294 294 y_max = max(math.fabs(sas_data2d.ymin), math.fabs(sas_data2d.ymax)) 295 295 296 296 ## fitting range 297 297 if qmin is None: … … 305 305 self.res_err_data = copy.deepcopy(self.err_data) 306 306 #self.res_err_data[self.res_err_data==0]=1 307 307 308 308 self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) 309 309 310 310 # Note: mask = True: for MASK while mask = False for NOT to mask 311 311 self.idx = ((self.qmin <= self.radius) &\ … … 371 371 372 372 return res, gn 373 373 374 374 def residuals_deriv(self, model, pars=[]): 375 375 """ 376 376 :return: residuals derivatives . 377 377 378 378 :note: in this case just return empty array 379 379 380 380 """ 381 381 return [] 382 383 382 383 384 384 class FitAbort(Exception): 385 385 """ … … 399 399 self.fit_arrange_dict = {} 400 400 self.fitter_id = None 401 401 402 402 def set_model(self, model, id, pars=[], constraints=[], data=None): 403 403 """ 404 404 set a model on a given in the fit engine. 405 406 :param model: sas.models type 405 406 :param model: sas.models type 407 407 :param id: is the key of the fitArrange dictionary where model is saved as a value 408 :param pars: the list of parameters to fit 409 :param constraints: list of 408 :param pars: the list of parameters to fit 409 :param constraints: list of 410 410 tuple (name of parameter, value of parameters) 411 411 the value of parameter must be a string to constraint 2 different 412 412 parameters. 413 Example: 413 Example: 414 414 we want to fit 2 model M1 and M2 both have parameters A and B. 415 415 constraints can be ``constraints = [(M1.A, M2.B+2), (M1.B= M2.A *5),...,]`` 416 417 416 417 418 418 :note: pars must contains only name of existing model's parameters 419 419 420 420 """ 421 421 if not pars: … … 448 448 in a FitArrange object and adds that object in a dictionary 449 449 with key id. 450 450 451 451 :param data: data added 452 452 :param id: unique key corresponding to a fitArrange object with data … … 459 459 dx=data.dx, dy=data.dy, smearer=smearer) 460 460 fitdata.sas_data = data 461 461 462 462 fitdata.set_fit_range(qmin=qmin, qmax=qmax) 463 463 #A fitArrange is already created but contains model only at id … … 469 469 fitproblem.add_data(fitdata) 470 470 self.fit_arrange_dict[id] = fitproblem 471 471 472 472 def get_model(self, id): 473 473 """ 474 474 :param id: id is key in the dictionary containing the model to return 475 475 476 476 :return: a model at this id or None if no FitArrange element was 477 477 created with this id … … 481 481 else: 482 482 return None 483 483 484 484 def remove_fit_problem(self, id): 485 485 """remove fitarrange in id""" 486 486 if id in self.fit_arrange_dict: 487 487 del self.fit_arrange_dict[id] 488 488 489 489 def select_problem_for_fit(self, id, value): 490 490 """ 491 491 select a couple of model and data at the id position in dictionary 492 492 and set in self.selected value to value 493 493 494 494 :param value: the value to allow fitting. 495 495 can only have the value one or zero … … 497 497 if id in self.fit_arrange_dict: 498 498 self.fit_arrange_dict[id].set_to_fit(value) 499 499 500 500 def get_problem_to_fit(self, id): 501 501 """ 502 502 return the self.selected value of the fit problem of id 503 503 504 504 :param id: the id of the problem 505 505 """ 506 506 if id in self.fit_arrange_dict: 507 507 self.fit_arrange_dict[id].get_to_fit() 508 509 508 509 510 510 class FitArrange: 511 511 def __init__(self): … … 514 514 to perform the Fit.FitArrange must contain exactly one model 515 515 and at least one data for the fit to be performed. 516 516 517 517 model: the model selected by the user 518 518 Ldata: a list of data what the user wants to fit 519 519 520 520 """ 521 521 self.model = None … … 528 528 """ 529 529 set_model save a copy of the model 530 530 531 531 :param model: the model being set 532 532 """ 533 533 self.model = model 534 534 535 535 def add_data(self, data): 536 536 """ 537 537 add_data fill a self.data_list with data to fit 538 538 539 539 :param data: Data to add in the list 540 540 """ 541 541 if not data in self.data_list: 542 542 self.data_list.append(data) 543 543 544 544 def get_model(self): 545 545 """ … … 547 547 """ 548 548 return self.model 549 549 550 550 def get_data(self): 551 551 """ … … 553 553 """ 554 554 return self.data_list[0] 555 555 556 556 def remove_data(self, data): 557 557 """ 558 558 Remove one element from the list 559 559 560 560 :param data: Data to remove from data_list 561 561 """ 562 562 if data in self.data_list: 563 563 self.data_list.remove(data) 564 564 565 565 def set_to_fit(self, value=0): 566 566 """ 567 567 set self.selected to 0 or 1 for other values raise an exception 568 568 569 569 :param value: integer between 0 or 1 570 570 """ 571 571 self.selected = value 572 572 573 573 def get_to_fit(self): 574 574 """ … … 602 602 if self.model is not None and self.data is not None: 603 603 self.inputs = [(self.model, self.data)] 604 604 605 605 def set_model(self, model): 606 606 """ 607 607 """ 608 608 self.model = model 609 609 610 610 def set_fitness(self, fitness): 611 611 """ 612 612 """ 613 613 self.fitness = fitness 614 614 615 615 def __str__(self): 616 616 """ … … 627 627 msg = [msg1, msg3] + msg2 628 628 return "\n".join(msg) 629 629 630 630 def print_summary(self): 631 631 """ -
src/sas/sasgui/perspectives/fitting/batchfitpage.py
r7432acb r50fcb09 5 5 import wx.lib.newevent 6 6 import math 7 8 from sas.sascalc.fit.qsmearing import smear_selection 9 7 10 from sas.sasgui.guiframe.events import StatusEvent 8 11 from sas.sasgui.guiframe.events import NewPlotEvent 12 from sas.sasgui.perspectives.fitting.basepage import PageInfoEvent 13 from sas.sasgui.perspectives.fitting.fitpage import FitPage 14 from sas.sasgui.perspectives.fitting.fitpage import check_data_validity 9 15 10 16 (Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() … … 13 19 SMEAR_SIZE_L = 0.00 14 20 SMEAR_SIZE_H = 0.00 15 16 from sas.sasgui.perspectives.fitting.basepage import PageInfoEvent17 from sas.sascalc.data_util.qsmearing import smear_selection18 from sas.sasgui.perspectives.fitting.fitpage import FitPage19 from sas.sasgui.perspectives.fitting.fitpage import check_data_validity20 21 21 22 class BatchFitPage(FitPage): … … 76 77 # """ 77 78 # is_2Ddata = False 78 # 79 # 79 80 # # Check if data is 2D 80 81 # if self.data.__class__.__name__ == "Data2D" or \ 81 82 # self.enable2D: 82 83 # is_2Ddata = True 83 # 84 # title = "Fitting" 84 # 85 # title = "Fitting" 85 86 # self._get_smear_info() 86 # 87 # 87 88 # #Sizers 88 89 # box_description_range = wx.StaticBox(self, wx.ID_ANY, str(title)) 89 # boxsizer_range = wx.StaticBoxSizer(box_description_range, wx.VERTICAL) 90 # boxsizer_range = wx.StaticBoxSizer(box_description_range, wx.VERTICAL) 90 91 # self.sizer_set_smearer = wx.BoxSizer(wx.VERTICAL) 91 92 # #sizer_smearer = wx.BoxSizer(wx.HORIZONTAL) … … 93 94 # self.sizer_set_masking = wx.BoxSizer(wx.HORIZONTAL) 94 95 # sizer_chi2 = wx.BoxSizer(wx.VERTICAL) 95 # 96 # 96 97 # sizer_fit = wx.GridSizer(2, 4, 2, 6) 97 98 # #Fit button … … 100 101 # self.btFit.Bind(wx.EVT_BUTTON, self._onFit, id= self.btFit.GetId()) 101 102 # self.btFit.SetToolTipString("Start fitting.") 102 # 103 # 103 104 # # Update and Draw button 104 105 # self.draw_button = wx.Button(self, self._ids.next(), 'Compute', size=(88, 24)) 105 106 # self.draw_button.Bind(wx.EVT_BUTTON, \ 106 107 # self._onDraw,id=self.draw_button.GetId()) 107 # self.draw_button.SetToolTipString("Compute and Draw.") 108 # self.draw_button.SetToolTipString("Compute and Draw.") 108 109 # sizer_fit.Add(self.draw_button, 0, 0) 109 # sizer_fit.Add(self.btFit, 0, 0) 110 # sizer_fit.Add(self.btFit, 0, 0) 110 111 # sizer_chi2.Add((-1, 5)) 111 112 # # get smear_selection … … 114 115 # #2D data? default 115 116 # is_2Ddata = False 116 # 117 # 117 118 # #check if it is 2D data 118 119 # if self.data.__class__.__name__ == "Data2D" or \ 119 120 # self.enable2D: 120 121 # is_2Ddata = True 121 # 122 # 122 123 # self.sizer5.Clear(True) 123 # 124 # 124 125 # self.qmin = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 125 # style=wx.TE_PROCESS_ENTER, 126 # style=wx.TE_PROCESS_ENTER, 126 127 # text_enter_callback = self._onQrangeEnter) 127 128 # self.qmin.SetValue(str(self.qmin_x)) 128 129 # self.qmin.SetToolTipString("Minimun value of Q in linear scale.") 129 # 130 # 130 131 # self.qmax = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 131 # style=wx.TE_PROCESS_ENTER, 132 # style=wx.TE_PROCESS_ENTER, 132 133 # text_enter_callback=self._onQrangeEnter) 133 134 # self.qmax.SetValue(str(self.qmax_x)) 134 135 # self.qmax.SetToolTipString("Maximum value of Q in linear scale.") 135 # 136 # 136 137 # id = self._ids.next() 137 138 # self.reset_qrange =wx.Button(self, id, 'Reset', size=(77, 20)) 138 # 139 # 139 140 # self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked, id=id) 140 141 # self.reset_qrange.SetToolTipString(\ 141 142 # "Reset Q range to the default values") 142 # 143 # 143 144 # sizer_horizontal = wx.BoxSizer(wx.HORIZONTAL) 144 145 # sizer = wx.GridSizer(2, 4, 2, 6) 145 # 146 # 146 147 # self.btEditMask = wx.Button(self, self._ids.next(),'Editor', size=(88, 23)) 147 # self.btEditMask.Bind(wx.EVT_BUTTON, 148 # self.btEditMask.Bind(wx.EVT_BUTTON, 148 149 # self._onMask,id=self.btEditMask.GetId()) 149 150 # self.btEditMask.SetToolTipString("Edit Mask.") 150 151 # self.EditMask_title = wx.StaticText(self, wx.ID_ANY, ' Masking(2D)') 151 # 152 # 152 153 # sizer.Add(wx.StaticText(self, wx.ID_ANY, 'Q range')) 153 154 # sizer.Add(wx.StaticText(self, wx.ID_ANY, ' Min[1/A]')) 154 155 # sizer.Add(wx.StaticText(self, wx.ID_ANY, ' Max[1/A]')) 155 156 # sizer.Add(self.EditMask_title) 156 # 157 # sizer.Add(self.reset_qrange) 157 # 158 # sizer.Add(self.reset_qrange) 158 159 # sizer.Add(self.qmin) 159 160 # sizer.Add(self.qmax) 160 # 161 # 161 162 # sizer.Add(self.btEditMask) 162 # boxsizer_range.Add(sizer_chi2) 163 # boxsizer_range.Add(sizer_chi2) 163 164 # boxsizer_range.Add((10, 10)) 164 165 # boxsizer_range.Add(sizer) 165 # 166 # 166 167 # boxsizer_range.Add((10, 15)) 167 168 # boxsizer_range.Add(sizer_fit) 168 169 # if is_2Ddata: 169 # self.btEditMask.Enable() 170 # self.EditMask_title.Enable() 170 # self.btEditMask.Enable() 171 # self.EditMask_title.Enable() 171 172 # else: 172 # self.btEditMask.Disable() 173 # self.btEditMask.Disable() 173 174 # self.EditMask_title.Disable() 174 # 175 # 175 176 # ## save state 176 177 # #self.save_current_state() 177 # 178 # 178 179 # self.sizer5.Add(boxsizer_range, 0, wx.EXPAND | wx.ALL, 10) 179 180 # self.sizer5.Layout() 180 # 181 # def _on_select_model(self, event=None): 181 # 182 # def _on_select_model(self, event=None): 182 183 # """ 183 184 # call back for model selection 184 # """ 185 # 186 # self.Show(False) 187 # self._on_select_model_helper() 188 # self.set_model_param_sizer(self.model) 185 # """ 186 # 187 # self.Show(False) 188 # self._on_select_model_helper() 189 # self.set_model_param_sizer(self.model) 189 190 # if self.model is None: 190 191 # self._set_bookmark_flag(False) … … 199 200 # self.state.structurecombobox = self.structurebox.GetCurrentSelection() 200 201 # self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() 201 # 202 # 202 203 # if self.model is not None: 203 204 # self._set_copy_flag(True) … … 206 207 # self._set_bookmark_flag(False) 207 208 # self._keep.Enable(False) 208 # 209 # 209 210 # temp_smear = None 210 211 # ## event to post model to fit to fitting plugins 211 212 # (ModelEventbox, _) = wx.lib.newevent.NewEvent() 212 # 213 # ## set smearing value whether or not 213 # 214 # ## set smearing value whether or not 214 215 # # the data contain the smearing info 215 # evt = ModelEventbox(model=self.model, 216 # smearer=temp_smear, 216 # evt = ModelEventbox(model=self.model, 217 # smearer=temp_smear, 217 218 # qmin=float(self.qmin_x), 218 219 # uid=self.uid, 219 # qmax=float(self.qmax_x)) 220 # 220 # qmax=float(self.qmax_x)) 221 # 221 222 # self._manager._on_model_panel(evt=evt) 222 223 # self.mbox_description.SetLabel("Model [%s]" % str(self.model.name)) 223 224 # self.state.model = self.model.clone() 224 225 # self.state.model.name = self.model.name 225 # 226 # 226 # 227 # 227 228 # if event is not None: 228 229 # ## post state to fit panel 229 230 # new_event = PageInfoEvent(page = self) 230 # wx.PostEvent(self.parent, new_event) 231 # wx.PostEvent(self.parent, new_event) 231 232 # #update list of plugins if new plugin is available 232 233 # if self.plugin_rbutton.GetValue(): … … 243 244 # self._draw_model() 244 245 # self.SetupScrolling() 245 # self.Show(True) 246 # 246 # self.Show(True) 247 # 247 248 # def _update_paramv_on_fit(self): 248 249 # """ … … 253 254 # self.fitrange = True 254 255 # is_modified = False 255 # 256 # 256 257 # if self.model is not None: 257 258 # ##Check the values … … 259 260 # self._check_value_enter( self.fixed_param) 260 261 # self._check_value_enter( self.parameters) 261 # 262 # # If qmin and qmax have been modified, update qmin and qmax and 262 # 263 # # If qmin and qmax have been modified, update qmin and qmax and 263 264 # # Here we should check whether the boundaries have been modified. 264 # # If qmin and qmax have been modified, update qmin and qmax and 265 # # If qmin and qmax have been modified, update qmin and qmax and 265 266 # # set the is_modified flag to True 266 267 # self.fitrange = self._validate_qrange(self.qmin, self.qmax) … … 273 274 # self.qmax_x = tempmax 274 275 # if tempmax == tempmin: 275 # flag = False 276 # flag = False 276 277 # #temp_smearer = None 277 278 # if self._is_2D(): 278 # # only 2D case set mask 279 # # only 2D case set mask 279 280 # flag = self._validate_Npts() 280 281 # if not flag: 281 282 # return flag 282 283 # else: flag = False 283 # else: 284 # else: 284 285 # flag = False 285 # 286 # #For invalid q range, disable the mask editor and fit button, vs. 286 # 287 # #For invalid q range, disable the mask editor and fit button, vs. 287 288 # if not self.fitrange: 288 289 # #self.btFit.Disable() … … 293 294 # if self._is_2D() and self.data is not None: 294 295 # self.btEditMask.Enable(True) 295 # 296 # 296 297 # if not flag: 297 298 # msg = "Cannot Plot or Fit :Must select a " 298 299 # msg += " model or Fitting range is not valid!!! " 299 300 # wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 300 # 301 # 301 302 # self.save_current_state() 302 # 303 # return flag 303 # 304 # return flag 304 305 # def save_current_state(self): 305 306 # """ 306 307 # Currently no save option implemented for batch page 307 308 # """ 308 # pass 309 # pass 309 310 # def save_current_state_fit(self): 310 311 # """ … … 314 315 # def set_data(self, data): 315 316 # """ 316 # reset the current data 317 # reset the current data 317 318 # """ 318 319 # #id = None … … 340 341 # self._set_save_flag(False) 341 342 # self._set_preview_flag(True) 342 # 343 # 343 344 # self.formfactorbox.Enable() 344 345 # self.structurebox.Enable() … … 346 347 # #set maximum range for x in linear scale 347 348 # if not hasattr(self.data,"data"): #Display only for 1D data fit 348 # # Minimum value of data 349 # # Minimum value of data 349 350 # data_min = min(self.data.x) 350 # # Maximum value of data 351 # # Maximum value of data 351 352 # data_max = max(self.data.x) 352 # self.btEditMask.Disable() 353 # self.btEditMask.Disable() 353 354 # self.EditMask_title.Disable() 354 355 # else: 355 # 356 # ## Minimum value of data 356 # 357 # ## Minimum value of data 357 358 # data_min = 0 358 # x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) 359 # x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) 359 360 # y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) 360 # ## Maximum value of data 361 # ## Maximum value of data 361 362 # data_max = math.sqrt(x*x + y*y) 362 # self.btEditMask.Enable() 363 # self.EditMask_title.Enable() 364 # 363 # self.btEditMask.Enable() 364 # self.EditMask_title.Enable() 365 # 365 366 # self.dataSource.SetValue(data_name) 366 367 # self.qmin_x = data_min … … 375 376 # self.state.qmin = self.qmin_x 376 377 # self.state.qmax = self.qmax_x 377 # 378 # 378 379 # #update model plot with new data information 379 380 # if flag: … … 385 386 # self.enable2D = False 386 387 # self.model_view.SetLabel("1D Mode") 387 # 388 # 388 389 # self.model_view.Disable() 389 # 390 # wx.PostEvent(self._manager.parent, 390 # 391 # wx.PostEvent(self._manager.parent, 391 392 # NewPlotEvent(group_id=group_id, 392 393 # action="delete")) 393 394 # #plot the current selected data 394 # wx.PostEvent(self._manager.parent, NewPlotEvent(plot=self.data, 395 # wx.PostEvent(self._manager.parent, NewPlotEvent(plot=self.data, 395 396 # title=str(self.data.title))) 396 397 # self._manager.store_data(uid=self.uid, data=data, -
src/sas/sasgui/perspectives/fitting/fitpage.py
red2276f r50fcb09 14 14 from sasmodels.weights import MODELS as POLYDISPERSITY_MODELS 15 15 16 from sas.sascalc.fit.qsmearing import smear_selection 17 16 18 from sas.sasgui.guiframe.events import StatusEvent, NewPlotEvent, \ 17 19 PlotQrangeEvent … … 23 25 from sas.sasgui.perspectives.fitting.basepage import PageInfoEvent as \ 24 26 PageInfoEvent 25 from sas.sascalc.data_util.qsmearing import smear_selection26 27 from .basepage import ModelTextCtrl 27 28 … … 289 290 self.btFitHelp.SetToolTipString("General fitting help.") 290 291 self.btFitHelp.Bind(wx.EVT_BUTTON, self._onFitHelp) 291 292 292 293 # Resolution Smearing Help button (for now use same technique as 293 294 # used for dI help to get tiniest possible button that works … … 303 304 self.btSmearHelp.SetToolTipString("Resolution smearing help.") 304 305 self.btSmearHelp.Bind(wx.EVT_BUTTON, self._onSmearHelp) 305 306 306 307 # textcntrl for custom resolution 307 308 self.smear_pinhole_percent = ModelTextCtrl(self, wx.ID_ANY, … … 564 565 sizer.Add(self.draw_button, 0, 0) 565 566 sizer.Add((-1, 5)) 566 567 567 568 sizer.Add(self.tcChi, 0, 0) 568 569 sizer.Add(self.Npts_fit, 0, 0) … … 570 571 sizer.Add(self.btFit, 0, 0) 571 572 sizer.Add(self.btFitHelp, 0, 0) 572 573 573 574 boxsizer_range.Add(sizer_chi2) 574 575 boxsizer_range.Add(sizer) … … 2775 2776 else: 2776 2777 return cmp(a.lower(), b.lower()) 2777 2778 2778 2779 # keys obtained now from ordered dict, so commenting alphabetical 2779 2780 # ordering keys.sort(custom_compare) -
src/sas/sasgui/perspectives/fitting/fitproblem.py
r959eb01 r50fcb09 14 14 ################################################################################ 15 15 import copy 16 from sas.sascalc.data_util.qsmearing import smear_selection 16 17 from sas.sascalc.fit.qsmearing import smear_selection 17 18 18 19 class FitProblemComponent(object): … … 622 623 # fit data: used for fit and can be modified for convenience 623 624 self.fit_data = copy.deepcopy(data) 624 self.smearer_computer_value = smear_selection(self.fit_data, 625 self.model) 625 self.smearer_computer_value = smear_selection(self.fit_data, self.model) 626 626 self.smearer_computed = True 627 627 self.result = None
Note: See TracChangeset
for help on using the changeset viewer.