Skip to content

Commit 17e5e25

Browse files
committed
Added docstrings for transform module
1 parent 2585d39 commit 17e5e25

File tree

3 files changed

+184
-1
lines changed

3 files changed

+184
-1
lines changed

doc/reference/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ Main `python-qwt` classes:
3030
symbol
3131
text
3232
text_engine
33+
transform
3334
toqimage

doc/reference/transform.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.. automodule:: qwt.transform
2+
:members:

qwt/transform.py

Lines changed: 181 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,69 +5,249 @@
55
# Copyright (c) 2015 Pierre Raybaut, for the Python translation/optimization
66
# (see LICENSE file for more details)
77

8+
"""
9+
QwtTransform
10+
------------
11+
12+
.. autoclass:: QwtTransform
13+
:members:
14+
15+
QwtNullTransform
16+
----------------
17+
18+
.. autoclass:: QwtNullTransform
19+
:members:
20+
21+
QwtLogTransform
22+
---------------
23+
24+
.. autoclass:: QwtLogTransform
25+
:members:
26+
27+
QwtPowerTransform
28+
-----------------
29+
30+
.. autoclass:: QwtPowerTransform
31+
:members:
32+
"""
33+
834
import numpy as np
935

1036

1137
class QwtTransform(object):
38+
"""
39+
A transformation between coordinate systems
40+
41+
QwtTransform manipulates values, when being mapped between
42+
the scale and the paint device coordinate system.
43+
44+
A transformation consists of 2 methods:
45+
46+
- transform
47+
- invTransform
48+
49+
where one is is the inverse function of the other.
50+
51+
When p1, p2 are the boundaries of the paint device coordinates
52+
and s1, s2 the boundaries of the scale, QwtScaleMap uses the
53+
following calculations::
54+
55+
p = p1 + (p2 - p1) * ( T(s) - T(s1) / (T(s2) - T(s1)) )
56+
s = invT( T(s1) + ( T(s2) - T(s1) ) * (p - p1) / (p2 - p1) )
57+
"""
1258
def __init__(self):
1359
pass
1460

1561
def bounded(self, value):
62+
"""
63+
Modify value to be a valid value for the transformation.
64+
The default implementation does nothing.
65+
"""
1666
return value
1767

1868
def transform(self, value):
69+
"""
70+
Transformation function
71+
72+
:param float value: Value
73+
:return: Modified value
74+
75+
.. seealso::
76+
77+
:py:meth:`invTransform()`
78+
"""
1979
raise NotImplementedError
2080

2181
def invTransform(self, value):
82+
"""
83+
Inverse transformation function
84+
85+
:param float value: Value
86+
:return: Modified value
87+
88+
.. seealso::
89+
90+
:py:meth:`transform()`
91+
"""
2292
raise NotImplementedError
2393

2494
def copy(self):
95+
"""
96+
:return: Clone of the transformation
97+
98+
The default implementation does nothing.
99+
"""
25100
raise NotImplementedError
26101

27102

28103
class QwtNullTransform(QwtTransform):
29104
def transform(self, value):
105+
"""
106+
Transformation function
107+
108+
:param float value: Value
109+
:return: Modified value
110+
111+
.. seealso::
112+
113+
:py:meth:`invTransform()`
114+
"""
30115
return value
31116

32117
def invTransform(self, value):
118+
"""
119+
Inverse transformation function
120+
121+
:param float value: Value
122+
:return: Modified value
123+
124+
.. seealso::
125+
126+
:py:meth:`transform()`
127+
"""
33128
return value
34129

35130
def copy(self):
131+
"""
132+
:return: Clone of the transformation
133+
"""
36134
return QwtNullTransform()
37135

38136

39137
class QwtLogTransform(QwtTransform):
138+
"""
139+
Logarithmic transformation
140+
141+
`QwtLogTransform` modifies the values using `numpy.log()` and
142+
`numpy.exp()`.
143+
144+
.. note::
145+
146+
In the calculations of `QwtScaleMap` the base of the log function
147+
has no effect on the mapping. So `QwtLogTransform` can be used
148+
for logarithmic scale in base 2 or base 10 or any other base.
149+
150+
Extremum values:
151+
152+
* `QwtLogTransform.LogMin`: Smallest allowed value for logarithmic
153+
scales: 1.0e-150
154+
* `QwtLogTransform.LogMax`: Largest allowed value for logarithmic
155+
scales: 1.0e150
156+
"""
157+
40158
LogMin = 1.0e-150
41159
LogMax = 1.0e150
160+
42161
def bounded(self, value):
162+
"""
163+
Modify value to be a valid value for the transformation.
164+
165+
:param float value: Value to be bounded
166+
:return: Value unmodified
167+
"""
43168
return np.clip(value, self.LogMin, self.LogMax)
44169

45170
def transform(self, value):
171+
"""
172+
Transformation function
173+
174+
:param float value: Value
175+
:return: Modified value
176+
177+
.. seealso::
178+
179+
:py:meth:`invTransform()`
180+
"""
46181
return np.log(value)
47182

48183
def invTransform(self, value):
184+
"""
185+
Inverse transformation function
186+
187+
:param float value: Value
188+
:return: Modified value
189+
190+
.. seealso::
191+
192+
:py:meth:`transform()`
193+
"""
49194
return np.exp(value)
50195

51196
def copy(self):
197+
"""
198+
:return: Clone of the transformation
199+
"""
52200
return QwtLogTransform()
53201

54202

55203
class QwtPowerTransform(QwtTransform):
204+
"""
205+
A transformation using `numpy.pow()`
206+
207+
`QwtPowerTransform` preserves the sign of a value.
208+
F.e. a transformation with a factor of 2
209+
transforms a value of -3 to -9 and v.v. Thus `QwtPowerTransform`
210+
can be used for scales including negative values.
211+
"""
212+
56213
def __init__(self, exponent):
57214
self.__exponent = exponent
58215
super(QwtPowerTransform, self).__init__()
59216

60217
def transform(self, value):
218+
"""
219+
Transformation function
220+
221+
:param float value: Value
222+
:return: Modified value
223+
224+
.. seealso::
225+
226+
:py:meth:`invTransform()`
227+
"""
61228
if value < 0.:
62229
return -np.pow(-value, 1./self.__exponent)
63230
else:
64231
return np.pow(value, 1./self.__exponent)
65232

66233
def invTransform(self, value):
234+
"""
235+
Inverse transformation function
236+
237+
:param float value: Value
238+
:return: Modified value
239+
240+
.. seealso::
241+
242+
:py:meth:`transform()`
243+
"""
67244
if value < 0.:
68245
return -np.pow(-value, self.__exponent)
69246
else:
70247
return np.pow(value, self.__exponent)
71248

72249
def copy(self):
73-
return QwtPowerTransform()
250+
"""
251+
:return: Clone of the transformation
252+
"""
253+
return QwtPowerTransform(self.__exponent)

0 commit comments

Comments
 (0)