SourceXtractorPlusPlus  0.11
Please provide a description of the project.
output.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 
20 import sys
21 
22 from .model_fitting import ParameterBase
23 from .aperture import Aperture
24 
25 _used_names = set()
26 model_fitting_parameter_columns = []
27 aperture_columns = []
28 
29 _type_column_map = {
30  ParameterBase : model_fitting_parameter_columns,
31  Aperture: aperture_columns
32 }
33 
34 
35 def print_output_columns(file=sys.stderr):
36  """
37  Print a human-readable representation of the configured output columns.
38 
39  Parameters
40  ----------
41  file : file object
42  Where to print the representation. Defaults to sys.stderr
43  """
44  if model_fitting_parameter_columns:
45  print('Model fitting parameter outputs:', file=file)
46  for n, ids in model_fitting_parameter_columns:
47  print(' {} : {}'.format(n, ids), file=file)
48  if aperture_columns:
49  print('Aperture outputs:', file=file)
50  for n, ids in aperture_columns:
51  print(' {} : {}'.format(n, ids), file=file)
52 
53 
54 def add_output_column(name, params):
55  """
56  Add a new set of columns to the output catalog.
57 
58  Parameters
59  ----------
60  name : str
61  Name/prefix of the new set of columns
62  params : list of columns
63  List of properties to add to the output with the given name/prefix. They must be subtype
64  of one of the known ones: ParameterBase for model fitting, or Aperture for aperture photometry.
65 
66  Raises
67  ------
68  ValueError
69  If the name has already been used
70  TypeError
71  If any of the parameters are not of a known type (see params)
72 
73  See Also
74  --------
75  aperture.add_aperture_photometry
76  model_fitting.ParameterBase
77  """
78  if name in _used_names:
79  raise ValueError('Column {} is already set'.format(name))
80  _used_names.add(name)
81 
82  if not isinstance(params, list):
83  params = [params]
84  param_type = type(params[0])
85 
86  known_subclass = False
87  for base in _type_column_map:
88  if issubclass(param_type, base):
89  _type_column_map[base].append((name, params))
90  known_subclass = True
91 
92  if not known_subclass:
93  raise TypeError('{} is not a known column type'.format(str(param_type)))
def print_output_columns(file=sys.stderr)
Definition: output.py:35
def add_output_column(name, params)
Definition: output.py:54