Changeset f60a8c2 in sasview for sansdataloader/src/sans/dataloader/data_info.py
- Timestamp:
- Apr 27, 2012 10:42:24 AM (12 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:
- 7d6351e
- Parents:
- 10bfeb3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansdataloader/src/sans/dataloader/data_info.py
re38e335 rf60a8c2 1 1 """ 2 Module that contains classes to hold information read from 2 Module that contains classes to hold information read from 3 3 reduced data files. 4 4 5 A good description of the data members can be found in 5 A good description of the data members can be found in 6 6 the CanSAS 1D XML data format: 7 7 8 8 http://www.smallangles.net/wgwiki/index.php/cansas1d_documentation 9 9 """ 10 11 10 ##################################################################### 12 11 #This software was developed by the University of Tennessee as part of the 13 12 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 14 #project funded by the US National Science Foundation. 15 #If you use DANSE applications to do scientific research that leads to 16 #publication, we ask that you acknowledge the use of the software with the 17 #following sentence: 18 #This work benefited from DANSE software developed under NSF award DMR-0520547. 13 #project funded by the US National Science Foundation. 14 #See the license text in license.txt 19 15 #copyright 2008, University of Tennessee 16 ###################################################################### 20 17 21 18 … … 28 25 import numpy 29 26 import math 27 30 28 31 29 class plottable_1D: … … 54 52 self.y = numpy.asarray(y) 55 53 if dx is not None: 56 57 if dy is not None: 54 self.dx = numpy.asarray(dx) 55 if dy is not None: 58 56 self.dy = numpy.asarray(dy) 59 if dxl is not None: 57 if dxl is not None: 60 58 self.dxl = numpy.asarray(dxl) 61 59 if dxw is not None: … … 75 73 self._yaxis = label 76 74 self._yunit = unit 75 77 76 78 77 class plottable_2D: … … 85 84 ymax = None 86 85 data = None 87 qx_data 88 qy_data 89 q_data 90 err_data 91 dqx_data 92 dqy_data 93 mask 86 qx_data = None 87 qy_data = None 88 q_data = None 89 err_data = None 90 dqx_data = None 91 dqy_data = None 92 mask = None 94 93 95 94 # Units … … 102 101 103 102 def __init__(self, data=None, err_data=None, qx_data=None, 104 105 103 qy_data=None, q_data=None, mask=None, 104 dqx_data=None, dqy_data=None): 106 105 self.data = numpy.asarray(data) 107 106 self.qx_data = numpy.asarray(qx_data) … … 110 109 self.mask = numpy.asarray(mask) 111 110 self.err_data = numpy.asarray(err_data) 112 if dqx_data is not None: self.dqx_data = numpy.asarray(dqx_data) 113 if dqy_data is not None: self.dqy_data = numpy.asarray(dqy_data) 111 if dqx_data is not None: 112 self.dqx_data = numpy.asarray(dqx_data) 113 if dqy_data is not None: 114 self.dqy_data = numpy.asarray(dqy_data) 114 115 115 116 def xaxis(self, label, unit): … … 174 175 distance = None 175 176 distance_unit = 'mm' 176 ## Offset of this detector position in X, Y, 177 #(and Z if necessary) [Vector] [mm] 177 ## Offset of this detector position in X, Y, 178 #(and Z if necessary) [Vector] [mm] 178 179 offset = None 179 180 offset_unit = 'm' … … 182 183 orientation = None 183 184 orientation_unit = 'degree' 184 ## Center of the beam on the detector in X and Y 185 ## Center of the beam on the detector in X and Y 185 186 #(and Z if necessary) [Vector] [mm] 186 187 beam_center = None … … 204 205 self.pixel_size = Vector() 205 206 206 207 207 def __str__(self): 208 208 _str = "Detector:\n" … … 222 222 return _str 223 223 224 224 225 class Aperture: 225 226 ## Name … … 239 240 self.size = Vector() 240 241 242 241 243 class Collimation: 242 244 """ … … 265 267 return _str 266 268 269 267 270 class Source: 268 271 """ 269 272 Class to hold source information 270 """ 273 """ 271 274 ## Name 272 275 name = None … … 296 299 self.beam_size = Vector() 297 300 298 299 301 def __str__(self): 300 302 _str = "Source:\n" … … 314 316 315 317 316 """ 318 """ 317 319 Definitions of radiation types 318 320 """ … … 321 323 MUON = 'muon' 322 324 ELECTRON = 'electron' 325 323 326 324 327 class Sample: … … 371 374 return _str 372 375 376 373 377 class Process: 374 378 """ … … 405 409 the data itself and any other meta data. 406 410 """ 407 ## Title 411 ## Title 408 412 title = '' 409 413 ## Run number … … 460 464 self.meta_data = {} 461 465 ## Loading errors 462 self.errors = [] 466 self.errors = [] 463 467 464 468 def append_empty_process(self): … … 497 501 # but should be implemented for each data class inherited from DataInfo 498 502 # that holds actual data (ex.: Data1D) 499 def _perform_operation(self, other, operation): 503 def _perform_operation(self, other, operation): 500 504 """ 501 505 Private method to perform operation. Not implemented for DataInfo, … … 619 623 def operation(a, b): 620 624 return b/a 621 return self._perform_operation(other, operation) 625 return self._perform_operation(other, operation) 626 622 627 623 628 class Data1D(plottable_1D, DataInfo): … … 631 636 DataInfo.__init__(self) 632 637 plottable_1D.__init__(self, x, y, dx, dy) 633 634 638 635 639 def __str__(self): … … 654 658 655 659 """ 656 def _check(v): 660 def _check(v): 657 661 if (v.__class__ == list or v.__class__ == numpy.ndarray) \ 658 662 and len(v) > 0 and min(v) > 0: … … 675 679 676 680 if clone is None or not issubclass(clone.__class__, Data1D): 677 x = numpy.zeros(length) 678 dx = numpy.zeros(length) 679 y = numpy.zeros(length) 680 dy = numpy.zeros(length) 681 x = numpy.zeros(length) 682 dx = numpy.zeros(length) 683 y = numpy.zeros(length) 684 dy = numpy.zeros(length) 681 685 clone = Data1D(x, y, dx=dx, dy=dy) 682 686 … … 684 688 clone.run = self.run 685 689 clone.filename = self.filename 686 clone.instrument 687 clone.notes = deepcopy(self.notes) 688 clone.process = deepcopy(self.process) 689 clone.detector = deepcopy(self.detector) 690 clone.sample = deepcopy(self.sample) 691 clone.source = deepcopy(self.source) 692 clone.collimation = deepcopy(self.collimation) 693 clone.meta_data = deepcopy(self.meta_data) 694 clone.errors = deepcopy(self.errors) 690 clone.instrument = self.instrument 691 clone.notes = deepcopy(self.notes) 692 clone.process = deepcopy(self.process) 693 clone.detector = deepcopy(self.detector) 694 clone.sample = deepcopy(self.sample) 695 clone.source = deepcopy(self.source) 696 clone.collimation = deepcopy(self.collimation) 697 clone.meta_data = deepcopy(self.meta_data) 698 clone.errors = deepcopy(self.errors) 695 699 696 700 return clone … … 716 720 if len(self.x) != len(other.x) or \ 717 721 len(self.y) != len(other.y): 718 msg = 722 msg = "Unable to perform operation: data length are not equal" 719 723 raise ValueError, msg 720 724 … … 734 738 dy = self.dy 735 739 if self.dy == None or (len(self.dy) != len(self.y)): 736 dy = numpy.zeros(len(self.y)) 740 dy = numpy.zeros(len(self.y)) 737 741 738 742 return dy, dy_other … … 761 765 return result 762 766 767 763 768 class Data2D(plottable_2D, DataInfo): 764 769 """ … … 777 782 y_bins = None 778 783 779 780 784 def __init__(self, data=None, err_data=None, qx_data=None, 781 qy_data=None, q_data=None, mask=None,782 785 qy_data=None, q_data=None, mask=None, 786 dqx_data=None, dqy_data=None): 783 787 self.y_bins = [] 784 788 self.x_bins = [] 785 789 DataInfo.__init__(self) 786 790 plottable_2D.__init__(self, data, err_data, qx_data, 787 qy_data, q_data, mask, dqx_data, dqy_data)791 qy_data, q_data, mask, dqx_data, dqy_data) 788 792 if len(self.detector) > 0: 789 793 raise RuntimeError, "Data2D: Detector bank already filled at init" 790 794 791 795 def __str__(self): 792 _str = 796 _str = "%s\n" % DataInfo.__str__(self) 793 797 794 798 _str += "Data:\n" … … 814 818 from copy import deepcopy 815 819 816 if clone is None or not issubclass(clone.__class__, Data2D): 817 data = numpy.zeros(length)818 err_data = numpy.zeros(length) 820 if clone is None or not issubclass(clone.__class__, Data2D): 821 data = numpy.zeros(length) 822 err_data = numpy.zeros(length) 819 823 qx_data = numpy.zeros(length) 820 824 qy_data = numpy.zeros(length) … … 824 828 dqy_data = None 825 829 clone = Data2D(data, err_data, qx_data, qy_data, 826 q_data, mask, dqx_data=dqx_data, dqy_data=dqy_data)830 q_data, mask, dqx_data=dqx_data, dqy_data=dqy_data) 827 831 828 832 clone.title = self.title … … 830 834 clone.filename = self.filename 831 835 clone.instrument = self.instrument 832 clone.notes = deepcopy(self.notes) 833 clone.process = deepcopy(self.process) 834 clone.detector = deepcopy(self.detector) 835 clone.sample = deepcopy(self.sample) 836 clone.source = deepcopy(self.source) 837 clone.collimation = deepcopy(self.collimation) 838 clone.meta_data = deepcopy(self.meta_data) 839 clone.errors = deepcopy(self.errors) 836 clone.notes = deepcopy(self.notes) 837 clone.process = deepcopy(self.process) 838 clone.detector = deepcopy(self.detector) 839 clone.sample = deepcopy(self.sample) 840 clone.source = deepcopy(self.source) 841 clone.collimation = deepcopy(self.collimation) 842 clone.meta_data = deepcopy(self.meta_data) 843 clone.errors = deepcopy(self.errors) 840 844 841 845 return clone 842 843 846 844 847 def _validity_check(self, other): … … 865 868 866 869 # Check that the scales match 867 #TODO: matching scales? 870 #TODO: matching scales? 868 871 869 872 # Check that the other data set has errors, otherwise … … 885 888 return err, err_other 886 889 887 888 890 def _perform_operation(self, other, operation): 889 891 """ … … 897 899 dy, dy_other = self._validity_check(other) 898 900 899 result = self.clone_without_data([numpy.size(self.data, 0), 901 result = self.clone_without_data([numpy.size(self.data, 0), 900 902 numpy.size(self.data, 1)]) 901 903 … … 917 919 result.err_data[i][j] = math.sqrt(math.fabs(output.variance)) 918 920 return result 919 920 921
Note: See TracChangeset
for help on using the changeset viewer.