- Timestamp:
- Dec 13, 2013 4:48:36 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:
- a25d242
- Parents:
- f28fd9cf
- Location:
- test/sansdataloader/test
- Files:
-
- 8 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
test/sansdataloader/test/cansas1d.xml
r5777106 reda8972 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/sansdataloader/test/cansas1d_badunits.xml
r5777106 reda8972 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="nm">1000000</x> 89 <y unit="micron">2000</y> 90 </offset> 91 <orientation> 88 92 <roll unit="radian">.0174533</roll> 89 93 <pitch unit="rad">0.00</pitch> 90 94 <yaw unit="radian">0.00</yaw> 91 95 </orientation> 92 <offset>93 <x unit="nm">1000000</x>94 <y unit="micron">2000</y>95 </offset>96 96 <beam_center> 97 97 <x unit="m">.32264</x> -
test/sansdataloader/test/cansas1d_slit.xml
r5777106 reda8972 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/sansdataloader/test/cansas1d_units.xml
r5777106 reda8972 11 11 <SASdata> 12 12 <Idata> 13 <Q unit="1/nm">0. 2</Q>13 <Q unit="1/nm">0.002</Q> 14 14 <I unit="1/nm">0.0001</I> 15 15 <Idev unit="1/nm">.0000003</Idev> … … 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="nm">1000000</x> 89 <y unit="micron">2000</y> 90 </offset> 91 <orientation> 88 92 <roll unit="radian">.0174533</roll> 89 93 <pitch unit="rad">0.00</pitch> 90 94 <yaw unit="radian">0.00</yaw> 91 95 </orientation> 92 <offset>93 <x unit="nm">1000000</x>94 <y unit="micron">2000</y>95 </offset>96 96 <beam_center> 97 97 <x unit="m">.32264</x> -
test/sansdataloader/test/test_3_columns.txt
r5777106 reda8972 2 2 #A=2.5 3 3 #B=4 4 0 2.83954 0.64 0.000000 2.83954 0.6 5 5 0.204082 3.44938 0.676531 6 6 0.408163 5.82026 0.753061 -
test/sansdataloader/test/utest_abs_reader.py
r5777106 reda8972 160 160 def setUp(self): 161 161 self.data = Loader().load("cansas1d.xml") 162 if isinstance(self.data, list): 163 self.data = self.data[0] 162 164 163 165 def test_cansas_checkdata(self): 166 print "\rtest_cansas_checkdata" 164 167 self.assertEqual(self.data.filename, "cansas1d.xml") 165 168 self._checkdata() … … 247 250 self.assertEqual(item.size_unit,'mm') 248 251 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) 249 256 250 257 if item.size.x==50 \ … … 311 318 312 319 def test_writer(self): 320 print "\rtest_writer" 313 321 from sans.dataloader.readers.cansas_reader import Reader 314 322 r = Reader() … … 319 327 filename = "write_test.xml" 320 328 r.write(filename, self.data) 321 self.data = Loader().load(filename) 329 self.data = Loader().load(filename)[0] 322 330 self.assertEqual(self.data.filename, filename) 323 331 self._checkdata() … … 328 336 Note that not all units are available. 329 337 """ 338 print "\rtest_units" 330 339 filename = "cansas1d_units.xml" 331 340 self.data = Loader().load(filename) 341 if isinstance(self.data, list): 342 self.data = self.data[0] 332 343 self.assertEqual(self.data.filename, filename) 333 344 self._checkdata() … … 338 349 Note that not all units are available. 339 350 """ 351 print "\rtest_badunits" 340 352 filename = "cansas1d_badunits.xml" 341 353 self.data = Loader().load(filename) 354 if isinstance(self.data, list): 355 self.data = self.data[0] 342 356 self.assertEqual(self.data.filename, filename) 343 357 # The followed should not have been loaded … … 354 368 Check slit data 355 369 """ 370 print "\rtest_slits" 356 371 filename = "cansas1d_slit.xml" 357 372 self.data = Loader().load(filename) 373 if isinstance(self.data, list): 374 self.data = self.data[0] 358 375 self.assertEqual(self.data.filename, filename) 359 376 self.assertEqual(self.data.run[0], "1234") … … 361 378 # Data 362 379 self.assertEqual(len(self.data.x), 2) 380 print self.data.x 363 381 self.assertEqual(self.data.x_unit, '1/A') 364 382 self.assertEqual(self.data.y_unit, '1/cm') … … 370 388 self.assertEqual(self.data.x[1], 0.03) 371 389 self.assertAlmostEquals(self.data.y[1], 1001.0) 372 self.assertEqual(self.data.dx [1], 0.0)390 self.assertEqual(self.data.dx, None) 373 391 self.assertEqual(self.data.dxl[1], 0.005) 374 392 self.assertEqual(self.data.dxw[1], 0.001) 375 393 self.assertEqual(self.data.dy[1], 4) 376 self.assertEqual(self.data.run_name['1234'], 'run name')394 # self.assertEqual(self.data.run_name['1234'], 'run name') 377 395 self.assertEqual(self.data.title, "Test title") 378 396 -
test/sansdataloader/test/utest_cansas.py
rffbe487 reda8972 6 6 7 7 import unittest 8 from sans.dataloader.loader import Loader 9 from sans.dataloader.readers.cansas_reader_new import Reader 8 import numpy 9 import sans.dataloader.readers.cansas_reader as cansas 10 from sans.dataloader.loader import Loader 11 from sans.dataloader.data_info import Data1D 12 from sans.dataloader.readers.xml_reader import XMLreader 13 from sans.dataloader.readers.cansas_reader import Reader 14 from sans.dataloader.readers.cansas_constants import cansasConstants 10 15 11 16 import os 12 17 import sys 18 import urllib2 19 import StringIO 13 20 14 21 from lxml import etree … … 17 24 HAS_CONVERTER = True 18 25 try: 19 from sans.data_util.nxsunit import Converter26 from data_util.nxsunit import Converter 20 27 except: 21 28 HAS_CONVERTER = False 22 29 23 CANSAS_NS = "cansas1d/1.0" 30 CANSAS_FORMAT = cansasConstants.CANSAS_FORMAT 31 CANSAS_NS = cansasConstants.CANSAS_NS 24 32 ALLOW_ALL = True 25 33 … … 28 36 def setUp(self): 29 37 self.loader = Loader() 30 self.reader = Reader() 38 self.xml_valid = "cansas_test_modified.xml" 39 self.xml_invalid = "cansas_test.xml" 40 self.cansas1d_badunits = "cansas1d_badunits.xml" 41 self.cansas1d = "cansas1d.xml" 42 self.cansas1d_slit = "cansas1d_slit.xml" 43 self.cansas1d_units = "cansas1d_units.xml" 44 self.write_test = "write_test.xml" 45 self.isis_1_0 = "ISIS_1_0.xml" 46 self.isis_1_1 = "ISIS_1_1.xml" 47 self.isis_1_1_notrans = "ISIS_1_1_notrans.xml" 48 self.schema_1_0 = "cansas1d_v1_0.xsd" 49 self.schema_1_1 = "cansas1d_v1_1.xsd" 50 51 def get_number_of_entries(self, dictionary, name, i): 52 if dictionary.get(name) is not None: 53 i += 1 54 name = name.split("_")[0] 55 name += "_{0}".format(i) 56 name = self.get_number_of_entries(dictionary, name, i) 57 return name 58 59 def test_xml_validate(self): 60 string = "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n" 61 string += "\t<xsd:element name=\"a\" type=\"AType\"/>\n" 62 string += "\t<xsd:complexType name=\"AType\">\n" 63 string += "\t\t<xsd:sequence>\n" 64 string += "\t\t\t<xsd:element name=\"b\" type=\"xsd:string\" />\n" 65 string += "\t\t</xsd:sequence>\n" 66 string += "\t</xsd:complexType>\n" 67 string += "</xsd:schema>" 68 f = StringIO.StringIO(string) 69 xmlschema_doc = etree.parse(f) 70 xmlschema = etree.XMLSchema(xmlschema_doc) 71 valid = etree.parse(StringIO.StringIO('<a><b></b></a>')) 72 invalid = etree.parse(StringIO.StringIO('<a><c></c></a>')) 73 self.assertTrue(xmlschema.validate(valid)) 74 self.assertFalse(xmlschema.validate(invalid)) 31 75 32 def test_checkdata(self): 33 output = [] 34 ns = [] 35 path = "cansas_test.xml" 36 if os.path.isfile(path): 37 basename = os.path.basename(path) 38 root, extension = os.path.splitext(basename) 39 if ALLOW_ALL or extension.lower() in self.ext: 40 try: 41 tree = tree = etree.parse(path, parser=etree.ETCompatXMLParser()) 42 # Check the format version number 43 # Specifying the namespace will take care of the file 44 # format version 45 for elem in tree.iter(): 46 tag = elem.tag.replace('{cansas1d/1.0}', '') 47 print 'element: {0}, stripped element: {1}, value: {2}'.format( 48 elem.tag, tag, elem.text) 49 # reader_return = self.reader._parse_entry(tree) 50 51 except Exception as e: 52 exc_type, exc_obj, exc_tb = sys.exc_info() 53 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] 54 print(exc_type, fname, exc_tb.tb_lineno) 76 def test_real_xml(self): 77 reader = XMLreader(self.xml_valid, self.schema_1_0) 78 valid = reader.validateXML() 79 if valid: 80 self.assertTrue(valid) 81 else: 82 self.assertFalse(valid) 55 83 56 print(output) 84 def test_cansas_xml(self): 85 xmlreader = XMLreader(self.isis_1_1, self.schema_1_1) 86 valid = xmlreader.validateXML() 87 self.assertTrue(valid) 88 reader = Reader() 89 dataloader = reader.read(self.isis_1_1) 90 for data in dataloader: 91 self.assertTrue(data.title == "TK49 c10_SANS") 92 self.assertTrue(data.x.size == 138) 93 self.assertTrue(len(data.meta_data) == 417) 94 self.assertTrue(data.detector[0].distance_unit == "mm") 95 96 def test_entry_name_recurse(self): 97 test_values = [1,2,3,4,5,6] 98 base_key = "key" 99 d = {} 100 for value in test_values: 101 new_key = self.get_number_of_entries(d, base_key, i = 0) 102 d[new_key] = value 103 self.assertTrue(len(d) == 6) 104 105 def test_load_cansas_file(self): 106 valid = [] 107 reader1 = XMLreader(self.xml_valid, self.schema_1_0) 108 self.assertTrue(reader1.validateXML()) 109 reader2 = XMLreader(self.xml_invalid, self.schema_1_0) 110 self.assertFalse(reader2.validateXML()) 111 reader3 = XMLreader(self.xml_valid, self.schema_1_1) 112 self.assertFalse(reader3.validateXML()) 113 reader4 = XMLreader(self.xml_invalid, self.schema_1_1) 114 self.assertFalse(reader4.validateXML()) 115 reader5 = XMLreader(self.isis_1_0, self.schema_1_0) 116 self.assertTrue(reader5.validateXML()) 117 reader6 = XMLreader(self.isis_1_1, self.schema_1_1) 118 self.assertTrue(reader6.validateXML()) 119 reader7 = XMLreader(self.isis_1_1, self.schema_1_0) 120 self.assertFalse(reader7.validateXML()) 121 122 def test_old_cansas_files(self): 123 reader1 = XMLreader(self.cansas1d, self.schema_1_0) 124 self.assertTrue(reader1.validateXML()) 125 reader2 = XMLreader(self.cansas1d_units, self.schema_1_0) 126 self.assertTrue(reader2.validateXML()) 127 reader3 = XMLreader(self.cansas1d_badunits, self.schema_1_0) 128 self.assertTrue(reader3.validateXML()) 129 reader4 = XMLreader(self.cansas1d_slit, self.schema_1_0) 130 self.assertTrue(reader4.validateXML()) 131 reader5 = XMLreader(self.write_test, self.schema_1_0) 132 self.assertTrue(reader5.validateXML()) 57 133 134 58 135 if __name__ == '__main__': 59 unittest.main() 136 unittest.main() -
test/sansdataloader/test/write_test.xml
r5777106 reda8972 16 16 1000.0 17 17 </I> 18 <Idev unit="1/cm"> 19 3.0 20 </Idev> 18 21 <Qdev unit="1/A"> 19 22 0.01 20 23 </Qdev> 21 <dQl unit="1/A">22 0.023 </dQl>24 <dQw unit="1/A">25 0.026 </dQw>27 <Idev unit="1/cm">28 3.029 </Idev>30 24 </Idata> 31 25 <Idata> … … 36 30 1001.0 37 31 </I> 32 <Idev unit="1/cm"> 33 4.0 34 </Idev> 38 35 <Qdev unit="1/A"> 39 36 0.02 40 37 </Qdev> 41 <dQl unit="1/A">42 0.043 </dQl>44 <dQw unit="1/A">45 0.046 </dQw>47 <Idev unit="1/cm">48 4.049 </Idev>50 38 </Idata> 51 39 </SASdata> … … 63 51 0.0 64 52 </temperature> 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> 65 69 <details> 66 70 http://chemtools.chem.soton.ac.uk/projects/blog/blogs.php/bit_id/2720 … … 69 73 Some text here 70 74 </details> 71 <position>72 <x unit="mm">73 10.074 </x>75 <y unit="mm">76 0.077 </y>78 </position>79 <orientation>80 <roll unit="degree">81 22.582 </roll>83 <pitch unit="degree">84 0.0285 </pitch>86 </orientation>87 75 </SASsample> 88 76 <SASinstrument> … … 94 82 neutron 95 83 </radiation> 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> 96 92 <beam_shape> 97 93 disc 98 94 </beam_shape> 99 <beam_size name="bm">100 <x unit="mm">101 12.0102 </x>103 <y unit="mm">104 13.0105 </y>106 </beam_size>107 95 <wavelength unit="A"> 108 96 6.0 … … 123 111 </length> 124 112 <aperture name="source" type="radius"> 125 <distance unit="mm">126 11000127 </distance>128 113 <size> 129 114 <x unit="mm"> … … 131 116 </x> 132 117 </size> 118 <distance unit="mm"> 119 11000 120 </distance> 133 121 </aperture> 134 122 <aperture name="sample" type="radius"> … … 155 143 </y> 156 144 </offset> 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> 157 156 <beam_center> 158 157 <x unit="mm"> … … 171 170 </y> 172 171 </pixel_size> 173 <orientation>174 <roll unit="degree">175 1.0176 </roll>177 <pitch unit="degree">178 0.0179 </pitch>180 <yaw unit="degree">181 0.0182 </yaw>183 </orientation>184 172 </SASdetector> 185 173 </SASinstrument> … … 258 246 1 259 247 </term> 248 <SASProcessnote /> 260 249 </SASprocess> 250 <SASnote /> 261 251 </SASentry> 262 252 </SASroot>
Note: See TracChangeset
for help on using the changeset viewer.