44 #include "sinfo_dfs.h"
47 #include "sinfo_error.h"
48 #include "sinfo_utilities.h"
49 #include "sinfo_utils_wrappers.h"
50 #include "sinfo_msg.h"
51 #include "sinfo_globals.h"
52 #include "sinfo_pro_save.h"
53 #include "sinfo_skycor.h"
54 #include "sinfo_file_handling.h"
68 #define FITS_MAGIC_SZ 6
69 #define SINFO_FIT_AMOEBA_NMAX 5000
81 sinfo_fit_amoeba_get_psum(
int ndim,
int mpts,
double** p,
double* psum);
85 sinfo_fit_amotry(
double** p,
89 double (*funk)(
double[]),
95 get_chisq(
int N,
int D,
96 int (*f)(
const double x[],
const double a[],
double *result),
100 const double *sigma);
102 static int get_candidate(
const double *a,
const int ia[],
105 int (*f)(
const double x[],
const double a[],
107 int (*dfda)(
const double x[],
const double a[],
120 sinfo_frame_is_raw_dark(
char * tag);
136 sinfo_frameset_extract(
const cpl_frameset *frames,
139 cpl_frameset *subset = NULL;
144 assure( frames != NULL, CPL_ERROR_ILLEGAL_INPUT,
"Null frameset" );
145 assure( tag != NULL, CPL_ERROR_ILLEGAL_INPUT,
"Null tag" );
147 subset = cpl_frameset_new();
149 for (f = cpl_frameset_find_const(frames, tag);
151 f = cpl_frameset_find_const(frames, NULL)) {
153 cpl_frameset_insert(subset, cpl_frame_duplicate(f));
166 int sinfo_print_rec_status(
const int val) {
167 if(cpl_error_get_code() != CPL_ERROR_NONE) {
194 sinfo_vector_clip(
const cpl_vector* vinp,
199 cpl_vector* vout=NULL;
200 cpl_vector* vtmp=NULL;
211 cknull(vinp,
"Null input vector");
212 check_nomsg(vout=cpl_vector_duplicate(vinp));
213 check_nomsg(mean=cpl_vector_get_mean(vout));
214 check_nomsg(median=cpl_vector_get_median_const(vout));
215 check_nomsg(stdev=cpl_vector_get_stdev(vout));
216 check_nomsg(pt=cpl_vector_get_data(vtmp));
225 check_nomsg(cpl_vector_sort(vout,1));
226 check_nomsg(po=cpl_vector_get_data(vout));
228 if( (size > 1) && (fabs(po[size-1]-mean) > kappa*stdev)) {
231 check_nomsg(vtmp=cpl_vector_new(size));
232 check_nomsg(pt=cpl_vector_get_data(vtmp));
233 for(i=0;i<size;i++) {
236 check_nomsg(cpl_vector_delete(vout));
237 check_nomsg(vout=cpl_vector_duplicate(vtmp));
238 check_nomsg(cpl_vector_delete(vtmp));
240 check_nomsg(mean=cpl_vector_get_mean(vout));
241 check_nomsg(stdev=cpl_vector_get_stdev(vout));
256 check_nomsg(cpl_vector_sort(vout,1));
257 check_nomsg(po=cpl_vector_get_data(vout));
259 if( (size > 1) && (fabs(po[size-1]-median) > kappa*stdev)) {
262 check_nomsg(vtmp=cpl_vector_new(size));
263 check_nomsg(pt=cpl_vector_get_data(vtmp));
264 for(i=0;i<size;i++) {
267 check_nomsg(cpl_vector_delete(vout));
268 check_nomsg(vout=cpl_vector_duplicate(vtmp));
269 check_nomsg(cpl_vector_delete(vtmp));
271 check_nomsg(median=cpl_vector_get_median_const(vout));
272 check_nomsg(stdev=cpl_vector_get_stdev(vout));
327 get_candidate(
const double *a,
const int ia[],
330 int (*f)(
const double x[],
const double a[],
double *result),
331 int (*dfda)(
const double x[],
const double a[],
double result[]),
351 Mfit = cpl_matrix_get_nrow(alpha);
353 alpha_data = cpl_matrix_get_data(alpha);
354 beta_data = cpl_matrix_get_data(beta);
367 cpl_matrix_fill(alpha, 0.0);
368 cpl_matrix_fill(beta , 0.0);
370 for (k = 0; k < N; k++)
374 const double *x_k = &(x[0+k*D]);
382 sm2 = 1.0 / (sigma[k] * sigma[k]);
386 cpl_ensure( f(x_k, a, &fx_k) == 0, CPL_ERROR_ILLEGAL_INPUT, -1);
389 cpl_ensure( dfda(x_k, a, partials) == 0,
390 CPL_ERROR_ILLEGAL_INPUT, -1);
392 for (i = 0, imfit = 0; i < M; i++)
398 sm2 * (y[k] - fx_k) * partials[i];
402 for (j = 0, jmfit = 0; j < i; j++)
406 alpha_data[jmfit + imfit*Mfit] +=
418 alpha_data[jmfit + imfit*Mfit] +=
420 partials[j] * (1 + lambda);
426 cpl_ensure( imfit == Mfit, CPL_ERROR_ILLEGAL_INPUT,-1);
430 for (i = 0, imfit = 0; i < M; i++) {
432 for (j = i+1, jmfit = imfit+1; j < M; j++) {
434 alpha_data[jmfit+imfit*Mfit] = alpha_data[imfit+jmfit*Mfit];
438 cpl_ensure( jmfit == Mfit,CPL_ERROR_ILLEGAL_INPUT,-1 );
442 cpl_ensure( imfit == Mfit, CPL_ERROR_ILLEGAL_INPUT,-1);
444 da = cpl_matrix_solve(alpha, beta);
446 cpl_ensure(da != NULL, cpl_error_get_code(), -1);
449 da_data = cpl_matrix_get_data(da);
451 for (i = 0, imfit = 0; i < M; i++)
455 a_da[i] = a[i] + da_data[0 + imfit*1];
465 cpl_ensure( imfit == Mfit ,CPL_ERROR_ILLEGAL_INPUT,-1);
467 cpl_matrix_delete(da);
499 get_chisq(
int N,
int D,
500 int (*f)(
const double x[],
const double a[],
double *result),
511 for (i = 0; i < N; i++)
515 const double *x_i = &(x[0+i*D]);
520 &fx_i) == 0, CPL_ERROR_ILLEGAL_INPUT, -1.0);
525 residual = (fx_i - y[i]);
529 residual = (fx_i - y[i]) / sigma[i];
532 chi_sq += residual*residual;
541 #ifndef CPL_VECTOR_FIT_MAXITER
542 #define CPL_VECTOR_FIT_MAXITER 1000
613 sinfo_fit_lm(
const cpl_matrix *x,
614 const cpl_matrix *sigma_x,
616 const cpl_vector *sigma_y,
619 int (*f)(
const double x[],
622 int (*dfda)(
const double x[],
627 cpl_matrix **covariance)
629 const double *x_data = NULL;
630 const double *y_data = NULL;
631 const double *sigma_data = NULL;
639 double MAXLAMBDA = 10e40;
646 cpl_matrix *alpha = NULL;
647 cpl_matrix *beta = NULL;
648 double *a_data = NULL;
651 int *ia_local = NULL;
656 if (covariance != NULL) *covariance = NULL;
659 cpl_ensure_code(x != NULL, CPL_ERROR_NULL_INPUT);
660 cpl_ensure_code(sigma_x == NULL, CPL_ERROR_UNSUPPORTED_MODE);
661 cpl_ensure_code(y != NULL, CPL_ERROR_NULL_INPUT);
662 cpl_ensure_code(a != NULL, CPL_ERROR_NULL_INPUT);
664 cpl_ensure_code(f != NULL, CPL_ERROR_NULL_INPUT);
665 cpl_ensure_code(dfda != NULL, CPL_ERROR_NULL_INPUT);
668 cpl_ensure_code( sigma_y != NULL ||
669 (red_chisq == NULL && covariance == NULL),
670 CPL_ERROR_INCOMPATIBLE_INPUT);
672 D = cpl_matrix_get_ncol(x);
673 N = cpl_matrix_get_nrow(x);
674 M = cpl_vector_get_size(a);
675 cpl_ensure_code(N > 0 && D > 0 && M > 0, CPL_ERROR_ILLEGAL_INPUT);
677 cpl_ensure_code( cpl_vector_get_size(y) == N,
678 CPL_ERROR_INCOMPATIBLE_INPUT);
680 x_data = cpl_matrix_get_data_const(x);
681 y_data = cpl_vector_get_data_const(y);
682 a_data = cpl_vector_get_data(a);
686 cpl_ensure_code( cpl_vector_get_size(sigma_y) == N,
687 CPL_ERROR_INCOMPATIBLE_INPUT);
689 cpl_ensure_code( cpl_vector_get_min (sigma_y) > 0,
690 CPL_ERROR_ILLEGAL_INPUT);
691 sigma_data = cpl_vector_get_data_const(sigma_y);
694 ia_local = cpl_malloc(M *
sizeof(
int));
695 cpl_ensure_code(ia_local != NULL, CPL_ERROR_ILLEGAL_OUTPUT);
703 for (i = 0; i < M; i++)
716 cpl_ensure_code( CPL_FALSE,
717 CPL_ERROR_ILLEGAL_INPUT);
727 for (i = 0; i < M; i++)
734 if (! ( red_chisq == NULL || N > Mfit ) )
739 CPL_ERROR_ILLEGAL_INPUT);
743 alpha = cpl_matrix_new(Mfit, Mfit);
749 CPL_ERROR_ILLEGAL_OUTPUT);
752 beta = cpl_matrix_new(Mfit, 1);
756 cpl_matrix_delete(alpha);
759 CPL_ERROR_ILLEGAL_OUTPUT);
762 a_da = cpl_malloc(M *
sizeof(
double));
766 cpl_matrix_delete(alpha);
767 cpl_matrix_delete(beta);
770 CPL_ERROR_ILLEGAL_OUTPUT);
773 part = cpl_malloc(M *
sizeof(
double));
777 cpl_matrix_delete(alpha);
778 cpl_matrix_delete(beta);
782 CPL_ERROR_ILLEGAL_OUTPUT);
789 if( (chi_sq = get_chisq(N, D, f, a_data, x_data, y_data, sigma_data)) < 0)
792 cpl_matrix_delete(alpha);
793 cpl_matrix_delete(beta);
798 cpl_error_get_code());
806 lambda < MAXLAMBDA &&
807 iterations < CPL_VECTOR_FIT_MAXITER)
813 double chi_sq_candidate = 0.0;
821 while( (returncode = get_candidate(a_data, ia_local,
824 x_data, y_data, sigma_data,
825 part, alpha, beta, a_da)
827 && cpl_error_get_code() == CPL_ERROR_SINGULAR_MATRIX
828 && lambda < MAXLAMBDA)
836 if ( !( lambda < MAXLAMBDA ) )
839 cpl_matrix_delete(alpha);
840 cpl_matrix_delete(beta);
851 cpl_matrix_delete(alpha);
852 cpl_matrix_delete(beta);
857 cpl_error_get_code());
861 if ((chi_sq_candidate = get_chisq(N, D, f, a_da,
862 x_data, y_data, sigma_data)) < 0)
865 cpl_matrix_delete(alpha);
866 cpl_matrix_delete(beta);
871 cpl_error_get_code());
877 if (chi_sq_candidate > chi_sq)
890 (chi_sq - chi_sq_candidate)/chi_sq < .01)
904 for (i = 0; i < M; i++) a_data[i] = a_da[i];
906 chi_sq = chi_sq_candidate;
912 if ( !( lambda < MAXLAMBDA && iterations < CPL_VECTOR_FIT_MAXITER ) )
915 cpl_matrix_delete(alpha);
916 cpl_matrix_delete(beta);
931 for(i = 0; i < N; i++)
934 double residual = 0.0;
937 if( f(&(x_data[i*D]),
942 cpl_matrix_delete(alpha);
943 cpl_matrix_delete(beta);
948 CPL_ERROR_ILLEGAL_INPUT);
951 residual = y_data[i] - fx_i;
952 *mse += residual * residual;
958 if (red_chisq != NULL)
961 *red_chisq = chi_sq / (N-Mfit);
967 if (covariance != NULL)
971 if( get_candidate(a_data, ia_local,
972 M, N, D, 0.0, f, dfda,
973 x_data, y_data, sigma_data,
974 part, alpha, beta, a_da)
978 cpl_matrix_delete(alpha);
979 cpl_matrix_delete(beta);
984 cpl_error_get_code());
987 cov = cpl_matrix_invert_create(alpha);
991 cpl_matrix_delete(alpha);
992 cpl_matrix_delete(beta);
997 cpl_error_get_code());
1003 for (i = 0; i < Mfit; i++)
1005 if ( !(cpl_matrix_get(cov, i, i) > 0) )
1008 cpl_matrix_delete(alpha);
1009 cpl_matrix_delete(beta);
1012 cpl_matrix_delete(cov);
1016 CPL_ERROR_SINGULAR_MATRIX);
1025 *covariance = cpl_matrix_new(M, M);
1026 if (*covariance == NULL)
1029 cpl_matrix_delete(alpha);
1030 cpl_matrix_delete(beta);
1033 cpl_matrix_delete(cov);
1036 CPL_ERROR_ILLEGAL_OUTPUT);
1042 for (j = 0, jmfit = 0; j < M; j++)
1043 if (ia_local[j] != 0)
1047 for (i = 0, imfit = 0; i < M; i++)
1048 if (ia_local[i] != 0)
1050 cpl_matrix_set(*covariance, i, j,
1052 cov, imfit, jmfit));
1056 cpl_ensure( imfit == Mfit, CPL_ERROR_ILLEGAL_INPUT,-1);
1061 cpl_ensure( jmfit == Mfit, CPL_ERROR_ILLEGAL_INPUT,-1 );
1064 cpl_matrix_delete(cov);
1068 cpl_matrix_delete(alpha);
1069 cpl_matrix_delete(beta);
1073 return CPL_ERROR_NONE;
1104 sinfo_fit_amoeba_get_psum(
int ndim,
int mpts,
double** p,
double* psum)
1109 for (j=0;j<ndim;j++) {
1110 for (sum=0.0,i=0;i<mpts;i++) {
1119 #define SINFO_FIT_AMOEBA_SWAP(a,b) {swap=(a);(a)=(b);(b)=swap;}
1155 double (*funk)(
double[]),
1170 cpl_vector* sum=NULL;
1173 sum=cpl_vector_new(ndim);
1174 psum=cpl_vector_get_data(sum);
1177 sinfo_fit_amoeba_get_psum(ndim,mpts,p,psum);
1186 ihi=y[0]>y[1] ? (inhi=1,0) : (inhi=0,1);
1188 for (i=0;i< mpts;i++) {
1189 if (y[i] <= y[ilo]) ilo=i;
1190 if (y[i] > y[ihi]) {
1193 }
else if (y[i] > y[inhi] && i != ihi) inhi=i;
1195 rtol=2.0*fabs(y[ihi]-y[ilo])/(fabs(y[ihi])+fabs(y[ilo]));
1202 SINFO_FIT_AMOEBA_SWAP(y[0],y[ilo]);
1203 for (i=0;i<ndim;i++) SINFO_FIT_AMOEBA_SWAP(p[1][i],p[ilo][i]);
1206 if (*nfunk >= SINFO_FIT_AMOEBA_NMAX) {
1208 SINFO_FIT_AMOEBA_SWAP(y[0],y[ilo]);
1209 for (i=0;i<ndim;i++) SINFO_FIT_AMOEBA_SWAP(p[1][i],p[ilo][i]);
1210 for (i=0;i<ndim;i++) {
1211 sinfo_msg(
"p[1][i]=%g p[ilo][i]=%g ilo=%d",p[1][i],p[ilo][i],ilo);
1213 assure(*nfunk >= SINFO_FIT_AMOEBA_NMAX,CPL_ERROR_UNSPECIFIED,
1224 ytry=sinfo_fit_amotry(p,y,psum,ndim,funk,ihi,-1.0);
1225 if(ytry <= y[ilo]) {
1230 ytry=sinfo_fit_amotry(p,y,psum,ndim,funk,ihi,2.0);
1231 }
else if (ytry >= y[inhi]) {
1238 ytry=sinfo_fit_amotry(p,y,psum,ndim,funk,ihi,0.5);
1244 for(i=0;i<mpts;i++) {
1246 for( j=0;j<ndim;j++) {
1247 p[i][j]=psum[j]=0.5*(p[i][j]+p[ilo][j]);
1253 sinfo_fit_amoeba_get_psum(ndim,mpts,p,psum);
1261 cpl_vector_delete(sum);
1266 sinfo_fit_amotry(
double** p,
double y[],
double psum[],
int ndim,
1267 double (*funk)(
double[]),
int ihi,
double fac)
1273 cpl_vector * vtry=NULL;
1276 vtry=cpl_vector_new(ndim);
1277 ptry=cpl_vector_get_data(vtry);
1279 fac1=(1.0-fac)/ndim;
1282 for (j=0;j<ndim;j++) {
1283 ptry[j]=psum[j]*fac1-p[ihi][j]*fac2;
1286 if (ytry < y[ihi]) {
1288 for (j=0;j<ndim;j++) {
1289 psum[j] += ptry[j]-p[ihi][j];
1293 sinfo_free_my_vector(&vtry);
1310 int sinfo_vector_dindgen(cpl_vector** v)
1316 cknull(*v,
"Null input vector");
1317 check(sz=cpl_vector_get_size(*v),
"Getting size of a vector");
1320 cpl_vector_set(*v,i,(
double)i);
1342 int sinfo_is_fits_file(
const char *filename)
1348 if ((fp = fopen(filename,
"r"))==NULL) {
1353 magic = cpl_calloc(FITS_MAGIC_SZ+1,
sizeof(
char)) ;
1354 (void)fread(magic, 1, FITS_MAGIC_SZ, fp) ;
1356 magic[FITS_MAGIC_SZ] = (char)0 ;
1357 if (strstr(magic,
"SIMPLE")!=NULL)
1373 sinfo_table_correl(cpl_table * t1, cpl_table* t2, cpl_table* range,
double* xcor)
1385 cpl_table* tmp_t1=NULL;
1386 cpl_table* tmp_t2=NULL;
1388 check_nomsg(nr=cpl_table_get_nrow(range));
1390 wsr=cpl_table_get_double(range,
"WSTART",i,&status);
1391 wer=cpl_table_get_double(range,
"WEND",i,&status);
1392 cpl_table_and_selected_double(t1,
"WAVE",CPL_NOT_LESS_THAN,wsr);
1393 cpl_table_and_selected_double(t1,
"WAVE",CPL_NOT_GREATER_THAN,wer);
1394 tmp_t1=cpl_table_extract_selected(t1);
1395 cpl_table_and_selected_double(t2,
"WAVE",CPL_NOT_LESS_THAN,wsr);
1396 cpl_table_and_selected_double(t2,
"WAVE",CPL_NOT_GREATER_THAN,wer);
1397 tmp_t2=cpl_table_extract_selected(t2);
1398 cpl_table_duplicate_column(tmp_t1,
"INT1",tmp_t1,
"INT");
1399 cpl_table_duplicate_column(tmp_t1,
"INT2",tmp_t2,
"INT");
1400 cpl_table_multiply_columns(tmp_t1,
"INT1",
"INT2");
1401 mean=cpl_table_get_column_mean(tmp_t1,
"INT1");
1402 nrows=cpl_table_get_nrow(tmp_t1);
1408 return cpl_error_get_code();
1417 sinfo_frameset_merge(cpl_frameset * set1, cpl_frameset* set2)
1420 cpl_frame* frm_tmp=NULL;
1421 cpl_frame* frm_dup=NULL;
1423 passure(set1 != NULL,
"Wrong input set");
1425 check_nomsg(frm_tmp = cpl_frameset_get_first(set2));
1426 while (frm_tmp != NULL)
1428 frm_dup=cpl_frame_duplicate(frm_tmp);
1429 cpl_frameset_insert(set1,frm_dup);
1430 frm_tmp = cpl_frameset_get_next(set2);
1434 return cpl_error_get_code();
1448 sinfo_extract_frames_group_type(
const cpl_frameset *
set,
1450 cpl_frame_group type)
1452 const cpl_frame* frm_tmp=NULL;
1453 cpl_frame* frm_dup=NULL;
1456 check_nomsg(*ext = cpl_frameset_new());
1457 check_nomsg(frm_tmp = cpl_frameset_get_first_const(
set));
1458 while (frm_tmp != NULL)
1460 g=cpl_frame_get_group(frm_tmp);
1462 frm_dup=cpl_frame_duplicate(frm_tmp);
1463 cpl_frameset_insert(*ext,frm_dup);
1465 type,cpl_frame_get_filename(frm_dup));
1467 frm_tmp = cpl_frameset_get_next_const(
set);
1471 return cpl_error_get_code();
1488 sinfo_get_pupil_shift(cpl_imagelist* iml,
const int n,cpl_table** qclog_tbl)
1490 cpl_size max_ima_x=0;
1491 cpl_size max_ima_y=0;
1498 double max_ima_cx=0;
1499 double max_ima_cy=0;
1501 cpl_image* img=NULL;
1502 cpl_image* img_dup=NULL;
1504 char key_name[FILE_NAME_SZ];
1506 img=cpl_imagelist_collapse_median_create(iml);
1507 nx=cpl_image_get_size_x(img);
1508 ny=cpl_image_get_size_y(img);
1510 img_dup=cpl_image_duplicate(img);
1511 sinfo_clean_nan(&img_dup);
1512 cpl_image_get_maxpos(img_dup,&max_ima_x,&max_ima_y);
1513 max_ima_cx=cpl_image_get_centroid_x_window(img_dup,1,1,nx,ny);
1514 max_ima_cy=cpl_image_get_centroid_y_window(img_dup,1,1,nx,ny);
1516 cpl_image_delete(img_dup);
1519 xshift=max_ima_cx-(double)nx/2;
1520 yshift=max_ima_cy-(double)ny/2;
1522 snprintf(key_name,
sizeof(key_name),
"%s%d%s",
"QC PUPIL",n,
" SHIFTX");
1523 sinfo_qclog_add_double(*qclog_tbl,key_name,xshift,
1524 "X shift centroid - center image",
"%f");
1526 snprintf(key_name,
sizeof(key_name),
"%s%d%s",
"QC PUPIL",n,
" SHIFTY");
1527 sinfo_qclog_add_double(*qclog_tbl,key_name,yshift,
1528 "Y shift centroid - center image",
"%f");
1529 cpl_image_delete(img);
1542 int sinfo_get_strehl_type(cpl_frameset* sof)
1547 cpl_frameset* obs=NULL;
1549 cpl_frame* frame=NULL;
1550 float* pix_scale=NULL;
1551 cpl_propertylist* plist=NULL;
1553 obs = cpl_frameset_new();
1555 sinfo_contains_frames_kind(sof,obs,PRO_OBS_PSF);
1557 nobs=cpl_frameset_get_size(obs);
1559 sinfo_contains_frames_kind(sof,obs,PRO_OBS_STD);
1560 nobs=cpl_frameset_get_size(obs);
1563 nobs=cpl_frameset_get_size(obs);
1568 pix_scale=cpl_calloc(nobs,
sizeof(
float));
1569 for(i=0;i<nobs;i++) {
1570 frame=cpl_frameset_get_frame(obs,i);
1571 plist=cpl_propertylist_load(cpl_frame_get_filename(frame),0);
1572 pix_scale[i]=sinfo_pfits_get_pixscale(plist);
1573 cpl_propertylist_delete(plist);
1575 if(sinfo_pix_scale_isnot_const(pix_scale,nobs)) {
1578 cpl_free(pix_scale);
1580 cpl_frameset_delete(obs);
1594 double sinfo_get_wave_cent(
const char* band)
1597 if (strcmp(band,
"H+K") == 0) {
1599 }
else if (strcmp(band,
"K") == 0) {
1601 }
else if (strcmp(band,
"J") == 0) {
1603 }
else if (strcmp(band,
"H") == 0) {
1620 int sinfo_pix_scale_isnot_const(
float* pix_scale,
const int n) {
1623 float ref=pix_scale[0];
1626 if(fabs(pix_scale[i]-ref) > eps)
return 1;
1639 const char* sinfo_get_pix_scale(
float ps) {
1641 const char* key_value;
1644 if(fabs(ps - 0.025) < eps) {
1647 else if (fabs(ps - 0.1) < eps) {
1650 else if (fabs(ps - 0.25) < eps) {
1653 else if (fabs(ps - 1.0) < eps) {
1679 int sinfo_get_clean_mean_window(cpl_image* img,
1680 int llx,
int lly,
int urx,
int ury,
1681 const int kappa,
const int nclip,
1682 double* local_clean_mean,
1683 double* clean_stdev)
1691 cpl_mask* mask=NULL;
1692 cpl_image* tmp=NULL;
1693 cpl_stats* stats=NULL;
1696 tmp=cpl_image_extract(img,llx,lly,urx,ury);
1697 cpl_image_accept_all(tmp);
1698 for(i=0;i<nclip;i++) {
1701 cpl_stats_delete(stats);
1702 stats = cpl_stats_new_from_image(tmp, CPL_STATS_MEAN | CPL_STATS_STDEV);
1703 mean = cpl_stats_get_mean(stats);
1704 stdev = cpl_stats_get_stdev(stats);
1706 threshold=kappa*stdev;
1707 lo_cut=mean-threshold;
1708 hi_cut=mean+threshold;
1709 cpl_image_accept_all(tmp);
1710 mask=cpl_mask_threshold_image_create(tmp,lo_cut,hi_cut);
1713 cpl_image_reject_from_mask(tmp,mask);
1714 cpl_mask_delete(mask);
1718 *local_clean_mean=mean;
1720 cpl_image_delete(tmp);
1721 cpl_stats_delete(stats);
1733 int sinfo_check_rec_status(
const int val) {
1734 if(cpl_error_get_code() != CPL_ERROR_NONE) {
1750 sinfo_clean_nan(cpl_image** im)
1758 nx=cpl_image_get_size_x(*im);
1759 ny=cpl_image_get_size_y(*im);
1760 data=cpl_image_get_data_float(*im);
1764 if(isnan(data[j*nx+i]) != 0) {
1782 sinfo_add_pro_fits_key(cpl_propertylist * plist,
1789 date = sinfo_get_datetime_iso8601() ;
1791 cpl_propertylist_insert_after_string(plist,
"EXPTIME",
1792 KEY_NAME_PIPEFILE, out_name) ;
1793 cpl_propertylist_set_comment(plist, KEY_NAME_PIPEFILE,KEY_HELP_PIPEFILE) ;
1795 cpl_propertylist_insert_after_string(plist,
"EXPTIME",
1796 KEY_NAME_HPRO_DID, KEY_VALUE_HPRO_DID) ;
1797 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DID,KEY_HELP_HPRO_DID) ;
1799 cpl_propertylist_insert_after_string(plist,
"EXPTIME",
1800 KEY_NAME_HPRO_TYPE,
"REDUCED") ;
1801 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_TYPE, KEY_HELP_HPRO_TYPE) ;
1803 cpl_propertylist_insert_after_string(plist,
"EXPTIME",
1804 KEY_NAME_HPRO_CATG, pro_catg) ;
1805 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_CATG, KEY_HELP_HPRO_CATG);
1807 cpl_propertylist_insert_after_string(plist,
"EXPTIME",
1808 KEY_NAME_HPRO_STATUS,
"OK") ;
1809 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_STATUS,KEY_HELP_HPRO_CATG);
1811 cpl_propertylist_insert_after_string(plist,
"EXPTIME",
1812 KEY_NAME_HPRO_DATE, date) ;
1813 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DATE, KEY_HELP_HPRO_DATE);
1815 cpl_propertylist_insert_after_string(plist,
"EXPTIME",
1816 KEY_NAME_HPRO_RECID, file_name) ;
1817 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_RECID,KEY_HELP_HPRO_RECID);
1819 cpl_propertylist_insert_after_string(plist,
"EXPTIME",
1820 KEY_NAME_HPRO_DRSID, PACKAGE_VERSION);
1821 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DRSID,KEY_HELP_HPRO_DRSID);
1833 int sinfo_compare_tags(
1834 const cpl_frame * frame1,
1835 const cpl_frame * frame2)
1841 if (frame1==NULL || frame2==NULL)
return -1 ;
1844 if ((v1 = (
char*)cpl_frame_get_tag(frame1)) == NULL)
return -1 ;
1845 if ((v2 = (
char*)cpl_frame_get_tag(frame2)) == NULL)
return -1 ;
1848 if (strcmp(v1, v2))
return 0 ;
1860 int sinfo_extract_raw_pinhole_frames(cpl_frameset * sof, cpl_frameset** raw)
1864 cpl_frame* frame = NULL;
1867 nsof = cpl_frameset_get_size(sof);
1868 for (i=0 ; i<nsof ; i++) {
1869 frame = cpl_frameset_get_frame(sof,i);
1870 name= (
char*) cpl_frame_get_filename(frame);
1871 if(sinfo_is_fits_file(name) == 1) {
1873 if(cpl_frame_get_tag(frame) != NULL) {
1875 tag= (
char*) cpl_frame_get_tag(frame);
1876 if(sinfo_frame_is_pinhole_lamp(tag) == 1) {
1877 cpl_frameset_insert(*raw,frame);
1886 int sinfo_get_ins_set(
char* band,
int* ins_set){
1888 if (strcmp(band,
"H") == 0) {
1891 else if (strcmp(band,
"H+K") == 0) {
1894 else if (strcmp(band,
"K") == 0) {
1897 else if (strcmp(band,
"J") == 0) {
1904 int sinfo_extract_raw_frames(cpl_frameset * sof, cpl_frameset** raw)
1908 cpl_frame* frame = NULL;
1911 nsof = cpl_frameset_get_size(sof);
1912 for (i=0 ; i<nsof ; i++) {
1913 frame = cpl_frameset_get_frame(sof,i);
1914 name= (
char*) cpl_frame_get_filename(frame);
1915 if(sinfo_is_fits_file(name) == 1) {
1917 if(cpl_frame_get_tag(frame) != NULL) {
1919 tag= (
char*) cpl_frame_get_tag(frame);
1920 if(sinfo_frame_is_raw(tag) == 1) {
1921 cpl_frameset_insert(*raw,frame);
1929 int sinfo_remove_qc_frames(cpl_frameset* sof,cpl_frameset** raw)
1933 cpl_frame* frame = NULL;
1937 nsof = cpl_frameset_get_size(sof);
1938 for (i=0 ; i<nsof ; i++) {
1939 frame = cpl_frameset_get_frame(sof,i);
1940 name= (
char*) cpl_frame_get_filename(frame);
1942 if(sinfo_is_fits_file(name) == 1) {
1945 if(cpl_frame_get_tag(frame) != NULL) {
1947 tag= (
char*) cpl_frame_get_tag(frame);
1949 if(strstr(tag,
"QC") != NULL) {
1951 cpl_frameset_erase(*raw,tag);
1956 cpl_frameset_erase_frame(*raw,frame);
1964 int sinfo_contains_frames_kind(cpl_frameset * sof,
1970 cpl_frame* frame = NULL;
1971 cpl_frame* frame_dup = NULL;
1975 nsof = cpl_frameset_get_size(sof);
1976 for (i=0 ; i<nsof ; i++) {
1977 frame = cpl_frameset_get_frame(sof,i);
1978 name= (
char*) cpl_frame_get_filename(frame);
1979 if(sinfo_is_fits_file(name) == 1) {
1981 if(cpl_frame_get_tag(frame) != NULL) {
1983 tag= (
char*) cpl_frame_get_tag(frame);
1985 if(strstr(tag,type) != NULL) {
1987 frame_dup = cpl_frame_duplicate(frame);
1988 cpl_frameset_insert(raw,frame_dup);
2000 int sinfo_is_fibres_on_off(cpl_frameset * sof,
2005 cpl_frame* frame = NULL;
2006 cpl_frame* frame_dup = NULL;
2010 nsof = cpl_frameset_get_size(sof);
2011 for (i=0 ; i<nsof ; i++) {
2012 frame = cpl_frameset_get_frame(sof,i);
2013 name= (
char*) cpl_frame_get_filename(frame);
2014 if(sinfo_is_fits_file(name) == 1) {
2016 if(cpl_frame_get_tag(frame) != NULL) {
2018 tag= (
char*) cpl_frame_get_tag(frame);
2020 if( strcmp(tag,PRO_FIBRE_NS_STACKED ) == 0) {
2022 frame_dup = cpl_frame_duplicate(frame);
2023 cpl_frameset_insert(raw,frame_dup);
2033 int sinfo_contains_frames_type(cpl_frameset * sof,
2039 cpl_frame* frame = NULL;
2040 cpl_frame* frame_dup = NULL;
2043 nsof = cpl_frameset_get_size(sof);
2044 for (i=0 ; i<nsof ; i++) {
2045 frame = cpl_frameset_get_frame(sof,i);
2046 name= (
char*) cpl_frame_get_filename(frame);
2047 if(sinfo_is_fits_file(name) == 1) {
2049 if(cpl_frame_get_tag(frame) != NULL) {
2051 tag= (
char*) cpl_frame_get_tag(frame);
2052 if(strstr(tag,type) != NULL) {
2054 frame_dup=cpl_frame_duplicate(frame);
2055 cpl_frameset_insert(*raw,frame_dup);
2063 int sinfo_extract_raw_frames_type2(cpl_frameset * sof,
2068 cpl_frame* frame=NULL;
2069 cpl_frame* frame_dup = NULL;
2070 frame = cpl_frameset_find(sof,type);
2072 frame_dup=cpl_frame_duplicate(frame);
2073 cpl_frameset_insert(*raw,frame_dup);
2074 frame = cpl_frameset_find(sof,NULL);
2081 int sinfo_extract_raw_frames_type1(cpl_frameset * sof,
2086 cpl_frame* frame=NULL;
2087 cpl_frame* frame_dup = NULL;
2088 frame = cpl_frameset_find(sof,type);
2090 frame_dup=cpl_frame_duplicate(frame);
2091 cpl_frameset_insert(raw,frame_dup);
2092 frame = cpl_frameset_find(sof,NULL);
2098 int sinfo_extract_raw_frames_type(cpl_frameset * sof,
2102 char tag[FILE_NAME_SZ];
2103 char name[FILE_NAME_SZ];
2104 cpl_frame* frame = NULL;
2105 cpl_frame* frame_dup = NULL;
2108 nsof = cpl_frameset_get_size(sof);
2109 for (i=0 ; i<nsof ; i++) {
2110 frame = cpl_frameset_get_frame(sof,i);
2111 strcpy(name, cpl_frame_get_filename(frame));
2112 if(sinfo_is_fits_file(name) == 1) {
2114 if(cpl_frame_get_tag(frame) != NULL) {
2116 strcpy(tag,cpl_frame_get_tag(frame));
2117 if(strcmp(tag,type) == 0) {
2119 frame_dup=cpl_frame_duplicate(frame);
2121 cpl_frameset_insert(*raw,frame_dup);
2129 int sinfo_extract_frames_type(cpl_frameset * sof,
2135 cpl_frame* frame = NULL;
2136 cpl_frame* frame_dup = NULL;
2139 nsof = cpl_frameset_get_size(sof);
2140 for (i=0 ; i<nsof ; i++) {
2141 frame = cpl_frameset_get_frame(sof,i);
2142 name= (
char*) cpl_frame_get_filename(frame);
2143 if(sinfo_is_fits_file(name) == 1) {
2145 if(cpl_frame_get_tag(frame) != NULL) {
2147 tag= (
char*) cpl_frame_get_tag(frame);
2148 if(strcmp(tag,type) == 0) {
2150 frame_dup=cpl_frame_duplicate(frame);
2151 cpl_frameset_insert(raw,frame_dup);
2160 int sinfo_extract_obj_frames(cpl_frameset * sof, cpl_frameset* obj)
2164 cpl_frame* frame = NULL;
2165 cpl_frame* frame_dup = NULL;
2169 nsof = cpl_frameset_get_size(sof);
2170 for (i=0 ; i<nsof ; i++) {
2171 frame = cpl_frameset_get_frame(sof,i);
2172 name= (
char*) cpl_frame_get_filename(frame);
2173 if(sinfo_is_fits_file(name) ==1) {
2175 if(cpl_frame_get_tag(frame) != NULL) {
2177 tag= (
char*) cpl_frame_get_tag(frame);
2178 if(sinfo_tag_is_obj(tag) == 1) {
2179 frame_dup=cpl_frame_duplicate(frame);
2180 cpl_frameset_insert(obj,frame_dup);
2190 int sinfo_extract_obj_products(cpl_frameset * sof, cpl_frameset* obj)
2194 cpl_frame* frame = NULL;
2195 cpl_frame* frame_dup = NULL;
2199 nsof = cpl_frameset_get_size(sof);
2200 for (i=0 ; i<nsof ; i++) {
2201 frame = cpl_frameset_get_frame(sof,i);
2202 name= (
char*) cpl_frame_get_filename(frame);
2203 if(sinfo_is_fits_file(name) ==1) {
2205 if(cpl_frame_get_tag(frame) != NULL) {
2207 tag= (
char*) cpl_frame_get_tag(frame);
2208 if(sinfo_tag_is_objpro(tag) == 1) {
2209 frame_dup=cpl_frame_duplicate(frame);
2210 cpl_frameset_insert(obj,frame_dup);
2219 int sinfo_extract_on_frames(cpl_frameset * sof, cpl_frameset* on)
2221 cpl_frame* frame = NULL;
2222 cpl_frame* frame_dup = NULL;
2226 nsof = cpl_frameset_get_size(sof);
2227 for (i=0 ; i<nsof ; i++) {
2228 frame = cpl_frameset_get_frame(sof,i);
2229 if(sinfo_frame_is_on(frame) ==1) {
2230 frame_dup=cpl_frame_duplicate(frame);
2231 cpl_frameset_insert(on,frame_dup);
2238 int sinfo_extract_sky_frames(cpl_frameset * sof, cpl_frameset* sky)
2242 cpl_frame* frame = NULL;
2243 cpl_frame* frame_dup = NULL;
2246 nsof = cpl_frameset_get_size(sof);
2247 for (i=0 ; i<nsof ; i++) {
2248 frame = cpl_frameset_get_frame(sof,i);
2249 name= (
char*) cpl_frame_get_filename(frame);
2250 if(sinfo_is_fits_file(name) ==1) {
2252 if(cpl_frame_get_tag(frame) != NULL) {
2254 tag= (
char*) cpl_frame_get_tag(frame);
2255 if(sinfo_tag_is_sky(tag) == 1) {
2256 frame_dup=cpl_frame_duplicate(frame);
2257 cpl_frameset_insert(sky,frame_dup);
2268 int sinfo_extract_off_frames(cpl_frameset * sof, cpl_frameset* off)
2270 cpl_frame* frame = NULL;
2271 cpl_frame* frame_dup = NULL;
2274 nsof = cpl_frameset_get_size(sof);
2275 for (i=0 ; i<nsof ; i++) {
2276 frame = cpl_frameset_get_frame(sof,i);
2277 if(sinfo_frame_is_on(frame)) {
2278 frame_dup=cpl_frame_duplicate(frame);
2279 cpl_frameset_insert(off,frame_dup);
2286 int sinfo_extract_mst_frames(cpl_frameset * sof, cpl_frameset* cdb)
2290 cpl_frame* frame = NULL;
2291 cpl_frame* frame_dup = NULL;
2295 nsof = cpl_frameset_get_size(sof);
2296 for (i=0 ; i<nsof ; i++) {
2297 frame = cpl_frameset_get_frame(sof,i);
2298 name= (
char*) cpl_frame_get_filename(frame);
2299 if(sinfo_is_fits_file(name) ==1) {
2301 if(cpl_frame_get_tag(frame) != NULL) {
2303 tag= (
char*) cpl_frame_get_tag(frame);
2304 if(sinfo_frame_is_cdb(tag) == 1) {
2305 frame_dup=cpl_frame_duplicate(frame);
2306 cpl_frameset_insert(cdb,frame_dup);
2315 cpl_frameset* sinfo_frameset_join(cpl_frameset* fs1,cpl_frameset* fs2) {
2317 cpl_frameset* join=NULL;
2318 cpl_frame* frm=NULL;
2319 cpl_frame* frm_dup=NULL;
2323 join=cpl_frameset_new();
2325 n=cpl_frameset_get_size(fs1);
2327 frm=cpl_frameset_get_frame(fs1,i);
2328 frm_dup= cpl_frame_duplicate(frm);
2329 cpl_frameset_insert(join,frm_dup);
2332 n=cpl_frameset_get_size(fs2);
2334 frm=cpl_frameset_get_frame(fs2,i);
2335 frm_dup= cpl_frame_duplicate(frm);
2336 cpl_frameset_insert(join,frm_dup);
2345 int sinfo_extract_stk_frames(cpl_frameset * sof,
2350 cpl_frame* frame = NULL;
2351 cpl_frame* frame_dup = NULL;
2355 nsof = cpl_frameset_get_size(sof);
2356 for (i=0 ; i<nsof ; i++) {
2357 frame = cpl_frameset_get_frame(sof,i);
2358 name= (
char*) cpl_frame_get_filename(frame);
2359 if(sinfo_is_fits_file(name) ==1) {
2361 if(cpl_frame_get_tag(frame) != NULL) {
2363 tag= (
char*) cpl_frame_get_tag(frame);
2364 if(sinfo_frame_is_stk(tag) == 1) {
2365 frame_dup=cpl_frame_duplicate(frame);
2366 cpl_frameset_insert(res,frame_dup);
2377 sinfo_extract_preoptic_frames(cpl_frameset * sof,
2382 cpl_frame* frame = NULL;
2383 cpl_frame* frame_dup = NULL;
2387 nsof = cpl_frameset_get_size(sof);
2388 for (i=0 ; i<nsof ; i++) {
2389 frame = cpl_frameset_get_frame(sof,i);
2390 name= (
char*) cpl_frame_get_filename(frame);
2391 if(sinfo_is_fits_file(name) ==1) {
2392 if(sinfo_frame_is_preoptic(frame,val) == 1) {
2393 frame_dup=cpl_frame_duplicate(frame);
2394 cpl_frameset_insert(*res,frame_dup);
2402 int sinfo_extract_raw_stack_frames(cpl_frameset * sof, cpl_frameset** pro)
2406 cpl_frame* frame = NULL;
2407 cpl_frame* frame_dup = NULL;
2411 nsof = cpl_frameset_get_size(sof);
2413 for (i=0 ; i<nsof ; i++) {
2414 frame = cpl_frameset_get_frame(sof,i);
2415 name= (
char*) cpl_frame_get_filename(frame);
2416 if(sinfo_is_fits_file(name) ==1) {
2418 if(cpl_frame_get_tag(frame) != NULL) {
2420 tag= (
char*) cpl_frame_get_tag(frame);
2422 if(sinfo_frame_is_raw_stack(tag) == 1) {
2423 frame_dup = cpl_frame_duplicate(frame);
2424 cpl_frameset_insert(*pro,frame_dup);
2434 int sinfo_extract_raw_slit_frames(cpl_frameset * sof, cpl_frameset** pro)
2438 cpl_frame* frame = NULL;
2441 nsof = cpl_frameset_get_size(sof);
2442 for (i=0 ; i<nsof ; i++) {
2443 frame = cpl_frameset_get_frame(sof,i);
2444 name= (
char*) cpl_frame_get_filename(frame);
2445 if(sinfo_is_fits_file(name) ==1) {
2447 if(cpl_frame_get_tag(frame) != NULL) {
2449 tag= (
char*) cpl_frame_get_tag(frame);
2450 if(sinfo_frame_is_slit_lamp(tag) == 1) {
2451 cpl_frameset_insert(*pro,frame);
2467 int sinfo_frame_is_raw(
char * tag)
2470 if (tag == NULL)
return -1 ;
2472 if (!strcmp(tag, RAW_LINEARITY_LAMP))
return 1 ;
2473 if (!strcmp(tag, RAW_DARK))
return 1 ;
2474 if (!strcmp(tag, RAW_PINHOLE_LAMP))
return 1 ;
2475 if (!strcmp(tag, RAW_SLIT_LAMP))
return 1 ;
2476 if (!strcmp(tag, RAW_WAVE_LAMP))
return 1 ;
2477 if (!strcmp(tag, RAW_FLAT_LAMP))
return 1 ;
2478 if (!strcmp(tag, RAW_WAVE_NS))
return 1 ;
2479 if (!strcmp(tag, RAW_FLAT_NS))
return 1 ;
2480 if (!strcmp(tag, RAW_FIBRE_LAMP))
return 1 ;
2481 if (!strcmp(tag, RAW_FIBRE_EW))
return 1 ;
2482 if (!strcmp(tag, RAW_FIBRE_NS))
return 1 ;
2483 if (!strcmp(tag, RAW_FLAT_SKY))
return 1 ;
2484 if (!strcmp(tag, RAW_FLUX_LAMP))
return 1 ;
2485 if (!strcmp(tag, RAW_PSF_CALIBRATOR))
return 1 ;
2486 if (!strcmp(tag, RAW_FOCUS))
return 1 ;
2488 if (!strcmp(tag, RAW_STD))
return 1 ;
2489 if (!strcmp(tag, RAW_STD_STAR))
return 1 ;
2490 if (!strcmp(tag, RAW_STD_STAR_DITHER))
return 1 ;
2491 if (!strcmp(tag, RAW_SKY_STD))
return 1 ;
2492 if (!strcmp(tag, RAW_SKY_OH))
return 1 ;
2493 if (!strcmp(tag, RAW_SKY_PSF_CALIBRATOR))
return 1 ;
2495 if (!strcmp(tag, RAW_PUPIL_LAMP))
return 1 ;
2496 if (!strcmp(tag, RAW_OBJECT_JITTER))
return 1 ;
2497 if (!strcmp(tag, RAW_SKY_JITTER))
return 1 ;
2498 if (!strcmp(tag, RAW_OBJECT_NODDING))
return 1 ;
2499 if (!strcmp(tag, RAW_OBJECT_SKYSPIDER))
return 1 ;
2500 if (!strcmp(tag, RAW_SKY_NODDING))
return 1 ;
2502 if (!strcmp(tag, RAW_FLAT_LAMP_DITHER))
return 1 ;
2503 if (!strcmp(tag, RAW_WAVE_LAMP_DITHER))
return 1 ;
2504 if (!strcmp(tag, RAW_STD_STAR_DITHER))
return 1 ;
2505 if (!strcmp(tag, RAW_OBJECT_NODDING_DITHER))
return 1 ;
2506 if (!strcmp(tag, RAW_OBJECT_SKYSPIDER_DITHER))
return 1 ;
2507 if (!strcmp(tag, RAW_SKY_NODDING_DITHER))
return 1 ;
2520 int sinfo_frame_is_raw_stack(
char * tag)
2523 if (tag == NULL)
return -1 ;
2526 if (!strcmp(tag, PRO_SKY_DUMMY))
return 1 ;
2527 if (!strcmp(tag, RAW_WAVE_LAMP))
return 1 ;
2528 if (!strcmp(tag, RAW_WAVE_LAMP_DITHER))
return 1 ;
2529 if (!strcmp(tag, RAW_WAVE_NS))
return 1 ;
2530 if (!strcmp(tag, RAW_WAVE_NS_DITHER))
return 1 ;
2532 if (!strcmp(tag, RAW_FLUX_LAMP))
return 1 ;
2533 if (!strcmp(tag, RAW_FIBRE_NS))
return 1 ;
2534 if (!strcmp(tag, RAW_FIBRE_EW))
return 1 ;
2536 if (!strcmp(tag, RAW_PSF_CALIBRATOR))
return 1 ;
2537 if (!strcmp(tag, RAW_FIBRE_PSF))
return 1 ;
2538 if (!strcmp(tag, RAW_FIBRE_DARK))
return 1 ;
2540 if (!strcmp(tag, RAW_FOCUS))
return 1 ;
2542 if (!strcmp(tag, RAW_PUPIL_LAMP))
return 1 ;
2543 if (!strcmp(tag, RAW_OBJECT_JITTER))
return 1 ;
2544 if (!strcmp(tag, RAW_SKY_JITTER))
return 1 ;
2545 if (!strcmp(tag, RAW_OBJECT_NODDING))
return 1 ;
2546 if (!strcmp(tag, RAW_OBJECT_SKYSPIDER))
return 1 ;
2547 if (!strcmp(tag, RAW_SKY_NODDING))
return 1 ;
2549 if (!strcmp(tag, RAW_OBJECT_NODDING_DITHER))
return 1 ;
2550 if (!strcmp(tag, RAW_OBJECT_SKYSPIDER_DITHER))
return 1 ;
2551 if (!strcmp(tag, RAW_SKY_NODDING_DITHER))
return 1 ;
2554 if (!strcmp(tag, RAW_IMAGE_PRE_OBJECT))
return 1 ;
2555 if (!strcmp(tag, RAW_IMAGE_PRE_SKY))
return 1 ;
2556 if (!strcmp(tag, RAW_STD))
return 1 ;
2557 if (!strcmp(tag, RAW_SKY_STD))
return 1 ;
2558 if (!strcmp(tag, RAW_SKY_OH))
return 1 ;
2559 if (!strcmp(tag, RAW_SKY_PSF_CALIBRATOR))
return 1 ;
2560 if (!strcmp(tag, RAW_STD_STAR))
return 1 ;
2561 if (!strcmp(tag, RAW_SKY))
return 1 ;
2574 int sinfo_frame_is_raw_dark(
char * tag)
2577 if (tag == NULL)
return -1 ;
2579 if (!strcmp(tag, RAW_DARK))
return 1 ;
2591 int sinfo_frame_is_slit_lamp(
char * tag)
2594 if (tag == NULL)
return -1 ;
2596 if (!strcmp(tag, RAW_SLIT_LAMP))
return 1 ;
2609 int sinfo_frame_is_pinhole_lamp(
char * tag)
2612 if (tag == NULL)
return -1 ;
2614 if (!strcmp(tag, RAW_PINHOLE_LAMP))
return 1 ;
2620 int sinfo_frame_is_cdb(
char * tag)
2623 if (tag == NULL)
return -1 ;
2653 if (!strcmp(tag, REF_LINE_ARC))
return 1 ;
2654 if (!strcmp(tag, REF_LINE_OH))
return 1 ;
2655 if (!strcmp(tag, PRO_BP_MAP))
return 1 ;
2656 if (!strcmp(tag, PRO_BP_MAP_HP))
return 1 ;
2657 if (!strcmp(tag, PRO_BP_MAP_DI))
return 1 ;
2658 if (!strcmp(tag, PRO_BP_MAP_NO))
return 1 ;
2659 if (!strcmp(tag, PRO_BP_MAP_NL))
return 1 ;
2660 if (!strcmp(tag, PRO_MASTER_BP_MAP))
return 1 ;
2661 if (!strcmp(tag, PRO_MASTER_DARK))
return 1 ;
2662 if (!strcmp(tag, PRO_SLOPE))
return 1 ;
2663 if (!strcmp(tag, PRO_DISTORTION))
return 1 ;
2664 if (!strcmp(tag, PRO_SLITLETS_DISTANCE))
return 1 ;
2665 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP))
return 1 ;
2666 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP1))
return 1 ;
2667 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP2))
return 1 ;
2668 if (!strcmp(tag, PRO_SLIT_POS))
return 1 ;
2669 if (!strcmp(tag, PRO_SLIT_POS_GUESS))
return 1 ;
2670 if (!strcmp(tag, PRO_WAVE_PAR_LIST))
return 1 ;
2671 if (!strcmp(tag, PRO_WAVE_COEF_SLIT))
return 1 ;
2672 if (!strcmp(tag, PRO_MASTER_LAMP_SPEC))
return 1 ;
2673 if (!strcmp(tag, PRO_MASTER_TWIFLAT))
return 1 ;
2674 if (!strcmp(tag, PRO_COEFF_LIST))
return 1 ;
2675 if (!strcmp(tag, PRO_INDEX_LIST))
return 1 ;
2676 if (!strcmp(tag, PRO_HALO_SPECT))
return 1 ;
2677 if (!strcmp(tag, PRO_FIRST_COL))
return 1 ;
2678 if (!strcmp(tag, PRO_FOCUS))
return 1 ;
2679 if (!strcmp(tag, PRO_WAVE_MAP))
return 1 ;
2680 if (!strcmp(tag, PRO_REF_ATM_REF_CORR))
return 1 ;
2689 int sinfo_frame_is_stk(
char * tag)
2692 if (tag == NULL)
return -1 ;
2696 if (!strcmp(tag, PRO_SKY_STACKED_DUMMY))
return 1 ;
2697 if (!strcmp(tag, PRO_STACK_SKY_DIST))
return 1 ;
2698 if (!strcmp(tag, PRO_STACK_MFLAT_DIST))
return 1 ;
2699 if (!strcmp(tag, PRO_PSF_CALIBRATOR_STACKED))
return 1 ;
2707 sinfo_propertylist_has(cpl_propertylist* plist,
2710 return cpl_propertylist_has(plist,key);
2714 int sinfo_frame_is_preoptic(cpl_frame* frame,
const char* val)
2718 char popt[FILE_NAME_SZ];
2719 cpl_propertylist* plist=NULL;
2722 file = cpl_strdup(cpl_frame_get_filename(frame)) ;
2723 if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
2725 cpl_propertylist_delete(plist) ;
2730 if (sinfo_propertylist_has(plist, KEY_NAME_PREOPTICS)) {
2731 strcpy(popt,cpl_propertylist_get_string(plist, KEY_NAME_PREOPTICS));
2737 cpl_propertylist_delete(plist) ;
2740 if (strstr(val,popt) != NULL)
return 1 ;
2748 int sinfo_get_preoptic(
const char* file,
const char* val)
2751 cpl_propertylist* plist=NULL;
2754 if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
2756 cpl_propertylist_delete(plist) ;
2760 if (sinfo_propertylist_has(plist, KEY_NAME_PREOPTICS)) {
2761 strcpy((
char*)val,cpl_propertylist_get_string(plist, KEY_NAME_PREOPTICS));
2766 cpl_propertylist_delete(plist) ;
2831 cpl_table* sinfo_compute_gain(cpl_frameset* son, cpl_frameset* sof)
2835 cpl_frame* frm=NULL;
2837 cpl_image* img_on1=NULL;
2838 cpl_image* img_on2=NULL;
2839 cpl_image* img_on_dif=NULL;
2840 cpl_image* img_on_sub=NULL;
2843 cpl_image* img_of1=NULL;
2844 cpl_image* img_of2=NULL;
2845 cpl_image* img_of_dif=NULL;
2846 cpl_image* img_of_sub=NULL;
2848 cpl_table* res_tbl=NULL;
2849 cpl_vector* dit_on=NULL;
2850 cpl_vector* dit_of=NULL;
2851 cpl_vector* exptime_on=NULL;
2852 cpl_vector* exptime_of=NULL;
2853 cpl_propertylist* plist=NULL;
2864 double sig_on_dif=0;
2865 double sig_of_dif=0;
2878 double exptime_ref=0;
2879 double exptime_tmp=0;
2884 non = cpl_frameset_get_size(son);
2885 nof = cpl_frameset_get_size(sof);
2886 nfr = (non <= nof) ? non : nof;
2888 dit_on=cpl_vector_new(nfr);
2889 dit_of=cpl_vector_new(nfr);
2890 exptime_on=cpl_vector_new(nfr);
2891 exptime_of=cpl_vector_new(nfr);
2893 for(i=0;i<nfr;i++) {
2895 frm=cpl_frameset_get_frame(son,i);
2896 name=(
char*)cpl_frame_get_filename(frm);
2897 plist=cpl_propertylist_load(name,0);
2898 dit_ref=sinfo_pfits_get_dit(plist);
2899 exptime_ref=(double)sinfo_pfits_get_exp_time(plist);
2900 cpl_propertylist_delete(plist);
2901 cpl_vector_set(dit_on,i,dit_ref);
2902 cpl_vector_set(exptime_on,i,exptime_ref);
2904 frm=cpl_frameset_get_frame(sof,i);
2905 name=(
char*)cpl_frame_get_filename(frm);
2906 plist=cpl_propertylist_load(name,0);
2907 dit_ref=sinfo_pfits_get_dit(plist);
2908 exptime_ref=(double)sinfo_pfits_get_exp_time(plist);
2909 cpl_propertylist_delete(plist);
2910 cpl_vector_set(dit_of,i,dit_ref);
2911 cpl_vector_set(exptime_of,i,exptime_ref);
2931 check_nomsg(res_tbl=cpl_table_new(nfr));
2932 cpl_table_new_column(res_tbl,
"adu", CPL_TYPE_DOUBLE);
2933 cpl_table_new_column(res_tbl,
"gain", CPL_TYPE_DOUBLE);
2935 for(i=0;i<nfr;i++) {
2936 frm=cpl_frameset_get_frame(son,i);
2937 name=(
char*)cpl_frame_get_filename(frm);
2938 img_on1=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
2940 frm=cpl_frameset_get_frame(sof,i);
2941 name=(
char*)cpl_frame_get_filename(frm);
2942 img_of1=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
2945 dit_ref=cpl_vector_get(dit_on,i);
2946 exptime_ref=cpl_vector_get(exptime_on,i);
2949 for(m=0;m<nfr; m++) {
2951 frm=cpl_frameset_get_frame(son,m);
2952 name=(
char*)cpl_frame_get_filename(frm);
2953 dit_tmp=cpl_vector_get(dit_on,m);
2954 exptime_tmp=cpl_vector_get(exptime_on,m);
2955 if(dit_tmp == dit_ref && exptime_tmp == exptime_ref) {
2957 img_on2=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
2958 frm=cpl_frameset_get_frame(sof,m);
2959 name=(
char*)cpl_frame_get_filename(frm);
2960 img_of2=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
2962 img_on_dif=cpl_image_subtract_create(img_on1,img_on2);
2963 img_of_dif=cpl_image_subtract_create(img_of1,img_of2);
2965 img_on_sub=cpl_image_extract(img_on_dif,llx,lly,urx,ury);
2966 img_of_sub=cpl_image_extract(img_of_dif,llx,lly,urx,ury);
2968 sinfo_get_clean_mean_window(img_on1,llx,lly,urx,ury,kappa,
2969 nclip,&avg_on1,&std);
2970 sinfo_get_clean_mean_window(img_on2,llx,lly,urx,ury,kappa,
2971 nclip,&avg_on2,&std);
2972 sinfo_get_clean_mean_window(img_of1,llx,lly,urx,ury,kappa,
2973 nclip,&avg_of1,&std);
2974 sinfo_get_clean_mean_window(img_of2,llx,lly,urx,ury,kappa,
2975 nclip,&avg_of2,&std);
2992 sinfo_get_clean_mean_window(img_on_dif,llx,lly,urx,ury,kappa,
2993 nclip,¢re,&sig_on_dif);
2994 sinfo_get_clean_mean_window(img_of_dif,llx,lly,urx,ury,kappa,
2995 nclip,¢re,&sig_of_dif);
3012 cpl_image_delete(img_on2);
3013 cpl_image_delete(img_of2);
3014 cpl_image_delete(img_on_dif);
3015 cpl_image_delete(img_of_dif);
3016 cpl_image_delete(img_on_sub);
3017 cpl_image_delete(img_of_sub);
3019 gain=((avg_on1+avg_on2)-(avg_of1+avg_of2))/
3020 ((sig_on_dif*sig_on_dif)-(sig_of_dif*sig_of_dif));
3022 cpl_table_set_double(res_tbl,
"gain",m,gain);
3023 cpl_table_set_double(res_tbl,
"adu",m,
3024 ((avg_on1+avg_on2)/2-(avg_of1+avg_of2)/2));
3035 cpl_image_delete(img_on1);
3036 cpl_image_delete(img_of1);
3047 cpl_vector_delete(dit_on);
3048 cpl_vector_delete(dit_of);
3049 cpl_vector_delete(exptime_on);
3050 cpl_vector_delete(exptime_of);
3075 sinfo_image_estimate_noise(cpl_image* img,
3076 const int noise_fit,
3090 double min_fct=HISTO_DIST_TEMPC_MIN_FCT;
3091 double max_fct=HISTO_DIST_TEMPC_MAX_FCT;
3112 cpl_table* data_tbl=NULL;
3113 cpl_table* histo=NULL;
3114 cpl_table* dist=NULL;
3115 cpl_table* min_xi=NULL;
3116 cpl_table* tmp_tbl1=NULL;
3117 cpl_table* tmp_tbl2=NULL;
3118 cpl_vector* vx=NULL;
3119 cpl_vector* vy=NULL;
3120 cpl_vector* sx=NULL;
3121 cpl_vector* sy=NULL;
3124 check_nomsg(xsz=cpl_image_get_size_x(img));
3125 check_nomsg(ysz=cpl_image_get_size_y(img));
3128 check_nomsg(data_tbl=cpl_table_new(n));
3129 check_nomsg(cpl_table_new_column(data_tbl,
"DATA",CPL_TYPE_DOUBLE));
3131 check_nomsg(pdata=cpl_image_get_data(img));
3133 if(!isnan(pdata[i])) {
3134 cpl_table_set_double(data_tbl,
"DATA",r,pdata[i]);
3139 check_nomsg(cpl_table_erase_invalid(data_tbl));
3140 check_nomsg(avg_d=cpl_table_get_column_mean(data_tbl,
"DATA"));
3141 check_nomsg(std_d=cpl_table_get_column_stdev(data_tbl,
"DATA"));
3143 cpl_table_save(data_tbl, NULL, NULL,
"out_data.fits", CPL_IO_DEFAULT);
3145 hmin=avg_d-kappa*std_d;
3146 hmax=avg_d+kappa*std_d;
3150 ck0(sinfo_histogram(data_tbl,nbins,hmin,hmax,&histo),
"building histogram");
3156 check_nomsg(peak=cpl_table_get_column_max(histo,
"HY"));
3158 sinfo_free_table(&tmp_tbl1);
3160 check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,
"HY",CPL_EQUAL_TO,peak));
3165 check_nomsg(*centre=cpl_table_get_column_mean(tmp_tbl1,
"HL"));
3168 sinfo_free_table(&tmp_tbl1);
3169 check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,
"HY",
3172 sinfo_free_table(&tmp_tbl2);
3173 check_nomsg(tmp_tbl2=sinfo_extract_table_rows(tmp_tbl1,
"HY",
3174 CPL_LESS_THAN,peak));
3175 sinfo_free_table(&tmp_tbl1);
3177 check_nomsg(tempc=*centre-cpl_table_get_column_min(tmp_tbl2,
"HL"));
3179 sinfo_free_table(&tmp_tbl2);
3181 check_nomsg(dist=sinfo_where_tab_min_max(histo,
"HL",
3183 *centre-min_fct*tempc,
3184 CPL_NOT_GREATER_THAN,
3185 *centre+max_fct*tempc));
3187 offset=cpl_table_get_column_min(histo,
"HY");
3188 sinfo_free_table(&histo);
3191 check_nomsg(ndist=cpl_table_get_nrow(dist));
3192 check_nomsg(cpl_table_cast_column(dist,
"HY",
"HYdouble",CPL_TYPE_DOUBLE));
3193 check_nomsg(disth=cpl_table_get_data_double(dist,
"HYdouble"));
3194 check_nomsg(distx=cpl_table_get_data_double(dist,
"HL"));
3195 cpl_table_save(dist, NULL, NULL,
"out_dist.fits", CPL_IO_DEFAULT);
3204 if(noise_fit == 1) {
3205 check_nomsg(vy=cpl_vector_wrap(ndist,disth));
3206 check_nomsg(vx=cpl_vector_wrap(ndist,distx));
3207 check_nomsg(sx=cpl_vector_new(ndist));
3208 check_nomsg(cpl_vector_fill(sx,1.));
3209 check_nomsg(sy=cpl_vector_duplicate(sx));
3213 if(CPL_ERROR_NONE != cpl_vector_fit_gaussian(vx,NULL,
3216 &x0,&sigma,&area,&offset,
3226 sinfo_unwrap_vector(&vx);
3227 sinfo_unwrap_vector(&vy);
3228 sinfo_free_my_vector(&sx);
3229 sinfo_free_my_vector(&sy);
3231 sinfo_free_table(&dist);
3236 sinfo_free_table(&min_xi);
3237 sinfo_free_table(&tmp_tbl1);
3238 sinfo_free_table(&tmp_tbl2);
3239 sinfo_free_table(&histo);
3240 sinfo_free_table(&dist);
3241 sinfo_free_table(&data_tbl);
3242 sinfo_free_my_vector(&sx);
3243 sinfo_free_my_vector(&sy);
3244 sinfo_unwrap_vector(&vx);
3245 sinfo_unwrap_vector(&vy);
3255 cpl_table* sinfo_compute_linearity(cpl_frameset* son, cpl_frameset* sof)
3258 cpl_frame* frm=NULL;
3276 cpl_image* img=NULL;
3277 cpl_vector* vec_adl=NULL;
3278 cpl_vector* vec_dit=NULL;
3279 cpl_vector* vec_avg=NULL;
3280 cpl_vector* vec_med=NULL;
3281 cpl_vector* vec_avg_dit=NULL;
3282 cpl_vector* vec_med_dit=NULL;
3283 cpl_propertylist* plist=NULL;
3286 cpl_table* lin_tbl=NULL;
3289 non = cpl_frameset_get_size(son);
3290 nof = cpl_frameset_get_size(sof);
3291 nfr = (non <= nof) ? non : nof;
3293 lin_tbl=cpl_table_new(nfr);
3294 cpl_table_new_column(lin_tbl,
"med", CPL_TYPE_DOUBLE);
3295 cpl_table_new_column(lin_tbl,
"avg", CPL_TYPE_DOUBLE);
3296 cpl_table_new_column(lin_tbl,
"med_dit", CPL_TYPE_DOUBLE);
3297 cpl_table_new_column(lin_tbl,
"avg_dit", CPL_TYPE_DOUBLE);
3298 cpl_table_new_column(lin_tbl,
"dit", CPL_TYPE_DOUBLE);
3299 vec_med=cpl_vector_new(nfr);
3300 vec_avg=cpl_vector_new(nfr);
3301 vec_med_dit=cpl_vector_new(nfr);
3302 vec_avg_dit=cpl_vector_new(nfr);
3303 vec_dit=cpl_vector_new(nfr);
3304 vec_adl=cpl_vector_new(nfr);
3306 for(i=0;i<nfr;i++) {
3307 frm=cpl_frameset_get_frame(son,i);
3308 name=(
char*)cpl_frame_get_filename(frm);
3309 img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
3310 med_on=cpl_image_get_median(img);
3311 avg_on=cpl_image_get_mean(img);
3312 cpl_image_delete(img);
3314 frm=cpl_frameset_get_frame(sof,i);
3315 name=(
char*)cpl_frame_get_filename(frm);
3316 img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
3317 med_of=cpl_image_get_median(img);
3318 avg_of=cpl_image_get_mean(img);
3319 cpl_image_delete(img);
3323 plist=cpl_propertylist_load(name,0);
3324 dit=(double)sinfo_pfits_get_dit(plist);
3325 cpl_propertylist_delete(plist);
3329 cpl_vector_set(vec_dit,i,dit);
3330 cpl_vector_set(vec_avg,i,avg);
3331 cpl_vector_set(vec_med,i,med);
3332 cpl_vector_set(vec_avg_dit,i,avg_dit);
3333 cpl_vector_set(vec_med_dit,i,med_dit);
3335 cpl_table_set_double(lin_tbl,
"dit",i,dit);
3336 cpl_table_set_double(lin_tbl,
"med",i,med);
3337 cpl_table_set_double(lin_tbl,
"avg",i,avg);
3338 cpl_table_set_double(lin_tbl,
"med_dit",i,med_dit);
3339 cpl_table_set_double(lin_tbl,
"avg_dit",i,avg_dit);
3342 cpl_table_new_column(lin_tbl,
"adl", CPL_TYPE_DOUBLE);
3343 med_dit=cpl_vector_get_mean(vec_med_dit);
3344 avg_dit=cpl_vector_get_mean(vec_avg_dit);
3346 for(i=0;i<nfr;i++) {
3347 dit = cpl_table_get_double(lin_tbl,
"dit",i,status);
3348 cpl_vector_set(vec_adl,i,dit*med_dit);
3349 cpl_table_set_double(lin_tbl,
"adl",i,dit*med_dit);
3352 cpl_vector_delete(vec_dit);
3353 cpl_vector_delete(vec_adl);
3354 cpl_vector_delete(vec_avg);
3355 cpl_vector_delete(vec_med);
3356 cpl_vector_delete(vec_avg_dit);
3357 cpl_vector_delete(vec_med_dit);
3373 sinfo_get_ron(cpl_frameset * framelist,
3378 const int ron_hsize,
3379 const int ron_nsamp,
3382 cpl_imagelist * iset =NULL;
3383 cpl_image * tmp_im =NULL;
3387 cpl_frame * frame =NULL;
3389 cpl_propertylist* plist=NULL;
3393 if (framelist == NULL)
return -1 ;
3396 if ((iset = sinfo_new_frameset_to_iset(framelist)) == NULL) {
3408 for (i=0 ; i<cpl_imagelist_get_size(iset)-1 ; i++) {
3411 if ((tmp_im=cpl_image_subtract_create(cpl_imagelist_get(iset,i),
3412 cpl_imagelist_get(iset, i+1)))
3415 sinfo_free_imagelist(&iset) ;
3420 if (cpl_flux_get_noise_window(tmp_im, zone, ron_hsize,
3421 ron_nsamp, &rms, NULL) != CPL_ERROR_NONE) {
3423 sinfo_free_image(&tmp_im) ;
3424 sinfo_free_imagelist(&iset) ;
3427 sinfo_free_image(&tmp_im) ;
3429 frame = cpl_frameset_get_frame(framelist, i) ;
3430 cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(frame),
3432 ndit=sinfo_pfits_get_ndit(plist);
3433 sinfo_free_propertylist(&plist);
3435 (*ron)[i] = rms * sqrt(ndit/2.0) ;
3440 sinfo_free_imagelist(&iset) ;
3444 sinfo_free_image(&tmp_im);
3445 sinfo_free_imagelist(&iset);
3446 sinfo_free_propertylist(&plist);
3460 int sinfo_stack_get_pro_tag(
char * tag_in,
char* tag_out)
3463 if (tag_in == NULL)
return -1 ;
3465 if (strcmp(tag_in,RAW_WAVE_LAMP_DITHER) == 0 ) {
3466 strcpy(tag_out,PRO_WAVE_LAMP_STACKED);
3471 if (strcmp(tag_in,RAW_WAVE_LAMP) == 0 ) {
3472 strcpy(tag_out,PRO_WAVE_LAMP_STACKED);
3476 if (strcmp(tag_in,RAW_WAVE_NS_DITHER) == 0 ) {
3477 strcpy(tag_out,PRO_WAVE_NS_STACKED);
3482 if (strcmp(tag_in,RAW_WAVE_NS) == 0 ) {
3483 strcpy(tag_out,PRO_WAVE_NS_STACKED);
3488 if (strcmp(tag_in,RAW_FIBRE_LAMP) == 0 ) {
3489 strcpy(tag_out,PRO_FIBRE_LAMP_STACKED);
3493 if (strcmp(tag_in,RAW_FIBRE_EW) == 0 ) {
3494 strcpy(tag_out,PRO_FIBRE_EW_STACKED);
3498 if (strcmp(tag_in,RAW_FIBRE_NS) == 0 ) {
3499 strcpy(tag_out,PRO_FIBRE_NS_STACKED);
3504 if (strcmp(tag_in,PRO_FIBRE_NS_STACKED_ON) == 0 ) {
3505 strcpy(tag_out,PRO_FIBRE_NS_STACKED);
3509 if (strcmp(tag_in,PRO_FIBRE_NS_STACKED) == 0 ) {
3510 strcpy(tag_out,PRO_FIBRE_NS_STACKED_DIST);
3515 if (strcmp(tag_in,RAW_SLIT_LAMP) == 0 ) {
3516 strcpy(tag_out,PRO_SLIT_LAMP_STACKED);
3521 if (strstr(tag_in,
"FLUX") != NULL ) {
3522 strcpy(tag_out,PRO_FLUX_LAMP_STACKED);
3526 if (strstr(tag_in,
"PSF") != NULL ) {
3527 strcpy(tag_out,PRO_PSF_CALIBRATOR_STACKED);
3532 if (strstr(tag_in,
"FOCUS") != NULL ) {
3533 strcpy(tag_out,PRO_FOCUS_STACKED);
3537 if (strstr(tag_in,
"OBJECT_NODDING") != NULL ) {
3538 strcpy(tag_out,PRO_OBJECT_NODDING_STACKED);
3542 if (strstr(tag_in,
"SKY_NODDING") != NULL ) {
3543 strcpy(tag_out,PRO_SKY_NODDING_STACKED);
3547 if (strstr(tag_in,
"STD_NODDING") != NULL ) {
3548 strcpy(tag_out,PRO_STD_NODDING_STACKED);
3552 if (strstr(tag_in,
"OBJECT_SKYSPIDER") != NULL ) {
3553 strcpy(tag_out,PRO_OBJECT_SKYSPIDER_STACKED);
3558 if (strstr(tag_in, RAW_STD) != NULL ) {
3559 strcpy(tag_out,PRO_STD_STACKED);
3564 if (strstr(tag_in, RAW_SKY_STD) != NULL ) {
3565 strcpy(tag_out,PRO_SKY_STD_STACKED);
3569 if (strstr(tag_in, RAW_SKY_OH) != NULL ) {
3570 strcpy(tag_out,PRO_SKY_OH_STACKED);
3574 if (strstr(tag_in, RAW_SKY_PSF_CALIBRATOR) != NULL ) {
3575 strcpy(tag_out,PRO_SKY_PSF_CALIBRATOR_STACKED);
3579 if (strstr(tag_in, RAW_STD_STAR) != NULL ) {
3580 strcpy(tag_out,PRO_STD_STAR_STACKED);
3584 if (strstr(tag_in, RAW_STD_STAR) != NULL ) {
3585 strcpy(tag_out,PRO_STD_STAR_DITHER_STACKED);
3589 if (strstr(tag_in, RAW_SKY) != NULL ) {
3590 strcpy(tag_out,PRO_SKY_STACKED);
3599 int sinfo_is_dark(
char * tag)
3602 if (tag == NULL)
return -1 ;
3604 if (!strcmp(tag, RAW_DARK))
return 1 ;
3605 if (!strcmp(tag, PRO_MASTER_DARK))
return 1 ;
3609 int sinfo_is_flat_bp(
char * tag)
3612 if (tag == NULL)
return -1 ;
3614 if (!strcmp(tag, RAW_LINEARITY_LAMP))
return 1 ;
3618 int sinfo_is_flat_lindet(
char * tag)
3621 if (tag == NULL)
return -1 ;
3623 if (!strcmp(tag, RAW_LINEARITY_LAMP))
return 1 ;
3628 int sinfo_blank2dot(
const char * in,
char* ou)
3645 int sinfo_is_sky_flat(
char * tag)
3648 if (tag == NULL)
return -1 ;
3649 if (!strcmp(tag, RAW_FLAT_SKY))
return 1 ;
3655 int sinfo_is_master_flat(
char * tag)
3658 if (tag == NULL)
return -1 ;
3660 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP))
return 1 ;
3661 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP1))
return 1 ;
3665 int sinfo_is_master_flat_dither(
char * tag)
3668 if (tag == NULL)
return -1 ;
3670 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP2))
return 1 ;
3681 int sinfo_is_stack(
char * tag)
3684 if (tag == NULL)
return -1 ;
3686 if (strstr(tag, PRO_STACKED) != NULL)
return 1 ;
3690 int sinfo_is_mflat(
char * tag)
3693 if (tag == NULL)
return -1 ;
3695 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP))
return 1 ;
3696 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP1))
return 1 ;
3697 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP2))
return 1 ;
3709 int sinfo_is_psf_calibrator_stacked(
char * tag)
3712 if (tag == NULL)
return -1 ;
3714 if (!strcmp(tag, PRO_PSF_CALIBRATOR_STACKED))
return 1 ;
3724 int sinfo_is_focus_stacked(
char * tag)
3727 if (tag == NULL)
return -1 ;
3729 if (!strcmp(tag, PRO_FOCUS_STACKED))
return 1 ;
3740 int sinfo_is_lamp_wave_stacked(
char * tag)
3743 if (tag == NULL)
return -1 ;
3745 if (!strcmp(tag, PRO_WAVE_LAMP_STACKED))
return 1 ;
3756 int sinfo_is_lamp_flux_stacked(
char * tag)
3759 if (tag == NULL)
return -1 ;
3761 if (!strcmp(tag, PRO_FLUX_LAMP_STACKED))
return 1 ;
3772 int sinfo_is_object_nodding_stacked(
char * tag)
3775 if (tag == NULL)
return -1 ;
3777 if (!strcmp(tag, PRO_OBJECT_NODDING_STACKED))
return 1 ;
3788 int sinfo_is_object_skyspider_stacked(
char * tag)
3791 if (tag == NULL)
return -1 ;
3793 if (!strcmp(tag, PRO_OBJECT_SKYSPIDER_STACKED))
return 1 ;
3805 int sinfo_is_sky_nodding_stacked(
char * tag)
3808 if (tag == NULL)
return -1 ;
3810 if (!strcmp(tag, PRO_SKY_NODDING_STACKED))
return 1 ;
3821 int sinfo_is_wavemap(
char * tag)
3824 if (tag == NULL)
return -1 ;
3826 if (!strcmp(tag, PRO_WAVE_MAP))
return 1 ;
3837 int sinfo_is_halosp(
char * tag)
3840 if (tag == NULL)
return -1 ;
3842 if (!strcmp(tag, PRO_HALO_SPECT))
return 1 ;
3853 int sinfo_is_distlist(
char * tag)
3856 if (tag == NULL)
return -1 ;
3858 if (!strcmp(tag, PRO_SLITLETS_DISTANCE))
return 1 ;
3869 int sinfo_is_slitpos(
char * tag)
3872 if (tag == NULL)
return -1 ;
3874 if (!strcmp(tag, PRO_SLIT_POS))
return 1 ;
3885 int sinfo_is_firstcol(
char * tag)
3888 if (tag == NULL)
return -1 ;
3890 if (!strcmp(tag, PRO_FIRST_COL))
return 1 ;
3901 int sinfo_is_bpmap(
char * tag)
3904 if (tag == NULL)
return -1 ;
3906 if (!strcmp(tag, PRO_BP_MAP))
return 1 ;
3922 int sinfo_get_band(cpl_frame * ref_frame,
char * band)
3925 char* ref_file=NULL;
3926 cpl_propertylist* plist=NULL;
3928 ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
3929 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
3931 cpl_propertylist_delete(plist) ;
3935 if (sinfo_propertylist_has(plist, KEY_NAME_FILT_NAME)) {
3936 strcpy(band, cpl_propertylist_get_string(plist, KEY_NAME_FILT_NAME));
3945 cpl_propertylist_delete(plist);
3962 int sinfo_get_obsname(cpl_frame * ref_frame,
const char* obs_name)
3965 char* ref_file=NULL;
3966 cpl_propertylist* plist=NULL;
3968 ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
3969 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
3971 cpl_propertylist_delete(plist) ;
3975 if (sinfo_propertylist_has(plist, KEY_NAME_OBS_NAME)) {
3976 strcpy((
char*)obs_name, cpl_propertylist_get_string(plist,
3977 KEY_NAME_OBS_NAME));
3986 cpl_propertylist_delete(plist);
4004 int sinfo_get_keyvalue_int(cpl_frame * ref_frame,
const char* key_name)
4007 char* ref_file=NULL;
4008 cpl_propertylist* plist=NULL;
4011 ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
4013 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
4015 cpl_propertylist_delete(plist) ;
4020 if (sinfo_propertylist_has(plist, key_name)) {
4021 result=cpl_propertylist_get_int(plist,key_name);
4028 cpl_propertylist_delete(plist);
4045 float sinfo_get_keyvalue_float(cpl_frame * ref_frame,
const char* key_name)
4048 char* ref_file=NULL;
4049 cpl_propertylist* plist=NULL;
4052 ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
4054 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
4056 cpl_propertylist_delete(plist) ;
4061 if (sinfo_propertylist_has(plist, key_name)) {
4062 result=cpl_propertylist_get_float(plist,key_name);
4069 cpl_propertylist_delete(plist);
4085 char sinfo_get_keyvalue_bool(cpl_frame * ref_frame,
const char* key_name)
4088 char* ref_file=NULL;
4089 cpl_propertylist* plist=NULL;
4092 ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
4094 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
4096 cpl_propertylist_delete(plist) ;
4101 if (sinfo_propertylist_has(plist, key_name)) {
4102 res_val=cpl_propertylist_get_bool(plist,key_name);
4109 cpl_propertylist_delete(plist);
4131 sinfo_get_keyvalue_string(cpl_frame * ref_frame,
const char* key_name)
4134 char* ref_file=NULL;
4135 cpl_propertylist* plist=NULL;
4136 const char* result=NULL;
4138 ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
4140 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
4142 cpl_propertylist_delete(plist) ;
4147 if (sinfo_propertylist_has(plist, key_name)) {
4148 result=cpl_propertylist_get_string(plist,key_name);
4155 cpl_propertylist_delete(plist);
4162 double sinfo_get_mjd_obs(cpl_frame * frame)
4164 cpl_propertylist* plist=NULL;
4165 const char* file=NULL;
4168 file = cpl_frame_get_filename(frame) ;
4170 if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
4172 sinfo_free_propertylist(&plist) ;
4176 if (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
4177 mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
4180 sinfo_free_propertylist(&plist) ;
4183 sinfo_free_propertylist(&plist) ;
4192 double sinfo_get_cumoffsetx(cpl_frame * frame)
4194 cpl_propertylist* plist=NULL;
4198 file = cpl_strdup( cpl_frame_get_filename(frame)) ;
4200 if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
4202 cpl_propertylist_delete(plist) ;
4207 if (sinfo_propertylist_has(plist, KEY_NAME_CUMOFFX)) {
4208 result=cpl_propertylist_get_double(plist, KEY_NAME_CUMOFFX);
4211 cpl_propertylist_delete(plist) ;
4214 cpl_propertylist_delete(plist) ;
4224 double sinfo_get_cumoffsety(cpl_frame * frame)
4226 cpl_propertylist* plist=NULL;
4230 file = cpl_strdup( cpl_frame_get_filename(frame)) ;
4232 if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
4234 cpl_propertylist_delete(plist) ;
4239 if (sinfo_propertylist_has(plist, KEY_NAME_CUMOFFY)) {
4240 result=cpl_propertylist_get_double(plist, KEY_NAME_CUMOFFY);
4243 cpl_propertylist_delete(plist) ;
4246 cpl_propertylist_delete(plist) ;
4253 int sinfo_frame_is_dither(cpl_frame * frame)
4257 char band[FILE_NAME_SZ];
4260 cpl_propertylist* plist=NULL;
4266 cknull(frame,
"Null input frame. Exit!");
4268 cknull_nomsg(strcpy(file,cpl_frame_get_filename(frame)));
4271 if(len<1)
goto cleanup;
4272 if(sinfo_file_exists(file)==0)
goto cleanup;
4274 cknull(plist = cpl_propertylist_load(file, 0),
4275 "getting header from reference frame %s",file);
4277 if (sinfo_propertylist_has(plist, KEY_NAME_FILT_NAME)) {
4278 strcpy(band,cpl_propertylist_get_string(plist, KEY_NAME_FILT_NAME));
4281 sinfo_free_propertylist(&plist) ;
4285 if (sinfo_propertylist_has(plist, KEY_NAME_GRAT_ENC)) {
4286 grat_encoder = cpl_propertylist_get_int(plist, KEY_NAME_GRAT_ENC);
4289 sinfo_free_propertylist(&plist) ;
4293 sinfo_free_propertylist(&plist) ;
4295 if (strcmp(band,
"H") == 0) {
4296 if( abs(grat_encoder - GRAT_VAL2_H) <= GRAT_VAL_TOL ) {
4302 else if (strcmp(band,
"H+K") == 0) {
4303 if( abs(grat_encoder - GRAT_VAL2_HK) <= GRAT_VAL_TOL ) {
4309 else if (strcmp(band,
"K") == 0) {
4310 if( abs(grat_encoder - GRAT_VAL2_K) <= GRAT_VAL_TOL ) {
4316 else if (strcmp(band,
"J") == 0) {
4317 if( abs(grat_encoder - GRAT_VAL2_J) <= GRAT_VAL_TOL ) {
4325 sinfo_free_propertylist(&plist) ;
4326 if(cpl_error_get_code() != CPL_ERROR_NONE) {
4344 int sinfo_get_spatial_res(cpl_frame * ref_frame,
char * spat_res)
4347 const char* ref_file;
4348 cpl_propertylist* plist=NULL;
4350 ref_file=cpl_frame_get_filename(ref_frame) ;
4351 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
4353 sinfo_free_propertylist(&plist) ;
4358 if (sinfo_propertylist_has(plist, KEY_NAME_PREOPTICS)) {
4359 strcpy(spat_res,cpl_propertylist_get_string(plist, KEY_NAME_PREOPTICS));
4363 sinfo_free_propertylist(&plist);
4366 sinfo_free_propertylist(&plist);
4381 int sinfo_frame_is_sky(cpl_frame * ref_frame)
4384 char dpr_type[FILE_NAME_SZ];
4385 char* ref_file=NULL;
4386 const char* sval=NULL;
4389 cpl_propertylist* plist=NULL;
4391 sval = cpl_frame_get_filename(ref_frame) ;
4392 ref_file = cpl_strdup(sval) ;
4394 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
4396 cpl_propertylist_delete(plist) ;
4401 if (sinfo_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
4402 strcpy(dpr_type,cpl_propertylist_get_string(plist, KEY_NAME_DPR_TYPE));
4406 cpl_propertylist_delete(plist) ;
4410 cpl_propertylist_delete(plist);
4411 if(strstr(dpr_type,RAW_SKY) != NULL) {
4431 int sinfo_tag_is_sky(
char * tag)
4437 (strcmp(tag,RAW_SKY) == 0) ||
4438 (strcmp(tag,RAW_IMAGE_PRE_SKY) == 0) ||
4439 (strcmp(tag,RAW_SKY_NODDING) == 0) ||
4440 (strcmp(tag,RAW_SKY_JITTER) == 0) ||
4441 (strcmp(tag,RAW_SKY_STD) == 0) ||
4442 (strcmp(tag,RAW_FIBRE_DARK) == 0) ||
4443 (strcmp(tag,RAW_SKY_OH) == 0) ||
4444 (strcmp(tag,RAW_SKY_PSF_CALIBRATOR) == 0)
4464 int sinfo_tag_is_obj(
char * tag)
4470 (strcmp(tag,RAW_PUPIL_LAMP) == 0) ||
4471 (strcmp(tag,RAW_OBJECT) == 0) ||
4472 (strcmp(tag,RAW_IMAGE_PRE_OBJECT) == 0) ||
4473 (strcmp(tag,RAW_OBJECT_NODDING) == 0) ||
4474 (strcmp(tag,RAW_OBJECT_JITTER) == 0) ||
4475 (strcmp(tag,RAW_PSF_CALIBRATOR) == 0) ||
4476 (strcmp(tag,RAW_FIBRE_PSF) == 0) ||
4477 (strcmp(tag,RAW_STD) == 0) ||
4478 (strcmp(tag,RAW_STD_STAR) == 0)
4498 int sinfo_tag_is_objpro(
char * tag)
4504 (strcmp(tag,PRO_COADD_OBJ) == 0) ||
4505 (strcmp(tag,PRO_COADD_PSF) == 0) ||
4506 (strcmp(tag,PRO_COADD_STD) == 0) ||
4507 (strcmp(tag,PRO_OBS_OBJ) == 0) ||
4508 (strcmp(tag,PRO_OBS_PSF) == 0) ||
4509 (strcmp(tag,PRO_OBS_STD) == 0) ||
4510 (strcmp(tag,PRO_PSF_CALIBRATOR_STACKED) == 0) ||
4511 (strcmp(tag,PRO_SKY_PSF_CALIBRATOR_STACKED) == 0) ||
4512 (strcmp(tag,PRO_STD_STACKED) == 0) ||
4513 (strcmp(tag,PRO_SKY_STD_STACKED) == 0) ||
4514 (strcmp(tag,PRO_OBJECT_NODDING_STACKED) == 0) ||
4515 (strcmp(tag,PRO_SKY_NODDING_STACKED) == 0)
4535 int sinfo_frame_is_on(cpl_frame * ref_frame)
4538 char ref_file[FILE_NAME_SZ];
4539 char dpr_type[FILE_NAME_SZ];
4547 cpl_propertylist* plist=NULL;
4548 const char* filename=NULL;
4549 cknull(ref_frame,
"Null input frame. Exit!");
4551 cknull_nomsg(filename=cpl_frame_get_filename(ref_frame));
4552 len= strlen(filename);
4553 if(len<1)
goto cleanup;
4555 check_nomsg(strcpy(ref_file, filename)) ;
4556 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file,0)) == NULL)) {
4558 sinfo_free_propertylist(&plist) ;
4568 if (sinfo_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
4569 strcpy(dpr_type,cpl_propertylist_get_string(plist, KEY_NAME_DPR_TYPE));
4573 sinfo_free_propertylist(&plist);
4583 if(strstr(dpr_type,
"STD") != NULL) {
4585 sinfo_free_propertylist(&plist);
4589 if(strstr(dpr_type,
"PSF") != NULL) {
4591 sinfo_free_propertylist(&plist);
4595 if(strstr(dpr_type,
"SKY") != NULL) {
4597 sinfo_free_propertylist(&plist);
4602 if(strstr(dpr_type,
"OBJECT") != NULL) {
4604 sinfo_free_propertylist(&plist);
4615 if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_XE)) {
4616 lamp_Xe=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_XE);
4620 sinfo_free_propertylist(&plist);
4624 if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_KR)) {
4625 lamp_Kr=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_KR);
4629 sinfo_free_propertylist(&plist);
4633 if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_NE)) {
4634 lamp_Ne=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_NE);
4638 sinfo_free_propertylist(&plist);
4642 if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_AR)) {
4643 lamp_Ar=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_AR);
4647 sinfo_free_propertylist(&plist);
4651 if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
4652 lamp_Halo=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_HALO);
4656 sinfo_free_propertylist(&plist);
4685 sinfo_free_propertylist(&plist);
4694 sinfo_pfits_add_qc(cpl_propertylist * plist,
4698 char key_value[80] ;
4703 if (plist == NULL)
return -1 ;
4707 for(i=0;i<qclog[0].n;i++) {
4708 strcpy(key_name,
"ESO ");
4709 strcat(key_name,qclog[i].name);
4710 if(strcmp(qclog[i].type,
"string") == 0) {
4711 snprintf(key_value,
sizeof(key_value)-1,
"%s",qclog[i].s_val);
4712 cpl_propertylist_append_string(plist, key_name,key_value) ;
4713 cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
4715 }
else if(strcmp(qclog[i].type,
"bool") == 0) {
4716 snprintf(key_value,
sizeof(key_value),
"%i",(
int)qclog[i].n_val);
4717 cpl_propertylist_append_bool(plist, key_name,(
int)qclog[i].n_val) ;
4718 cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
4719 }
else if(strcmp(qclog[i].type,
"int") == 0) {
4720 snprintf(key_value,
sizeof(key_value),
"%i",(
int)qclog[i].n_val);
4721 cpl_propertylist_append_int(plist, key_name,(
int)qclog[i].n_val) ;
4722 cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
4723 }
else if(strcmp(qclog[i].type,
"float") == 0) {
4724 snprintf(key_value,
sizeof(key_value),
"%f",(
float)qclog[i].n_val);
4725 cpl_propertylist_append_float(plist, key_name,(
float)qclog[i].n_val) ;
4726 cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
4727 }
else if(strcmp(qclog[i].type,
"double") == 0) {
4728 snprintf(key_value,
sizeof(key_value),
"%f",qclog[i].n_val);
4729 cpl_propertylist_append_double(plist, key_name,qclog[i].n_val) ;
4730 cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;