44#include <casu_utils.h>
45#include <casu_stats.h>
47#include <catalogue/imcore.h>
49#include "vircam_utils.h"
50#include "vircam_pfits.h"
57#define NOMPIXSIZE 0.34
74static const char *illcor_cols[NI_COLS] = {
"xmin",
"xmax",
"ymin",
"ymax",
79static float madfunc(
int npts,
float *xt,
float *yt,
float b);
80static double pixsize (cpl_propertylist *plist);
81static int vircam_phot_open(cpl_table *phottab,
char *filt, photstrct *p);
82static void vircam_phot_close(photstrct *p);
83static int extract_columns(cpl_table *tab, photstrct *p);
84static int extract_coleq(cpl_table *tab, photstrct *p);
117 const char *vircam_license =
118 "This file is part of the VIRCAM Instrument Pipeline\n"
119 "Copyright (C) 2015 European Southern Observatory\n"
121 "This program is free software; you can redistribute it and/or modify\n"
122 "it under the terms of the GNU General Public License as published by\n"
123 "the Free Software Foundation; either version 2 of the License, or\n"
124 "(at your option) any later version.\n"
126 "This program is distributed in the hope that it will be useful,\n"
127 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
128 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
129 "GNU General Public License for more details.\n"
131 "You should have received a copy of the GNU General Public License\n"
132 "along with this program; if not, write to the Free Software\n"
133 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, \n"
135 return(vircam_license);
167 int nvircam = 16,n,nmax;
168 const char *fctid =
"vircam_exten_range";
172 n = cpl_frame_get_nextensions(fr);
178 cpl_msg_warning(fctid,
179 "Only %" CPL_SIZE_FORMAT
" extensions out of %" CPL_SIZE_FORMAT
" are present",
180 (cpl_size)n,(cpl_size)nvircam);
197 if (inexten > nmax) {
199 "Requested extension %" CPL_SIZE_FORMAT
" is not present",
240 float *intercept,
float *slope) {
242 float sx,sy,sxx,sxy,det,aa,bb,temp,chisq,sigb,b1,f1,b2,f2,f;
250 for (j = 0; j < npts; j++) {
253 sxx += xdata[j]*xdata[j];
254 sxy += xdata[j]*ydata[j];
256 det = (float)npts*sxx - sx*sx;
262 aa = (sxx*sy - sx*sxy)/det;
263 bb = ((float)npts*sxy - sx*sy)/det;
265 for (j = 0; j < npts; j++) {
266 temp = ydata[j] - (aa + bb*xdata[j]);
269 sigb = sqrt(chisq/det);
279 f1 = madfunc(npts,xdata,ydata,b1);
280 b2 = bb + ((f1 > 0.0) ? fabs(3.0*sigb) : -fabs(3.0*sigb));
281 f2 = madfunc(npts,xdata,ydata,b2);
282 while (f1*f2 > 0.0) {
287 f2 = madfunc(npts,xdata,ydata,b2);
293 while (fabs(b2 - b1) > sigb) {
295 if (bb == b1 || bb == b2)
297 f = madfunc(npts,xdata,ydata,bb);
336static float madfunc(
int npts,
float *xt,
float *yt,
float b) {
340 arr = cpl_malloc(npts*
sizeof(*arr));
341 for (j = 0; j < npts; j++)
342 arr[j] = yt[j] - b*xt[j];
345 for (j = 0; j < npts; j++) {
346 d = yt[j] - (b*xt[j] + aa);
347 sum += d > 0.0 ? xt[j] : -xt[j];
383 double *intercept,
double *slope,
double *sig) {
385 double sx,sy,sxx,sxy,det,aa,bb,temp,sum,sumsq;
393 for (j = 0; j < npts; j++) {
396 sxx += xdata[j]*xdata[j];
397 sxy += xdata[j]*ydata[j];
399 det = (double)npts*sxx - sx*sx;
409 aa = (sxx*sy - sx*sxy)/det;
410 bb = ((double)npts*sxy - sx*sy)/det;
416 for (j = 0; j < npts; j++) {
417 temp = ydata[j] - (aa + bb*xdata[j]);
425 *sig = sqrt(sumsq/(
double)npts - sum*sum);
457 double temp,big,pivot,rmax;
458 int i,iu,j,k,jl,ib,ir;
462 for (i = 0; i < iu; i++) {
467 for (k = i; k < m; k++) {
468 rmax = fabs(a[i][k]);
478 for (ib = 0; ib < m; ib++)
480 cpl_msg_error(
"vircam_solve_gauss",
"Zero Determinant\n");
488 for (j = 0; j < m; j++) {
504 for (j = jl; j < m; j++) {
505 temp = a[i][j]/pivot;
507 for (k = i; k < m; k++)
508 a[k][j] -= temp*a[k][i];
514 for (i = 0; i < m; i++) {
516 if (a[ir][ir] != 0.0) {
519 for (j = 1; j <= i; j++) {
521 temp -= a[k][ir]*b[k];
524 b[ir] = temp/a[ir][ir];
572 int ncoefs,
int ilim,
int niter,
float lclip,
573 float hclip, cpl_array **polycf,
double *sigfit) {
574 const char *fctid =
"vircam_polyfit";
575 int npts,iter,i,j,nnew,k,retval,n;
576 double *xdata,*ydata,*pdata,*res,**a,*b,temp,sum,sumsq,val;
587 npts = (int)cpl_array_get_size(xarray);
592 cpl_msg_warning(fctid,
593 "Not data for fit, Npts = %" CPL_SIZE_FORMAT
", Ncoefs = %" CPL_SIZE_FORMAT,
594 (cpl_size)npts,(cpl_size)ncoefs);
600 a = cpl_malloc(ncoefs*
sizeof(
double *));
601 b = cpl_calloc(ncoefs,
sizeof(
double));
602 for (i = 0; i < ncoefs; i++)
603 a[i] = cpl_calloc(ncoefs,
sizeof(
double));
604 pm = cpl_calloc(npts,
sizeof(
unsigned char));
605 res = cpl_malloc(npts*
sizeof(
double));
609 xdata = (
double *)cpl_array_get_data_double_const(xarray);
610 ydata = (
double *)cpl_array_get_data_double_const(yarray);
614 *polycf = cpl_array_new((cpl_size)ncoefs,CPL_TYPE_DOUBLE);
615 pdata = cpl_array_get_data_double(*polycf);
619 for (iter = 0; iter <= niter; iter++) {
623 for (i = 0; i < ncoefs; i++) {
624 for (j = 0; j < ncoefs; j++)
632 for (i = 0; i < npts; i++) {
635 for (k = 0; k < ncoefs; k++) {
638 temp = pow(xdata[i],(
double)(k+ilim));
639 b[k] += ydata[i]*temp;
640 for (j = 0; j <= k; j++) {
642 if (k + j + 2*ilim != 0)
643 temp = pow(xdata[i],(
double)(k+j+2*ilim));
648 for (k = 1; k < ncoefs; k++)
649 for (j = 0; j < k; j++)
655 if (retval != CASU_OK) {
656 cpl_msg_warning(fctid,
"Fit failed");
658 freespace2(a,ncoefs);
667 for (i = 0; i < ncoefs; i++)
675 for (i = 0; i < npts; i++) {
679 for (j = 0; j < ncoefs; j++)
680 val += pdata[j]*pow(xdata[i],(
double)j+ilim);
681 res[i] = val - ydata[i];
683 sumsq += pow(res[i],2.0);
687 *sigfit = sqrt(sumsq/(
double)n - sum*sum);
691 lcut = sum - lclip*(*sigfit);
692 hcut = sum + hclip*(*sigfit);
694 for (i = 0; i < npts; i++) {
697 if (res[i] > hcut || res[i] < lcut) {
712 freespace2(a,ncoefs);
763 unsigned char *bpm, cpl_table *chantab,
764 int ncells,
int oper,
float *global_diff,
765 float *global_rms, cpl_image **diffim,
766 cpl_table **diffimstats) {
767 float *ddata,*work,mean,sig,med,mad;
769 int nrows,i,nc1,nc2,nr,ixmin,ixmax,iymin,iymax,cnum,cx,cy,idx,idy;
770 int icx,icy,indy1,indy2,indx1,indx2,jp,jcx,jj,jcy,ii,ncx,ncy;
771 const char *fctid =
"vircam_difference_image";
782 if (prog == NULL || master == NULL)
789 *diffim = cpl_image_subtract_create(prog,master);
792 *diffim = cpl_image_divide_create(prog,master);
796 cpl_msg_error(fctid,
"Invalid operation requested %" CPL_SIZE_FORMAT,
805 ddata = cpl_image_get_data_float(*diffim);
806 nx = (int)cpl_image_get_size_x(*diffim);
807 ny = (int)cpl_image_get_size_y(*diffim);
809 casu_medmad(ddata,bpm,npts,global_diff,global_rms);
820 if (! cpl_table_has_column(chantab,
"ixmin") ||
821 ! cpl_table_has_column(chantab,
"ixmax") ||
822 ! cpl_table_has_column(chantab,
"iymin") ||
823 ! cpl_table_has_column(chantab,
"iymax") ||
824 ! cpl_table_has_column(chantab,
"channum")) {
825 cpl_msg_error(fctid,
"Channel table is missing one of the required columns");
869 nrows = (int)cpl_table_count_selected(chantab);
875 for (i = 0; i < nrows; i++) {
876 ixmin = cpl_table_get_int(chantab,
"ixmin",(cpl_size)i,NULL);
877 ixmax = cpl_table_get_int(chantab,
"ixmax",(cpl_size)i,NULL);
878 iymin = cpl_table_get_int(chantab,
"iymin",(cpl_size)i,NULL);
879 iymax = cpl_table_get_int(chantab,
"iymax",(cpl_size)i,NULL);
880 cnum = cpl_table_get_int(chantab,
"channum",(cpl_size)i,NULL);
887 cx = ixmax - ixmin + 1;
888 cy = iymax - iymin + 1;
892 }
else if (cx < cy) {
904 work = cpl_malloc(idx*idy*
sizeof(*work));
908 for (icy = 0; icy < ncy; icy++) {
910 indy2 = min(iymax,indy1+idy-1);
911 for (icx = 0; icx < ncx; icx++) {
913 indx2 = min(ixmax,indx1+idx-1);
915 for (jcy = indy1; jcy < indy2; jcy++) {
917 for (jcx = indx1; jcx < indx2; jcx++) {
919 if (bpm != NULL && bpm[ii] == 0)
920 work[jp++] = ddata[ii];
925 cpl_table_set_int(*diffimstats,
"xmin",(cpl_size)nr,indx1+1);
926 cpl_table_set_int(*diffimstats,
"xmax",(cpl_size)nr,indx2+1);
927 cpl_table_set_int(*diffimstats,
"ymin",(cpl_size)nr,indy1+1);
928 cpl_table_set_int(*diffimstats,
"ymax",(cpl_size)nr,indy2+1);
929 cpl_table_set_int(*diffimstats,
"chan",(cpl_size)nr,cnum);
930 cpl_table_set_float(*diffimstats,
"mean",(cpl_size)nr,mean);
931 cpl_table_set_float(*diffimstats,
"median",(cpl_size)nr,med);
932 cpl_table_set_float(*diffimstats,
"variance",(cpl_size)nr,
934 cpl_table_set_float(*diffimstats,
"mad",(cpl_size)(nr++),mad);
961 cpl_table *diffimstats;
963 diffimstats = cpl_table_new((cpl_size)nrows);
964 cpl_table_new_column(diffimstats,
"xmin",CPL_TYPE_INT);
965 cpl_table_set_column_unit(diffimstats,
"xmin",
"pixels");
966 cpl_table_new_column(diffimstats,
"xmax",CPL_TYPE_INT);
967 cpl_table_set_column_unit(diffimstats,
"xmax",
"pixels");
968 cpl_table_new_column(diffimstats,
"ymin",CPL_TYPE_INT);
969 cpl_table_set_column_unit(diffimstats,
"ymin",
"pixels");
970 cpl_table_new_column(diffimstats,
"ymax",CPL_TYPE_INT);
971 cpl_table_set_column_unit(diffimstats,
"ymax",
"pixels");
972 cpl_table_new_column(diffimstats,
"chan",CPL_TYPE_INT);
973 cpl_table_set_column_unit(diffimstats,
"chan",
"pixels");
974 cpl_table_new_column(diffimstats,
"mean",CPL_TYPE_FLOAT);
975 cpl_table_set_column_unit(diffimstats,
"mean",
"ADU");
976 cpl_table_new_column(diffimstats,
"median",CPL_TYPE_FLOAT);
977 cpl_table_set_column_unit(diffimstats,
"median",
"ADU");
978 cpl_table_new_column(diffimstats,
"variance",CPL_TYPE_FLOAT);
979 cpl_table_set_column_unit(diffimstats,
"variance",
"ADU**2");
980 cpl_table_new_column(diffimstats,
"mad",CPL_TYPE_FLOAT);
981 cpl_table_set_column_unit(diffimstats,
"mad",
"ADU");
1009 cdata = cpl_malloc(n*
sizeof(*cdata));
1010 for (i = 0; i < n; i++)
1042 return(cpl_propertylist_has(p,
"ESO DRS IMADUMMY"));
1070 illcor = cpl_table_new((cpl_size)nrows);
1071 for (i = 0; i < NI_COLS; i++)
1072 cpl_table_new_column(illcor,illcor_cols[i],CPL_TYPE_FLOAT);
1109 (void)gettimeofday(&tv,NULL);
1111 tm = gmtime_r(&(tv.tv_sec), &result);
1112 sec = (float)tm->tm_sec + 1.0e-6*(
float)tv.tv_usec;
1116 (void)snprintf(out,n,
"%04d-%02d-%02dT%02d:%02d:%07.4f",1900+tm->tm_year,
1117 tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,sec);
1149 double crval1,crval2;
1167 if (fabs(crval1) < 1.0e-6 && fabs(crval2) < 1.0e-6) {
1171 p = cpl_propertylist_get_property(ehu,
"CRVAL1");
1172 cpl_property_set_name(p,
"OLDCR1");
1173 p = cpl_propertylist_get_property(ehu,
"CRVAL2");
1174 cpl_property_set_name(p,
"OLDCR2");
1175 cpl_propertylist_insert_after_double(ehu,
"OLDCR2",
"CRVAL1",crval1);
1176 cpl_propertylist_insert_after_double(ehu,
"CRVAL1",
"CRVAL2",crval2);
1177 cpl_propertylist_erase(ehu,
"OLDCR1");
1178 cpl_propertylist_erase(ehu,
"OLDCR2");
1208 (void)cpl_propertylist_erase_regexp(p2,CPL_WCS_REGEXP,0);
1209 cpl_propertylist_copy_property_regexp(p2,p1,CPL_WCS_REGEXP,0);
1259 int ndit,
int jst,
int jfn, cpl_array **mins,
1260 cpl_array **maxs, cpl_array **aves,
1261 cpl_frameset **out,
int *status) {
1262 int i,n,nj,j,live,gotit;
1263 double val,dndit,fmin,fmax,sum;
1264 cpl_propertylist *p;
1274 dndit = (double)ndit;
1275 *mins = cpl_array_new(nj,CPL_TYPE_DOUBLE);
1276 *maxs = cpl_array_new(nj,CPL_TYPE_DOUBLE);
1277 *aves = cpl_array_new(nj,CPL_TYPE_DOUBLE);
1281 n = cpl_frameset_get_size(in);
1282 for (j = jst; j <= jfn; j++) {
1290 fr = cpl_frameset_get_position(in,0);
1291 p = cpl_propertylist_load(cpl_frame_get_filename(fr),j);
1293 cpl_propertylist_delete(p);
1295 cpl_array_set(*mins,j-jst,0.0);
1296 cpl_array_set(*maxs,j-jst,0.0);
1297 cpl_array_set(*aves,j-jst,0.0);
1307 *out = cpl_frameset_new();
1315 fmin = 1000000000.0;
1316 fmax = -1000000000.0;
1318 for (i = 0; i < n; i++) {
1319 fr = cpl_frameset_get_position(in,i);
1320 im = cpl_image_load(cpl_frame_get_filename(fr),CPL_TYPE_FLOAT,0,j);
1321 val = cpl_image_get_median(im);
1323 cpl_image_delete(im);
1324 fmin = min(fmin,val);
1325 fmax = max(fmax,val);
1328 if (val >= lthr && val <= hthr)
1329 cpl_frameset_insert(*out,cpl_frame_duplicate(fr));
1332 cpl_array_set(*mins,j-jst,fmin);
1333 cpl_array_set(*maxs,j-jst,fmax);
1334 cpl_array_set(*aves,j-jst,sum/(
double)n);
1343 if (cpl_frameset_get_size(*out) == 0)
1407 cpl_propertylist **pl,
int nimages,
char *filt,
1408 cpl_table *phottab,
int nbsize, cpl_table **illcor,
1409 float *illcor_rms,
int *status) {
1410 const char *fctid =
"vircam_illum";
1411 float **stdmagptr,fracx,fracy,**results,cdfudge,saturate,apcor3,exptime;
1412 float airmass,*catcore3,*xx,*yy,extinct,cf,fluxmag3,refmag,dm3,med,mad;
1413 float xmin,xmax,ymin,ymax,*resall,medall,lcut,hcut,sig,cut,*good;
1414 int nx,ny,ifracx,ifracy,nbsizx,nbsizy,nbx,nby,*nres,*nall,i,j,ncat,k;
1415 int ix,iy,ind,nresall,nallocall,ngood;
1417 cpl_propertylist *ehu_im,*ehu_cat;
1418 cpl_table *stds,*cl;
1425 if (*status != CASU_OK)
1431 cpl_msg_error(fctid,
"No images included in photometric calibration");
1438 if (vircam_phot_open(phottab,filt,&p) != CASU_OK)
1443 stdmagptr = cpl_malloc(p.ncolumns_coleq*
sizeof(
float *));
1449 fracx = ((float)nx)/((float)nbsize);
1450 fracy = ((float)ny)/((float)nbsize);
1451 ifracx = (int)(fracx + 0.1);
1452 ifracy = (int)(fracy + 0.1);
1455 nbsize = max(casu_nint(0.9*nbsize),min(nbsize,min(nbsizx,nbsizy)));
1456 nbsize = min(nx,min(ny,nbsize));
1467 results = cpl_malloc(nbx*nby*
sizeof(
float *));
1468 good = cpl_malloc(nbx*nby*
sizeof(
float));
1469 nres = cpl_calloc(nbx*nby,
sizeof(
int));
1470 nall = cpl_malloc(nbx*nby*
sizeof(
int));
1471 for (i = 0; i < nbx*nby; i++) {
1472 results[i] = cpl_malloc(INITALLOC*
sizeof(
float));
1473 nall[i] = INITALLOC;
1475 resall = cpl_malloc(INITALLOC*
sizeof(
float));
1477 nallocall = INITALLOC;
1488 for (i = 0; i < nimages; i++) {
1495 cdfudge = 2.5*log10((
double)pixsize(ehu_im)/NOMPIXSIZE);
1500 saturate = cpl_propertylist_get_float(ehu_cat,
"ESO QC SATURATION");
1501 apcor3 = cpl_propertylist_get_float(ehu_cat,
"APCOR3");
1504 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1505 cpl_msg_error(fctid,
"Unable to get header info for %s",
1513 cpl_table_select_all(stds);
1514 (void)cpl_table_and_selected_float(stds,
"Ellipticity",CPL_LESS_THAN,
1516 (void)cpl_table_and_selected_float(stds,
"Peak_height",CPL_LESS_THAN,
1518 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1519 cpl_msg_error(fctid,
"Unable select data from matched stds tab %s",
1528 cl = cpl_table_extract_selected(stds);
1529 ncat = (int)cpl_table_get_nrow(cl);
1531 cpl_msg_error(fctid,
"No good standards available for %s",
1533 cpl_table_delete(cl);
1540 catcore3 = cpl_table_get_data_float(cl,
"Aper_flux_3");
1541 xx = cpl_table_get_data_float(cl,
"X_coordinate");
1542 yy = cpl_table_get_data_float(cl,
"Y_coordinate");
1543 for (j = 0; j < p.ncolumns_coleq; j++)
1544 stdmagptr[j] = cpl_table_get_data_float(cl,(p.coleq_columns)[j]);
1548 extinct = p.atm_extcoef*(airmass - 1.0);
1549 for (j = 0; j < ncat; j++) {
1553 cf = catcore3[j]/exptime;
1556 fluxmag3 = 2.5*log10((
double)cf) + apcor3;
1560 refmag = p.mag_offset;
1561 for (k = 0; k < p.ncolumns_coleq; k++)
1562 refmag += ((p.coleq_coefs)[k]*stdmagptr[k][j]);
1566 dm3 = refmag + fluxmag3 + extinct + cdfudge;
1570 ix = (int)(xx[j]/(
float)nbsize);
1571 iy = (int)(yy[j]/(
float)nbsize);
1573 if (nres[ind] == nall[ind] - 1) {
1574 results[ind] = cpl_realloc(results[ind],
1575 (nall[ind]+INITALLOC)*
sizeof(
float));
1576 nall[ind] += INITALLOC;
1578 results[ind][nres[ind]] = dm3;
1583 if (nresall == nallocall) {
1584 resall = cpl_realloc(resall,(nallocall+INITALLOC)*
sizeof(
float));
1585 nallocall += INITALLOC;
1587 resall[nresall++] = dm3;
1598 (void)
casu_medmad(resall,NULL,(
long)nresall,&medall,&mad);
1599 cut = max(3.0*1.48*mad,0.1);
1600 lcut = medall - cut;
1601 hcut = medall + cut;
1612 for (i = 0; i < nbx*nby; i++) {
1614 (void)
casu_medmad(results[i],NULL,(
long)nres[i],&med,&mad);
1615 cut = max(3.0*1.48*mad,0.3);
1622 good[ngood++] = med;
1632 xmax = xmin + nbsize - 1;
1636 ymax = ymin + nbsize - 1;
1642 cpl_table_set_float(*illcor,
"xmin",(cpl_size)i,xmin);
1643 cpl_table_set_float(*illcor,
"xmax",(cpl_size)i,xmax);
1644 cpl_table_set_float(*illcor,
"ymin",(cpl_size)i,ymin);
1645 cpl_table_set_float(*illcor,
"ymax",(cpl_size)i,ymax);
1646 cpl_table_set_float(*illcor,
"illcor",(cpl_size)i,med);
1652 casu_medsig(good,NULL,(
long)ngood,&med,illcor_rms);
1658 for (i = 0; i < nbx*nby; i++)
1659 freespace(results[i]);
1663 freespace(stdmagptr);
1666 vircam_phot_close(&p);
1704static int vircam_phot_open(cpl_table *phottab,
char *filt, photstrct *p) {
1705 const char *fctid =
"vircam_phot_open";
1706 int ns,nerr,null,nr;
1709 const char *req_cols[8] = {
"filter_name",
"atm_extcoef",
"mag_offset",
1710 "coleq_columns",
"coleq_coefs",
"gal_extcoef",
1711 "default_zp",
"default_zp_err"};
1715 p->coleq_coefs = NULL;
1716 p->coleq_columns = NULL;
1717 p->ncolumns_coleq = 0;
1718 p->mag_offset = 0.0;
1723 for (ns = 0; ns < 8; ns++) {
1724 if (! cpl_table_has_column(phottab,req_cols[ns])) {
1725 cpl_msg_error(fctid,
"Photometry table missing column %s",
1738 filts = cpl_table_get_data_string(phottab,
"filter_name");
1739 nr = cpl_table_get_nrow(phottab);
1741 for (ns = 0; ns < nr; ns++) {
1742 if (strncmp(filts[ns],filt,16) == 0) {
1748 cpl_msg_error(fctid,
"Unable to match photometry table to filter %s",
1752 cpl_table_and_selected_window(phottab,ns,1);
1756 subset = cpl_table_extract_selected(phottab);
1757 p->filter_name = (
char *)cpl_table_get_string(subset,
"filter_name",0);
1758 p->atm_extcoef = cpl_table_get_float(subset,
"atm_extcoef",0,&null);
1759 p->mag_offset = cpl_table_get_float(subset,
"mag_offset",0,&null);
1760 p->gal_extcoef = cpl_table_get_float(subset,
"gal_extcoef",0,&null);
1761 p->default_zp = cpl_table_get_float(subset,
"default_zp",0,&null);
1762 p->default_zp_err = cpl_table_get_float(subset,
"default_zp_err",0,&null);
1763 if (extract_columns(subset,p) != CASU_OK) {
1767 if (extract_coleq(subset,p) != CASU_OK) {
1796static void vircam_phot_close(photstrct *p) {
1799 for (j = 0; j < p->ncolumns_coleq; j++)
1800 freespace((p->coleq_columns)[j]);
1801 freespace(p->coleq_columns);
1802 freespace(p->coleq_coefs);
1826static int extract_columns(cpl_table *tab, photstrct *p) {
1832 v = cpl_strdup(cpl_table_get_string(tab,
"coleq_columns",0));
1839 for (i = 0; i < j; i++)
1842 p->ncolumns_coleq = nv;
1846 z = cpl_malloc(nv*
sizeof(
char *));
1847 char *saveptr = NULL;
1848 for (i = 0; i < nv; i++) {
1850 w = strtok_r(v,
",",&saveptr);
1852 w = strtok_r(NULL,
",",&saveptr);
1853 z[i] = cpl_strdup(w);
1855 p->coleq_columns = z;
1882static int extract_coleq(cpl_table *tab, photstrct *p) {
1889 v = cpl_strdup(cpl_table_get_string(tab,
"coleq_coefs",0));
1896 for (i = 0; i < j; i++)
1902 z = cpl_malloc(nv*
sizeof(
float));
1904 for (i = 0; i < nv; i++) {
1906 w = strtok_r(v,
",", &saveptr1);
1908 w = strtok_r(NULL,
",", &saveptr1);
1909 z[i] = (float)atof(w);
1935static double pixsize (cpl_propertylist *plist) {
1939 wcs = cpl_wcs_new_from_propertylist(plist);
1940 cd = cpl_matrix_get_data((cpl_matrix *)cpl_wcs_get_cd(wcs));
1941 pix = 3600.0*sqrt(fabs(cd[0]*cd[3] - cd[1]*cd[2]));
1942 cpl_wcs_delete(wcs);
cpl_image * casu_fits_get_image(casu_fits *p)
char * casu_fits_get_fullname(casu_fits *p)
cpl_propertylist * casu_fits_get_phu(casu_fits *p)
cpl_propertylist * casu_fits_get_ehu(casu_fits *p)
void casu_medmad(float *data, unsigned char *bpm, long np, float *med, float *mad)
float casu_med(float *data, unsigned char *bpm, long npts)
void casu_medsig(float *data, unsigned char *bpm, long np, float *med, float *sig)
void casu_medmadcut(float *data, unsigned char *bpm, long np, float lcut, float hcut, float *med, float *mad)
int casu_meansig(float *data, unsigned char *bpm, long npts, float *mean, float *sig)
int vircam_illum(casu_fits **images, cpl_table **mstds, cpl_propertylist **pl, int nimages, char *filt, cpl_table *phottab, int nbsize, cpl_table **illcor, float *illcor_rms, int *status)
Work out the illumination correction.
int vircam_pfits_get_ra(const cpl_propertylist *plist, double *ra)
Get the value of RA.
int vircam_pfits_get_dec(const cpl_propertylist *plist, double *dec)
Get the value of DEC.
int vircam_pfits_get_crval1(const cpl_propertylist *plist, double *crval1)
Get the value of crval1.
int vircam_pfits_get_crval2(const cpl_propertylist *plist, double *crval2)
Get the value of crval2.
int vircam_pfits_get_detlive(const cpl_propertylist *plist, int *detlive)
Get the value of DET_LIVE.
int vircam_pfits_get_exptime(const cpl_propertylist *plist, float *exptime)
Get the value of exposure time.
int vircam_pfits_get_airmass(const cpl_propertylist *plist, float *airmass)
Get the value of the airmass.
void vircam_timestamp(char *out, int n)
int vircam_solve_gauss(double **a, double *b, int m)
const char * vircam_get_license(void)
void vircam_linfit(int npts, double *xdata, double *ydata, double *intercept, double *slope, double *sig)
void vircam_cull(cpl_frameset *in, float lthr, float hthr, int ndit, int jst, int jfn, cpl_array **mins, cpl_array **maxs, cpl_array **aves, cpl_frameset **out, int *status)
int vircam_check_crval(cpl_propertylist *phu, cpl_propertylist *ehu)
int vircam_polyfit(const cpl_array *xarray, const cpl_array *yarray, int ncoefs, int ilim, int niter, float lclip, float hclip, cpl_array **polycf, double *sigfit)
cpl_table * vircam_create_diffimg_stats(int nrows)
void vircam_copywcs(cpl_propertylist *p1, cpl_propertylist *p2)
void vircam_difference_image(cpl_image *master, cpl_image *prog, unsigned char *bpm, cpl_table *chantab, int ncells, int oper, float *global_diff, float *global_rms, cpl_image **diffim, cpl_table **diffimstats)
void vircam_madfit(int npts, float *xdata, float *ydata, float *intercept, float *slope)
int vircam_is_dummy(cpl_propertylist *p)
cpl_table * vircam_illcor_newtab(int nrows)
void vircam_exten_range(int inexten, const cpl_frame *fr, int *out1, int *out2)
int * vircam_dummy_confidence(long n)