source: sasview/guitools/transform.py @ 5e14aee

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 5e14aee was 2e014bf, checked in by Gervaise Alina <gervyh@…>, 16 years ago

made some changes in transform file

  • Property mode set to 100644
File size: 5.1 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
137
138
139def errToYX2(x, y, dx=None, dy=None):
140    if dx==None:
141        dx=0
142    if dy==None:
143        dy=0
144    err =math.sqrt((2*x*y*dx)**2 +((x**2)*dy)**2)
145    #if err >= math.fabs(x):
146    #    err =0.9*x
147    return err
148   
149def errToLogXY(x,y,dx=None, dy=None):
150    """
151        calculate error of Log(xy)
152    """
153    if (x!=0) and (y!=0):
154        if dx == None:
155            dx = 0
156        if dy == None:
157            dy = 0
158        err = (dx/x)**2 + (dy/y)**2
159        #if  math.sqrt(math.fabs(err)) >= math.fabs(x):
160        #    err= 0.9*x
161    else:
162        raise ValueError, "cannot compute this error"
163   
164    return math.sqrt(math.fabs(err))
165   
166def errToLogYX2(x,y,dx=None, dy=None):
167    """
168        calculate error of Log(yx**2)
169    """
170    if (x > 0) and (y > 0):
171        if (dx == None):
172            dx = 0
173        if (dy == None):
174            dy = 0
175        err = (2*dx/x)**2 + (dy/y)**2
176        #if 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 errOneOverX(x,y=None,dx=None, dy=None):
184    """
185         calculate error on 1/x
186    """
187    if (x != 0):
188        if dx ==None:
189            dx= 0
190        err = -(dx)**2/x**2
191    else:
192        raise ValueError,"Cannot compute this error"
193   
194    if math.fabs(err)>= math.fabs(x):
195        err= 0.9*x
196    return math.fabs(err)
197
198def errOneOverSqrtX(x,y=None, dx=None,dy=None):
199    """
200        Calculate error on 1/sqrt(x)
201    """
202    if (x >0):
203        if dx==None:
204            dx =0
205        err= -1/2*math.pow(x, -3/2)* dx
206        #if math.fabs(err)>= math.fabs(x):
207        #    err=0.9*x
208    else:
209        raise ValueError, "Cannot compute this error"
210   
211    return math.fabs(err)
212def errToLogYX4(x,y=None,dx=None,dy=None):
213    """
214        error for ln(y*x^(4))
215        @param x: float value
216    """
217    if dx==None:
218        dx=0
219    if dy==None:
220        dy=0
221    err =math.sqrt((4*dx/x)**2 +(dy/y)**2)
222    #if err >= math.fabs(x):
223    #err =0.9*x
224    return err
225
226           
Note: See TracBrowser for help on using the repository browser.