Changeset 442f42f in sasview for DataLoader/data_info.py
- Timestamp:
- Aug 29, 2008 5:20:02 PM (16 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:
- b88c6e0
- Parents:
- 579ba85
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/data_info.py
r579ba85 r442f42f 81 81 82 82 def __init__(self, data=None, err_data=None): 83 self.data = data84 self.err_data = err_data83 self.data = numpy.asarray(data) 84 self.err_data = numpy.asarray(err_data) 85 85 86 86 def xaxis(self, label, unit): … … 687 687 return _str 688 688 689 def clone_without_data(self, length=0): 690 """ 691 Clone the current object, without copying the data (which 692 will be filled out by a subsequent operation). 693 The data arrays will be initialized to zero. 694 695 @param length: length of the data array to be initialized 696 """ 697 from copy import deepcopy 698 699 data = numpy.zeros(length) 700 err_data = numpy.zeros(length) 701 702 clone = Data2D(data, err_data) 703 clone.title = self.title 704 clone.run = self.run 705 clone.filename = self.filename 706 clone.notes = deepcopy(self.notes) 707 clone.process = deepcopy(self.process) 708 clone.detector = deepcopy(self.detector) 709 clone.sample = deepcopy(self.sample) 710 clone.source = deepcopy(self.source) 711 clone.collimation = deepcopy(self.collimation) 712 clone.meta_data = deepcopy(self.meta_data) 713 clone.errors = deepcopy(self.errors) 714 715 return clone 716 717 718 def _validity_check(self, other): 719 """ 720 Checks that the data lengths are compatible. 721 Checks that the x vectors are compatible. 722 Returns errors vectors equal to original 723 errors vectors if they were present or vectors 724 of zeros when none was found. 725 726 @param other: other data set for operation 727 @return: dy for self, dy for other [numpy arrays] 728 @raise ValueError: when lengths are not compatible 729 """ 730 err_other = None 731 if isinstance(other, Data2D): 732 # Check that data lengths are the same 733 if numpy.size(self.data) != numpy.size(other.data): 734 raise ValueError, "Unable to perform operation: data length are not equal" 735 736 # Check that the scales match 737 #TODO: matching scales? 738 739 # Check that the other data set has errors, otherwise 740 # create zero vector 741 #TODO: test this 742 err_other = other.err_data 743 if other.err_data==None or (numpy.size(other.err_data) != numpy.size(other.data)): 744 err_other = numpy.zeros([numpy.size(other.data,0), numpy.size(other.data,1)]) 745 746 # Check that we have errors, otherwise create zero vector 747 err = self.err_data 748 if self.err_data==None or (numpy.size(self.err_data) != numpy.size(self.data)): 749 err = numpy.zeros([numpy.size(self.data,0), numpy.size(self.data,1)]) 750 751 return err, err_other 752 753 754 def _perform_operation(self, other, operation): 755 """ 756 Perform 2D operations between data sets 757 758 @param other: other data set 759 @param operation: function defining the operation 760 """ 761 # First, check the data compatibility 762 dy, dy_other = self._validity_check(other) 763 764 result = self.clone_without_data([numpy.size(self.data,0), numpy.size(self.data,1)]) 765 766 for i in range(numpy.size(self.data,0)): 767 for j in range(numpy.size(self.data,1)): 768 result.data[i][j] = self.data[i][j] 769 if self.err_data is not None and numpy.size(self.data)==numpy.size(self.err_data): 770 result.err_data[i][j] = self.err_data[i][j] 771 772 a = Uncertainty(self.data[i][j], dy[i][j]**2) 773 if isinstance(other, Data2D): 774 b = Uncertainty(other.data[i][j], dy_other[i][j]**2) 775 else: 776 b = other 777 778 output = operation(a, b) 779 result.data[i][j] = output.x 780 result.err_data[i][j] = math.sqrt(math.fabs(output.variance)) 781 return result 782
Note: See TracChangeset
for help on using the changeset viewer.