Changeset 535752b in sasview
- Timestamp:
- Jan 6, 2011 2:45:07 PM (14 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- d6da3b1
- Parents:
- 1cc23fd
- Location:
- DataLoader
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/extensions/smearer.hh
ra378756 r535752b 61 61 protected: 62 62 // Number of points used in the smearing computation 63 static const int npts = 1000;63 static const int npts = 2000; 64 64 65 65 public: -
DataLoader/qsmearing.py
r7241d56 r535752b 79 79 # If we found slit smearing data, return a slit smearer 80 80 if _found_slit == True: 81 return SlitSmearer(data1D )81 return SlitSmearer(data1D, model) 82 82 return None 83 83 … … 167 167 if first_bin < 0: 168 168 first_bin = 0 169 169 170 170 # With a model given, compute I for the extrapolated points and append 171 171 # to the iq_in 172 #iq_in_temp = iq_in172 iq_in_temp = iq_in 173 173 if self.model != None: 174 174 temp_first, temp_last = self._get_extrapolated_bin( \ 175 175 first_bin, last_bin) 176 iq_in_low = self.model.evalDistribution( \ 176 if self.nbins_low > 1: 177 iq_in_low = self.model.evalDistribution( \ 177 178 numpy.fabs(self.qvalues[0:self.nbins_low])) 178 179 iq_in_high = self.model.evalDistribution( \ … … 190 191 temp_first = first_bin 191 192 temp_last = last_bin 192 iq_in_temp = iq_in193 #iq_in_temp = iq_in 193 194 194 195 # Sanity check … … 211 212 temp_first += self.nbins_low 212 213 temp_last = self.nbins - self.nbins_high 213 214 return iq_out[temp_first: temp_last] 214 out = iq_out[temp_first: temp_last] 215 216 return out 215 217 216 218 def _initialize_smearer(self): … … 218 220 """ 219 221 return NotImplemented 220 221 def set_model(self, model):222 """223 Set model224 """225 if model != None:226 self.model = model227 222 228 223 … … 300 295 self.nbins = nbins 301 296 ## Number of points used in the smearing computation 302 self.npts = 1000297 self.npts = 2000 303 298 ## Smearing matrix 304 299 self._weights = None … … 335 330 Adaptor for slit smearing class and SANS data 336 331 """ 337 def __init__(self, data1D ):332 def __init__(self, data1D, model = None): 338 333 """ 339 334 Assumption: equally spaced bins of increasing q-values. … … 348 343 self.nbins_low = 0 349 344 self.nbins_high = 0 345 self.model = model 350 346 if data1D.dxw is not None and len(data1D.dxw) == len(data1D.x): 351 347 self.width = data1D.dxw[0] … … 366 362 msg += " the same for all data" 367 363 raise RuntimeError, msg 368 364 # If a model is given, get the q extrapolation 365 if self.model == None: 366 data1d_x = data1D.x 367 else: 368 # Take larger sigma 369 if self.height > self.width: 370 # The denominator (2.0) covers all the possible w^2 + h^2 range 371 sigma_in = data1D.dxl / 2.0 372 elif self.width > 0: 373 sigma_in = data1D.dxw / 2.0 374 else: 375 sigma_in = [] 376 377 self.nbins_low, self.nbins_high, _, data1d_x = \ 378 get_qextrapolate(sigma_in, data1D.x) 379 369 380 ## Number of Q bins 370 self.nbins = len(data1 D.x)381 self.nbins = len(data1d_x) 371 382 ## Minimum Q 372 self.min = min(data1 D.x)383 self.min = min(data1d_x) 373 384 ## Maximum 374 self.max = max(data1 D.x)385 self.max = max(data1d_x) 375 386 ## Q-values 376 self.qvalues = data1 D.x387 self.qvalues = data1d_x 377 388 378 389 … … 491 502 width_low = math.fabs(width[0]) 492 503 width_high = math.fabs(width[length -1]) 493 # Find bin sizes 494 bin_size_low = math.fabs(data_x[1] - data_x[0]) 495 bin_size_high = math.fabs(data_x[length - 1] - data_x[length - 2]) 504 496 505 # Compare width(dQ) to the data bin size and take smaller one as the bin 497 506 # size of the extrapolation; this will correct some weird behavior 498 # at the edge 499 if width_low < (bin_size_low): 500 bin_size_low = width_low / 2.0 501 if width_high < (bin_size_high): 502 bin_size_high = width_high / 2.0 507 # at the edge: This method was out (commented) 508 # because it becomes very expansive when 509 # bin size is very small comparing to the width. 510 # Now on, we will just give the bin size of the extrapolated points 511 # based on the width. 512 # Find bin sizes 513 #bin_size_low = math.fabs(data_x[1] - data_x[0]) 514 #bin_size_high = math.fabs(data_x[length - 1] - data_x[length - 2]) 515 # Let's set the bin size 1/3 of the width(sigma), it is good as long as 516 # the scattering is monotonous. 517 #if width_low < (bin_size_low): 518 bin_size_low = width_low / 10.0 519 #if width_high < (bin_size_high): 520 bin_size_high = width_high / 10.0 503 521 504 522 # Number of q points required below the 1st data point in order to extend 505 523 # them 3 times of the width (std) 506 nbins_low = math.ceil(3 * width_low / bin_size_low)524 nbins_low = math.ceil(3.0 * width_low / bin_size_low) 507 525 # Number of q points required above the last data point 508 nbins_high = math.ceil(3 * width_high / (bin_size_high))526 nbins_high = math.ceil(3.0 * width_high / (bin_size_high)) 509 527 # Make null q points 510 528 extra_low = numpy.zeros(nbins_low) … … 513 531 ind = 0 514 532 qvalue = data_x[0] - bin_size_low 533 #if qvalue > 0: 515 534 while(ind < nbins_low): 516 535 extra_low[nbins_low - (ind + 1)] = qvalue 517 536 qvalue -= bin_size_low 518 537 ind += 1 519 # Remove the points <= 0 520 #extra_low = extra_low[extra_low > 0] 521 #nbins_low = len(extra_low) 538 #if qvalue <= 0: 539 # break 540 # Redefine nbins_low 541 nbins_low = ind 522 542 # Reset ind for another extrapolation 523 543 ind = 0 … … 528 548 ind += 1 529 549 # Make a new qx array 530 data_x_ext = numpy.append(extra_low, data_x) 550 if nbins_low > 0: 551 data_x_ext = numpy.append(extra_low, data_x) 552 else: 553 data_x_ext = data_x 531 554 data_x_ext = numpy.append(data_x_ext, extra_high) 532 555 533 556 # Redefine extra_low and high based on corrected nbins 534 # And note that it is not necessary for extra_width to be a non-zero 535 extra_low = numpy.zeros(nbins_low) 557 # And note that it is not necessary for extra_width to be a non-zero 558 if nbins_low > 0: 559 extra_low = numpy.zeros(nbins_low) 536 560 extra_high = numpy.zeros(nbins_high) 537 561 # Make new width array 538 562 new_width = numpy.append(extra_low, width) 539 563 new_width = numpy.append(new_width, extra_high) 540 541 return nbins_low, nbins_high, new_width, data_x_ext 564 565 # nbins corrections due to the negative q value 566 nbins_low = nbins_low - len(data_x_ext[data_x_ext<0]) 567 return nbins_low, nbins_high, \ 568 new_width[data_x_ext>0], data_x_ext[data_x_ext>0] 542 569 543 570 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.