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 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <math.h>
00039 #include <string.h>
00040
00041 #include "omega_photometry.h"
00042 #include "omega_catalog.h"
00043 #include "omega_dfs.h"
00044 #include "omega_pfits.h"
00045 #include "omega_utils.h"
00046
00065
00077
00078
00079 cpl_table *omega_photom_tbl(const char *star, double gain,
00080 const cpl_frame *refcat, cpl_parameterlist *pars, cpl_table **extra)
00081 {
00082 int i, nsources, nstds;
00083 int npars = 0;
00084 int nmatches = 0;
00085 double exptime = 0.0;
00086 double omega_x1,omega_x2,omega_y1,omega_y2;
00087 double radius = 0.0;
00088 double photom_thre = 0.0;
00089 double airmass = 0.0;
00090 double pixscalex = 0.0;
00091 double pixscaley = 0.0;
00092 double seeing = 0.0;
00093 double ellipticity = 0.0;
00094 double aperture = 0.0;
00095 char *cmd = NULL;
00096 const char *text = NULL;
00097 const char *path;
00098 const char *sex_conf = NULL;
00099 const char *sex_conv = NULL;
00100 const char *sex_par = NULL;
00101 const char *sex_nnw = NULL;
00102 const char *srcs = "omega_cat_photom_sources.fits";
00103 cpl_parameter *par;
00104 cpl_array *status;
00105 cpl_table *sources, *stds, *data;
00106 cpl_table *matchstds = NULL;
00107 cpl_matrix *from, *to;
00108 cpl_wcs *wcs;
00109 cpl_vector *coords;
00110 cpl_propertylist *xlist = NULL;
00111 cpl_propertylist *p, *filterlist;
00112
00113
00114 npars = cpl_parameterlist_get_size(pars);
00115 par = cpl_parameterlist_get_first(pars);
00116
00117 for(i=0; i<npars; i++) {
00118 text = cpl_parameter_get_alias(par, CPL_PARAMETER_MODE_CLI);
00119 if(strcmp("bin-path", text) == 0) {
00120 path = cpl_parameter_get_string(par) ;
00121 }
00122 else if(strcmp("sex-config", text) == 0) {
00123 sex_conf = cpl_parameter_get_string(par) ;
00124 }
00125 else if(strcmp("sex-conv", text) == 0) {
00126 sex_conv = cpl_parameter_get_string(par) ;
00127 }
00128 else if(strcmp("sex-param", text) == 0) {
00129 sex_par = cpl_parameter_get_string(par) ;
00130 }
00131 else if(strcmp("sex-nnw", text) == 0) {
00132 sex_nnw = cpl_parameter_get_string(par) ;
00133 }
00134 else if(strcmp("photom-thre", text) == 0){
00135 photom_thre = cpl_parameter_get_double(par);
00136 }
00137 else if(strcmp("radius", text) == 0){
00138 radius = cpl_parameter_get_double(par);
00139 }
00140 else if(strcmp("aperture", text) == 0){
00141 aperture = cpl_parameter_get_double(par);
00142 }
00143 par = cpl_parameterlist_get_next(pars);
00144
00145 }
00146
00147
00148
00149 cmd = cpl_sprintf("%s/sex %s -c %s -PARAMETERS_NAME %s -FILTER_NAME %s -STARNNW_NAME %s "
00150 "-FILTER Y -DETECT_THRESH %g -ANALYSIS_THRESH %g -GAIN %g -PHOT_APERTURES %g -CATALOG_TYPE FITS_1.0 "
00151 "-CATALOG_NAME %s -CHECKIMAGE_NAME %s -CHECKIMAGE_TYPE OBJECTS -DETECT_MINAREA 5",
00152 path, star, sex_conf, sex_par, sex_conv, sex_nnw, photom_thre, 3.0, gain, aperture,
00153 srcs, "omega_ima_detected_photom_srcs.fits");
00154
00155 cpl_msg_debug(cpl_func,"cmd: %s",cmd);
00156 if (system(cmd) != 0) {
00157 cpl_msg_error(cpl_func,"Failed to detect sources in image using Sextractor");
00158 freespace(cmd);
00159 return NULL;
00160 }
00161 freespace(cmd);
00162
00163 data = cpl_table_load(srcs, 1, 0);
00164 if (data == NULL) {
00165 cpl_msg_error(cpl_func,"Sources table is NULL");
00166 return NULL;
00167 }
00168
00169
00170 sources = omega_filter_table_int(data, "FLAGS", CPL_EQUAL_TO, 0, &nsources);
00171 freetable(data);
00172 cpl_msg_debug(cpl_func,"Number of stars in reduced image: %d", nsources);
00173
00174
00175 xlist = cpl_propertylist_load(star, 1);
00176 omega_get_pixelscale(xlist, &pixscalex, &pixscaley);
00177
00178
00179
00180 p = cpl_propertylist_load(star, 0);
00181
00182
00183 if (cpl_propertylist_has(xlist,"EXTNAME") == 1) {
00184 cpl_propertylist_update_string(p, "EXTNAME",
00185 cpl_propertylist_get_string(xlist, "EXTNAME"));
00186
00187 }
00188
00189 filterlist = omega_pfits_get_filter_info(p);
00190 omega_pfits_get_mean_airmass(p, &airmass);
00191 exptime = omega_pfits_get_exptime(p);
00192 freeplist(p);
00193
00194
00195
00196 if(omega_basic_param(sources, pixscalex, &seeing, &ellipticity) == -1){
00197 cpl_msg_warning(cpl_func,"Cannot find stars with CLASS_STAR near 1 to calculate seeing");
00198 }
00199
00200
00201 *extra = cpl_table_new(1);
00202 cpl_table_new_column(*extra, "FILT_ID", CPL_TYPE_STRING);
00203 cpl_table_set_string(*extra, "FILT_ID",0, cpl_propertylist_get_string(filterlist, "FILT_ID"));
00204 cpl_table_new_column(*extra, "FILT_NAME", CPL_TYPE_STRING);
00205 cpl_table_set_string(*extra, "FILT_NAME",0, cpl_propertylist_get_string(filterlist, "FILT_NAME"));
00206 cpl_table_new_column(*extra, "REF_MAG_ID", CPL_TYPE_STRING);
00207 cpl_table_set_string(*extra, "REF_MAG_ID",0, cpl_propertylist_get_string(filterlist, "REF_MAG_ID"));
00208 cpl_table_new_column(*extra, "REF_MAG_ID_ERR", CPL_TYPE_STRING);
00209 cpl_table_set_string(*extra, "REF_MAG_ID_ERR",0, cpl_propertylist_get_string(filterlist, "REF_MAG_ID_ERR"));
00210 cpl_table_new_column(*extra, "CWL", CPL_TYPE_DOUBLE);
00211 cpl_table_set_double(*extra, "CWL",0, cpl_propertylist_get_double(filterlist, "CWL"));
00212 cpl_table_new_column(*extra, "EXPTIME", CPL_TYPE_DOUBLE);
00213 if(cpl_propertylist_has(xlist, "EXPTIME") == 0)
00214 cpl_table_set_double(*extra, "EXPTIME",0, exptime);
00215 else
00216 cpl_table_set_double(*extra, "EXPTIME",0, cpl_propertylist_get_double(xlist, "EXPTIME"));
00217
00218 cpl_table_new_column(*extra, "AIRMASS", CPL_TYPE_DOUBLE);
00219 cpl_table_set_double(*extra, "AIRMASS",0, airmass);
00220 cpl_table_new_column(*extra, "CHIP_ID", CPL_TYPE_STRING);
00221 cpl_table_set_string(*extra, "CHIP_ID", 0, omega_pfits_get_chipid(xlist));
00222 cpl_table_new_column(*extra, "SEEING", CPL_TYPE_DOUBLE);
00223 cpl_table_set_double(*extra, "SEEING", 0, seeing);
00224 cpl_table_new_column(*extra, "ELLIPTICITY", CPL_TYPE_DOUBLE);
00225 cpl_table_set_double(*extra, "ELLIPTICITY", 0, ellipticity);
00226
00227 freeplist(filterlist);
00228
00229
00230 p = cpl_propertylist_new();
00231 cpl_propertylist_append_bool(p,"Y_IMAGE",0);
00232 if (cpl_table_sort(sources, p) != CPL_ERROR_NONE) {
00233 cpl_msg_error(cpl_func,"Cannot sort sources table");
00234 cpl_propertylist_delete(p);
00235 cpl_propertylist_delete(xlist);
00236 freetable(sources);
00237 return NULL;
00238 }
00239 freeplist(p);
00240
00241
00242 from = cpl_matrix_new(nsources, 2);
00243 for (i=0; i<nsources; i++){
00244 float xim = cpl_table_get_float(sources, "X_IMAGE", i, NULL);
00245 float yim = cpl_table_get_float(sources, "Y_IMAGE", i, NULL);
00246 cpl_matrix_set(from, i, 0, xim);
00247 cpl_matrix_set(from, i, 1, yim);
00248 }
00249
00250
00251 if(omega_get_coverage(xlist, 0, from, &omega_x1, &omega_x2, &omega_y1, &omega_y2) != 0){
00252 cpl_msg_error(cpl_func,"Cannot get coverage of image");
00253 freematrix(from);
00254 freeplist(xlist);
00255 freetable(sources);
00256 return NULL;
00257 }
00258 freematrix(from);
00259
00260
00261
00262
00263 coords = cpl_vector_new(4);
00264 cpl_vector_set(coords, 0, omega_x1);
00265 cpl_vector_set(coords, 1, omega_x2);
00266 cpl_vector_set(coords, 2, omega_y1);
00267 cpl_vector_set(coords, 3, omega_y2);
00268
00269 stds = omega_get_stds_table(cpl_frame_get_filename(refcat), coords, &nstds);
00270 if (stds == NULL) {
00271 cpl_msg_warning(cpl_func,"Cannot find reference standard stars in this region: "
00272 "{RA-RA:DEC-DEC}={%g-%g:%g=%g}", omega_x1,omega_x2,omega_y1,omega_y2);
00273 freeplist(xlist);
00274 freetable(sources);
00275 freevector(coords);
00276 return NULL;
00277 }
00278 freevector(coords);
00279
00280 cpl_msg_debug(cpl_func,"%d reference standards fall in region: {RA-RA:DEC-DEC}={%g-%g:%g=%g}",
00281 nstds,omega_x1,omega_x2,omega_y1,omega_y2);
00282
00283
00284 from = cpl_matrix_new(nstds, 2);
00285 for (i=0; i<nstds; i++){
00286 cpl_matrix_set(from, i, 0, cpl_table_get_double(stds, "Ra", i, NULL));
00287 cpl_matrix_set(from, i, 1, cpl_table_get_double(stds, "Dec", i, NULL));
00288 }
00289
00290 to = NULL;
00291 status = NULL;
00292 wcs = cpl_wcs_new_from_propertylist(xlist);
00293 if(cpl_wcs_convert(wcs, from, &to, &status, CPL_WCS_WORLD2PHYS) != CPL_ERROR_NONE){
00294 freewcs(wcs);
00295 cpl_array_delete(status);
00296 freematrix(from);
00297 freematrix(to);
00298 freeplist(xlist);
00299 freetable(sources);
00300 freetable(stds);
00301 cpl_msg_error(cpl_func,"Error in cpl_wcs conversion. %s",cpl_error_get_message());
00302 return NULL;
00303 }
00304 freewcs(wcs);
00305 freematrix(from);
00306 freeplist(xlist);
00307 cpl_array_delete(status);
00308
00309
00310 cpl_table_new_column(stds,"xpredict",CPL_TYPE_FLOAT);
00311 cpl_table_set_column_unit(stds,"xpredict","pixels");
00312 cpl_table_new_column(stds,"ypredict",CPL_TYPE_FLOAT);
00313 cpl_table_set_column_unit(stds,"ypredict","pixels");
00314
00315 for(i=0; i< nstds; i++){
00316 float xp = (float)cpl_matrix_get(to, i, 0);
00317 float yp = (float)cpl_matrix_get(to, i, 1);
00318 cpl_table_set_float(stds,"xpredict", i, xp);
00319 cpl_table_set_float(stds,"ypredict", i, yp);
00320 }
00321 freematrix(to);
00322
00323
00324 p = cpl_propertylist_new();
00325 cpl_propertylist_append_bool(p,"ypredict",0);
00326 if (cpl_table_sort(stds, p) != CPL_ERROR_NONE) {
00327 cpl_msg_error(cpl_func,"Cannot sort stds table");
00328 freeplist(p);
00329 freetable(sources);
00330 freetable(stds);
00331 return NULL;
00332 }
00333 freeplist(p);
00334
00335
00336 if (omega_matchstds(sources, stds, radius, &matchstds) != 0){
00337 cpl_msg_error(cpl_func,"Failed to match reference standards to image sources. %s",cpl_error_get_message());
00338 freetable(stds);
00339 freetable(sources);
00340 return NULL;
00341 }
00342
00343 nmatches = cpl_table_get_nrow(matchstds);
00344 if(nmatches < 2){
00345 cpl_msg_info(cpl_func,"Not enough matches (n=%d). Trying again...",nmatches);
00346
00347 for(i=0; i<4; i++){
00348 radius = radius + 10.0;
00349 freetable(matchstds);
00350 if (omega_matchstds(sources, stds, radius, &matchstds) != 0){
00351 cpl_msg_error(cpl_func,"Failed to match reference standards to image sources. %s",
00352 cpl_error_get_message());
00353 freetable(stds);
00354 freetable(sources);
00355 freetable(matchstds);
00356 return NULL;
00357 }
00358 nmatches = cpl_table_get_nrow(matchstds);
00359 if(nmatches < 2)
00360 continue;
00361
00362 }
00363 }
00364 if(nmatches < 2){
00365 cpl_msg_warning(cpl_func,"There are no standard stars in image");
00366 freetable(stds);
00367 freetable(sources);
00368 freetable(matchstds);
00369 return NULL;
00370 }
00371
00372 cpl_msg_info(cpl_func,"Found %d standard stars in image", nmatches);
00373
00374 freetable(stds);
00375 freetable(sources);
00376
00377 return matchstds;
00378 }
00379
00380
00381 void omega_get_extinction(cpl_table *extra, cpl_table *extinct2,
00382 cpl_table *extinct1, double *extinction, cpl_table *monit2,
00383 double *shift_err, double *extinction_airmass,
00384 double *extinction_error_kwad)
00385 {
00386
00387
00388
00389 double upr = 0.;
00390 double slope = 0.;
00391 double shift = 0.;
00392 double temp_ext = 0.;
00393 double upr_ext = 0.;
00394 double lwr_ext = 0.;
00395 double cwl = 0.;
00396 double airmass = 0.;
00397 int i = 0;
00398 int numrows = 0;
00399 double wincr = 0;
00400 double lwr = 0;
00401 cwl = cpl_table_get_double(extra, "CWL", 0, NULL);
00402 airmass = cpl_table_get_double(extra, "AIRMASS", 0, NULL);
00403 wincr = cpl_table_get_float(extinct2, "wavel_incr", 0, NULL);
00404 lwr = cwl - fmod(cwl, wincr);
00405 numrows = cpl_table_get_nrow(extinct1);
00406 for(i=0; i< numrows; i++) {
00407 int number = cpl_table_get_float(extinct1,"wavelength", i, NULL);
00408 if(number == lwr) {
00409 lwr_ext = cpl_table_get_float(extinct1,"extinction",i, NULL);
00410 break;
00411 }
00412 }
00413 upr = cwl - fmod(cwl, wincr) + wincr;
00414 for(i=0; i< numrows; i++) {
00415 int number = cpl_table_get_float(extinct1,"wavelength", i, NULL);
00416 if(number == upr) {
00417 upr_ext = cpl_table_get_float(extinct1,"extinction",i, NULL);
00418 break;
00419 }
00420 }
00421 slope = (upr_ext - lwr_ext) / wincr;
00422 temp_ext = fmod(cwl, wincr);
00423 *extinction = (temp_ext * slope) + lwr_ext;
00424
00425
00426
00427 shift = cpl_table_get_float(monit2, "shift", 0, NULL);
00428 *shift_err = cpl_table_get_float(monit2, "shift_err", 0, NULL);
00429 *extinction_airmass = *extinction + shift;
00430 *extinction = (*extinction_airmass) * (airmass);
00431 *extinction_error_kwad = ((*shift_err) * (airmass)) * ((*shift_err) * (airmass));
00432
00433 return;
00434 }
00435
00436
00447
00448 cpl_table *omega_zeropoints(cpl_table *matches, cpl_table *extra, const cpl_frame *monitfr,
00449 const cpl_frame *extfr, const cpl_frame *colfr)
00450 {
00451
00452 int i = 0;
00453 int j = 0;
00454 int nrows = 0;
00455 double extinction = 0.0;
00456 double shift_err = 0.0;
00457 double extinction_airmass = 0.0;
00458 double meanZP = 0.0;
00459 double ZPerror = 0.0;
00460 double extinction_error_kwad = 0.0;
00461 double weight_sum = 0.0;
00462 double sum_data = 0.0;
00463 double clip_median=0.;
00464 double clip_stdev=0.;
00465 double clip_min=0.;
00466 double clip_max=0.;
00467
00468 const char *refmag;
00469 const char *refmagerr;
00470 const char *filt_id = NULL;
00471 const char *filt_name = NULL;
00472
00473 cpl_table *raw_tbl, *monit1, *monit2;
00474 cpl_table *extinct1, *extinct2;
00475 cpl_table *coltbl = NULL;
00476 cpl_table *tbl, *zptbl;
00477 cpl_table * raw_tbl_tmp=NULL;
00478
00479
00480
00481 monit1 = cpl_table_load(cpl_frame_get_filename(monitfr), 1, 0);
00482 if (monit1 == NULL) {
00483 cpl_msg_error(cpl_func, "Cannot load 1st extension of monitoring report table");
00484 return NULL;
00485 }
00486
00487 monit2 = cpl_table_load(cpl_frame_get_filename(monitfr), 2, 0);
00488 if (monit2 == NULL) {
00489 cpl_msg_error(cpl_func, "Cannot load 2nd extension of monitoring report table");
00490 freetable(monit1);
00491 return NULL;
00492 }
00493
00494
00495 extinct1 = cpl_table_load(cpl_frame_get_filename(extfr), 1, 0);
00496 if (extinct1 == NULL) {
00497 cpl_msg_error(cpl_func, "Cannot load 1st extension of std extinction table");
00498 freetable(monit1);
00499 freetable(monit2);
00500 return NULL;
00501 }
00502
00503 extinct2 = cpl_table_load(cpl_frame_get_filename(extfr), 2, 0);
00504 if (extinct2 == NULL) {
00505 cpl_msg_error(cpl_func, "Cannot load 2nd extension of std extinction table");
00506 freetable(monit1);
00507 freetable(monit2);
00508 freetable(extinct1);
00509 return NULL;
00510 }
00511
00512
00513 if (colfr != NULL) {
00514 coltbl = cpl_table_load(cpl_frame_get_filename(colfr), 1, 0);
00515 if (coltbl == NULL){
00516 cpl_msg_error(cpl_func, "Cannot load colour terms table");
00517 freetable(monit1);
00518 freetable(monit2);
00519 freetable(extinct1);
00520 freetable(extinct2);
00521 return NULL;
00522 }
00523 }
00524
00525 filt_id = cpl_table_get_string(extra, "FILT_ID", 0);
00526 filt_name = cpl_table_get_string(extra, "FILT_NAME", 0);
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541 nrows = cpl_table_get_nrow(matches);
00542 raw_tbl = cpl_table_new(nrows);
00543 refmag = cpl_table_get_string(extra, "REF_MAG_ID", 0);
00544 refmagerr = cpl_table_get_string(extra, "REF_MAG_ID_ERR", 0);
00545
00546 cpl_table_duplicate_column(raw_tbl,"mag", matches, refmag);
00547 cpl_table_duplicate_column(raw_tbl,"mag_err", matches, refmagerr);
00548 cpl_table_duplicate_column(raw_tbl, "instmag", matches, "MAG_APER");
00549 cpl_table_duplicate_column(raw_tbl,"instmag_err", matches, "MAGERR_APER");
00550
00551
00552 tbl = omega_filter_table_float(raw_tbl, "instmag", CPL_LESS_THAN, 25.0, &nrows);
00553 freetable(raw_tbl);
00554 raw_tbl = omega_filter_table_float(tbl, "instmag", CPL_GREATER_THAN, -25.0, &nrows);
00555 freetable(tbl);
00556 tbl = omega_filter_table_float(raw_tbl, "mag", CPL_NOT_EQUAL_TO, 0.0, &nrows);
00557 freetable(raw_tbl);
00558 raw_tbl = cpl_table_duplicate(tbl);
00559 freetable(tbl);
00560
00561 if(cpl_table_get_column_mean(raw_tbl, "mag") == 0.0) {
00562 cpl_msg_warning(cpl_func, "Reference table magnitudes (%s) are NULL for the selected stds.",refmag);
00563 freetable(raw_tbl);
00564 freetable(monit1);
00565 freetable(monit2);
00566 freetable(extinct1);
00567 freetable(extinct2);
00568 if(coltbl) freetable(coltbl);
00569 return NULL;
00570 }
00571
00572 cpl_table_subtract_columns(raw_tbl,"mag","instmag");
00573
00574
00575 if(coltbl != NULL){
00576 double colour = 0.0;
00577 for(j = 0; j < 8; j++){
00578 if(strcmp(filt_name, cpl_table_get_string(coltbl, "FILT_NAME", j)) == 0){
00579 colour = cpl_table_get_double(coltbl, "COLOUR_TERM",j, NULL);
00580 break;
00581 }
00582 else if(strcmp(filt_id, cpl_table_get_string(coltbl, "FILT_ID", j)) == 0){
00583 colour = cpl_table_get_double(coltbl, "COLOUR_TERM",j, NULL);
00584 break;
00585 }
00586 }
00587
00588 cpl_table_subtract_scalar(raw_tbl, "mag", colour);
00589 freetable(coltbl);
00590 }
00591
00592 cpl_table_erase_column(raw_tbl,"instmag");
00593 cpl_table_name_column(raw_tbl,"mag","rawZP");
00594
00595
00596
00597
00598
00599 if(cpl_table_get_nrow(raw_tbl)>=3){
00600
00601 raw_tbl_tmp=cpl_table_duplicate(raw_tbl);
00602 freetable(raw_tbl);
00603
00604 clip_median= cpl_table_get_column_median(raw_tbl_tmp, "rawZP");
00605 clip_stdev = cpl_table_get_column_stdev(raw_tbl_tmp, "rawZP");
00606 clip_min=clip_median - 2 * clip_stdev;
00607 clip_max=clip_median + 2 * clip_stdev;
00608
00609 cpl_msg_info(cpl_func,"Using objects with magnitudes within [%g, %g] "
00610 "to derive the weighted zeropoint", clip_min, clip_max);
00611
00612
00613 cpl_table_and_selected_float(raw_tbl_tmp, "rawZP", CPL_NOT_GREATER_THAN,
00614 clip_max);
00615 cpl_table_and_selected_float(raw_tbl_tmp, "rawZP", CPL_NOT_LESS_THAN,
00616 clip_min);
00617
00618 raw_tbl=cpl_table_extract_selected(raw_tbl_tmp);
00619 freetable(raw_tbl_tmp);
00620
00621 }
00622
00623
00624 cpl_table_power_column(raw_tbl,"mag_err", 2.0);
00625 cpl_table_power_column(raw_tbl,"instmag_err", 2.0);
00626 cpl_table_add_columns(raw_tbl,"mag_err", "instmag_err");
00627 cpl_table_power_column(raw_tbl,"mag_err",0.5);
00628 cpl_table_erase_column(raw_tbl,"instmag_err");
00629
00630 cpl_table_name_column(raw_tbl,"mag_err","rawZP_err");
00631 omega_get_extinction(extra, extinct2, extinct1, &extinction, monit2,
00632 &shift_err, &extinction_airmass, &extinction_error_kwad);
00633
00634 cpl_table_add_scalar(raw_tbl, "rawZP", extinction);
00635 cpl_table_power_column(raw_tbl, "rawZP_err", 2.0);
00636 cpl_table_add_scalar(raw_tbl, "rawZP_err", extinction_error_kwad);
00637 cpl_table_power_column(raw_tbl, "rawZP_err", 0.5);
00638 cpl_table_name_column(raw_tbl, "rawZP", "zeropoint");
00639 cpl_table_name_column(raw_tbl, "rawZP_err", "zeropoint_err");
00640
00641 cpl_table_duplicate_column(raw_tbl, "weights", raw_tbl, "zeropoint_err");
00642
00643 cpl_table_power_column(raw_tbl, "weights", -2.);
00644
00645
00646 weight_sum = 0.0;
00647 for (i=0; i<nrows; i++) {
00648 weight_sum += cpl_table_get_float(raw_tbl,"weights", i, NULL);
00649 }
00650
00651 cpl_table_multiply_columns(raw_tbl, "zeropoint", "weights");
00652
00653 sum_data = 0.0;
00654 for(i=0; i<nrows; i++) {
00655 sum_data += cpl_table_get_float(raw_tbl, "zeropoint", i, NULL);
00656 }
00657
00658
00659 meanZP = sum_data/weight_sum;
00660 ZPerror = sqrt(1./weight_sum);
00661
00662 cpl_msg_debug(cpl_func,"meanZP: %f ZPerror: %f",meanZP,ZPerror);
00663
00664
00665 cpl_msg_info("","Photometric parameters for filter %s",filt_name);
00666 cpl_msg_info("","Weighted Average Zeropoint (mag) %0.5g", meanZP);
00667 cpl_msg_info("","Zeropoint error (mag) %0.5g", ZPerror);
00668 cpl_msg_info("","Extinction (mag/airmass) %0.5g", extinction_airmass);
00669 cpl_msg_info("","Extinction times airmass (mag) %0.5g", extinction);
00670 cpl_msg_info("","Extinction error (mag/airmass) %0.5g", shift_err);
00671 cpl_msg_info("","Seeing (arcsec) %0.5g", cpl_table_get_double(extra,"SEEING",0,NULL));
00672 cpl_msg_info("","Ellipticity %0.5g", cpl_table_get_double(extra,"ELLIPTICITY",0,NULL));
00673
00674
00675
00676
00677 zptbl = cpl_table_new(1);
00678 cpl_table_duplicate_column(zptbl,"CHIP_ID", extra, "CHIP_ID");
00679 cpl_table_duplicate_column(zptbl,"FILT_ID", extra, "FILT_ID");
00680 cpl_table_duplicate_column(zptbl,"FILT_NAME", extra, "FILT_NAME");
00681
00682 cpl_table_new_column(zptbl,"ZEROPOINT", CPL_TYPE_DOUBLE);
00683 cpl_table_set_double(zptbl,"ZEROPOINT", 0, meanZP);
00684
00685 cpl_table_new_column(zptbl,"ZEROPOINT_ERR", CPL_TYPE_DOUBLE);
00686 cpl_table_set_double(zptbl,"ZEROPOINT_ERR", 0, ZPerror);
00687
00688 cpl_table_new_column(zptbl,"EXTINCTION", CPL_TYPE_DOUBLE);
00689 cpl_table_set_double(zptbl,"EXTINCTION", 0, extinction_airmass);
00690
00691 cpl_table_new_column(zptbl,"EXTINCTION_ERR", CPL_TYPE_DOUBLE);
00692 cpl_table_set_double(zptbl,"EXTINCTION_ERR", 0, shift_err);
00693
00694 cpl_table_duplicate_column(zptbl,"SEEING", extra, "SEEING");
00695 cpl_table_duplicate_column(zptbl,"ELLIPTICITY", extra, "ELLIPTICITY");
00696
00697 cpl_table_new_column(zptbl, "NSTARS", CPL_TYPE_INT);
00698 cpl_table_set_int(zptbl, "NSTARS", 0, nrows);
00699
00700
00701 freetable(monit1);
00702 freetable(monit2);
00703 freetable(extinct1);
00704 freetable(extinct2);
00705 freetable(raw_tbl);
00706
00707 return zptbl;
00708 }
00709
00710
00711
00720
00721 int omega_basic_param(cpl_table *sources, double scale, double *seeing,
00722 double * ellipticity)
00723 {
00724
00725 int n = 0;
00726 float stellarity = 0.9;
00727 double median = 0.0;
00728 cpl_table *tbl;
00729
00730 *seeing = 0.0;
00731 cpl_table_select_all(sources);
00732
00733 n = cpl_table_and_selected_float(sources, "CLASS_STAR", CPL_NOT_LESS_THAN, stellarity);
00734 if(n <= 0) {
00735 stellarity = 0.8;
00736 n = cpl_table_and_selected_float(sources, "CLASS_STAR", CPL_NOT_LESS_THAN, stellarity);
00737 if(n <= 0){
00738 return -1;
00739 }
00740 }
00741
00742 cpl_table_and_selected_float(sources, "FWHM_IMAGE", CPL_GREATER_THAN, 0.1);
00743 tbl = cpl_table_extract_selected(sources);
00744 median = cpl_table_get_column_median(tbl, "FWHM_IMAGE");
00745 cpl_msg_debug(cpl_func,"median1: %g",median);
00746 freetable(tbl);
00747
00748 cpl_table_and_selected_float(sources, "FWHM_IMAGE", CPL_NOT_GREATER_THAN, median);
00749 tbl = cpl_table_extract_selected(sources);
00750 median = cpl_table_get_column_median(tbl, "FWHM_IMAGE");
00751 cpl_msg_debug(cpl_func,"median2: %g",median);
00752
00753 *seeing = median * fabs(scale)*3600;
00754
00755 if(cpl_table_has_column(tbl,"ELLIPTICITY")){
00756 *ellipticity = cpl_table_get_column_median(tbl, "ELLIPTICITY");
00757 }
00758 freetable(tbl);
00759
00760 return 0;
00761 }
00762
00763