source: sasview/guitools/transform.py @ 831149e

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

working better .Since have to think about the zoom

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