00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033
00034 #include <math.h>
00035
00036 #include "vircam_mods.h"
00037 #include "vircam_utils.h"
00038 #include "vircam_wcsutils.h"
00039 #include "vircam_fits.h"
00040 #include "catalogue/imcore.h"
00041 #include "vircam_pfits.h"
00042
00043 #define NOMPIXSIZE 0.34
00044
00045 static double pixsize (cpl_propertylist *plist);
00046
00049
00148
00149
00150 extern int vircam_imcore(vir_fits *infile, vir_fits *conf, int ipix,
00151 float threshold, int icrowd, float rcore, int nbsize,
00152 int cattyp, float filtfwhm, vir_tfits **outtab,
00153 int *status) {
00154 int retval;
00155 const char *fctid = "vircam_imcore";
00156 cpl_propertylist *plist,*elist;
00157 vir_fits *in,*c;
00158 double pixarcsec,*cd,theta_east,theta_north,theta_north_2;
00159 float fwhm,fitpa;
00160 cpl_wcs *wcs;
00161
00162
00163
00164 *outtab = NULL;
00165 if (*status != VIR_OK)
00166 return(*status);
00167
00168
00169
00170 cattype = cattyp;
00171 in = vircam_fits_duplicate(infile);
00172 c = vircam_fits_duplicate(conf);
00173
00174
00175
00176 retval = imcore_conf(in,c,ipix,threshold,icrowd,rcore,nbsize,cattype,
00177 filtfwhm,outtab);
00178 vircam_fits_delete(in);
00179 vircam_fits_delete(c);
00180 if (retval != VIR_OK)
00181 FATAL_ERROR;
00182 if ((int)cpl_table_get_nrow(vircam_tfits_get_table(*outtab)) == 0) {
00183 cpl_msg_warning(fctid,"No objects found in %s",
00184 vircam_fits_get_fullname(infile));
00185 freetfits(*outtab);
00186 WARN_RETURN
00187 }
00188
00189
00190
00191 plist = vircam_fits_get_phu(infile);
00192 if (plist == NULL) {
00193 cpl_msg_error(fctid,"Unable to open propertylist %s",
00194 vircam_fits_get_filename(infile));
00195 FATAL_ERROR
00196 }
00197
00198
00199
00200 retval = classify(*outtab,plist,16.0,cattype);
00201 if (retval != VIR_OK)
00202 WARN_RETURN
00203
00204
00205
00206 elist = vircam_fits_get_ehu(infile);
00207 pixarcsec = pixsize(elist);
00208 fwhm = cpl_propertylist_get_float(vircam_tfits_get_ehu(*outtab),
00209 "ESO QC IMAGE_SIZE");
00210 fwhm *= pixarcsec;
00211 cpl_propertylist_update_float(vircam_tfits_get_ehu(*outtab),
00212 "ESO QC IMAGE_SIZE",fwhm);
00213 cpl_propertylist_set_comment(vircam_tfits_get_ehu(*outtab),
00214 "ESO QC IMAGE_SIZE",
00215 "[arcsec] Average FWHM of stellar objects");
00216
00217
00218
00219
00220 fitpa = cpl_propertylist_get_float(vircam_tfits_get_ehu(*outtab),
00221 "ESO QC POSANG");
00222 if (fitpa != 0.0) {
00223 wcs = cpl_wcs_new_from_propertylist(elist);
00224 cd = cpl_matrix_get_data((cpl_matrix *)cpl_wcs_get_cd(wcs));
00225 theta_east = DEGRAD*atan2(cd[1],cd[0]);
00226 theta_north = DEGRAD*atan2(cd[3],cd[2]);
00227 theta_north_2 = (theta_north < 0.0 ? theta_north + 360.0 : theta_north);
00228 if (abs(theta_north-theta_east-90.0) < 5.0 ||
00229 abs(theta_north-theta_east+270.0) < 5.0) {
00230 fitpa = theta_north_2 - fitpa;
00231 } else {
00232 fitpa = 360.0 - theta_north_2 + fitpa;
00233 }
00234 if (fitpa < 0.0)
00235 fitpa += 360.0;
00236 if (fitpa > 180.0)
00237 fitpa -= 180.0;
00238 cpl_wcs_delete((cpl_wcs *)wcs);
00239 cpl_propertylist_update_float(vircam_tfits_get_ehu(*outtab),
00240 "ESO QC POSANG",fitpa);
00241 cpl_propertylist_set_comment(vircam_tfits_get_ehu(*outtab),
00242 "ESO QC POSANG",
00243 "[degrees] Median position angle (from North)");
00244 }
00245
00246 GOOD_STATUS
00247 }
00248
00249
00266
00267
00268 static double pixsize (cpl_propertylist *plist) {
00269 double cd1_1,cd1_2,pix;
00270
00271 if (vircam_pfits_get_cd11(plist,&cd1_1) != VIR_OK ||
00272 vircam_pfits_get_cd12(plist,&cd1_2) != VIR_OK) {
00273 pix = NOMPIXSIZE;
00274 } else {
00275 pix = 3600.0*sqrt(cd1_1*cd1_1 + cd1_2*cd1_2);
00276 }
00277 return(pix);
00278 }
00279
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372