Changeset 5d2e4c1 in sasview for sansmodels/src/sans
- Timestamp:
- Aug 26, 2011 3:15:04 PM (13 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:
- 6e4c9fe
- Parents:
- 32cd80c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/qsmearing.py
raaeae3a0 r5d2e4c1 11 11 import logging 12 12 import sys 13 import sans.models.sans_extension.smearer as smearer 13 import copy 14 import sans_extension.smearer as smearer 14 15 from sans.models.smearing_2d import Smearer2D 15 16 … … 94 95 self._smearer = None 95 96 self.model = None 96 97 def __deepcopy__(self, memo={}): 98 """ 99 Return a valid copy of self. 100 Avoid copying the _smearer C object and force a matrix recompute 101 when the copy is used. 102 """ 103 result = _BaseSmearer() 104 result.nbins = self.nbins 105 return result 106 97 107 98 def _compute_matrix(self): 108 99 """ … … 125 116 if q_max == None: 126 117 q_max = self.max 127 128 118 _qmin_unsmeared, _qmax_unsmeared = self.get_unsmeared_range(q_min, 129 119 q_max) … … 172 162 iq_in_temp = iq_in 173 163 if self.model != None: 174 temp_first, temp_last = self._get_extrapolated_bin( \175 first_bin,last_bin)164 temp_first, temp_last = self._get_extrapolated_bin(first_bin, 165 last_bin) 176 166 if self.nbins_low > 0: 177 iq_in_low = self.model.evalDistribution( \167 iq_in_low = self.model.evalDistribution( 178 168 numpy.fabs(self.qvalues[0:self.nbins_low])) 179 iq_in_high = self.model.evalDistribution( \169 iq_in_high = self.model.evalDistribution( 180 170 self.qvalues[(len(self.qvalues) - \ 181 171 self.nbins_high - 1):]) … … 191 181 temp_first = first_bin 192 182 temp_last = last_bin 193 #iq_in_temp = iq_in194 195 183 # Sanity check 196 184 if len(iq_in_temp) != self.nbins: … … 300 288 self.qvalues = None 301 289 290 302 291 def _initialize_smearer(self): 303 292 """ … … 343 332 self.nbins_low = 0 344 333 self.nbins_high = 0 334 self.data = data1D 345 335 self.model = model 346 336 if data1D.dxw is not None and len(data1D.dxw) == len(data1D.x): … … 387 377 self.qvalues = data1d_x 388 378 379 def __deepcopy__(self, memo={}): 380 """ 381 Return a valid copy of self. 382 Avoid copying the _smearer C object and force a matrix recompute 383 when the copy is used. 384 """ 385 result = SlitSmearer(self.data, self.model) 386 result.width = self.width 387 result.height = self.height 388 result.nbins_low = self.nbins_low 389 result.nbins_high = self.nbins_high 390 result.data = copy.deepcopy(self.data) 391 result.model = copy.deepcopy(self.model) 392 result.nbins = self.nbins 393 result.nbins_low = self.nbins_low 394 result.nbins_high = self.nbins_high 395 result._weights = self._weights 396 ## Internal flag to keep track of C++ smearer initialization 397 result._init_complete = self._init_complete 398 import sans_extension.smearer as smearer 399 result._smearer = smearer.new_slit_smearer_with_q(self.width, 400 self.height, self.qvalues) 401 return result 402 403 404 def __setstate__(self, state): 405 """ 406 """ 407 self.__dict__, self.model, self.data = state 408 import sans_extension.smearer as smearer 409 self._smearer = smearer.new_slit_smearer_with_q(self.width, 410 self.height, self.qvalues) 411 412 def __reduce_ex__(self, proto): 413 """ 414 Overwrite the __reduce_ex__ of PyTypeObject *type call in the init of 415 c model. 416 """ 417 model = copy.deepcopy(self.model) 418 data = copy.deepcopy(self.data) 419 dict = self.__dict__ 420 if "_smearer" in dict.keys(): 421 del dict["_smearer"] 422 state = (dict, model, data) 423 return (QSmearer, (data, model), state, None, None) 424 389 425 390 426 class _QSmearer(_BaseSmearer): … … 457 493 super(QSmearer, self).__init__() 458 494 data1d_x = [] 495 self.data = copy.deepcopy(data1D) 459 496 self.nbins_low = 0 460 497 self.nbins_high = 0 461 self.model = model498 self.model = copy.deepcopy(model) 462 499 ## Resolution 463 500 #self.width = numpy.zeros(len(data1D.x)) … … 470 507 self.nbins_low, self.nbins_high, self.width, data1d_x = \ 471 508 get_qextrapolate(self.width, data1D.x) 472 473 509 ## Number of Q bins 474 510 self.nbins = len(data1d_x) … … 479 515 ## Q-values 480 516 self.qvalues = data1d_x 517 518 def __deepcopy__(self, memo={}): 519 """ 520 Return a valid copy of self. 521 Avoid copying the _smearer C object and force a matrix recompute 522 when the copy is used. 523 """ 524 result = QSmearer(self.data, self.model) 525 result.nbins = self.nbins 526 result.min = self.min 527 result.max = self.max 528 result.nbins_low = self.nbins_low 529 result.nbins_high = self.nbins_high 530 result.width = copy.deepcopy(self.width) 531 result._weights = copy.deepcopy(self._weights) 532 result.qvalues = copy.deepcopy(self.qvalues) 533 ## Internal flag to keep track of C++ smearer initialization 534 result._init_complete = self._init_complete 535 import sans_extension.smearer as smearer 536 result._smearer = smearer.new_q_smearer_with_q(numpy.asarray(result.width), 537 result.qvalues) 538 return result 539 540 541 def __setstate__(self, state): 542 """ 543 """ 544 self.__dict__, self.model, self.data = state 545 import sans_extension.smearer as smearer 546 self._smearer = smearer.new_q_smearer_with_q(numpy.asarray(self.width), 547 self.qvalues) 548 549 def __reduce_ex__(self, proto): 550 """ 551 Overwrite the __reduce_ex__ of PyTypeObject *type call in the init of 552 c model. 553 """ 554 model = copy.deepcopy(self.model) 555 data = copy.deepcopy(self.data) 556 dict = self.__dict__ 557 if "_smearer" in dict.keys(): 558 del dict["_smearer"] 559 state = (dict, model, data) 560 return (QSmearer, (data, model), state, None, None) 561 481 562 482 563
Note: See TracChangeset
for help on using the changeset viewer.