Changeset fa38d83 in sasview for sansview/plugins


Ignore:
Timestamp:
Sep 29, 2008 9:47:47 AM (16 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
65b788b2
Parents:
fa9674b
Message:

example plugin for sansview

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansview/plugins/testmodel.py

    rb30f001 rfa38d83  
    22    Test plug-in model 
    33""" 
    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 # 
     4from sans.models.pluginmodel import Model1DPlugin 
    135import math 
    14 from sans.models.BaseComponent import BaseComponent 
    15 import math 
    16 class Model1DPlugin(BaseComponent): 
    17     ## Name of the model 
    18     name = "Plugin Model" 
    196 
    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) 
    567 
    578# Your model HAS to be called Model 
Note: See TracChangeset for help on using the changeset viewer.