Changeset a3f125f0 in sasview for src/sas/models/qsmearing.py
- Timestamp:
- Mar 30, 2015 10:51:41 AM (9 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:
- edfc8ac
- Parents:
- d5419f7f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/models/qsmearing.py
r9f7fbd9 ra3f125f0 59 59 if _found_resolution == True: 60 60 return QSmearer(data1D, model) 61 #return pinhole_smear(data1D, model) 61 62 62 63 # Look for slit smearing data … … 81 82 # If we found slit smearing data, return a slit smearer 82 83 if _found_slit == True: 83 return PySlitSmearer(data1D, model) 84 #return SlitSmearer(data1D, model) 85 return slit_smear(data1D, model) 84 86 return None 85 87 … … 198 200 iq_in[len(iq_in) - 1] = iq_in_high[0] 199 201 # Append the extrapolated points to the data points 200 if self.nbins_low > 0: 202 if self.nbins_low > 0: 201 203 iq_in_temp = numpy.append(iq_in_low, iq_in) 202 204 if self.nbins_high > 0: … … 586 588 587 589 588 from .resolution import Slit1D 589 class PySlitSmearer(object): 590 def __init__(self, data1D, model = None): 590 from .resolution import Slit1D, Pinhole1D 591 class PySmear(object): 592 """ 593 Wrapper for pure python sasmodels resolution functions. 594 """ 595 def __init__(self, resolution, model): 591 596 self.model = model 592 593 q = data1D.x 594 width = data1D.dxw if data1D.dxw is not None else 0 595 height = data1D.dxl if data1D.dxl is not None else 0 596 # TODO: width and height seem to be reversed 597 self.resolution = Slit1D(q, height, width) 598 599 def __call__(self, iq_in, first_bin=0, last_bin=None): 600 if last_bin is None or last_bin >= len(iq_in): 601 last_bin = len(iq_in) - 1 597 self.resolution = resolution 598 self.offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 599 600 def apply(self, iq_in, first_bin=0, last_bin=None): 601 """ 602 Apply the resolution function to the data. 603 604 Note that this is called with iq_in matching data.x, but with 605 iq_in[first_bin:last_bin] set to theory values for these bins, 606 and the remainder left undefined. The first_bin, last_bin values 607 should be those returned from get_bin_range. 608 609 The returned value is of the same length as iq_in, with the range 610 first_bin:last_bin set to the resolution smeared values. 611 """ 612 if last_bin is None: last_bin = len(iq_in) 613 start, end = first_bin + self.offset, last_bin + self.offset 602 614 q_calc = self.resolution.q_calc 603 615 iq_calc = numpy.empty_like(q_calc) 604 iq_calc[:first_bin] = 0 605 iq_calc[first_bin:last_bin+1] = iq_in 606 if last_bin < len(q_calc)-1: 607 iq_calc[last_bin:] = self.model.evalDistribution(q_calc[last_bin:]) 608 iq_out = self.resolution.apply(iq_calc) 609 return iq_out[first_bin:last_bin+1] 616 if start > 0: 617 iq_calc[:start] = self.model.evalDistribution(q_calc[:start]) 618 if end+1 < len(q_calc): 619 iq_calc[end+1:] = self.model.evalDistribution(q_calc[end+1:]) 620 iq_calc[start:end+1] = iq_in[first_bin:last_bin+1] 621 smeared = self.resolution.apply(iq_calc) 622 return smeared 623 __call__ = apply 610 624 611 625 def get_bin_range(self, q_min=None, q_max=None): 612 626 """ 613 614 :param q_min: minimum q-value to smear 615 :param q_max: maximum q-value to smear 616 617 """ 618 # assume the data values are sorted 619 first = numpy.searchsorted(self.resolution.q, q_min) 620 # assume that the resolution is much larger than the q range 621 last = len(self.resolution.q)-1 622 return first, last 627 For a given q_min, q_max, find the corresponding indices in the data. 628 629 Returns first, last. 630 631 Note that these are indexes into q from the data, not the q_calc 632 needed by the resolution function. Note also that these are the 633 indices, not the range limits. That is, the complete range will be 634 q[first:last+1]. 635 """ 636 q = self.resolution.q 637 first = numpy.searchsorted(q, q_min) 638 last = numpy.searchsorted(q, q_max) 639 return first, min(last,len(q)-1) 640 641 def slit_smear(data, model=None): 642 q = data.x 643 width = data.dxw if data.dxw is not None else 0 644 height = data.dxl if data.dxl is not None else 0 645 # TODO: width and height seem to be reversed 646 return PySmear(Slit1D(q, height, width), model) 647 648 def pinhole_smear(data, model=None): 649 q = data.x 650 width = data.dx if data.dx is not None else 0 651 return PySmear(Pinhole1D(q, width), model)
Note: See TracChangeset
for help on using the changeset viewer.