Changeset b30f001 in sasview for sansview/plugins
- Timestamp:
- Sep 10, 2008 3:49:53 PM (16 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:
- 49b7efa
- Parents:
- aa92772
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/plugins/testmodel.py
raa92772 rb30f001 2 2 Test plug-in model 3 3 """ 4 try: 5 from DataPlugin import * 6 except: 7 import sys, os 8 print os.path.abspath('..') 9 sys.path.insert(1,os.path.abspath('..')) 10 from DataPlugin import * 11 print "Running independently" 4 #try: 5 # from DataPlugin import * 6 #except: 7 # import sys, os 8 # print os.path.abspath('..') 9 # sys.path.insert(1,os.path.abspath('..')) 10 # from DataPlugin import * 11 # print "Running independently" 12 # 13 import math 14 from sans.models.BaseComponent import BaseComponent 15 import math 16 class Model1DPlugin(BaseComponent): 17 ## Name of the model 18 name = "Plugin Model" 12 19 13 import math 20 def __init__(self): 21 """ Initialization """ 22 self.details = {} 23 self.params = {} 24 25 def function(self, x): 26 """ 27 Function to be implemented by the plug-in writer 28 """ 29 return x 30 31 def run(self, x = 0.0): 32 """ Evaluate the model 33 @param x: input x, or [x, phi] [radian] 34 @return: function value 35 """ 36 if x.__class__.__name__ == 'list': 37 x_val = x[0]*math.cos(x[1]) 38 y_val = x[0]*math.sin(x[1]) 39 return self.function(x_val)*self.function(y_val) 40 elif x.__class__.__name__ == 'tuple': 41 raise ValueError, "Tuples are not allowed as input to BaseComponent models" 42 else: 43 return self.function(x) 44 45 def runXY(self, x = 0.0): 46 """ Evaluate the model 47 @param x: input x, or [x, y] 48 @return: function value 49 """ 50 if x.__class__.__name__ == 'list': 51 return self.function(x[0])*self.function(x[1]) 52 elif x.__class__.__name__ == 'tuple': 53 raise ValueError, "Tuples are not allowed as input to BaseComponent models" 54 else: 55 return self.function(x) 14 56 15 57 # Your model HAS to be called Model … … 23 65 def __init__(self): 24 66 """ Initialization """ 25 26 Model1DPlugin.__init__(self) 67 27 68 28 69 ## Parameters definition and defaults
Note: See TracChangeset
for help on using the changeset viewer.