source: sasview/guitools/transform.py @ 863607a

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 863607a was 46693050, checked in by Gervaise Alina <gervyh@…>, 16 years ago

working on fit linear

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