Changeset 2b440504 in sasview
- Timestamp:
- Sep 30, 2011 8:01:06 AM (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:
- 62f851f
- Parents:
- 29a4024
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/qsmearing.py
r946b452 r2b440504 11 11 import logging 12 12 import sys 13 import copy 14 import sans_extension.smearer as smearer 13 import sans.models.sans_extension.smearer as smearer 15 14 from sans.models.smearing_2d import Smearer2D 16 15 … … 95 94 self._smearer = None 96 95 self.model = None 97 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 98 107 def _compute_matrix(self): 99 108 """ … … 116 125 if q_max == None: 117 126 q_max = self.max 127 118 128 _qmin_unsmeared, _qmax_unsmeared = self.get_unsmeared_range(q_min, 119 129 q_max) … … 162 172 iq_in_temp = iq_in 163 173 if self.model != None: 164 temp_first, temp_last = self._get_extrapolated_bin( first_bin,165 174 temp_first, temp_last = self._get_extrapolated_bin( \ 175 first_bin, last_bin) 166 176 if self.nbins_low > 0: 167 iq_in_low = self.model.evalDistribution( 177 iq_in_low = self.model.evalDistribution( \ 168 178 numpy.fabs(self.qvalues[0:self.nbins_low])) 169 iq_in_high = self.model.evalDistribution( 179 iq_in_high = self.model.evalDistribution( \ 170 180 self.qvalues[(len(self.qvalues) - \ 171 181 self.nbins_high - 1):]) … … 181 191 temp_first = first_bin 182 192 temp_last = last_bin 193 #iq_in_temp = iq_in 194 183 195 # Sanity check 184 196 if len(iq_in_temp) != self.nbins: … … 288 300 self.qvalues = None 289 301 290 291 302 def _initialize_smearer(self): 292 303 """ … … 332 343 self.nbins_low = 0 333 344 self.nbins_high = 0 334 self.data = data1D335 345 self.model = model 336 346 if data1D.dxw is not None and len(data1D.dxw) == len(data1D.x): … … 377 387 self.qvalues = data1d_x 378 388 379 def __deepcopy__(self, memo={}):380 """381 Return a valid copy of self.382 Avoid copying the _smearer C object and force a matrix recompute383 when the copy is used.384 """385 result = SlitSmearer(self.data, self.model)386 result.width = self.width387 result.height = self.height388 result.nbins_low = self.nbins_low389 result.nbins_high = self.nbins_high390 result.data = copy.deepcopy(self.data)391 result.model = copy.deepcopy(self.model)392 result.nbins = self.nbins393 result.nbins_low = self.nbins_low394 result.nbins_high = self.nbins_high395 result._weights = self._weights396 ## Internal flag to keep track of C++ smearer initialization397 result._init_complete = self._init_complete398 import sans_extension.smearer as smearer399 result._smearer = smearer.new_slit_smearer_with_q(self.width,400 self.height, self.qvalues)401 return result402 403 404 def __setstate__(self, state):405 """406 Restore the state of the object by reconstruction the (smearer) object407 """408 self.__dict__, self.model, self.data = state409 import sans_extension.smearer as smearer410 self._smearer = smearer.new_slit_smearer_with_q(self.width,411 self.height, self.qvalues)412 self.__dict__['_smearer'] = self._smearer413 414 def __reduce_ex__(self, proto):415 """416 Overwrite the __reduce_ex__to avoid pickle PyCobject(smearer)417 """418 model = copy.deepcopy(self.model)419 data = copy.deepcopy(self.data)420 dict = {}421 for k , v in self.__dict__.iteritems():422 if k != "_smearer":423 dict[k] = v424 state = (dict, model, data)425 return (SlitSmearer, (data, model), state, None, None)426 427 389 428 390 class _QSmearer(_BaseSmearer): … … 452 414 self._weights = None 453 415 self.qvalues = None 454 455 416 456 417 def _initialize_smearer(self): … … 496 457 super(QSmearer, self).__init__() 497 458 data1d_x = [] 498 self.data = copy.deepcopy(data1D)499 459 self.nbins_low = 0 500 460 self.nbins_high = 0 501 self.model = copy.deepcopy(model)461 self.model = model 502 462 ## Resolution 503 463 #self.width = numpy.zeros(len(data1D.x)) … … 510 470 self.nbins_low, self.nbins_high, self.width, data1d_x = \ 511 471 get_qextrapolate(self.width, data1D.x) 472 512 473 ## Number of Q bins 513 474 self.nbins = len(data1d_x) … … 518 479 ## Q-values 519 480 self.qvalues = data1d_x 520 521 522 def __deepcopy__(self, memo={}):523 """524 Return a valid copy of self.525 Avoid copying the _smearer C object and force a matrix recompute526 when the copy is used.527 """528 result = QSmearer(self.data, self.model)529 result.nbins = self.nbins530 result.min = self.min531 result.max = self.max532 result.nbins_low = self.nbins_low533 result.nbins_high = self.nbins_high534 result.width = copy.deepcopy(self.width)535 result._weights = copy.deepcopy(self._weights)536 result.qvalues = copy.deepcopy(self.qvalues)537 ## Internal flag to keep track of C++ smearer initialization538 result._init_complete = self._init_complete539 import sans_extension.smearer as smearer540 result._smearer = smearer.new_q_smearer_with_q(numpy.asarray(result.width),541 result.qvalues)542 return result543 544 545 def __setstate__(self, state):546 """547 Restore the state of the object by reconstruction the (smearer) object548 """549 self.__dict__, self.model, self.data = state550 import sans_extension.smearer as smearer551 self._smearer = smearer.new_q_smearer_with_q(numpy.asarray(self.width),552 self.qvalues)553 self.__dict__['_smearer'] = self._smearer554 555 def __reduce_ex__(self, proto):556 """557 Overwrite the __reduce_ex__to avoid pickle PyCobject(smearer)558 """559 model = copy.deepcopy(self.model)560 data = copy.deepcopy(self.data)561 dict = {}562 for k , v in self.__dict__.iteritems():563 if k != "_smearer":564 dict[k] = v565 state = (dict, model, data)566 return (QSmearer, (data, model), state, None, None)567 568 481 569 482
Note: See TracChangeset
for help on using the changeset viewer.