Changeset 75eeb425 in sasview
- 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
- Files:
-
- 4 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
.pydevproject
rf468791 r75eeb425 4 4 <pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property> 5 5 <pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH"> 6 <path>/ code/src</path>6 <path>/trunk/src</path> 7 7 </pydev_pathproperty> 8 8 </pydev_project> -
src/sans/dataloader/data_info.py
rffbe487 r75eeb425 401 401 return _str 402 402 403 class TransmissionSpectrum: 404 """ 405 Class that holds information about transmission spectrum 406 for white beams and spallation sources. 407 """ 408 name = '' 409 timestamp = '' 410 ## Wavelength (float) [A] 411 wavelength = None 412 wavelength_unit = 'A' 413 ## Transmission (float) [unit less] 414 transmission = None 415 transmission_unit = '' 416 ## Transmission Deviation (float) [unit less] 417 transmission_deviation = None 418 transmission_deviation_unit = '' 419 420 def __init__(self): 421 self.wavelength = [] 422 self.transmission = [] 423 self.transmission_deviation = [] 424 425 def __str__(self): 426 _str = "Transmission Spectrum:\n" 427 _str += " Name: {0}".format(self.name) 428 _str += " Timestamp: {1}".format(self.timestamp) 429 _str += " Wavelength [{0}] | Transmission [{1}] | Trans Dev [{2}]\n".format(self.wavelength_unit, self.transmission_unit, self.transmission_deviation_unit) 430 for i in range(len(self.wavelength)): 431 _str += " {0}, {1}".format(self.wavelength[i], self.transmission[i]) 432 if len(self.transmission_deviation > i): 433 _str += ", {0}".format(self.transmission_deviation[i]) 434 _str += "\n" 435 return _str 436 403 437 404 438 class DataInfo: … … 431 465 ## Collimation information 432 466 collimation = None 467 ## Transmission Spectrum INfo 468 trans_spectrum = None 433 469 ## Additional meta-data 434 470 meta_data = None … … 461 497 ## Collimation information 462 498 self.collimation = [] 499 ## Transmission Spectrum 500 self.trans_spectrum = TransmissionSpectrum() 463 501 ## Additional meta-data 464 502 self.meta_data = {} -
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 -
test/sansdataloader/test/cansas1d_units.xml
reda8972 r75eeb425 11 11 <SASdata> 12 12 <Idata> 13 <Q unit="1/nm">0. 002</Q>13 <Q unit="1/nm">0.2</Q> 14 14 <I unit="1/nm">0.0001</I> 15 15 <Idev unit="1/nm">.0000003</Idev> -
test/sansdataloader/test/test_log.txt
reda8972 r75eeb425 1 2013-12- 13 14:02:18,947DEBUG Inside testLoad module2 2013-12- 13 14:02:19,323INFO Danse_reader Reading MP_New.sans1 2013-12-20 15:51:09,931 DEBUG Inside testLoad module 2 2013-12-20 15:51:10,296 INFO Danse_reader Reading MP_New.sans 3 3 4 2013-12- 13 14:02:19,381INFO Danse_reader Reading P_New.sans4 2013-12-20 15:51:10,348 INFO Danse_reader Reading P_New.sans 5 5 -
test/sansdataloader/test/utest_abs_reader.py
reda8972 r75eeb425 159 159 160 160 def setUp(self): 161 self.data = Loader().load("cansas1d.xml") 162 if isinstance(self.data, list): 163 self.data = self.data[0] 161 data = Loader().load("cansas1d.xml") 162 self.data = data[0] 164 163 165 164 def test_cansas_checkdata(self): 166 print "\rtest_cansas_checkdata"167 165 self.assertEqual(self.data.filename, "cansas1d.xml") 168 166 self._checkdata() … … 212 210 213 211 self.assertEqual(self.data.sample.orientation_unit, 'degree') 214 self.assert Equal(self.data.sample.orientation.x, 22.5)215 self.assert Equal(self.data.sample.orientation.y, 0.02)212 self.assertAlmostEqual(self.data.sample.orientation.x, 22.5, 6) 213 self.assertAlmostEqual(self.data.sample.orientation.y, 0.02, 6) 216 214 217 215 self.assertEqual(self.data.sample.details[0], "http://chemtools.chem.soton.ac.uk/projects/blog/blogs.php/bit_id/2720") … … 250 248 self.assertEqual(item.size_unit,'mm') 251 249 self.assertEqual(item.distance_unit,'mm') 252 print "size.x = {0}".format(item.size.x)253 print "distance = {0}".format(item.distance)254 print "name = {0}".format(item.name)255 print "type = {0}".format(item.type)256 250 257 251 if item.size.x==50 \ … … 266 260 267 261 if _found1==False or _found2==False: 268 print item.distance269 262 raise RuntimeError, "Could not find all data %s %s" % (_found1, _found2) 270 263 … … 275 268 276 269 self.assertEqual(self.data.detector[0].orientation_unit, "degree") 277 self.assert Equal(self.data.detector[0].orientation.x, 1.0)270 self.assertAlmostEqual(self.data.detector[0].orientation.x, 1.0, 6) 278 271 self.assertEqual(self.data.detector[0].orientation.y, 0.0) 279 272 self.assertEqual(self.data.detector[0].orientation.z, 0.0) … … 318 311 319 312 def test_writer(self): 320 print "\rtest_writer"321 313 from sans.dataloader.readers.cansas_reader import Reader 322 314 r = Reader() … … 327 319 filename = "write_test.xml" 328 320 r.write(filename, self.data) 329 self.data = Loader().load(filename)[0] 321 data = Loader().load(filename) 322 self.data = data[0] 330 323 self.assertEqual(self.data.filename, filename) 331 324 self._checkdata() … … 336 329 Note that not all units are available. 337 330 """ 338 print "\rtest_units"339 331 filename = "cansas1d_units.xml" 340 self.data = Loader().load(filename) 341 if isinstance(self.data, list): 342 self.data = self.data[0] 332 data = Loader().load(filename) 333 self.data = data[0] 343 334 self.assertEqual(self.data.filename, filename) 344 335 self._checkdata() … … 349 340 Note that not all units are available. 350 341 """ 351 print "\rtest_badunits"352 342 filename = "cansas1d_badunits.xml" 353 self.data = Loader().load(filename) 354 if isinstance(self.data, list): 355 self.data = self.data[0] 343 data = Loader().load(filename) 344 self.data = data[0] 356 345 self.assertEqual(self.data.filename, filename) 357 346 # The followed should not have been loaded … … 368 357 Check slit data 369 358 """ 370 print "\rtest_slits"371 359 filename = "cansas1d_slit.xml" 372 self.data = Loader().load(filename) 373 if isinstance(self.data, list): 374 self.data = self.data[0] 360 data = Loader().load(filename) 361 self.data = data[0] 375 362 self.assertEqual(self.data.filename, filename) 376 363 self.assertEqual(self.data.run[0], "1234") … … 378 365 # Data 379 366 self.assertEqual(len(self.data.x), 2) 380 print self.data.x381 367 self.assertEqual(self.data.x_unit, '1/A') 382 368 self.assertEqual(self.data.y_unit, '1/cm') … … 392 378 self.assertEqual(self.data.dxw[1], 0.001) 393 379 self.assertEqual(self.data.dy[1], 4) 394 #self.assertEqual(self.data.run_name['1234'], 'run name')380 self.assertEqual(self.data.run_name['1234'], 'run name') 395 381 self.assertEqual(self.data.title, "Test title") 396 382 397 383 398 384 -
test/sansdataloader/test/utest_cansas.py
reda8972 r75eeb425 21 21 from lxml import etree 22 22 import xml.dom.minidom 23 _ZERO = 1e-1624 HAS_CONVERTER = True25 try:26 from data_util.nxsunit import Converter27 except:28 HAS_CONVERTER = False29 23 30 24 CANSAS_FORMAT = cansasConstants.CANSAS_FORMAT 31 25 CANSAS_NS = cansasConstants.CANSAS_NS 32 ALLOW_ALL = True33 26 34 27 class cansas_reader(unittest.TestCase): … … 48 41 self.schema_1_0 = "cansas1d_v1_0.xsd" 49 42 self.schema_1_1 = "cansas1d_v1_1.xsd" 43 50 44 51 45 def get_number_of_entries(self, dictionary, name, i): … … 56 50 name = self.get_number_of_entries(dictionary, name, i) 57 51 return name 52 58 53 59 54 def test_xml_validate(self): … … 74 69 self.assertFalse(xmlschema.validate(invalid)) 75 70 71 76 72 def test_real_xml(self): 77 73 reader = XMLreader(self.xml_valid, self.schema_1_0) … … 81 77 else: 82 78 self.assertFalse(valid) 79 83 80 84 81 def test_cansas_xml(self): 82 filename = "isis_1_1_write_test.xml" 85 83 xmlreader = XMLreader(self.isis_1_1, self.schema_1_1) 86 84 valid = xmlreader.validateXML() … … 91 89 self.assertTrue(data.title == "TK49 c10_SANS") 92 90 self.assertTrue(data.x.size == 138) 93 self.assertTrue(len(data.meta_data) == 417)91 self.assertTrue(len(data.meta_data) == 2) 94 92 self.assertTrue(data.detector[0].distance_unit == "mm") 93 reader.write(filename, data) 94 reader2 = Reader() 95 return_data = reader2.read(filename) 96 data_new = return_data 97 self.data = return_data[0] 98 self.assertTrue(self.data.x.size == 138) 99 self.assertTrue(len(self.data.meta_data) == 2) 100 self.assertTrue(self.data.detector[0].distance_unit == "mm") 101 self.assertTrue(self.data.title == "TK49 c10_SANS") 95 102 96 103 def test_entry_name_recurse(self): … … 102 109 d[new_key] = value 103 110 self.assertTrue(len(d) == 6) 111 104 112 105 113 def test_load_cansas_file(self): … … 119 127 reader7 = XMLreader(self.isis_1_1, self.schema_1_0) 120 128 self.assertFalse(reader7.validateXML()) 129 121 130 122 131 def test_old_cansas_files(self): -
test/sansdataloader/test/write_test.xml
reda8972 r75eeb425 16 16 1000.0 17 17 </I> 18 19 20 18 <Idev unit="1/cm"> 19 3.0 20 </Idev> 21 21 <Qdev unit="1/A"> 22 22 0.01 … … 30 30 1001.0 31 31 </I> 32 33 34 32 <Idev unit="1/cm"> 33 4.0 34 </Idev> 35 35 <Qdev unit="1/A"> 36 36 0.02 … … 51 51 0.0 52 52 </temperature> 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 53 <position> 54 <x unit="mm"> 55 10.0 56 </x> 57 <y unit="mm"> 58 0.0 59 </y> 60 </position> 61 <orientation> 62 <roll unit="degree"> 63 22.5 64 </roll> 65 <pitch unit="degree"> 66 0.02 67 </pitch> 68 </orientation> 69 69 <details> 70 70 http://chemtools.chem.soton.ac.uk/projects/blog/blogs.php/bit_id/2720 … … 82 82 neutron 83 83 </radiation> 84 85 86 87 88 89 90 91 84 <beam_size name="bm"> 85 <x unit="mm"> 86 12.0 87 </x> 88 <y unit="mm"> 89 13.0 90 </y> 91 </beam_size> 92 92 <beam_shape> 93 93 disc … … 117 117 </size> 118 118 <distance unit="mm"> 119 11000120 119 11000.0 120 </distance> 121 121 </aperture> 122 122 <aperture name="sample" type="radius"> 123 <size name="size name">123 <size> 124 124 <x unit="mm"> 125 125 1.0 … … 133 133 </name> 134 134 <SDD unit="mm"> 135 4150 135 4150.0 136 136 </SDD> 137 137 <offset> … … 143 143 </y> 144 144 </offset> 145 146 147 148 149 150 151 152 153 154 155 145 <orientation> 146 <roll unit="degree"> 147 1.0 148 </roll> 149 <pitch unit="degree"> 150 0.0 151 </pitch> 152 <yaw unit="degree"> 153 0.0 154 </yaw> 155 </orientation> 156 156 <beam_center> 157 157 <x unit="mm"> … … 195 195 </term> 196 196 <SASprocessnote> 197 AvA1 0.0000E+00 AsA2 1.0000E+00 XvA3 1.0526E+03 XsA4 198 5.2200E-02 XfA5 0.0000E+00 199 </SASprocessnote> 200 <SASprocessnote> 201 S... 13597 0 2.26E+02 2A 5mM 0%D2O Sbak 13594 0 1.13E+02 202 H2O Buffer 203 </SASprocessnote> 204 <SASprocessnote> 205 V... 13552 3 1.00E+00 H2O5m 197 206 198 </SASprocessnote> 207 199 </SASprocess> … … 246 238 1 247 239 </term> 248 <SASProcessnote /> 240 <SASprocessnote> 241 242 </SASprocessnote> 249 243 </SASprocess> 250 <SASnote 244 <SASnote/> 251 245 </SASentry> 252 246 </SASroot> -
test/sansguiframe/test/cansas1d.xml
r5777106 r75eeb425 49 49 50 50 </SASsample> 51 <SASinstrument name="TEST instrument">51 <SASinstrument> 52 52 <name>canSAS instrument</name> 53 53 <SASsource name="source name"> … … 85 85 4.150 86 86 </SDD> 87 <orientation> 87 <offset> 88 <x unit="mm">1</x> 89 <y unit="mm">2</y> 90 </offset> 91 <orientation> 88 92 <roll unit="degree">1.00</roll> 89 93 <pitch unit="degree">0.00</pitch> 90 94 <yaw unit="degree">0.00</yaw> 91 95 </orientation> 92 <offset>93 <x unit="mm">1</x>94 <y unit="mm">2</y>95 </offset>96 96 <beam_center> 97 97 <x unit="mm">322.64</x> … … 135 135 <term name="ABS:IZERO">230.09</term> 136 136 <term name="ABS:XSECT" unit="mm">1</term> 137 <SASprocessnote />137 <SASprocessnote>No Information</SASprocessnote> 138 138 </SASprocess> 139 139 <SASnote /> -
test/sansguiframe/test/utest_manipulations.py
r5777106 r75eeb425 15 15 16 16 def setUp(self): 17 self.data = Loader().load("cansas1d.xml") 17 data = Loader().load("cansas1d.xml") 18 self.data = data[0] 18 19 19 20 def test_clone1D(self): … … 29 30 30 31 def setUp(self): 31 self.data = Loader().load("cansas1d.xml") 32 data = Loader().load("cansas1d.xml") 33 self.data = data[0] 32 34 33 35 def test_clone_theory1D(self): -
test/sansinvariant/test/utest_data_handling.py
r5777106 r75eeb425 92 92 """ 93 93 def setUp(self): 94 self.data = Loader().load("latex_smeared_slit.xml") 94 data = Loader().load("latex_smeared_slit.xml") 95 self.data = data[0] 95 96 self.data.dxl = None 96 97 -
test/sansmodels/test/cansas1d_slit.xml
r5777106 r75eeb425 14 14 <I unit="1/cm">1000</I> 15 15 <Idev unit="1/cm">3</Idev> 16 <dQw unit="1/A">0.001</dQw> 16 17 <dQl unit="1/A">0.005</dQl> 17 <dQw unit="1/A">0.001</dQw> 18 <Shadowfactor><!-- Shadowfactor is optional --></Shadowfactor> 18 <Shadowfactor><!-- Shadowfactor is optional --></Shadowfactor> 19 19 </Idata> 20 20 <Idata> … … 22 22 <I unit="1/cm">1001</I> 23 23 <Idev unit="1/cm">4</Idev> 24 <dQw unit="1/A">0.001</dQw> 24 25 <dQl unit="1/A">0.005</dQl> 25 <dQw unit="1/A">0.001</dQw> 26 <Shadowfactor><!-- Shadowfactor is optional --></Shadowfactor> 26 <Shadowfactor><!-- Shadowfactor is optional --></Shadowfactor> 27 27 </Idata> 28 28 </SASdata> … … 49 49 50 50 </SASsample> 51 <SASinstrument name="TEST instrument">51 <SASinstrument> 52 52 <name>canSAS instrument</name> 53 53 <SASsource name="source name"> … … 85 85 4.150 86 86 </SDD> 87 <orientation> 87 <offset> 88 <x unit="mm">1</x> 89 <y unit="mm">2</y> 90 </offset> 91 <orientation> 88 92 <roll unit="degree">1.00</roll> 89 93 <pitch unit="degree">0.00</pitch> 90 94 <yaw unit="degree">0.00</yaw> 91 95 </orientation> 92 <offset>93 <x unit="mm">1</x>94 <y unit="mm">2</y>95 </offset>96 96 <beam_center> 97 97 <x unit="mm">322.64</x> -
test/sansmodels/test/utest_smearing.py
r5777106 r75eeb425 16 16 17 17 def setUp(self): 18 self.data = Loader().load("cansas1d_slit.xml") 18 data = Loader().load("cansas1d_slit.xml") 19 self.data = data[0] 19 20 20 21 x = 0.001*numpy.arange(1,11)
Note: See TracChangeset
for help on using the changeset viewer.