def distance(shape, center=None, scale=1, dtype=float, out=None): """ Returns an array whose values are the distances to a given center. Parameters ---------- shape : tuple of integer dimensions of the output array. For a 2d array, the first integer is for the Y-axis and the second one for the X-axis. center : array-like, optional The coordinates (x0, y0, ...) of the point from which the distance is calculated, assuming a zero-based coordinate indexing. Default value is the array center. scale : float or array-like, optional Inter-pixel distance (dx, dy, ...). If scale is a Quantity, its unit will be carried over to the returned distance array dtype : np.dtype, optional The output data type. Example ------- nx, ny = 3, 3 print(distance((ny,nx))) [[ 1.41421356 1. 1.41421356] [ 1. 0. 1. ] [ 1.41421356 1. 1.41421356]] """ shape = tointtuple(shape) dtype = np.dtype(dtype) unit = getattr(scale, '_unit', None) if out is None: out = np.empty(shape, dtype) ndim = out.ndim dtype = float_intrinsic_dtype(out.dtype) if ndim in (1, 2) and dtype != out.dtype: out_ = np.empty(shape, dtype) else: out_ = out if center is None: center = (np.array(shape[::-1]) - 1) / 2 else: center = np.ascontiguousarray(center, dtype) if isscalarlike(scale): scale = np.resize(scale, out.ndim) scale = np.ascontiguousarray(scale, dtype) if ndim in (1, 2): fname = 'distance_{0}d_r{1}'.format(ndim, dtype.itemsize) func = getattr(flib.datautils, fname) if ndim == 1: func(out_, center[0], scale[0]) else: func(out_.T, center, scale) if not isalias(out, out_): out[...] = out_ else: _distance_slow(shape, center, scale, dtype, out) return Map(out, copy=False, unit=unit)
def profile(input, bin=1, nbins=None, histogram=False, center=None, scale=1): """ Returns axisymmetric profile of a 2d image. x, y[, n] = profile(image, [center, bin, nbins, histogram=True]) Parameters ---------- input: array 2d input array bin: number, optional Width of the profile bins. nbins: integer, optional Number of profile bins. histogram: boolean, optional If set to True, return the histogram. center : array-like, optional Center (x0, y0) of the profile, in pixel coordinates. By convention, the coordinates of the center of the pixel [0, 0] are (0, 0). Default is the image center. scale : float, optional The inter-pixel distance. """ input = np.array(input, order='c', copy=False) dtype = float_intrinsic_dtype(input.dtype) input = np.array(input, dtype=dtype, copy=False) if center is None: center = (np.array(input.shape[::-1], dtype) - 1) / 2 else: center = np.ascontiguousarray(center, dtype) bin_scaled = bin / scale if nbins is None: nbins = int( max(input.shape[0] - center[1], center[1], input.shape[1] - center[0], center[0]) / bin_scaled) fname = 'profile_axisymmetric_2d_r{}'.format(dtype.itemsize) func = getattr(flib.datautils, fname) x, y, n = func(input.T, center, bin_scaled, nbins) x *= scale if histogram: return x, y, n else: return x, y
def profile(input, bin=1, nbins=None, histogram=False, center=None, scale=1): """ Returns axisymmetric profile of a 2d image. x, y[, n] = profile(image, [center, bin, nbins, histogram=True]) Parameters ---------- input: array 2d input array bin: number, optional Width of the profile bins. nbins: integer, optional Number of profile bins. histogram: boolean, optional If set to True, return the histogram. center : array-like, optional Center (x0, y0) of the profile, in pixel coordinates. By convention, the coordinates of the center of the pixel [0, 0] are (0, 0). Default is the image center. scale : float, optional The inter-pixel distance. """ input = np.array(input, order='c', copy=False) dtype = float_intrinsic_dtype(input.dtype) input = np.array(input, dtype=dtype, copy=False) if center is None: center = (np.array(input.shape[::-1], dtype) - 1) / 2 else: center = np.ascontiguousarray(center, dtype) bin_scaled = bin / scale if nbins is None: nbins = int(max(input.shape[0]-center[1], center[1], input.shape[1]-center[0], center[0]) / bin_scaled) fname = 'profile_axisymmetric_2d_r{}'.format(dtype.itemsize) func = getattr(flib.datautils, fname) x, y, n = func(input.T, center, bin_scaled, nbins) x *= scale if histogram: return x, y, n else: return x, y