Changeset 0abf7bf in sasview for sansmodels
- Timestamp:
- Nov 23, 2011 3:16: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:
- 26da93f
- Parents:
- 953fe92
- Location:
- sansmodels
- Files:
-
- 17 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/setup.py
rd7a2531 r0abf7bf 1 1 """ 2 2 Installation script for SANS models 3 4 - To compile and install:5 python setup.py install6 - To create distribution:7 python setup.py bdist_wininst8 - To create odb files:9 python setup.py odb10 11 3 """ 12 4 13 5 import sys 14 6 import os 15 16 17 7 from numpy.distutils.misc_util import get_numpy_include_dirs 18 8 numpy_incl_path = os.path.join(get_numpy_include_dirs()[0], "numpy") 19 20 def createODBcontent(class_name): 21 """ 22 Return the content of the Pyre odb file for a given class 23 @param class_name: Name of the class to write an odb file for [string] 24 @return: content of the file [string] 25 """ 26 content = "\"\"\"\n" 27 content += " Facility for SANS model\n\n" 28 content += " WARNING: THIS FILE WAS AUTOGENERATED AT INSTALL TIME\n" 29 content += " DO NOT MODIFY\n\n" 30 content += " This code was written as part of the DANSE project\n" 31 content += " http://danse.us/trac/sans/\n" 32 content += " @copyright 2007:" 33 content += " SANS/DANSE Group (University of Tennessee), for the DANSE project\n\n" 34 content += "\"\"\"\n" 35 content += "def model():\n" 36 content += " from ScatteringIntensityFactory import ScatteringIntensityFactory\n" 37 content += " from sans.models.%s import %s\n" % (class_name, class_name) 38 content += " return ScatteringIntensityFactory(%s)('%s')\n"\ 39 % (class_name, class_name) 40 41 return content 42 43 def createODBfiles(): 44 """ 45 Create odb files for all available models 46 """ 47 from sans.models.ModelFactory import ModelFactory 48 49 class_list = ModelFactory().getAllModels() 50 for name in class_list: 51 odb = open("src/sans/models/pyre/%s.odb" % name, 'w') 52 odb.write(createODBcontent(name)) 53 odb.close() 54 print "src/sans/models/pyre/%s.odb created" % name 55 56 # 57 # Proceed with installation 58 # 59 60 # First, create the odb files 61 if len(sys.argv) > 1 and sys.argv[1].lower() == 'odb': 62 print "Creating odb files" 63 try: 64 createODBfiles() 65 except: 66 print "ERROR: could not create odb files" 67 print sys.exc_value 68 sys.exit() 69 9 70 10 # Then build and install the modules 71 11 from distutils.core import Extension, setup … … 139 79 package_data={'sans.models': [os.path.join('media', "*")]}, 140 80 packages = ["sans","sans.models", 141 "sans.models.sans_extension", "sans.models.pyre",],81 "sans.models.sans_extension",], 142 82 143 83 ext_modules = [ Extension("sans.models.sans_extension.c_models", -
sansmodels/src/sans/models/DisperseModel.py
r79ac6f8 r0abf7bf 24 24 Example: :: 25 25 26 cyl = ModelFactory().getModel("CylinderModel")26 cyl = CylinderModel() 27 27 disp = DisperseModel(cyl, ['cyl_phi'], [0.3]) 28 28 disp.run([0.01, 1.57]) -
sansmodels/src/sans/models/__init__.py
rb1a65b6 r0abf7bf 48 48 # To create a model: 49 49 # \verbatim 50 #from sans.models. ModelFactory import ModelFactory51 # cyl = ModelFactory().getModel('CylinderModel')50 #from sans.models.CylinderModel import CylinderModel 51 # cyl = CylinderModel() 52 52 # \endverbatim 53 53 # -
sansmodels/test/SmearList.py
r18e250c r0abf7bf 1 1 2 from sans.models.ModelFactory import ModelFactory3 2 from sans.models.BaseComponent import BaseComponent 4 3 import math … … 15 14 16 15 ## Model to smear 17 #self.model = factory.getModel(model_name)18 16 self.model = model 19 17 ## Standard deviation of the smearing … … 53 51 54 52 # Gaussian function used to weigh points 55 #gaussian = ModelFactory().getModel("Gaussian")56 53 gaussian = Gaussian() 57 54 gaussian.setParam('sigma', self.sigmas[id]) … … 162 159 163 160 return value 164 165 # main166 if __name__ == '__main__':167 import math168 if True:169 cyl = ModelFactory().getModel("CylinderModel")170 cyl.setParam('length', 2000.0)171 cyl.setParam('cyl_phi', .45)172 cyl.setParam('cyl_theta', 2.)173 #app = Smear(cyl,['cyl_theta', 'cyl_phi'], [.01, .01])174 #app = Smear(cyl,['cyl_theta', 'cyl_phi'], [2.0, 2.0])175 #app = Smear(cyl,['cyl_theta'], [2.5])176 app = Smear(cyl, ['cyl_phi', 'cyl_theta'], [math.pi, math.pi])177 #app = Smear(cyl,['scale', 'scale'],[.5,1.0])178 val_no = cyl.run([.001, 1.0])179 print "Cylinder (no smear) f(.1):", val_no180 val_sm = app.run([.001, 1.0])181 print "Cylinder (smear) f(.1):", val_sm, app.error, app.error/val_sm182 print "Cylinder (1D) f(.1):", cyl.run(.001), cyl.run(.001)/val_sm183 184 185 print "--------------"186 sinsin = ModelFactory().getModel("SinSin")187 sinsin.setParam('a', -1.7)188 sinsin.setParam('b', 5.45)189 #app = Smear(sinsin, ['A'], [3.1])190 #app = Smear(sinsin, ['A', 'b'], [math.pi/2.0, .0])191 app = Smear(sinsin, ['A'], [math.pi/2.0])192 #app = Smear(cyl,['scale', 'scale'],[.5,1.0])193 val_no = sinsin.run(1.0)194 print "SinSin (no smear) :", val_no195 val_sm = app.run(1.0)196 print "SinSin (smear) : %g +- %g" % (val_sm, app.error)197 -
sansmodels/test/utest_disperser.py
r77220ee r0abf7bf 15 15 16 16 from sans.models.sans_extension.c_models import Disperser 17 from sans.models. ModelFactory import ModelFactory17 from sans.models.CylinderModel import CylinderModel 18 18 from sans.models.DisperseModel import DisperseModel 19 19 … … 22 22 23 23 def setUp(self): 24 self.model = ModelFactory().getModel("CylinderModel")24 self.model = CylinderModel() 25 25 self.model.setParam("cyl_theta", 1.57) 26 26 self.model.setParam("cyl_phi", 0.1) … … 84 84 85 85 def setUp(self): 86 self.model = ModelFactory().getModel("CylinderModel")86 self.model = CylinderModel() 87 87 self.model.setParam("cyl_theta", 1.57) 88 88 self.model.setParam("cyl_phi", 0.1) -
sansmodels/test/utest_models.py
r18e250c r0abf7bf 63 63 self.comp.setParam('cyl_phi', 1*180/math.pi) 64 64 self.assertAlmostEqual(self.comp.run([0.2, 2.5]), 65 0.038176446608393366, 4) 66 67 def testIO(self): 68 from sans.models.ModelFactory import ModelFactory 69 from sans.models.ModelIO import ModelIO 70 factory = ModelFactory() 71 io = ModelIO(factory) 72 io.save(self.comp,"myModel.xml") 73 value = self.comp.run(1) 74 loaded = io.load("myModel.xml") 75 self.assertEqual(value, loaded.run(1)) 76 77 def testIO_add(self): 78 # version 0.5.0: No longer supported 79 return 80 from sans.models.ModelFactory import ModelFactory 81 from sans.models.ModelIO import ModelIO 82 factory = ModelFactory() 83 io = ModelIO(factory) 84 sph = factory.getModel("SphereModel") 85 cyl = factory.getModel("CylinderModel") 86 combo = sph - cyl 87 io.save(combo,"myModel.xml") 88 value = combo.run(1) 89 loaded = io.load("myModel.xml") 90 self.assertEqual(value, loaded.run(1)) 91 92 def testIO_add2(self): 93 # version 0.5.0: No longer supported 94 return 95 from sans.models.ModelFactory import ModelFactory 96 #from sans.models.ModelIO import ModelIO 97 factory = ModelFactory() 98 #io = ModelIO(factory) 99 sph = factory.getModel("SphereModel") 100 cyl = factory.getModel("CylinderModel") 101 sph2 = factory.getModel("SphereModel") 102 combo1 = cyl - sph 103 combo = combo1 / sph2 104 #combo1 = sph 105 #io.save(combo,"myModel.xml") 106 # Just check that we have some output 107 self.assertTrue(math.fabs(combo.run(1))>0) 108 #loaded = io.load("myModel.xml") 109 #self.assertEqual(value, loaded.run(1)) 110 111 112 113 114 class TestFactory(unittest.TestCase): 115 """Unit tests for Model Factory""" 116 117 def setUp(self): 118 from sans.models.ModelFactory import ModelFactory 119 self.comp = ModelFactory().getModel('CylinderModel') 120 121 def test1D(self): 122 """ Test 1D model of a cylinder """ 123 self.assertAlmostEqual(self.comp.run(0.2), 0.041761386790780453, 4) 124 65 0.038176446608393366, 4) 125 66 126 67 class TestGaussian(unittest.TestCase): -
sansmodels/test/validate_1D_model.py
r18e250c r0abf7bf 25 25 @param filename: name of the test data set 26 26 """ 27 from sans.models. ModelFactory import ModelFactory27 from sans.models.CylinderModel import CylinderModel 28 28 29 29 # Read the data file … … 46 46 print "Found class", toks[1] 47 47 classname = toks[1].lstrip().rstrip() 48 model_object = ModelFactory().getModel(classname) 48 exec "from sans.models.%s import %s" % (classname, classname) 49 exec "model_object = %s()" % classname 49 50 50 51 # Output file for plotting
Note: See TracChangeset
for help on using the changeset viewer.