I have an image with size 3000 * 3000 pixels. I first find the center of my interested area, say at position (1000,2000). I want to extract the data within the annulus with R1 = 10 pixels, R2 = 20 pixels and find the mode of the data within the annulus. Is there any python routine to do that or any smart and concise way to implement it? I know the photutils.aperture_photometry
can get the sum of the annulus, but not any individual data points at each pixel.
import numpy as np
data = np.random.uniform(0,10,size=(3000,3000))
center = (1000,2000) #### in pixel space
R1 = 10 #### pixels
R2 = 20 #### pixels
....
There is no any answer...... Astonished. I have very straightforward two loops function to do that.
imin = center[0] - R2
imax = center[0] + R2 + 1
jmin = center[1] - R2
jmax = center[1] + R2 + 1
target = []
for i in np.arange(imin, imax):
for j in np.arange(jmin, jmax):
ij = np.array([i,j])
dist = np.linalg.norm(ij - np.array(center))
if dist > R1 and dist <= R2:
target.append([i,j,data[i][j]])
target = np.array(target)
Any better implementation?