Changeset 278ddee in sasview for src/sas/sascalc/dataloader
- 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
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/data_info.py
r9a5097c r7432acb 353 353 details = None 354 354 ## SESANS zacceptance 355 zacceptance = None 355 zacceptance = (0,"") 356 yacceptance = (0,"") 356 357 357 358 def __init__(self): … … 805 806 # create zero vector 806 807 dy_other = other.dy 807 if other.dy ==None or (len(other.dy) != len(other.y)):808 if other.dy is None or (len(other.dy) != len(other.y)): 808 809 dy_other = np.zeros(len(other.y)) 809 810 810 811 # Check that we have errors, otherwise create zero vector 811 812 dy = self.dy 812 if self.dy ==None or (len(self.dy) != len(self.y)):813 if self.dy is None or (len(self.dy) != len(self.y)): 813 814 dy = np.zeros(len(self.y)) 814 815 … … 821 822 dy, dy_other = self._validity_check(other) 822 823 result = self.clone_without_data(len(self.x)) 823 if self.dxw ==None:824 if self.dxw is None: 824 825 result.dxw = None 825 826 else: 826 827 result.dxw = np.zeros(len(self.x)) 827 if self.dxl ==None:828 if self.dxl is None: 828 829 result.dxl = None 829 830 else: … … 883 884 self._validity_check_union(other) 884 885 result = self.clone_without_data(len(self.x) + len(other.x)) 885 if self.dy ==None or other.dy is None:886 if self.dy is None or other.dy is None: 886 887 result.dy = None 887 888 else: 888 889 result.dy = np.zeros(len(self.x) + len(other.x)) 889 if self.dx ==None or other.dx is None:890 if self.dx is None or other.dx is None: 890 891 result.dx = None 891 892 else: 892 893 result.dx = np.zeros(len(self.x) + len(other.x)) 893 if self.dxw ==None or other.dxw is None:894 if self.dxw is None or other.dxw is None: 894 895 result.dxw = None 895 896 else: 896 897 result.dxw = np.zeros(len(self.x) + len(other.x)) 897 if self.dxl ==None or other.dxl is None:898 if self.dxl is None or other.dxl is None: 898 899 result.dxl = None 899 900 else: … … 906 907 result.y = np.append(self.y, other.y) 907 908 result.y = result.y[ind] 908 if result.dy !=None:909 if result.dy is not None: 909 910 result.dy = np.append(self.dy, other.dy) 910 911 result.dy = result.dy[ind] … … 1029 1030 # Check that the scales match 1030 1031 err_other = other.err_data 1031 if other.err_data ==None or \1032 if other.err_data is None or \ 1032 1033 (len(other.err_data) != len(other.data)): 1033 1034 err_other = np.zeros(len(other.data)) … … 1035 1036 # Check that we have errors, otherwise create zero vector 1036 1037 err = self.err_data 1037 if self.err_data ==None or \1038 if self.err_data is None or \ 1038 1039 (len(self.err_data) != len(self.data)): 1039 1040 err = np.zeros(len(other.data)) … … 1050 1051 dy, dy_other = self._validity_check(other) 1051 1052 result = self.clone_without_data(np.size(self.data)) 1052 if self.dqx_data == None or self.dqy_data ==None:1053 if self.dqx_data is None or self.dqy_data is None: 1053 1054 result.dqx_data = None 1054 1055 result.dqy_data = None … … 1124 1125 result.ymin = self.ymin 1125 1126 result.ymax = self.ymax 1126 if self.dqx_data == None or self.dqy_data ==None or \1127 other.dqx_data == None or other.dqy_data ==None:1127 if self.dqx_data is None or self.dqy_data is None or \ 1128 other.dqx_data is None or other.dqy_data is None: 1128 1129 result.dqx_data = None 1129 1130 result.dqy_data = None -
src/sas/sascalc/dataloader/loader.py
r7f75a3f r278ddee 34 34 from readers import cansas_reader_HDF5 35 35 36 37 logger = logging.getLogger(__name__) 36 38 37 39 class Registry(ExtensionRegistry): … … 114 116 msg = "DataLoader couldn't locate DataLoader plugin folder." 115 117 msg += """ "%s" does not exist""" % dir 116 logg ing.warning(msg)118 logger.warning(msg) 117 119 return readers_found 118 120 … … 132 134 msg = "Loader: Error importing " 133 135 msg += "%s\n %s" % (item, sys.exc_value) 134 logg ing.error(msg)136 logger.error(msg) 135 137 136 138 # Process zip files … … 154 156 msg = "Loader: Error importing" 155 157 msg += " %s\n %s" % (mfile, sys.exc_value) 156 logg ing.error(msg)158 logger.error(msg) 157 159 158 160 except: 159 161 msg = "Loader: Error importing " 160 162 msg += " %s\n %s" % (item, sys.exc_value) 161 logg ing.error(msg)163 logger.error(msg) 162 164 163 165 return readers_found … … 205 207 msg = "Loader: Error accessing" 206 208 msg += " Reader in %s\n %s" % (module.__name__, sys.exc_value) 207 logg ing.error(msg)209 logger.error(msg) 208 210 return reader_found 209 211 … … 238 240 msg = "Loader: Error accessing Reader " 239 241 msg += "in %s\n %s" % (loader.__name__, sys.exc_value) 240 logg ing.error(msg)242 logger.error(msg) 241 243 return reader_found 242 244 … … 283 285 msg = "Loader: Error accessing Reader" 284 286 msg += " in %s\n %s" % (module.__name__, sys.exc_value) 285 logg ing.error(msg)287 logger.error(msg) 286 288 return reader_found 287 289 -
src/sas/sascalc/dataloader/manipulations.py
rdd11014 r7432acb 210 210 y[i_q] += frac * data[npts] 211 211 212 if err_data ==None or err_data[npts] == 0.0:212 if err_data is None or err_data[npts] == 0.0: 213 213 if data[npts] < 0: 214 214 data[npts] = -data[npts] … … 333 333 continue 334 334 y += frac * data[npts] 335 if err_data ==None or err_data[npts] == 0.0:335 if err_data is None or err_data[npts] == 0.0: 336 336 if data[npts] < 0: 337 337 data[npts] = -data[npts] … … 422 422 423 423 # Get the dq for resolution averaging 424 if data2D.dqx_data != None and data2D.dqy_data !=None:424 if data2D.dqx_data is not None and data2D.dqy_data is not None: 425 425 # The pinholes and det. pix contribution present 426 426 # in both direction of the 2D which must be subtracted when … … 462 462 463 463 #q_data_max = numpy.max(q_data) 464 if len(data2D.q_data) ==None:464 if len(data2D.q_data) is None: 465 465 msg = "Circular averaging: invalid q_data: %g" % data2D.q_data 466 466 raise RuntimeError, msg … … 502 502 # Take dqs from data to get the q_average 503 503 x[i_q] += frac * q_value 504 if err_data ==None or err_data[npt] == 0.0:504 if err_data is None or err_data[npt] == 0.0: 505 505 if data_n < 0: 506 506 data_n = -data_n … … 508 508 else: 509 509 err_y[i_q] += frac * frac * err_data[npt] * err_data[npt] 510 if dq_data !=None:510 if dq_data is not None: 511 511 # To be consistent with dq calculation in 1d reduction, 512 512 # we need just the averages (not quadratures) because … … 523 523 err_y[n] = -err_y[n] 524 524 err_y[n] = math.sqrt(err_y[n]) 525 #if err_x !=None:525 #if err_x is not None: 526 526 # err_x[n] = math.sqrt(err_x[n]) 527 527 … … 532 532 idx = (numpy.isfinite(y)) & (numpy.isfinite(x)) 533 533 534 if err_x !=None:534 if err_x is not None: 535 535 d_x = err_x[idx] / y_counts[idx] 536 536 else: … … 623 623 phi_bins[i_phi] += frac * data[npt] 624 624 625 if err_data ==None or err_data[npt] == 0.0:625 if err_data is None or err_data[npt] == 0.0: 626 626 if data_n < 0: 627 627 data_n = -data_n … … 777 777 778 778 # Get the dq for resolution averaging 779 if data2D.dqx_data != None and data2D.dqy_data !=None:779 if data2D.dqx_data is not None and data2D.dqy_data is not None: 780 780 # The pinholes and det. pix contribution present 781 781 # in both direction of the 2D which must be subtracted when … … 888 888 y[i_bin] += frac * data_n 889 889 x[i_bin] += frac * q_value 890 if err_data[n] ==None or err_data[n] == 0.0:890 if err_data[n] is None or err_data[n] == 0.0: 891 891 if data_n < 0: 892 892 data_n = -data_n … … 895 895 y_err[i_bin] += frac * frac * err_data[n] * err_data[n] 896 896 897 if dq_data !=None:897 if dq_data is not None: 898 898 # To be consistent with dq calculation in 1d reduction, 899 899 # we need just the averages (not quadratures) because … … 925 925 y_err[y_err == 0] = numpy.average(y_err) 926 926 idx = (numpy.isfinite(y) & numpy.isfinite(y_err)) 927 if x_err !=None:927 if x_err is not None: 928 928 d_x = x_err[idx] / y_counts[idx] 929 929 else: -
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.