I have a fits
image and I am trying to find the coordinates of local maxima in my image but so far I couldn't quite make it work. My image can be find here.
What I have so far is
import numpy as np
import scipy.nimage as ndimage
from astropy.wcs import WCS
from astropy import units as u
from astropy import coordinates as coord
from astropy.io import fits
import scipy.ndimage.filters as filters
from scipy.ndimage.filters import maximum_filter
hdulist=fits.open("MapSNR.fits")
#reading a two dimensional array from fits file
d=hdulist[0].data
w=WCS("MapSNR.fits")
idx,idy=np.where(d==np.max(d))
rr,dd=w.all_pix2word(idx,idy,o)
c=coord.SkyCoord(ra=rr*u.degree, dec=dd*u.degree)
#The sky coordinate of the image maximum
print c.ra
print c.dec
That is how I can find the global maximum of the image, but I would like to obtain the coordinates of the local maximas which have the significance of being greater than three.
What I have found by looking up in the web was this following answer which doesn't work properly in my case. update: I have used this function
def detect_peaks(data, threshold=1.5, neighborhood_size=5):
data_max = filters.maximum_filter(data, neighborhood_size)
maxima = (data == data_max)
data_min = filters.minimum_filter(data, neighborhood_size)
diff = ((data_max - data_min) > threshold)
maxima[diff == 0] = 0 # sets values <= threshold as background
labeled, num_objects = ndimage.label(maxima)
slices = ndimage.find_objects(labeled)
x,y=[],[]
for dy,dx in slices:
x_center = (dx.start + dx.stop - 1)/2
y_center = (dy.start + dy.stop - 1)/2
x.append(x_center)
y.append(y_center)
return x,y
I would like to find a method using a better approach like the derivative in the array or divide and conquer method. I will appropriate for a better recommended solution.