Changeset 278ddee in sasview for src/sas/sascalc
- 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
- Files:
-
- 1 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/calculator/kiessig_calculator.py
rb699768 r235f514 49 49 return None 50 50 # check if delta_q is zero 51 if dq == 0.0 or dq ==None:51 if dq == 0.0 or dq is None: 52 52 return None 53 53 else: -
src/sas/sascalc/calculator/resolution_calculator.py
r9a5097c r7432acb 15 15 import sys 16 16 import logging 17 18 logger = logging.getLogger(__name__) 17 19 18 20 #Plank's constant in cgs unit … … 606 608 a_value *= 1.0E-16 607 609 # if lamda is give (broad meanning of A) return 2* lamda^2 * A 608 if lamda !=None:610 if lamda is not None: 609 611 a_value *= (4 * lamda * lamda) 610 612 return a_value … … 1006 1008 detector_offset = self.sample2detector_distance[1] 1007 1009 except: 1008 logg ing.error(sys.exc_value)1010 logger.error(sys.exc_value) 1009 1011 1010 1012 # detector size in [no of pix_x,no of pix_y] … … 1093 1095 output.qy_data = qy_value 1094 1096 except: 1095 logg ing.error(sys.exc_value)1097 logger.error(sys.exc_value) 1096 1098 1097 1099 return output -
src/sas/sascalc/calculator/sas_gen.py
r9a5097c r7432acb 12 12 import sys 13 13 import logging 14 15 logger = logging.getLogger(__name__) 14 16 15 17 MFACTOR_AM = 2.853E-12 … … 95 97 :Param volume: pixel volume [float] 96 98 """ 97 if self.data_vol ==None:99 if self.data_vol is None: 98 100 raise 99 101 self.data_vol = volume … … 117 119 pos_z = self.data_z 118 120 len_x = len(pos_x) 119 if self.is_avg ==None:121 if self.is_avg is None: 120 122 len_x *= -1 121 123 pos_x, pos_y, pos_z = transform_center(pos_x, pos_y, pos_z) … … 255 257 self.sld_n = np.zeros(length) 256 258 257 if omfdata.mx ==None:259 if omfdata.mx is None: 258 260 self.mx = np.zeros(length) 259 if omfdata.my ==None:261 if omfdata.my is None: 260 262 self.my = np.zeros(length) 261 if omfdata.mz ==None:263 if omfdata.mz is None: 262 264 self.mz = np.zeros(length) 263 265 … … 285 287 mask = (x_dir2 + y_dir2 + z_dir2) <= 1.0 286 288 except: 287 logg ing.error(sys.exc_value)289 logger.error(sys.exc_value) 288 290 self.output = MagSLD(self.pos_x[mask], self.pos_y[mask], 289 291 self.pos_z[mask], self.sld_n[mask], … … 394 396 except: 395 397 # Skip non-data lines 396 logg ing.error(sys.exc_value)398 logger.error(sys.exc_value) 397 399 #Reading Header; Segment count ignored 398 400 s_line = line.split(":", 1) … … 589 591 z_lines.append(z_line) 590 592 except: 591 logg ing.error(sys.exc_value)593 logger.error(sys.exc_value) 592 594 593 595 output = MagSLD(pos_x, pos_y, pos_z, sld_n, sld_mx, sld_my, sld_mz) … … 683 685 except: 684 686 # Skip non-data lines 685 logg ing.error(sys.exc_value)687 logger.error(sys.exc_value) 686 688 output = MagSLD(pos_x, pos_y, pos_z, sld_n, 687 689 sld_mx, sld_my, sld_mz) … … 689 691 output.set_pix_type('pixel') 690 692 output.set_pixel_symbols('pixel') 691 if vol_pix !=None:693 if vol_pix is not None: 692 694 output.set_pixel_volumes(vol_pix) 693 695 return output … … 701 703 :Param data: MagSLD data object 702 704 """ 703 if path ==None:705 if path is None: 704 706 raise ValueError, "Missing the file path." 705 if data ==None:707 if data is None: 706 708 raise ValueError, "Missing the data to save." 707 709 x_val = data.pos_x … … 711 713 length = len(x_val) 712 714 sld_n = data.sld_n 713 if sld_n ==None:715 if sld_n is None: 714 716 sld_n = np.zeros(length) 715 717 sld_mx = data.sld_mx 716 if sld_mx ==None:718 if sld_mx is None: 717 719 sld_mx = np.zeros(length) 718 720 sld_my = np.zeros(length) … … 865 867 self.sld_theta = None 866 868 self.pix_symbol = None 867 if sld_mx != None and sld_my != None and sld_mz !=None:869 if sld_mx is not None and sld_my is not None and sld_mz is not None: 868 870 self.set_sldms(sld_mx, sld_my, sld_mz) 869 871 self.set_nodes() … … 933 935 :Params pixel: str; pixel or atomic symbol, or array of strings 934 936 """ 935 if self.sld_n ==None:937 if self.sld_n is None: 936 938 return 937 939 if symbol.__class__.__name__ == 'str': … … 945 947 :Params pixel: str; pixel or atomic symbol, or array of strings 946 948 """ 947 if self.sld_n ==None:949 if self.sld_n is None: 948 950 return 949 951 if vol.__class__.__name__ == 'ndarray': -
src/sas/sascalc/data_util/calcthread.py
r934ce649 r7432acb 8 8 import traceback 9 9 import sys 10 import logging 10 11 11 12 if sys.platform.count("darwin") > 0: … … 21 22 from time import clock 22 23 from time import sleep 24 25 logger = logging.getLogger(__name__) 23 26 24 27 … … 202 205 def update(self, **kwargs): 203 206 """Update GUI with the lastest results from the current work unit.""" 204 if self.updatefn !=None and clock() > self._time_for_update:207 if self.updatefn is not None and clock() > self._time_for_update: 205 208 self._lock.acquire() 206 209 self._time_for_update = clock() + self._delay … … 218 221 def complete(self, **kwargs): 219 222 """Update the GUI with the completed results from a work unit.""" 220 if self.completefn !=None:223 if self.completefn is not None: 221 224 self.completefn(**kwargs) 222 225 sleep(self.yieldtime) … … 243 246 except Exception: 244 247 pass 245 import logging 246 logging.error(traceback.format_exc()) 248 logger.error(traceback.format_exc()) 247 249 #print 'CalcThread exception', 248 250 -
src/sas/sascalc/data_util/qsmearing.py
r9a5097c r235f514 42 42 # This checks for 2D data (does not throw exception because fail is common) 43 43 if data.__class__.__name__ not in ['Data1D', 'Theory1D']: 44 if data ==None:44 if data is None: 45 45 return None 46 elif data.dqx_data == None or data.dqy_data ==None:46 elif data.dqx_data is None or data.dqy_data is None: 47 47 return None 48 48 return PySmear2D(data) -
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/file_converter/cansas_writer.py
r0b1a677 r7432acb 17 17 # Write the file 18 18 file_ref = open(filename, 'w') 19 if self.encoding ==None:19 if self.encoding is None: 20 20 self.encoding = "UTF-8" 21 21 doc.write(file_ref, encoding=self.encoding, … … 96 96 self.write_node(point, "I", datainfo.y[i], 97 97 {'unit': datainfo.y_unit}) 98 if datainfo.dy !=None and len(datainfo.dy) > i:98 if datainfo.dy is not None and len(datainfo.dy) > i: 99 99 self.write_node(point, "Idev", datainfo.dy[i], 100 100 {'unit': datainfo.y_unit}) 101 if datainfo.dx !=None and len(datainfo.dx) > i:101 if datainfo.dx is not None and len(datainfo.dx) > i: 102 102 self.write_node(point, "Qdev", datainfo.dx[i], 103 103 {'unit': datainfo.x_unit}) 104 if datainfo.dxw !=None and len(datainfo.dxw) > i:104 if datainfo.dxw is not None and len(datainfo.dxw) > i: 105 105 self.write_node(point, "dQw", datainfo.dxw[i], 106 106 {'unit': datainfo.x_unit}) 107 if datainfo.dxl !=None and len(datainfo.dxl) > i:107 if datainfo.dxl is not None and len(datainfo.dxl) > i: 108 108 self.write_node(point, "dQl", datainfo.dxl[i], 109 109 {'unit': datainfo.x_unit}) -
src/sas/sascalc/fit/AbstractFitEngine.py
r9a5097c r7432acb 190 190 if qmin == 0.0 and not np.isfinite(self.y[qmin]): 191 191 self.qmin = min(self.x[self.x != 0]) 192 elif qmin !=None:192 elif qmin is not None: 193 193 self.qmin = qmin 194 if qmax !=None:194 if qmax is not None: 195 195 self.qmax = qmax 196 196 # Determine the range needed in unsmeared-Q to cover … … 202 202 self._last_unsmeared_bin = len(self.x) - 1 203 203 204 if self.smearer !=None:204 if self.smearer is not None: 205 205 self._first_unsmeared_bin, self._last_unsmeared_bin = \ 206 206 self.smearer.get_bin_range(self.qmin, self.qmax) … … 294 294 295 295 ## fitting range 296 if qmin ==None:296 if qmin is None: 297 297 self.qmin = 1e-16 298 if qmax ==None:298 if qmax is None: 299 299 self.qmax = math.sqrt(x_max * x_max + y_max * y_max) 300 300 ## new error image for fitting purpose 301 if self.err_data ==None or self.err_data == []:301 if self.err_data is None or self.err_data == []: 302 302 self.res_err_data = np.ones(len(self.data)) 303 303 else: … … 318 318 Set smearer 319 319 """ 320 if smearer ==None:320 if smearer is None: 321 321 return 322 322 self.smearer = smearer … … 330 330 if qmin == 0.0: 331 331 self.qmin = 1e-16 332 elif qmin !=None:332 elif qmin is not None: 333 333 self.qmin = qmin 334 if qmax !=None:334 if qmax is not None: 335 335 self.qmax = qmax 336 336 self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) … … 357 357 return the residuals 358 358 """ 359 if self.smearer !=None:359 if self.smearer is not None: 360 360 fn.set_index(self.idx) 361 361 gn = fn.get_value() … … 612 612 """ 613 613 """ 614 if self.pvec ==None and self.model is None and self.param_list is None:614 if self.pvec is None and self.model is None and self.param_list is None: 615 615 return "No results" 616 616 -
src/sas/sascalc/fit/Loader.py
r9a5097c rac07a3a 34 34 def set_values(self): 35 35 """ Store the values loaded from file in local variables""" 36 if not self.filename ==None:36 if self.filename is not None: 37 37 input_f = open(self.filename, 'r') 38 38 buff = input_f.read() -
src/sas/sascalc/fit/MultiplicationModel.py
r9a5097c r7432acb 178 178 """ 179 179 value = self.params['volfraction'] 180 if value !=None:180 if value is not None: 181 181 factor = self.p_model.calculate_VR() 182 if factor ==None or factor == NotImplemented or factor == 0.0:182 if factor is None or factor == NotImplemented or factor == 0.0: 183 183 val = value 184 184 else: … … 195 195 effective_radius = self.p_model.calculate_ER() 196 196 #Reset the effective_radius of s_model just before the run 197 if effective_radius !=None and effective_radius != NotImplemented:197 if effective_radius is not None and effective_radius != NotImplemented: 198 198 self.s_model.setParam('radius_effective', effective_radius) 199 199 -
src/sas/sascalc/invariant/invariant.py
r9a5097c r7432acb 329 329 330 330 ##power is given only for function = power_law 331 if power !=None:331 if power is not None: 332 332 sigma2 = linearized_data.dy * linearized_data.dy 333 333 a = -(power) … … 389 389 self._data = self._get_data(data) 390 390 # get the dxl if the data is smeared: This is done only once on init. 391 if self._data.dxl !=None and self._data.dxl.all() > 0:391 if self._data.dxl is not None and self._data.dxl.all() > 0: 392 392 # assumes constant dxl 393 393 self._smeared = self._data.dxl[0] … … 579 579 580 580 result_data = LoaderData1D(x=q, y=iq, dy=diq) 581 if self._smeared !=None:581 if self._smeared is not None: 582 582 result_data.dxl = self._smeared * np.ones(len(q)) 583 583 return result_data -
src/sas/sascalc/pr/fit/AbstractFitEngine.py
r9a5097c r7432acb 190 190 if qmin == 0.0 and not np.isfinite(self.y[qmin]): 191 191 self.qmin = min(self.x[self.x != 0]) 192 elif qmin !=None:192 elif qmin is not None: 193 193 self.qmin = qmin 194 if qmax !=None:194 if qmax is not None: 195 195 self.qmax = qmax 196 196 # Determine the range needed in unsmeared-Q to cover … … 202 202 self._last_unsmeared_bin = len(self.x) - 1 203 203 204 if self.smearer !=None:204 if self.smearer is not None: 205 205 self._first_unsmeared_bin, self._last_unsmeared_bin = \ 206 206 self.smearer.get_bin_range(self.qmin, self.qmax) … … 294 294 295 295 ## fitting range 296 if qmin ==None:296 if qmin is None: 297 297 self.qmin = 1e-16 298 if qmax ==None:298 if qmax is None: 299 299 self.qmax = math.sqrt(x_max * x_max + y_max * y_max) 300 300 ## new error image for fitting purpose 301 if self.err_data ==None or self.err_data == []:301 if self.err_data is None or self.err_data == []: 302 302 self.res_err_data = np.ones(len(self.data)) 303 303 else: … … 318 318 Set smearer 319 319 """ 320 if smearer ==None:320 if smearer is None: 321 321 return 322 322 self.smearer = smearer … … 330 330 if qmin == 0.0: 331 331 self.qmin = 1e-16 332 elif qmin !=None:332 elif qmin is not None: 333 333 self.qmin = qmin 334 if qmax !=None:334 if qmax is not None: 335 335 self.qmax = qmax 336 336 self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) … … 357 357 return the residuals 358 358 """ 359 if self.smearer !=None:359 if self.smearer is not None: 360 360 fn.set_index(self.idx) 361 361 # Get necessary data from self.data and set the data for smearing … … 615 615 """ 616 616 """ 617 if self.pvec ==None and self.model is None and self.param_list is None:617 if self.pvec is None and self.model is None and self.param_list is None: 618 618 return "No results" 619 619 -
src/sas/sascalc/pr/fit/Loader.py
r9a5097c rac07a3a 34 34 def set_values(self): 35 35 """ Store the values loaded from file in local variables""" 36 if not self.filename ==None:36 if self.filename is not None: 37 37 input_f = open(self.filename, 'r') 38 38 buff = input_f.read() -
src/sas/sascalc/pr/invertor.py
r9a5097c r45dffa69 18 18 from scipy import optimize 19 19 from sas.sascalc.pr.core.pr_inversion import Cinvertor 20 21 logger = logging.getLogger(__name__) 20 22 21 23 def help(): … … 160 162 return self.set_dmax(value) 161 163 elif name == 'q_min': 162 if value ==None:164 if value is None: 163 165 return self.set_qmin(-1.0) 164 166 return self.set_qmin(value) 165 167 elif name == 'q_max': 166 if value ==None:168 if value is None: 167 169 return self.set_qmax(-1.0) 168 170 return self.set_qmax(value) … … 393 395 Check q-value against user-defined range 394 396 """ 395 if not self.q_min ==None and q < self.q_min:397 if self.q_min is not None and q < self.q_min: 396 398 return False 397 if not self.q_max ==None and q > self.q_max:399 if self.q_max is not None and q > self.q_max: 398 400 return False 399 401 return True … … 495 497 # We were not able to estimate the errors 496 498 # Return an empty error matrix 497 logg ing.error(sys.exc_value)499 logger.error(sys.exc_value) 498 500 499 501 # Keep a copy of the last output … … 541 543 # number of terms 542 544 best_alpha, _, _ = self.estimate_alpha(self.nfunc) 543 logg ing.warning("Invertor.estimate_numterms: %s" % sys.exc_value)545 logger.warning("Invertor.estimate_numterms: %s" % sys.exc_value) 544 546 return self.nfunc, best_alpha, "Could not estimate number of terms" 545 547 … … 656 658 file.write("#has_bck=0\n") 657 659 file.write("#alpha_estimate=%g\n" % self.suggested_alpha) 658 if not self.out ==None:660 if self.out is not None: 659 661 if len(self.out) == len(self.cov): 660 662 for i in range(len(self.out)): -
src/sas/sascalc/pr/num_term.py
r9a5097c r7432acb 5 5 import logging 6 6 from sas.sascalc.pr.invertor import Invertor 7 8 logger = logging.getLogger(__name__) 7 9 8 10 class NTermEstimator(object): … … 65 67 self.alpha_list = [] 66 68 for k in range(self.nterm_min, self.nterm_max, 1): 67 if self.isquit_func !=None:69 if self.isquit_func is not None: 68 70 self.isquit_func() 69 71 best_alpha, message, _ = inver.estimate_alpha(k) … … 157 159 scale = None 158 160 min_err = 0.0 159 if not path ==None:161 if path is not None: 160 162 input_f = open(path, 'r') 161 163 buff = input_f.read() … … 169 171 err = float(toks[2]) 170 172 else: 171 if scale ==None:173 if scale is None: 172 174 scale = 0.05 * math.sqrt(test_y) 173 175 #scale = 0.05/math.sqrt(y) … … 180 182 data_err = np.append(data_err, err) 181 183 except: 182 logg ing.error(sys.exc_value)184 logger.error(sys.exc_value) 183 185 184 186 return data_x, data_y, data_err -
src/sas/sascalc/realspace/VolumeCanvas.py
rd85c194 r235f514 293 293 """ 294 294 # If the handle is not provided, create one 295 if id ==None:295 if id is None: 296 296 id = shapeDesc.params["type"]+str(self.shapecount) 297 297 … … 303 303 self.shapecount += 1 304 304 305 # model changed, need to recalculate P(r)305 # model changed, need to recalculate P(r) 306 306 self._model_changed() 307 307 … … 325 325 """ 326 326 # If the handle is not provided, create one 327 if id ==None:327 if id is None: 328 328 id = "shape"+str(self.shapecount) 329 329 330 # shapeDesc = ShapeDescriptor(shape.lower())330 # shapeDesc = ShapeDescriptor(shape.lower()) 331 331 if shape.lower() in shape_dict: 332 332 shapeDesc = shape_dict[shape.lower()]() … … 335 335 shapeDesc = PDBDescriptor(shape) 336 336 else: 337 raise ValueError , "VolumeCanvas.add: Unknown shape %s" % shape337 raise ValueError("VolumeCanvas.add: Unknown shape %s" % shape) 338 338 339 339 return self.addObject(shapeDesc, id) … … 345 345 """ 346 346 347 if self.shapes.has_key(id):347 if id in self.shapes: 348 348 del self.shapes[id] 349 349 else: 350 raise KeyError , "VolumeCanvas.delete: could not find shape ID"351 352 # model changed, need to recalculate P(r)350 raise KeyError("VolumeCanvas.delete: could not find shape ID") 351 352 # model changed, need to recalculate P(r) 353 353 self._model_changed() 354 354 … … 379 379 # If a shape identifier was given, look the shape up 380 380 # in the dictionary 381 if len(toks) >1:382 if toks[0] in self.shapes .keys():381 if len(toks): 382 if toks[0] in self.shapes: 383 383 # The shape was found, now look for the parameter 384 384 if toks[1] in self.shapes[toks[0]].params: … … 387 387 self._model_changed() 388 388 else: 389 raise ValueError , "Could not find parameter %s" % name389 raise ValueError("Could not find parameter %s" % name) 390 390 else: 391 raise ValueError , "Could not find shape %s" % toks[0]391 raise ValueError("Could not find shape %s" % toks[0]) 392 392 393 393 else: … … 410 410 if len(toks) == 1: 411 411 try: 412 self.params.has_key(toks[0])412 value = self.params[toks[0]] 413 413 except KeyError: 414 raise ValueError, \ 415 "VolumeCanvas.getParam: Could not find %s" % name 416 417 value = self.params[toks[0]] 414 raise ValueError("VolumeCanvas.getParam: Could not find" 415 " %s" % name) 418 416 if isinstance(value, ShapeDescriptor): 419 raise ValueError , \420 "VolumeCanvas.getParam: Cannot get parameter value."417 raise ValueError("VolumeCanvas.getParam: Cannot get parameter" 418 " value.") 421 419 else: 422 420 return value … … 424 422 elif len(toks) == 2: 425 423 try: 426 s elf.shapes.has_key(toks[0])424 shapeinstance = self.shapes[toks[0]] 427 425 except KeyError: 428 raise ValueError, \ 429 "VolumeCanvas.getParam: Could not find %s" % name 430 431 shapeinstance = self.shapes[toks[0]] 432 433 try: 434 shapeinstance.params.has_key(toks[1]) 435 except KeyError: 436 raise ValueError, \ 437 "VolumeCanvas.getParam: Could not find %s" % name 426 raise ValueError("VolumeCanvas.getParam: Could not find " 427 "%s" % name) 428 429 if not toks[1] in shapeinstance.params: 430 raise ValueError("VolumeCanvas.getParam: Could not find " 431 "%s" % name) 438 432 439 433 return shapeinstance.params[toks[1]] 440 434 441 435 else: 442 raise ValueError, \ 443 "VolumeCanvas.getParam: Could not find %s" % name 444 445 def getParamList(self, shapeid = None): 436 raise ValueError("VolumeCanvas.getParam: Could not find %s" % name) 437 438 def getParamList(self, shapeid=None): 446 439 """ 447 440 return a full list of all available parameters from … … 455 448 456 449 param_list = [] 457 if shapeid == None:458 for key1 in self.params .keys():450 if shapeid is None: 451 for key1 in self.params: 459 452 #value1 = self.params[key1] 460 453 param_list.append(key1) 461 for key2 in self.shapes .keys():454 for key2 in self.shapes: 462 455 value2 = self.shapes[key2] 463 456 header = key2 + '.' 464 for key3 in value2.params .keys():457 for key3 in value2.params: 465 458 fullname = header + key3 466 459 param_list.append(fullname) 467 460 468 461 else: 469 try: 470 self.shapes.has_key(shapeid) 471 except KeyError: 472 raise ValueError, \ 473 "VolumeCanvas: getParamList: Could not find %s" % shapeid 462 if not shapeid in self.shapes: 463 raise ValueError("VolumeCanvas: getParamList: Could not find " 464 "%s" % shapeid) 465 474 466 header = shapeid + '.' 475 param_list = self.shapes[shapeid].params.keys() 476 for i in range(len(param_list)): 477 param_list[i] = header + param_list[i] 478 467 param_list = [header + param for param in self.shapes[shapeid].params] 479 468 return param_list 480 469 … … 490 479 @param shapeDesc: shape description 491 480 """ 492 # Create the object model481 # Create the object model 493 482 shapeDesc.create() 494 483 … … 605 594 # type we recognize 606 595 else: 607 raise ValueError , "run(q): bad type for q"596 raise ValueError("run(q): bad type for q") 608 597 609 598 def runXY(self, q = 0): … … 625 614 # type we recognize 626 615 else: 627 raise ValueError , "runXY(q): bad type for q"616 raise ValueError("runXY(q): bad type for q") 628 617 629 618 def _create_modelObject(self): … … 674 663 # If this is the first simulation call, we need to generate the 675 664 # space points 676 if self.points ==None:665 if self.points is None: 677 666 self._create_modelObject() 678 667 679 668 # Protect against empty model 680 if self.points ==None:669 if self.points is None: 681 670 return 0 682 671 -
src/sas/sascalc/data_util/registry.py
rb699768 r7f75a3f 7 7 """ 8 8 9 import os.path 9 from sas.sascalc.dataloader.loader_exceptions import NoKnownLoaderException 10 10 11 11 12 class ExtensionRegistry(object): … … 61 62 def __init__(self, **kw): 62 63 self.loaders = {} 64 63 65 def __setitem__(self, ext, loader): 64 66 if ext not in self.loaders: 65 67 self.loaders[ext] = [] 66 68 self.loaders[ext].insert(0,loader) 69 67 70 def __getitem__(self, ext): 68 71 return self.loaders[ext] 72 69 73 def __contains__(self, ext): 70 74 return ext in self.loaders 75 71 76 def formats(self): 72 77 """ … … 76 81 names.sort() 77 82 return names 83 78 84 def extensions(self): 79 85 """ … … 83 89 exts.sort() 84 90 return exts 91 85 92 def lookup(self, path): 86 93 """ 87 94 Return the loader associated with the file type of path. 88 95 89 Raises ValueError if file type is not known. 96 :param path: Data file path 97 :raises ValueError: When no loaders are found for the file. 98 :return: List of available readers for the file extension 90 99 """ 91 100 # Find matching extensions … … 105 114 # Raise an error if there are no matching extensions 106 115 if len(loaders) == 0: 107 raise ValueError, "Unknown file type for "+path 108 # All done 116 raise ValueError("Unknown file type for "+path) 109 117 return loaders 118 110 119 def load(self, path, format=None): 111 120 """ 112 121 Call the loader for the file type of path. 113 122 114 Raises ValueErrorif no loader is available.115 Raises KeyErrorif format is not available.116 May raise a loader-defined exception if loader fails. 123 :raise ValueError: if no loader is available. 124 :raise KeyError: if format is not available. 125 May raise a loader-defined exception if loader fails. 117 126 """ 127 loaders = [] 118 128 if format is None: 119 loaders = self.lookup(path) 129 try: 130 loaders = self.lookup(path) 131 except ValueError as e: 132 pass 120 133 else: 121 loaders = self.loaders[format] 134 try: 135 loaders = self.loaders[format] 136 except KeyError as e: 137 pass 122 138 for fn in loaders: 123 139 try: 124 140 return fn(path) 125 except :126 pass # give other loaders a chance to succeed141 except Exception as e: 142 pass # give other loaders a chance to succeed 127 143 # If we get here it is because all loaders failed 128 raise # reraises last exception 129 130 def test(): 131 reg = ExtensionRegistry() 132 class CxError(Exception): pass 133 def cx(file): return 'cx' 134 def new_cx(file): return 'new_cx' 135 def fail_cx(file): raise CxError 136 def cat(file): return 'cat' 137 def gunzip(file): return 'gunzip' 138 reg['.cx'] = cx 139 reg['.cx1'] = cx 140 reg['.cx'] = new_cx 141 reg['.gz'] = gunzip 142 reg['.cx.gz'] = new_cx 143 reg['.cx1.gz'] = fail_cx 144 reg['.cx1'] = fail_cx 145 reg['.cx2'] = fail_cx 146 reg['new_cx'] = new_cx 147 148 # Two loaders associated with .cx 149 assert reg.lookup('hello.cx') == [new_cx,cx] 150 # Make sure the last loader applies first 151 assert reg.load('hello.cx') == 'new_cx' 152 # Make sure the next loader applies if the first fails 153 assert reg.load('hello.cx1') == 'cx' 154 # Make sure the format override works 155 assert reg.load('hello.cx1',format='.cx.gz') == 'new_cx' 156 # Make sure the format override works 157 assert reg.load('hello.cx1',format='new_cx') == 'new_cx' 158 # Make sure the case of all loaders failing is correct 159 try: reg.load('hello.cx2') 160 except CxError: pass # correct failure 161 else: raise AssertError,"Incorrect error on load failure" 162 # Make sure the case of no loaders fails correctly 163 try: reg.load('hello.missing') 164 except ValueError,msg: 165 assert str(msg)=="Unknown file type for hello.missing",'Message: <%s>'%(msg) 166 else: raise AssertError,"No error raised for missing extension" 167 assert reg.formats() == ['new_cx'] 168 assert reg.extensions() == ['.cx','.cx.gz','.cx1','.cx1.gz','.cx2','.gz'] 169 # make sure that it supports multiple '.' in filename 170 assert reg.load('hello.extra.cx1') == 'cx' 171 assert reg.load('hello.gz') == 'gunzip' 172 assert reg.load('hello.cx1.gz') == 'gunzip' # Since .cx1.gz fails 173 174 if __name__ == "__main__": test() 144 raise NoKnownLoaderException(e.message) # raise generic exception -
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.