- Timestamp:
- Jan 12, 2017 11:01:09 AM (8 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, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 1905128
- Parents:
- 83c09af
- Location:
- src/sas
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/cansas_reader.py
r83c09af raf08e55 21 21 # For saving individual sections of data 22 22 from sas.sascalc.dataloader.data_info import Data1D, Data2D, DataInfo, \ 23 plottable_1D 23 plottable_1D, plottable_2D 24 24 from sas.sascalc.dataloader.data_info import Collimation, TransmissionSpectrum, \ 25 25 Detector, Process, Aperture … … 59 59 The CanSAS reader requires PyXML 0.8.4 or later. 60 60 """ 61 # #CanSAS version - defaults to version 1.061 # CanSAS version - defaults to version 1.0 62 62 cansas_version = "1.0" 63 63 base_ns = "{cansas1d/1.0}" … … 66 66 invalid = True 67 67 frm = "" 68 # #Log messages and errors68 # Log messages and errors 69 69 logging = None 70 70 errors = set() 71 # #Namespace hierarchy for current xml_file object71 # Namespace hierarchy for current xml_file object 72 72 names = None 73 73 ns_list = None 74 # #Temporary storage location for loading multiple data sets in a single file74 # Temporary storage location for loading multiple data sets in a single file 75 75 current_datainfo = None 76 76 current_dataset = None 77 77 current_data1d = None 78 78 data = None 79 # #List of data1D objects to be sent back to SasView79 # List of data1D objects to be sent back to SasView 80 80 output = None 81 # #Wildcards81 # Wildcards 82 82 type = ["XML files (*.xml)|*.xml", "SasView Save Files (*.svs)|*.svs"] 83 # #List of allowed extensions83 # List of allowed extensions 84 84 ext = ['.xml', '.XML', '.svs', '.SVS'] 85 # #Flag to bypass extension check85 # Flag to bypass extension check 86 86 allow_all = True 87 87 … … 223 223 self.parent_class = tagname_original 224 224 if tagname == 'SASdata': 225 self._initialize_new_data_set() 226 ## Recursion step to access data within the group 225 self._initialize_new_data_set(node) 226 if isinstance(self.current_dataset, plottable_2D): 227 x_bins = attr.get("x_bins", "") 228 y_bins = attr.get("y_bins", "") 229 if x_bins is not "" and y_bins is not "": 230 self.current_dataset.shape = (x_bins, y_bins) 231 else: 232 self.current_dataset.shape = () 233 # Recursion step to access data within the group 227 234 self._parse_entry(node, True) 228 235 if tagname == "SASsample": … … 239 246 data_point, unit = self._get_node_value(node, tagname) 240 247 241 # #If this is a dataset, store the data appropriately248 # If this is a dataset, store the data appropriately 242 249 if tagname == 'Run': 243 250 self.current_datainfo.run_name[data_point] = name … … 248 255 self.current_datainfo.notes.append(data_point) 249 256 250 # # I and Q Data251 elif tagname == 'I' :257 # I and Q - 1D data 258 elif tagname == 'I' and isinstance(self.current_dataset, plottable_1D): 252 259 self.current_dataset.yaxis("Intensity", unit) 253 260 self.current_dataset.y = np.append(self.current_dataset.y, data_point) 254 elif tagname == 'Idev' :261 elif tagname == 'Idev' and isinstance(self.current_dataset, plottable_1D): 255 262 self.current_dataset.dy = np.append(self.current_dataset.dy, data_point) 256 263 elif tagname == 'Q': … … 267 274 elif tagname == 'Shadowfactor': 268 275 pass 269 270 ## Sample Information 276 # I and Qx, Qy - 2D data 277 elif tagname == 'I' and isinstance(self.current_dataset, plottable_2D): 278 self.current_dataset.yaxis("Intensity", unit) 279 self.current_dataset.data = np.append(self.current_dataset.data, data_point) 280 elif tagname == 'Idev' and isinstance(self.current_dataset, plottable_2D): 281 self.current_dataset.err_data = np.append(self.current_dataset.err_data, data_point) 282 elif tagname == 'Qx': 283 self.current_dataset.xaxis("Qx", unit) 284 self.current_dataset.qx_data = np.append(self.current_dataset.qx_data, data_point) 285 elif tagname == 'Qy': 286 self.current_dataset.yaxis("Qy", unit) 287 self.current_dataset.qy_data = np.append(self.current_dataset.qy_data, data_point) 288 elif tagname == 'Qxdev': 289 self.current_dataset.xaxis("Qxdev", unit) 290 self.current_dataset.dqx_data = np.append(self.current_dataset.dqx_data, data_point) 291 elif tagname == 'Qydev': 292 self.current_dataset.yaxis("Qydev", unit) 293 self.current_dataset.dqy_data = np.append(self.current_dataset.dqy_data, data_point) 294 elif tagname == 'Mask': 295 self.current_dataset.mask = np.append(self.current_dataset.mask, bool(data_point)) 296 297 # Sample Information 271 298 elif tagname == 'ID' and self.parent_class == 'SASsample': 272 299 self.current_datainfo.sample.ID = data_point … … 302 329 self.current_datainfo.sample.orientation_unit = unit 303 330 304 # #Instrumental Information331 # Instrumental Information 305 332 elif tagname == 'name' and self.parent_class == 'SASinstrument': 306 333 self.current_datainfo.instrument = data_point 307 # #Detector Information334 # Detector Information 308 335 elif tagname == 'name' and self.parent_class == 'SASdetector': 309 336 self.detector.name = data_point … … 350 377 self.detector.orientation.z = data_point 351 378 self.detector.orientation_unit = unit 352 # #Collimation and Aperture379 # Collimation and Aperture 353 380 elif tagname == 'length' and self.parent_class == 'SAScollimation': 354 381 self.collimation.length = data_point … … 369 396 self.collimation.size_unit = unit 370 397 371 # #Process Information398 # Process Information 372 399 elif tagname == 'name' and self.parent_class == 'SASprocess': 373 400 self.process.name = data_point … … 389 416 self.process.term.append(dic) 390 417 391 # #Transmission Spectrum418 # Transmission Spectrum 392 419 elif tagname == 'T' and self.parent_class == 'Tdata': 393 420 self.transspectrum.transmission = np.append(self.transspectrum.transmission, data_point) … … 400 427 self.transspectrum.wavelength_unit = unit 401 428 402 # #Source Information429 # Source Information 403 430 elif tagname == 'wavelength' and (self.parent_class == 'SASsource' or self.parent_class == 'SASData'): 404 431 self.current_datainfo.source.wavelength = data_point … … 427 454 self.current_datainfo.source.beam_shape = data_point 428 455 429 # #Everything else goes in meta_data456 # Everything else goes in meta_data 430 457 else: 431 458 new_key = self._create_unique_key(self.current_datainfo.meta_data, tagname) … … 441 468 self.add_data_set() 442 469 empty = None 443 if self.output[0].dx is not None:444 self.output[0].dxl = np.empty(0)445 self.output[0].dxw = np.empty(0)446 else:447 self.output[0].dx = np.empty(0)448 470 return self.output[0], empty 449 471 … … 517 539 self.current_datainfo = DataInfo() 518 540 519 def _initialize_new_data_set(self, parent_list=None):541 def _initialize_new_data_set(self, node=None): 520 542 """ 521 543 A private class method to generate a new 1D data object. 522 544 Outside methods should call add_data_set() to be sure any existing data is stored properly. 523 545 524 :param parent_list: List of names of parent elements 525 """ 526 527 if parent_list is None: 528 parent_list = [] 546 :param node: XML node to determine if 1D or 2D data 547 """ 529 548 x = np.array(0) 530 549 y = np.array(0) 550 for child in node: 551 if child.tag.replace(self.base_ns, "") == "Idata": 552 for i_child in child: 553 if i_child.tag.replace(self.base_ns, "") == "Qx": 554 self.current_dataset = plottable_2D() 555 return 531 556 self.current_dataset = plottable_1D(x, y) 532 557 … … 563 588 """ 564 589 565 # #Append errors to dataset and reset class errors590 # Append errors to dataset and reset class errors 566 591 self.current_datainfo.errors = set() 567 592 for error in self.errors: … … 569 594 self.errors.clear() 570 595 571 # #Combine all plottables with datainfo and append each to output572 # #Type cast data arrays to float64 and find min/max as appropriate596 # Combine all plottables with datainfo and append each to output 597 # Type cast data arrays to float64 and find min/max as appropriate 573 598 for dataset in self.data: 574 if dataset.x is not None: 575 dataset.x = np.delete(dataset.x, [0]) 576 dataset.x = dataset.x.astype(np.float64) 577 dataset.xmin = np.min(dataset.x) 578 dataset.xmax = np.max(dataset.x) 579 if dataset.y is not None: 580 dataset.y = np.delete(dataset.y, [0]) 581 dataset.y = dataset.y.astype(np.float64) 582 dataset.ymin = np.min(dataset.y) 583 dataset.ymax = np.max(dataset.y) 584 if dataset.dx is not None: 585 dataset.dx = np.delete(dataset.dx, [0]) 586 dataset.dx = dataset.dx.astype(np.float64) 587 if dataset.dxl is not None: 588 dataset.dxl = np.delete(dataset.dxl, [0]) 589 dataset.dxl = dataset.dxl.astype(np.float64) 590 if dataset.dxw is not None: 591 dataset.dxw = np.delete(dataset.dxw, [0]) 592 dataset.dxw = dataset.dxw.astype(np.float64) 593 if dataset.dy is not None: 594 dataset.dy = np.delete(dataset.dy, [0]) 595 dataset.dy = dataset.dy.astype(np.float64) 596 np.trim_zeros(dataset.x) 597 np.trim_zeros(dataset.y) 598 np.trim_zeros(dataset.dy) 599 if isinstance(dataset, plottable_1D): 600 if dataset.x is not None: 601 dataset.x = np.delete(dataset.x, [0]) 602 dataset.x = dataset.x.astype(np.float64) 603 dataset.xmin = np.min(dataset.x) 604 dataset.xmax = np.max(dataset.x) 605 if dataset.y is not None: 606 dataset.y = np.delete(dataset.y, [0]) 607 dataset.y = dataset.y.astype(np.float64) 608 dataset.ymin = np.min(dataset.y) 609 dataset.ymax = np.max(dataset.y) 610 if dataset.dx is not None: 611 dataset.dx = np.delete(dataset.dx, [0]) 612 dataset.dx = dataset.dx.astype(np.float64) 613 if dataset.dxl is not None: 614 dataset.dxl = np.delete(dataset.dxl, [0]) 615 dataset.dxl = dataset.dxl.astype(np.float64) 616 if dataset.dxw is not None: 617 dataset.dxw = np.delete(dataset.dxw, [0]) 618 dataset.dxw = dataset.dxw.astype(np.float64) 619 if dataset.dy is not None: 620 dataset.dy = np.delete(dataset.dy, [0]) 621 dataset.dy = dataset.dy.astype(np.float64) 622 np.trim_zeros(dataset.x) 623 np.trim_zeros(dataset.y) 624 np.trim_zeros(dataset.dy) 625 elif isinstance(dataset, plottable_2D): 626 dataset.data = np.delete(dataset.data, [0]) 627 dataset.data = dataset.data.astype(np.float64) 628 dataset.qx_data = np.delete(dataset.qx_data, [0]) 629 dataset.qx_data = dataset.qx_data.astype(np.float64) 630 dataset.xmin = np.min(dataset.qx_data) 631 dataset.xmax = np.max(dataset.qx_data) 632 dataset.qy_data = np.delete(dataset.qy_data, [0]) 633 dataset.qy_data = dataset.qy_data.astype(np.float64) 634 dataset.ymin = np.min(dataset.qy_data) 635 dataset.ymax = np.max(dataset.qy_data) 636 dataset.q_data = np.sqrt(dataset.qx_data * dataset.qx_data 637 + dataset.qy_data * dataset.qy_data) 638 if dataset.err_data is not None: 639 dataset.err_data = np.delete(dataset.err_data, [0]) 640 dataset.err_data = dataset.err_data.astype(np.float64) 641 if dataset.dqx_data is not None: 642 dataset.dqx_data = np.delete(dataset.dqx_data, [0]) 643 dataset.dqx_data = dataset.dqx_data.astype(np.float64) 644 if dataset.dqy_data is not None: 645 dataset.dqy_data = np.delete(dataset.dqy_data, [0]) 646 dataset.dqy_data = dataset.dqy_data.astype(np.float64) 647 if dataset.mask is not None: 648 dataset.mask = np.delete(dataset.mask, [0]) 649 dataset.mask = dataset.mask.astype(dtype=bool) 650 651 if len(dataset.shape) == 2: 652 n_rows, n_cols = dataset.shape 653 dataset.y_bins = dataset.qy_data[0::int(n_cols)] 654 dataset.x_bins = dataset.qx_data[:int(n_cols)] 655 dataset.data = dataset.data.flatten() 656 else: 657 dataset.y_bins = [] 658 dataset.x_bins = [] 659 dataset.data = dataset.data.flatten() 660 599 661 final_dataset = combine_data(dataset, self.current_datainfo) 600 662 self.output.append(final_dataset) … … 696 758 and local_unit.lower() != "none": 697 759 if HAS_CONVERTER == True: 698 # #Check local units - bad units raise KeyError760 # Check local units - bad units raise KeyError 699 761 data_conv_q = Converter(local_unit) 700 762 value_unit = default_unit … … 743 805 A method to check all resolution data sets are the same size as I and Q 744 806 """ 745 dql_exists = False 746 dqw_exists = False 747 dq_exists = False 748 di_exists = False 749 if self.current_dataset.dxl is not None: 750 dql_exists = True 751 if self.current_dataset.dxw is not None: 752 dqw_exists = True 753 if self.current_dataset.dx is not None: 754 dq_exists = True 755 if self.current_dataset.dy is not None: 756 di_exists = True 757 if dqw_exists and not dql_exists: 758 array_size = self.current_dataset.dxw.size - 1 759 self.current_dataset.dxl = np.append(self.current_dataset.dxl, np.zeros([array_size])) 760 elif dql_exists and not dqw_exists: 761 array_size = self.current_dataset.dxl.size - 1 762 self.current_dataset.dxw = np.append(self.current_dataset.dxw, np.zeros([array_size])) 763 elif not dql_exists and not dqw_exists and not dq_exists: 764 array_size = self.current_dataset.x.size - 1 765 self.current_dataset.dx = np.append(self.current_dataset.dx, np.zeros([array_size])) 766 if not di_exists: 767 array_size = self.current_dataset.y.size - 1 768 self.current_dataset.dy = np.append(self.current_dataset.dy, np.zeros([array_size])) 769 807 if isinstance(self.current_dataset, plottable_1D): 808 dql_exists = False 809 dqw_exists = False 810 dq_exists = False 811 di_exists = False 812 if self.current_dataset.dxl is not None: 813 dql_exists = True 814 if self.current_dataset.dxw is not None: 815 dqw_exists = True 816 if self.current_dataset.dx is not None: 817 dq_exists = True 818 if self.current_dataset.dy is not None: 819 di_exists = True 820 if dqw_exists and not dql_exists: 821 array_size = self.current_dataset.dxw.size - 1 822 self.current_dataset.dxl = np.append(self.current_dataset.dxl, 823 np.zeros([array_size])) 824 elif dql_exists and not dqw_exists: 825 array_size = self.current_dataset.dxl.size - 1 826 self.current_dataset.dxw = np.append(self.current_dataset.dxw, 827 np.zeros([array_size])) 828 elif not dql_exists and not dqw_exists and not dq_exists: 829 array_size = self.current_dataset.x.size - 1 830 self.current_dataset.dx = np.append(self.current_dataset.dx, 831 np.zeros([array_size])) 832 if not di_exists: 833 array_size = self.current_dataset.y.size - 1 834 self.current_dataset.dy = np.append(self.current_dataset.dy, 835 np.zeros([array_size])) 836 elif isinstance(self.current_dataset, plottable_2D): 837 dqx_exists = False 838 dqy_exists = False 839 di_exists = False 840 mask_exists = False 841 if self.current_dataset.dqx_data is not None: 842 dqx_exists = True 843 if self.current_dataset.dqy_data is not None: 844 dqy_exists = True 845 if self.current_dataset.err_data is not None: 846 di_exists = True 847 if self.current_dataset.mask is not None: 848 mask_exists = True 849 if not dqy_exists: 850 array_size = self.current_dataset.qy_data.size - 1 851 self.current_dataset.dqy_data = np.append( 852 self.current_dataset.dqy_data, np.zeros([array_size])) 853 if not dqx_exists: 854 array_size = self.current_dataset.qx_data.size - 1 855 self.current_dataset.dqx_data = np.append( 856 self.current_dataset.dqx_data, np.zeros([array_size])) 857 if not di_exists: 858 array_size = self.current_dataset.data.size - 1 859 self.current_dataset.err_data = np.append( 860 self.current_dataset.err_data, np.zeros([array_size])) 861 if not mask_exists: 862 array_size = self.current_dataset.data.size - 1 863 self.current_dataset.mask = np.append( 864 self.current_dataset.mask, 865 np.ones([array_size] ,dtype=bool)) 770 866 771 867 ####### All methods below are for writing CanSAS XML files ####### 772 773 868 774 869 def write(self, filename, datainfo): … … 795 890 :param datainfo: Data1D object 796 891 """ 892 is_2d = False 797 893 if issubclass(datainfo.__class__, Data2D): 798 894 is_2d = True … … 950 1046 """ 951 1047 node = self.create_element("SASdata") 1048 attr = {} 1049 if datainfo.data.shape: 1050 attr["x_bins"] = len(datainfo.x_bins) 1051 attr["y_bins"] = len(datainfo.y_bins) 952 1052 self.append(node, entry_node) 953 1053 … … 971 1071 {'unit': datainfo._xunit}) 972 1072 if datainfo.mask is not None and len(datainfo.mask) > i: 973 self.write_node(point, "Mask", datainfo. err_data[i])1073 self.write_node(point, "Mask", datainfo.mask[i]) 974 1074 975 1075 def _write_trans_spectrum(self, datainfo, entry_node): -
src/sas/sascalc/dataloader/readers/schema/cansas1d_invalid_v1_0.xsd
r83c09af raf08e55 62 62 <attribute name="name" type="string" use="optional" default="" /> 63 63 <attribute name="timestamp" type="dateTime" use="optional" /> 64 <attribute name="x_bins" type="string" use="optional" /> 65 <attribute name="y_bins" type="string" use="optional" /> 64 66 </complexType> 65 67 -
src/sas/sascalc/dataloader/readers/schema/cansas1d_invalid_v1_1.xsd
r83c09af raf08e55 62 62 <attribute name="name" type="string" use="optional" default="" /> 63 63 <attribute name="timestamp" type="dateTime" use="optional" /> 64 <attribute name="x_bins" type="string" use="optional" /> 65 <attribute name="y_bins" type="string" use="optional" /> 64 66 </complexType> 65 67 -
src/sas/sasgui/perspectives/fitting/pagestate.py
r83c09af raf08e55 1109 1109 """ 1110 1110 node = dom.xpath('ns:data_class', namespaces={'ns': CANSAS_NS}) 1111 if not node or node[0].text.lstrip().rstrip() != "Data2D": 1112 return_value, _ = self._parse_entry(dom) 1113 numpy.trim_zeros(return_value.x) 1114 numpy.trim_zeros(return_value.y) 1115 numpy.trim_zeros(return_value.dy) 1116 size_dx = return_value.dx.size 1117 size_dxl = return_value.dxl.size 1118 size_dxw = return_value.dxw.size 1119 if size_dxl == 0 and size_dxw == 0: 1120 return_value.dxl = None 1121 return_value.dxw = None 1122 numpy.trim_zeros(return_value.dx) 1123 elif size_dx == 0: 1124 return_value.dx = None 1125 size_dx = size_dxl 1126 numpy.trim_zeros(return_value.dxl) 1127 numpy.trim_zeros(return_value.dxw) 1128 1129 return return_value, _ 1130 1131 # Parse 2D 1132 data_info = Data2D() 1133 1134 # Look up title 1135 self._store_content('ns:Title', dom, 'title', data_info) 1136 1137 # Look up run number 1138 nodes = dom.xpath('ns:Run', namespaces={'ns': CANSAS_NS}) 1139 for item in nodes: 1140 if item.text is not None: 1141 value = item.text.strip() 1142 if len(value) > 0: 1143 data_info.run.append(value) 1144 if item.get('name') is not None: 1145 data_info.run_name[value] = item.get('name') 1146 1147 # Look up instrument name 1148 self._store_content('ns:SASinstrument/ns:name', dom, 1149 'instrument', data_info) 1150 1151 # Notes 1152 note_list = dom.xpath('ns:SASnote', namespaces={'ns': CANSAS_NS}) 1153 for note in note_list: 1154 try: 1155 if note.text is not None: 1156 note_value = note.text.strip() 1157 if len(note_value) > 0: 1158 data_info.notes.append(note_value) 1159 except Exception: 1160 err_mess = "cansas_reader.read: error processing entry notes\n" 1161 err_mess += " %s" % sys.exc_value 1162 self.errors.append(err_mess) 1163 logging.error(err_mess) 1164 1165 # Sample info ################### 1166 entry = get_content('ns:SASsample', dom) 1167 if entry is not None: 1168 data_info.sample.name = entry.get('name') 1169 1170 self._store_content('ns:SASsample/ns:ID', dom, 'ID', data_info.sample) 1171 self._store_float('ns:SASsample/ns:thickness', dom, 'thickness', 1172 data_info.sample) 1173 self._store_float('ns:SASsample/ns:transmission', dom, 'transmission', 1174 data_info.sample) 1175 self._store_float('ns:SASsample/ns:temperature', dom, 'temperature', 1176 data_info.sample) 1177 1178 nodes = dom.xpath('ns:SASsample/ns:details', 1179 namespaces={'ns': CANSAS_NS}) 1180 for item in nodes: 1181 try: 1182 if item.text is not None: 1183 detail_value = item.text.strip() 1184 if len(detail_value) > 0: 1185 data_info.sample.details.append(detail_value) 1186 except Exception: 1187 err_mess = "cansas_reader.read: error processing entry notes\n" 1188 err_mess += " %s" % sys.exc_value 1189 self.errors.append(err_mess) 1190 logging.error(err_mess) 1191 1192 # Position (as a vector) 1193 self._store_float('ns:SASsample/ns:position/ns:x', dom, 'position.x', 1194 data_info.sample) 1195 self._store_float('ns:SASsample/ns:position/ns:y', dom, 'position.y', 1196 data_info.sample) 1197 self._store_float('ns:SASsample/ns:position/ns:z', dom, 'position.z', 1198 data_info.sample) 1199 1200 # Orientation (as a vector) 1201 self._store_float('ns:SASsample/ns:orientation/ns:roll', 1202 dom, 'orientation.x', data_info.sample) 1203 self._store_float('ns:SASsample/ns:orientation/ns:pitch', 1204 dom, 'orientation.y', data_info.sample) 1205 self._store_float('ns:SASsample/ns:orientation/ns:yaw', 1206 dom, 'orientation.z', data_info.sample) 1207 1208 # Source info ################### 1209 entry = get_content('ns:SASinstrument/ns:SASsource', dom) 1210 if entry is not None: 1211 data_info.source.name = entry.get('name') 1212 1213 self._store_content('ns:SASinstrument/ns:SASsource/ns:radiation', 1214 dom, 'radiation', data_info.source) 1215 self._store_content('ns:SASinstrument/ns:SASsource/ns:beam_shape', 1216 dom, 'beam_shape', data_info.source) 1217 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength', 1218 dom, 'wavelength', data_info.source) 1219 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_min', 1220 dom, 'wavelength_min', data_info.source) 1221 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_max', 1222 dom, 'wavelength_max', data_info.source) 1223 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_spread', 1224 dom, 'wavelength_spread', data_info.source) 1225 1226 # Beam size (as a vector) 1227 entry = get_content('ns:SASinstrument/ns:SASsource/ns:beam_size', dom) 1228 if entry is not None: 1229 data_info.source.beam_size_name = entry.get('name') 1230 1231 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:x', 1232 dom, 'beam_size.x', data_info.source) 1233 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:y', 1234 dom, 'beam_size.y', data_info.source) 1235 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:z', 1236 dom, 'beam_size.z', data_info.source) 1237 1238 # Collimation info ################### 1239 nodes = dom.xpath('ns:SASinstrument/ns:SAScollimation', 1240 namespaces={'ns': CANSAS_NS}) 1241 for item in nodes: 1242 collim = Collimation() 1243 if item.get('name') is not None: 1244 collim.name = item.get('name') 1245 self._store_float('ns:length', item, 'length', collim) 1246 1247 # Look for apertures 1248 apert_list = item.xpath('ns:aperture', 1249 namespaces={'ns': CANSAS_NS}) 1250 for apert in apert_list: 1251 aperture = Aperture() 1252 1253 # Get the name and type of the aperture 1254 aperture.name = apert.get('name') 1255 aperture.type = apert.get('type') 1256 1257 self._store_float('ns:distance', apert, 'distance', aperture) 1258 1259 entry = get_content('ns:size', apert) 1260 if entry is not None: 1261 aperture.size_name = entry.get('name') 1262 1263 self._store_float('ns:size/ns:x', apert, 'size.x', aperture) 1264 self._store_float('ns:size/ns:y', apert, 'size.y', aperture) 1265 self._store_float('ns:size/ns:z', apert, 'size.z', aperture) 1266 1267 collim.aperture.append(aperture) 1268 1269 data_info.collimation.append(collim) 1270 1271 # Detector info ###################### 1272 nodes = dom.xpath('ns:SASinstrument/ns:SASdetector', 1273 namespaces={'ns': CANSAS_NS}) 1274 for item in nodes: 1275 1276 detector = Detector() 1277 1278 self._store_content('ns:name', item, 'name', detector) 1279 self._store_float('ns:SDD', item, 'distance', detector) 1280 1281 # Detector offset (as a vector) 1282 self._store_float('ns:offset/ns:x', item, 'offset.x', detector) 1283 self._store_float('ns:offset/ns:y', item, 'offset.y', detector) 1284 self._store_float('ns:offset/ns:z', item, 'offset.z', detector) 1285 1286 # Detector orientation (as a vector) 1287 self._store_float('ns:orientation/ns:roll', item, 1288 'orientation.x', detector) 1289 self._store_float('ns:orientation/ns:pitch', item, 1290 'orientation.y', detector) 1291 self._store_float('ns:orientation/ns:yaw', item, 1292 'orientation.z', detector) 1293 1294 # Beam center (as a vector) 1295 self._store_float('ns:beam_center/ns:x', item, 1296 'beam_center.x', detector) 1297 self._store_float('ns:beam_center/ns:y', item, 1298 'beam_center.y', detector) 1299 self._store_float('ns:beam_center/ns:z', item, 1300 'beam_center.z', detector) 1301 1302 # Pixel size (as a vector) 1303 self._store_float('ns:pixel_size/ns:x', item, 1304 'pixel_size.x', detector) 1305 self._store_float('ns:pixel_size/ns:y', item, 1306 'pixel_size.y', detector) 1307 self._store_float('ns:pixel_size/ns:z', item, 1308 'pixel_size.z', detector) 1309 1310 self._store_float('ns:slit_length', item, 'slit_length', detector) 1311 1312 data_info.detector.append(detector) 1313 1314 # Processes info ###################### 1315 nodes = dom.xpath('ns:SASprocess', namespaces={'ns': CANSAS_NS}) 1316 for item in nodes: 1317 process = Process() 1318 self._store_content('ns:name', item, 'name', process) 1319 self._store_content('ns:date', item, 'date', process) 1320 self._store_content('ns:description', item, 'description', process) 1321 1322 term_list = item.xpath('ns:term', namespaces={'ns': CANSAS_NS}) 1323 for term in term_list: 1324 try: 1325 term_attr = {} 1326 for attr in term.keys(): 1327 term_attr[attr] = term.get(attr).strip() 1328 if term.text is not None: 1329 term_attr['value'] = term.text.strip() 1330 process.term.append(term_attr) 1331 except: 1332 err_mess = "cansas_reader.read: error processing " 1333 err_mess += "entry notes\n %s" % sys.exc_value 1334 self.errors.append(err_mess) 1335 logging.error(err_mess) 1336 1337 note_list = item.xpath('ns:SASprocessnote', 1338 namespaces={'ns': CANSAS_NS}) 1339 for note in note_list: 1340 if note.text is not None: 1341 process.notes.append(note.text.strip()) 1342 1343 data_info.process.append(process) 1344 1345 # Data info ###################### 1346 nodes = dom.xpath('ns:SASdata', namespaces={'ns': CANSAS_NS}) 1347 if len(nodes) > 1: 1348 raise RuntimeError, "CanSAS reader is not compatible with" + \ 1349 " multiple SASdata entries" 1350 1351 for entry in nodes: 1352 for item in LIST_OF_DATA_2D_ATTR: 1353 # get node 1354 node = get_content('ns:%s' % item[0], entry) 1355 setattr(data_info, item[1], parse_entry_helper(node, item)) 1356 1357 for item in LIST_OF_DATA_2D_VALUES: 1358 field = get_content('ns:%s' % item[0], entry) 1359 value_list = [] 1360 if field is not None: 1361 value_list = \ 1362 [parse_entry_helper(node, item) for node in field] 1363 if len(value_list) < 2: 1364 setattr(data_info, item[0], None) 1365 else: 1366 setattr(data_info, item[0], numpy.array(value_list)) 1367 1368 return data_info 1111 return_value, _ = self._parse_entry(dom) 1112 return return_value, _ 1369 1113 1370 1114 def _read_cansas(self, path):
Note: See TracChangeset
for help on using the changeset viewer.