def stretch(array, function, exponent=2, midpoint=None): if function == 'linear': return array elif function == 'log': if not m.isnumeric(midpoint): midpoint = 0.05 return np.log10(array/midpoint+1.) / np.log10(1./midpoint+1.) elif function == 'sqrt': return np.sqrt(array) elif function == 'arcsinh': if not m.isnumeric(midpoint): midpoint = -0.033 return np.arcsinh(array/midpoint) / np.arcsinh(1./midpoint) elif function == 'power': return np.power(array, exponent) else: raise Exception("Unknown function : " + function)
def stretch(array, function, exponent=2, midpoint=None): if function is 'linear': return array elif function is 'log': if not m.isnumeric(midpoint): midpoint = 0.05 return np.log10(array/midpoint+1.) / np.log10(1./midpoint+1.) elif function is 'sqrt': return np.sqrt(array) elif function is 'arcsinh': if not m.isnumeric(midpoint): midpoint = -0.033 return np.arcsinh(array/midpoint) / np.arcsinh(1./midpoint) elif function is 'power': return np.power(array, exponent) else: raise Exception("Unknown function : " + function)
def __call__(self, x_new): ipos = np.searchsorted(self.x, x_new) if m.isnumeric(x_new): if ipos == 0: ipos = 1 if ipos == len(self.x): ipos = len(self.x)-1 else: ipos[ipos == 0] = 1 ipos[ipos == len(self.x)] = len(self.x)-1 ipos = ipos - 1 return (x_new - self.x[ipos]) * self.dy[ipos] + self.y[ipos]