Ignore:
Timestamp:
Dec 20, 2011 5:25:39 PM (13 years ago)
Author:
Jae Cho <jhjcho@…>
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:
b025572
Parents:
1352c78
Message:

more completion of custom model edit

Location:
fittingview/src/sans/perspectives/fitting/plugin_models
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • fittingview/src/sans/perspectives/fitting/plugin_models/sum_p1_p2.py

    r96814e1 r7c8d3093  
    22import copy 
    33from sans.models.pluginmodel import Model1DPlugin 
    4 # User can change the name of the model (only with single functional model) 
    5 from sans.models.CylinderModel import CylinderModel as P1 
    6 from sans.models.PolymerExclVolume import PolymerExclVolume as P2 
    7  
    8  
     4# Possible model names 
     5""" 
     6BCCrystalModel, BEPolyelectrolyte, BarBellModel, BinaryHSModel, BroadPeakModel, 
     7CSParallelepipedModel, CappedCylinderModel, CoreShellCylinderModel, 
     8CoreShellEllipsoidModel, CoreShellModel, CorrLengthModel, CylinderModel,  
     9DABModel, DebyeModel, EllipsoidModel, EllipticalCylinderModel, FCCrystalModel, 
     10FlexCylEllipXModel, FlexibleCylinderModel, FractalCoreShellModel, FractalModel, 
     11FuzzySphereModel, GaussLorentzGelModel, GuinierModel, GuinierPorodModel, 
     12HardsphereStructure, HayterMSAStructure, HollowCylinderModel, LamellarFFHGModel, 
     13LamellarModel, LamellarPCrystalModel, LamellarPSHGModel, LamellarPSModel, 
     14LineModel, LorentzModel, MultiShellModel, ParallelepipedModel, PeakGaussModel, 
     15PeakLorentzModel, PearlNecklaceModel, Poly_GaussCoil, PolymerExclVolume, 
     16PorodModel, PowerLawAbsModel, SCCrystalModel, SphereModel, SquareWellStructure, 
     17StackedDisksModel, StickyHSStructure, TeubnerStreyModel, TriaxialEllipsoidModel, 
     18TwoLorentzianModel, TwoPowerLawModel, VesicleModel 
     19""" 
     20## This is same as the Easy Custom Sum(p1 + p2)  
     21# 
     22#     Custom model = scale_factor * (P1 + P2) 
     23# 
     24## User can REPLACE model names below two arrowed lines (two names per line) 
     25from sans.models.CylinderModel import CylinderModel as P1          #<======== 
     26from sans.models.PolymerExclVolume import PolymerExclVolume as P2  #<======== 
     27 
     28#####DO NOT CHANGE ANYTHING BELOW THIS LINE  
     29#####------------------------------------------------------------------------ 
    930class Model(Model1DPlugin): 
    1031    """ 
     
    2344        ## Setting  model name model description 
    2445        self.description="" 
    25         self.name = "Sum[" + "P1(Cyl)"  +", "+ "P2(PEV)" + "]" 
     46        self.name = self._get_name(p_model1.name, p_model2.name) 
    2647        self.description = p_model1.name+"\n" 
    2748        self.description += p_model2.name+"\n" 
     
    5273        ## Parameter details [units, min, max] 
    5374        self._set_details() 
    54         self.details['scale_factor'] = ['',     None, None] 
     75        self.details['scale_factor'] = ['',  None, None] 
    5576 
    5677         
     
    96117        return obj 
    97118     
    98      
     119    def _get_name(self, name1, name2): 
     120        """ 
     121        Get combined name from two model names 
     122        """ 
     123        name = self._get_upper_name(name1) 
     124        name += "+" 
     125        name += self._get_upper_name(name2) 
     126        return name 
     127     
     128    def _get_upper_name(self, name=None): 
     129        """ 
     130        Get uppercase string from model name 
     131        """ 
     132        if name == None: 
     133            return "" 
     134        upper_name = "" 
     135        str_name = str(name) 
     136        for index in range(len(str_name)): 
     137            if str_name[index].isupper(): 
     138                upper_name += str_name[index] 
     139        return upper_name 
     140         
    99141    def _set_dispersion(self): 
    100142        """ 
     
    339381if __name__ == "__main__":  
    340382    m1= Model()  
    341     m1.setParam("p1_scale", 25)   
    342     m1.setParam("p1_length", 1000) 
    343     m1.setParam("p2_scale", 100)  
    344     m1.setParam("p2_rg", 100)  
     383    #m1.setParam("p1_scale", 25)   
     384    #m1.setParam("p1_length", 1000) 
     385    #m1.setParam("p2_scale", 100)  
     386    #m1.setParam("p2_rg", 100)  
    345387    out1 = m1.runXY(0.01) 
    346388 
    347389    m2= Model() 
    348     m2.p_model1.setParam("scale", 25)  
    349     m2.p_model1.setParam("length", 1000)  
    350     m2.p_model2.setParam("scale", 100) 
    351     m2.p_model2.setParam("rg", 100) 
     390    #m2.p_model1.setParam("scale", 25)  
     391    #m2.p_model1.setParam("length", 1000)  
     392    #m2.p_model2.setParam("scale", 100) 
     393    #m2.p_model2.setParam("rg", 100) 
    352394    out2 = m2.p_model1.runXY(0.01) + m2.p_model2.runXY(0.01) 
     395    print "Testing at Q = 0.01:" 
    353396    print out1, " = ", out2 
    354  
    355     
     397    if out1 == out2: 
     398        print "===> Simple Test: Passed!" 
     399    else: 
     400        print "===> Simple Test: Failed!" 
  • fittingview/src/sans/perspectives/fitting/plugin_models/testmodel.py

    r96814e1 r7c8d3093  
    77""" 
    88from sans.models.pluginmodel import Model1DPlugin  ##DO NOT CHANGE THIS LINE!!! 
    9 from math import *                    ##DO NOT CHANGE THIS LINE!!! 
    10 from numpy import *                ##DO NOT CHANGE THIS LINE!!! 
     9import math                  ##DO NOT CHANGE THIS LINE!!! 
     10import numpy               ##DO NOT CHANGE THIS LINE!!! 
    1111 
    1212##PLEASE READ COMMENTS CAREFULLY !!! COMMENT ARE IN CAPITAL LETTERS AND AFTER ## 
     
    8383        ## numpy FUNCTIONS ARE FOR EXPERT USER 
    8484         
    85         return self.params['A']+self.params['B']*cos(2.0*x)+self.params['C']*math.sin(2.0*x) 
    86     
     85        return self.params['A']+self.params['B']*math.cos(2.0*x)+self.params['C']*math.sin(2.0*x) 
     86     
     87## DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!!        
     88if __name__ == "__main__":  
     89    m= Model()  
     90    out1 = m.runXY(0.0) 
     91    out2 = m.runXY(0.01) 
     92    isfine1 = numpy.isfinite(out1) 
     93    isfine2 = numpy.isfinite(out2) 
     94    print "Testing the value at Q = 0.0:" 
     95    print out1, " : finite? ", isfine1 
     96    print "Testing the value at Q = 0.01:" 
     97    print out2, " : finite? ", isfine2 
     98    if isfine1 and isfine2: 
     99        print "===> Simple Test: Passed!" 
     100    else: 
     101        print "===> Simple Test: Failed!" 
  • fittingview/src/sans/perspectives/fitting/plugin_models/testmodel_2.py

    r96814e1 r7c8d3093  
    133133            result = 1                      ## <-----    
    134134        else:                               ## <-----    
    135             result = sin(poly)/poly    ## <-----    
     135            result = math.sin(poly)/poly    ## <-----    
    136136             
    137137        #Re-scale                          ## <-----    
     
    139139 
    140140        return result ## MODIFY ONLY RESULT. DON'T DELETE RETURN!!!! 
    141     
     141     
     142## DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!!        
     143if __name__ == "__main__":  
     144    m= Model()  
     145    out1 = m.runXY(0.0) 
     146    out2 = m.runXY(0.01) 
     147    isfine1 = numpy.isfinite(out1) 
     148    isfine2 = numpy.isfinite(out2) 
     149    print "Testing the value at Q = 0.0:" 
     150    print out1, " : finite? ", isfine1 
     151    print "Testing the value at Q = 0.01:" 
     152    print out2, " : finite? ", isfine2 
     153    if isfine1 and isfine2: 
     154        print "===> Simple Test: Passed!" 
     155    else: 
     156        print "===> Simple Test: Failed!" 
Note: See TracChangeset for help on using the changeset viewer.