Changes in src/sas/sascalc/dataloader/data_info.py [1b1a1c1:7988501] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/data_info.py
r1b1a1c1 r7988501 25 25 import numpy 26 26 import math 27 28 class plottable_sesans1D(object):29 """30 SESANS is a place holder for 1D SESANS plottables.31 32 #TODO: This was directly copied from the plottables_1D. Modified Somewhat.33 #Class has been updated.34 """35 # The presence of these should be mutually36 # exclusive with the presence of Qdev (dx)37 x = None38 y = None39 lam = None40 dx = None41 dy = None42 dlam = None43 ## Slit smearing length44 dxl = None45 ## Slit smearing width46 dxw = None47 48 # Units49 _xaxis = ''50 _xunit = ''51 _yaxis = ''52 _yunit = ''53 54 def __init__(self, x, y, lam, dx=None, dy=None, dlam=None):55 # print "SESANS plottable working"56 self.x = numpy.asarray(x)57 self.y = numpy.asarray(y)58 self.lam = numpy.asarray(lam)59 if dx is not None:60 self.dx = numpy.asarray(dx)61 if dy is not None:62 self.dy = numpy.asarray(dy)63 if dlam is not None:64 self.dlam = numpy.asarray(dlam)65 66 def xaxis(self, label, unit):67 """68 set the x axis label and unit69 """70 self._xaxis = label71 self._xunit = unit72 73 def yaxis(self, label, unit):74 """75 set the y axis label and unit76 """77 self._yaxis = label78 self._yunit = unit79 80 27 81 28 class plottable_1D(object): … … 94 41 dxw = None 95 42 43 ## SESANS specific params (wavelengths for spin echo length calculation) 44 45 lam = None 46 dlam = None 47 96 48 # Units 97 49 _xaxis = '' … … 100 52 _yunit = '' 101 53 102 def __init__(self, x, y, dx=None, dy=None, dxl=None, dxw=None ):54 def __init__(self, x, y, dx=None, dy=None, dxl=None, dxw=None, lam=None, dlam=None): 103 55 self.x = numpy.asarray(x) 104 56 self.y = numpy.asarray(y) … … 111 63 if dxw is not None: 112 64 self.dxw = numpy.asarray(dxw) 65 if lam is not None: 66 self.lam = numpy.asarray(lam) 67 if dlam is not None: 68 self.dlam = numpy.asarray(dlam) 113 69 114 70 def xaxis(self, label, unit): … … 736 692 return self._perform_union(other) 737 693 738 class SESANSData1D(plottable_sesans1D, DataInfo): 739 """ 740 SESANS 1D data class 741 """ 742 x_unit = 'nm' 743 y_unit = 'pol' 744 745 def __init__(self, x=None, y=None, lam=None, dx=None, dy=None, dlam=None): 694 class Data1D(plottable_1D, DataInfo): 695 """ 696 1D data class 697 """ 698 if plottable_1D.lam is None: # This means it's SANS data! 699 x_unit = '1/A' 700 y_unit = '1/cm' 701 elif plottable_1D.lam is not None: # This means it's SESANS data! 702 x_unit = 'A' 703 y_unit = 'pol' 704 else: # and if it's neither, you get punished! 705 raise(TypeError,'This is neither SANS nor SESANS data, what the hell are you doing??') 706 707 def __init__(self, x=None, y=None, dx=None, dy=None, lam=None, dlam=None): 746 708 DataInfo.__init__(self) 747 plottable_sesans1D.__init__(self, x, y, lam, dx, dy, dlam) 709 plottable_1D.__init__(self, x, y, dx, dy,None, None, lam, dlam) 710 if self.lam is None: # This means the lam param was not detected in the data: it's SANS data! 711 x_unit = '1/A' 712 y_unit = '1/cm' 713 elif self.lam is not None: # This means lam was detected (should be an empty ndarray): it's SESANS data! 714 x_unit = 'A' 715 y_unit = 'pol' 716 else: # and if it's neither, you get punished! 717 raise(TypeError,'This is neither SANS nor SESANS data, what the hell are you doing??') 748 718 749 719 def __str__(self): … … 759 729 return _str 760 730 731 def is_slit_smeared(self): 732 """ 733 Check whether the data has slit smearing information 734 :return: True is slit smearing info is present, False otherwise 735 """ 736 def _check(v): 737 if (v.__class__ == list or v.__class__ == numpy.ndarray) \ 738 and len(v) > 0 and min(v) > 0: 739 return True 740 return False 741 return _check(self.dxl) or _check(self.dxw) 742 761 743 def clone_without_data(self, length=0, clone=None): 762 744 """ … … 769 751 """ 770 752 from copy import deepcopy 753 771 754 if clone is None or not issubclass(clone.__class__, Data1D): 772 755 x = numpy.zeros(length) … … 774 757 y = numpy.zeros(length) 775 758 dy = numpy.zeros(length) 776 clone = Data1D(x, y, dx=dx, dy=dy) 759 lam = numpy.zeros(length) 760 dlam = numpy.zeros(length) 761 clone = Data1D(x, y, lam=lam, dx=dx, dy=dy, dlam=dlam ) 777 762 778 763 clone.title = self.title … … 792 777 return clone 793 778 794 class Data1D(plottable_1D, DataInfo):795 """796 1D data class797 """798 x_unit = '1/A'799 y_unit = '1/cm'800 801 def __init__(self, x, y, dx=None, dy=None):802 DataInfo.__init__(self)803 plottable_1D.__init__(self, x, y, dx, dy)804 805 def __str__(self):806 """807 Nice printout808 """809 _str = "%s\n" % DataInfo.__str__(self)810 _str += "Data:\n"811 _str += " Type: %s\n" % self.__class__.__name__812 _str += " X-axis: %s\t[%s]\n" % (self._xaxis, self._xunit)813 _str += " Y-axis: %s\t[%s]\n" % (self._yaxis, self._yunit)814 _str += " Length: %g\n" % len(self.x)815 return _str816 817 def is_slit_smeared(self):818 """819 Check whether the data has slit smearing information820 :return: True is slit smearing info is present, False otherwise821 """822 def _check(v):823 if (v.__class__ == list or v.__class__ == numpy.ndarray) \824 and len(v) > 0 and min(v) > 0:825 return True826 return False827 return _check(self.dxl) or _check(self.dxw)828 829 def clone_without_data(self, length=0, clone=None):830 """831 Clone the current object, without copying the data (which832 will be filled out by a subsequent operation).833 The data arrays will be initialized to zero.834 835 :param length: length of the data array to be initialized836 :param clone: if provided, the data will be copied to clone837 """838 from copy import deepcopy839 840 if clone is None or not issubclass(clone.__class__, Data1D):841 x = numpy.zeros(length)842 dx = numpy.zeros(length)843 y = numpy.zeros(length)844 dy = numpy.zeros(length)845 clone = Data1D(x, y, dx=dx, dy=dy)846 847 clone.title = self.title848 clone.run = self.run849 clone.filename = self.filename850 clone.instrument = self.instrument851 clone.notes = deepcopy(self.notes)852 clone.process = deepcopy(self.process)853 clone.detector = deepcopy(self.detector)854 clone.sample = deepcopy(self.sample)855 clone.source = deepcopy(self.source)856 clone.collimation = deepcopy(self.collimation)857 clone.trans_spectrum = deepcopy(self.trans_spectrum)858 clone.meta_data = deepcopy(self.meta_data)859 clone.errors = deepcopy(self.errors)860 861 return clone862 863 779 def _validity_check(self, other): 864 780 """ … … 881 797 raise ValueError, msg 882 798 # Here we could also extrapolate between data points 883 TOLERANCE = 0.01799 ZERO = 1.0e-12 884 800 for i in range(len(self.x)): 885 if math.fabs( (self.x[i] - other.x[i])/self.x[i]) > TOLERANCE:801 if math.fabs(self.x[i] - other.x[i]) > ZERO: 886 802 msg = "Incompatible data sets: x-values do not match" 887 803 raise ValueError, msg … … 1093 1009 """ 1094 1010 err_other = None 1095 TOLERANCE = 0.011096 1011 if isinstance(other, Data2D): 1097 1012 # Check that data lengths are the same … … 1102 1017 raise ValueError, msg 1103 1018 for ind in range(len(self.data)): 1104 if math.fabs((self.qx_data[ind] - other.qx_data[ind])/self.qx_data[ind]) > TOLERANCE:1105 msg = "Incompatible data sets: qx-values do not match : %s %s" % (self.qx_data[ind], other.qx_data[ind])1019 if self.qx_data[ind] != other.qx_data[ind]: 1020 msg = "Incompatible data sets: qx-values do not match" 1106 1021 raise ValueError, msg 1107 if math.fabs((self.qy_data[ind] - other.qy_data[ind])/self.qy_data[ind]) > TOLERANCE:1108 msg = "Incompatible data sets: qy-values do not match : %s %s" % (self.qy_data[ind], other.qy_data[ind])1022 if self.qy_data[ind] != other.qy_data[ind]: 1023 msg = "Incompatible data sets: qy-values do not match" 1109 1024 raise ValueError, msg 1110 1025
Note: See TracChangeset
for help on using the changeset viewer.