Changeset cbb9551 in sasview for src/sas/sascalc
- Timestamp:
- Apr 10, 2017 10:19:20 AM (8 years ago)
- Children:
- 4597637
- Parents:
- 1b9a367 (diff), d26f025 (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. - Location:
- src/sas/sascalc
- Files:
-
- 1 added
- 25 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
rb699768 r463e7ffc 32 32 from readers import cansas_reader 33 33 34 logger = logging.getLogger(__name__) 35 34 36 class Registry(ExtensionRegistry): 35 37 """ … … 99 101 msg = "DataLoader couldn't locate DataLoader plugin folder." 100 102 msg += """ "%s" does not exist""" % dir 101 logg ing.warning(msg)103 logger.warning(msg) 102 104 return readers_found 103 105 … … 117 119 msg = "Loader: Error importing " 118 120 msg += "%s\n %s" % (item, sys.exc_value) 119 logg ing.error(msg)121 logger.error(msg) 120 122 121 123 # Process zip files … … 139 141 msg = "Loader: Error importing" 140 142 msg += " %s\n %s" % (mfile, sys.exc_value) 141 logg ing.error(msg)143 logger.error(msg) 142 144 143 145 except: 144 146 msg = "Loader: Error importing " 145 147 msg += " %s\n %s" % (item, sys.exc_value) 146 logg ing.error(msg)148 logger.error(msg) 147 149 148 150 return readers_found … … 190 192 msg = "Loader: Error accessing" 191 193 msg += " Reader in %s\n %s" % (module.__name__, sys.exc_value) 192 logg ing.error(msg)194 logger.error(msg) 193 195 return reader_found 194 196 … … 223 225 msg = "Loader: Error accessing Reader " 224 226 msg += "in %s\n %s" % (loader.__name__, sys.exc_value) 225 logg ing.error(msg)227 logger.error(msg) 226 228 return reader_found 227 229 … … 268 270 msg = "Loader: Error accessing Reader" 269 271 msg += " in %s\n %s" % (module.__name__, sys.exc_value) 270 logg ing.error(msg)272 logger.error(msg) 271 273 return reader_found 272 274 -
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
r9a5097c r235f514 128 128 if new_lentoks > 2: 129 129 _dy = float(toks[2]) 130 has_error_dy = False if _dy ==None else True130 has_error_dy = False if _dy is None else True 131 131 132 132 # If a 4th row is present, consider it dx 133 133 if new_lentoks > 3: 134 134 _dx = float(toks[3]) 135 has_error_dx = False if _dx ==None else True135 has_error_dx = False if _dx is None else True 136 136 137 137 # Delete the previously stored lines of data candidates if -
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
r1b9a367 rcbb9551 33 33 import xml.dom.minidom 34 34 from xml.dom.minidom import parseString 35 36 logger = logging.getLogger(__name__) 35 37 36 38 PREPROCESS = "xmlpreprocess" … … 990 992 :param data1d: presumably a Data1D object 991 993 """ 992 if self.current_dataset ==None:994 if self.current_dataset is None: 993 995 x_vals = np.empty(0) 994 996 y_vals = np.empty(0) … … 1078 1080 # Write the file 1079 1081 file_ref = open(filename, 'w') 1080 if self.encoding ==None:1082 if self.encoding is None: 1081 1083 self.encoding = "UTF-8" 1082 1084 doc.write(file_ref, encoding=self.encoding, … … 1201 1203 :param entry_node: lxml node ElementTree object to be appended to 1202 1204 """ 1203 if datainfo.run ==None or datainfo.run == []:1205 if datainfo.run is None or datainfo.run == []: 1204 1206 datainfo.run.append(RUN_NAME_DEFAULT) 1205 1207 datainfo.run_name[RUN_NAME_DEFAULT] = RUN_NAME_DEFAULT … … 1245 1247 sesans.text = str(datainfo.isSesans) 1246 1248 node.append(sesans) 1249 self.write_node(node, "yacceptance", datainfo.sample.yacceptance[0], 1250 {'unit': datainfo.sample.yacceptance[1]}) 1247 1251 self.write_node(node, "zacceptance", datainfo.sample.zacceptance[0], 1248 1252 {'unit': datainfo.sample.zacceptance[1]}) … … 1317 1321 self.write_node(point, "T", spectrum.transmission[i], 1318 1322 {'unit': spectrum.transmission_unit}) 1319 if spectrum.transmission_deviation !=None \1323 if spectrum.transmission_deviation is not None \ 1320 1324 and len(spectrum.transmission_deviation) >= i: 1321 1325 self.write_node(point, "Tdev", … … 1397 1401 str(datainfo.source.name)) 1398 1402 self.append(source, instr) 1399 if datainfo.source.radiation ==None or datainfo.source.radiation == '':1403 if datainfo.source.radiation is None or datainfo.source.radiation == '': 1400 1404 datainfo.source.radiation = "neutron" 1401 1405 self.write_node(source, "radiation", datainfo.source.radiation) … … 1438 1442 :param instr: lxml node ElementTree object to be appended to 1439 1443 """ 1440 if datainfo.collimation == [] or datainfo.collimation ==None:1444 if datainfo.collimation == [] or datainfo.collimation is None: 1441 1445 coll = Collimation() 1442 1446 datainfo.collimation.append(coll) … … 1483 1487 :param inst: lxml instrument node to be appended to 1484 1488 """ 1485 if datainfo.detector ==None or datainfo.detector == []:1489 if datainfo.detector is None or datainfo.detector == []: 1486 1490 det = Detector() 1487 1491 det.name = "" … … 1659 1663 local_unit = None 1660 1664 exec "local_unit = storage.%s_unit" % toks[0] 1661 if local_unit !=None and units.lower() != local_unit.lower():1665 if local_unit is not None and units.lower() != local_unit.lower(): 1662 1666 if HAS_CONVERTER == True: 1663 1667 try: … … 1672 1676 self.errors.add(err_mess) 1673 1677 if optional: 1674 logg ing.info(err_mess)1678 logger.info(err_mess) 1675 1679 else: 1676 1680 raise ValueError, err_mess … … 1681 1685 self.errors.add(err_mess) 1682 1686 if optional: 1683 logg ing.info(err_mess)1687 logger.info(err_mess) 1684 1688 else: 1685 1689 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
ra235f715 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) … … 71 73 self.xmlroot = self.xmldoc.getroot() 72 74 except etree.XMLSyntaxError as xml_error: 73 logg ing.info(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
Note: See TracChangeset
for help on using the changeset viewer.