source: sasview/guitools/transform.py @ bbec827

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

some changes

  • Property mode set to 100644
File size: 5.3 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)
118   
119def errToLogX(x,y=None,dx=None,dy=None):
120    """
121        calculate error of Log(x)
122        @param x: float value
123        @param dx: float value
124    """
125    if dx==None:
126        dx = 0
127    if x!=0:
128        dx = dx/x
129    else:
130        raise ValueError, "errToLogX: divide by zero"
131   
132    if math.fabs(dx) >= math.fabs(x):
133        dx = 0.9*x
134   
135    return dx
136
137def errToXY(x, y, dx=None, dy=None):
138    if dx==None:
139        dx=0
140    if dy==None:
141        dy=0
142    err =math.sqrt((y*dx)**2 +(x*dy)**2)
143    if err >= math.fabs(x):
144        err =0.9*x
145    return err
146
147def errToYX2(x, y, dx=None, dy=None):
148    if dx==None:
149        dx=0
150    if dy==None:
151        dy=0
152    err =math.sqrt((2*x*y*dx)**2 +((x**2)*dy)**2)
153    if err >= math.fabs(x):
154        err =0.9*x
155    return err
156   
157def errToLogXY(x,y,dx=None, dy=None):
158    """
159        calculate error of Log(xy)
160    """
161    if (x!=0) and (y!=0):
162        if dx == None:
163            dx = 0
164        if dy == None:
165            dy = 0
166        err = (dx/x)**2 + (dy/y)**2
167        if  math.sqrt(math.fabs(err)) >= math.fabs(x):
168            err= 0.9*x
169    else:
170        raise ValueError, "cannot compute this error"
171   
172    return math.sqrt(math.fabs(err))
173   
174def errToLogYX2(x,y,dx=None, dy=None):
175    """
176        calculate error of Log(yx**2)
177    """
178    if (x > 0) and (y > 0):
179        if (dx == None):
180            dx = 0
181        if (dy == None):
182            dy = 0
183        err = (2*dx/x)**2 + (dy/y)**2
184        if math.fabs(err) >= math.fabs(x):
185            err =0.9*x
186    else:
187         raise ValueError, "cannot compute this error"
188     
189    return math.sqrt(math.fabs(err)) 
190       
191def errOneOverX(x,y=None,dx=None, dy=None):
192    """
193         calculate error on 1/x
194    """
195    if (x != 0):
196        if dx ==None:
197            dx= 0
198        err = -(dx)**2/x**2
199    else:
200        raise ValueError,"Cannot compute this error"
201   
202    if math.fabs(err)>= math.fabs(x):
203        err= 0.9*x
204    return math.fabs(err)
205
206def errOneOverSqrtX(x,y=None, dx=None,dy=None):
207    """
208        Calculate error on 1/sqrt(x)
209    """
210    if (x >0):
211        if dx==None:
212            dx =0
213        err= -1/2*math.pow(x, -3/2)* dx
214        if math.fabs(err)>= math.fabs(x):
215            err=0.9*x
216    else:
217        raise ValueError, "Cannot compute this error"
218   
219    return math.fabs(err)
220def errToLogYX4(x,y=None,dx=None,dy=None):
221    """
222        error for ln(y*x^(4))
223        @param x: float value
224    """
225    if dx==None:
226        dx=0
227    if dy==None:
228        dy=0
229    err =math.sqrt((4*dx/x)**2 +(dy/y)**2)
230    if err >= math.fabs(x):
231        err =0.9*x
232    return err
233
234           
Note: See TracBrowser for help on using the repository browser.