38 #include <casu_utils.h>
39 #include <casu_wcsutils.h>
40 #include <casu_stats.h>
42 #include "vircam_mods.h"
61 const char *apcorkeys[NAPCOR] = {
"APCOR1",
"APCOR2",
"APCOR3",
"APCOR4",
"APCOR5",
64 static int gettabinfo(cpl_propertylist *plist, tables *tab,
double *mjdobs);
65 static void tidytabs(tables maintab, tables *tabs);
109 cpl_frameset *input_confs, casu_tfits **outtab,
111 int retval,i,j,m,nrows,*conf_data,k,ix,iy,ind,k2,nc,mjd_day = 0;
112 tables maintab,pawtabs[NPAWS*NEXTN];
113 double *x,*y,*x2,*y2,expon,*dspace,mjdobs;
114 cpl_array *colnames_array;
116 cpl_propertylist *plist;
117 casu_fits *conf_fits;
118 float delta_mag,xmax,ymax,*mjds,*cnumb,*fspace,*fluxcor,*fluxes[NAPCOR+1];
119 float *fluxerrs[NAPCOR+1],work[NEXTN],confwt,scale,*xptr,*yptr,*data;
120 char **colnames,msg[81],sval[81];
121 const char *fluxcols[NAPCOR+1] = {
"Aper_flux_1",
"Aper_flux_2",
122 "Aper_flux_3",
"Aper_flux_4",
123 "Aper_flux_5",
"Aper_flux_6",
124 "Aper_flux_7",
"Peak_height"};
125 const char *errcols[NAPCOR+1] = {
"Aper_flux_1_err",
"Aper_flux_2_err",
126 "Aper_flux_3_err",
"Aper_flux_4_err",
127 "Aper_flux_5_err",
"Aper_flux_6_err",
128 "Aper_flux_7_err",
"Peak_height_err"};
133 if (*status != CASU_OK)
151 for (i = 0; i < NPAWS*NEXTN; i++)
152 pawtabs[i].wcs = NULL;
157 if (retval != CASU_OK) {
165 dspace = cpl_malloc(4*nrows*
sizeof(
double));
168 x2 = dspace + 2*nrows;
169 y2 = dspace + 3*nrows;
173 fspace = cpl_calloc((2+NAPCOR)*nrows,
sizeof(
float));
175 cnumb = fspace + nrows;
176 fluxcor = fspace + 2*nrows;
185 for (i = 0; i < nrows; i++) {
186 x[i] = (double)xptr[i];
187 y[i] = (double)yptr[i];
193 for (i = 0; i < NPAWS; i++) {
194 fr = cpl_frameset_get_position(input_cats,i);
195 for (j = 0; j < NEXTN; j++) {
196 plist = cpl_propertylist_load(cpl_frame_get_filename(fr),j+1);
197 retval = gettabinfo(plist,&(pawtabs[m]),&mjdobs);
198 if (retval != CASU_OK) {
202 freepropertylist(plist);
205 if (i == 0 && j == 0)
206 mjd_day = (int)mjdobs;
207 pawtabs[m].mjdobs = (float)(1440.0*(mjdobs - (
double)mjd_day));
209 freepropertylist(plist);
216 for (i = 0; i < NPAWS; i++) {
217 fr = cpl_frameset_get_position(input_confs,i);
218 for (j = 0; j < NEXTN; j++) {
222 delta_mag = maintab.magzpt - pawtabs[m].magzpt;
233 xmax = (float)pawtabs[m].nxout - 0.5;
234 ymax = (float)pawtabs[m].nyout;
235 for (k = 0; k < nrows; k++) {
236 if (x2[k] >= 0.5 && x2[k] < xmax &&
237 y2[k] >= 0.5 && y2[k] < ymax) {
238 ix = (int)(x2[k] + 0.5) - 1;
239 iy = (int)(y2[k] + 0.5) - 1;
240 ind = iy*pawtabs[m].nxout + ix;
241 confwt = (float)max(1.0,conf_data[ind]);
242 mjds[k] += confwt*pawtabs[m].mjdobs;
244 for (k2 = 0; k2 < NAPCOR; k2++) {
245 expon = 0.4*(double)(pawtabs[m].apcors[k2] -
246 maintab.apcors[k2] + delta_mag);
247 fluxcor[k2*nrows+k] += confwt*pow(10.0,expon);
257 for (i = 0; i < NAPCOR+1; i++) {
266 for (k = 0; k < nrows; k++) {
267 for (k2 = 0; k2 < NAPCOR; k2++) {
269 scale = fluxcor[k2*nrows+k]/cnumb[k];
272 fluxes[k2][k] *= scale;
273 fluxerrs[k2][k] *= scale;
275 fluxes[NAPCOR][k] *= scale;
276 fluxerrs[NAPCOR][k] *= scale;
288 colnames = cpl_array_get_data_string(colnames_array);
289 nc = cpl_array_get_size(colnames_array);
291 while (i < nc && strncmp(colnames[i],
"Blank",5))
300 memmove(data,mjds,nrows*
sizeof(
float));
302 cpl_array_delete(colnames_array);
307 cpl_propertylist_append_bool(plist,
"ESO DRS GROUTED",1);
308 cpl_propertylist_set_comment(plist,
"ESO DRS GROUTED",
309 "Table has been grouted");
310 cpl_propertylist_append_float(plist,
"MJD_DAY",mjd_day);
311 cpl_propertylist_set_comment(plist,
"MJD_DAY",
"MJD day");
317 for (i = 0; i < NPAWS; i++) {
318 for (j = 0; j < NEXTN; j++)
319 work[j] = pawtabs[m++].magzpt;
320 delta_mag =
casu_med(work,NULL,NEXTN);
321 (void)sprintf(sval,
"%0.3f ",delta_mag);
322 (void)strcat(msg,sval);
324 cpl_propertylist_append_string(plist,
"ESO DRS PAWMAGZP",msg);
325 cpl_propertylist_set_comment(plist,
"ESO DRS PAWMAGZP",
326 "Mag Zpt of input pawprints");
332 for (i = 0; i < NPAWS; i++) {
333 for (j = 0; j < NEXTN; j++)
334 work[j] = pawtabs[m++].ellipt;
335 delta_mag =
casu_med(work,NULL,NEXTN);
336 (void)sprintf(sval,
"%0.3f ",delta_mag);
337 (void)strcat(msg,sval);
339 cpl_propertylist_append_string(plist,
"ESO DRS PAWELLPT",msg);
340 cpl_propertylist_set_comment(plist,
"ESO DRS PAWELLPT",
341 "Median paw ELLIPTIC");
347 for (i = 0; i < NPAWS; i++) {
348 for (j = 0; j < NEXTN; j++)
349 work[j] = pawtabs[m++].seeing;
350 delta_mag =
casu_med(work,NULL,NEXTN);
351 (void)sprintf(sval,
"%0.3f ",delta_mag);
352 (void)strcat(msg,sval);
354 cpl_propertylist_append_string(plist,
"ESO DRS PAWSEENG",msg);
355 cpl_propertylist_set_comment(plist,
"ESO DRS PAWSEENG",
356 "[arcsec] Median paw SEEING");
362 tidytabs(maintab,pawtabs);
371 static int gettabinfo(cpl_propertylist *plist, tables *tab,
double *mjdobs) {
376 tab->wcs = cpl_wcs_new_from_propertylist(plist);
380 for (i = 0; i < NAPCOR; i++)
381 tab->apcors[i] = cpl_propertylist_get_float(plist,apcorkeys[i]);
385 tab->magzpt = cpl_propertylist_get_float(plist,
"ESO QC MAGZPT");
389 tab->seeing = cpl_propertylist_get_float(plist,
"ESO DRS SEEING");
393 tab->ellipt = cpl_propertylist_get_float(plist,
"ESO QC ELLIPTICITY");
397 *mjdobs = cpl_propertylist_get_float(plist,
"MJD_MEAN");
401 tab->nxout = cpl_propertylist_get_int(plist,
"ESO DRS NXOUT");
402 tab->nyout = cpl_propertylist_get_int(plist,
"ESO DRS NYOUT");
406 static void tidytabs(tables maintab, tables *tabs) {
409 freewcs(maintab.wcs);
410 for (i = 0; i < NEXTN*NPAWS; i++)
411 freewcs(tabs[i].wcs);
cpl_image * casu_fits_get_image(casu_fits *p)
casu_fits * casu_fits_load(cpl_frame *frame, cpl_type type, int nexten)
float casu_med(float *data, unsigned char *bpm, long npts)
cpl_table * casu_tfits_get_table(casu_tfits *p)
cpl_propertylist * casu_tfits_get_ehu(casu_tfits *p)
casu_tfits * casu_tfits_duplicate(casu_tfits *in)
void casu_xytoxy_list(cpl_wcs *wcs1, cpl_wcs *wcs2, int nc, double *x_1, double *y_1, double *x_2, double *y_2)
int vircam_grout(casu_tfits *intab, cpl_frameset *input_cats, cpl_frameset *input_confs, casu_tfits **outtab, int *status)
Correct input tile catalogues.