Changeset 7c8d3093 in sasview for fittingview/src/sans/perspectives/fitting/plugin_models
- Timestamp:
- Dec 20, 2011 5:25:39 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:
- b025572
- Parents:
- 1352c78
- 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 2 2 import copy 3 3 from 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 """ 6 BCCrystalModel, BEPolyelectrolyte, BarBellModel, BinaryHSModel, BroadPeakModel, 7 CSParallelepipedModel, CappedCylinderModel, CoreShellCylinderModel, 8 CoreShellEllipsoidModel, CoreShellModel, CorrLengthModel, CylinderModel, 9 DABModel, DebyeModel, EllipsoidModel, EllipticalCylinderModel, FCCrystalModel, 10 FlexCylEllipXModel, FlexibleCylinderModel, FractalCoreShellModel, FractalModel, 11 FuzzySphereModel, GaussLorentzGelModel, GuinierModel, GuinierPorodModel, 12 HardsphereStructure, HayterMSAStructure, HollowCylinderModel, LamellarFFHGModel, 13 LamellarModel, LamellarPCrystalModel, LamellarPSHGModel, LamellarPSModel, 14 LineModel, LorentzModel, MultiShellModel, ParallelepipedModel, PeakGaussModel, 15 PeakLorentzModel, PearlNecklaceModel, Poly_GaussCoil, PolymerExclVolume, 16 PorodModel, PowerLawAbsModel, SCCrystalModel, SphereModel, SquareWellStructure, 17 StackedDisksModel, StickyHSStructure, TeubnerStreyModel, TriaxialEllipsoidModel, 18 TwoLorentzianModel, 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) 25 from sans.models.CylinderModel import CylinderModel as P1 #<======== 26 from sans.models.PolymerExclVolume import PolymerExclVolume as P2 #<======== 27 28 #####DO NOT CHANGE ANYTHING BELOW THIS LINE 29 #####------------------------------------------------------------------------ 9 30 class Model(Model1DPlugin): 10 31 """ … … 23 44 ## Setting model name model description 24 45 self.description="" 25 self.name = "Sum[" + "P1(Cyl)" +", "+ "P2(PEV)" + "]"46 self.name = self._get_name(p_model1.name, p_model2.name) 26 47 self.description = p_model1.name+"\n" 27 48 self.description += p_model2.name+"\n" … … 52 73 ## Parameter details [units, min, max] 53 74 self._set_details() 54 self.details['scale_factor'] = ['', 75 self.details['scale_factor'] = ['', None, None] 55 76 56 77 … … 96 117 return obj 97 118 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 99 141 def _set_dispersion(self): 100 142 """ … … 339 381 if __name__ == "__main__": 340 382 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) 345 387 out1 = m1.runXY(0.01) 346 388 347 389 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) 352 394 out2 = m2.p_model1.runXY(0.01) + m2.p_model2.runXY(0.01) 395 print "Testing at Q = 0.01:" 353 396 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 7 7 """ 8 8 from 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!!!9 import math ##DO NOT CHANGE THIS LINE!!! 10 import numpy ##DO NOT CHANGE THIS LINE!!! 11 11 12 12 ##PLEASE READ COMMENTS CAREFULLY !!! COMMENT ARE IN CAPITAL LETTERS AND AFTER ## … … 83 83 ## numpy FUNCTIONS ARE FOR EXPERT USER 84 84 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!!!!!!!!!!!!!!!! 88 if __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 133 133 result = 1 ## <----- 134 134 else: ## <----- 135 result = sin(poly)/poly ## <-----135 result = math.sin(poly)/poly ## <----- 136 136 137 137 #Re-scale ## <----- … … 139 139 140 140 return result ## MODIFY ONLY RESULT. DON'T DELETE RETURN!!!! 141 141 142 ## DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!! 143 if __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.