ERIS Pipeline Reference Manual 1.9.2
eris_nix_img_cal_wcs.c
1/* $Id$
2 *
3 * This file is part of the ERIS Pipeline
4 * Copyright (C) 2017 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/*
22 * $Author$
23 * $Date$
24 * $Revision$
25 */
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31/*-----------------------------------------------------------------------------
32 Includes
33 -----------------------------------------------------------------------------*/
34
35#include <string.h>
36#include "eris_nix_utils.h"
37#include "eris_nix_dfs.h"
38#include "eris_nix_scired.h"
39#include <hdrl.h>
40
41#include <cpl.h>
42
43/*-----------------------------------------------------------------------------
44 Static variables
45 -----------------------------------------------------------------------------*/
46
47static const char eris_nix_img_cal_wcs_description[] =
48"This recipe calibrates the astrometry of ERIS/NIX frames.\n"
49"\n"
50" Input files:\n"
51" DO CATG Explanation Req. #Frames\n"
52" ------- ----------- --- -------\n"
53" "ERIS_NIX_SKYSUB_OBJECT_JITTER_PRO_CATG
54 " sky-subtracted Y 1-n\n"
55" target frames\n"
56" or\n"
57" "ERIS_NIX_SKYSUB_STD_JITTER_PRO_CATG
58 " sky-subtracted Y 1-n\n"
59" STD frames\n"
60" "ERIS_NIX_WCS_MATCHED_CATALOGUE_PRO_CATG
61 " manual match of N 0-1\n"
62" stars in first\n"
63" jitter to RA, Dec\n"
64"\n"
65" Output files:\n"
66"\n"
67" DO CATG Explanation Name\n"
68" ------- ----------- ----\n"
69" "ERIS_NIX_CAL_WCS_OBJECT_JITTER_PRO_CATG
70 " The wcs cal_wcs.<in_name>\n"
71" calibrated\n"
72" target frame\n"
73" or\n"
74" "ERIS_NIX_CAL_WCS_STD_JITTER_PRO_CATG
75 " The wcs cal_wcs.<in_name>\n"
76" calibrated\n"
77" STD frame\n"
78"\n"
79" There are two stages to the calibration. \n"
80"\n"
81" First, the jitter nearest the centre of the jitter pattern is \n"
82" identified as the 'reference' jitter. The wcs of the 'reference'\n"
83" jitter is calibrated in one of 3 ways as described further below.\n"
84" The aim is to calibrate this jitter against an absolute\n"
85" reference such as Gaia.\n"
86"\n"
87" Second, the wcs calibration is propagated to other jitters in\n"
88" turn, adding them to the calibrated pool as we go. At each step\n"
89" the next jitter to calibrate is the one with the largest overlap\n"
90" with a jitter in the calibrated pool, so the most likely to have\n"
91" sources in common. The calibration is achieved by comparing their\n"
92" source catalogues.\n"
93"\n"
94"\n"
95" Catalogues are matched by trying all possible associations between \n"
96" their objects and calculating a metric of the pattern match for \n"
97" each - that is, the number of object pairs that lie within a \n"
98" small distance of each other. The association with the highest \n"
99" number of matches is selected.\n"
100"\n"
101" The catalogues are sorted in order of decreasing brightness \n"
102" using column 'Aper_flux_3', if it exists. If few sources are \n"
103" present this means that matches between the brightest \n"
104" will be favoured.\n"
105"\n"
106" When a match is found the wcs of the image to be calibrated is \n"
107" recalculated to make the matched sources coincide.\n"
108"\n"
109"\n"
110" The 'reference' jitter can be calibrated in one of 3 ways:\n"
111"\n"
112"1. If an online astrometric catalogue is specified by parameter\n"
113" cdssearch-astrom it will be searched over the area of the\n"
114" jitter image for astrometric standards. \n"
115"\n"
116" In this case, if the calibration succeeds the headers of the \n"
117" output files will have keywords:\n"
118" -- ESO.WCS_METHOD = '"ERIS_NIX_WCS_CATALOGUE_MATCH"'\n"
119" -- WCS_CAT = <the name of the catalogue used>\n"
120"\n"
121"2. If no reference catalogue is given, cdssearch-astrom is \n"
122" 'none', then the wcs cannot be calibrated absolutely and \n"
123" the recipe can only align the jitters relative to the \n"
124" 'reference'. \n"
125"\n"
126" If the calibration succeeds the output files will have \n"
127" keywords:\n"
128" -- ESO.WCS_METHOD = '"ERIS_NIX_WCS_JITTER_RELATIVE"'\n"
129" -- WCS_CAT = 'none'\n"
130"\n"
131"3. The user can directly specify a position in the 'reference'\n"
132" jitter. This is done by putting the required information \n"
133" in a FITS table and including that file in the SoF with tag\n"
134" "ERIS_NIX_WCS_MATCHED_CATALOGUE_PRO_CATG".\n"
135"\n"
136" The format of the FITS table should be:\n"
137"\n"
138"Filename RA Dec X_coordinate Y_coordinate Catalogue\n"
139"xyz.fits 99.791... 8.736... 544 599.5 Gaia\n"
140"abc.fits 99.791... 8.736... 561.5 595.2 Gaia\n"
141"pqr.fits 99.791... 8.736... 557.2 496.8 Gaia\n"
142" . . . . . .\n"
143"\n"
144" where:\n"
145" Filename holds the name of the 'reference' jitter.\n"
146" RA and Dec hold the coords in degrees of the index position.\n"
147" X_coordinate and Y_coordinate hold the x,y coords of the \n"
148" index position.\n"
149" Catalogue has the name of the source catalogue of RA, Dec.\n"
150"\n"
151" If the 'Catalogue' entry is 'Gaia' or '2mass' then the output\n"
152" file will have keywords:\n"
153" -- ESO.WCS_METHOD = '"ERIS_NIX_WCS_CATALOGUE_MATCH"'\n"
154" -- WCS_CAT = <the name of the catalogue used>\n"
155" otherwise:\n"
156" -- ESO.WCS_METHOD = '"ERIS_NIX_WCS_JITTER_RELATIVE"'\n"
157" -- WCS_CAT = 'none'\n"
158"\n"
159"\n"
160" If the calibration fails then the wcs of the file is not modified\n"
161" and the relevant header keywords are set thus:\n"
162" -- ESO.WCS_METHOD = '"ERIS_NIX_WCS_TEL_POINTING"'\n"
163" -- WCS_CAT = 'none'\n";
164
165#define RECIPE_NAME "eris_nix_img_cal_wcs"
166#define CONTEXT "eris."RECIPE_NAME
167/*-----------------------------------------------------------------------------
168 Private function prototypes
169 -----------------------------------------------------------------------------*/
170
171cpl_recipe_define(eris_nix_img_cal_wcs, ERIS_BINARY_VERSION,
172 "John Lightfoot",
173 PACKAGE_BUGREPORT, "2017",
174 "Calibrate wcs of ERIS/NIX frames",
175 eris_nix_img_cal_wcs_description);
176
177/*-----------------------------------------------------------------------------
178 Function code
179 -----------------------------------------------------------------------------*/
180
181/*----------------------------------------------------------------------------*/
189/*----------------------------------------------------------------------------*/
190
191static cpl_error_code eris_nix_img_cal_wcs_fill_parameterlist(
192 cpl_parameterlist * self) {
193
194 if (cpl_error_get_code() != CPL_ERROR_NONE) return cpl_error_get_code();
195
196 hdrl_parameter * catalogue_defaults = NULL;
197 cpl_parameterlist * catalogue_parlist = NULL;
198 cpl_parameter * p = NULL;
199
200 /* generate the general parameter list for the catalogue */
201
202 catalogue_defaults = hdrl_catalogue_parameter_create(20, 3.0, CPL_TRUE,
203 10.0, CPL_TRUE, 128, 5.0, 3.0,
204 ERIS_NIX_SATURATION_DEFAULT, HDRL_CATALOGUE_ALL);
205 catalogue_parlist = hdrl_catalogue_parameter_create_parlist(CONTEXT,
206 "catalogue", catalogue_defaults);
207
208 /* subset of parameters to be used */
209
210 for (p = cpl_parameterlist_get_first(catalogue_parlist);
211 p != NULL;
212 p = cpl_parameterlist_get_next(catalogue_parlist)) {
213
214 const char * pname = cpl_parameter_get_name(p);
215 if (strstr(pname, "minmax") == NULL) {
216 cpl_parameter * duplicate = cpl_parameter_duplicate(p);
217 cpl_parameterlist_append(self, duplicate);
218 }
219 }
220
221 /* ..add ao-params which specifies how to set params depending on AO */
222
223 p = cpl_parameter_new_enum(CONTEXT".catalogue.ao-params",
224 CPL_TYPE_STRING,
225 "Default catalogue.core-radius and "
226 "catalogue.mesh-size depending on "
227 "AOMODE, or not",
228 CONTEXT,
229 "auto", 2, "auto", "user");
230 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "catalogue.ao-params");
231 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
232 cpl_parameterlist_append(self, p);
233
234 /* Flag to decide how we get the astrometric standard star information.
235 If "none", then use the local catalogues specified in the sof. If not,
236 then use one of the selection of catalogues available from CDS -
237 only gaia has sufficient accuracy */
238
239 p = cpl_parameter_new_enum(CONTEXT".cdssearch_astrom",
240 CPL_TYPE_STRING,
241 "CDS astrometric catalogue",
242 CONTEXT,
243 "none", 3, "none", "2mass", "gaiadr3");
244 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "cdssearch-astrom");
245 cpl_parameterlist_append(self, p);
246
247 p = cpl_parameter_new_value(CONTEXT".debug-data",
248 CPL_TYPE_BOOL, "true to save interim results",
249 CONTEXT, CPL_FALSE);
250 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "debug-data");
251 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
252 cpl_parameterlist_append(self, p);
253
254 p = cpl_parameter_new_value(CONTEXT".edges-trim",
255 CPL_TYPE_STRING,
256 "Trim image edges in the source detection: "
257 "[txmin,tymin,txmax,tymax]. t means trim "
258 "the user can trim differently from the min and "
259 "max image edge values along X and Y axes",
260 CONTEXT, "30,30,30,30");
261 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "edges-trim");
262 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
263 cpl_parameterlist_append(self, p);
264
265 /* tidy up */
266
267 hdrl_parameter_delete(catalogue_defaults);
268 cpl_parameterlist_delete(catalogue_parlist);
269
270 return 0;
271}
272
273
274/*----------------------------------------------------------------------------*/
281/*----------------------------------------------------------------------------*/
282
283static int eris_nix_img_cal_wcs(cpl_frameset * frameset,
284 const cpl_parameterlist * parlist) {
285
286 eris_nix_scired_cal_wcs(frameset, parlist, RECIPE_NAME, CONTEXT);
287
288
289 return (int) cpl_error_get_code();
290}
cpl_error_code eris_nix_scired_cal_wcs(cpl_frameset *frameset, const cpl_parameterlist *parlist, const char *recipe_name, const char *context)
This recipe calibrates the astrometry of ERIS/NIX frames.
hdrl_parameter * hdrl_catalogue_parameter_create(int obj_min_pixels, double obj_threshold, cpl_boolean obj_deblending, double obj_core_radius, cpl_boolean bkg_estimate, int bkg_mesh_size, double bkg_smooth_fwhm, double det_eff_gain, double det_saturation, hdrl_catalogue_options resulttype)
Creates catalogue Parameters object.
cpl_parameterlist * hdrl_catalogue_parameter_create_parlist(const char *base_context, const char *prefix, hdrl_parameter *defaults)
Create parameter list for the catalogue computation.
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter