27 #define STORE_SLIT_WIDTH 28 #define STORE_BIN_WIDTH 40 #include "muse_instrument.h" 41 #include "muse_optimize.h" 42 #include "muse_pfits.h" 43 #include "muse_pixtable.h" 44 #include "muse_quality.h" 45 #include "muse_resampling.h" 46 #include "muse_tracing.h" 47 #include "muse_utils.h" 48 #include "muse_wavecalib.h" 78 muse_lsf_check_arc_line(cpl_table *aPixtable,
double aLambda)
80 cpl_size nrows = cpl_table_get_nrow(aPixtable);
85 cpl_errorstate prestate = cpl_errorstate_get();
90 cpl_vector *pos = cpl_vector_new(nrows);
91 cpl_vector *val = cpl_vector_new(nrows);
92 cpl_vector *err = cpl_vector_new(nrows);
93 double *d_pos = cpl_vector_get_data(pos);
94 double *d_val = cpl_vector_get_data(val);
95 double *d_err = cpl_vector_get_data(err);
101 for (i = 0; i < nrows; i++) {
102 if (fabs(d_lambda[i] - aLambda) > 5.5) {
103 bglevel += d_data[i];
106 d_pos[i] = d_lambda[i];
107 d_val[i] = d_data[i];
108 d_err[i] = sqrt(d_stat[i]);
112 double sigma, area, mse;
114 cpl_fit_mode fit_pars = CPL_FIT_STDEV | CPL_FIT_AREA | CPL_FIT_CENTROID;
115 cpl_vector_fit_gaussian(pos, NULL, val, NULL, fit_pars, &xc, &sigma,
116 &area, &bglevel, &mse, NULL, NULL);
119 for (i = 0; i < nrows; i++) {
120 double e = (d_pos[i] - xc)/sigma;
121 d_val[i] -= area / (CPL_MATH_SQRT2PI * sigma) * exp(-e*e/2) - bglevel;
125 double maxerror = 0.5 * sqrt(area) + 0.15 * area;
127 cpl_table_unselect_all(aPixtable);
128 for (i = 0; i < nrows; i++) {
129 if ((d_val[i] < -maxerror) || (d_val[i] > maxerror)) {
131 cpl_table_select_row(aPixtable, i);
134 cpl_vector_delete(pos);
135 cpl_vector_delete(val);
136 cpl_vector_delete(err);
137 cpl_table_erase_selected(aPixtable);
138 nrows = cpl_table_get_nrow(aPixtable);
143 cpl_table_fill_column_window_float(aPixtable,
"line_lambda",
145 cpl_table_fill_column_window_float(aPixtable,
"line_flux",
147 cpl_table_fill_column_window_float(aPixtable,
"line_background",
151 if (!cpl_errorstate_is_equal(prestate)) {
152 cpl_errorstate_set(prestate);
156 if (area/meansigma < 50) {
161 if ((sigma > 3) || (sigma < 0.7)) {
164 cpl_msg_debug(__func__,
"Slice %2i.%02i: " 165 "Ignoring line %.1f with implausible width %f (flux=%.0f)",
166 i_ifu, i_slice, aLambda, sigma, area);
194 muse_lsf_select_arc_line(
muse_pixtable *aPixtable,
double aLambda,
204 cpl_table *sel = cpl_table_extract(aPixtable->
table, low + 1, high - low);
205 cpl_table_select_all(sel);
206 cpl_table_and_selected_int(sel,
"dq", CPL_NOT_EQUAL_TO, 0);
207 cpl_table_erase_selected(sel);
208 if (cpl_table_get_nrow(sel) == 0) {
209 cpl_table_delete(sel);
213 cpl_table_new_column(sel,
"line_lambda", CPL_TYPE_FLOAT);
214 cpl_table_new_column(sel,
"line_flux", CPL_TYPE_FLOAT);
215 cpl_table_new_column(sel,
"line_background", CPL_TYPE_FLOAT);
217 cpl_size nrows = muse_lsf_check_arc_line(sel, aLambda);
219 cpl_table_delete(sel);
251 cpl_table *aTrace, cpl_table *aWave,
252 cpl_table *aArcLines,
int aQuality,
double aWindow)
254 cpl_ensure(aImages, CPL_ERROR_NULL_INPUT, NULL);
255 cpl_ensure(aTrace, CPL_ERROR_NULL_INPUT, NULL);
256 cpl_ensure(aWave, CPL_ERROR_NULL_INPUT, NULL);
257 cpl_ensure(aArcLines, CPL_ERROR_NULL_INPUT, NULL);
262 cpl_table_new_column(pt->
table,
"line_lambda", CPL_TYPE_FLOAT);
263 cpl_table_new_column(pt->
table,
"line_flux", CPL_TYPE_FLOAT);
264 cpl_table_new_column(pt->
table,
"line_background", CPL_TYPE_FLOAT);
268 #pragma omp parallel for default(none) \ 269 shared(i_image, n_images, aImages, aTrace, aWave, aArcLines, \ 270 aQuality, aWindow, pt) 272 for (i_image = 0; i_image < n_images; i_image++) {
275 if (pixtable == NULL) {
280 pt->
header = cpl_propertylist_duplicate(pixtable->
header);
283 if (strlen(l) == 0) {
284 cpl_msg_warning(__func__,
285 "Ignoring frame without arc lamp switched on");
290 char *lamp = cpl_malloc(strlen(l)+3);
291 sprintf(lamp,
"|%s|", l);
294 cpl_size n_entries = 0;
298 for (i_line = 0; i_line < cpl_table_get_nrow(aArcLines); i_line++) {
299 double lambda = cpl_table_get_float(aArcLines,
"lambda", i_line, NULL);
301 cpl_table_get_int(aArcLines,
"quality", i_line, NULL) < aQuality) {
305 char *name = cpl_malloc(strlen(n) + 3);
306 sprintf(name,
"|%s|", n);
307 if (strstr(name, lamp)) {
310 #pragma omp parallel for default(none) \ 311 shared(i_slice, n_slices, n_entries, lambda, slice_pixtable, \ 314 for (i_slice = 0; i_slice < n_slices; i_slice++) {
315 cpl_table *sel = muse_lsf_select_arc_line(slice_pixtable[i_slice],
319 #pragma omp critical(construct_pixtable) 321 cpl_table_insert(pt->
table, sel, cpl_table_get_nrow(pt->
table));
325 n_entries += cpl_table_get_nrow(sel);
326 cpl_table_delete(sel);
334 cpl_msg_info(__func__,
"Using %"CPL_SIZE_FORMAT
" entries with lamp %s",
367 static cpl_polynomial *
368 muse_lsf_fit_polynomial(cpl_table *aPixtable,
int aOrderLsf,
int aOrderLambda)
370 cpl_errorstate prestate = cpl_errorstate_get();
371 cpl_size nrows = cpl_table_get_nrow(aPixtable);
372 if (nrows <= (aOrderLsf + 1) * (aOrderLambda)) {
375 double *p_dlambda = cpl_table_get_data_double(aPixtable,
"d_lambda");
376 cpl_ensure(p_dlambda, CPL_ERROR_ILLEGAL_INPUT, NULL);
377 float *p_line = cpl_table_get_data_float(aPixtable,
"line_lambda");
378 cpl_ensure(p_line, CPL_ERROR_ILLEGAL_INPUT, NULL);
380 cpl_ensure(p_data, CPL_ERROR_ILLEGAL_INPUT, NULL);
381 float *p_flux = cpl_table_get_data_float(aPixtable,
"line_flux");
382 cpl_ensure(p_flux, CPL_ERROR_ILLEGAL_INPUT, NULL);
383 float *p_background = cpl_table_get_data_float(aPixtable,
"line_background");
384 cpl_ensure(p_background, CPL_ERROR_ILLEGAL_INPUT, NULL);
386 cpl_matrix *coord = cpl_matrix_new(2, nrows);
387 cpl_vector *data = cpl_vector_new(nrows);
388 double *coord_ptr = cpl_matrix_get_data(coord);
389 double *data_ptr = cpl_vector_get_data(data);
392 for (i_row = 0; i_row < nrows; i_row++) {
393 coord_ptr[i_row] = p_dlambda[i_row];
394 coord_ptr[i_row + nrows] = p_line[i_row];
395 data_ptr[i_row] = (p_data[i_row] - p_background[i_row]) / p_flux[i_row];
398 cpl_polynomial *p = cpl_polynomial_new(2);
399 const cpl_size maxdeg2d[] = { aOrderLsf, aOrderLambda };
400 cpl_polynomial_fit(p, coord, NULL, data, NULL, CPL_TRUE, NULL, maxdeg2d);
401 cpl_matrix_delete(coord);
402 cpl_vector_delete(data);
404 if (!cpl_errorstate_is_equal(prestate)) {
405 cpl_errorstate_set(prestate);
444 muse_wcs *aWCS,
double aLsfRegressionWindow)
446 cpl_ensure_code(aPixtable && aPixtable->
table, CPL_ERROR_NULL_INPUT);
447 cpl_ensure_code(aLsfImage, CPL_ERROR_NULL_INPUT);
448 cpl_ensure_code(aWCS, CPL_ERROR_NULL_INPUT);
449 cpl_ensure_code(aLsfRegressionWindow > 0, CPL_ERROR_ILLEGAL_INPUT);
453 return CPL_ERROR_NONE;
456 cpl_table *pixtable = cpl_table_duplicate(aPixtable->
table);
460 cpl_msg_info(__func__,
"processing slice %2i.%02i" 461 " with %"CPL_SIZE_FORMAT
" entries",
462 i_ifu, i_slice, nrows);
469 cpl_table_subtract_columns(pixtable,
"d_lambda",
"line_lambda");
470 cpl_propertylist *order = cpl_propertylist_new();
471 cpl_propertylist_append_bool(order,
"d_lambda", CPL_FALSE);
472 cpl_table_sort(pixtable, order);
473 cpl_propertylist_delete(order);
478 cpl_size n_lsf = cpl_image_get_size_x(aLsfImage);
479 cpl_size n_lambda = cpl_image_get_size_y(aLsfImage);
480 for (i_lsf = 1; i_lsf <= n_lsf; i_lsf++) {
481 double x = aWCS->crval1 + (i_lsf - aWCS->crpix1) * aWCS->cd11;
482 double x_ref = CPL_MAX(x, cpl_table_get_column_min(pixtable,
"d_lambda")
483 + aLsfRegressionWindow);
484 x_ref = CPL_MIN(x, cpl_table_get_column_max(pixtable,
"d_lambda")
485 - aLsfRegressionWindow);
487 x_ref - aLsfRegressionWindow);
489 x_ref + aLsfRegressionWindow);
490 cpl_table *selected = cpl_table_extract(pixtable, low+1, high-low);
491 cpl_polynomial *p = muse_lsf_fit_polynomial(selected, 2, 3);
493 cpl_vector *c = cpl_vector_new(2);
494 cpl_vector_set(c, 0, x);
497 for (i_lambda = 1; i_lambda <= n_lambda; i_lambda++) {
499 cpl_vector_set(c, 1, y);
500 double flux = cpl_polynomial_eval(p, c);
501 cpl_image_set(aLsfImage, i_lsf, i_lambda, flux);
503 cpl_vector_delete(c);
505 cpl_msg_warning(__func__,
506 "Failed polynomial fit %2i.%02i %.2f;" 507 " %"CPL_SIZE_FORMAT
" entries",
508 i_ifu, i_slice, x, cpl_table_get_nrow(selected));
510 for (i_lambda = 1; i_lambda <= n_lambda; i_lambda++) {
511 cpl_image_reject(aLsfImage, i_lsf, i_lambda);
514 cpl_polynomial_delete(p);
515 cpl_table_delete(selected);
517 cpl_table_delete(pixtable);
521 for (i_lambda = 1; i_lambda <= n_lambda; i_lambda++) {
522 double line_flux = cpl_image_get_flux_window(aLsfImage, 1, i_lambda,
523 n_lsf, i_lambda) * aWCS->cd11;
524 for (i_lsf = 1; i_lsf <= n_lsf; i_lsf++) {
526 double flux = cpl_image_get(aLsfImage, i_lsf, i_lambda, &invalid);
528 cpl_image_set(aLsfImage, i_lsf, i_lambda, flux / line_flux);
532 return CPL_ERROR_NONE;
547 const cpl_propertylist *aHeader)
550 lsf->
header = cpl_propertylist_new();
553 const char *regex = MUSE_HDR_OVSC_REGEXP
"|"MUSE_WCS_KEYS"|"MUSE_HDR_PT_REGEXP;
554 cpl_propertylist_copy_property_regexp(lsf->
header, aHeader, regex, 1);
556 lsf->
img = cpl_imagelist_new();
558 for (i = 0; i < kMuseSlicesPerCCD; i++) {
559 cpl_imagelist_set(lsf->
img,
560 cpl_image_new(aNLsf, aNLambda, CPL_TYPE_FLOAT), i);
562 double lsf_step = 2*aLsfHalfRange / (aNLsf - 1),
563 lambda_step = (kMuseNominalLambdaMax - kMuseNominalLambdaMin)
566 lsf->
wcs->cd11 = lsf_step;
570 lsf->
wcs->crval1 = -aLsfHalfRange;
571 lsf->
wcs->
crval2 = kMuseNominalLambdaMin;
572 lsf->
wcs->crpix1 = 1.;
589 cpl_propertylist_delete(aLsfCube->
header);
590 cpl_imagelist_delete(aLsfCube->
img);
591 cpl_free(aLsfCube->
wcs);
605 cpl_ensure_code(aLsfCube, CPL_ERROR_NULL_INPUT);
606 cpl_error_code rc = cpl_propertylist_save(aLsfCube->
header, aFileName,
608 if (rc != CPL_ERROR_NONE) {
612 cpl_propertylist *header = cpl_propertylist_new();
613 cpl_propertylist_append_string(header,
"EXTNAME",
"LSF_PROFILE");
614 cpl_propertylist_append_int(header,
"WCSAXES", 2);
615 cpl_propertylist_append_double(header,
"CD1_1", aLsfCube->
wcs->cd11);
616 cpl_propertylist_append_double(header,
"CD1_2", aLsfCube->
wcs->cd12);
617 cpl_propertylist_append_double(header,
"CD2_1", aLsfCube->
wcs->cd21);
618 cpl_propertylist_append_double(header,
"CD2_2", aLsfCube->
wcs->
cd22);
619 cpl_propertylist_append_double(header,
"CRPIX1", aLsfCube->
wcs->crpix1);
620 cpl_propertylist_append_double(header,
"CRPIX2", aLsfCube->
wcs->
crpix2);
621 cpl_propertylist_append_double(header,
"CRVAL1", aLsfCube->
wcs->crval1);
622 cpl_propertylist_append_double(header,
"CRVAL2", aLsfCube->
wcs->
crval2);
623 cpl_propertylist_append_string(header,
"CTYPE1",
"PARAM");
624 cpl_propertylist_append_string(header,
"CTYPE2",
"AWAV");
625 cpl_propertylist_append_string(header,
"CUNIT1",
"Angstrom");
626 cpl_propertylist_append_string(header,
"CUNIT2",
"Angstrom");
628 rc = cpl_imagelist_save(aLsfCube->
img, aFileName,
629 CPL_TYPE_FLOAT, header, CPL_IO_EXTEND);
630 cpl_propertylist_delete(header);
650 cpl_ensure(aProcessing, CPL_ERROR_NULL_INPUT, NULL);
652 unsigned char ifu, nlsfs = 0;
653 for (ifu = 1; ifu <= kMuseNumIFUs; ifu++) {
655 MUSE_TAG_LSF_PROFILE, ifu, CPL_FALSE);
656 cpl_errorstate es = cpl_errorstate_get();
657 cpl_frame *frame = cpl_frameset_get_position(frames, 0);
659 cpl_msg_warning(__func__,
"No %s (cube format) specified for IFU %2hhu!",
660 MUSE_TAG_LSF_PROFILE, ifu);
661 cpl_errorstate_set(es);
662 cpl_frameset_delete(frames);
665 const char *fn = cpl_frame_get_filename(frame);
667 if (lsf[ifu-1] == NULL) {
668 cpl_msg_warning(__func__,
"Could not load LSF (cube format) for IFU %2hhu " 669 "from \"%s\"!", ifu, fn);
670 cpl_frameset_delete(frames);
675 cpl_frameset_delete(frames);
679 cpl_msg_error(__func__,
"Did not load any %ss (cube format)!",
680 MUSE_TAG_LSF_PROFILE);
684 cpl_msg_info(__func__,
"Successfully loaded %s%hhu %ss (cube format).",
685 nlsfs == kMuseNumIFUs ?
"all ":
"", nlsfs, MUSE_TAG_LSF_PROFILE);
702 for (ifu = 0; ifu < kMuseNumIFUs; ifu++) {
720 cpl_ensure(aFileName, CPL_ERROR_NULL_INPUT, NULL);
723 int ext = cpl_fits_find_extension(aFileName,
"LSF_PROFILE");
724 char *extname = NULL;
726 extname = cpl_sprintf(
"CHAN%02hhu.LSF_PROFILE", aIFU);
727 ext = cpl_fits_find_extension(aFileName, extname);
730 cpl_error_set(__func__, CPL_ERROR_DATA_NOT_FOUND);
737 lsf->
header = cpl_propertylist_load(aFileName, 0);
738 lsf->
img = cpl_imagelist_load(aFileName, CPL_TYPE_DOUBLE, ext);
740 if (lsf->
img == NULL) {
745 cpl_propertylist *header = cpl_propertylist_load(aFileName, ext);
746 if (header == NULL) {
763 cpl_propertylist_delete(header);
783 cpl_ensure(aLsfCube, CPL_ERROR_NULL_INPUT, NULL);
784 cpl_image *img = NULL;
786 cpl_size w[kMuseNumIFUs][kMuseSlicesPerCCD];
788 for (ifu = 0; ifu < kMuseNumIFUs; ifu++) {
790 for (i_slice = 0; i_slice < kMuseSlicesPerCCD; i_slice++) {
791 w[ifu][i_slice] = (aPixtable == NULL)?1.0:0.0;
798 uint32_t *origin = (uint32_t *)cpl_table_get_data_int(aPixtable->
table,
800 for (i_row = 0; i_row < n_rows; i_row++) {
803 w[i_ifu-1][i_slice-1]++;
807 for (ifu = 0; ifu < kMuseNumIFUs; ifu++) {
808 if (aLsfCube[ifu] == NULL) {
812 cpl_size n_slices = cpl_imagelist_get_size(aLsfCube[ifu]->img);
813 for (i_slice = 0; i_slice < n_slices; i_slice++) {
814 if (w[ifu][i_slice] > 0) {
815 cpl_image *m = cpl_imagelist_get(aLsfCube[ifu]->img, i_slice);
816 m = cpl_image_duplicate(m);
817 cpl_image_multiply_scalar(m, w[ifu][i_slice]);
818 wsum += w[ifu][i_slice];
822 cpl_errorstate pre = cpl_errorstate_get();
823 cpl_error_code rc = cpl_image_add(img, m);
825 if (rc != CPL_ERROR_NONE) {
826 cpl_msg_warning(__func__,
"Could not add cube of IFU %" 827 CPL_SIZE_FORMAT
": %s",
828 ifu+1, cpl_error_get_message());
829 cpl_errorstate_set(pre);
836 if ((img) && (wsum > 0)) {
837 cpl_image_divide_scalar(img, wsum);
840 cpl_image_delete(img);
862 cpl_ensure(aLsfCubes, CPL_ERROR_NULL_INPUT, NULL);
864 for (ifu = 0; ifu < kMuseNumIFUs; ifu++) {
865 if (aLsfCubes[ifu]) {
866 return aLsfCubes[ifu]->
wcs;
888 cpl_ensure_code(aLsfImage && aWCS, CPL_ERROR_NULL_INPUT);
889 cpl_ensure_code(aBinWidth > 0., CPL_ERROR_ILLEGAL_INPUT);
891 cpl_size ncol_kernel = aBinWidth / aWCS->cd11;
892 ncol_kernel = ((ncol_kernel + 1) / 2) * 2 + 1;
893 double r = ncol_kernel - aBinWidth / aWCS->cd11;
894 cpl_matrix *kernel = cpl_matrix_new(1, ncol_kernel);
895 cpl_matrix_fill(kernel, 1.0);
896 cpl_matrix_set(kernel, 0, 0, 1 - r/2);
897 cpl_matrix_set(kernel, 0, ncol_kernel-1, 1 - r/2);
898 cpl_image *lsfImage0 = cpl_image_duplicate(aLsfImage);
899 cpl_image_filter(aLsfImage, lsfImage0, kernel, CPL_FILTER_LINEAR,
901 cpl_matrix_delete(kernel);
902 cpl_image_delete(lsfImage0);
904 return CPL_ERROR_NONE;
924 cpl_array *aVal,
double aLambda)
926 cpl_ensure_code(aLsfImage, CPL_ERROR_NULL_INPUT);
927 cpl_ensure_code(aWCS, CPL_ERROR_NULL_INPUT);
928 cpl_ensure_code(aVal, CPL_ERROR_NULL_INPUT);
929 cpl_size n_lsf = cpl_image_get_size_x(aLsfImage);
930 cpl_size n_lambda = cpl_image_get_size_y(aLsfImage);
934 if (lambda_pix < 1) {
937 if (lambda_pix > n_lambda) {
938 lambda_pix = n_lambda;
940 cpl_size i_lambda = floor(lambda_pix);
941 lambda_pix -= i_lambda;
945 cpl_array *lsf_lambda = cpl_array_new(n_lsf + 4, CPL_TYPE_DOUBLE);
946 cpl_array *lsf_values = cpl_array_new(n_lsf + 4, CPL_TYPE_DOUBLE);
948 for (i = 1; i <= n_lsf; i++) {
950 double z = cpl_image_get(aLsfImage, i, i_lambda, &res);
951 if (lambda_pix > 0) {
952 z = z * (1 - lambda_pix)
953 + cpl_image_get(aLsfImage, i, i_lambda+1, &res) * lambda_pix;
955 cpl_array_set(lsf_values, i+1, z);
956 cpl_array_set(lsf_lambda, i+1, aWCS->crval1 + (i - aWCS->crpix1) * aWCS->cd11);
960 cpl_array_set(lsf_lambda, 0, -10000);
961 cpl_array_set(lsf_values, 0, 0);
962 cpl_array_set(lsf_lambda, 1, aWCS->crval1 - aWCS->crpix1 * aWCS->cd11);
963 cpl_array_set(lsf_values, 1, 0);
964 cpl_array_set(lsf_lambda, n_lsf+2, aWCS->crval1 + (n_lsf+1 - aWCS->crpix1) * aWCS->cd11);
965 cpl_array_set(lsf_values, n_lsf+2, 0);
966 cpl_array_set(lsf_lambda, n_lsf+3, 10000);
967 cpl_array_set(lsf_values, n_lsf+3, 0);
970 cpl_array *v = cpl_array_duplicate(lsf_values);
971 cpl_array_multiply(v, lsf_lambda);
972 double offset = cpl_array_get_mean(v)/cpl_array_get_mean(lsf_values);
974 cpl_array_subtract_scalar (lsf_lambda, offset);
977 double norm = cpl_array_get_mean(lsf_values) * (n_lsf + 4) * aWCS->cd11;
978 cpl_array_divide_scalar(lsf_values, norm);
984 memcpy(cpl_array_get_data_double(aVal), cpl_array_get_data_double(values),
985 cpl_array_get_size(aVal) *
sizeof(
double));
987 cpl_array_delete(values);
988 cpl_array_delete(lsf_lambda);
989 cpl_array_delete(lsf_values);
990 return CPL_ERROR_NONE;
1011 double aFlux, cpl_image *aLsfImage,
muse_wcs *aLsfWCS)
1013 cpl_propertylist *order = cpl_propertylist_new();
1015 cpl_table_sort(aPixtable->
table, order);
1016 cpl_propertylist_delete(order);
1020 cpl_array *lambda = NULL;
1022 == CPL_TYPE_DOUBLE) {
1027 "lambda_double", CPL_TYPE_DOUBLE);
1031 double l_min = aLsfWCS->crval1 + aLsfWCS->cd11 * (1 - aLsfWCS->crpix1),
1032 l_max = aLsfWCS->crval1
1033 + aLsfWCS->cd11 * (cpl_image_get_size_x(aLsfImage) - aLsfWCS->crpix1);
1036 cpl_array *l0 = cpl_array_extract(lambda, imin, imax-imin+1);
1037 cpl_array_subtract_scalar(l0, aWavelength);
1039 cpl_array_multiply_scalar(l0, aFlux);
1041 cpl_array_delete(l0);
1042 cpl_array_unwrap(lsf_data);
1043 cpl_array_unwrap(lambda);
1044 if (cpl_table_has_column(aPixtable->
table,
"lambda_double")) {
1045 cpl_table_erase_column(aPixtable->
table,
"lambda_double");
1048 return CPL_ERROR_NONE;
Structure definition for a collection of muse_images.
muse_wcs * wcs
Common WCS information for each slice.
void muse_pixtable_extracted_delete(muse_pixtable **aPixtables)
Delete a pixel table array.
double muse_pfits_get_cd(const cpl_propertylist *aHeaders, unsigned int aAxisI, unsigned int aAxisJ)
find out the WCS coordinate at the reference point
unsigned short muse_pixtable_origin_get_slice(uint32_t aOrigin)
Get the slice number from the encoded 32bit origin number.
cpl_size muse_pixtable_extracted_get_size(muse_pixtable **aPixtables)
Get the size of an array of extracted pixel tables.
cpl_propertylist * header
Primary header used to save the LSF cube to disk.
double muse_pfits_get_crval(const cpl_propertylist *aHeaders, unsigned int aAxis)
find out the WCS coordinate at the reference point
A structure containing a spatial two-axis WCS.
muse_pixtable ** muse_pixtable_extracted_get_slices(muse_pixtable *aPixtable)
Extract one pixel table per IFU and slice.
cpl_size muse_pixtable_get_nrow(const muse_pixtable *aPixtable)
get the number of rows within the pixel table
cpl_image * muse_lsf_average_cube_all(muse_lsf_cube **aLsfCube, muse_pixtable *aPixtable)
Create an average image from all LSF cubes.
Data cube/stacked image list containing the LSF for one IFU.
muse_lsf_cube * muse_lsf_cube_new(double aLsfHalfRange, cpl_size aNLsf, cpl_size aNLambda, const cpl_propertylist *aHeader)
Create a new LSF datacube.
Structure definition of MUSE three extension FITS file.
cpl_error_code muse_lsf_cube_save(muse_lsf_cube *aLsfCube, const char *aFileName)
Save the LSF cube to disk.
cpl_table * table
The pixel table.
#define MUSE_PIXTABLE_DATA
unsigned int muse_imagelist_get_size(muse_imagelist *aList)
Return the number of stored images.
cpl_error_code muse_lsf_apply_slice(muse_pixtable *aPixtable, double aWavelength, double aFlux, cpl_image *aLsfImage, muse_wcs *aLsfWCS)
Add line spread function to a MUSE slice of a pixtable.
cpl_table * muse_cpltable_new(const muse_cpltable_def *aDef, cpl_size aLength)
Create an empty table according to the specified definition.
muse_lsf_cube * muse_lsf_cube_load(const char *aFileName, unsigned char aIFU)
Load a LSF cube for one single IFU from disk.
const char * muse_wave_lines_get_lampname(cpl_table *aTable, const int aIdx)
Associate the ion listed in a linelist table row to a lamp name.
double muse_pfits_get_crpix(const cpl_propertylist *aHeaders, unsigned int aAxis)
find out the WCS reference point
Structure definition of MUSE pixel table.
cpl_boolean muse_wave_lines_covered_by_data(double aLambda, muse_ins_mode aMode)
Check, if a given wavelength is covered by a given instrument mode.
#define MUSE_WCS_KEYS
regular expression for WCS properties
muse_image * muse_imagelist_get(muse_imagelist *aList, unsigned int aIdx)
Get the muse_image of given list index.
cpl_array * muse_cpltable_extract_column(cpl_table *aTable, const char *aColumn)
Create an array from a section of a column.
muse_lsf_cube ** muse_lsf_cube_load_all(muse_processing *aProcessing)
Load all LSF cubes for all IFUs into an array.
cpl_array * muse_cplarray_interpolate_linear(const cpl_array *aTargetAbscissa, const cpl_array *aSourceAbscissa, const cpl_array *aSourceOrdinate)
Linear interpolation of a 1d array.
void muse_processing_append_used(muse_processing *aProcessing, cpl_frame *aFrame, cpl_frame_group aGroup, int aDuplicate)
Add a frame to the set of used frames.
cpl_error_code muse_lsf_apply(const cpl_image *aLsfImage, const muse_wcs *aWCS, cpl_array *aVal, double aLambda)
Apply the LSF to a number of data points of one slice.
muse_pixtable * muse_pixtable_create(muse_image *aImage, cpl_table *aTrace, cpl_table *aWave, cpl_table *aGeoTable)
Create the pixel table for one CCD.
cpl_error_code muse_cplarray_add_window(cpl_array *aDest, cpl_size aStart, const cpl_array *aArray)
Add the value of an array to a window of a table column.
char * muse_utils_header_get_lamp_names(cpl_propertylist *aHeader, char aSep)
Concatenate names of all active calibration lamps.
#define MUSE_PIXTABLE_ORIGIN
cpl_size muse_cpltable_find_sorted(const cpl_table *aTable, const char *aColumn, double aValue)
Find a row in a table.
unsigned short muse_pixtable_origin_get_ifu(uint32_t aOrigin)
Get the IFU number from the encoded 32bit origin number.
#define MUSE_PIXTABLE_STAT
void muse_lsf_cube_delete_all(muse_lsf_cube **aLsfCube)
Delete all LSF cubes.
const muse_cpltable_def muse_pixtable_def[]
MUSE pixel table definition.
muse_wcs * muse_lsf_cube_get_wcs_all(muse_lsf_cube **aLsfCubes)
Get the world coordinate representative of all LSF cubes.
#define MUSE_PIXTABLE_LAMBDA
muse_pixtable * muse_lsf_create_arcpixtable(muse_imagelist *aImages, cpl_table *aTrace, cpl_table *aWave, cpl_table *aArcLines, int aQuality, double aWindow)
Read images and combine the arc lines into one pixtable.
cpl_error_code muse_lsf_fold_rectangle(cpl_image *aLsfImage, const muse_wcs *aWCS, double aBinWidth)
Filter an LSF image with a rectangle to model spectrum binning.
void muse_lsf_cube_delete(muse_lsf_cube *aLsfCube)
Deallocate the memory for the LSF cube.
cpl_imagelist * img
Stacked image list for LSF; one per slice.
cpl_frameset * muse_frameset_find(const cpl_frameset *aFrames, const char *aTag, unsigned char aIFU, cpl_boolean aInvert)
return frameset containing data from an IFU/channel with a certain tag
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
cpl_size muse_cplarray_find_sorted(const cpl_array *aArray, double aValue)
Find a row in an array.
muse_ins_mode muse_pfits_get_mode(const cpl_propertylist *aHeaders)
find out the observation mode
cpl_error_code muse_lsf_fit_slice(const muse_pixtable *aPixtable, cpl_image *aLsfImage, muse_wcs *aWCS, double aLsfRegressionWindow)
Compute the LSF for all wavelengths of one slice.
cpl_propertylist * header
The FITS header.