Changeset 75eeb425 in sasview for src/sans/dataloader/readers
- Timestamp:
- Dec 24, 2013 1:32:14 PM (11 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:
- 81b524f
- Parents:
- a25d242
- Location:
- src/sans/dataloader/readers
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sans/dataloader/readers/cansas_constants.py
reda8972 r75eeb425 15 15 "SASentry" : { 16 16 "units_optional" : True, 17 "variable" : " ",17 "variable" : None, 18 18 "storeas" : "content", 19 19 "attributes" : {"name" : {"variable" : "{0}.run_name[node_value] = \"{1}\""}}, … … 26 26 "SASdata" : { 27 27 "attributes" : {"name" : {"variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"",}}, 28 "variable" : None, 28 29 "children" : {"Idata" : { 29 30 "storeas" : "float", 31 "units_optional" : False, 30 32 "variable" : None, 31 "units_optional" : False,32 33 "attributes" : { 33 34 "name" : { … … 43 44 "Q" : { 44 45 "variable" : "{0}.x = numpy.append({0}.x, {1})", 45 "unit" : " _xunit",46 "unit" : "x_unit", 46 47 "attributes" : { 47 48 "unit" : { 48 "variable" : "{0}._xunit ",49 "variable" : "{0}._xunit = \"{1}\"", 49 50 "storeas" : "content" 50 51 } … … 53 54 "I" : { 54 55 "variable" : "{0}.y = numpy.append({0}.y, {1})", 55 "unit" : " _yunit",56 "unit" : "y_unit", 56 57 "attributes" : { 57 58 "unit" : { 58 "variable" : "{0}._yunit ",59 "variable" : "{0}._yunit = \"{1}\"", 59 60 "storeas" : "content" 60 61 } … … 63 64 "Idev" : { 64 65 "variable" : "{0}.dy = numpy.append({0}.dy, {1})", 66 "unit" : "y_unit", 65 67 "attributes" : { 66 68 "unit" : { … … 72 74 "Qdev" : { 73 75 "variable" : "{0}.dx = numpy.append({0}.dx, {1})", 76 "unit" : "x_unit", 74 77 "attributes" : { 75 78 "unit" : { … … 81 84 "dQw" : { 82 85 "variable" : "{0}.dxw = numpy.append({0}.dxw, {1})", 86 "unit" : "x_unit", 83 87 "attributes" : { 84 88 "unit" : { … … 90 94 "dQl" : { 91 95 "variable" : "{0}.dxl = numpy.append({0}.dxl, {1})", 96 "unit" : "x_unit", 92 97 "attributes" : { 93 98 "unit" : { … … 99 104 "Qmean" : { 100 105 "storeas" : "content", 106 "unit" : "x_unit", 101 107 "variable" : "{0}.meta_data[\"{2}\"] = {1}", 102 108 "attributes" : {"unit" : {"variable" : "{0}.meta_data[\"{2}\"] = \"{1}\""}}, … … 116 122 }, 117 123 "SAStransmission_spectrum" : { 124 "variable" : None, 118 125 "children" : { 119 126 "Tdata" : { 127 "storeas" : "float", 128 "variable" : None, 120 129 "children" : { 121 130 "Lambda" : { 122 "variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"", 123 "attributes" : {"unit" : {"variable" : "{0}.meta_data[\"{2}\"] = \"{1}\""}} 131 "variable" : "{0}.trans_spectrum.wavelength.append({1})", 132 "unit" : "trans_spectrum.wavelength_unit", 133 "attributes" : { 134 "unit" : { 135 "variable" : "{0}.trans_spectrum.wavelength_unit = \"{1}\"", 136 "storeas" : "content" 137 } 138 } 124 139 }, 125 140 "T" : { 126 "variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"", 127 "attributes" : {"unit" : {"variable" : "{0}.meta_data[\"{2}\"] = \"{1}\""}} 141 "variable" : "{0}.trans_spectrum.transmission.append({1})", 142 "unit" : "trans_spectrum.transmission_unit", 143 "attributes" : { 144 "unit" : { 145 "variable" : "{0}.trans_spectrum.transmission_unit = \"{1}\"", 146 "storeas" : "content" 147 } 148 } 128 149 }, 129 150 "Tdev" : { 130 "variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"", 131 "attributes" : {"unit" : {"variable" : "{0}.meta_data[\"{2}\"] = \"{1}\""}} 151 "variable" : "{0}.trans_spectrum.transmission_deviation.append({1})", 152 "unit" : "trans_spectrum.transmission_deviation_unit", 153 "attributes" : { 154 "unit" : { 155 "variable" : "{0}.trans_spectrum.transmission_deviation_unit = \"{1}\"", 156 "storeas" : "content" 157 } 158 } 132 159 }, 133 160 "<any>" : {"variable" : "{0}.meta_data[\"{2}\"] = \"{1}\""}, … … 136 163 "<any>" : {"variable" : "{0}.meta_data[\"{2}\"] = \"{1}\""}, 137 164 }, 138 "attributes" : {"name" : {"variable" : "{0}. meta_data[\"{2}\"]= \"{1}\""},139 "timestamp" : {"variable" : "{0}. meta_data[\"{2}\"]= \"{1}\""},}165 "attributes" : {"name" : {"variable" : "{0}.trans_spectrum.name = \"{1}\""}, 166 "timestamp" : {"variable" : "{0}.trans_spectrum.timestamp = \"{1}\""},} 140 167 }, 141 168 "SASsample" : { 142 169 "attributes" : {"name" : {"variable" : "{0}.sample.name = \"{1}\""},}, 170 "variable" : None, 143 171 "children" : { 144 172 "ID" : {"variable" : "{0}.sample.ID = \"{1}\""}, … … 171 199 "position" : { 172 200 "children" : { 201 "variable" : None, 173 202 "x" : { 174 203 "variable" : "{0}.sample.position.x = {1}", … … 205 234 }, 206 235 "orientation" : { 236 "variable" : None, 207 237 "children" : { 208 238 "roll" : { … … 246 276 }, 247 277 "SASinstrument" : { 278 "variable" : None, 248 279 "children" : { 280 "variable" : None, 249 281 "name" : {"variable" : "{0}.instrument = \"{1}\""}, 250 282 "SASsource" : { 251 283 "attributes" : {"name" : {"variable" : "{0}.source.name = \"{1}\""}}, 284 "variable" : None, 252 285 "children" : { 253 286 "radiation" : {"variable" : "{0}.source.radiation = \"{1}\""}, 254 287 "beam_size" : { 255 288 "attributes" : {"name" : {"variable" : "{0}.source.beam_size_name = \"{1}\""}}, 289 "variable" : None, 256 290 "children" : { 257 291 "x" : { … … 343 377 }, 344 378 "aperture" : { 379 "variable" : None, 345 380 "attributes" : { 346 381 "name" : {"variable" : "{0}.name = \"{1}\""}, … … 386 421 } 387 422 }, 388 "distance" : {"attributes" : {"unit" : {"variable" : "{0}.distance_unit = \"{1}\""}}, 423 "distance" : { 424 "storeas" : "float", 425 "attributes" : { 426 "storeas" : "content", 427 "unit" : {"variable" : "{0}.distance_unit = \"{1}\""}}, 389 428 "variable" : "{0}.distance = {1}", 390 "unit" : " length_unit",429 "unit" : "distance_unit", 391 430 } 392 431 } … … 419 458 }, 420 459 "offset" : { 460 "variable" : None, 421 461 "children" : { 422 462 "x" : { … … 453 493 }, 454 494 "orientation" : { 495 "variable" : None, 455 496 "children" : { 456 497 "roll" : { … … 481 522 }, 482 523 "beam_center" : { 524 "variable" : None, 483 525 "children" : { 484 526 "x" : { … … 509 551 }, 510 552 "pixel_size" : { 553 "variable" : None, 511 554 "children" : { 512 555 "x" : { … … 551 594 }, 552 595 "SASprocess" : { 553 "variable" : " ",596 "variable" : None, 554 597 "children" : { 555 "name" : {"variable" : "{0}.name = \ "{1}\""},556 "date" : {"variable" : "{0}.date = \ "{1}\""},557 "description" : {"variable" : "{0}.description = \ "{1}\""},598 "name" : {"variable" : "{0}.name = \'{1}\'"}, 599 "date" : {"variable" : "{0}.date = \'{1}\'"}, 600 "description" : {"variable" : "{0}.description = \'{1}\'"}, 558 601 "term" : { 559 602 "variable" : None, … … 563 606 } 564 607 }, 565 "SASprocessnote" : {"children" : {"<any>" : {"variable" : "{0}.notes.append(\"{2}: {1}\")"}}}, 566 "<any>" : {"variable" : "{0}.notes.append(\"{2}: {1}\")",} 608 "SASprocessnote" : { 609 "variable" : None, 610 "children" : {"<any>" : {"variable" : "{0}.notes.append(\'2}: {1}\')"}}}, 611 "<any>" : {"variable" : "{0}.notes.append(\'{2}: {1}\')",} 567 612 }, 568 613 }, 569 "SASnote" : {"variable" : "{0}.notes.append(\ "{1}\")"},570 "<any>" : {"variable" : "{0}.meta_data[\"{2}\" = \"{1}\""},614 "SASnote" : {"variable" : "{0}.notes.append(\'{1}\')"}, 615 "<any>" : {"variable" : "{0}.meta_data[\"{2}\"] = \'{1}\'"}, 571 616 } 572 617 } -
src/sans/dataloader/readers/cansas_reader.py
reda8972 r75eeb425 123 123 errors = [] 124 124 125 type_name = "canSAS" 126 127 ## Wildcards 128 type = ["XML files (*.xml)|*.xml"] 129 ## List of allowed extensions 130 ext = ['.xml', '.XML'] 131 132 ## Flag to bypass extension check 133 allow_all = True 134 125 135 def __init__(self): 126 136 ## List of errors … … 156 166 ns = [] 157 167 158 try: 159 # Load in the xml file and get the cansas version from the header 160 self.reader.setXMLFile(xml) 161 root = self.reader.xmlroot 162 self.cansasVersion = root.get("version") 163 # Generic values for the cansas file based on the version 164 cansas_defaults = CANSAS_NS.get(self.cansasVersion) 165 166 # Link a schema to the XML file. 168 # Check that the file exists 169 if os.path.isfile(xml): 167 170 basename = os.path.basename(xml) 168 base_name = xml_reader.__file__ 169 base = base_name.split("\\sans\\")[0] 170 schema_path = "{0}\\sans\\dataloader\\readers\\schema\\{1}".format(base, cansas_defaults.get("schema")).replace("\\", "/") 171 self.reader.setSchema(schema_path) 172 173 # Try to load the file, but raise an error if unable to. 174 # Check the file matches the XML schema 175 if self.isCansas(): 176 # Get each SASentry from the XML file and add it to a list. 177 entry_list = root.xpath('/ns:SASroot/ns:SASentry', 178 namespaces={'ns': cansas_defaults.get("ns")}) 179 ns.append("SASentry") 180 181 # If there are multiple files, modify the name for each is unique 182 multipleFiles = len(entry_list) - 1 183 n = 0 184 name = basename 185 # Parse each SASentry item 186 for entry in entry_list: 187 188 # Define a new Data1D object with zeroes for x and y 189 data1D = Data1D(x,y,dx,dy) 190 data1D.dxl = dxl 191 data1D.dxw = dxw 192 193 # If more than one SASentry, number each in order 194 if multipleFiles: 195 name += "_{0}".format(n) 196 n += 1 197 198 # Set the Data1D name and then parse the entry. The entry is appended to a list of entry values 199 data1D.filename = name 200 data1D.meta_data["loader"] = "CanSAS 1D" 201 return_value, extras = self._parse_entry(entry, ns, data1D) 202 del extras[:] 203 204 #Final cleanup - Remove empty nodes, verify array sizes are correct 205 return_value.errors = self.errors 206 del self.errors[:] 207 numpy.trim_zeros(return_value.x) 208 numpy.trim_zeros(return_value.y) 209 numpy.trim_zeros(return_value.dy) 210 size_dx = return_value.dx.size 211 size_dxl = return_value.dxl.size 212 size_dxw = return_value.dxw.size 213 if size_dxl == 0 and size_dxw == 0: 214 return_value.dxl = None 215 return_value.dxw = None 216 numpy.trim_zeros(return_value.dx) 217 elif size_dx == 0: 218 return_value.dx = None 219 size_dx = size_dxl 220 numpy.trim_zeros(return_value.dxl) 221 numpy.trim_zeros(return_value.dxw) 222 223 output.append(return_value) 224 else: 225 # If the file does not match the schema, raise this error 226 raise RuntimeError, "%s cannot be read \n" % xml 227 # If an exception occurs while loading the file, give a descriptive output. 228 except Exception: 229 raise RuntimeError, "%s cannot be read \n" % xml 171 _, extension = os.path.splitext(basename) 172 # If the fiel type is not allowed, return nothing 173 if extension in self.ext or self.allow_all: 174 base_name = xml_reader.__file__ 175 base = base_name.split("\\sans\\")[0] 176 177 # Load in the xml file and get the cansas version from the header 178 self.reader.setXMLFile(xml) 179 root = self.reader.xmlroot 180 if root is None: 181 root = {} 182 self.cansasVersion = root.get("version", "1.0") 183 184 # Generic values for the cansas file based on the version 185 cansas_defaults = CANSAS_NS.get(self.cansasVersion, "1.0") 186 schema_path = "{0}\\sans\\dataloader\\readers\\schema\\{1}".format(base, cansas_defaults.get("schema")).replace("\\", "/") 187 188 # Link a schema to the XML file. 189 self.reader.setSchema(schema_path) 230 190 191 # Try to load the file, but raise an error if unable to. 192 # Check the file matches the XML schema 193 try: 194 if self.isCansas(): 195 # Get each SASentry from the XML file and add it to a list. 196 entry_list = root.xpath('/ns:SASroot/ns:SASentry', 197 namespaces={'ns': cansas_defaults.get("ns")}) 198 ns.append("SASentry") 199 200 # If there are multiple files, modify the name for each is unique 201 multipleFiles = len(entry_list) - 1 202 n = 0 203 name = basename 204 # Parse each SASentry item 205 for entry in entry_list: 206 207 # Define a new Data1D object with zeroes for x and y 208 data1D = Data1D(x,y,dx,dy) 209 data1D.dxl = dxl 210 data1D.dxw = dxw 211 212 # If more than one SASentry, number each in order 213 if multipleFiles: 214 name += "_{0}".format(n) 215 n += 1 216 217 # Set the Data1D name and then parse the entry. The entry is appended to a list of entry values 218 data1D.filename = name 219 data1D.meta_data["loader"] = "CanSAS 1D" 220 return_value, extras = self._parse_entry(entry, ns, data1D) 221 del extras[:] 222 223 #Final cleanup - Remove empty nodes, verify array sizes are correct 224 for error in self.errors: 225 return_value.errors.append(error) 226 del self.errors[:] 227 numpy.trim_zeros(return_value.x) 228 numpy.trim_zeros(return_value.y) 229 numpy.trim_zeros(return_value.dy) 230 size_dx = return_value.dx.size 231 size_dxl = return_value.dxl.size 232 size_dxw = return_value.dxw.size 233 if size_dxl == 0 and size_dxw == 0: 234 return_value.dxl = None 235 return_value.dxw = None 236 numpy.trim_zeros(return_value.dx) 237 elif size_dx == 0: 238 return_value.dx = None 239 size_dx = size_dxl 240 numpy.trim_zeros(return_value.dxl) 241 numpy.trim_zeros(return_value.dxw) 242 243 output.append(return_value) 244 else: 245 value = self.reader.findInvalidXML() 246 output.append("Invalid XML at: {0}".format(value)) 247 except: 248 # If the file does not match the schema, raise this error 249 raise RuntimeError, "%s cannot be read \n" % xml 250 return output 231 251 # Return a list of parsed entries that dataloader can manage 232 return output252 return None 233 253 234 254 def _create_unique_key(self, dictionary, name, i): … … 264 284 def _unit_conversion(self, new_current_level, attr, data1D, node_value, optional = True): 265 285 value_unit = '' 266 if 'unit' in attr and 'unit' in new_current_level:286 if 'unit' in attr and new_current_level.get('unit') is not None: 267 287 try: 268 288 if isinstance(node_value, float) is False: … … 270 290 default_unit = None 271 291 unitname = new_current_level.get("unit") 272 exec "default_unit = data1D.{0}.lower()".format(unitname) 273 local_unit = attr['unit'].lower() 274 if local_unit != default_unit: 292 exec "default_unit = data1D.{0}".format(unitname) 293 local_unit = attr['unit'] 294 if local_unit.lower() != default_unit.lower() and local_unit is not None\ 295 and local_unit.lower() != "none" and default_unit is not None: 275 296 if HAS_CONVERTER == True: 276 297 try: … … 279 300 exec "node_value = data_conv_q(node_value, units=data1D.{0})".format(unitname) 280 301 except: 281 msg = "CanSAS reader: could not convert " 282 msg += "Q unit [%s]; " % attr['unit'], 283 exec "msg += \"expecting [%s]\n %s\" % (data1D.{0}, sys.exc_info()[1])".format(unitname) 284 raise ValueError, msg 302 err_msg = "CanSAS reader: could not convert " 303 err_msg += "Q unit {0}; ".format(local_unit) 304 intermediate = "err_msg += \"expecting [{1}] {2}\".format(data1D.{0}, sys.exc_info()[1])".format(unitname, "{0}", "{1}") 305 exec intermediate 306 self.errors.append(err_msg) 307 if optional: 308 logging.info(err_msg) 309 else: 310 raise ValueError, err_msg 285 311 else: 286 312 value_unit = local_unit 287 err_m ess= "CanSAS reader: unrecognized %s unit [%s];"\313 err_msg = "CanSAS reader: unrecognized %s unit [%s];"\ 288 314 % (node_value, default_unit) 289 err_m ess+= " expecting [%s]" % local_unit290 self.errors.append(err_m ess)315 err_msg += " expecting [%s]" % local_unit 316 self.errors.append(err_msg) 291 317 if optional: 292 logging.info(err_m ess)318 logging.info(err_msg) 293 319 else: 294 raise ValueError, err_mess 295 except Exception as e: 296 msg = "CanSAS reader: could not convert " 297 msg += "Q unit [%s]; " % attr['unit'], 298 exec "msg += \"expecting [%s]\n %s\" % (data1D.{0}, sys.exc_info()[1])".format(unitname) 299 self.errors.append(msg) 300 raise ValueError, msg 320 raise ValueError, err_msg 321 else: 322 value_unit = local_unit 323 except: 324 err_msg = "CanSAS reader: could not convert " 325 err_msg += "Q unit [%s]; " % attr['unit'], 326 exec "err_msg += \"expecting [%s]\n %s\" % (data1D.{0}, sys.exc_info()[1])".format(unitname) 327 self.errors.append(err_msg) 328 if optional: 329 logging.info(err_msg) 330 else: 331 raise ValueError, err_msg 301 332 elif 'unit' in attr: 302 333 value_unit = attr['unit'] … … 340 371 term_attr = {} 341 372 for attr in child.keys(): 342 term_attr[attr] = child.get(attr).strip()373 term_attr[attr] = ' '.join(child.get(attr).split()) 343 374 if child.text is not None: 344 term_attr['value'] = child.text.strip()345 375 term_attr['value'] = ' '.join(child.text.split()) 376 data1D.term.append(term_attr) 346 377 elif tagname == "aperture": 347 378 data1D = Aperture() … … 356 387 #Get the information from the node 357 388 node_value = node.text 358 if node_value is not None:359 node_value = node_value.strip().replace("\r"," ").replace("\n"," ")360 389 if node_value == "": 361 390 node_value = None 391 if node_value is not None: 392 node_value = ' '.join(node_value.split()) 362 393 363 394 # If the value is a float, compile with units. 364 395 if ns_datatype == "float": 365 396 # If an empty value is given, store as zero. 366 if node_value is None: 367 node_value = "0.0" 368 elif node_value.isspace(): 397 if node_value is None or node_value.isspace() or node_value.lower() == "nan": 369 398 node_value = "0.0" 370 399 node_value, unit = self._unit_conversion(new_current_level, attr, data1D, node_value, optional) … … 438 467 raise RuntimeError, "The cansas writer expects a Data1D instance" 439 468 469 ns = CANSAS_NS.get(self.cansasVersion).get("ns") 440 470 doc = xml.dom.minidom.Document() 441 471 main_node = doc.createElement("SASroot") 442 main_node.setAttribute(" cansasVersion", self.cansasVersion)443 main_node.setAttribute("xmlns", "cansas1d/%s" % self.cansasVersion)472 main_node.setAttribute("version", self.cansasVersion) 473 main_node.setAttribute("xmlns", ns) 444 474 main_node.setAttribute("xmlns:xsi", 445 475 "http://www.w3.org/2001/XMLSchema-instance") 446 476 main_node.setAttribute("xsi:schemaLocation", 447 " cansas1d/%s http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd" % self.cansasVersion)477 "{0} http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd".format(ns)) 448 478 449 479 doc.appendChild(main_node) … … 471 501 write_node(doc, pt, "I", datainfo.y[i], 472 502 {'unit': datainfo.y_unit}) 503 if datainfo.dy != None and len(datainfo.dy) >= i: 504 write_node(doc, pt, "Idev", datainfo.dy[i], 505 {'unit': datainfo.y_unit}) 473 506 if datainfo.dx != None and len(datainfo.dx) >= i: 474 507 write_node(doc, pt, "Qdev", datainfo.dx[i], 508 {'unit': datainfo.x_unit}) 509 if datainfo.dxw != None and len(datainfo.dxw) >= i: 510 write_node(doc, pt, "dQw", datainfo.dxw[i], 475 511 {'unit': datainfo.x_unit}) 476 512 if datainfo.dxl != None and len(datainfo.dxl) >= i: 477 513 write_node(doc, pt, "dQl", datainfo.dxl[i], 478 514 {'unit': datainfo.x_unit}) 479 if datainfo.dxw != None and len(datainfo.dxw) >= i: 480 write_node(doc, pt, "dQw", datainfo.dxw[i], 481 {'unit': datainfo.x_unit}) 482 if datainfo.dy != None and len(datainfo.dy) >= i: 483 write_node(doc, pt, "Idev", datainfo.dy[i], 484 {'unit': datainfo.y_unit}) 515 516 # Transmission Spectrum Info 517 if len(datainfo.trans_spectrum.wavelength) > 0: 518 node = doc.createElement("SAStransmission_spectrum") 519 entry_node.appendChild(node) 520 for i in range(len(datainfo.trans_spectrum.wavelength)): 521 pt = doc.createElement("Tdata") 522 node.appendChild(pt) 523 write_node(doc, pt, "Lambda", datainfo.trans_spectrum.wavelength[i], 524 {'unit': datainfo.trans_spectrum.wavelength_unit}) 525 write_node(doc, pt, "T", datainfo.trans_spectrum.transmission[i], 526 {'unit': datainfo.trans_spectrum.transmission_unit}) 527 if datainfo.trans_spectrum.transmission_deviation != None \ 528 and len(datainfo.trans_spectrum.transmission_deviation) >= i: 529 write_node(doc, pt, "Tdev", datainfo.trans_spectrum.transmission_deviation[i], 530 {'unit': datainfo.trans_spectrum.transmission_deviation_unit}) 485 531 486 532 # Sample info … … 495 541 write_node(doc, sample, "temperature", datainfo.sample.temperature, 496 542 {"unit": datainfo.sample.temperature_unit}) 497 498 for item in datainfo.sample.details:499 write_node(doc, sample, "details", item)500 543 501 544 pos = doc.createElement("position") … … 524 567 sample.appendChild(ori) 525 568 569 for item in datainfo.sample.details: 570 write_node(doc, sample, "details", item) 571 526 572 # Instrument info 527 573 instr = doc.createElement("SASinstrument") … … 535 581 source.setAttribute("name", str(datainfo.source.name)) 536 582 instr.appendChild(source) 537 538 583 write_node(doc, source, "radiation", datainfo.source.radiation) 539 write_node(doc, source, "beam_shape", datainfo.source.beam_shape)584 540 585 size = doc.createElement("beam_size") 541 586 if datainfo.source.beam_size_name is not None: … … 552 597 source.appendChild(size) 553 598 599 write_node(doc, source, "beam_shape", datainfo.source.beam_shape) 554 600 write_node(doc, source, "wavelength", 555 601 datainfo.source.wavelength, … … 583 629 coll.appendChild(ap) 584 630 585 write_node(doc, ap, "distance", apert.distance,586 {"unit": apert.distance_unit})587 588 631 size = doc.createElement("size") 589 632 if apert.size_name is not None: … … 597 640 if written == True: 598 641 ap.appendChild(size) 642 643 write_node(doc, ap, "distance", apert.distance, 644 {"unit": apert.distance_unit}) 599 645 600 646 # Detectors … … 604 650 written = written | write_node(doc, det, "SDD", item.distance, 605 651 {"unit": item.distance_unit}) 606 written = written | write_node(doc, det, "slit_length",607 item.slit_length,608 {"unit": item.slit_length_unit})609 652 if written == True: 610 653 instr.appendChild(det) … … 619 662 if written == True: 620 663 det.appendChild(off) 664 665 ori = doc.createElement("orientation") 666 written = write_node(doc, ori, "roll", item.orientation.x, 667 {"unit": item.orientation_unit}) 668 written = written | write_node(doc, ori, "pitch", 669 item.orientation.y, 670 {"unit": item.orientation_unit}) 671 written = written | write_node(doc, ori, "yaw", 672 item.orientation.z, 673 {"unit": item.orientation_unit}) 674 if written == True: 675 det.appendChild(ori) 621 676 622 677 center = doc.createElement("beam_center") … … 641 696 if written == True: 642 697 det.appendChild(pix) 643 644 ori = doc.createElement("orientation") 645 written = write_node(doc, ori, "roll", item.orientation.x, 646 {"unit": item.orientation_unit}) 647 written = written | write_node(doc, ori, "pitch", 648 item.orientation.y, 649 {"unit": item.orientation_unit}) 650 written = written | write_node(doc, ori, "yaw", 651 item.orientation.z, 652 {"unit": item.orientation_unit}) 653 if written == True: 654 det.appendChild(ori) 655 698 written = written | write_node(doc, det, "slit_length", 699 item.slit_length, 700 {"unit": item.slit_length_unit}) 701 656 702 # Processes info 657 703 for item in datainfo.process: … … 668 714 for note in item.notes: 669 715 write_node(doc, node, "SASprocessnote", note) 670 716 if len(item.notes) == 0: 717 write_node(doc, node, "SASprocessnote", "") 718 719 # Note info 720 if len(datainfo.notes) == 0: 721 node = doc.createElement("SASnote") 722 entry_node.appendChild(node) 723 if node.hasChildNodes(): 724 for child in node.childNodes: 725 node.removeChild(child) 726 else: 727 for item in datainfo.notes: 728 node = doc.createElement("SASnote") 729 entry_node.appendChild(node) 730 node.appendChild(doc.createTextNode(item)) 731 671 732 # Return the document, and the SASentry node associated with 672 733 # the data we just wrote
Note: See TracChangeset
for help on using the changeset viewer.