disk - The type is bool. Array values of 1 indicate that...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import numpy as np def disk(r, center, shape): ''' Makes a bool array containing an N-dimensional ellipsoid mask. Parameters ---------- r : scalar or N-dimensional tuple The radii of the ellipsoid, may be fractional. If N-dimensional, elliptical radii are specified in each dimension. If scalar, same radius applies to all dimensions. center : tuple Gives the position of the center of the ellipsoid, may be fractional and of any dimension. Note that if the desired "ellipsoid" is 1D, specifying (20) on the command line results in an int, not a tuple containing an int. Say (20,) to force a tuple containing an int. shape : tuple, int Gives the shape of the output array. Must be integer and same length as center. Returns ------- output : boolean array This function returns a bool array containing an N-dimensional ellipsoid (line segment, filled ellipse, ellipsoid, etc.). The ellipsoid is centered at center and has the radii given by r. Shape specifies the shape.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The type is bool. Array values of 1 indicate that the center of a pixel is within the given ellipsoid. Pixel values of 0 indicate the opposite. The center of each pixel is the integer position of that pixel. Examples-------->>> import pylab as plt >>> import disk >>> r = (110, 150) >>> center = (230, 220) >>> shape = (600, 500) >>> plt.imshow(disk.disk(r, center, shape), origin='lower', interpolation='nearest') >>> plt.gray() >>> plt.show() Revisions---------2003-04-04 0.1 jh@oobleck.astro.cornell.edu Initial version. 2007-11-25 0.2 jh@physics.ucf.edu IDL->Python, made N-dimensional. 2008-11-04 0.3 kstevenson@physics.ucf.edu Updated docstring ''' idisk = np.indices(shape, dtype=float) cctr = np.asarray(center) sshape = np.ones(1 + cctr.size) sshape[0] = cctr.size cctr.shape = sshape rr = np.asarray(r) rshape = np.ones(1+rr.size) rshape[0] = rr.size rr.shape = rshape return np.sum(((idisk - cctr)/rr)**2, axis=0) <= 1....
View Full Document

Page1 / 2

disk - The type is bool. Array values of 1 indicate that...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online