33 #include "muse_postproc.h" 34 #include "muse_instrument.h" 36 #include "muse_astro.h" 39 #include "muse_imagelist.h" 40 #include "muse_pfits.h" 41 #include "muse_phys.h" 42 #include "muse_quality.h" 43 #include "muse_raman.h" 45 # include "muse_sky_old.h" 47 #include "muse_utils.h" 80 case MUSE_POSTPROC_SCIPOST:
81 case MUSE_POSTPROC_STANDARD:
82 case MUSE_POSTPROC_ASTROMETRY:
86 cpl_msg_error(__func__,
"No such setup known: %d", aType);
87 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT);
112 cpl_propertylist_delete(aProp->
wcs);
114 #ifdef USE_LSF_PARAMS 137 cpl_ensure(aSave, CPL_ERROR_NULL_INPUT, CPL_FALSE);
138 if (strlen(aSave) < 4) {
139 cpl_error_set_message(__func__, CPL_ERROR_DATA_NOT_FOUND,
140 "no (valid) save option given!");
144 cpl_boolean allvalid = CPL_TRUE;
148 ns = cpl_array_get_size(asave),
149 nv = cpl_array_get_size(avalid);
150 for (i = 0; i < ns; i++) {
151 cpl_boolean valid = CPL_FALSE;
152 for (j = 0; j < nv; j++) {
153 if (!strcmp(cpl_array_get_string(asave, i),
154 cpl_array_get_string(avalid, j))) {
159 cpl_error_set_message(__func__, CPL_ERROR_ILLEGAL_INPUT,
160 "save option %d (%s) is not valid!", i + 1,
161 cpl_array_get_string(asave, i));
162 allvalid = CPL_FALSE;
165 cpl_array_delete(asave);
166 cpl_array_delete(avalid);
190 if (!strncmp(aResampleString,
"nearest", 8)) {
193 if (!strncmp(aResampleString,
"linear", 7)) {
196 if (!strncmp(aResampleString,
"quadratic", 10)) {
199 if (!strncmp(aResampleString,
"renka", 6)) {
202 if (!strncmp(aResampleString,
"drizzle", 8)) {
205 if (!strncmp(aResampleString,
"lanczos", 8)) {
231 if (!strncmp(aCRTypeString,
"iraf", 5)) {
234 if (!strncmp(aCRTypeString,
"mean", 5)) {
237 if (!strncmp(aCRTypeString,
"median", 7)) {
262 if (!strncmp(aFormatString,
"Cube", 5)) {
265 if (!strncmp(aFormatString,
"Euro3D", 7)) {
268 if (!strncmp(aFormatString,
"xCube", 6)) {
271 if (!strncmp(aFormatString,
"xEuro3D", 8)) {
274 if (!strncmp(aFormatString,
"sdpCube", 8)) {
299 if (!strncmp(aWeightString,
"exptime", 8)) {
302 if (!strncmp(aWeightString,
"fwhm", 5)) {
305 if (!strncmp(aWeightString,
"none", 5)) {
339 const cpl_frame *aFrame,
float aWarnLimit,
340 float aErrLimit,
double *aRA,
double *aDEC)
342 cpl_ensure(aHeader && aFrame, CPL_ERROR_NULL_INPUT, NULL);
343 cpl_errorstate state = cpl_errorstate_get();
346 cpl_ensure(cpl_errorstate_is_equal(state), CPL_ERROR_DATA_NOT_FOUND, NULL);
347 cpl_msg_debug(__func__,
"reference coordinates: RA = %e deg, DEC =%e deg",
356 const char *fn = cpl_frame_get_filename(aFrame);
357 cpl_propertylist *header;
358 double dmin = FLT_MAX;
359 int iext, inearest = -1, next = cpl_fits_count_extensions(fn);
360 for (iext = 1; iext <= next; iext++) {
361 header = cpl_propertylist_load(fn, iext);
362 const char *extname = cpl_propertylist_get_string(header,
"EXTNAME");
366 cpl_msg_debug(__func__,
"extension %d [%s]: RA = %e deg, DEC = %e deg --> " 367 "d = %e deg", iext, extname, ra, dec, d);
372 cpl_propertylist_delete(header);
375 if (dmin * 3600. > aErrLimit) {
376 char *msg = cpl_sprintf(
"Distance of nearest reference table to observed " 377 "position is %.2f arcmin, certainly a wrong " 378 "reference object!", dmin * 60.);
379 cpl_msg_error(__func__,
"%s", msg);
380 cpl_error_set_message(__func__, CPL_ERROR_INCOMPATIBLE_INPUT,
"%s", msg);
384 if (dmin * 3600. > aWarnLimit) {
385 cpl_msg_warning(__func__,
"Distance of nearest reference table to observed " 386 "position is %.2f arcmin! (Wrong reference object?)",
389 header = cpl_propertylist_load(fn, inearest);
390 const char *extname = cpl_propertylist_get_string(header,
"EXTNAME");
391 cpl_msg_info(__func__,
"Loading \"%s[%s]\" (distance %.1f arcsec)", fn,
392 extname, dmin * 3600.);
393 cpl_propertylist_delete(header);
394 cpl_table *table = cpl_table_load(fn, inearest, 1);
419 cpl_ensure_code(aPt && aPt->
header, CPL_ERROR_NULL_INPUT);
421 return CPL_ERROR_NONE;
425 cpl_boolean respff = cpl_propertylist_has(aResponse->
header,
426 MUSE_HDR_FLUX_FFCORR),
428 if (respff == ptff || !ptff) {
431 return CPL_ERROR_NONE;
434 cpl_msg_warning(__func__,
"Adapt pixel table to %s for backward compatibility" 435 ": revert correction by flat-field spectrum!",
436 MUSE_TAG_STD_RESPONSE);
444 MUSE_PIXTABLE_OPERATION_DIVIDE);
445 cpl_array_unwrap(lambdas);
446 cpl_array_unwrap(ffdata);
447 cpl_table_delete(aPt->
ffspec);
450 cpl_msg_info(__func__,
"Pixel table now convolved with flat-field spectrum " 452 return CPL_ERROR_NONE;
471 cpl_ensure(aPixtable, CPL_ERROR_NULL_INPUT, NULL);
473 cpl_boolean usegrid = getenv(
"MUSE_COLLAPSE_PIXTABLE")
474 && atoi(getenv(
"MUSE_COLLAPSE_PIXTABLE")) > 0;
484 usegrid ? &grid : NULL);
486 cpl_msg_error(__func__,
"Could not create cube for whitelight image");
496 cube, fwhite, params);
534 static cpl_error_code
536 const cpl_table *aOffsets,
540 cpl_ensure_code(aPT && aProp, CPL_ERROR_NULL_INPUT);
545 cpl_msg_info(__func__,
"Preparing masking for self-calibration using input " 547 cpl_errorstate state = cpl_errorstate_get();
548 cpl_table_select_all(aPT->
table);
549 cpl_size nbefore = cpl_table_count_selected(aPT->
table);
551 cpl_size nafter = cpl_table_count_selected(aPT->
table);
552 if (!cpl_errorstate_is_equal(state)) {
553 if (nafter < nbefore) {
554 cpl_msg_warning(__func__,
"An error occurred during pixel selection " 555 "using %s: %s", MUSE_TAG_SKY_MASK,
556 cpl_error_get_message());
560 cpl_errorstate_set(state);
562 cpl_msg_error(__func__,
"Selecting sky pixels using %s failed: %s",
563 MUSE_TAG_SKY_MASK, cpl_error_get_message());
564 return cpl_error_get_code();
569 cpl_msg_info(__func__,
"Intermediate resampling to produce white-light " 570 "image to create auto calibration mask");
571 cpl_msg_indent_more();
578 cpl_msg_error(__func__,
"Could not create cube for white-light image");
579 return CPL_ERROR_ILLEGAL_OUTPUT;
584 cpl_msg_indent_less();
588 cpl_table_select_all(aPT->
table);
591 aACalOut->
mask = skymask;
595 cpl_size nsel = cpl_table_count_selected(aPT->
table);
596 cpl_msg_info(__func__,
"Mask selected %"CPL_SIZE_FORMAT
" pixels (%.2f %%) ",
597 nsel, 100.*nsel/nrows);
606 *aWhite = whitelight;
612 if (getenv(
"MUSE_DEBUG_AUTOCALIB")) {
613 cpl_msg_debug(__func__,
"Saving pixel table mask");
615 cpl_table_new_column(aPT->
table,
"MASK", CPL_TYPE_INT);
616 for (cpl_size n = 0; n < nrows; n++) {
617 cpl_table_set_int(aPT->
table,
"MASK", n,
618 cpl_table_is_selected(aPT->
table, n) == 0 ? 1 : 0);
625 cpl_table_select_all(aPT->
table);
663 const cpl_table *aOffsets,
669 cpl_ensure_code(aPT && aProp, CPL_ERROR_NULL_INPUT);
671 cpl_msg_error(__func__,
"Raman signal modelling not done, given width " 672 "parameter only %.2f Angstrom (should be %.2f at least)!",
674 return cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT);
677 cpl_msg_error(__func__,
"Raman signal modelling not done, %s missing!",
678 MUSE_TAG_RAMAN_LINES);
679 return cpl_error_set(__func__, CPL_ERROR_DATA_NOT_FOUND);
682 cpl_msg_error(__func__,
"Raman signal modelling not done, %s missing!",
683 MUSE_TAG_LSF_PROFILE);
684 return cpl_error_set(__func__, CPL_ERROR_DATA_NOT_FOUND);
688 double wl[MUSE_RAMAN_RANGES] = {
694 if (llo > wl[1] || lhi < wl[0]) {
695 cpl_msg_info(__func__,
"Available wavelengths (%.3f ... %.3f) do not cover " 696 "Raman features, not trying to correct them.", llo, lhi);
697 return CPL_ERROR_NONE;
700 double cputime = cpl_test_get_cputime(),
701 walltime = cpl_test_get_walltime();
704 cpl_msg_debug(__func__,
"Adding temporary pixel table columns...");
708 cpl_msg_debug(__func__,
"... lsf ...");
709 cpl_table_new_column(aPT->
table,
"lsf", CPL_TYPE_DOUBLE);
710 cpl_table_fill_column_window_double(aPT->
table,
"lsf", 0,
711 cpl_table_get_nrow(aPT->
table), 0);
714 cpl_msg_debug(__func__,
"... raman ...");
715 cpl_table_new_column(aPT->
table,
"raman", CPL_TYPE_DOUBLE);
716 cpl_table_fill_column_window_double(aPT->
table,
"raman", 0,
717 cpl_table_get_nrow(aPT->
table), 0);
718 cpl_msg_debug(__func__,
"... done.");
725 for (i = 0; i < MUSE_RAMAN_RANGES; i++) {
730 cpl_msg_warning(__func__,
"Raman correction for %s feature not possible, " 731 "%.3f..%.3f Angstrom is outside the wavelength range!",
732 i == 0 ?
"O2" :
"N2", lo, hi);
741 cpl_msg_info(__func__,
"Intermediate resampling to produce white-light image" 742 " for Raman correction (%s feature, %.3f..%.3f Angstrom):",
743 i == 0 ?
"O2" :
"N2", lo, hi);
744 cpl_msg_indent_more();
746 cpl_msg_indent_less();
757 cpl_propertylist_erase_regexp(images[i]->header,
"ESO DRS MUSE", 0);
758 cpl_propertylist_update_string(images[i]->header,
"BUNIT",
"");
761 cpl_image_fill_rejected(images[i]->data, NAN);
762 cpl_image_delete(images[i]->dq);
763 images[i]->
dq = NULL;
770 if (!sky_maskr[0] && !sky_maskr[1]) {
772 cpl_msg_info(__func__,
"Neither O2 nor N2 features can be analysed, not " 773 "carrying out Raman correction.");
774 for (i = 0; i < MUSE_RAMAN_RANGES; i++) {
778 cpl_table_erase_column(aPT->
table,
"raman");
779 cpl_table_erase_column(aPT->
table,
"lsf");
780 return CPL_ERROR_NONE;
785 for (i = 0; i < MUSE_RAMAN_RANGES; i++) {
786 if (!pt[i] || !sky_maskr[i]) {
790 cpl_table_select_all(pt[i]->table);
791 for (j = 0; j < MUSE_RAMAN_RANGES; j++) {
792 if (!pt[j] || !sky_maskr[j]) {
802 cpl_table_not_selected(pt[i]->table);
803 cpl_table_erase_selected(pt[i]->table);
808 CPL_NOT_EQUAL_TO, EURO3D_GOODPIXEL);
809 cpl_table_erase_selected(pt[i]->table);
813 for (i = 0; !aRamanCube && i < MUSE_RAMAN_RANGES; i++) {
818 for (i = 0; i < MUSE_RAMAN_RANGES; i++) {
829 for (i = 0; i < MUSE_RAMAN_RANGES; i++) {
835 const char *colunit = cpl_table_get_column_unit(aProp->
raman_lines,
"flux");
839 if (strstr(colunit,
"10**(-20)") || strstr(colunit,
"10^(-20)")) {
841 char *p = strstr(colunit,
"erg");
842 unit = cpl_sprintf(
"%s", p);
845 unit = cpl_sprintf(
"%s", colunit);
848 double totflux[MUSE_RAMAN_RANGES];
849 for (i = 0; i < MUSE_RAMAN_RANGES; i++) {
851 totflux[i] = cpl_array_get(param, 5 + i, NULL) * fscale;
855 cpl_table_and_selected_int(aProp->
raman_lines,
"group", CPL_EQUAL_TO, i);
856 cpl_table *t = cpl_table_extract_selected(aProp->
raman_lines);
857 double sum = cpl_table_get_nrow(t) * cpl_table_get_column_mean(t,
"flux");
864 cpl_msg_info(__func__,
"spatial: %g x^2 %+g xy %+g y^2 %+g x %+g y +1",
865 cpl_array_get(param, 0, NULL), cpl_array_get(param, 1, NULL),
866 cpl_array_get(param, 2, NULL), cpl_array_get(param, 3, NULL),
867 cpl_array_get(param, 4, NULL));
868 cpl_msg_info(__func__,
"O2 flux = %g, N2 flux = %g %s", totflux[0], totflux[1],
874 for (i = 0; i < MUSE_RAMAN_RANGES; i++) {
886 (*aRamanCube)->data = cpl_imagelist_new();
888 cpl_imagelist_set((*aRamanCube)->data, cpl_image_duplicate(fits[0]->data), 0);
889 (*aRamanCube)->header = cpl_propertylist_duplicate(fits[0]->header);
891 cpl_imagelist_set((*aRamanCube)->data, cpl_image_duplicate(fits[1]->data), 0);
892 (*aRamanCube)->header = cpl_propertylist_duplicate(fits[1]->header);
896 cpl_propertylist_append_double((*aRamanCube)->header, QC_POST_RAMAN_SP_XX,
897 cpl_array_get(param, 0, NULL));
898 cpl_propertylist_append_double((*aRamanCube)->header, QC_POST_RAMAN_SP_XY,
899 cpl_array_get(param, 1, NULL));
900 cpl_propertylist_append_double((*aRamanCube)->header, QC_POST_RAMAN_SP_YY,
901 cpl_array_get(param, 2, NULL));
902 cpl_propertylist_append_double((*aRamanCube)->header, QC_POST_RAMAN_SP_X,
903 cpl_array_get(param, 3, NULL));
904 cpl_propertylist_append_double((*aRamanCube)->header, QC_POST_RAMAN_SP_Y,
905 cpl_array_get(param, 4, NULL));
906 cpl_propertylist_append_float((*aRamanCube)->header, QC_POST_RAMAN_FLUXO2,
908 cpl_propertylist_append_float((*aRamanCube)->header, QC_POST_RAMAN_FLUXN2,
914 for (i = 0; i < MUSE_RAMAN_RANGES; i++) {
920 masks[i]->
header = cpl_propertylist_duplicate(sky_maskr[i]->header);
921 masks[i]->
data = cpl_image_new_from_mask(sky_maskr[i]->mask);
928 cpl_image_multiply_scalar(fits[i]->data, totflux[i]);
929 cpl_propertylist_update_string(fits[i]->header,
"BUNIT",
930 kMuseFluxUnitString);
934 (*aRamanCube)->recnames = cpl_array_new(6, CPL_TYPE_STRING);
935 cpl_errorstate state = cpl_errorstate_get();
942 if (!cpl_errorstate_is_equal(state)) {
943 cpl_msg_debug(__func__,
"Some images for the Raman cube were not saved...");
945 cpl_errorstate_set(state);
947 cpl_array_set_string((*aRamanCube)->recnames, 0,
"RAMAN_IMAGE_O2");
948 cpl_array_set_string((*aRamanCube)->recnames, 1,
"SKY_MASK_O2");
949 cpl_array_set_string((*aRamanCube)->recnames, 2,
"RAMAN_IMAGE_N2");
950 cpl_array_set_string((*aRamanCube)->recnames, 3,
"SKY_MASK_N2");
951 cpl_array_set_string((*aRamanCube)->recnames, 4,
"RAMAN_FIT_O2");
952 cpl_array_set_string((*aRamanCube)->recnames, 5,
"RAMAN_FIT_N2");
960 for (i = 0; i < MUSE_RAMAN_RANGES; i++) {
961 double flux = cpl_array_get(param, 5 + i, NULL);
964 cpl_msg_info(__func__,
"Simulate Raman light with given parameters");
967 cpl_array_delete(param);
968 cpl_array_unwrap(raman);
969 cpl_msg_info(__func__,
"Subtract Raman light");
973 cpl_table_erase_column(aPT->
table,
"raman");
974 cpl_table_erase_column(aPT->
table,
"lsf");
976 cpl_msg_debug(__func__,
"Raman correction took %gs (CPU time), %gs (wall-clock)",
977 cpl_test_get_cputime() - cputime,
978 cpl_test_get_walltime() - walltime);
980 return CPL_ERROR_NONE;
1032 unsigned int aIndex,
1036 const cpl_table *aOffsets)
1038 cpl_ensure(aProp && aProp->
exposures, CPL_ERROR_NULL_INPUT, NULL);
1039 cpl_ensure((
int)aIndex < cpl_table_get_nrow(aProp->
exposures),
1040 CPL_ERROR_ILLEGAL_INPUT, NULL);
1041 cpl_msg_info(__func__,
"Starting to process exposure %d (DATE-OBS=%s)",
1042 aIndex + 1, cpl_table_get_string(aProp->
exposures,
"DATE-OBS",
1044 cpl_ensure(aProp->
exposures, CPL_ERROR_NULL_INPUT, NULL);
1046 cpl_table *exposure = cpl_table_extract(aProp->
exposures, aIndex, 1);
1050 cpl_table_delete(exposure);
1055 cpl_propertylist_erase_regexp(pt->
header,
"ESO QC ", 0);
1058 if (getenv(
"MUSE_SUPERFLAT_POS")) {
1060 getenv(
"MUSE_SUPERFLAT_POS"),
",");
1061 int nval = cpl_array_get_size(values);
1063 cpl_msg_error(__func__,
"MUSE_SUPERFLAT_POS needs 3 parameters, only" 1064 "%d were found.", nval);
1065 cpl_array_delete(values);
1067 double ra = atof(cpl_array_get_string(values, 0));
1068 cpl_propertylist_set_double(pt->
header,
"RA", ra);
1069 double dec = atof(cpl_array_get_string(values, 1));
1070 cpl_propertylist_set_double(pt->
header,
"DEC", dec);
1071 double drot = atof(cpl_array_get_string(values, 2));
1072 cpl_propertylist_set_double(pt->
header,
"ESO INS DROT POSANG", drot);
1073 cpl_msg_info(__func__,
"Overriding RA=%f, DEC=%f, DROT=%f", ra, dec, drot);
1074 cpl_array_delete(values);
1082 cpl_boolean labdata = CPL_FALSE;
1083 cpl_errorstate prestate = cpl_errorstate_get();
1088 if (!cpl_errorstate_is_equal(prestate) || airmass < 1.) {
1089 cpl_msg_warning(__func__,
"This seems to be lab data (RA=%f DEC=%f, " 1090 "airmass=%f), not doing any DAR correction!", ra, dec,
1092 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
1093 cpl_errorstate_set(prestate);
1096 cpl_error_code rc = CPL_ERROR_NONE;
1098 cpl_msg_debug(__func__,
"WFM detected: starting DAR correction");
1100 cpl_msg_debug(__func__,
"DAR correction returned rc=%d: %s", rc,
1101 rc != CPL_ERROR_NONE ? cpl_error_get_message() :
"");
1104 if (aProp->
darcheck != MUSE_POSTPROC_DARCHECK_NONE) {
1105 cpl_boolean dorefine = aProp->
darcheck == MUSE_POSTPROC_DARCHECK_CORRECT;
1106 double maxshift = 0;
1108 if (rc != CPL_ERROR_NONE) {
1109 cpl_msg_warning(__func__,
"Maximum %s shift %f\'\' (rc = %d: %s)",
1110 dorefine ?
"corrected" :
"detected", maxshift, rc,
1111 cpl_error_get_message());
1113 cpl_msg_info(__func__,
"Maximum %s shift %f\'\'",
1114 dorefine ?
"corrected" :
"detected", maxshift);
1119 if (aProp->
type != MUSE_POSTPROC_STANDARD) {
1123 if (rc != CPL_ERROR_NONE && rc != CPL_ERROR_UNSUPPORTED_MODE) {
1126 cpl_msg_warning(__func__,
"Flux calibration returned rc=%d: %s", rc,
1127 cpl_error_get_message());
1131 cpl_msg_debug(__func__,
"Flux calibration returned rc=%d: %s", rc,
1132 rc != CPL_ERROR_NONE ? cpl_error_get_message_default(rc) :
"");
1135 cpl_msg_info(__func__,
"Skipping flux calibration (no %s curve)",
1136 MUSE_TAG_STD_RESPONSE);
1146 if (aProp->
autocalib == MUSE_POSTPROC_AUTOCALIB_DEEPFIELD) {
1147 muse_postproc_run_autocalib(pt, aProp, aOffsets, aACalOut, &cube,
1158 cpl_table *sky_cont = NULL,
1161 (aProp->
skymethod == MUSE_POSTPROC_SKYMETHOD_SIMPLE)) {
1165 cpl_table_select_all(sky_pt->
table);
1171 cpl_msg_info(__func__,
"Intermediate resampling to produce white-light image" 1172 " for sky-spectrum creation:");
1173 cpl_msg_indent_more();
1180 cpl_msg_error(__func__,
"Could not create cube for whitelight image");
1189 cpl_msg_indent_less();
1197 cpl_table_select_all(sky_pt->
table);
1199 cpl_table *spectrum =
1202 if (aProp->
skymethod == MUSE_POSTPROC_SKYMETHOD_MODEL) {
1205 double lambda_low = cpl_array_get_min(lambda),
1206 lambda_high = cpl_array_get_max(lambda);
1207 sky_lines = cpl_table_duplicate(aProp->
sky_lines);
1211 prestate = cpl_errorstate_get();
1219 if (!cpl_errorstate_is_equal(prestate)) {
1220 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
1221 cpl_errorstate_set(prestate);
1226 cpl_msg_info(__func__,
"No sky continuum given, create it from the data");
1230 cpl_msg_info(__func__,
"Using sky continuum given as input");
1234 cpl_image_delete(lsfImage);
1235 #ifdef USE_LSF_PARAMS 1239 if (!cpl_errorstate_is_equal(prestate)) {
1240 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
1241 cpl_errorstate_set(prestate);
1245 cpl_msg_info(__func__,
"No sky continuum given, create it from the data");
1249 cpl_table_erase_column(sky_cont,
"stat");
1250 cpl_table_erase_column(sky_cont,
"dq");
1251 cpl_table_name_column(sky_cont,
"data",
"flux");
1255 cpl_array_unwrap(lambda);
1259 cpl_table *spec2 = cpl_table_duplicate(spectrum);
1260 cpl_table_name_column(spec2,
"data",
"flux");
1262 cpl_table_delete(spec2);
1265 aSkyOut->
mask = sky_mask;
1269 cpl_table_delete(spectrum);
1274 aSkyOut->
image = whitelight;
1283 if ((aProp->
skymethod == MUSE_POSTPROC_SKYMETHOD_NONE) ||
1284 (aProp->
skymethod == MUSE_POSTPROC_SKYMETHOD_MODEL)) {
1286 cpl_msg_debug(__func__,
"doing sky continuum subtraction with input " 1289 }
else if (sky_cont) {
1290 cpl_msg_debug(__func__,
"doing sky continuum subtraction with created " 1295 cpl_msg_debug(__func__,
"doing sky line subtraction with created list");
1298 #ifdef USE_LSF_PARAMS 1304 cpl_msg_debug(__func__,
"doing sky line subtraction with input list");
1307 #ifdef USE_LSF_PARAMS 1317 aSkyOut->
lines = sky_lines;
1320 cpl_table_delete(sky_lines);
1321 cpl_table_delete(sky_cont);
1328 if (aProp->
type == MUSE_POSTPROC_STANDARD) {
1329 double raref, decref;
1334 cpl_msg_error(__func__,
"Correct %s could not be loaded, observed " 1335 "target not listed?", MUSE_TAG_STD_FLUX_TABLE);
1340 cpl_msg_error(__func__,
"%s does not have a recognized format!",
1341 MUSE_TAG_STD_FLUX_TABLE);
1342 cpl_table_delete(reftable);
1347 prestate = cpl_errorstate_get();
1351 cpl_msg_debug(__func__,
"Flux integration found %"CPL_SIZE_FORMAT
" stars",
1356 cpl_msg_warning(__func__,
"Invalid airmass derived (%.3e), resetting to " 1360 flux->
raref = raref;
1364 cpl_table_delete(reftable);
1369 if (!cpl_errorstate_is_equal(prestate)) {
1370 cpl_msg_warning(__func__,
"The following errors happened while computing " 1371 "the flux calibration (rc = %d/%s):", rc,
1372 cpl_error_get_message_default(rc));
1379 if (aProp->
type == MUSE_POSTPROC_ASTROMETRY) {
1384 cpl_msg_error(__func__,
"Correct %s could not be loaded, observed " 1385 "target not listed?", MUSE_TAG_ASTROMETRY_REFERENCE);
1389 prestate = cpl_errorstate_get();
1392 wcs->crpix1 = aProp->crpix1;
1393 wcs->crpix2 = aProp->
crpix2;
1406 cpl_propertylist_update_float(wcs->wcs, MUSE_HDR_WCS_DETSIGMA,
1408 cpl_propertylist_set_comment(wcs->wcs, MUSE_HDR_WCS_DETSIGMA,
1409 MUSE_HDR_WCS_DETSIGMA_C_ONE);
1412 cpl_table_delete(reftable);
1413 cpl_msg_debug(__func__,
"Solving astrometry (initial radius %.1f pix, " 1414 "initial relative accuracy %.1f, %d iterations with rejection" 1415 " sigma %.2f) returned rc=%d: %s", aProp->
radius,
1417 rc, rc != CPL_ERROR_NONE ? cpl_error_get_message() :
"");
1420 if (!cpl_errorstate_is_equal(prestate)) {
1421 cpl_msg_warning(__func__,
"The following errors happened while computing " 1422 "the astrometric solution (rc = %d/%s):", rc,
1423 cpl_error_get_message());
1430 cpl_propertylist *wcs = aProp->
wcs;
1434 cpl_msg_warning(__func__,
"Using default MUSE %cFM astrometry, output world" 1435 " coordinates will be inaccurate!", mode[0]);
1439 cpl_msg_debug(__func__,
"Astrometry correction returned rc=%d: %s", rc,
1440 rc != CPL_ERROR_NONE ? cpl_error_get_message() :
"");
1442 cpl_propertylist_delete(wcs);
1464 const char *aPurpose)
1466 if (!aPT || !aOffsets) {
1472 cpl_msg_info(__func__,
"Applying offsets to %s...", aPurpose);
1473 cpl_msg_indent_more();
1478 char keyword[KEYWORD_LENGTH], comment[KEYWORD_LENGTH];
1480 if (isfinite(offsets[0]) && isfinite(offsets[1])) {
1483 cpl_msg_debug(__func__,
"Applying coordinate offsets to exposure: %e/%e" 1484 " deg", offsets[0], offsets[1]);
1486 cpl_errorstate state = cpl_errorstate_get();
1487 cpl_propertylist_update_double(aPT->
header,
"RA", ra);
1488 if (!cpl_errorstate_is_equal(state)) {
1489 cpl_errorstate_set(state);
1490 cpl_propertylist_update_float(aPT->
header,
"RA", ra);
1492 cpl_propertylist_set_comment(aPT->
header,
"RA",
"offset applied!");
1493 state = cpl_errorstate_get();
1494 cpl_propertylist_update_double(aPT->
header,
"DEC", dec);
1495 if (!cpl_errorstate_is_equal(state)) {
1496 cpl_errorstate_set(state);
1497 cpl_propertylist_update_float(aPT->
header,
"DEC", dec);
1499 cpl_propertylist_set_comment(aPT->
header,
"DEC",
"offset applied!");
1501 snprintf(keyword, KEYWORD_LENGTH, MUSE_HDR_OFFSETi_DRA, 1);
1502 snprintf(comment, KEYWORD_LENGTH, MUSE_HDR_OFFSETi_DRA_C, offsets[0] * 3600.);
1503 cpl_propertylist_append_double(aPT->
header, keyword, offsets[0]);
1504 cpl_propertylist_set_comment(aPT->
header, keyword, comment);
1505 snprintf(keyword, KEYWORD_LENGTH, MUSE_HDR_OFFSETi_DDEC, 1);
1506 snprintf(comment, KEYWORD_LENGTH, MUSE_HDR_OFFSETi_DDEC_C, offsets[1] * 3600.);
1507 cpl_propertylist_append_double(aPT->
header, keyword, offsets[1]);
1508 cpl_propertylist_set_comment(aPT->
header, keyword, comment);
1510 if (isnormal(offsets[2])) {
1512 cpl_msg_debug(__func__,
"Scaling flux of exposure by %g.", offsets[2]);
1515 snprintf(keyword, KEYWORD_LENGTH, MUSE_HDR_FLUX_SCALEi, 1);
1516 cpl_propertylist_append_double(aPT->
header, keyword, offsets[2]);
1517 cpl_propertylist_set_comment(aPT->
header, keyword, MUSE_HDR_FLUX_SCALEi_C);
1520 snprintf(keyword, KEYWORD_LENGTH, MUSE_HDR_OFFSETi_DATEOBS, 1);
1521 snprintf(comment, KEYWORD_LENGTH, MUSE_HDR_OFFSETi_DATEOBS_C, 1);
1522 cpl_propertylist_append_string(aPT->
header, keyword,
1524 cpl_propertylist_set_comment(aPT->
header, keyword, comment);
1527 cpl_msg_indent_less();
1552 cpl_ensure(aProcessing, CPL_ERROR_NULL_INPUT, NULL);
1555 MUSE_TAG_OUTPUT_WCS, 0, CPL_FALSE);
1556 if (!fwcs || cpl_frameset_get_size(fwcs) <= 0) {
1558 cpl_frameset_delete(fwcs);
1561 cpl_frame *frame = cpl_frameset_get_position(fwcs, 0);
1562 const char *fn = cpl_frame_get_filename(frame);
1563 cpl_propertylist *header = NULL;
1564 int iext, next = cpl_fits_count_extensions(fn);
1565 for (iext = 0; iext <= next; iext++) {
1566 header = cpl_propertylist_load(fn, iext);
1567 cpl_errorstate es = cpl_errorstate_get();
1568 cpl_wcs *wcs = cpl_wcs_new_from_propertylist(header);
1569 if (!cpl_errorstate_is_equal(es)) {
1570 cpl_errorstate_set(es);
1573 cpl_propertylist_delete(header);
1578 int naxis = cpl_wcs_get_image_naxis(wcs);
1579 cpl_boolean valid = naxis == 2 || naxis == 3;
1581 const cpl_array *ctypes = cpl_wcs_get_ctype(wcs);
1582 if (valid && cpl_array_get_string(ctypes, 0)) {
1583 valid = valid && !strncmp(cpl_array_get_string(ctypes, 0),
"RA---TAN", 9);
1585 if (valid && cpl_array_get_string(ctypes, 1)) {
1586 valid = valid && !strncmp(cpl_array_get_string(ctypes, 1),
"DEC--TAN", 9);
1589 if (valid && naxis == 3 && cpl_array_get_string(ctypes, 2)) {
1590 const char *ctype3 = cpl_array_get_string(ctypes, 2);
1592 && (!strncmp(ctype3,
"AWAV", 5) || !strncmp(ctype3,
"AWAV-LOG", 9) ||
1593 !strncmp(ctype3,
"WAVE", 5) || !strncmp(ctype3,
"WAVE-LOG", 9));
1597 cpl_propertylist *pc = cpl_propertylist_new();
1598 cpl_propertylist_copy_property_regexp(pc, header,
"^PC[0-9]+_[0-9]+", 0);
1599 valid = cpl_propertylist_get_size(pc) == 0;
1600 cpl_propertylist_delete(pc);
1602 cpl_wcs_delete(wcs);
1604 cpl_msg_debug(__func__,
"Apparently valid header %s found in extension %d" 1605 " of \"%s\"", MUSE_TAG_OUTPUT_WCS, iext, fn);
1609 cpl_propertylist_delete(header);
1613 cpl_msg_warning(__func__,
"No valid headers for %s found in \"%s\"",
1614 MUSE_TAG_OUTPUT_WCS, fn);
1616 cpl_frameset_delete(fwcs);
1644 const char *aFilter)
1646 cpl_ensure_code(aProcessing && aPixtable && aParams, CPL_ERROR_NULL_INPUT);
1664 cpl_msg_info(__func__,
"Resampling to final cube follows, output format " 1666 cpl_msg_indent_more();
1668 cpl_msg_indent_less();
1669 cpl_ensure_code(e3d, cpl_error_get_code());
1673 cpl_msg_info(__func__,
"Resampling to final cube follows, output format " 1675 cpl_msg_indent_more();
1677 cpl_msg_indent_less();
1678 cpl_ensure_code(fits, cpl_error_get_code());
1684 int i, ipos = 0, nfilters = cpl_array_get_size(filters);
1685 for (i = 0; i < nfilters; i++) {
1688 cpl_array_get_string(filters, i));
1699 if (getenv(
"MUSE_COLLAPSE_PIXTABLE") &&
1700 atoi(getenv(
"MUSE_COLLAPSE_PIXTABLE")) > 0) {
1715 ((
muse_datacube *)cube)->recnames = cpl_array_new(0, CPL_TYPE_STRING);
1720 cpl_array_set_size(((
muse_datacube *)cube)->recnames, ipos+1);
1721 cpl_array_set_string(((
muse_datacube *)cube)->recnames, ipos,
1722 cpl_array_get_string(filters, i));
1728 cpl_array_get_string(filters, i));
1729 cpl_propertylist_update_string(fov->
header, MUSE_HDR_FILTER,
1730 cpl_array_get_string(filters, i));
1732 if (muse_idp_properties_update_fov(fov) != CPL_ERROR_NONE) {
1733 cpl_msg_warning(__func__,
"Writing IDP keywords to field-of-view " 1742 cpl_array_delete(filters);
1748 muse_idp_properties *properties =
1749 muse_idp_properties_collect(aProcessing, ((
muse_datacube *)cube)->header,
1750 MUSE_TAG_CUBE_FINAL);
1754 muse_idp_properties_update((
muse_datacube *)cube)->header, properties);
1757 cpl_error_code rc = CPL_ERROR_NONE;
1778 muse_idp_properties_delete(properties);
1810 cpl_ensure_code(aProcessing && aCube, CPL_ERROR_NULL_INPUT);
1813 const char *prefix =
"";
1814 if (!strncmp(aProcessing->
name,
"muse_scipost", 13)) {
1815 prefix = QC_POST_PREFIX_SCIPOST;
1816 }
else if (!strncmp(aProcessing->
name,
"muse_exp_combine", 17)) {
1817 prefix = QC_POST_PREFIX_EXPCOMBINE;
1818 }
else if (!strncmp(aProcessing->
name,
"muse_standard", 14)) {
1819 prefix = QC_POST_PREFIX_STANDARD;
1820 }
else if (!strncmp(aProcessing->
name,
"muse_astrometry", 16)) {
1821 prefix = QC_POST_PREFIX_ASTROMETRY;
1823 cpl_msg_info(__func__,
"Recipe \"%s\" found, not generating QC1 keywords",
1825 return CPL_ERROR_NONE;
1830 int plane = cpl_imagelist_get_size(aCube->
data) / 2;
1831 cpl_image *cim = cpl_imagelist_get(aCube->
data, plane);
1832 double dsigmas[] = { 5., 4., 3. };
1833 int ndsigmas =
sizeof(dsigmas) /
sizeof(
double);
1834 cpl_vector *vsigmas = cpl_vector_wrap(ndsigmas, dsigmas);
1835 cpl_size isigma = -1;
1836 cpl_errorstate prestate = cpl_errorstate_get();
1837 cpl_apertures *apertures = cpl_apertures_extract(cim, vsigmas, &isigma);
1838 cpl_vector_unwrap(vsigmas);
1841 char keyword[KEYWORD_LENGTH];
1848 ? crval3 * exp((plane + 1. - crpix3) * cd33 / crval3)
1849 : (plane + 1. - crpix3) * cd33 + crval3;
1850 snprintf(keyword, KEYWORD_LENGTH, QC_POST_LAMBDA, prefix);
1851 cpl_propertylist_update_float(aCube->
header, keyword, lambda);
1854 if (!apertures || !cpl_errorstate_is_equal(prestate)) {
1856 snprintf(keyword, KEYWORD_LENGTH, QC_POST_NDET, prefix);
1857 cpl_propertylist_update_int(aCube->
header, keyword, 0);
1859 snprintf(keyword, KEYWORD_LENGTH, QC_POST_POSX, prefix, 0);
1860 cpl_propertylist_update_float(aCube->
header, keyword, -1.);
1861 snprintf(keyword, KEYWORD_LENGTH, QC_POST_POSY, prefix, 0);
1862 cpl_propertylist_update_float(aCube->
header, keyword, -1.);
1863 snprintf(keyword, KEYWORD_LENGTH, QC_POST_FWHMX, prefix, 0);
1864 cpl_propertylist_update_float(aCube->
header, keyword, -1.);
1865 snprintf(keyword, KEYWORD_LENGTH, QC_POST_FWHMY, prefix, 0);
1866 cpl_propertylist_update_float(aCube->
header, keyword, -1.);
1868 cpl_errorstate_set(prestate);
1869 cpl_msg_warning(__func__,
"No sources found for FWHM measurement down to " 1870 "%.1f sigma limit on plane %d, QC parameters will not " 1871 "contain useful information", dsigmas[ndsigmas-1], plane+1);
1872 return CPL_ERROR_DATA_NOT_FOUND;
1874 int ndet = cpl_apertures_get_size(apertures);
1875 snprintf(keyword, KEYWORD_LENGTH, QC_POST_NDET, prefix);
1876 cpl_propertylist_update_int(aCube->
header, keyword, ndet);
1880 double cd11 = kMuseSpaxelSizeX_WFM, cd12 = 0., cd21 = 0.,
1881 cd22 = kMuseSpaxelSizeY_WFM;
1882 cpl_errorstate es = cpl_errorstate_get();
1883 cpl_wcs *wcs = cpl_wcs_new_from_propertylist(aCube->
header);
1884 if (!cpl_errorstate_is_equal(es)) {
1885 cpl_errorstate_set(es);
1889 cd11 = kMuseSpaxelSizeX_NFM;
1890 cd22 = kMuseSpaxelSizeY_NFM;
1893 const cpl_matrix *cd = cpl_wcs_get_cd(wcs);
1895 cd11 = fabs(cpl_matrix_get(cd, 0, 0)) * 3600.,
1896 cd12 = fabs(cpl_matrix_get(cd, 0, 1)) * 3600.,
1897 cd21 = fabs(cpl_matrix_get(cd, 1, 0)) * 3600.,
1898 cd22 = fabs(cpl_matrix_get(cd, 1, 1)) * 3600.;
1900 cpl_wcs_delete(wcs);
1904 cpl_image *statimage = cpl_image_new(ndet, 2, CPL_TYPE_DOUBLE);
1906 printf(
"index RA_FWHM DEC_FWHM\n");
1909 for (n = 1; n <= ndet; n++) {
1910 cpl_size xcen = lround(cpl_apertures_get_centroid_x(apertures, n)),
1911 ycen = lround(cpl_apertures_get_centroid_y(apertures, n));
1913 cpl_errorstate state = cpl_errorstate_get();
1914 cpl_image_get_fwhm(cim, xcen, ycen, &x, &y);
1915 const char *fwhmcomment = NULL;
1916 if (x < 0 || y < 0 || !cpl_errorstate_is_equal(state)) {
1921 cpl_image_reject(statimage, n, 1);
1922 cpl_image_reject(statimage, n, 2);
1923 fwhmcomment =
"[arcsec] failure determining FWHM";
1926 cpl_errorstate_set(state);
1929 x = cd11 * x + cd12 * y;
1930 y = cd22 * y + cd21 * x;
1931 cpl_image_set(statimage, n, 1, x);
1932 cpl_image_set(statimage, n, 2, y);
1935 printf(
"%4d %f %f\n", n, x, y);
1939 snprintf(keyword, KEYWORD_LENGTH, QC_POST_POSX, prefix, n);
1940 cpl_propertylist_update_float(aCube->
header, keyword, xcen);
1941 snprintf(keyword, KEYWORD_LENGTH, QC_POST_POSY, prefix, n);
1942 cpl_propertylist_update_float(aCube->
header, keyword, ycen);
1943 snprintf(keyword, KEYWORD_LENGTH, QC_POST_FWHMX, prefix, n);
1944 cpl_propertylist_update_float(aCube->
header, keyword, x);
1946 cpl_propertylist_set_comment(aCube->
header, keyword, fwhmcomment);
1948 snprintf(keyword, KEYWORD_LENGTH, QC_POST_FWHMY, prefix, n);
1949 cpl_propertylist_update_float(aCube->
header, keyword, y);
1951 cpl_propertylist_set_comment(aCube->
header, keyword, fwhmcomment);
1957 cpl_apertures_delete(apertures);
1960 snprintf(keyword, KEYWORD_LENGTH, QC_POST_FWHM_NVALID, prefix);
1961 cpl_propertylist_update_int(aCube->
header, keyword, ndet - nbad);
1962 cpl_errorstate state = cpl_errorstate_get();
1963 cpl_stats *s = cpl_stats_new_from_image(statimage,
1964 CPL_STATS_MEDIAN | CPL_STATS_MAD);
1965 cpl_boolean error = !cpl_errorstate_is_equal(state);
1966 cpl_errorstate_set(state);
1967 snprintf(keyword, KEYWORD_LENGTH, QC_POST_FWHM_MEDIAN, prefix);
1968 if (error || ndet < 3) {
1969 cpl_propertylist_update_float(aCube->
header, keyword, 0.);
1971 cpl_propertylist_update_float(aCube->
header, keyword, cpl_stats_get_median(s));
1973 snprintf(keyword, KEYWORD_LENGTH, QC_POST_FWHM_MAD, prefix);
1974 if (error || ndet < 3) {
1975 cpl_propertylist_update_float(aCube->
header, keyword, 0.);
1977 cpl_propertylist_update_float(aCube->
header, keyword, cpl_stats_get_mad(s));
1979 cpl_stats_delete(s);
1980 cpl_image_delete(statimage);
1981 cpl_msg_info(__func__,
"Computed FWHM QC parameters for %d of %d source%s " 1982 "found down to the %.1f sigma threshold on plane %d",
1983 ndet - nbad, ndet, ndet == 1 ?
"" :
"s", dsigmas[isigma],
1986 return CPL_ERROR_NONE;
cpl_error_code muse_sky_lines_fit(cpl_table *, cpl_table *, cpl_image *, muse_wcs *)
Fit all entries of the pixel table to the master sky.
cpl_table * muse_sky_continuum_create(cpl_table *, cpl_table *, cpl_image *, muse_wcs *, double)
Create a continuum spectrum.
muse_image * muse_resampling_collapse_pixgrid(muse_pixtable *aPixtable, muse_pixgrid *aGrid, muse_datacube *aCube, const muse_table *aFilter, muse_resampling_params *aParams)
Integrate a pixel table / pixel grid along the wavelength direction.
#define MUSE_PIXTABLE_FFDATA
Structure definition of a MUSE datacube.
muse_rvcorrect_type rvtype
cpl_propertylist * muse_postproc_cube_load_output_wcs(muse_processing *aProcessing)
Find a file with a usable output WCS in the input frameset.
muse_autocalib_type autocalib
muse_postproc_properties * muse_postproc_properties_new(muse_postproc_type aType)
Create a post-processing properties object.
muse_flux_selection_type select
cpl_error_code muse_flux_compute_qc(muse_flux_object *aFluxObj)
Compute QC parameters, related to on-sky throughput.
void muse_image_delete(muse_image *aImage)
Deallocate memory associated to a muse_image object.
double muse_pfits_get_cd(const cpl_propertylist *aHeaders, unsigned int aAxisI, unsigned int aAxisJ)
find out the WCS coordinate at the reference point
const char * muse_pfits_get_insmode(const cpl_propertylist *aHeaders)
find out the observation mode
muse_pixtable * muse_pixtable_duplicate(muse_pixtable *aPixtable)
Make a copy of the pixtanle.
cpl_array * muse_raman_simulate(muse_pixtable *aPixtable, cpl_array *aPar, cpl_array *aRetval)
Apply the LSF and spatial Raman light distribution.
double muse_pfits_get_crval(const cpl_propertylist *aHeaders, unsigned int aAxis)
find out the WCS coordinate at the reference point
#define MUSE_PIXTABLE_FFLAMBDA
A structure containing a spatial two-axis WCS.
muse_wcs_centroid_type centroid
cpl_table * muse_resampling_spectrum_iterate(muse_pixtable *aPixtable, double aBinwidth, float aLo, float aHi, unsigned char aIter)
Iteratively resample selected pixels of a pixel table into spectrum.
double muse_pfits_get_ra(const cpl_propertylist *aHeaders)
find out the right ascension
cpl_error_code muse_postproc_correct_raman(muse_pixtable *aPT, muse_postproc_properties *aProp, const cpl_table *aOffsets, muse_datacube **aRamanCube)
Set up and run Raman-light removal.
void muse_postproc_offsets_scale(muse_pixtable *aPT, const cpl_table *aOffsets, const char *aPurpose)
Apply spatial offsets and flux scale to a pixel table (of a single exposure)
cpl_image * data
the data extension
cpl_error_code muse_rvcorrect(muse_pixtable *aPixtable, muse_rvcorrect_type aType)
Correct the wavelengths of all pixels of a given pixel table for radial velocity shift.
cpl_size muse_pixtable_get_nrow(const muse_pixtable *aPixtable)
get the number of rows within the pixel table
void muse_mask_delete(muse_mask *aMask)
Deallocate memory associated to a muse_mask object.
#define MUSE_HDR_PT_LHI
FITS header keyword contains the upper limit of the data in spectral direction.
muse_xcombine_types muse_postproc_get_weight_type(const char *aWeightString)
Select correct weighting type for weight string.
cpl_error_code muse_dar_correct(muse_pixtable *aPixtable, double aLambdaRef)
Correct the pixel coordinates of all pixels of a given pixel table for differential atmospheric refra...
cpl_error_code muse_postproc_revert_ffspec_maybe(muse_pixtable *aPt, const muse_table *aResponse)
Revert correction of on-sky data with the flat-field spectrum.
cpl_image * muse_lsf_average_cube_all(muse_lsf_cube **aLsfCube, muse_pixtable *aPixtable)
Create an average image from all LSF cubes.
muse_resampling_crstats_type muse_postproc_get_cr_type(const char *aCRTypeString)
Select correct cosmic ray rejection type for crtype string.
muse_datacube * muse_resampling_cube(muse_pixtable *aPixtable, muse_resampling_params *aParams, muse_pixgrid **aGrid)
Resample a pixel table onto a regular grid structure representing a FITS NAXIS=3 datacube.
const char * muse_pfits_get_dateobs(const cpl_propertylist *aHeaders)
find out the date of observations
void muse_datacube_delete(muse_datacube *aCube)
Deallocate memory associated to a muse_datacube object.
cpl_error_code muse_dar_check(muse_pixtable *aPixtable, double *aMaxShift, cpl_boolean aCorrect, muse_datacube **aCube)
check that the continuum of objects in the frame is well-aligned perpendicular to the spatial axis...
#define MUSE_HDR_PT_FFCORR
cpl_error_code muse_flux_reference_table_check(cpl_table *aTable)
Check and/or adapt the standard flux reference table format.
cpl_error_code muse_postproc_qc_fwhm(muse_processing *aProcessing, muse_datacube *aCube)
Compute QC1 parameters for datacubes and save them in the FITS header.
WCS object to store data needed while computing the astrometric solution.
Structure definition of MUSE three extension FITS file.
muse_flux_object * muse_flux_object_new(void)
Allocate memory for a new muse_flux_object object.
cpl_error_code muse_flux_calibrate(muse_pixtable *aPixtable, const muse_table *aResponse, const cpl_table *aExtinction, const muse_table *aTelluric)
Convert the input pixel table from counts to fluxes.
cpl_error_code muse_postproc_cube_resample_and_collapse(muse_processing *aProcessing, muse_pixtable *aPixtable, muse_cube_type aFormat, muse_resampling_params *aParams, const char *aFilter)
High level function to resample to a datacube and collapse that to an image of the field of view and ...
cpl_table * table
The pixel table.
muse_flux_profile_type profile
void muse_lsf_params_delete_all(muse_lsf_params **aParams)
Delete an allocated array of muse_lsf_params structure.
muse_postproc_skymethod skymethod
cpl_propertylist * header
the FITS header
muse_lsf_params ** lsf_params
#define MUSE_PIXTABLE_DATA
unsigned int muse_imagelist_get_size(muse_imagelist *aList)
Return the number of stored images.
cpl_error_code muse_wcs_project_tan(muse_pixtable *aPixtable, const cpl_propertylist *aWCS)
Carry out a gnomonic projection of a pixel table into native spherical coordinates.
muse_resampling_crstats_type crtype
cpl_image * dq
the data quality extension
double muse_pfits_get_crpix(const cpl_propertylist *aHeaders, unsigned int aAxis)
find out the WCS reference point
cpl_error_code muse_flux_get_telluric_table(muse_flux_object *aFluxObj)
Get the table of the telluric correction.
void muse_pixgrid_delete(muse_pixgrid *aGrid)
Delete a pixel grid and remove its memory.
cpl_array * muse_raman_fit(muse_pixtable *aPixtable[MUSE_RAMAN_RANGES])
Fit raman lines to an array of pixtables.
cpl_array * muse_cplarray_new_from_delimited_string(const char *aString, const char *aDelim)
Convert a delimited string into an array of strings.
Structure definition of MUSE pixel table.
Flux object to store data needed while computing the flux calibration.
cpl_error_code muse_datacube_convert_dq(muse_datacube *aCube)
Convert the DQ extension of a datacube to NANs in DATA and STAT.
muse_cube_type muse_postproc_get_cube_format(const char *aFormatString)
Select correct cube format for format string.
cpl_error_code muse_sky_subtract_lines_old(muse_pixtable *aPixtable, cpl_table *aLines, muse_lsf_params **aLsfParams)
Subtract sky lines from a pixtable.
cpl_array * muse_cpltable_extract_column(cpl_table *aTable, const char *aColumn)
Create an array from a section of a column.
double * muse_xcombine_find_offsets(const cpl_table *aOffsets, const char *aDateObs)
Get offsets and scale from table row with matching DATE-OBS entry.
cpl_boolean muse_postproc_check_save_param(const char *aSave, const char *aValid)
Check the –save parameter contents against allowed options.
cpl_error_code muse_autocalib_slice_median(muse_pixtable *aPixtable, double aClip, muse_table **aFactors)
Correct the background level of the slices (port from MPDAF).
cpl_error_code muse_flux_response_compute(muse_flux_object *aFluxObj, muse_flux_selection_type aSelect, double aAirmass, const cpl_table *aReference, const cpl_table *aTellBands, const cpl_table *aExtinct)
Compare measured flux distribution over wavelength with calibrated stellar fluxes and derive instrume...
muse_resampling_crstats_type
Cosmic ray rejection statistics type.
cpl_propertylist * muse_wcs_create_default(const cpl_propertylist *aHeader)
Create FITS headers containing a default (relative) WCS.
muse_resampling_params * muse_resampling_params_new(muse_resampling_type aMethod)
Create the resampling parameters structure.
cpl_error_code muse_processing_save_cube(muse_processing *aProcessing, int aIFU, void *aCube, const char *aTag, muse_cube_type aType)
Save a MUSE datacube to disk.
cpl_error_code muse_wcs_solve(muse_wcs_object *aWCSObj, cpl_table *aReference, float aRadius, float aFAccuracy, int aIter, float aThresh)
Find the world coordinate solution for a given field using coordinates of detected sources and coordi...
muse_wcs_object * muse_wcs_object_new(void)
Allocate memory for a new muse_wcs_object object.
cpl_table * ffspec
A flat-field spectrum.
muse_flux_smooth_type smooth
Structure definition of the post-processing properties.
void muse_cplerrorstate_dump_some(unsigned aCurrent, unsigned aFirst, unsigned aLast)
Dump some CPL errors.
void muse_euro3dcube_delete(muse_euro3dcube *aEuro3D)
Deallocate memory associated to a muse_euro3dcube object.
muse_table * muse_table_load_filter(muse_processing *aProcessing, const char *aFilterName)
Load a table for a given filter name.
void muse_postproc_properties_delete(muse_postproc_properties *aProp)
Free memory taken by a post-processing properties object and all its components.
cpl_table * muse_postproc_load_nearest(const cpl_propertylist *aHeader, const cpl_frame *aFrame, float aWarnLimit, float aErrLimit, double *aRA, double *aDEC)
Load the calibration from a multi-table FITS file that is nearest on the sky.
cpl_imagelist * data
the cube containing the actual data values
cpl_error_code muse_sky_subtract_continuum(muse_pixtable *, cpl_table *)
Subtract sky continuum from pixel table.
cpl_error_code muse_sky_lines_set_range(cpl_table *, double, double)
Limit the lines in the table to a wavelength range.
Structure definition of a Euro3D datacube.
double muse_pfits_get_dec(const cpl_propertylist *aHeaders)
find out the declination
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_pixtable_and_selected_mask(muse_pixtable *aPixtable, const muse_mask *aMask, const cpl_propertylist *aWCS, const cpl_table *aOffsets)
Select all pixels where the spatial positions are enabled in the given mask.
Structure to store a table together with a property list.
cpl_error_code muse_flux_get_response_table(muse_flux_object *aFluxObj, muse_flux_smooth_type aSmooth)
Get the table of the standard star response function.
muse_image * muse_postproc_whitelight(muse_pixtable *aPixtable, double aCRSigma)
Create a white-light image of the field of view.
muse_pixtable * muse_pixtable_extract_wavelength(muse_pixtable *aPixtable, double aLow, double aHigh)
Create a new pixtable with values within the selected wavelengths.
void muse_table_delete(muse_table *aTable)
Deallocate memory associated to a muse_table object.
muse_resampling_dispersion_type tlambda
#define MUSE_HDR_PT_LLO
FITS header keyword contains the lower limit of the data in spectral direction.
muse_lsf_cube ** lsf_cube
cpl_propertylist * header
the header
const char * muse_pfits_get_ctype(const cpl_propertylist *aHeaders, unsigned int aAxis)
find out the WCS axis type string
void * muse_postproc_process_exposure(muse_postproc_properties *aProp, unsigned int aIndex, muse_postproc_autocal_outputs *aACalOut, muse_datacube **aRamanCube, muse_postproc_sky_outputs *aSkyOut, const cpl_table *aOffsets)
Merge and process pixel tables from one exposure.
muse_postproc_type
Type of per-exposure processing to run.
cpl_error_code muse_flux_integrate_std(muse_pixtable *aPixtable, muse_flux_profile_type aProfile, muse_flux_object *aFluxObj)
Reconstruct a cube, detect the standard star, and integrate its flux.
cpl_propertylist * header
the FITS header
int muse_processing_save_image(muse_processing *aProcessing, int aIFU, muse_image *aImage, const char *aTag)
Save a computed MUSE image to disk.
muse_pixtable * muse_pixtable_load_merge_channels(cpl_table *aExposureList, double aLambdaMin, double aLambdaMax)
Load and merge the pixel tables of the 24 MUSE sub-fields.
cpl_error_code muse_wcs_optimize_solution(muse_wcs_object *aWCSObj, float aDetSigma, muse_wcs_centroid_type aCentroid, cpl_table *aReference, float aRadius, float aFAccuracy, int aIter, float aRejSigma)
Find an optimal astrometry solution given a detection image.
muse_resampling_type muse_postproc_get_resampling_type(const char *aResampleString)
Select correct resampling type for resample string.
muse_mask * muse_autocalib_create_mask(muse_image *aImage, double aNSigma, const char *aQCPrefix)
Create Select spaxels to be considered as sky for autocalibration.
cpl_error_code muse_phys_air_to_vacuum(muse_pixtable *aPixtable, unsigned int aFlags)
Convert a pixel table from air to vacuum wavelengths.
cpl_error_code muse_raman_add_lsf(muse_pixtable *aPixtable, cpl_table *aRamanLines, int aGroup, double aFlux, muse_lsf_cube **aLsfCube)
Add a Raman line profile to pixtable.
Handling of "mask" files.
cpl_error_code muse_image_reject_from_dq(muse_image *aImage)
Reject pixels of a muse_image depending on its DQ data.
void muse_lsf_cube_delete_all(muse_lsf_cube **aLsfCube)
Delete all LSF cubes.
muse_imagelist * muse_imagelist_new(void)
Create a new (empty) MUSE image list.
muse_wcs * muse_lsf_cube_get_wcs_all(muse_lsf_cube **aLsfCubes)
Get the world coordinate representative of all LSF cubes.
muse_mask * muse_sky_create_skymask(muse_image *, double, double, const char *)
Select spaxels to be considered as sky.
cpl_error_code muse_sky_subtract_lines(muse_pixtable *, cpl_table *, muse_lsf_cube **)
Subtract sky lines from a pixtable.
muse_resampling_type
Resampling types.
cpl_error_code muse_pixtable_spectrum_apply(muse_pixtable *aPixtable, const cpl_array *aLambdas, const cpl_array *aFlux, muse_pixtable_operation aOperation)
Apply a spectrum given by two arrays with an operation to a pixel table.
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.
muse_euro3dcube * muse_resampling_euro3d(muse_pixtable *aPixtable, muse_resampling_params *aParams)
Resample a pixel table onto a regular grid structure representing a Euro3D format file...
Structure definition of the post-processing output sky data.
void muse_resampling_params_delete(muse_resampling_params *aParams)
Delete a resampling parameters structure.
muse_resampling_type method
muse_image * muse_datacube_collapse(muse_datacube *aCube, const muse_table *aFilter)
Integrate a FITS NAXIS=3 datacube along the wavelength direction.
muse_image * muse_image_new(void)
Allocate memory for a new muse_image object.
cpl_table * muse_resampling_spectrum(muse_pixtable *aPixtable, double aBinwidth)
Resample the selected pixels of a pixel table into a spectrum.
muse_image * muse_raman_simulate_image(const muse_image *aImage, const cpl_array *aPar)
Simulate an image of the parameters of the spatial Raman light fit.
Structure definition of the post-processing output auto-calibration.
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
cpl_error_code muse_sky_lines_fit_old(cpl_table *aSpectrum, cpl_table *aLines)
Fit all entries of the pixel table to the master sky.
muse_sky_params skymodel_params
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
muse_postproc_darcheck darcheck
cpl_table * sky_continuum
muse_xcombine_types
Xposure combination types.
cpl_error_code muse_imagelist_set(muse_imagelist *aList, muse_image *aImage, unsigned int aIdx)
Set the muse_image of given list index.
double muse_astro_angular_distance(double aRA1, double aDEC1, double aRA2, double aDEC2)
Compute angular distance in the sky between two positions.
muse_ins_mode muse_pfits_get_mode(const cpl_propertylist *aHeaders)
find out the observation mode
cpl_error_code muse_utils_copy_modified_header(cpl_propertylist *aH1, cpl_propertylist *aH2, const char *aKeyword, const char *aString)
Copy a modified header keyword from one header to another.
cpl_error_code muse_wcs_locate_sources(muse_pixtable *aPixtable, float aSigma, muse_wcs_centroid_type aCentroid, muse_wcs_object *aWCSObj)
Determine the centers of stars on an astrometric exposure.
muse_image * muse_euro3dcube_collapse(muse_euro3dcube *aEuro3D, const muse_table *aFilter)
Integrate a Euro3D datacube along the wavelength direction.
cpl_error_code muse_image_dq_to_nan(muse_image *aImage)
Convert pixels flagged in the DQ extension to NANs in DATA (and STAT, if present).
double muse_astro_airmass(cpl_propertylist *aHeader)
Derive the effective airmass of an observation from information in a FITS header. ...
cpl_propertylist * header
The FITS header.
cpl_error_code muse_pixtable_flux_multiply(muse_pixtable *aPixtable, double aScale)
Scale the flux of a pixel table with correct treatment of variance.