~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

Viewing changes to chaco/transform_color_mapper.py

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2014-06-01 17:04:08 UTC
  • mfrom: (7.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20140601170408-m86xvdjd83a4qon0
Tags: 4.4.1-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
 - Let the binary-predeb target work on the usr/lib/python* directory
   as we don't have usr/share/pyshared anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from numpy import clip, isinf, ones_like
 
1
from numpy import clip, isinf, ones_like, empty
2
2
 
3
3
from chaco.api import ColorMapper
4
4
from traits.api import Trait, Callable, Tuple, Float, on_trait_change
5
5
 
 
6
from speedups import map_colors, map_colors_uint8
6
7
 
7
8
class TransformColorMapper(ColorMapper):
8
9
    """This class adds arbitrary data transformations to a ColorMapper.
116
117
        """
117
118
 
118
119
        norm_data = self._compute_normalized_data(data_array)
119
 
        return self._map(norm_data)
 
120
        # The data are normalized, so we can pass low = 0, high = 1
 
121
        rgba = map_colors(norm_data, self.steps, 0, 1, self._red_lut,
 
122
                self._green_lut, self._blue_lut, self._alpha_lut)
 
123
        return rgba
120
124
 
121
125
 
122
126
    def map_index(self, data_array):
123
127
        """ Maps an array of values to their corresponding color band index. 
124
128
        """
125
 
 
126
129
        norm_data = self._compute_normalized_data(data_array)
127
130
        indices = (norm_data * (self.steps-1)).astype(int)
128
131
        return indices
129
132
 
 
133
    def map_uint8(self, data_array):
 
134
        """ Maps an array of data values to an array of colors.
 
135
        """
 
136
        norm_data = self._compute_normalized_data(data_array)
 
137
        rgba = map_colors_uint8(norm_data, self.steps, 0.0, 1.0,
 
138
                self._red_lut_uint8, self._green_lut_uint8,
 
139
                self._blue_lut_uint8, self._alpha_lut_uint8)
 
140
 
 
141
        return rgba
 
142
 
130
143
    #-------------------------------------------------------------------
131
144
    # Private methods
132
145
    #-------------------------------------------------------------------
156
169
            # initialization before range is connected to a data source).
157
170
            norm_data = 0.5*ones_like(data_array)
158
171
        else:
159
 
            norm_data = clip((data_array - low) / range_diff, 0.0, 1.0)
 
172
            norm_data = empty(data_array.shape, dtype='float32')
 
173
            norm_data[:] = data_array
 
174
            norm_data -= low
 
175
            norm_data /= range_diff
 
176
            clip(norm_data, 0.0, 1.0, norm_data)
160
177
 
161
178
        if self.unit_func is not None:
162
179
            norm_data = self.unit_func(norm_data)