From: <md...@us...> - 2008-08-05 17:44:57
|
Revision: 5975 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5975&view=rev Author: mdboom Date: 2008-08-05 17:44:55 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Fix Nx3 color array bug. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2008-08-05 17:25:12 UTC (rev 5974) +++ trunk/matplotlib/lib/matplotlib/colors.py 2008-08-05 17:44:55 UTC (rev 5975) @@ -337,11 +337,21 @@ # If c is a list it must be maintained as the same list # with modified items so that items can be appended to # it. This is needed for examples/dynamic_collections.py. - if not isinstance(c, (list, np.ndarray)): # specific; don't need duck-typing - c = list(c) + if isinstance(c, np.ndarray): + if len(c.shape) != 2: + raise ValueError("Color array must be two-dimensional") + if c.shape[1] != 4: + output = np.zeros((c.shape[0], 4)) + else: + output = c + elif not isinstance(c, list): + output = list(c) + else: + output = c + for i, cc in enumerate(c): - c[i] = self.to_rgba(cc, alpha) # change in place - result = c + output[i] = self.to_rgba(cc, alpha) # change in place + result = output return np.asarray(result, np.float_) colorConverter = ColorConverter() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2008-10-18 19:51:36
|
Revision: 6256 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6256&view=rev Author: efiring Date: 2008-10-18 19:51:22 +0000 (Sat, 18 Oct 2008) Log Message: ----------- Clip floating point values before conversion to integer; thanks to Tony Yu. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2008-10-18 17:47:28 UTC (rev 6255) +++ trunk/matplotlib/lib/matplotlib/colors.py 2008-10-18 19:51:22 UTC (rev 6256) @@ -455,7 +455,10 @@ mask_bad = ma.getmask(xma) if xa.dtype.char in np.typecodes['Float']: np.putmask(xa, xa==1.0, 0.9999999) #Treat 1.0 as slightly less than 1. - xa = (xa * self.N).astype(int) + # The following clip is fast, and prevents possible + # conversion of large positive values to negative integers. + np.clip(xa * self.N, -1, self.N, out=xa) + xa = xa.astype(int) # Set the over-range indices before the under-range; # otherwise the under-range values get converted to over-range. np.putmask(xa, xa>self.N-1, self._i_over) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2008-11-18 21:37:35
|
Revision: 6413 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6413&view=rev Author: efiring Date: 2008-11-18 21:37:25 +0000 (Tue, 18 Nov 2008) Log Message: ----------- Improved docstrings in colors.py Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2008-11-17 23:08:20 UTC (rev 6412) +++ trunk/matplotlib/lib/matplotlib/colors.py 2008-11-18 21:37:25 UTC (rev 6413) @@ -1,10 +1,25 @@ """ -A class for converting color arguments to RGB or RGBA +A module for converting numbers or color arguments to *RGB* or *RGBA* -This class instantiates a single instance colorConverter that is used -to convert matlab color strings to RGB. RGB is a tuple of float RGB -values in the range 0-1. +*RGB* and *RGBA* are sequences of, respectively, 3 or 4 floats in the +range 0-1. +This module includes functions and classes for color specification +conversions, and for mapping numbers to colors in a 1-D array of +colors called a colormap. Colormapping typically involves two steps: +a data array is first mapped onto the range 0-1 using an instance +of :class:`Normalize` or of a subclass; then this number in the 0-1 +range is mapped to a color using an instance of a subclass of +:class:`Colormap`. Two are provided here: +:class:`LinearSegmentedColormap`, which is used to generate all +the built-in colormap instances, but is also useful for making +custom colormaps, and :class:`ListedColormap`, which is used for +generating a custom colormap from a list of color specifications. + +The module also provides a single instance, *colorConverter*, of the +:class:`ColorConverter` class providing methods for converting single +color specifications or sequences of them to *RGB* or *RGBA*. + Commands which take color arguments can use several formats to specify the colors. For the basic builtin colors, you can use a single letter @@ -193,6 +208,7 @@ cnames[k] = v def is_color_like(c): + 'Return *True* if *c* can be converted to *RGB*' try: colorConverter.to_rgb(c) return True @@ -218,6 +234,15 @@ return tuple([int(n, 16)/255.0 for n in (s[1:3], s[3:5], s[5:7])]) class ColorConverter: + """ + Provides methods for converting color specifications to *RGB* or *RGBA* + + Caching is used for more efficient conversion upon repeated calls + with the same argument. + + Ordinarily only the single instance instantiated in this module, + *colorConverter*, is needed. + """ colors = { 'b' : (0.0, 0.0, 1.0), 'g' : (0.0, 0.5, 0.0), @@ -526,18 +551,48 @@ class LinearSegmentedColormap(Colormap): """Colormap objects based on lookup tables using linear segments. - The lookup transfer function is a simple linear function between - defined intensities. There is no limit to the number of segments - that may be defined. Though as the segment intervals start containing - fewer and fewer array locations, there will be inevitable quantization - errors + The lookup table is generated using linear interpolation for each + primary color, with the 0-1 domain divided into any number of + segments. """ def __init__(self, name, segmentdata, N=256): """Create color map from linear mapping segments segmentdata argument is a dictionary with a red, green and blue - entries. Each entry should be a list of x, y0, y1 tuples. + entries. Each entry should be a list of *x*, *y0*, *y1* tuples, + forming rows in a table. + Example: suppose you want red to increase from 0 to 1 over + the bottom half, green to do the same over the middle half, + and blue over the top half. Then you would use:: + + cdict = {'red': [(0.0, 0.0, 0.0), + (0.5, 1.0, 1.0), + (1.0, 1.0, 1.0)], + + 'green': [(0.0, 0.0, 0.0), + (0.25, 0.0, 0.0), + (0.75, 1.0, 1.0), + (1.0, 1.0, 1.0)], + + 'blue': [(0.0, 0.0, 0.0), + (0.5, 0.0, 0.0), + (1.0, 1.0, 1.0)]} + + Each row in the table for a given color is a sequence of + *x*, *y0*, *y1* tuples. In each sequence, *x* must increase + monotonically from 0 to 1. For any input value *z* falling + between *x[i]* and *x[i+1]*, the output value of a given color + will be linearly interpolated between *y1[i]* and *y0[i+1]*:: + + row i: x y0 y1 + / + / + row i+1: x y0 y1 + + Hence y0 in the first row and y1 in the last row are never used. + + .. seealso:: :func:`makeMappingArray` """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <js...@us...> - 2009-03-14 13:49:16
|
Revision: 6976 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6976&view=rev Author: jswhit Date: 2009-03-14 13:49:09 +0000 (Sat, 14 Mar 2009) Log Message: ----------- fix bug in hsv_to_rgb (returned rgb array wrong shape) Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2009-03-14 13:22:32 UTC (rev 6975) +++ trunk/matplotlib/lib/matplotlib/colors.py 2009-03-14 13:49:09 UTC (rev 6976) @@ -951,7 +951,9 @@ r[idx] = v[idx]; g[idx] = p[idx]; b[idx] = q[idx] idx = s == 0 r[idx] = v[idx]; g[idx] = v[idx]; b[idx] = v[idx] - return np.array((r,g,b)).T + rgb = np.empty_like(hsv) + rgb[:,:,0]=r; rgb[:,:,1]=g; rgb[:,:,2]=b + return rgb class lightsource(object): """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <js...@us...> - 2009-03-14 13:54:39
|
Revision: 6978 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6978&view=rev Author: jswhit Date: 2009-03-14 13:54:37 +0000 (Sat, 14 Mar 2009) Log Message: ----------- docstring fix for lightsource class Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2009-03-14 13:53:24 UTC (rev 6977) +++ trunk/matplotlib/lib/matplotlib/colors.py 2009-03-14 13:54:37 UTC (rev 6978) @@ -959,7 +959,7 @@ """ Create a light source coming from the specified azimuth and elevation. Angles are in degrees, with the azimuth measured - clockwise from south and elevation up from the zero plane of the surface. + clockwise from north and elevation up from the zero plane of the surface. The :meth:`shade` is used to produce rgb values for a shaded relief image given a data array. """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2009-06-06 21:36:43
|
Revision: 7189 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7189&view=rev Author: efiring Date: 2009-06-06 21:35:36 +0000 (Sat, 06 Jun 2009) Log Message: ----------- Tweak John's change to handling of rgba arrays Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2009-06-06 18:21:51 UTC (rev 7188) +++ trunk/matplotlib/lib/matplotlib/colors.py 2009-06-06 21:35:36 UTC (rev 7189) @@ -361,27 +361,35 @@ then an empty array will be returned. Same for an empty list. """ try: - if c.lower() == 'none': - return np.zeros((0,4), dtype=np.float_) + nc = len(c) + except TypeError: + raise ValueError( + "Cannot convert argument type %s to rgba array" % type(c)) + try: + if nc == 0 or c.lower() == 'none': + return np.zeros((0,4), dtype=np.float) except AttributeError: pass - if len(c) == 0: - return np.zeros((0,4), dtype=np.float_) try: - result = np.array([self.to_rgba(c, alpha)], dtype=np.float_) + # Single value? Put it in an array with a single row. + return np.array([self.to_rgba(c, alpha)], dtype=np.float) except ValueError: if isinstance(c, np.ndarray): if c.ndim != 2 and c.dtype.kind not in 'SU': raise ValueError("Color array must be two-dimensional") - if len(c.shape)==2 and c.shape[-1]==4: + if (c.ndim == 2 and c.shape[1] == 4 and c.dtype.kind == 'f'): + if (c.ravel() > 1).any() or (c.ravel() < 0).any(): + raise ValueError( + "number in rgba sequence is outside 0-1 range") # looks like rgba already, nothing to be done; do # we want to apply alpha here if # (c[:,3]==1).all() ? - return c - result = np.zeros((len(c), 4)) + return np.asarray(c, np.float) + # It must be some other sequence of color specs. + result = np.zeros((nc, 4), dtype=np.float) for i, cc in enumerate(c): - result[i] = self.to_rgba(cc, alpha) # change in place - return np.asarray(result, np.float_) + result[i] = self.to_rgba(cc, alpha) + return result colorConverter = ColorConverter() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-05-11 20:23:11
|
Revision: 8308 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8308&view=rev Author: efiring Date: 2010-05-11 20:23:04 +0000 (Tue, 11 May 2010) Log Message: ----------- close bug 2997687: integer overflow problem in Normalize Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2010-05-11 20:00:14 UTC (rev 8307) +++ trunk/matplotlib/lib/matplotlib/colors.py 2010-05-11 20:23:04 UTC (rev 8308) @@ -796,11 +796,13 @@ elif vmin==vmax: result = 0.0 * val else: + vmin = float(vmin) + vmax = float(vmax) if clip: mask = ma.getmask(val) val = ma.array(np.clip(val.filled(vmax), vmin, vmax), mask=mask) - result = (val-vmin) * (1.0/(vmax-vmin)) + result = (val-vmin) / (vmax-vmin) if vtype == 'scalar': result = result[0] return result @@ -809,6 +811,10 @@ if not self.scaled(): raise ValueError("Not invertible until scaled") vmin, vmax = self.vmin, self.vmax + if vmin >= vmax: + raise ValueError("Inversion requires valid vmax > vmin") + vmin = float(vmin) + vmax = float(vmax) if cbook.iterable(value): val = ma.asarray(value) @@ -816,18 +822,17 @@ else: return vmin + value * (vmax - vmin) - def autoscale(self, A): ''' Set *vmin*, *vmax* to min, max of *A*. ''' - self.vmin = ma.minimum(A) - self.vmax = ma.maximum(A) + self.vmin = ma.min(A) + self.vmax = ma.max(A) def autoscale_None(self, A): ' autoscale only None-valued vmin or vmax' - if self.vmin is None: self.vmin = ma.minimum(A) - if self.vmax is None: self.vmax = ma.maximum(A) + if self.vmin is None: self.vmin = ma.min(A) + if self.vmax is None: self.vmax = ma.max(A) def scaled(self): 'return true if vmin and vmax set' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-05-30 23:58:33
|
Revision: 8348 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8348&view=rev Author: efiring Date: 2010-05-30 23:58:27 +0000 (Sun, 30 May 2010) Log Message: ----------- LogNorm.autoscale ignores nonpositive values; closes 2953069 Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2010-05-30 21:31:19 UTC (rev 8347) +++ trunk/matplotlib/lib/matplotlib/colors.py 2010-05-30 23:58:27 UTC (rev 8348) @@ -850,6 +850,8 @@ vtype = 'scalar' val = ma.array([value]).astype(np.float) + val = ma.masked_less_equal(val, 0, copy=False) + self.autoscale_None(val) vmin, vmax = self.vmin, self.vmax if vmin > vmax: @@ -879,6 +881,24 @@ else: return vmin * pow((vmax/vmin), value) + def autoscale(self, A): + ''' + Set *vmin*, *vmax* to min, max of *A*. + ''' + A = ma.masked_less_equal(A, 0, copy=False) + self.vmin = ma.min(A) + self.vmax = ma.max(A) + + def autoscale_None(self, A): + ' autoscale only None-valued vmin or vmax' + if self.vmin is not None and self.vmax is not None: + return + A = ma.masked_less_equal(A, 0, copy=False) + if self.vmin is None: + self.vmin = ma.min(A) + if self.vmax is None: + self.vmax = ma.max(A) + class BoundaryNorm(Normalize): ''' Generate a colormap index based on discrete intervals. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-06-01 00:31:48
|
Revision: 8355 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8355&view=rev Author: efiring Date: 2010-06-01 00:31:42 +0000 (Tue, 01 Jun 2010) Log Message: ----------- Colormap.__call__: override existing alpha only if alpha is specified. Closes 2891982. The color for masked data is still handled differently; this may need to be changed. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2010-05-31 23:05:55 UTC (rev 8354) +++ trunk/matplotlib/lib/matplotlib/colors.py 2010-06-01 00:31:42 UTC (rev 8355) @@ -482,7 +482,7 @@ self._isinit = False - def __call__(self, X, alpha=1.0, bytes=False): + def __call__(self, X, alpha=None, bytes=False): """ *X* is either a scalar or an array (of any dimension). If scalar, a tuple of rgba values is returned, otherwise @@ -490,18 +490,12 @@ are integers, then they are used as indices into the array. If they are floating point, then they must be in the interval (0.0, 1.0). - Alpha must be a scalar. + Alpha must be a scalar between 0 and 1, or None. If bytes is False, the rgba values will be floats on a 0-1 scale; if True, they will be uint8, 0-255. """ if not self._isinit: self._init() - alpha = min(alpha, 1.0) # alpha must be between 0 and 1 - alpha = max(alpha, 0.0) - self._lut[:-1,-1] = alpha # Don't assign global alpha to i_bad; - # it would defeat the purpose of the - # default behavior, which is to not - # show anything where data are missing. mask_bad = None if not cbook.iterable(X): vtype = 'scalar' @@ -532,7 +526,17 @@ if bytes: lut = (self._lut * 255).astype(np.uint8) else: - lut = self._lut + lut = self._lut.copy() + + if alpha is not None: + alpha = min(alpha, 1.0) # alpha must be between 0 and 1 + alpha = max(alpha, 0.0) + lut[:-1,-1] = alpha # Don't assign global alpha to i_bad; + # it would defeat the purpose of the + # default behavior, which is to not + # show anything where data are missing. + + rgba = np.empty(shape=xa.shape+(4,), dtype=lut.dtype) lut.take(xa, axis=0, mode='clip', out=rgba) # twice as fast as lut[xa]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-06-01 01:03:12
|
Revision: 8356 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8356&view=rev Author: efiring Date: 2010-06-01 01:03:06 +0000 (Tue, 01 Jun 2010) Log Message: ----------- colors.py: more improvement in alpha handling for over, under, and bad values Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2010-06-01 00:31:42 UTC (rev 8355) +++ trunk/matplotlib/lib/matplotlib/colors.py 2010-06-01 01:03:06 UTC (rev 8356) @@ -526,17 +526,21 @@ if bytes: lut = (self._lut * 255).astype(np.uint8) else: - lut = self._lut.copy() + lut = self._lut.copy() # Don't let alpha modify original _lut. if alpha is not None: alpha = min(alpha, 1.0) # alpha must be between 0 and 1 alpha = max(alpha, 0.0) - lut[:-1,-1] = alpha # Don't assign global alpha to i_bad; - # it would defeat the purpose of the - # default behavior, which is to not - # show anything where data are missing. + if (lut[-1] == 0).all(): + lut[:-1, -1] = alpha + # All zeros is taken as a flag for the default bad + # color, which is no color--fully transparent. We + # don't want to override this. + else: + lut[:,-1] = alpha + # If the bad value is set to have a color, then we + # override its alpha just as for any other value. - rgba = np.empty(shape=xa.shape+(4,), dtype=lut.dtype) lut.take(xa, axis=0, mode='clip', out=rgba) # twice as fast as lut[xa]; @@ -546,20 +550,20 @@ rgba = tuple(rgba[0,:]) return rgba - def set_bad(self, color = 'k', alpha = 1.0): + def set_bad(self, color = 'k', alpha = None): '''Set color to be used for masked values. ''' self._rgba_bad = colorConverter.to_rgba(color, alpha) if self._isinit: self._set_extremes() - def set_under(self, color = 'k', alpha = 1.0): + def set_under(self, color = 'k', alpha = None): '''Set color to be used for low out-of-range values. Requires norm.clip = False ''' self._rgba_under = colorConverter.to_rgba(color, alpha) if self._isinit: self._set_extremes() - def set_over(self, color = 'k', alpha = 1.0): + def set_over(self, color = 'k', alpha = None): '''Set color to be used for high out-of-range values. Requires norm.clip = False ''' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2011-02-09 04:16:14
|
Revision: 8965 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8965&view=rev Author: efiring Date: 2011-02-09 04:16:08 +0000 (Wed, 09 Feb 2011) Log Message: ----------- Normalize: major speed-up via bypassing masked array division Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2011-02-08 13:27:16 UTC (rev 8964) +++ trunk/matplotlib/lib/matplotlib/colors.py 2011-02-09 04:16:08 UTC (rev 8965) @@ -853,8 +853,11 @@ mask = ma.getmask(result) result = ma.array(np.clip(result.filled(vmax), vmin, vmax), mask=mask) - result -= vmin - result /= vmax - vmin + # ma division is very slow; we can take a shortcut + resdat = result.data + resdat -= vmin + resdat /= (vmax - vmin) + result = np.ma.array(resdat, mask=result.mask, copy=False) if is_scalar: result = result[0] return result This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2011-02-10 01:21:34
|
Revision: 8968 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8968&view=rev Author: efiring Date: 2011-02-10 01:21:27 +0000 (Thu, 10 Feb 2011) Log Message: ----------- bugfix: handle alpha correctly in colormapping with uint8 Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2011-02-09 17:57:14 UTC (rev 8967) +++ trunk/matplotlib/lib/matplotlib/colors.py 2011-02-10 01:21:27 UTC (rev 8968) @@ -547,6 +547,8 @@ if alpha is not None: alpha = min(alpha, 1.0) # alpha must be between 0 and 1 alpha = max(alpha, 0.0) + if bytes: + alpha = int(alpha * 255) if (lut[-1] == 0).all(): lut[:-1, -1] = alpha # All zeros is taken as a flag for the default bad This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2011-02-10 07:37:11
|
Revision: 8969 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8969&view=rev Author: efiring Date: 2011-02-10 07:37:05 +0000 (Thu, 10 Feb 2011) Log Message: ----------- LogNorm: speed-up by dealing with mask explicitly Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2011-02-10 01:21:27 UTC (rev 8968) +++ trunk/matplotlib/lib/matplotlib/colors.py 2011-02-10 07:37:05 UTC (rev 8969) @@ -921,9 +921,17 @@ mask=mask) #result = (ma.log(result)-np.log(vmin))/(np.log(vmax)-np.log(vmin)) # in-place equivalent of above can be much faster - np.ma.log(result, result) - result -= np.log(vmin) - result /= (np.log(vmax) - np.log(vmin)) + resdat = result.data + mask = result.mask + if mask is np.ma.nomask: + mask = (resdat <= 0) + else: + mask |= resdat <= 0 + np.putmask(resdat, mask, 1) + np.log(resdat, resdat) + resdat -= np.log(vmin) + resdat /= (np.log(vmax) - np.log(vmin)) + result = np.ma.array(resdat, mask=mask, copy=False) if is_scalar: result = result[0] return result This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |