Changeset 5da3cc5 in sasview
- Timestamp:
- Jul 10, 2012 9:59:33 AM (12 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:
- 83d9120
- Parents:
- c2e5898
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
fittingview/src/sans/perspectives/fitting/models.py
ra269378 r5da3cc5 571 571 self.shape_indep_list.append(UnifiedPowerRgModel) 572 572 self.multi_func_list.append(UnifiedPowerRgModel) 573 574 from sans.models.UnifiedPowerRgModel2 import UnifiedPowerRgModel2 575 self.shape_indep_list.append(UnifiedPowerRgModel2) 576 self.multi_func_list.append(UnifiedPowerRgModel2) 573 577 574 578 from sans.models.LineModel import LineModel -
plottools/src/danse/common/plottools/PlotPanel.py
r8f59e95 r5da3cc5 906 906 id = wx.NewId() 907 907 slicerpop.AppendSeparator() 908 slicerpop.Append(id, '&Toggle Leg ned On/Off', 'Toggle Legend On/Off')908 slicerpop.Append(id, '&Toggle Legend On/Off', 'Toggle Legend On/Off') 909 909 wx.EVT_MENU(self, id, self.onLegend) 910 910 … … 953 953 Toggles whether legend is visible/not visible 954 954 """ 955 956 if not legOnOff:955 self.legend_on = legOnOff 956 if not self.legend_on: 957 957 for ax in self.axes: 958 958 self.remove_legend(ax) … … 972 972 973 973 self.subplot.figure.canvas.draw_idle() 974 self.legend_on = legOnOff 974 975 975 976 976 -
sansguiframe/src/sans/guiframe/local_perspectives/plotting/Plotter1D.py
r0899c82 r5da3cc5 677 677 678 678 self.onGridOnOff(self.graphApp.get_togglegrid()) 679 679 680 self.onLegend(self.graphApp.get_togglelegend()) 680 681 self.ChangeLegendLoc(self.graphApp.get_legend_loc()) -
sansmodels/include/dabmodel.h
rfa6db8b r5da3cc5 4 4 #include "parameters.hh" 5 5 6 /** 7 This software was developed by Institut Laue-Langevin as part of 8 Distributed Data Analysis of Neutron Scattering Experiments (DANSE). 9 10 Copyright 2012 Institut Laue-Langevin 11 12 **/ 6 13 7 14 -
sansmodels/include/libmultifunc/libfunc.h
r08648c0 r5da3cc5 10 10 double gamln(double x); 11 11 12 void gser(float *gamser, float a, float x, float *gln); 13 14 void gcf(float *gammcf, float a, float x, float *gln); 15 16 float gammp(float a,float x); 17 18 float erff(float x); 19 12 20 #endif -
sansmodels/src/c_models/libfunc.c
rf8644dd r5da3cc5 11 11 //used in Si func 12 12 13 int factorial(int i) 13 int factorial(int i) { 14 15 int k, j; 16 if (i<2){ 17 return 1; 18 } 19 20 k=1; 21 22 for(j=1;j<i;j++) { 23 k=k*(j+1); 24 } 25 26 return k; 27 28 } 29 30 31 32 // Used in pearl nec model 33 34 // Sine integral function: approximated within 1%!!! 35 36 // integral of sin(x)/x up to namx term nmax=6 looks the best. 37 38 double Si(double x) 14 39 15 40 { 16 17 int k, j;18 19 if (i<2){20 21 return 1;22 23 }24 25 k=1;26 27 for(j=1;j<i;j++)28 29 {30 31 k=k*(j+1);32 33 }34 35 return k;36 37 }38 39 40 41 // Used in pearl nec model42 43 // Sine integral function: approximated within 1%!!!44 45 // integral of sin(x)/x up to namx term nmax=6 looks the best.46 47 double Si(double x)48 49 {50 51 41 int i; 52 53 42 int nmax=6; 54 55 43 double out; 56 57 44 long double power; 58 59 45 double pi = 4.0*atan(1.0); 60 46 61 47 if (x >= pi*6.2/4.0){ 62 63 64 65 48 double out_sin = 0.0; 66 67 49 double out_cos = 0.0; 68 69 50 out = pi/2.0; 70 51 71 for (i=0; i<nmax-2; i+=1){ 72 52 for (i=0; i<nmax-2; i+=1) { 73 53 out_cos += pow(-1.0, i) * (double)factorial(2*i) / pow(x, 2*i+1); 74 75 54 out_sin += pow(-1.0, i) * (double)factorial(2*i+1) / pow(x, 2*i+2); 76 77 55 } 78 56 79 57 out -= cos(x) * out_cos; 80 81 58 out -= sin(x) * out_sin; 82 83 59 return out; 84 85 60 } 86 61 87 62 out = 0.0; 88 63 89 for (i=0; i<nmax; i+=1) 90 91 { 92 93 if (i==0){ 94 64 for (i=0; i<nmax; i+=1) { 65 if (i==0) { 95 66 out += x; 96 97 67 continue; 98 99 68 } 100 69 101 70 power = pow(x,(2 * i + 1)); 102 103 71 out += (double)pow(-1, i) * power / ((2.0 * (double)i + 1.0) * (double)factorial(2 * i + 1)); 104 72 105 73 //printf ("Si=%g %g %d\n", x, out, i); 106 107 74 } 108 75 109 76 return out; 110 111 77 } 112 78 … … 138 104 } 139 105 106 /** Modifications below by kieranrcampbell@gmail.com 107 Institut Laue-Langevin, July 2012 108 **/ 109 110 /** 111 Implements eq 6.2.5 (small gamma) of Numerical Recipes in C, essentially 112 the incomplete gamma function multiplied by the gamma function. 113 Required for implementation of fast error function (erf) 114 **/ 115 116 117 #define ITMAX 100 118 #define EPS 3.0e-7 119 #define FPMIN 1.0e-30 120 121 void gser(float *gamser, float a, float x, float *gln) { 122 int n; 123 float sum,del,ap; 124 125 *gln = gamln(a); 126 if(x <= 0.0) { 127 if (x < 0.0) printf("Error: x less than 0 in routine gser"); 128 *gamser = 0.0; 129 return; 130 } else { 131 ap = a; 132 del = sum = 1.0/a; 133 134 for(n=1;n<=ITMAX;n++) { 135 ++ap; 136 del *= x/ap; 137 sum += del; 138 if(fabs(del) < fabs(sum)*EPS) { 139 *gamser = sum * exp(-x + a * log(x) - (*gln)); 140 return; 141 } 142 } 143 printf("a too large, ITMAX too small in routine gser"); 144 return; 145 146 } 147 148 149 } 150 151 /** 152 Implements the incomplete gamma function Q(a,x) evaluated by its continued fraction 153 representation 154 **/ 155 156 void gcf(float *gammcf, float a, float x, float *gln) { 157 int i; 158 float an,b,c,d,del,h; 159 160 *gln = gamln(a); 161 b = x+1.0-a; 162 c = 1.0/FPMIN; 163 d = 1.0/b; 164 h=d; 165 for (i=1;i <= ITMAX; i++) { 166 an = -i*(i-a); 167 b += 2.0; 168 d = an*d + b; 169 if (fabs(d) < FPMIN) d = FPMIN; 170 c = b+an/c; 171 if (fabs(c) < FPMIN) c = FPMIN; 172 d = 1.0/d; 173 del = d*c; 174 h += del; 175 if (fabs(del-1.0) < EPS) break; 176 } 177 if (i > ITMAX) printf("a too large, ITMAX too small in gcf"); 178 *gammcf = exp(-x+a*log(x)-(*gln))*h; 179 return; 180 } 181 182 183 /** 184 Represents incomplete error function, P(a,x) 185 **/ 186 float gammp(float a, float x) { 187 float gamser,gammcf,gln; 188 if(x < 0.0 || a <= 0.0) printf("Invalid arguments in routine gammp"); 189 if (x < (a+1.0)) { 190 gser(&gamser,a,x,&gln); 191 return gamser; 192 } else { 193 gcf(&gammcf,a,x,&gln); 194 return 1.0 - gammcf; 195 } 196 } 197 198 /** 199 Implementation of the error function, erf(x) 200 **/ 201 202 float erff(float x) { 203 return x < 0.0 ? -gammp(0.5,x*x) : gammp(0.5,x*x); 204 } 205 -
sansmodels/src/python_wrapper/WrapperGenerator.py
rfa6db8b r5da3cc5 92 92 # Model category 93 93 self.category = None 94 # Whether model belongs to multifunc 95 self.is_multifunc = False 94 96 ## output directory for wrappers 95 97 self.output_dir = output_dir … … 228 230 raise ValueError, "Could not parse file %s" % self.file 229 231 230 232 # is_multifunc 233 key = "[MULTIPLICITY_INFO]" 234 if line.count(key) > 0: 235 self.is_multifunc = True 236 try: 237 index = line.index(key) 238 toks = line[index:].split("=") 239 self.multiplicity_info = toks[1].lstrip().rstrip() 240 except: 241 raise ValueError, "Could not parse file %s" % self.file 231 242 232 243 # Catch struct name … … 331 342 newline = self.replaceToken(newline, 332 343 "[MODELSTRUCT]", self.structName) 344 345 # Sort model initialization based on multifunc 346 if(self.is_multifunc): 347 line = "int level = 1;\nPyArg_ParseTuple(args,\"i\",&level);\n" 348 line += "self->model = new " + self.pythonClass + "(level);" 349 else: 350 line = "self->model = new " + self.pythonClass + "();" 351 352 newline = self.replaceToken(newline,"[INITIALIZE_MODEL]", 353 line) 333 354 334 355 # Dictionary initialization … … 465 486 newline = self.replaceToken(newline, 466 487 "[PAR_DETAILS]", self.details) 488 489 # Call base constructor 490 if self.is_multifunc: 491 newline = self.replaceToken(newline,"[CALL_CPYTHON_INIT]", 492 'C' + self.pythonClass + ".__init__(self,multfactor)\n\tself.is_multifunc = True") 493 newline = self.replaceToken(newline,"[MULTIPLICITY_INFO]",self.multiplicity_info) 494 else: 495 newline = self.replaceToken(newline,"[CALL_CPYTHON_INIT]", 496 'C' + self.pythonClass + ".__init__(self)\n\tself.is_multifunc = False") 497 newline = self.replaceToken(newline,"[MULTIPLICITY_INFO]","None") 498 467 499 468 500 # fixed list details -
sansmodels/src/python_wrapper/classTemplate.txt
re08bd5b r5da3cc5 86 86 self->params = PyDict_New(); 87 87 self->dispersion = PyDict_New(); 88 self->model = new [CMODEL](); 89 88 89 [INITIALIZE_MODEL] 90 90 91 [INITDICTIONARY] 91 92 -
sansmodels/src/python_wrapper/modelTemplate.txt
rfa6db8b r5da3cc5 43 43 """ 44 44 45 def __init__(self ):45 def __init__(self,multfactor=1): 46 46 """ Initialization """ 47 47 self.__dict__ = {} … … 50 50 BaseComponent.__init__(self) 51 51 #apply([CPYTHONCLASS].__init__, (self,)) 52 [CPYTHONCLASS].__init__(self) 53 52 53 [CALL_CPYTHON_INIT] 54 54 55 ## Name of the model 55 56 self.name = "[PYTHONCLASS]" … … 70 71 71 72 self.category = [CATEGORY] 73 self.multiplicity_info = [MULTIPLICITY_INFO] 74 72 75 73 76 def __setstate__(self, state):
Note: See TracChangeset
for help on using the changeset viewer.