34#include "irplib_wcs.h"
36#include "cr2res_utils.h"
38#include "cr2res_pfits.h"
39#include "cr2res_dfs.h"
40#include "cr2res_extract.h"
41#include "cr2res_trace.h"
49#define max(a,b) (((a)>(b))?(a):(b))
61 int hours, minutes, seconds, day, month, year;
66 struct tm *local = localtime(&now);
67 hours = local->tm_hour;
68 minutes = local->tm_min;
69 seconds = local->tm_sec;
71 month = local->tm_mon + 1;
72 year = local->tm_year + 1900;
75 irplib_wcs_mjd_from_iso8601(&mjd_obs, year, month, day, hours,
91 return order_zp + order_idx - 1;
104 return order_real - order_zp + 1;
141 return ((
double)ss/60.0 + (
double)mm)/60.0 + dd;
157 if (setting_id == NULL)
return -1 ;
159 len = strlen(setting_id) ;
160 for (i=0 ; i<len ; i++)
if (setting_id[i] ==
'/') setting_id[i] =
'_' ;
174 if (setting_id == NULL)
return -1 ;
176 if (setting_id[0] ==
'H' || setting_id[0] ==
'J' ||
177 setting_id[0] ==
'K' || setting_id[0] ==
'Y')
195 if (setting_id == NULL)
return -1 ;
197 len = strlen(setting_id) ;
198 for (i=0 ; i<len ; i++)
if (setting_id[i] ==
'_') setting_id[i] =
'/' ;
216 img = cpl_image_wrap_double(1,cpl_vector_get_size(invec),
217 cpl_vector_get_data(invec));
218 median = cpl_image_get_mad(img, mad);
219 cpl_image_unwrap(img);
231 const cpl_vector * ycen)
236 if (ycen == NULL)
return NULL;
238 lenx = cpl_vector_get_size(ycen);
239 ycen_int = cpl_malloc(lenx*
sizeof(
int));
240 for (i=0 ; i<lenx ; i++){
241 ycen_int[i] = (int)cpl_vector_get(ycen,i);
254 const cpl_vector * ycen)
259 if (ycen == NULL)
return NULL;
261 lenx = cpl_vector_get_size(ycen);
262 ycen_rest = cpl_malloc(lenx*
sizeof(
double));
263 for (i=0 ; i<lenx ; i++){
264 ycen_rest[i] = fmod( cpl_vector_get(ycen,i), 1.0) ;
279 const cpl_table * extracta,
280 const cpl_table * extractb)
282 cpl_table * extractc ;
283 cpl_array * col_names ;
286 hdrl_spectrum1D_wave_scale scale ;
287 hdrl_spectrum1D * a_spec ;
288 hdrl_spectrum1D * b_spec ;
289 hdrl_spectrum1D * c_spec ;
290 hdrl_spectrum1D_wavelength spec_wav ;
291 hdrl_parameter * params ;
294 cpl_size ncols, i, j, sz, sz_a, sz_b ;
295 int trace_nb, order, increasing_values ;
298 if (extracta == NULL || extractb == NULL)
return NULL ;
301 scale = hdrl_spectrum1D_wave_scale_linear;
302 extractc = cpl_table_duplicate(extracta) ;
305 col_names = cpl_table_get_column_names(extractc);
306 ncols = cpl_table_get_ncol(extractc) ;
309 for (i=0 ; i<ncols ; i++) {
311 const char * col_name ;
313 col_name = cpl_array_get_string(col_names, i);
316 if (col_type != NULL && !strcmp(col_type, CR2RES_COL_SPEC_SUFFIX)) {
325 col_name, wave_col, err_col, NULL, scale);
329 col_name, wave_col, err_col, NULL, scale);
332 if (a_spec == NULL || b_spec == NULL) {
333 cpl_msg_error(__func__,
"Cannot create HDRL spectra - abort") ;
337 cpl_array_delete(col_names) ;
338 cpl_table_delete(extractc) ;
345 cpl_msg_error(__func__,
346 "a and b spectra have diff. sizes - abort") ;
352 cpl_array_delete(col_names) ;
353 cpl_table_delete(extractc) ;
358 increasing_values = 1 ;
359 for (j=1 ; j<sz_a ; j++) {
368 if (vala1 >= vala2 || valb1 >=valb2) {
369 increasing_values = 0 ;
373 if (increasing_values == 0) {
374 cpl_msg_warning(__func__,
375 "Column %s - Values should increase - abort",
381 if (col_type != NULL) cpl_free(col_type) ;
383 p_flux = cpl_table_get_data_double(extractc, col_name) ;
384 sz = cpl_table_get_nrow(extractc) ;
385 for (j = 0; j < sz; j++) p_flux[j]= 0.0;
392 hdrl_spectrum1D_interp_akima);
398 if (c_spec == NULL) {
399 cpl_msg_error(__func__,
"Cannot resample HDRL spectra - abort") ;
402 if (col_type != NULL) cpl_free(col_type) ;
403 cpl_array_delete(col_names) ;
405 cpl_table_delete(extractc) ;
415 p_flux = cpl_table_get_data_double(extractc, col_name) ;
416 if ((p_err = cpl_table_get_data_double(extractc, err_col))
420 cpl_table_new_column(extractc, err_col, CPL_TYPE_DOUBLE);
421 p_err = cpl_table_get_data_double(extractc, err_col) ;
423 sz = cpl_table_get_nrow(extractc) ;
425 cpl_msg_error(__func__,
"Wrong size - abort") ;
429 if (col_type != NULL) cpl_free(col_type) ;
430 cpl_array_delete(col_names) ;
431 cpl_table_delete(extractc) ;
434 for (j = 0; j < sz; j++) {
442 if (col_type != NULL) cpl_free(col_type) ;
444 cpl_array_delete(col_names) ;
463 cpl_table * trace_wave,
468 if (img == NULL || trace_wave == NULL)
return NULL;
469 if (order_x < 0 || order_y < 0)
return NULL;
477 const cpl_array *lower;
478 const cpl_array *upper;
480 cpl_polynomial *poly_lower = NULL;
481 cpl_polynomial *poly_upper = NULL;
483 int nb_order_idx_values;
485 &nb_order_idx_values);
486 int * porder_idx_values;
489 double y_lower, y_upper;
492 cpl_matrix *samppos = cpl_matrix_new(2, cpl_image_get_size_x(img) *
493 cpl_image_get_size_y(img));
494 cpl_vector *fitvals = cpl_vector_new(cpl_image_get_size_x(img) *
495 cpl_image_get_size_y(img));
496 cpl_vector *x = cpl_vector_new(1);
499 int pis_rejected = 0;
503 int nrows = cpl_table_get_nrow(trace_wave);
505 porder_idx_values = cpl_table_get_data_int(trace_wave, CR2RES_COL_ORDER);
506 ptraces = cpl_table_get_data_int(trace_wave, CR2RES_COL_TRACENB);
508 for(
int m = 0; m <= nb_order_idx_values; m++) {
510 if (m != nb_order_idx_values) order_idx = order_idx_values[m];
513 order_idx = order_idx_values[0];
514 for(
int t = 1; t < nb_order_idx_values; t++) {
515 if (order_idx_values[t] > order_idx)
516 order_idx = order_idx_values[t];
523 for (k=0 ; k<nrows ; k++) {
525 if (porder_idx_values[k] == order_idx-1 && ptraces[k] == trace2) {
527 lower = cpl_table_get_array(trace_wave, CR2RES_COL_UPPER, k);
532 for (k=0 ; k<nrows ; k++) {
533 if (porder_idx_values[k] == order_idx && ptraces[k] == trace1) {
535 upper = cpl_table_get_array(trace_wave,CR2RES_COL_LOWER, k);
542 if (poly_lower == NULL) {
543 poly_lower = cpl_polynomial_new(1);
544 cpl_polynomial_set_coeff(poly_lower, &power, 1);
547 if (poly_upper == NULL) {
548 poly_upper = cpl_polynomial_new(1);
549 cpl_polynomial_set_coeff(poly_upper, &power,
550 cpl_image_get_size_y(img));
555 for(cpl_size i = 1; i < cpl_image_get_size_x(img)-1; i++) {
556 cpl_vector_set(x, 0, (
double)i);
557 y_lower = cpl_polynomial_eval(poly_lower, x);
558 y_upper = cpl_polynomial_eval(poly_upper, x);
560 for(cpl_size j = y_lower; j < y_upper; j++) {
561 value = cpl_image_get(img, i, j, &pis_rejected);
562 if (pis_rejected == 0){
563 cpl_matrix_set(samppos, 0, c, (
double)i);
564 cpl_matrix_set(samppos, 1, c, (
double)j);
566 cpl_vector_set(fitvals, c, value);
571 cpl_polynomial_delete(poly_lower);
573 cpl_polynomial_delete(poly_upper);
578 cpl_matrix_set_size(samppos, 2, c);
579 cpl_vector_set_size(fitvals, c);
583 cpl_polynomial *fit = cpl_polynomial_new(2);
587 const cpl_boolean *sampsym = NULL;
590 const cpl_vector *fitsigm = NULL;
592 const cpl_boolean dimdeg = TRUE;
594 const cpl_size * mindeg = NULL;
596 const cpl_size maxdeg[] = {order_x, order_y};
598 cpl_error_code ec = cpl_polynomial_fit(fit, samppos, sampsym, fitvals,
599 fitsigm, dimdeg, mindeg, maxdeg);
601 cpl_free(order_idx_values);
602 cpl_matrix_delete(samppos);
603 cpl_vector_delete(fitvals);
604 cpl_vector_delete(x);
605 if (ec == CPL_ERROR_NONE)
return fit;
628 const cpl_table * trace_wave,
629 cpl_polynomial *** coef_slit,
630 cpl_polynomial *** coef_wave,
634 if (trace_wave == NULL || coef_slit == NULL ||
635 coef_wave == NULL || size == NULL)
return -1;
638 cpl_polynomial * wave;
639 cpl_polynomial * line[3];
640 const cpl_array * slit;
641 const cpl_array * curv_b;
642 const cpl_array * curv_c;
643 cpl_polynomial * curv_poly_b;
644 cpl_polynomial * curv_poly_c;
645 int * order_idx_values;
647 const cpl_size maxdeg = 2;
650 double px, py, pw, ps;
651 double pcb, pcc, pc_offset;
652 int nb_order_idx_values, nb_traces;
653 cpl_error_code errcode;
657 x = cpl_vector_new(CR2RES_DETECTOR_SIZE);
658 for (i = 0; i < CR2RES_DETECTOR_SIZE; i++)
659 cpl_vector_set(x, i, i+1);
662 &nb_order_idx_values);
665 *coef_wave = cpl_malloc(nb_order_idx_values *
sizeof(cpl_polynomial*));
666 *coef_slit = cpl_malloc(nb_order_idx_values *
sizeof(cpl_polynomial*));
667 for (i=0; i < nb_order_idx_values; i++) {
668 (*coef_wave)[i] = cpl_polynomial_new(2);
669 (*coef_slit)[i] = cpl_polynomial_new(2);
671 *size = nb_order_idx_values;
673 for (i = 0; i < nb_order_idx_values; i++) {
674 cpl_matrix *matrix_xy;
675 cpl_matrix *matrix_wd;
678 cpl_polynomial *poly;
682 order_idx = order_idx_values[i];
687 matrix_xy = cpl_matrix_new(2, CR2RES_DETECTOR_SIZE * nb_traces * 3);
688 matrix_wd = cpl_matrix_new(2, CR2RES_DETECTOR_SIZE * nb_traces * 3);
689 vec_w = cpl_vector_new(CR2RES_DETECTOR_SIZE * nb_traces * 3);
690 vec_s = cpl_vector_new(CR2RES_DETECTOR_SIZE * nb_traces * 3);
692 for (j = 0; j < nb_traces; j++) {
704 slit = cpl_table_get_array(trace_wave, CR2RES_COL_SLIT_FRACTION, k);
706 curv_b = cpl_table_get_array(trace_wave, CR2RES_COL_SLIT_CURV_B, k);
707 curv_c = cpl_table_get_array(trace_wave, CR2RES_COL_SLIT_CURV_C, k);
713 for (n = 0; n < CR2RES_DETECTOR_SIZE; n++) {
715 for (m = 0; m < 3; m++){
717 px = cpl_vector_get(x, n);
718 py = cpl_polynomial_eval_1d(line[m], px, NULL);
721 pcb = cpl_polynomial_eval_1d(curv_poly_b, px, NULL);
722 pcc = cpl_polynomial_eval_1d(curv_poly_c, px, NULL);
724 ycen = cpl_polynomial_eval_1d(line[1], px, NULL);
725 pcb += 2 * ycen * pcc;
726 pc_offset = (pcc*(py - ycen) + pcb) * (py - ycen);
727 cpl_msg_debug(__func__,
"pc_offset: %g %g %g %g %g",
728 pc_offset, pcb, pcc, ycen, py);
729 pw = cpl_polynomial_eval_1d(wave, px - pc_offset, NULL);
730 ps = cpl_array_get_double(slit, m, NULL);
732 cpl_matrix_set(matrix_xy, 0, row, px);
733 cpl_matrix_set(matrix_xy, 1, row, py);
734 cpl_matrix_set(matrix_wd, 0, row, pw);
735 cpl_matrix_set(matrix_wd, 1, row, py);
736 cpl_vector_set(vec_w, row, pw);
737 cpl_vector_set(vec_s, row, ps);
741 cpl_polynomial_delete(line[0]);
742 cpl_polynomial_delete(line[1]);
743 cpl_polynomial_delete(line[2]);
744 cpl_polynomial_delete(curv_poly_b);
745 cpl_polynomial_delete(curv_poly_c);
746 cpl_polynomial_delete(wave);
750 poly = (*coef_wave)[i];
751 errcode = cpl_polynomial_fit(poly, matrix_xy, NULL, vec_w,
752 NULL, FALSE, NULL, &maxdeg);
753 if (errcode != CPL_ERROR_NONE){
754 cpl_msg_error(__func__,
"Polynomial fit failed with error: %s", cpl_error_get_message());
756 for (i=0; i < nb_order_idx_values; i++) {
757 cpl_polynomial_delete((*coef_wave)[i]);
758 cpl_polynomial_delete((*coef_slit)[i]);
760 cpl_free(*coef_wave);
761 cpl_free(*coef_slit);
762 cpl_matrix_delete(matrix_xy);
763 cpl_matrix_delete(matrix_wd);
764 cpl_vector_delete(vec_s);
765 cpl_vector_delete(vec_w);
767 cpl_vector_delete(x);
768 cpl_free(order_idx_values);
775 poly = (*coef_slit)[i];
776 errcode = cpl_polynomial_fit(poly, matrix_wd, NULL, vec_s,
777 NULL, FALSE, NULL, &maxdeg);
778 if (errcode != CPL_ERROR_NONE){
779 cpl_msg_error(__func__,
"Polynomial fit failed with error: %s", cpl_error_get_message());
781 for (i=0; i < nb_order_idx_values; i++) {
782 cpl_polynomial_delete((*coef_wave)[i]);
783 cpl_polynomial_delete((*coef_slit)[i]);
785 cpl_free(*coef_wave);
786 cpl_free(*coef_slit);
787 cpl_matrix_delete(matrix_xy);
788 cpl_matrix_delete(matrix_wd);
789 cpl_vector_delete(vec_s);
790 cpl_vector_delete(vec_w);
792 cpl_vector_delete(x);
793 cpl_free(order_idx_values);
799 cpl_matrix_delete(matrix_xy);
800 cpl_matrix_delete(matrix_wd);
801 cpl_vector_delete(vec_s);
802 cpl_vector_delete(vec_w);
807 cpl_vector_delete(x);
808 cpl_free(order_idx_values);
811 if (cpl_error_get_code() != CPL_ERROR_NONE){
812 for (i=0; i < nb_order_idx_values; i++) {
813 cpl_polynomial_delete((*coef_wave)[i]);
814 cpl_polynomial_delete((*coef_slit)[i]);
816 cpl_free(*coef_wave);
817 cpl_free(*coef_slit);
821 cpl_msg_error(__func__,
"ERROR: %s", cpl_error_get_message());
842 const cpl_table * trace_wave,
843 cpl_image ** slitpos,
844 cpl_image ** wavelength)
846 if (trace_wave == NULL || slitpos == NULL || wavelength == NULL)
return -1;
849 int i, k, x, y, nb_order_idx_values;
852 cpl_polynomial ** coef_slit;
853 cpl_polynomial ** coef_wave;
855 if (
cr2res_slit_pos(trace_wave, &coef_slit, &coef_wave, &nb_order_idx_values)){
860 *slitpos = cpl_image_new(CR2RES_DETECTOR_SIZE, CR2RES_DETECTOR_SIZE,
862 *wavelength = cpl_image_new(CR2RES_DETECTOR_SIZE, CR2RES_DETECTOR_SIZE,
865 vec_xy = cpl_vector_new(2);
866 vec_wd = cpl_vector_new(2);
868 for (k = 0; k < nb_order_idx_values; k++) {
869 for (x=1; x <= CR2RES_DETECTOR_SIZE; x++) {
870 for (y=1; y <= CR2RES_DETECTOR_SIZE; y++) {
871 cpl_vector_set(vec_xy, 0, (
double)x);
872 cpl_vector_set(vec_xy, 1, (
double)y);
873 w = cpl_polynomial_eval(coef_wave[k], vec_xy);
875 cpl_vector_set(vec_wd, 0, w);
876 cpl_vector_set(vec_wd, 1, (
double)y);
877 s = cpl_polynomial_eval(coef_slit[k], vec_wd);
879 if ((s >= 0) && (s <= 1)) {
880 cpl_image_set(*slitpos, x, y, s);
881 cpl_image_set(*wavelength, x, y, w);
887 for (i=0; i < nb_order_idx_values; i++){
888 cpl_polynomial_delete(coef_wave[i]);
889 cpl_polynomial_delete(coef_slit[i]);
893 cpl_vector_delete(vec_wd);
894 cpl_vector_delete(vec_xy);
908 const cpl_image * img_in,
909 const cpl_vector * ycen,
918 int empty_bottom = 0;
920 if (img_in == NULL || ycen == NULL || height < 1)
return NULL;
922 imtyp = cpl_image_get_type(img_in);
923 lenx = cpl_image_get_size_x(img_in);
924 leny = cpl_image_get_size_y(img_in);
926 img_out = cpl_image_new(lenx, height, imtyp);
929 for (i = 1; i <= lenx; i++) {
933 ymin = ycen_int[i-1]-(height/2);
934 ymax = ycen_int[i-1]+(height/2) + height%2 ;
935 if ((ymax <= 1) || (ymin > leny)) {
938 for (j = 1; j <= height; j++){
939 cpl_image_set(img_out, i, j, NAN);
940 cpl_image_reject(img_out, i, j);
945 empty_bottom = 1 - ymin;
951 cpl_msg_error(__func__,
"Unreasonable borders in column %i",i);
953 cpl_image_delete(img_out);
958 img_1d = cpl_image_extract(img_in, i, ymin, i, ymax);
959 cpl_image_copy(img_out, img_1d, i, 1+empty_bottom);
960 if (cpl_error_get_code() != CPL_ERROR_NONE) {
961 cpl_msg_error(__func__,
962 "Cannot extract and copy column %d, %d %d %d, %s",
963 i, ymin, ymax, empty_bottom, cpl_error_get_where());
965 cpl_image_delete(img_out);
966 if (img_1d != NULL) cpl_image_delete(img_1d);
970 cpl_image_delete(img_1d);
985 const cpl_image * rect_in,
986 const cpl_vector * ycen,
990 cpl_size lenx, leny, height;
994 if (rect_in == NULL || ycen == NULL || img_out == NULL)
return -1;
996 lenx = cpl_image_get_size_x(img_out);
997 leny = cpl_image_get_size_y(img_out);
998 height = cpl_image_get_size_y(rect_in);
999 if (cpl_image_get_size_x(rect_in) != lenx) {
1000 cpl_msg_error(__func__,
"Length of rect and img need to be the same");
1006 for (i=1;i<=lenx;i++){
1011 ymin = ycen_int[i-1]-(height/2);
1012 ymax = ycen_int[i-1]+(height/2) + height%2 ;
1013 if ((ymax <= 1) || (ymin > leny)) {
1016 for (j = 1; j <= height; j++){
1017 cpl_image_set(img_out, i, j, NAN);
1018 cpl_image_reject(img_out, i, j);
1023 empty_bottom = 1 - ymin;
1029 cpl_msg_error(__func__,
"Unreasonable borders in column %i", i);
1034 img_1d = cpl_image_extract(rect_in, i, empty_bottom+1, i, height);
1035 cpl_image_copy(img_out, img_1d, i, ymin);
1036 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1037 cpl_msg_error(__func__,
"Cannot re-insert column %d, %d %d %d, %s",
1038 i, ymin, ymax, empty_bottom, cpl_error_get_where());
1041 if (img_1d != NULL) cpl_image_delete(img_1d);
1044 cpl_image_delete(img_1d);
1060 const cpl_polynomial * poly,
1061 const cpl_vector * vec)
1065 cpl_vector * outvec;
1067 if (poly == NULL || vec == NULL)
return NULL;
1069 nx = cpl_vector_get_size(vec);
1070 outvec = cpl_vector_new(nx);
1071 for (i=0; i<nx; i++){
1072 cpl_vector_set(outvec, i,
1073 cpl_polynomial_eval_1d(poly, cpl_vector_get(vec,i), NULL));
1090 const cpl_vector * invector,
1094 cpl_vector * smoothed;
1096 if (invector == NULL || smooth < 0)
return NULL;
1098 smoothed = cpl_vector_filter_median_create(invector, (smooth/2)+1);
1099 cpl_vector_subtract(smoothed, invector);
1100 cpl_vector_add_scalar(smoothed, thresh);
1101 cpl_vector_multiply_scalar(smoothed, -1.0);
1115 if (filename == NULL)
return NULL;
1117 p = strrchr (filename,
'/');
1118 return p ? p + 1 : (
char *) filename;
1130 static char path[4096+1];
1132 if (filename == NULL)
return NULL;
1134 if (strlen(filename)>4096)
return NULL ;
1135 memset(path, 0, 4096);
1136 strcpy(path, filename);
1137 lastdot = strrchr(path,
'.');
1138 if (lastdot == NULL)
return path ;
1139 if ((!strcmp(lastdot,
".fits")) || (!strcmp(lastdot,
".FITS")) ||
1140 (!strcmp(lastdot,
".dat")) || (!strcmp(lastdot,
".DAT")) ||
1141 (!strcmp(lastdot,
".paf")) || (!strcmp(lastdot,
".PAF")) ||
1142 (!strcmp(lastdot,
".txt")) || (!strcmp(lastdot,
".TXT")) ||
1143 (!strcmp(lastdot,
".ascii")) || (!strcmp(lastdot,
".ASCII")))
1145 lastdot[0] = (char)0;
1158const char * cr2res_extract_filename(
1159 const cpl_frameset * in,
1162 const cpl_frame * cur_frame ;
1165 if ((cur_frame = cpl_frameset_find_const(in, tag)) == NULL)
return NULL ;
1166 return cpl_frame_get_filename(cur_frame) ;
1180 const cpl_frameset * in,
1183 cpl_frameset * out ;
1184 cpl_frame * loc_frame ;
1189 if (in == NULL)
return NULL ;
1190 if (tag == NULL)
return NULL ;
1193 nbframes = cpl_frameset_get_size(in) ;
1196 if ((cpl_frameset_count_tags(in, tag)) == 0)
return NULL ;
1199 out = cpl_frameset_new() ;
1202 for (i=0 ; i<nbframes ; i++) {
1203 const cpl_frame * cur_frame ;
1204 cur_frame = cpl_frameset_get_position_const(in, i) ;
1205 if (!strcmp(cpl_frame_get_tag(cur_frame), tag)) {
1206 loc_frame = cpl_frame_duplicate(cur_frame) ;
1207 cpl_frameset_insert(out, loc_frame) ;
1225 const cpl_frameset * in,
1229 cpl_frameset * out ;
1230 cpl_frame * loc_frame ;
1235 if (in == NULL)
return NULL ;
1236 if (tags == NULL)
return NULL ;
1237 if (ntags < 1)
return NULL ;
1240 nbframes = cpl_frameset_get_size(in) ;
1243 out = cpl_frameset_new() ;
1246 for (i=0 ; i<nbframes ; i++) {
1247 const cpl_frame * cur_frame ;
1249 cur_frame = cpl_frameset_get_position_const(in, i) ;
1251 for (j=0 ; j<ntags ; j++) {
1252 if (!strcmp(cpl_frame_get_tag(cur_frame), tags[j]))
1256 loc_frame = cpl_frame_duplicate(cur_frame) ;
1257 cpl_frameset_insert(out, loc_frame) ;
1262 if (cpl_frameset_get_size(out) == 0) {
1263 cpl_frameset_delete(out) ;
1283 if (dpos == CR2RES_DECKER_INVALID) {
1284 out = cpl_strdup(
"INVALID") ;
1285 }
else if (dpos == CR2RES_DECKER_NONE) {
1286 out = cpl_strdup(
"NONE") ;
1287 }
else if (dpos == CR2RES_DECKER_1_3) {
1288 out = cpl_strdup(
"1_3") ;
1289 }
else if (dpos == CR2RES_DECKER_2_4) {
1290 out = cpl_strdup(
"2_4") ;
1292 out = cpl_strdup(
"Unknown Decker Code") ;
1307 cpl_polynomial * out ;
1311 if (arr == NULL)
return NULL ;
1314 out = cpl_polynomial_new(1) ;
1317 for (i=0 ; i<cpl_array_get_size(arr) ; i++) {
1319 val = cpl_array_get(arr, i, NULL) ;
1321 cpl_polynomial_delete(out) ;
1324 cpl_polynomial_set_coeff(out, &i, cpl_array_get(arr, i, NULL)) ;
1340 const cpl_polynomial * poly,
1344 cpl_size degree, i ;
1347 if (poly == NULL || size < 1)
return NULL ;
1350 degree = cpl_polynomial_get_degree(poly) ;
1353 if (size < degree+1) {
1354 cpl_msg_error(__func__,
1355 "The requested array size is too small for the polynomial") ;
1360 out = cpl_array_new(size, CPL_TYPE_DOUBLE) ;
1361 cpl_array_fill_window(out, 0, size, 0.0) ;
1364 for (i=0 ; i<=degree ; i++) {
1365 cpl_array_set(out, i, cpl_polynomial_get_coeff(poly, &i)) ;
1371int cr2res_vector_erase_element(cpl_vector * vector, cpl_size pos)
1375 if (vector == NULL)
return -1;
1377 n = cpl_vector_get_size(vector);
1378 if (pos >= n || pos < 0)
return -1;
1381 for (i = pos; i < n - 1; i++){
1382 cpl_vector_set(vector, i, cpl_vector_get(vector, i + 1));
1385 cpl_vector_set_size(vector, n-1);
1390int cr2res_vector_abs(cpl_vector * vector){
1393 if (vector == NULL)
return 0;
1395 for (i = 0; i < cpl_vector_get_size(vector); i++){
1396 cpl_vector_set(vector, i,
1397 fabs(cpl_vector_get(vector, i)));
1427 const cpl_image * ima_data,
1430 cpl_image ** ima_errs)
1432 cpl_ensure_code(ima_data, CPL_ERROR_NULL_INPUT);
1433 cpl_ensure_code(ima_errs, CPL_ERROR_NULL_INPUT);
1434 cpl_ensure_code(gain > 0., CPL_ERROR_ILLEGAL_INPUT);
1435 cpl_ensure_code(ron > -1e-5, CPL_ERROR_ILLEGAL_INPUT);
1437 *ima_errs = cpl_image_duplicate(ima_data);
1439 cpl_image_threshold(*ima_errs, 0., DBL_MAX, ron, ron);
1440 cpl_image_divide_scalar(*ima_errs, gain);
1441 cpl_image_add_scalar(*ima_errs, ron * ron);
1442 cpl_image_power(*ima_errs, 0.5);
1444 return cpl_error_get_code();
1459 const cpl_bivector * extracted_spec,
1460 const cpl_bivector * catalog,
1465 cpl_bivector ** bivectors ;
1470 cpl_bivector * tmp_biv0 ;
1471 cpl_bivector * tmp_biv1 ;
1476 if (extracted_spec==NULL||catalog==NULL||title==NULL)
1483 bivectors = cpl_malloc(2*
sizeof(cpl_bivector*)) ;
1484 bivectors[0] = cpl_bivector_duplicate(extracted_spec) ;
1485 bivectors[1] = cpl_bivector_duplicate(catalog) ;
1488 cpl_bivector_sort(bivectors[0], bivectors[0], CPL_SORT_ASCENDING,
1490 p0x = cpl_bivector_get_x_data(bivectors[0]) ;
1491 p0y = cpl_bivector_get_y_data(bivectors[0]) ;
1492 cpl_bivector_sort(bivectors[1], bivectors[1], CPL_SORT_ASCENDING,
1494 p1x = cpl_bivector_get_x_data(bivectors[1]) ;
1495 p1y = cpl_bivector_get_y_data(bivectors[1]) ;
1498 if (wmin > 0.0 && wmax > 0.0 && wmax > wmin) {
1501 for (i=0 ; i<cpl_bivector_get_size(bivectors[0]) ; i++)
1502 if (p0x[i] >= wmin && p0x[i] <= wmax) n0++ ;
1503 for (i=0 ; i<cpl_bivector_get_size(bivectors[1]) ; i++)
1504 if (p1x[i] >= wmin && p1x[i] <= wmax) n1++ ;
1506 if (n0 > 0 && n1 > 0) {
1512 tmp_biv0 = cpl_bivector_new(n0) ;
1513 ptmp_biv0x = cpl_bivector_get_x_data(tmp_biv0) ;
1514 ptmp_biv0y = cpl_bivector_get_y_data(tmp_biv0) ;
1516 for (i=0 ; i<cpl_bivector_get_size(bivectors[0]) ; i++)
1517 if (p0x[i] >= wmin && p0x[i] <= wmax) {
1518 ptmp_biv0x[n0] = p0x[i] ;
1519 ptmp_biv0y[n0] = p0y[i] ;
1522 tmp_biv1 = cpl_bivector_new(n1) ;
1523 ptmp_biv1x = cpl_bivector_get_x_data(tmp_biv1) ;
1524 ptmp_biv1y = cpl_bivector_get_y_data(tmp_biv1) ;
1526 for (i=0 ; i<cpl_bivector_get_size(bivectors[1]) ; i++)
1527 if (p1x[i] >= wmin && p1x[i] <= wmax) {
1528 ptmp_biv1x[n1] = p1x[i] ;
1529 ptmp_biv1y[n1] = p1y[i] ;
1532 cpl_bivector_delete(bivectors[0]) ;
1533 cpl_bivector_delete(bivectors[1]) ;
1535 bivectors[0] = tmp_biv0 ;
1536 bivectors[1] = tmp_biv1 ;
1541 rate = -1* fabs(10*cpl_vector_get_mean(cpl_bivector_get_y(bivectors[0])) /
1542 cpl_vector_get_mean(cpl_bivector_get_y(bivectors[1]))) ;
1543 cpl_vector_multiply_scalar(cpl_bivector_get_y(bivectors[1]), rate) ;
1546 if (cpl_bivector_get_size(bivectors[0]) > 0 &&
1547 cpl_bivector_get_size(bivectors[1]) > 0) {
1549 char ** options = cpl_malloc(2*
sizeof(
char*)) ;
1550 options[0] = cpl_sprintf(
"t '1-Extracted %s' w lines", title) ;
1551 options[1] =
"t '2-Catalog' w impulses" ;
1552 cpl_plot_bivectors(
"set grid;set xlabel 'Wavelength (nm)';",
1553 (
const char **)options,
1554 "", (
const cpl_bivector **)bivectors, 2);
1555 cpl_free(options[0]) ;
1560 cpl_bivector_delete(bivectors[0]) ;
1561 cpl_bivector_delete(bivectors[1]) ;
1562 cpl_free(bivectors) ;
1593int cr2res_util_optimal_filter_1d(
1594 const double * Yarg,
1599 const double * Xarg,
1600 const double * Weights,
1603 int i, flag_x, flag_w, flag_lam2;
1606 flag_x =(Options[0])?1:0;
1607 flag_w =(Options[1])?1:0;
1608 flag_lam2=(Options[2])?1:0;
1614 dx=(
double *)cpl_malloc((n-1)*
sizeof(double));
1616 for(i=0; i<n-1; i++)
1618 dx[i]=Xarg[i+1]-Xarg[i];
1619 if(dx[i]>0.) nzero++;
1620 else if(dx[i]<0.) nzero--;
1632 ddx2=(
double *)cpl_malloc((n-2)*
sizeof(double));
1633 for(i=0; i<n-2; i++)
1635 ddx2[i]=(Xarg[i+2]-Xarg[i])*0.5;
1639 aij=(
double *)cpl_malloc(n*5*
sizeof(
double));
1640 bj =(
double *)cpl_malloc(n*
sizeof(
double));
1644 for(i=0; i<n-2; i++) aij[i+2]=Lam2/(dx[i]*dx[i+1]*ddx2[i]);
1648 for(i=0; i<n-1; i++) aij[n+i+1] =-Lam1/(dx[i]*dx[i]);
1649 for(i=0; i<n-2; i++)
1651 aij[n+i+1]-= Lam2/(dx[i ]*dx[i ]*ddx2[i])
1652 +Lam2/(dx[i ]*dx[i+1]*ddx2[i]);
1653 aij[n+i+2]-= Lam2/(dx[i+1]*dx[i+1]*ddx2[i])
1654 +Lam2/(dx[i ]*dx[i+1]*ddx2[i]);
1659 if(flag_w)
for(i=0; i<n; i++) aij[2*n+i]=Weights[i];
1660 else for(i=0; i<n; i++) aij[2*n+i]=1.;
1662 for(i=0; i<n-1; i++) aij[2*n+i ]+=Lam1/(dx[i]*dx[i]);
1664 for(i=0; i<n-1; i++) aij[2*n+i+1]+=Lam1/(dx[i]*dx[i]);
1666 for(i=0; i<n-2; i++)
1669 aij[2*n+i ]+=Lam2/(dx[i ]*dx[i ]*ddx2[i]);
1670 dddd=1./dx[i]+1./dx[i+1]; dddd*=dddd;
1671 aij[2*n+i+1]+=Lam2*dddd/ddx2[i];
1672 aij[2*n+i+2]+=Lam2/(dx[i+1]*dx[i+1]*ddx2[i]);
1677 for(i=0; i<n-1; i++) aij[3*n+i]=-Lam1/(dx[i]*dx[i]);
1680 for(i=0; i<n-2; i++)
1682 aij[3*n+i ]-= Lam2/(dx[i ]*dx[i ]*ddx2[i])
1683 +Lam2/(dx[i ]*dx[i+1]*ddx2[i]);
1684 aij[3*n+i+1]-= Lam2/(dx[i+1]*dx[i+1]*ddx2[i])
1685 +Lam2/(dx[i ]*dx[i+1]*ddx2[i]);
1690 for(i=0; i<n-2; i++) aij[4*n+i]=Lam2/(dx[i+1]*dx[i]*ddx2[i]);
1691 aij[5*n-2]=aij[5*n-1]=0.;
1695 if(flag_w)
for(i=0; i<n; i++) bj[i]=Yarg[i]*Weights[i];
1696 else for(i=0; i<n; i++) bj[i]=Yarg[i];
1698 cr2res_extract_slitdec_bandsol(aij, bj, n, 5, Lam1);
1699 for(i=0; i<n; i++) Result[i]=bj[i];
1705 return CPL_ERROR_NONE;
1709 aij=(
double *)cpl_malloc(n*3*
sizeof(
double));
1710 bj =(
double *)cpl_malloc(n*
sizeof(
double));
1714 for(i=0; i<n-1; i++) aij[i+1]=-Lam1/(dx[i]*dx[i]);
1718 if(flag_w)
for(i=0; i<n; i++) aij[n+i]=Weights[i];
1719 else for(i=0; i<n; i++) aij[n+i]=1.;
1721 for(i=0; i<n-1; i++) aij[n+i ]+=Lam1/(dx[i]*dx[i]);
1722 for(i=0; i<n-1; i++) aij[n+i+1]+=Lam1/(dx[i]*dx[i]);
1726 for(i=0; i<n-1; i++) aij[2*n+i]=-Lam1/(dx[i]*dx[i]);
1731 if(flag_w)
for(i=0; i<n; i++) bj[i]=Yarg[i]*Weights[i];
1732 else for(i=0; i<n; i++) bj[i]=Yarg[i];
1734 cr2res_extract_slitdec_bandsol(aij, bj, n, 3, Lam1);
1735 for(i=0; i<n; i++) Result[i]=bj[i];
1740 return CPL_ERROR_NONE;
1747 aij=(
double *)cpl_malloc(n*5*
sizeof(
double));
1748 bj =(
double *)cpl_malloc(n*
sizeof(
double));
1752 for(i=0; i<n-2; i++) aij[i+2]=Lam2;
1757 for(i=0; i<n-1; i++) aij[n+i+1]=-Lam1;
1758 for(i=0; i<n-2; i++) aij[n+i+1]-=2*Lam2;
1759 for(i=0; i<n-2; i++) aij[n+i+2]-=2*Lam2;
1763 if(flag_w)
for(i=0; i<n; i++) aij[2*n+i]=Weights[i];
1764 else for(i=0; i<n; i++) aij[2*n+i]=1.;
1765 for(i=0; i<n-1; i++) aij[2*n+i ]+=Lam1;
1766 for(i=0; i<n-1; i++) aij[2*n+i+1]+=Lam1;
1767 for(i=0; i<n-2; i++) aij[2*n+i ]+=Lam2;
1768 for(i=0; i<n-2; i++) aij[2*n+i+1]+=Lam2*4;
1769 for(i=0; i<n-2; i++) aij[2*n+i+2]+=Lam2;
1773 for(i=0; i<n-1; i++) aij[3*n+i]=-Lam1;
1775 for(i=0; i<n-2; i++) aij[3*n+i ]-=Lam2*2;
1776 for(i=0; i<n-2; i++) aij[3*n+i+1]-=Lam2*2;
1780 for(i=0; i<n-2; i++) aij[4*n+i]=Lam2;
1781 aij[5*n-2]=aij[5*n-1]=0.;
1785 if(flag_w)
for(i=0; i<n; i++) bj[i]=Yarg[i]*Weights[i];
1786 else for(i=0; i<n; i++) bj[i]=Yarg[i];
1788 cr2res_extract_slitdec_bandsol(aij, bj, n, 5, Lam1);
1789 for(i=0; i<n; i++) Result[i]=bj[i];
1793 return CPL_ERROR_NONE;
1797 aij=(
double *)cpl_malloc(n*3*
sizeof(
double));
1798 bj =(
double *)cpl_malloc(n*
sizeof(
double));
1802 for(i=0; i<n-1; i++) aij[i+1]=-Lam1;
1806 if(flag_w)
for(i=0; i<n; i++) aij[n+i]=Weights[i];
1807 else for(i=0; i<n; i++) aij[n+i]=1.;
1809 for(i=0; i<n-1; i++) aij[n+i ]+=Lam1;
1810 for(i=0; i<n-1; i++) aij[n+i+1]+=Lam1;
1814 for(i=0; i<n-1; i++) aij[2*n+i]=-Lam1;
1819 if(flag_w)
for(i=0; i<n; i++) bj[i]=Yarg[i]*Weights[i];
1820 else for(i=0; i<n; i++) bj[i]=Yarg[i];
1822 cr2res_extract_slitdec_bandsol(aij, bj, n, 3, Lam1);
1823 for(i=0; i<n; i++) Result[i]=bj[i];
1827 return CPL_ERROR_NONE;
1832#define aij_index(x, y) ((y) * n) + (x)
1833#define w_index(x, y) ((y) * nx) + (x)
1849 const cpl_image * img,
1850 const cpl_image * weight,
1854 cpl_size nx, ny, i, j, k;
1857 const double * weight_data;
1858 cpl_image * rhs_image;
1861 nx = cpl_image_get_size_x(img);
1862 ny = cpl_image_get_size_y(img);
1866 lam_x = fabs(lam_x);
1867 lam_y = fabs(lam_y);
1869 weight_data = cpl_image_get_data_double_const(weight);
1871 aij = cpl_malloc(n * ndiag *
sizeof(
double));
1873 aij[aij_index(0, nx)] = weight_data[w_index(0, 0)] + lam_x + lam_y;
1875 for (i = 1; i < nx; i++)
1877 aij[aij_index(i, nx)] = weight_data[w_index(i, 0)] + 2 * lam_x + lam_y;
1881 for (i = 0; i < nx; i++)
1883 for (j = 1; j < ny-2; j++){
1884 aij[aij_index(k, nx)] = weight_data[w_index(i, j)]
1885 + 2 * lam_x + 2 * lam_y;
1891 for (i = n - nx; i < n - 1; i++)
1893 aij[aij_index(i, nx)] = weight_data[w_index(j, ny-1)]
1894 + 2 * lam_x + lam_y;
1898 aij[aij_index(n-1, nx)] = weight_data[w_index(nx-1, ny-1)] + lam_x + lam_y;
1899 for (i = 1; i < n; i++)
1902 aij[aij_index(i, nx-1)] = -1 * lam_x;
1904 aij[aij_index(i-1, nx+1)] = -1 * lam_x;
1907 for (i = 0; i < ny-1; i++)
1910 j = i * nx + nx + nx * n;
1912 aij[j-1] = aij[j - 1] - lam_x;
1914 aij[j] = aij[j] - lam_x;
1916 for (i = 0; i < ny - 1; i++){
1920 aij[aij_index(j - 1, nx + 1)] = 0;
1922 aij[aij_index(j, nx - 1)] = 0;
1925 for (i = nx; i < n; i++)
1927 aij[aij_index(i, 0)] = -lam_y;
1930 for (i = 0; i < n - nx; i++)
1932 aij[aij_index(i, ndiag - 1)] = -lam_y;
1935 rhs_image = cpl_image_multiply_create(img, weight);
1936 rhs = cpl_image_get_data_double(rhs_image);
1938 cr2res_extract_slitdec_bandsol(aij, rhs, n, ndiag, max(lam_x, lam_y));
2064 const cpl_vector * x,
2065 const cpl_vector * y,
2066 const cpl_vector * z,
2067 const cpl_matrix * degree)
2069 cpl_size npoints, ndegrees;
2070 double norm_x, norm_y;
2074 cpl_polynomial * poly;
2075 cpl_vector * xhat, * yhat, *zhat;
2076 cpl_matrix * mh, * mz;
2080 if (x == NULL || y == NULL || z == NULL || degree == NULL)
return NULL;
2082 npoints = cpl_vector_get_size(x);
2083 if (cpl_vector_get_size(y) != npoints || cpl_vector_get_size(z) != npoints){
2085 cpl_msg_error(__func__,
"Vectors in polyfit2d are not of the same size");
2088 ndegrees = cpl_matrix_get_nrow(degree);
2090 cpl_msg_error(__func__,
"No fit degrees passed to polyfit2d");
2104 norm_x = cpl_vector_get_max(x);
2105 norm_y = cpl_vector_get_max(y);
2106 if (norm_x == 0) norm_x = 1;
2107 if (norm_y == 0) norm_y = 1;
2109 xhat = cpl_vector_duplicate(x);
2110 yhat = cpl_vector_duplicate(y);
2113 cpl_vector_divide_scalar(xhat, norm_x);
2116 cpl_vector_divide_scalar(yhat, norm_y);
2120 const double * xdata, *ydata;
2121 double xdegree, ydegree;
2122 mh = cpl_matrix_new(npoints, ndegrees);
2124 xdata = cpl_vector_get_data_const(xhat);
2125 ydata = cpl_vector_get_data_const(yhat);
2128 for (i = 0; i < ndegrees; i++)
2130 xdegree = cpl_matrix_get(degree, i, 0);
2131 ydegree = cpl_matrix_get(degree, i, 1);
2133 for (j = 0; j < npoints; j++)
2135 cpl_matrix_set(mh, j, i, pow(xdata[j], xdegree) * pow(ydata[j], ydegree));
2141 zhat = cpl_vector_duplicate(z);
2142 mz = cpl_matrix_wrap(npoints, 1, cpl_vector_get_data(zhat));
2145 mcoef = cpl_matrix_solve_svd(mh, mz);
2147 cpl_matrix_unwrap(mz);
2148 cpl_matrix_delete(mh);
2151 for (i = 0; i < ndegrees; i++){
2152 xdegree = cpl_matrix_get(degree, i, 0);
2153 ydegree = cpl_matrix_get(degree, i, 1);
2155 coef = cpl_matrix_get(mcoef, i, 0);
2156 coef /= pow(norm_x, xdegree) * pow(norm_y, ydegree);
2157 cpl_matrix_set(mcoef, i, 0, coef);
2162 poly = cpl_polynomial_new(2);
2163 for (i = 0; i < ndegrees; i++)
2165 power[0] = cpl_matrix_get(degree, i, 0);
2166 power[1] = cpl_matrix_get(degree, i, 1);
2167 coef = cpl_matrix_get(mcoef, i, 0);
2168 cpl_polynomial_set_coeff(poly, power, coef);
2171 cpl_vector_delete(xhat);
2172 cpl_vector_delete(yhat);
2173 cpl_vector_delete(zhat);
2174 cpl_matrix_delete(mcoef);
2180cpl_polynomial * cr2res_polyfit_2d(
2181 const cpl_vector * x,
2182 const cpl_vector * y,
2183 const cpl_vector * z,
2184 const cpl_size degree[2]
2188 cpl_polynomial * result;
2189 cpl_size ndegrees = degree[0] * degree[1] + 1;
2190 cpl_size max_degree = max(degree[0], degree[1]);
2193 deg = cpl_matrix_new(ndegrees, 2);
2196 for (i = 0; i < degree[0]; i++)
2198 for (j = 0; j < degree[1]; j++)
2200 if (i + j > max_degree)
continue;
2201 cpl_matrix_set(deg, n, 0, i);
2202 cpl_matrix_set(deg, n, 1, j);
2207 cpl_matrix_set_size(deg, n, 2);
2210 cpl_matrix_delete(deg);
2224 const cpl_table * blaze,
2228 cpl_array * col_names ;
2229 const double * pspec ;
2230 cpl_size ncols, i, j, nrows;
2233 if (blaze == NULL)
return 1.0 ;
2236 col_names = cpl_table_get_column_names(blaze);
2237 ncols = cpl_table_get_ncol(blaze) ;
2239 cpl_array_delete(col_names) ;
2247 for (i = 0; i < ncols; i++) {
2249 const char *col_name;
2250 int trace_nb, order ;
2251 col_name = cpl_array_get_string(col_names, i);
2254 if (col_type != NULL && !strcmp(col_type, CR2RES_COL_SPEC_SUFFIX)) {
2258 pspec = cpl_table_get_data_double_const(blaze, col_name) ;
2260 nrows = cpl_table_get_nrow(blaze) ;
2261 for (j=0 ; j<nrows ; j++) {
2263 (*blaze_tot) += pspec[j] ;
2268 if (col_type != NULL) cpl_free(col_type) ;
2270 cpl_array_delete(col_names) ;
2275 return *blaze_tot / *ngood ;
2278#define SECONDS_TO_DAYS 1.157407e-5
2291 cpl_size nframes = 0;
2293 double total, total_weight;
2295 const char exptime_name[] =
"EXPTIME";
2296 const char mjd_mid_name[] =
"MJD-OBS";
2298 if (frameset == NULL)
return -1;
2305 nframes = cpl_frameset_get_size(frameset);
2306 for ( i = 0; i < nframes; i++)
2308 const cpl_frame * frame;
2309 cpl_propertylist * pl;
2310 double exptime, mjd;
2313 frame = cpl_frameset_get_position_const(frameset, i);
2314 fname = cpl_frame_get_filename(frame);
2315 pl = cpl_propertylist_load(fname, 0);
2317 cpl_msg_error(__func__,
"Could not read file %s", fname);
2324 mjd = cpl_propertylist_get_double(pl, mjd_mid_name);
2326 cpl_msg_error(__func__,
"Property %s not found in file %s", mjd_mid_name, fname);
2327 cpl_propertylist_delete(pl);
2331 exptime = cpl_propertylist_get_double(pl, exptime_name);
2333 cpl_msg_error(__func__,
"Property %s not found in file %s", exptime_name, fname);
2334 cpl_propertylist_delete(pl);
2338 cpl_propertylist_delete(pl);
2341 mjd += exptime / 2.0 * SECONDS_TO_DAYS;
2344 total += mjd * exptime;
2345 total_weight += exptime;
2349 total /= total_weight;
2364 const char * cr2res_license =
2365 "This file is part of the CR2RES Instrument Pipeline\n"
2366 "Copyright (C) 2002,2003 European Southern Observatory\n"
2368 "This program is free software; you can redistribute it and/or modify\n"
2369 "it under the terms of the GNU General Public License as published by\n"
2370 "the Free Software Foundation; either version 2 of the License, or\n"
2371 "(at your option) any later version.\n"
2373 "This program is distributed in the hope that it will be useful,\n"
2374 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
2375 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
2376 "GNU General Public License for more details.\n"
2378 "You should have received a copy of the GNU General Public License\n"
2379 "along with this program; if not, write to the Free Software\n"
2380 "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, \n"
2381 "MA 02111-1307 USA" ;
2382 return cr2res_license ;
char * cr2res_dfs_SPEC_ERR_colname(int order_idx, int trace)
Get the ERR column name for a given order/trace.
char * cr2res_dfs_WAVELENGTH_colname(int order_idx, int trace)
Get the WAVELENGTH column name for a given order/trace.
char * cr2res_dfs_SPEC_colname_parse(const char *colname, int *order_idx, int *trace)
Parse a column name ORDER_TRACE_TYPE format.
cpl_size cr2res_get_trace_table_index(const cpl_table *trace_wave, int order_idx, int trace_nb)
Get the index in a TRACE_WAVE table.
int * cr2res_get_trace_numbers(const cpl_table *trace_wave, int order_idx, int *nb_traces)
Get the trace numbers for a specified order_idx.
cpl_polynomial * cr2res_get_trace_wave_poly(const cpl_table *trace_wave, const char *poly_column, int order_idx, int trace_nb)
Get a polynomial from a TRACE_WAVE table.
int * cr2res_trace_get_order_idx_values(const cpl_table *trace, int *nb_order_idx_values)
Count and return the different order_idx values from a TW table.
double cr2res_mjd_obs_now(void)
Get the current MJD-OBS.
int cr2res_format_setting2(char *setting_id)
Format the setting.
int cr2res_format_setting(char *setting_id)
Format the setting.
double cr2res_ra_hms2deg(int hh, int mm, double ss)
Convert the RA from hh mm ss to degrees.
cpl_image * cr2res_image_cut_rectify(const cpl_image *img_in, const cpl_vector *ycen, int height)
Cut a bent order into a rectangle, shifting columns.
char * cr2res_decker_print_position(cr2res_decker dpos)
Get the decker position string for display.
int * cr2res_vector_get_int(const cpl_vector *ycen)
cpl_error_code cr2res_detector_shotnoise_model(const cpl_image *ima_data, const double gain, const double ron, cpl_image **ima_errs)
compute photon count error in [ADU]
cpl_polynomial * cr2res_fit_interorder(cpl_image *img, cpl_table *trace_wave, cpl_size order_x, cpl_size order_y)
Fit a 2D Polynomial to the interorder regions.
double cr2res_dec_hms2deg(int dd, int mm, double ss)
Convert the DEC from dd mm ss to degrees.
double cr2res_vector_get_mad(cpl_vector *invec, double *mad)
Get MAD from a vector.
cpl_polynomial * cr2res_convert_array_to_poly(const cpl_array *arr)
Convert an array to polynomial.
cpl_vector * cr2res_threshold_spec(const cpl_vector *invector, int smooth, double thresh)
Find the regions with over-average values in a vector.
double * cr2res_vector_get_rest(const cpl_vector *ycen)
cpl_vector * cr2res_polynomial_eval_vector(const cpl_polynomial *poly, const cpl_vector *vec)
Evaluate a polynomial on a vector.
int cr2res_order_idx_to_real(int order_idx, int order_zp)
Convert the order_idx into order_real.
double cr2res_utils_get_center_mjd(const cpl_frameset *frameset)
Calculate the middle of the exposures in the frameset.
cpl_array * cr2res_convert_poly_to_array(const cpl_polynomial *poly, int size)
Convert a polynomial to array.
double cr2res_util_blaze_stat(const cpl_table *blaze, int *ngood, double *blaze_tot)
Computes the average of the blaze.
cpl_image * cr2res_util_optimal_filter_2d(const cpl_image *img, const cpl_image *weight, double lam_x, double lam_y)
Apply the optimal filter in the 2D case.
int cr2res_is_short_wavelength(const char *setting_id)
Identify Short Wavelength.
char * cr2res_get_root_name(const char *filename)
Find out the root part of a basename (name without extension).
int cr2res_plot_wavecal_result(const cpl_bivector *extracted_spec, const cpl_bivector *catalog, const char *title, double wmin, double wmax)
Plot the spectrum with the catalog.
cpl_frameset * cr2res_extract_frameset_several_tags(const cpl_frameset *in, const char **tags, int ntags)
Extract the frames whose tag is within a list from a frameset.
cpl_table * cr2res_combine_extracted(const cpl_table *extracta, const cpl_table *extractb)
Combine two extracted spectra by resampling one to the other's WL.
int cr2res_slit_pos_image(const cpl_table *trace_wave, cpl_image **slitpos, cpl_image **wavelength)
get a image of the slitposition (and wavelength) along the slit
int cr2res_slit_pos(const cpl_table *trace_wave, cpl_polynomial ***coef_slit, cpl_polynomial ***coef_wave, int *size)
Create the polynomials needed to calculate the slit pos and wavelength at any point x,...
int cr2res_order_real_to_idx(int order_real, int order_zp)
Convert the order_real into order_idx.
cpl_frameset * cr2res_extract_frameset(const cpl_frameset *in, const char *tag)
Extract the frames with the given tag from a frameset.
int cr2res_image_insert_rect(const cpl_image *rect_in, const cpl_vector *ycen, cpl_image *img_out)
Re-insert a rectangular cut-out of an order into the full frame.
char * cr2res_get_base_name(const char *filename)
Find out the base name of a file (i.e. without prefix path)
cpl_polynomial * cr2res_polyfit_2d_loc(const cpl_vector *x, const cpl_vector *y, const cpl_vector *z, const cpl_matrix *degree)
Perform a 2D polynomial fit f(x, y) = z.
const char * cr2res_get_license(void)
Get the pipeline copyright and license.
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter
hdrl_spectrum1D * hdrl_spectrum1D_resample(const hdrl_spectrum1D *self, const hdrl_spectrum1D_wavelength *waves, const hdrl_parameter *par)
resample a hdrl_spectrum1D on the wavelengths contained in waves
hdrl_parameter * hdrl_spectrum1D_resample_interpolate_parameter_create(const hdrl_spectrum1D_interpolation_method method)
constructor for the hdrl_parameter in the case of interpolation
cpl_size hdrl_spectrum1D_get_size(const hdrl_spectrum1D *self)
hdrl_spectrum1D getter for size
void hdrl_spectrum1D_delete(hdrl_spectrum1D **p_self)
hdrl_spectrum1D destructor
hdrl_spectrum1D * hdrl_spectrum1D_convert_from_table(const cpl_table *self, const char *flux_col_name, const char *wavelength_col_name, const char *flux_e_col_name, const char *flux_bpm_col_name, hdrl_spectrum1D_wave_scale scale)
convert a table to a spectrum
cpl_error_code hdrl_spectrum1D_add_spectrum(hdrl_spectrum1D *self, const hdrl_spectrum1D *other)
sum two spectra
hdrl_spectrum1D_wavelength hdrl_spectrum1D_get_wavelength(const hdrl_spectrum1D *self)
hdrl_spectrum1D getter for wavelengths
hdrl_data_t hdrl_spectrum1D_get_wavelength_value(const hdrl_spectrum1D *self, int idx, int *rej)
hdrl_spectrum1D getter for a wavelength value
hdrl_value hdrl_spectrum1D_get_flux_value(const hdrl_spectrum1D *self, int idx, int *rej)
hdrl_spectrum1D getter for a flux value