def moon_mask(img): """Generate a masking array that covers the moon in a given image. Parameters --------- img : image.AllSkyImage The image. Returns ------- numpy.ndarray An array where pixels inside the moon are marked with False and those outside the moon are marked with True. """ # Get the fraction visible for interpolation and find the # location of the moon. vis = moon_phase(img) x, y, _ = find_moon(img) # Creates the circle patch we use. r = moon_circle(vis) circ = Circle((x, y), r, fill=False) # The following code converts the patch to a 512x512 mask array, with True # for values outside the circle and False for those inside. # This is the same syntax as np.ma.make_mask returns. # This section of code generates an 262144x2 array of the # 512x512 pixel locations. 262144 = 512^2 points = np.zeros((512**2, 2)) index = 0 for i in range(0, 512): for j in range(0, 512): # These are backwards as expected due to how reshape works later. # Points is in x,y format, but reshape reshapes such that # it needs to be in y,x format. points[index, 0] = j points[index, 1] = i index += 1 # Checks all the points are inside the circle, then reshapes it to the # 512x512 size. mask = circ.contains_points(points) mask = mask.reshape(512, 512) return mask