SourceXtractorPlusPlus  0.11
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
aperture.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 
3 # Copyright © 2019 Université de Genève, LMU Munich - Faculty of Physics, IAP-CNRS/Sorbonne Université
4 #
5 # This library is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation; either version 3.0 of the License, or (at your option)
8 # any later version.
9 #
10 # This library is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this library; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 from __future__ import division, print_function
19 from .measurement_images import MeasurementImage, MeasurementGroup
20 
21 import _SourceXtractorPy as cpp
22 
23 apertures_for_image = {}
24 
25 
26 Aperture = cpp.Aperture
27 
28 
29 def add_aperture_photometry(target, apertures):
30  """
31  Flux measurement from the image above the background inside a circular aperture.
32 
33  Parameters
34  ----------
35  target : MeasurementImage object, or leaf MeasurementGroup object with a single image, or a list of either
36  Target images on which to measure the aperture photometry. Leaf MeasurementGroup with a single image
37  are accepted as a convenience.
38 
39  apertures : float, or list of float
40  Diameter of the aperture. As different MeasurementImage may not be aligned, nor have equivalent pixel size,
41  the aperture is interpreted as diameter in pixels of a circle on the detection image.
42  A transformation will be applied for each frame, so the covered area is equivalent.
43 
44  Returns
45  -------
46  list of Aperture objects
47  An Aperture object is an internal representation of a property on the measurement frame that contains the
48  apertures. To actually get the measurements on the output catalog, you need to add explicitly them to the
49  output.
50 
51  See Also
52  --------
53  add_output_column
54 
55  Notes
56  -----
57  This property will generate five columns with the prefix specified by `add_output_column`:
58  - ``_flux`` and ``_flux_err``, for the flux and its associated error
59  - ``_mag`` and ``_mag_err``, for the magnitude and its associated error
60  - ``_flags``, to mark, for instance, saturation, boundary conditions, etc.
61 
62  For M apertures and N images, the cells on the output column will be an array of MxN fluxes.
63 
64  Examples
65  --------
66  >>> measurement_group = MeasurementGroup(load_fits_images(frames, psfs))
67  >>> all_apertures = []
68  >>> for img in measurement_group:
69  >>> all_apertures.extend(add_aperture_photometry(img, [5, 10, 20]))
70  >>> add_output_column('aperture', all_apertures)
71  """
72  if not isinstance(target, list):
73  target = [target]
74  if not isinstance(apertures, list):
75  apertures = [apertures]
76 
77  apertures = [float(a) for a in apertures]
78  outputs = []
79 
80  for t in target:
81  if isinstance(t, MeasurementGroup):
82  if not t.is_leaf():
83  raise Exception('The MeasurementGroup is not a leaf')
84  elif len(t) != 1:
85  raise Exception('The MeasurementGroup contains {} images'.format(len(t)))
86  t = [i for i in t][0]
87 
88  if not isinstance(t, MeasurementImage):
89  raise Exception('Only MeasurementImage supported as targets, got {}'.format(type(t)))
90  else:
91  if t.id in apertures_for_image:
92  raise Exception('Apertures already set for the image {}'.format(t.id))
93  apertures_for_image[t.id] = cpp.Aperture(apertures)
94  outputs.append(apertures_for_image[t.id])
95 
96  return outputs