Changes in src/sas/sascalc/dataloader/data_info.py [7988501:1b1a1c1] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/data_info.py
r7988501 r1b1a1c1 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 mutually 36 # exclusive with the presence of Qdev (dx) 37 x = None 38 y = None 39 lam = None 40 dx = None 41 dy = None 42 dlam = None 43 ## Slit smearing length 44 dxl = None 45 ## Slit smearing width 46 dxw = None 47 48 # Units 49 _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 unit 69 """ 70 self._xaxis = label 71 self._xunit = unit 72 73 def yaxis(self, label, unit): 74 """ 75 set the y axis label and unit 76 """ 77 self._yaxis = label 78 self._yunit = unit 79 27 80 28 81 class plottable_1D(object): … … 41 94 dxw = None 42 95 43 ## SESANS specific params (wavelengths for spin echo length calculation)44 45 lam = None46 dlam = None47 48 96 # Units 49 97 _xaxis = '' … … 52 100 _yunit = '' 53 101 54 def __init__(self, x, y, dx=None, dy=None, dxl=None, dxw=None , lam=None, dlam=None):102 def __init__(self, x, y, dx=None, dy=None, dxl=None, dxw=None): 55 103 self.x = numpy.asarray(x) 56 104 self.y = numpy.asarray(y) … … 63 111 if dxw is not None: 64 112 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)69 113 70 114 def xaxis(self, label, unit): … … 692 736 return self._perform_union(other) 693 737 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): 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): 708 746 DataInfo.__init__(self) 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??') 747 plottable_sesans1D.__init__(self, x, y, lam, dx, dy, dlam) 718 748 719 749 def __str__(self): … … 729 759 return _str 730 760 731 def is_slit_smeared(self):732 """733 Check whether the data has slit smearing information734 :return: True is slit smearing info is present, False otherwise735 """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 True740 return False741 return _check(self.dxl) or _check(self.dxw)742 743 761 def clone_without_data(self, length=0, clone=None): 744 762 """ … … 751 769 """ 752 770 from copy import deepcopy 753 754 771 if clone is None or not issubclass(clone.__class__, Data1D): 755 772 x = numpy.zeros(length) … … 757 774 y = numpy.zeros(length) 758 775 dy = numpy.zeros(length) 759 lam = numpy.zeros(length) 760 dlam = numpy.zeros(length) 761 clone = Data1D(x, y, lam=lam, dx=dx, dy=dy, dlam=dlam ) 776 clone = Data1D(x, y, dx=dx, dy=dy) 762 777 763 778 clone.title = self.title … … 777 792 return clone 778 793 794 class Data1D(plottable_1D, DataInfo): 795 """ 796 1D data class 797 """ 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 printout 808 """ 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 _str 816 817 def is_slit_smeared(self): 818 """ 819 Check whether the data has slit smearing information 820 :return: True is slit smearing info is present, False otherwise 821 """ 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 True 826 return False 827 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 (which 832 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 initialized 836 :param clone: if provided, the data will be copied to clone 837 """ 838 from copy import deepcopy 839 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.title 848 clone.run = self.run 849 clone.filename = self.filename 850 clone.instrument = self.instrument 851 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 clone 862 779 863 def _validity_check(self, other): 780 864 """ … … 797 881 raise ValueError, msg 798 882 # Here we could also extrapolate between data points 799 ZERO = 1.0e-12883 TOLERANCE = 0.01 800 884 for i in range(len(self.x)): 801 if math.fabs( self.x[i] - other.x[i]) > ZERO:885 if math.fabs((self.x[i] - other.x[i])/self.x[i]) > TOLERANCE: 802 886 msg = "Incompatible data sets: x-values do not match" 803 887 raise ValueError, msg … … 1009 1093 """ 1010 1094 err_other = None 1095 TOLERANCE = 0.01 1011 1096 if isinstance(other, Data2D): 1012 1097 # Check that data lengths are the same … … 1017 1102 raise ValueError, msg 1018 1103 for ind in range(len(self.data)): 1019 if self.qx_data[ind] != other.qx_data[ind]:1020 msg = "Incompatible data sets: qx-values do not match "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]) 1021 1106 raise ValueError, msg 1022 if self.qy_data[ind] != other.qy_data[ind]:1023 msg = "Incompatible data sets: qy-values do not match "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]) 1024 1109 raise ValueError, msg 1025 1110
Note: See TracChangeset
for help on using the changeset viewer.