source: sasview/guitools/transform.py @ 35891ce

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 35891ce was 8e44d51, checked in by Gervaise Alina <gervyh@…>, 16 years ago

one more bug fixed

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