Changeset 574adc7 in sasview for src/sas/sascalc/fit
- Timestamp:
- Sep 22, 2017 4:01:32 PM (7 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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 34d7b35
- Parents:
- 9706d88
- Location:
- src/sas/sascalc/fit
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/sas/sascalc/fit/AbstractFitEngine.py ¶
r50fcb09 r574adc7 251 251 msg = "FitData1D: invalid error array " 252 252 msg += "%d <> %d" % (np.shape(self.dy), np.size(fx)) 253 raise RuntimeError , msg253 raise RuntimeError(msg) 254 254 return (self.y[self.idx] - fx[self.idx]) / self.dy[self.idx], fx[self.idx] 255 255 -
TabularUnified src/sas/sascalc/fit/Loader.py ¶
ra1b8fee r574adc7 18 18 self.dy = dy 19 19 self.filename = None 20 20 21 21 def set_filename(self, path=None): 22 22 """ 23 Store path into a variable.If the user doesn't give 23 Store path into a variable.If the user doesn't give 24 24 a path as a parameter a pop-up 25 25 window appears to select the file. 26 26 27 27 :param path: the path given by the user 28 28 29 29 """ 30 30 self.filename = path 31 31 32 32 def get_filename(self): 33 33 """ return the file's path""" 34 34 return self.filename 35 35 36 36 def set_values(self): 37 37 """ Store the values loaded from file in local variables""" … … 42 42 self.x = [] 43 43 self.y = [] 44 self.dx = [] 44 self.dx = [] 45 45 self.dy = [] 46 46 for line in lines: … … 50 50 y = float(toks[1]) 51 51 dy = float(toks[2]) 52 52 53 53 self.x.append(x) 54 54 self.y.append(y) … … 59 59 # Sanity check 60 60 if not len(self.x) == len(self.dx): 61 raise ValueError , "x and dx have different length"61 raise ValueError("x and dx have different length") 62 62 if not len(self.y) == len(self.dy): 63 raise ValueError , "y and dy have different length"64 65 63 raise ValueError("y and dy have different length") 64 65 66 66 def get_values(self): 67 67 """ Return x, y, dx, dy""" 68 68 return self.x, self.y, self.dx, self.dy 69 69 70 70 def load_data(self, data): 71 71 """ Return plottable""" … … 77 77 #Load its View class 78 78 #plottable.reset_view() 79 80 81 if __name__ == "__main__": 79 80 81 if __name__ == "__main__": 82 82 load = Load() 83 83 load.set_filename("testdata_line.txt") 84 print(load.get_filename()) 84 print(load.get_filename()) 85 85 load.set_values() 86 86 print(load.get_values()) 87 88 87 -
TabularUnified src/sas/sascalc/fit/MultiplicationModel.py ¶
r7432acb r574adc7 109 109 """ 110 110 ##set dispersion only from p_model 111 for name , value in self.p_model.dispersion.ite ritems():111 for name , value in self.p_model.dispersion.items(): 112 112 self.dispersion[name] = value 113 113 … … 135 135 """ 136 136 137 for name , value in self.p_model.params.ite ritems():137 for name , value in self.p_model.params.items(): 138 138 if not name in self.params.keys() and name not in self.excluded_params: 139 139 self.params[name] = value 140 140 141 for name , value in self.s_model.params.ite ritems():141 for name , value in self.s_model.params.items(): 142 142 #Remove the radius_effective from the (P*S) model parameters. 143 143 if not name in self.params.keys() and name not in self.excluded_params: … … 155 155 this model's details 156 156 """ 157 for name, detail in self.p_model.details.ite ritems():157 for name, detail in self.p_model.details.items(): 158 158 if name not in self.excluded_params: 159 159 self.details[name] = detail 160 160 161 for name , detail in self.s_model.details.ite ritems():161 for name , detail in self.s_model.details.items(): 162 162 if not name in self.details.keys() or name not in self.exluded_params: 163 163 self.details[name] = detail … … 245 245 return 246 246 247 raise ValueError , "Model does not contain parameter %s" % name247 raise ValueError("Model does not contain parameter %s" % name) 248 248 249 249 -
TabularUnified src/sas/sascalc/fit/expression.py ¶
ra1b8fee r574adc7 59 59 occur multiple times. The return value is a set with the elements in 60 60 no particular order. 61 61 62 62 This is the first step in computing a dependency graph. 63 63 """ … … 81 81 offset = end 82 82 pieces.append(expr[offset:]) 83 83 84 84 # Join the pieces and return them 85 85 return "".join(pieces) … … 88 88 """ 89 89 Returns a list of pair-wise dependencies from the parameter expressions. 90 90 91 91 For example, if p3 = p1+p2, then find_dependencies([p1,p2,p3]) will 92 92 return [(p3,p1),(p3,p2)]. For base expressions without dependencies, … … 110 110 """ 111 111 Find the parameter substitution we need so that expressions can 112 be evaluated without having to traverse a chain of 112 be evaluated without having to traverse a chain of 113 113 model.layer.parameter.value 114 114 """ … … 122 122 return definition, substitution 123 123 124 def no_constraints(): 124 def no_constraints(): 125 125 """ 126 126 This parameter set has no constraints between the parameters. … … 163 163 164 164 Parameter names are assumed to contain only _.a-zA-Z0-9#[] 165 165 166 166 Both names are provided for inverse functions, e.g., acos and arccos. 167 167 168 168 Should try running the function to identify syntax errors before 169 169 running it in a fit. 170 170 171 171 Use help(fn) to see the code generated for the returned function fn. 172 172 dis.dis(fn) will show the corresponding python vm instructions. … … 239 239 if independent == emptyset: 240 240 cycleset = ", ".join(str(s) for s in left) 241 raise ValueError ,"Cyclic dependencies amongst %s"%cycleset241 raise ValueError("Cyclic dependencies amongst %s"%cycleset) 242 242 243 243 # The possibly resolvable items are those that depend on the independents … … 267 267 n.sort() 268 268 items = list(items); items.sort() 269 raise Exception,"%s expect %s to contain %s for %s"%(msg,n,items,pairs)269 raise ValueError("%s expect %s to contain %s for %s"%(msg,n,items,pairs)) 270 270 for lo,hi in pairs: 271 271 if lo in n and hi in n and n.index(lo) >= n.index(hi): 272 raise Exception,"%s expect %s before %s in %s for %s"%(msg,lo,hi,n,pairs)272 raise ValueError("%s expect %s before %s in %s for %s"%(msg,lo,hi,n,pairs)) 273 273 274 274 def test_deps(): … … 288 288 # Cycle test 289 289 pairs = [(1,4),(4,3),(4,5),(5,1)] 290 try: n = order_dependencies(pairs) 291 except ValueError: pass 292 else: raise Exception,"test3 expect ValueError exception for %s"%(pairs,) 290 try: 291 n = order_dependencies(pairs) 292 except ValueError: 293 pass 294 else: 295 raise ValueError("test3 expect ValueError exception for %s"%(pairs,)) 293 296 294 297 # large test for gross speed check … … 308 311 import inspect, dis 309 312 import math 310 313 311 314 symtab = {'a.b.x':1, 'a.c':2, 'a.b':3, 'b.x':4} 312 315 expr = 'a.b.x + sin(4*pi*a.c) + a.b.x/a.b' 313 316 314 317 # Check symbol lookup 315 318 assert _symbols(expr, symtab) == set([1,2,3]) … … 357 360 expected = 2*math.pi*math.sin(5/.1875) + 6 358 361 assert p2.value == expected,"Value was %s, not %s"%(p2.value,expected) 359 362 360 363 # Check empty dependency set doesn't crash 361 364 fn = compile_constraints(*world(p1,p3)) … … 381 384 fn() 382 385 assert p5.value == 2.07,"Value for %s was %s"%(p5.expression,p5.value) 383 386 384 387 385 388 # Verify that we capture invalid expressions 386 for expr in ['G4.cage', 'M0.cage', 'M1.G1 + *2', 389 for expr in ['G4.cage', 'M0.cage', 'M1.G1 + *2', 387 390 'piddle', 388 391 '5; import sys; print "p0wned"', -
TabularUnified src/sas/sascalc/fit/pagestate.py ¶
r277257f r574adc7 313 313 314 314 if len(self.disp_obj_dict) > 0: 315 for k, v in self.disp_obj_dict.ite ritems():315 for k, v in self.disp_obj_dict.items(): 316 316 obj.disp_obj_dict[k] = v 317 317 if len(self.disp_cb_dict) > 0: 318 for k, v in self.disp_cb_dict.ite ritems():318 for k, v in self.disp_cb_dict.items(): 319 319 obj.disp_cb_dict[k] = v 320 320 if len(self.values) > 0: 321 for k, v in self.values.ite ritems():321 for k, v in self.values.items(): 322 322 obj.values[k] = v 323 323 if len(self.weights) > 0: 324 for k, v in self.weights.ite ritems():324 for k, v in self.weights.items(): 325 325 obj.weights[k] = v 326 326 obj.enable_smearer = copy.deepcopy(self.enable_smearer) … … 347 347 obj.version = copy.deepcopy(self.version) 348 348 349 for name, state in self.saved_states.ite ritems():349 for name, state in self.saved_states.items(): 350 350 copy_name = copy.deepcopy(name) 351 351 copy_state = state.clone() … … 430 430 """ 431 431 p_map = [] 432 for name, info in params.ite ritems():432 for name, info in params.items(): 433 433 if ".fittable" in name or ".std" in name or ".upper" in name or \ 434 434 ".lower" in name or ".units" in name: … … 475 475 formfactor, str_params = convert.convert_model( 476 476 self.formfactorcombobox, str_pars, False, self.version) 477 for key, value in str_params.ite ritems():477 for key, value in str_params.items(): 478 478 params[key] = value 479 479 … … 835 835 element = newdoc.createElement(item[0]) 836 836 value_list = getattr(self, item[1]) 837 for key, value in value_list.ite ritems():837 for key, value in value_list.items(): 838 838 sub_element = newdoc.createElement(key) 839 839 sub_element.setAttribute('name', str(key)) … … 848 848 element = newdoc.createElement(tagname) 849 849 value_list = getattr(self, varname) 850 for key, value in value_list.ite ritems():850 for key, value in value_list.items(): 851 851 sub_element = newdoc.createElement(key) 852 852 sub_element.setAttribute('name', str(key)) … … 950 950 msg = "PageState no longer supports non-CanSAS" 951 951 msg += " format for fitting files" 952 raise RuntimeError , msg952 raise RuntimeError(msg) 953 953 954 954 if node.get('version'): … … 1241 1241 else: 1242 1242 self.call_back(format=ext) 1243 raise RuntimeError , "%s is not a file" % path1243 raise RuntimeError("%s is not a file" % path) 1244 1244 1245 1245 # Return output consistent with the loader's api -
TabularUnified src/sas/sascalc/fit/pluginmodel.py ¶
r5213d22 r574adc7 35 35 return self.function(x_val)*self.function(y_val) 36 36 elif x.__class__.__name__ == 'tuple': 37 raise ValueError , "Tuples are not allowed as input to BaseComponent models"37 raise ValueError("Tuples are not allowed as input to BaseComponent models") 38 38 else: 39 39 return self.function(x) … … 52 52 return self.function(x[0])*self.function(x[1]) 53 53 elif x.__class__.__name__ == 'tuple': 54 raise ValueError , "Tuples are not allowed as input to BaseComponent models"54 raise ValueError("Tuples are not allowed as input to BaseComponent models") 55 55 else: 56 56 return self.function(x)
Note: See TracChangeset
for help on using the changeset viewer.