Changeset d83549c in sasview for calculatorview/src/sans/perspectives/calculator
- Timestamp:
- Jan 17, 2012 8:05:37 PM (13 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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 530cc84
- Parents:
- a8db60c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
calculatorview/src/sans/perspectives/calculator/model_editor.py
r7434020 rd83549c 221 221 self.name = 'untitled' 222 222 self.overwrite_name = True 223 self.is_2d = False 223 224 self.fname = None 224 225 self.param_strings = '' … … 472 473 lines = CUSTOM_TEMPLATE.split('\n') 473 474 has_scipy = func_str.count("scipy.") 475 self.is_2d = func_str.count("#self.ndim = 2") 476 line_2d = '' 477 if self.is_2d: 478 line_2d = CUSTOM_2D_TEMP.split('\n') 479 line_test = TEST_TEMPLATE.split('\n') 474 480 local_params = '' 475 481 spaces = ' '#8spaces 482 # write function here 476 483 for line in lines: 477 484 # The location where to put the strings is … … 492 499 desc= self.name 493 500 out_f.write(line% desc + "\n") 501 elif line.count("def function(self, x=0.0%s):"): 502 if self.is_2d: 503 y_str = ', y=0.0' 504 out_f.write(line% y_str + "\n") 505 else: 506 out_f.write(line% '' + "\n") 494 507 elif line.count("#function here"): 495 508 for func_line in func_str.split('\n'): … … 498 511 out_f.write(spaces + f_line + "\n") 499 512 if not func_str: 500 out_f.write(spaces + 'return y' + "\n") 513 dep_var = 'y' 514 if self.is_2d: 515 dep_var = 'z' 516 out_f.write(spaces + 'return %s'% dep_var + "\n") 501 517 elif line.count("#import scipy?"): 502 518 if has_scipy: … … 506 522 elif line: 507 523 out_f.write(line + "\n") 524 # run string for 2d 525 if line_2d: 526 for line in line_2d: 527 out_f.write(line + "\n") 528 # Test strins 529 for line in line_test: 530 out_f.write(line + "\n") 531 508 532 out_f.close() 509 533 … … 590 614 self.description = "%s" 591 615 self.set_details() 592 def function(self, x = 0.0):616 def function(self, x=0.0%s): 593 617 #local params here 594 #function here 618 #function here 619 """ 620 TEST_TEMPLATE = """ 595 621 ###################################################################### 596 622 ## THIS IS FOR TEST. DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!! … … 609 635 else: 610 636 print "===> Simple Test: Failed!" 611 """ 612 637 """ 638 CUSTOM_2D_TEMP = """ 639 def run(self, x=0.0): 640 if x.__class__.__name__ == 'list': 641 x_val = x[0]*math.cos(x[1]) 642 y_val = x[0]*math.sin(x[1]) 643 return self.function(x_val, y_val) 644 elif x.__class__.__name__ == 'tuple': 645 msg = "Tuples are not allowed as input to BaseComponent models" 646 raise ValueError, msg 647 else: 648 return self.function(x, x) 649 def runXY(self, x=0.0, y=0.0): 650 if x.__class__.__name__ == 'list': 651 return self.function(x, y) 652 elif x.__class__.__name__ == 'tuple': 653 msg = "Tuples are not allowed as input to BaseComponent models" 654 raise ValueError, msg 655 else: 656 return self.function(x, y) 657 def evalDistribution(self, qdist): 658 if qdist.__class__.__name__ == 'list': 659 msg = "evalDistribution expects a list of 2 ndarrays" 660 if len(qdist)!=2: 661 raise RuntimeError, msg 662 if qdist[0].__class__.__name__ != 'ndarray': 663 raise RuntimeError, msg 664 if qdist[1].__class__.__name__ != 'ndarray': 665 raise RuntimeError, msg 666 v_model = numpy.vectorize(self.runXY, otypes=[float]) 667 iq_array = v_model(qdist[0], qdist[1]) 668 return iq_array 669 elif qdist.__class__.__name__ == 'ndarray': 670 v_model = numpy.vectorize(self.runXY, otypes=[float]) 671 iq_array = v_model(qdist) 672 return iq_array 673 """ 613 674 SUM_TEMPLATE = """ 614 675 # A sample of an experimental model function for Sum(Pmodel1,Pmodel2)
Note: See TracChangeset
for help on using the changeset viewer.