Changeset 278ddee in sasview for src/sas/sascalc/dataloader/readers
- Timestamp:
- Apr 11, 2017 9:51:05 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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- beba407
- Parents:
- 7f75a3f (diff), 97c60f8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - git-author:
- Jeff Krzywon <krzywon@…> (04/11/17 09:51:05)
- git-committer:
- krzywon <krzywon@…> (04/11/17 09:51:05)
- Location:
- src/sas/sascalc/dataloader/readers
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/ascii_reader.py
r7f75a3f r235f514 17 17 import os 18 18 from sas.sascalc.dataloader.data_info import Data1D 19 from sas.sascalc.dataloader.loader_exceptions import FileContentsException20 19 21 20 # Check whether we have a converter available … … 129 128 if new_lentoks > 2: 130 129 _dy = float(toks[2]) 131 has_error_dy = False if _dy ==None else True130 has_error_dy = False if _dy is None else True 132 131 133 132 # If a 4th row is present, consider it dx 134 133 if new_lentoks > 3: 135 134 _dx = float(toks[3]) 136 has_error_dx = False if _dx ==None else True135 has_error_dx = False if _dx is None else True 137 136 138 137 # Delete the previously stored lines of data candidates if … … 174 173 if not is_data: 175 174 msg = "ascii_reader: x has no data" 176 raise FileContentsException, msg175 raise RuntimeError, msg 177 176 # Sanity check 178 177 if has_error_dy == True and not len(ty) == len(tdy): 179 178 msg = "ascii_reader: y and dy have different length" 180 raise FileContentsException, msg179 raise RuntimeError, msg 181 180 if has_error_dx == True and not len(tx) == len(tdx): 182 181 msg = "ascii_reader: y and dy have different length" 183 raise FileContentsException, msg182 raise RuntimeError, msg 184 183 # If the data length is zero, consider this as 185 184 # though we were not able to read the file. 186 185 if len(tx) == 0: 187 raise FileContentsException, "ascii_reader: could not load file"186 raise RuntimeError, "ascii_reader: could not load file" 188 187 189 188 #Let's re-order the data to make cal. -
src/sas/sascalc/dataloader/readers/associations.py
re5c09cf r959eb01 18 18 import logging 19 19 import json 20 21 logger = logging.getLogger(__name__) 20 22 21 23 FILE_NAME = 'defaults.json' … … 67 69 msg = "read_associations: skipping association" 68 70 msg += " for %s\n %s" % (ext.lower(), sys.exc_value) 69 logg ing.error(msg)71 logger.error(msg) 70 72 else: 71 73 print "Could not find reader association settings\n %s [%s]" % (__file__, os.getcwd()) … … 81 83 :param registry_function: function to be called to register each reader 82 84 """ 83 logg ing.info("register_readers is now obsolete: use read_associations()")85 logger.info("register_readers is now obsolete: use read_associations()") 84 86 import abs_reader 85 87 import ascii_reader -
src/sas/sascalc/dataloader/readers/cansas_constants.py
rad4632c r63d773c 135 135 "Sesans": {"storeas": "content"}, 136 136 "zacceptance": {"storeas": "float"}, 137 "yacceptance": {"storeas": "float"}, 137 138 "<any>" : ANY 138 139 } -
src/sas/sascalc/dataloader/readers/cansas_reader.py
r7f75a3f r278ddee 34 34 import xml.dom.minidom 35 35 from xml.dom.minidom import parseString 36 37 logger = logging.getLogger(__name__) 36 38 37 39 PREPROCESS = "xmlpreprocess" … … 291 293 elif tagname == 'Sesans': 292 294 self.current_datainfo.isSesans = bool(data_point) 295 elif tagname == 'yacceptance': 296 self.current_datainfo.sample.yacceptance = (data_point, unit) 293 297 elif tagname == 'zacceptance': 294 298 self.current_datainfo.sample.zacceptance = (data_point, unit) … … 809 813 :param data1d: presumably a Data1D object 810 814 """ 811 if self.current_dataset ==None:815 if self.current_dataset is None: 812 816 x_vals = np.empty(0) 813 817 y_vals = np.empty(0) … … 897 901 # Write the file 898 902 file_ref = open(filename, 'w') 899 if self.encoding ==None:903 if self.encoding is None: 900 904 self.encoding = "UTF-8" 901 905 doc.write(file_ref, encoding=self.encoding, … … 1017 1021 :param entry_node: lxml node ElementTree object to be appended to 1018 1022 """ 1019 if datainfo.run ==None or datainfo.run == []:1023 if datainfo.run is None or datainfo.run == []: 1020 1024 datainfo.run.append(RUN_NAME_DEFAULT) 1021 1025 datainfo.run_name[RUN_NAME_DEFAULT] = RUN_NAME_DEFAULT … … 1061 1065 sesans.text = str(datainfo.isSesans) 1062 1066 node.append(sesans) 1067 self.write_node(node, "yacceptance", datainfo.sample.yacceptance[0], 1068 {'unit': datainfo.sample.yacceptance[1]}) 1063 1069 self.write_node(node, "zacceptance", datainfo.sample.zacceptance[0], 1064 1070 {'unit': datainfo.sample.zacceptance[1]}) … … 1133 1139 self.write_node(point, "T", spectrum.transmission[i], 1134 1140 {'unit': spectrum.transmission_unit}) 1135 if spectrum.transmission_deviation !=None \1141 if spectrum.transmission_deviation is not None \ 1136 1142 and len(spectrum.transmission_deviation) >= i: 1137 1143 self.write_node(point, "Tdev", … … 1213 1219 str(datainfo.source.name)) 1214 1220 self.append(source, instr) 1215 if datainfo.source.radiation ==None or datainfo.source.radiation == '':1221 if datainfo.source.radiation is None or datainfo.source.radiation == '': 1216 1222 datainfo.source.radiation = "neutron" 1217 1223 self.write_node(source, "radiation", datainfo.source.radiation) … … 1254 1260 :param instr: lxml node ElementTree object to be appended to 1255 1261 """ 1256 if datainfo.collimation == [] or datainfo.collimation ==None:1262 if datainfo.collimation == [] or datainfo.collimation is None: 1257 1263 coll = Collimation() 1258 1264 datainfo.collimation.append(coll) … … 1299 1305 :param inst: lxml instrument node to be appended to 1300 1306 """ 1301 if datainfo.detector ==None or datainfo.detector == []:1307 if datainfo.detector is None or datainfo.detector == []: 1302 1308 det = Detector() 1303 1309 det.name = "" … … 1464 1470 local_unit = None 1465 1471 exec "local_unit = storage.%s_unit" % toks[0] 1466 if local_unit !=None and units.lower() != local_unit.lower():1472 if local_unit is not None and units.lower() != local_unit.lower(): 1467 1473 if HAS_CONVERTER == True: 1468 1474 try: … … 1477 1483 self.errors.add(err_mess) 1478 1484 if optional: 1479 logg ing.info(err_mess)1485 logger.info(err_mess) 1480 1486 else: 1481 1487 raise ValueError, err_mess … … 1486 1492 self.errors.add(err_mess) 1487 1493 if optional: 1488 logg ing.info(err_mess)1494 logger.info(err_mess) 1489 1495 else: 1490 1496 raise ValueError, err_mess -
src/sas/sascalc/dataloader/readers/danse_reader.py
r9a5097c r235f514 19 19 from sas.sascalc.dataloader.data_info import Data2D, Detector 20 20 from sas.sascalc.dataloader.manipulations import reader2D_converter 21 22 logger = logging.getLogger(__name__) 21 23 22 24 # Look for unit converter … … 142 144 error.append(err) 143 145 except: 144 logg ing.info("Skipping line:%s,%s" %(data_str,146 logger.info("Skipping line:%s,%s" %(data_str, 145 147 sys.exc_value)) 146 148 … … 164 166 165 167 x_vals.append(qx) 166 if xmin ==None or qx < xmin:168 if xmin is None or qx < xmin: 167 169 xmin = qx 168 if xmax ==None or qx > xmax:170 if xmax is None or qx > xmax: 169 171 xmax = qx 170 172 … … 179 181 180 182 y_vals.append(qy) 181 if ymin ==None or qy < ymin:183 if ymin is None or qy < ymin: 182 184 ymin = qy 183 if ymax ==None or qy > ymax:185 if ymax is None or qy > ymax: 184 186 ymax = qy 185 187 … … 196 198 msg = "Skipping entry (v1.0):%s,%s" % (str(data[i_pt]), 197 199 sys.exc_value) 198 logg ing.info(msg)200 logger.info(msg) 199 201 200 202 # Get bin number … … 271 273 raise ValueError, msg 272 274 else: 273 logg ing.info("Danse_reader Reading %s \n" % filename)275 logger.info("Danse_reader Reading %s \n" % filename) 274 276 275 277 # Store loading process information -
src/sas/sascalc/dataloader/readers/tiff_reader.py
r9a5097c r959eb01 16 16 from sas.sascalc.dataloader.data_info import Data2D 17 17 from sas.sascalc.dataloader.manipulations import reader2D_converter 18 18 19 logger = logging.getLogger(__name__) 20 19 21 class Reader: 20 22 """ … … 76 78 value = float(val) 77 79 except: 78 logg ing.error("tiff_reader: had to skip a non-float point")80 logger.error("tiff_reader: had to skip a non-float point") 79 81 continue 80 82 -
src/sas/sascalc/dataloader/readers/xml_reader.py
r7f75a3f r235f514 18 18 from lxml import etree 19 19 from lxml.builder import E 20 21 logger = logging.getLogger(__name__) 20 22 21 23 PARSER = etree.ETCompatXMLParser(remove_comments=True, remove_pis=False) … … 70 72 self.xmldoc = etree.parse(self.xml, parser=PARSER) 71 73 self.xmlroot = self.xmldoc.getroot() 72 except etree.XMLSyntaxError :73 raise74 except etree.XMLSyntaxError as xml_error: 75 logger.info(xml_error) 74 76 except Exception: 75 77 self.xml = None … … 88 90 self.xmlroot = etree.fromstring(tag_soup) 89 91 except etree.XMLSyntaxError as xml_error: 90 logg ing.info(xml_error)92 logger.info(xml_error) 91 93 except Exception: 92 94 self.xml = None … … 102 104 self.schemadoc = etree.parse(self.schema, parser=PARSER) 103 105 except etree.XMLSyntaxError as xml_error: 104 logg ing.info(xml_error)106 logger.info(xml_error) 105 107 except Exception: 106 108 self.schema = None … … 238 240 :param name: The name of the element to be created 239 241 """ 240 if attrib ==None:242 if attrib is None: 241 243 attrib = {} 242 244 return etree.Element(name, attrib, nsmap) … … 297 299 """ 298 300 text = str(text) 299 if attrib ==None:301 if attrib is None: 300 302 attrib = {} 301 303 elem = E(elementname, attrib, text) -
src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py
rc94280c r7f75a3f 13 13 TransmissionSpectrum, Detector 14 14 from sas.sascalc.dataloader.data_info import combine_data_info_with_plottable 15 from sas.sascalc.dataloader.loader_exceptions import FileContentsException 15 16 16 17 … … 75 76 if extension in self.ext or self.allow_all: 76 77 # Load the data file 77 self.raw_data = h5py.File(filename, 'r') 78 try: 79 self.raw_data = h5py.File(filename, 'r') 80 except Exception as e: 81 raise FileContentsException, e 78 82 # Read in all child elements of top level SASroot 79 83 self.read_children(self.raw_data, [])
Note: See TracChangeset
for help on using the changeset viewer.