source: sasview/guitools/transform.py @ 7afdc14

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 7afdc14 was 2e07e8f, checked in by Gervaise Alina <gervyh@…>, 16 years ago

litle change on fit

  • Property mode set to 100644
File size: 5.5 KB
Line 
1import math 
2         
3def toX(x,y=None):
4    """
5    This function is used to load value on Plottable.View
6    @param x: Float value
7    @return x,
8    """
9    return x
10
11def toX2(x,y=None):
12    """
13        This function is used to load value on Plottable.View
14        Calculate x^(2)
15        @param x: float value
16    """
17    return x*x
18
19def fromX2(x,y=None):
20     """
21         This function is used to load value on Plottable.View
22        Calculate square root of x
23        @param x: float value
24     """
25     if not x >=0 :
26         raise ValueError, "square root of a negative value "
27     else:
28         return math.sqrt(x)
29def toLogX(x,y=None):
30    """
31        This function is used to load value on Plottable.View
32        calculate log x
33        @param x: float value
34    """
35    if not x > 0:
36        raise ValueError, "Log(X)of a negative value "
37    else:
38        return math.log(x)
39   
40def toOneOverX(x,y=None):
41    if x !=0:
42        return 1/x
43    else:
44        raise ValueError,"cannot divide by zero"
45def toOneOverSqrtX(y , x=None):
46    if y!=None:
47        if y > 0:
48            return 1/math.sqrt(y)
49        else:
50            raise ValueError,"cannot be computed"
51   
52   
53def toLogYX2(y,x):
54    if y*(x**2) >0:
55        return math.log(y*(x**2))
56    else:
57         raise ValueError,"cannot be computed"
58     
59
60def toLogYX4(y, x):
61    if math.pow(x,4)*y > 0:
62        return math.log(math.pow(x,4)*y)
63
64def toLogXY(y,x):
65    """
66        This function is used to load value on Plottable.View
67        calculate log x
68        @param x: float value
69    """
70    if not x*y > 0:
71        raise ValueError, "Log(X*Y)of a negative value "
72    else:
73        return math.log(x*y)
74
75
76
77def errToX(x,y=None,dx=None,dy=None):
78    """
79        calculate error of x**2
80        @param x: float value
81        @param dx: float value
82    """
83    if dx==None:
84        dx=0
85    return dx
86
87
88def errToX2(x,y=None,dx=None,dy=None):
89    """
90        calculate error of x**2
91        @param x: float value
92        @param dx: float value
93    """
94    if  dx != None:
95        err = 2*x*dx
96        if math.fabs(err) >= math.fabs(x):
97            err = 0.9*x
98        return math.fabs(err)
99    else:
100        return 0.0
101def errFromX2(x,y=None,dx=None,dy=None):
102    """
103        calculate error of sqrt(x)
104        @param x: float value
105        @param dx: float value
106    """
107    if (x > 0):
108        if(dx != None):
109            err = dx/(2*math.sqrt(x))
110        else:
111            err = 0
112        if math.fabs(err) >= math.fabs(x):
113            err = 0.9*x   
114    else:
115        err = 0.9*x
116       
117        return math.fabs(err)
118def errToLog10X(x,y=None,dx=None,dy=None):
119    """
120        calculate error of Log(x)
121        @param x: float value
122        @param dx: float value
123    """
124    if dx==None:
125        dx = 0
126    if x!=0:
127        dx = dx/(x*math.log(10))
128    else:
129        raise ValueError, "errToLogX: divide by zero"
130   
131    if math.fabs(dx) >= math.fabs(x):
132        dx = 0.9*x
133   
134    return dx
135   
136def errToLogX(x,y=None,dx=None,dy=None):
137    """
138        calculate error of Log(x)
139        @param x: float value
140        @param dx: float value
141    """
142    if dx==None:
143        dx = 0
144    if x!=0:
145        dx = dx/x
146    else:
147        raise ValueError, "errToLogX: divide by zero"
148   
149    if math.fabs(dx) >= math.fabs(x):
150        dx = 0.9*x
151   
152    return dx
153
154
155
156def errToYX2(x, y, dx=None, dy=None):
157    if dx==None:
158        dx=0
159    if dy==None:
160        dy=0
161    err =math.sqrt((2*x*y*dx)**2 +((x**2)*dy)**2)
162    #if err >= math.fabs(x):
163    #    err =0.9*x
164    return err
165   
166def errToLogXY(x,y,dx=None, dy=None):
167    """
168        calculate error of Log(xy)
169    """
170    if (x!=0) and (y!=0):
171        if dx == None:
172            dx = 0
173        if dy == None:
174            dy = 0
175        err = (dx/x)**2 + (dy/y)**2
176        #if  math.sqrt(math.fabs(err)) >= math.fabs(x):
177        #    err= 0.9*x
178    else:
179        raise ValueError, "cannot compute this error"
180   
181    return math.sqrt(math.fabs(err))
182   
183def errToLogYX2(x,y,dx=None, dy=None):
184    """
185        calculate error of Log(yx**2)
186    """
187    if (x > 0) and (y > 0):
188        if (dx == None):
189            dx = 0
190        if (dy == None):
191            dy = 0
192        err = (2*dx/x)**2 + (dy/y)**2
193        #if math.fabs(err) >= math.fabs(x):
194        #   err =0.9*x
195    else:
196         raise ValueError, "cannot compute this error"
197     
198    return math.sqrt(math.fabs(err)) 
199       
200def errOneOverX(x,y=None,dx=None, dy=None):
201    """
202         calculate error on 1/x
203    """
204    if (x != 0):
205        if dx ==None:
206            dx= 0
207        err = -(dx)**2/x**2
208    else:
209        raise ValueError,"Cannot compute this error"
210   
211    if math.fabs(err)>= math.fabs(x):
212        err= 0.9*x
213    return math.fabs(err)
214
215def errOneOverSqrtX(x,y=None, dx=None,dy=None):
216    """
217        Calculate error on 1/sqrt(x)
218    """
219    if (x >0):
220        if dx==None:
221            dx =0
222        err= -1/2*math.pow(x, -3/2)* dx
223        #if math.fabs(err)>= math.fabs(x):
224        #    err=0.9*x
225    else:
226        raise ValueError, "Cannot compute this error"
227   
228    return math.fabs(err)
229def errToLogYX4(x,y=None,dx=None,dy=None):
230    """
231        error for ln(y*x^(4))
232        @param x: float value
233    """
234    if dx==None:
235        dx=0
236    if dy==None:
237        dy=0
238    err =math.sqrt((4*dx/x)**2 +(dy/y)**2)
239    #if err >= math.fabs(x):
240    #err =0.9*x
241    return err
242
243           
Note: See TracBrowser for help on using the repository browser.