Changeset 4c00964 in sasview
- Timestamp:
- Aug 28, 2008 4:53:26 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:
- 579ba85
- Parents:
- 3c404d3
- Location:
- DataLoader
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/data_info.py
rd6513cd r4c00964 147 147 148 148 class Aperture: 149 # Aperture size [Vector] 149 ## Name 150 name = '' 151 ## Type 152 type = '' 153 ## Aperture size [Vector] 150 154 size = None 151 155 size_unit = 'mm' 152 # Aperture distance [float]156 ## Aperture distance [float] 153 157 distance = None 154 158 distance_unit = 'mm' … … 161 165 Class to hold collimation information 162 166 """ 163 167 ## Name 168 name = '' 164 169 ## Length [float] [mm] 165 170 length = None … … 186 191 Class to hold source information 187 192 """ 193 ## Name 194 name = '' 188 195 ## Radiation type [string] 189 196 radiation = '' -
DataLoader/readers/cansas_reader.py
rd6513cd r4c00964 10 10 11 11 #TODO: Unit conversion 12 #TODO: missing aperture type: go through all entries and check for additional attributes 13 #TODO: check that all vectors are written only if they have at least one non-empty value 14 #TODO: multiple SASEntrys 12 15 #TODO: Store error list 13 16 #TODO: convert from pixel to mm for beam center... … … 22 25 from DataLoader.data_info import Data1D, Collimation, Detector, Process, Aperture 23 26 from xml import xpath 27 import xml.dom.minidom 28 24 29 25 30 has_converter = True … … 28 33 except: 29 34 has_converter = False 35 36 def write_node(doc, parent, name, value, attr={}): 37 """ 38 @param doc: document DOM 39 @param parent: parent node 40 @param name: tag of the element 41 @param value: value of the child text node 42 @param attr: attribute dictionary 43 @return: True if something was appended, otherwise False 44 """ 45 if value is not None: 46 node = doc.createElement(name) 47 node.appendChild(doc.createTextNode(str(value))) 48 for item in attr: 49 node.setAttribute(item, attr[item]) 50 parent.appendChild(node) 51 return True 52 return False 30 53 31 54 def get_node_text(node): … … 287 310 288 311 # Source info ################### 312 value, attr = get_content('SASinstrument/SASsource', dom) 313 if attr.has_key('name'): 314 data_info.source.name = attr['name'] 315 289 316 _store_content('SASinstrument/SASsource/radiation', 290 317 dom, 'radiation', data_info.source) … … 312 339 for item in nodes: 313 340 collim = Collimation() 341 value, attr = get_node_text(item) 342 if attr.has_key('name'): 343 collim.name = attr['name'] 314 344 _store_float('length', item, 'length', collim) 315 345 … … 318 348 for apert in apert_list: 319 349 aperture = Aperture() 350 351 # Get the name and type of the aperture 352 ap_value, ap_attr = get_node_text(item) 353 if ap_attr.has_key('name'): 354 aperture.name = ap_attr['name'] 355 if ap_attr.has_key('type'): 356 aperture.type = ap_attr['type'] 357 320 358 _store_float('distance', apert, 'distance', aperture) 321 359 _store_float('size/x', apert, 'size.x', aperture) … … 451 489 return data_info 452 490 453 491 def write(self, filename, datainfo): 492 """ 493 Write the content of a Data1D as a CanSAS XML file 494 495 @param filename: name of the file to write 496 @param datainfo: Data1D object 497 """ 498 499 if not datainfo.__class__ == Data1D: 500 raise RuntimeError, "The cansas writer expects a Data1D instance" 501 502 doc = xml.dom.minidom.Document() 503 main_node = doc.createElement("SASroot") 504 main_node.setAttribute("version", "1.0") 505 doc.appendChild(main_node) 506 507 entry_node = doc.createElement("SASentry") 508 main_node.appendChild(entry_node) 509 510 write_node(doc, entry_node, "title", datainfo.title) 511 write_node(doc, entry_node, "run", datainfo.run) 512 513 # Data info 514 node = doc.createElement("SASdata") 515 entry_node.appendChild(node) 516 517 # Sample info 518 sample = doc.createElement("SASsample") 519 entry_node.appendChild(sample) 520 write_node(doc, sample, "ID", datainfo.sample.ID) 521 write_node(doc, sample, "thickness", datainfo.sample.thickness, {"unit":datainfo.sample.thickness_unit}) 522 write_node(doc, sample, "transmission", datainfo.sample.transmission) 523 write_node(doc, sample, "temperature", datainfo.sample.temperature, {"unit":datainfo.sample.temperature_unit}) 524 525 for item in datainfo.sample.details: 526 write_node(doc, sample, "details", item) 527 528 pos = doc.createElement("position") 529 written = False 530 written = written or write_node(doc, pos, "x", datainfo.sample.position.x, {"unit":datainfo.sample.position_unit}) 531 written = written or write_node(doc, pos, "y", datainfo.sample.position.y, {"unit":datainfo.sample.position_unit}) 532 written = written or write_node(doc, pos, "z", datainfo.sample.position.z, {"unit":datainfo.sample.position_unit}) 533 if written == True: 534 sample.appendChild(pos) 535 536 ori = doc.createElement("orientation") 537 written = False 538 written = written or write_node(doc, ori, "roll", datainfo.sample.orientation.x, {"unit":datainfo.sample.orientation_unit}) 539 written = written or write_node(doc, ori, "pitch", datainfo.sample.orientation.y, {"unit":datainfo.sample.orientation_unit}) 540 written = written or write_node(doc, ori, "yaw", datainfo.sample.orientation.z, {"unit":datainfo.sample.orientation_unit}) 541 if written == True: 542 sample.appendChild(ori) 543 544 # Instrument info 545 instr = doc.createElement("SASinstrument") 546 entry_node.appendChild(instr) 547 548 write_node(doc, instr, "name", datainfo.instrument) 549 550 # Source 551 source = doc.createElement("SASsource") 552 source.setAttribute("name", str(datainfo.source.name)) 553 instr.appendChild(source) 554 555 write_node(doc, source, "radiation", datainfo.source.radiation) 556 write_node(doc, source, "beam_shape", datainfo.source.beam_shape) 557 write_node(doc, source, "wavelength", datainfo.source.wavelength, {"unit":datainfo.source.wavelength_unit}) 558 write_node(doc, source, "wavelength_min", datainfo.source.wavelength_min, {"unit":datainfo.source.wavelength_min_unit}) 559 write_node(doc, source, "wavelength_max", datainfo.source.wavelength_max, {"unit":datainfo.source.wavelength_max_unit}) 560 write_node(doc, source, "wavelength_spread", datainfo.source.wavelength_spread, {"unit":datainfo.source.wavelength_spread_unit}) 561 562 # Collimation 563 for item in datainfo.collimation: 564 coll = doc.createElement("SAScollimation") 565 coll.setAttribute("name", item.name) 566 instr.appendChild(coll) 567 568 write_node(doc, coll, "length", item.length, {"unit":item.length_unit}) 569 570 for apert in item.aperture: 571 ap = doc.createElement("SAScollimation") 572 ap.setAttribute("name", apert.name) 573 ap.setAttribute("type", apert.type) 574 instr.appendChild(ap) 575 576 write_node(doc, ap, "distance", apert.distance, {"unit":apert.distance_unit}) 577 578 size = doc.createElement("size") 579 ap.appendChild(size) 580 write_node(doc, size, "x", apert.size.x, {"unit":apert.size_unit}) 581 write_node(doc, size, "y", apert.size.y, {"unit":apert.size_unit}) 582 write_node(doc, size, "z", apert.size.z, {"unit":apert.size_unit}) 583 584 585 # Detectors 586 for item in datainfo.detector: 587 det = doc.createElement("SASdetector") 588 instr.appendChild(det) 589 590 write_node(doc, det, "name", item.name) 591 write_node(doc, det, "SDD", item.distance, {"unit":item.distance_unit}) 592 write_node(doc, det, "slit_length", item.slit_length, {"unit":item.slit_length_unit}) 593 594 off = doc.createElement("offset") 595 det.appendChild(off) 596 write_node(doc, off, "x", item.offset.x, {"unit":item.offset_unit}) 597 write_node(doc, off, "y", item.offset.y, {"unit":item.offset_unit}) 598 write_node(doc, off, "z", item.offset.z, {"unit":item.offset_unit}) 599 600 601 center = doc.createElement("beam_center") 602 det.appendChild(center) 603 write_node(doc, center, "x", item.beam_center.x, {"unit":item.beam_center_unit}) 604 write_node(doc, center, "y", item.beam_center.y, {"unit":item.beam_center_unit}) 605 write_node(doc, center, "z", item.beam_center.z, {"unit":item.beam_center_unit}) 606 607 pix = doc.createElement("pixel_size") 608 det.appendChild(pix) 609 write_node(doc, pix, "x", item.pixel_size.x, {"unit":item.pixel_size_unit}) 610 write_node(doc, pix, "y", item.pixel_size.y, {"unit":item.pixel_size_unit}) 611 write_node(doc, pix, "z", item.pixel_size.z, {"unit":item.pixel_size_unit}) 612 613 614 # Sample info 615 for item in datainfo.process: 616 node = doc.createElement("SASprocess") 617 entry_node.appendChild(node) 618 619 write_node(doc, entry_node, "run", item.name) 620 621 622 # Write the file 623 fd = open(filename, 'w') 624 fd.write(doc.toprettyxml()) 625 fd.close() 626 627 454 628 if __name__ == "__main__": 455 629 logging.basicConfig(level=logging.ERROR, -
DataLoader/release_notes.txt
r9198b83 r4c00964 20 20 * numpy 21 21 * data_util from svn://danse.us/common/releases/data_util-0.1 22 22 * The CanSAS reader needs PyXML installed 23 23 24 3- Known Issues 24 25 -
DataLoader/test/cansas1d.xml
rd6513cd r4c00964 51 51 <SASinstrument name="TEST instrument"> 52 52 <name>canSAS instrument</name> 53 <SASsource >53 <SASsource name="source name"> 54 54 <radiation>neutron</radiation> 55 55 <beam_size> … … 65 65 </wavelength_spread> 66 66 </SASsource> 67 <SAScollimation >67 <SAScollimation name="test coll name"> 68 68 <length unit='mm'> 123.0</length> 69 69 <aperture name="source" type="radius"> … … 90 90 <yaw unit="degree">0.00</yaw> 91 91 </orientation> 92 <offset> 93 <x unit="mm">1</x> 94 <y unit="mm">2</y> 95 </offset> 92 96 <beam_center> 93 97 <x unit="mm">322.64</x> -
DataLoader/test/testplugings.py
r16d8e5f r4c00964 50 50 self.assertEqual(output.x[i],x[i]) 51 51 self.assertEqual(output.y[i],y[i]) 52 53 # How about actually executing the tests... 54 if __name__ == '__main__': 55 unittest.main() -
DataLoader/test/utest_abs_reader.py
rd6513cd r4c00964 207 207 raise RuntimeError, "Could not find all data %s %s" % (_found1, _found2) 208 208 209 # Detector 210 self.assertEqual(self.data.detector[0].name, "fictional hybrid") 211 self.assertEqual(self.data.detector[0].distance_unit, "m") 212 self.assertEqual(self.data.detector[0].distance, 4.150) 213 214 self.assertEqual(self.data.detector[0].orientation_unit, "degree") 215 self.assertEqual(self.data.detector[0].orientation.x, 1.0) 216 self.assertEqual(self.data.detector[0].orientation.y, 0.0) 217 self.assertEqual(self.data.detector[0].orientation.z, 0.0) 218 219 self.assertEqual(self.data.detector[0].offset_unit, "m") 220 self.assertEqual(self.data.detector[0].offset.x, .01) 221 self.assertEqual(self.data.detector[0].offset.y, .02) 222 self.assertEqual(self.data.detector[0].offset.z, None) 223 224 self.assertEqual(self.data.detector[0].beam_center_unit, "mm") 225 self.assertEqual(self.data.detector[0].beam_center.x, 322.64) 226 self.assertEqual(self.data.detector[0].beam_center.y, 327.68) 227 self.assertEqual(self.data.detector[0].beam_center.z, None) 228 229 self.assertEqual(self.data.detector[0].pixel_size_unit, "mm") 230 self.assertEqual(self.data.detector[0].pixel_size.x, 5) 231 self.assertEqual(self.data.detector[0].pixel_size.y, 5) 232 self.assertEqual(self.data.detector[0].pixel_size.z, None) 233 234 # Process 235 236 237 238 def test_writer(self): 239 from DataLoader.readers.cansas_reader import Reader 240 r = Reader() 241 x = numpy.ones(5) 242 y = numpy.ones(5) 243 dy = numpy.ones(5) 244 245 d = Loader().load("jan08002.ABS") 246 #d = Data1D(x, y, dy) 247 r.write("write_test.xml", d) 248 249 209 250 210 251
Note: See TracChangeset
for help on using the changeset viewer.