-
-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathpower_scale.py
More file actions
68 lines (53 loc) · 2.4 KB
/
power_scale.py
File metadata and controls
68 lines (53 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -----------------------------------------------------------------------------
# Copyright (c) 2009-2016 Nicolas P. Rougier. All rights reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
import numpy as np
from glumpy import library
from . transform import Transform
from . quantitative_scale import QuantitativeScale
class PowerScale(QuantitativeScale):
"""
Power scales are similar to linear scales, except there's an exponential
transform that is applied to the input domain value before the output range
value is computed. The mapping to the output range value y can be expressed
as a function of the input domain value x: y = mx^k + b, where k is the
exponent value. Power scales also support negative values, in which case
the input value is multiplied by -1, and the resulting output value is also
multiplied by -1.
:param 2-tuple domain: Input domains. Default is (-1,+1).
:param 2-tuple range: Output range. Default is (-1,+1).
:param float exponent: Power exponent. Default is 1.
:param bool clamp: Clamping test. Default is False.
:param bool discard: Discard test. Default is True.
"""
aliases = { "domain" : "power_scale_domain",
"range" : "power_scale_range",
"clamp" : "power_scale_clamp",
"discard" : "power_scale_discard",
"exponent" : "power_scale_exponent" }
def __init__(self, *args, **kwargs):
"""
Initialize the transform.
"""
self._exponents = Transform._get_kwarg("exponent", kwargs, 1.0)
code = library.get("transforms/power-scale.glsl")
QuantitativeScale.__init__(self, code, *args, **kwargs)
@property
def exponent(self):
""" Input exponent for xyz """
return self._exponents
@exponent.setter
def exponent(self, value):
self._exponents = abs(float(value))
if self.is_attached:
self["exponent"] = self._exponents
self["domain"] = self._process_domain()
def on_attach(self, program):
QuantitativeScale.on_attach(self, program)
self["exponent"] = self._exponents
def _process_domain(self):
domain = self._domain
exponent = self._exponents
domain = np.copysign(1,domain) * np.power(np.abs(domain), exponent)
return domain