-
Notifications
You must be signed in to change notification settings - Fork 2
/
FFI_photometry.py
66 lines (46 loc) · 1.76 KB
/
FFI_photometry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Brigitta Sipocz 2016 --
#
# Photometry of Kepler Full Frame Images using the Astropy stack
import glob
import numpy as np
import os
from astropy.coordinates import match_coordinates_sky
from astropy.io import fits
from astropy.stats import mad_std
from astropy.wcs.utils import pixel_to_skycoord
from astropy.wcs import WCS
from astropy.utils.misc import isiterable
from photutils import daofind, aperture_photometry, CircularAperture
def do_photometry(hdu, extensions=None, threshold=5, fwhm=2.5):
if extensions is None:
extensions = np.arange(1, len(hdu))
if not isiterable(extensions):
extensions = (extensions, )
output = {}
for ext in extensions:
header = hdu[ext].header
data = hdu[ext].data
image_wcs = WCS(header)
background = mad_std(data)
sources = daofind(data, threshold=threshold * background, fwhm=fwhm)
positions = (sources['xcentroid'], sources['ycentroid'])
sky_positions = pixel_to_skycoord(*positions, wcs=image_wcs)
apertures = CircularAperture(positions, r=2.)
photometry_table = aperture_photometry(data, apertures)
photometry_table['sky_center'] = sky_positions
output[str(ext)] = photometry_table
return output
def cross_match_ffi(reference_sources, input_sources):
# TODO sort out the matchings from the tuple, do something with the
# duplicates
matching = match_coordinates_sky(reference_sources, input_sources)
return matching
input_files = glob.glob('data/kplr*ffi-cal.fits')
phot_results = {}
for ffi in input_files:
ffi_name = os.path.basename(ffi).split('_')[0]
ffi_hdu = fits.open(ffi)
phot_results[ffi_name] = do_photometry(ffi_hdu, extensions=1)