VIRCAM Pipeline 2.3.15
casu_imcore.c
1/* $Id: casu_imcore.c,v 1.5 2015/11/05 12:00:35 jim Exp $
2 *
3 * This file is part of the CASU Pipeline utilities
4 * Copyright (C) 2015 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: jim $
23 * $Date: 2015/11/05 12:00:35 $
24 * $Revision: 1.5 $
25 * $Name: $
26 */
27
28/* Includes */
29
30#ifdef HAVE_CONFIG_H
31#include <config.h>
32#endif
33
34#include <math.h>
35
36#include "casu_mods.h"
37#include "catalogue/casu_utils.h"
38#include "catalogue/casu_wcsutils.h"
39#include "catalogue/casu_fits.h"
40#include "catalogue/imcore.h"
41
44/*---------------------------------------------------------------------------*/
147/*---------------------------------------------------------------------------*/
148
149extern int casu_imcore(casu_fits *infile, casu_fits *conf, int ipix,
150 float threshold, int icrowd, float rcore, int nbsize,
151 int cattype, float filtfwhm, casu_tfits **outtab,
152 float gainloc, int *status) {
153 int retval;
154 const char *fctid = "casu_imcore";
155 cpl_propertylist *plist,*elist;
156 casu_fits *in,*c;
157 double theta_east,*cd,theta_north,theta_north_2,pixarcsec;
158 float fwhm,fitpa,ell;
159 cpl_wcs *wcs;
160
161 /* Inherited status */
162
163 *outtab = NULL;
164 if (*status != CASU_OK)
165 return(*status);
166
167 /* Copy the input */
168
169 in = casu_fits_duplicate(infile);
170 c = casu_fits_duplicate(conf);
171
172 /* Call the main processing routine and get the catalogue */
173
174
175 retval = imcore_conf(in,c,ipix,threshold,icrowd,rcore,nbsize,cattype,
176 filtfwhm,gainloc,outtab);
179 if (retval != CASU_OK)
180 FATAL_ERROR;
181 if ((int)cpl_table_get_nrow(casu_tfits_get_table(*outtab)) == 0) {
182 cpl_msg_warning(fctid,"No objects found in %s",
183 casu_fits_get_fullname(infile));
184 freetfits(*outtab);
185 WARN_RETURN
186 }
187
188 /* Get the property list from the input frame */
189
190 plist = casu_fits_get_phu(infile);
191 if (plist == NULL) {
192 cpl_msg_error(fctid,"Unable to open propertylist %s",
193 casu_fits_get_filename(infile));
194 FATAL_ERROR
195 }
196
197 /* Do the classification */
198
199 if (cattype != 3) {
200 retval = imcore_classify(*outtab,16.0,cattype);
201 if (retval != CASU_OK)
202 WARN_RETURN
203
204 /* Convert the QC FWHM value to arcsec */
205
206 elist = casu_fits_get_ehu(infile);
207 wcs = cpl_wcs_new_from_propertylist(elist);
208 cd = cpl_matrix_get_data((cpl_matrix *)cpl_wcs_get_cd(wcs));
209 pixarcsec = 3600.0*sqrt(fabs(cd[0]*cd[3] - cd[1]*cd[2]));
210 cpl_wcs_delete((cpl_wcs *)wcs);
211 fwhm = cpl_propertylist_get_float(casu_tfits_get_ehu(*outtab),
212 "ESO QC IMAGE_SIZE");
213 if (fwhm != -1.0)
214 fwhm *= pixarcsec;
216 "ESO QC IMAGE_SIZE",fwhm);
217 cpl_propertylist_set_comment(casu_tfits_get_ehu(*outtab),
218 "ESO QC IMAGE_SIZE",
219 "[arcsec] Average FWHM of stellar objects");
220 casu_propertylist_update_float(elist,"ESO DRS IMAGE_SIZE",fwhm);
221 cpl_propertylist_set_comment(elist,"ESO DRS IMAGE_SIZE",
222 "[arcsec] Average FWHM of stellar objects");
223
224 /* Now convert the median position angle estimate to degrees from
225 North in an Easterly direction...*/
226
227 fitpa = cpl_propertylist_get_float(casu_tfits_get_ehu(*outtab),
228 "ESO QC POSANG");
229 if (fitpa != 0.0) {
230 wcs = cpl_wcs_new_from_propertylist(elist);
231 cd = cpl_matrix_get_data((cpl_matrix *)cpl_wcs_get_cd(wcs));
232 theta_east = DEGRAD*atan2(cd[1],cd[0]);
233 theta_north = DEGRAD*atan2(cd[3],cd[2]);
234 theta_north_2 = (theta_north < 0.0 ? theta_north + 360.0 : theta_north);
235 if (fabs(theta_north-theta_east-90.0) < 5.0 ||
236 fabs(theta_north-theta_east+270.0) < 5.0) {
237 fitpa = theta_north_2 - fitpa;
238 } else {
239 fitpa = 360.0 - theta_north_2 + fitpa;
240 }
241 if (fitpa < 0.0)
242 fitpa += 360.0;
243 if (fitpa > 180.0)
244 fitpa -= 180.0;
245 cpl_wcs_delete((cpl_wcs *)wcs);
246 cpl_propertylist_update_float(casu_tfits_get_ehu(*outtab),
247 "ESO QC POSANG",fitpa);
248 cpl_propertylist_set_comment(casu_tfits_get_ehu(*outtab),
249 "ESO QC POSANG",
250 "[degrees] Median position angle (from North)");
251 }
252
253 /* Add a few things to help with PhaseIII deliverables */
254
256 fwhm);
257 cpl_propertylist_set_comment(casu_tfits_get_ehu(*outtab),"PSF_FWHM",
258 "[arcsec] spatial resolution");
260 fwhm);
261 cpl_propertylist_set_comment(casu_fits_get_ehu(infile),"PSF_FWHM",
262 "[arcsec] spatial resolution");
263 ell = cpl_propertylist_get_float(casu_tfits_get_ehu(*outtab),
264 "ESO QC ELLIPTICITY");
266 ell);
267 cpl_propertylist_set_comment(casu_fits_get_ehu(infile),"ELLIPTIC",
268 "average ellipticity of point sources");
270 ell);
271 cpl_propertylist_set_comment(casu_tfits_get_ehu(*outtab),"ELLIPTIC",
272 "average ellipticity of point sources");
273 }
274 GOOD_STATUS
275}
276
279/*
280
281$Log: casu_imcore.c,v $
282Revision 1.5 2015/11/05 12:00:35 jim
283*** empty log message ***
284
285Revision 1.4 2015/09/30 08:33:06 jim
286superficial changes
287
288Revision 1.3 2015/08/12 11:20:23 jim
289changed call to imcore procedure names where necessary
290
291Revision 1.2 2015/08/07 13:06:54 jim
292Fixed copyright to ESO
293
294Revision 1.1.1.1 2015/06/12 10:44:32 jim
295Initial import
296
297Revision 1.6 2015/02/14 12:31:45 jim
298Modified the way some stuff is written to headers
299
300Revision 1.5 2015/01/29 11:51:56 jim
301modified comments
302
303Revision 1.4 2015/01/09 12:13:15 jim
304*** empty log message ***
305
306Revision 1.3 2014/12/11 12:23:33 jim
307new version
308
309Revision 1.2 2013/11/21 09:38:14 jim
310detabbed
311
312Revision 1.1.1.1 2013-08-27 12:07:48 jim
313Imported
314
315
316*/
void casu_fits_delete(casu_fits *p)
Definition: casu_fits.c:364
char * casu_fits_get_fullname(casu_fits *p)
Definition: casu_fits.c:680
casu_fits * casu_fits_duplicate(casu_fits *in)
Definition: casu_fits.c:225
cpl_propertylist * casu_fits_get_phu(casu_fits *p)
Definition: casu_fits.c:531
char * casu_fits_get_filename(casu_fits *p)
Definition: casu_fits.c:646
cpl_propertylist * casu_fits_get_ehu(casu_fits *p)
Definition: casu_fits.c:576
int casu_imcore(casu_fits *infile, casu_fits *conf, int ipix, float threshold, int icrowd, float rcore, int nbsize, int cattype, float filtfwhm, casu_tfits **outtab, float gainloc, int *status)
Generate object catalogues from input images.
Definition: casu_imcore.c:149
cpl_propertylist * casu_tfits_get_ehu(casu_tfits *p)
Definition: casu_tfits.c:473
cpl_table * casu_tfits_get_table(casu_tfits *p)
Definition: casu_tfits.c:364
void casu_propertylist_update_float(cpl_propertylist *plist, const char *name, float val)
Definition: casu_utils.c:1163
int imcore_conf(casu_fits *infile, casu_fits *conf, int ipix, float threshold, int icrowd, float rcore, int nbsize, int cattype, float filtfwhm, float gain, casu_tfits **outcat)
Do source extraction.
Definition: imcore_conf.c:147
int imcore_classify(casu_tfits *catalogue, float minsize, int cattype)
Do star/galaxy classification.
Definition: classify.c:203