def get_bounds(self): """ Returns the minimum and maximum values of the data source's data. Implements AbstractDataSource. """ if not self._bounds_cache_valid: if self.raw_value.size == 0: self._cached_bounds = (0, 0) else: # nanmin and nanmax raise an annoying RuntimeWarning when # all raw_value entries are NaN. Use fmin.reduce and # fmax.reduce to avoid this. self._cached_bounds = (fmin.reduce(self.raw_value, axis=None), fmax.reduce(self.raw_value, axis=None)) self._bounds_cache_valid = True return self._cached_bounds
def get_bounds(self): """ Returns the minimum and maximum values of the data source's data. Implements AbstractDataSource. """ if not self._bounds_cache_valid: if self.raw_value.size == 0: self._cached_bounds = (0, 0) else: # nanmin and nanmax raise an annoying RuntimeWarning when # all raw_value entries are NaN. Use fmin.reduce and # fmax.reduce to avoid this. self._cached_bounds = ( fmin.reduce(self.raw_value, axis=None), fmax.reduce(self.raw_value, axis=None)) self._bounds_cache_valid = True return self._cached_bounds
def render(self, todraw, mass, mode=None, vmin=None, vmax=None, logscale=True, logweight=True, cmap=pygascmap, gamma=1.0, mmin=None, mmax=None, over=None, composite=None): """ vmin can be a string, eg '40 dB', so the vmin=vmax/1e4 """ if mode == 'intensity' or mode == 'mean': todraw /= mass if logscale: if vmin is not None and not isinstance(vmin, basestring): vmin = 10**vmin if vmax is not None: vmax = 10**vmax if vmax is None: if mode == 'intensity' or mode == 'mean' or over is None: vmax = fmax.reduce(todraw.flat) else: sort = todraw.ravel().argsort() ind = sort[(len(sort) - 1) * (1.0 - over)] vmax = todraw.ravel()[ind] del sort if vmin is None: if logscale: vmin = ccode.pmin.reduce(todraw.flat) else: vmin = fmin.reduce(todraw.flat) elif isinstance(vmin, basestring): db = int(vmin[:-3]) vmin = vmax / 10**(db / 10.) if logscale: log10(todraw, todraw) vmin = log10(vmin) vmax = log10(vmax) print 'vmax, vmin =', vmax, vmin image = zeros(dtype=('u1', 4), shape=todraw.shape) # gacolor is much faster then matplotlib's normalize and uses less memory(4times fewer). if not hasattr(cmap, 'table'): cmap = gacmap(cmap) ccode.color(image, todraw, max=vmax, min=vmin, logscale=False, colormap=cmap) del todraw if mode == 'intensity': weight = mass if logweight: # in camera mode do not use logscale for mass. weight.clip(ccode.pmin.reduce(weight.ravel()), inf, weight) log10(weight, weight) print 'weight', weight.mean(), weight.max(), weight.min() if mmin is None: mmin = weight.min() if mmax is None: if over is None: mmax = weight.max() else: sort = weight.ravel().argsort() ind = sort[(len(sort) - 1) * (1.0 - over)] mmax = weight.ravel()[ind] print 'mmax, mmin', mmax, mmin weight -= mmin weight /= (mmax - mmin) weight.clip(0, 1, weight) else: weight = image[:, :, 3] / 255.0 weight **= gamma if composite is not None: alpha = composite[:, :, 3] / 255.0 multiply(1.0 - weight[:, :], alpha[:, :], alpha[:, :]) multiply(image[:, :, 0:3], weight[:, :, newaxis], image[:, :, 0:3]) multiply(composite[:, :, 0:3], alpha[:, :, newaxis], composite[:, :, 0:3]) add(image[:, :, 0:3], composite[:, :, 0:3], image[:, :, 0:3]) image[:, :, 3] = (alpha[:, :] + weight[:, :]) * 255 else: #multiply(image[:, :, 0:3], weight[:, :, newaxis], image[:, :, 0:3]) #image[:, :, 3] = 255 #weight **= 0.33333333333 multiply(255.9999, weight[:, :], out=image[:, :, 3], casting='unsafe') # print 'alpha', image[:, :, 3].ravel().min(), image[:,:,3].ravel().max() return image
def render(self, todraw, mass, mode=None, vmin=None, vmax=None, logscale=True, logweight=True, cmap=pygascmap, gamma=1.0, mmin=None, mmax=None, over=None, composite=None): """ vmin can be a string, eg '40 dB', so the vmin=vmax/1e4 """ if mode == 'intensity' or mode == 'mean': todraw /= mass if logscale: if vmin is not None and not isinstance(vmin, basestring): vmin = 10 ** vmin if vmax is not None: vmax = 10 ** vmax if vmax is None: if mode == 'intensity' or mode == 'mean' or over is None: vmax = fmax.reduce(todraw.flat) else: sort = todraw.ravel().argsort() ind = sort[(len(sort) - 1) * (1.0 - over)] vmax = todraw.ravel()[ind] del sort if vmin is None: if logscale: vmin = ccode.pmin.reduce(todraw.flat) else: vmin = fmin.reduce(todraw.flat) elif isinstance(vmin, basestring): db = int(vmin[:-3]) vmin = vmax / 10 ** (db/10.) if logscale: log10(todraw, todraw) vmin = log10(vmin) vmax = log10(vmax) print 'vmax, vmin =' , vmax, vmin image = zeros(dtype = ('u1', 4), shape = todraw.shape) # gacolor is much faster then matplotlib's normalize and uses less memory(4times fewer). if not hasattr(cmap, 'table'): cmap = gacmap(cmap) ccode.color(image, todraw, max = vmax, min = vmin, logscale=False, colormap = cmap) del todraw if mode == 'intensity': weight = mass if logweight: # in camera mode do not use logscale for mass. weight.clip(ccode.pmin.reduce(weight.ravel()), inf, weight) log10(weight, weight) print 'weight', weight.mean(), weight.max(), weight.min() if mmin is None: mmin = weight.min() if mmax is None: if over is None: mmax = weight.max() else: sort = weight.ravel().argsort() ind = sort[(len(sort) - 1) * (1.0 - over)] mmax = weight.ravel()[ind] print 'mmax, mmin', mmax, mmin weight -= mmin weight /= (mmax - mmin) weight.clip(0, 1, weight) else: weight = image[:, :, 3] / 255.0 weight **= gamma if composite is not None: alpha = composite[:, :, 3] / 255.0 multiply(1.0 - weight[:, :], alpha[:, :], alpha[:, :]) multiply(image[:, :, 0:3], weight[:, :, newaxis], image[:, :, 0:3]) multiply(composite[:, :, 0:3], alpha[:, :, newaxis], composite[:, :, 0:3]) add(image[:, :, 0:3], composite[:, :, 0:3], image[:, :, 0:3]) image[:, :, 3] = (alpha[:, :] + weight[:, :]) * 255 else: #multiply(image[:, :, 0:3], weight[:, :, newaxis], image[:, :, 0:3]) #image[:, :, 3] = 255 #weight **= 0.33333333333 multiply(255.9999, weight[:, :], out=image[:,:,3], casting='unsafe') # print 'alpha', image[:, :, 3].ravel().min(), image[:,:,3].ravel().max() return image