python - Determine the coordinates of local maximas in a two-dimensional array using derivative -


i have fits image , trying find coordinates of local maxima in image far couldn't quite make work. my image can find here. have far

import numpy np import scipy.nimage ndimage astropy.wcs import wcs astropy import units u astropy import coordinates coord astropy.io import fits import scipy.ndimage.filters filters scipy.ndimage.filters import maximum_filter hdulist=fits.open("mapsnr.fits") #reading 2 dimensional array 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 image maximum print c.ra print c.dec 

that how can find global maximum of image, obtain coordinates of local maximas have the significance of being greater three.

what have found looking in web this following answer doesn't work in case. update: have used 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 background   labeled, num_objects = ndimage.label(maxima)   slices = ndimage.find_objects(labeled)   x,y=[],[]   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 find method using better approach derivative in array or divide , conquer method. appropriate better recommended solution.

you use photutils.detection.find_peaks function, 1 of photutils detection methods.

if @ photutils.detection.find_peaks implementation, you'll see it's using scipy.ndimage.maximum_filter compute maximum image (by default in 3x3 box size footprint) , finding pixels original image equals maximum image.

the rest of function 2 things might of interest you:

  1. if pass in wcs object, can sky coordinates out, not pixel coordinates.
  2. there's option sub-pixel precision coordinates.

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

Python Error - TypeError: input expected at most 1 arguments, got 3 -

dns - How To Use Custom Nameserver On Free Cloudflare? -