Guest User

Untitled

a guest
Jul 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. from astropy.stats import gaussian_fwhm_to_sigma
  5. from astropy.convolution import Gaussian2DKernel
  6. from astropy.wcs import WCS
  7. import astropy.units as u
  8.  
  9. from photutils import detect_threshold, source_properties, detect_sources
  10. from photutils import SkyEllipticalAperture
  11. from photutils import datasets
  12.  
  13. # get a mock image
  14. hdu = datasets.load_star_image()
  15. threshold = detect_threshold(hdu.data, snr=3.)
  16. image_wcs = WCS(hdu.header)
  17.  
  18. # detect sources
  19. sigma = 2.0 * gaussian_fwhm_to_sigma
  20. kernel = Gaussian2DKernel(sigma, x_size=3, y_size=3)
  21. kernel.normalize()
  22. segm = detect_sources(hdu.data, threshold, npixels=5, filter_kernel=kernel)
  23.  
  24. # get properties of detected objects
  25. props = source_properties(hdu.data, segm, wcs=image_wcs)
  26.  
  27.  
  28. # ---
  29. # create a sky aperture using detected properties
  30.  
  31. # the unit of "semimajor_axis_sigma" should be "pix"
  32. print(props[0].semimajor_axis_sigma.unit)
  33.  
  34. # this works
  35. aperture_1 = SkyEllipticalAperture(positions=props[0].sky_centroid,
  36. a=props[0].semimajor_axis_sigma.value * u.pix,
  37. b=props[0].semiminor_axis_sigma.value * u.pix,
  38. theta=props[0].orientation)
  39.  
  40. # but this doesn't
  41. aperture_2 = SkyEllipticalAperture(positions=props[0].sky_centroid,
  42. a=props[0].semimajor_axis_sigma,
  43. b=props[0].semiminor_axis_sigma,
  44. theta=props[0].orientation)
Add Comment
Please, Sign In to add comment