33 #include "muse_pixtable.h" 34 #include "muse_instrument.h" 36 #include "muse_cplwrappers.h" 38 #include "muse_mask.h" 39 #include "muse_pfits.h" 40 #include "muse_quadrants.h" 41 #include "muse_quality.h" 42 #include "muse_postproc.h" 43 #include "muse_tracing.h" 44 #include "muse_wavecalib.h" 46 #include "muse_utils.h" 52 #define CREATE_MINIMAL_PIXTABLE 0 53 #define PIXTABLE_CREATE_CCDSIZED 1 54 #define DEBUG_PIXTABLE_CREATION 0 55 #define DEBUG_PIXTABLE_FEW_SLICES 0 57 #define PIXTABLE_MASK_PARALLEL 0 103 #define MUSE_ORIGIN_SHIFT_XSLICE 24 104 #define MUSE_ORIGIN_SHIFT_YPIX 11 105 #define MUSE_ORIGIN_SHIFT_IFU 6 109 #define MUSE_ORIGIN_SLICE_SAFETY_OFFSET -20 113 static inline uint32_t
114 muse_pixtable_origin_encode_fast(
unsigned int aX,
unsigned int aY,
116 unsigned short aSlice,
unsigned int aOffset)
118 return ((aX - aOffset) << MUSE_ORIGIN_SHIFT_XSLICE)
119 | (aY << MUSE_ORIGIN_SHIFT_YPIX)
120 | (aIFU << MUSE_ORIGIN_SHIFT_IFU)
125 static inline unsigned int 126 muse_pixtable_origin_get_x_fast(uint32_t aOrigin, uint32_t aOffset)
128 return ((aOrigin >> MUSE_ORIGIN_SHIFT_XSLICE) & 0x7f) + aOffset;
132 static inline unsigned int 133 muse_pixtable_origin_get_y_fast(uint32_t aOrigin)
135 return (aOrigin >> MUSE_ORIGIN_SHIFT_YPIX) & 0x1fff;
139 static inline unsigned short 140 muse_pixtable_origin_get_ifu_fast(uint32_t aOrigin)
142 return (aOrigin >> MUSE_ORIGIN_SHIFT_IFU) & 0x1f;
146 static inline unsigned short 147 muse_pixtable_origin_get_slice_fast(uint32_t aOrigin)
149 return aOrigin & 0x3f;
172 unsigned short aSlice,
unsigned int aOffset)
177 cpl_ensure(aX < 8192 && aX > 0 && aY < 8192 && aY > 0 &&
178 aIFU <= kMuseNumIFUs && aIFU >= 1 &&
179 aSlice <= kMuseSlicesPerCCD && aSlice >= 1 && aOffset < 8192,
180 CPL_ERROR_ILLEGAL_INPUT, 0);
183 cpl_msg_debug(__func__,
"origin (%d, %d, %d, %d, %d) = 0x%x",
184 aX, aY, aIFU, aSlice, aOffset,
185 ((aX - aOffset) << MUSE_ORIGIN_SHIFT_XSLICE)
186 | (aY << MUSE_ORIGIN_SHIFT_YPIX)
187 | (aIFU << MUSE_ORIGIN_SHIFT_IFU)
192 return muse_pixtable_origin_encode_fast(aX, aY, aIFU, aSlice, aOffset);
218 unsigned short slice = muse_pixtable_origin_get_slice_fast(aOrigin),
219 ifu = muse_pixtable_origin_get_ifu_fast(aOrigin);
220 cpl_errorstate prestate = cpl_errorstate_get();
222 if (!cpl_errorstate_is_equal(prestate)) {
223 cpl_errorstate_set(prestate);
227 x = muse_pixtable_origin_get_x_fast(aOrigin, offset);
229 if (x > 8191 || x < 1 || !cpl_errorstate_is_equal(prestate)) {
230 cpl_msg_error(__func__,
"aOrigin=%#x x=%d (%d %d %d), %s",
231 aOrigin, x, slice, ifu, offset, cpl_error_get_message());
234 cpl_ensure(x <= 8191 && x >= 1 && cpl_errorstate_is_equal(prestate),
235 CPL_ERROR_ILLEGAL_OUTPUT, 0);
251 unsigned int y = muse_pixtable_origin_get_y_fast(aOrigin);
253 if (y > 8191 || y < 1) {
254 cpl_msg_error(__func__,
"aOrigin=%#x y=%d", aOrigin, y);
257 cpl_ensure(y <= 8191 && y >= 1, CPL_ERROR_ILLEGAL_OUTPUT, 0);
273 unsigned short ifu = muse_pixtable_origin_get_ifu_fast(aOrigin);
275 if (ifu > kMuseNumIFUs || ifu < 1) {
276 cpl_msg_error(__func__,
"aOrigin=%#x ifu=%d", aOrigin, ifu);
279 cpl_ensure(ifu <= kMuseNumIFUs && ifu >= 1, CPL_ERROR_ILLEGAL_OUTPUT, 0);
295 unsigned short slice = muse_pixtable_origin_get_slice_fast(aOrigin);
297 if (slice > kMuseSlicesPerCCD || slice < 1) {
298 cpl_msg_error(__func__,
"aOrigin=%#x slice=%d", aOrigin, slice);
301 cpl_ensure(slice <= kMuseSlicesPerCCD && slice >= 1,
302 CPL_ERROR_ILLEGAL_OUTPUT, 0);
324 cpl_polynomial *aLTrace,
325 unsigned short aIFU,
unsigned short aSlice)
327 cpl_ensure(aPixtable && aPixtable->
header, CPL_ERROR_NULL_INPUT, 0);
328 cpl_errorstate prestate = cpl_errorstate_get();
329 unsigned int offset = floor(cpl_polynomial_eval_1d(aLTrace, 1, NULL))
330 + MUSE_ORIGIN_SLICE_SAFETY_OFFSET;
331 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
335 cpl_propertylist_update_int(aPixtable->
header, keyword, offset);
336 cpl_propertylist_set_comment(aPixtable->
header, keyword,
337 MUSE_HDR_PT_IFU_SLICE_OFFSET_COMMENT);
359 unsigned short aIFU,
unsigned short aSlice)
361 cpl_ensure(aPixtable && aPixtable->
header, CPL_ERROR_NULL_INPUT, 0);
364 cpl_errorstate prestate = cpl_errorstate_get();
365 unsigned int offset = cpl_propertylist_get_int(aPixtable->
header, keyword);
368 if (offset > 8191 || offset < 1) {
369 cpl_msg_error(__func__,
"aIFU=%d aSlice=%d offset=%d",
370 aIFU, aSlice, offset);
373 cpl_ensure(offset <= 8191 && offset >= 1 && cpl_errorstate_is_equal(prestate),
374 CPL_ERROR_ILLEGAL_OUTPUT, 0);
403 cpl_ensure_code(aOut && aOut->
header, CPL_ERROR_NULL_INPUT);
404 cpl_propertylist *dest = aOut->
header,
406 if (aFrom && aFrom->
header) {
409 char keyword[KEYWORD_LENGTH];
410 unsigned short nifu, nslice;
411 for (nifu = 1; nifu <= kMuseNumIFUs; nifu++) {
412 for (nslice = 1; nslice <= kMuseSlicesPerCCD; nslice++) {
416 cpl_errorstate prestate = cpl_errorstate_get();
417 unsigned int offset = cpl_propertylist_get_int(from, keyword);
418 if (!cpl_errorstate_is_equal(prestate)) {
420 cpl_errorstate_set(prestate);
424 cpl_propertylist_erase(from, keyword);
428 cpl_propertylist_update_int(dest, keyword, offset);
429 cpl_propertylist_set_comment(dest, keyword,
430 MUSE_HDR_PT_IFU_SLICE_OFFSET_COMMENT);
434 return CPL_ERROR_NONE;
459 unsigned short **aX,
unsigned short **aY,
460 unsigned char **aIFU,
unsigned char **aSlice)
463 cpl_ensure_code(aPixtable, CPL_ERROR_NULL_INPUT);
464 const uint32_t *origin
465 = (uint32_t *)cpl_table_get_data_int_const(aPixtable->
table,
467 cpl_ensure_code(origin, CPL_ERROR_BAD_FILE_FORMAT);
468 cpl_ensure_code(aX && aIFU && aSlice, CPL_ERROR_NULL_INPUT);
472 *aX = cpl_malloc(nrow *
sizeof(
unsigned short));
474 *aY = cpl_malloc(nrow *
sizeof(
unsigned short));
476 *aIFU = cpl_malloc(nrow *
sizeof(
unsigned char));
477 *aSlice = cpl_malloc(nrow *
sizeof(
unsigned char));
483 cpl_errorstate prestate = cpl_errorstate_get();
486 if (!cpl_errorstate_is_equal(prestate)) {
487 cpl_errorstate_set(prestate);
489 cpl_boolean multiexp = expnum != expnumN;
492 unsigned int offset = 0;
494 for (i = 0; i < nrow; i++) {
495 (*aIFU)[i] = muse_pixtable_origin_get_ifu_fast(origin[i]);
496 (*aSlice)[i] = muse_pixtable_origin_get_slice_fast(origin[i]);
499 if ((i == 0) || (i > 0 && ((*aSlice)[i] != (*aSlice)[i-1]))) {
501 if (multiexp && i > 0 && (*aIFU)[i] != (*aIFU)[i-1]) {
510 (*aX)[i] = muse_pixtable_origin_get_x_fast(origin[i], offset);
512 (*aY)[i]= muse_pixtable_origin_get_y_fast(origin[i]);
516 return CPL_ERROR_NONE;
538 cpl_ensure(aPixtable && aPixtable->
header, CPL_ERROR_NULL_INPUT, 0);
540 CPL_ERROR_ILLEGAL_INPUT, 0);
542 char keyword[KEYWORD_LENGTH];
543 unsigned int exposure = 0;
544 cpl_size lo = 0, hi = 0;
546 cpl_errorstate prestate = cpl_errorstate_get();
548 lo = cpl_propertylist_get_long_long(aPixtable->
header, keyword);
550 hi = cpl_propertylist_get_long_long(aPixtable->
header, keyword);
551 if (!cpl_errorstate_is_equal(prestate)) {
558 cpl_errorstate_set(prestate);
562 cpl_ensure(lo <= aRow && hi >= aRow, CPL_ERROR_ILLEGAL_OUTPUT, 0);
589 "relative x-pixel position in the output datacube", CPL_TRUE},
591 "relative y-pixel position in the output datacube", CPL_TRUE},
593 "wavelength of this pixel", CPL_TRUE},
595 "data value in this pixel", CPL_TRUE},
597 "Euro3D bad pixel status of this pixel", CPL_TRUE},
599 "data variance of this pixel", CPL_TRUE},
601 "encoded value of IFU and slice number, as well as x and y " 602 "position in the raw (trimmed) data", CPL_TRUE},
603 { NULL, 0, NULL, NULL, NULL, CPL_FALSE }
655 cpl_table *aGeoTable)
657 cpl_ensure(aImage && aWave && aTrace, CPL_ERROR_NULL_INPUT, NULL);
660 cpl_ensure(ifu >= 1 && ifu <= kMuseNumIFUs, CPL_ERROR_DATA_NOT_FOUND, NULL);
663 if (!cpl_propertylist_has(aImage->
header,
"BUNIT")) {
664 char *msg = cpl_sprintf(
"Input data of IFU %hhu does not contain a data " 665 "unit (\"BUNIT\"), cannot proceed!", ifu);
666 cpl_msg_error(__func__,
"%s", msg);
667 cpl_error_set_message(__func__, CPL_ERROR_INCOMPATIBLE_INPUT,
"%s", msg);
672 if (strncmp(unit,
"count", 6)) {
673 char *msg = cpl_sprintf(
"Input data of IFU %hhu is not in \"count\" units " 674 "but in \"%s\", not suitable for a new pixel table!",
676 cpl_msg_error(__func__,
"%s", msg);
677 cpl_error_set_message(__func__, CPL_ERROR_INCOMPATIBLE_INPUT,
"%s", msg);
685 int xsize = cpl_image_get_size_x(aImage->
data),
686 ysize = cpl_image_get_size_y(aImage->
data),
687 #if PIXTABLE_CREATE_CCDSIZED 690 isize = xsize * ysize;
694 isize = ysize * kMuseSlicesPerCCD * kMuseSliceHiLikelyWidth;
700 pt->
header = cpl_propertylist_duplicate(aImage->
header);
701 cpl_propertylist_erase_regexp(pt->
header,
702 "^SIMPLE$|^BITPIX$|^NAXIS|^EXTEND$|^XTENSION$|" 703 "^DATASUM$|^DATAMIN$|^DATAMAX$|^DATAMD5$|" 704 "^PCOUNT$|^GCOUNT$|^HDUVERS$|^BLANK$|" 705 "^BZERO$|^BSCALE$|^BUNIT$|^CHECKSUM$|^INHERIT$|" 708 aGeoTable ? MUSE_PIXTABLE_STRING_FULL
709 : MUSE_PIXTABLE_STRING_SIMPLE);
711 aGeoTable ? MUSE_PIXTABLE_COMMENT_FULL
712 : MUSE_PIXTABLE_COMMENT_SIMPLE);
732 uint32_t *cdata_origin = (uint32_t *)cpl_table_get_data_int(pt->
table,
736 const float *pixdata = cpl_image_get_data_float_const(aImage->
data),
737 *pixstat = cpl_image_get_data_float_const(aImage->
stat);
738 const int *pixdq = cpl_image_get_data_int_const(aImage->
dq);
741 unsigned short wavexorder, waveyorder;
743 cpl_msg_info(__func__,
"Creating pixel table for IFU %hhu, using order %d for " 744 "trace solution and orders %hu/%hu for wavelength solution", ifu,
748 cpl_table *geopos = NULL;
749 double *slice_x = NULL, *slice_y = NULL, *slice_angle = NULL,
753 slice_x = cpl_table_get_data_double(geopos, MUSE_GEOTABLE_X);
754 slice_y = cpl_table_get_data_double(geopos, MUSE_GEOTABLE_Y);
756 if (!geopos || !slice_x || !slice_y) {
758 ? cpl_sprintf(
"Geometry table is missing data for IFU %hhu!", ifu)
759 : cpl_sprintf(
"Geometry table is missing column%s%s%s!",
760 !slice_x && !slice_y ?
"s" :
"",
761 slice_x ?
"" :
" \""MUSE_GEOTABLE_X
"\"",
762 slice_y ?
"" :
" \""MUSE_GEOTABLE_Y
"\"");
763 cpl_error_set_message(__func__, CPL_ERROR_ILLEGAL_INPUT,
"%s", msg);
764 cpl_msg_error(__func__,
"%s", msg);
766 cpl_table_delete(geopos);
772 cpl_errorstate prestate = cpl_errorstate_get();
773 slice_angle = cpl_table_get_data_double(geopos, MUSE_GEOTABLE_ANGLE);
774 slice_width = cpl_table_get_data_double(geopos, MUSE_GEOTABLE_WIDTH);
775 if (!cpl_errorstate_is_equal(prestate)) {
776 char *msg = cpl_sprintf(
"Geometry table is missing column%s%s%s!",
777 !slice_angle && !slice_width ?
"s" :
"",
778 slice_angle ?
"" :
" \""MUSE_GEOTABLE_ANGLE
"\"",
779 slice_width ?
"" :
" \""MUSE_GEOTABLE_WIDTH
"\"");
780 cpl_error_set_message(__func__, CPL_ERROR_BAD_FILE_FORMAT,
"%s", msg);
781 cpl_msg_error(__func__,
"%s", msg);
783 if (!getenv(
"MUSE_EXPERT_USER")) {
784 cpl_table_delete(geopos);
792 cpl_size itablerow = 0;
794 double cputime = cpl_test_get_cputime(),
795 walltime = cpl_test_get_walltime();
798 #if DEBUG_PIXTABLE_FEW_SLICES > 0 799 # define SLICE_LIMIT DEBUG_PIXTABLE_FEW_SLICES 801 # define SLICE_LIMIT kMuseSlicesPerCCD 803 for (islice = 0; islice < SLICE_LIMIT; islice++) {
804 #if DEBUG_PIXTABLE_CREATION 805 cpl_msg_debug(__func__,
"Starting to process slice %2d of IFU %2hhu",
813 cpl_vector *pos = cpl_vector_new(2);
816 cpl_vector_set(pos, 0, kMuseOutputYTop / 2);
817 cpl_vector_set(pos, 1, kMuseOutputYTop / 2);
818 double ltest = cpl_polynomial_eval(pwave, pos);
819 if (!pwave || !isnormal(ltest) || fabs(ltest) < DBL_EPSILON) {
820 char *msg = cpl_sprintf(
"Wavelength calibration polynomial for slice %d " 821 "of IFU %hhu is not well defined!", islice + 1,
823 cpl_error_set_message(__func__, CPL_ERROR_ILLEGAL_INPUT,
"%s", msg);
824 cpl_msg_error(__func__,
"%s", msg);
826 cpl_polynomial_delete(pwave);
827 cpl_vector_delete(pos);
828 if (getenv(
"MUSE_EXPERT_USER")) {
831 cpl_table_delete(geopos);
841 char *msg = cpl_sprintf(
"Tracing polynomials for slice %d of IFU %hhu are" 842 " not well defined!", islice + 1, ifu);
843 cpl_error_set_message(__func__, CPL_ERROR_ILLEGAL_INPUT,
"%s", msg);
844 cpl_msg_error(__func__,
"%s", msg);
846 cpl_polynomial_delete(pwave);
847 cpl_vector_delete(pos);
848 if (getenv(
"MUSE_EXPERT_USER")) {
851 cpl_table_delete(geopos);
857 ptrace[MUSE_TRACE_LEFT],
862 for (j = 1; j <= ysize; j++) {
865 double x1 = cpl_polynomial_eval_1d(ptrace[MUSE_TRACE_LEFT], j, NULL),
866 x2 = cpl_polynomial_eval_1d(ptrace[MUSE_TRACE_RIGHT], j, NULL),
867 xcenter = (x1 + x2) / 2.,
869 if (!isnormal(x1) || !isnormal(x2) || x1 < 1 || x2 > xsize || x1 > x2) {
870 cpl_msg_warning(__func__,
"slice %2d of IFU %hhu: faulty polynomial " 871 "detected at y=%d (borders: %f ... %f)", islice + 1,
876 int ileft = ceil(x1),
878 cpl_vector_set(pos, 1, j);
882 for (i = ileft; i <= iright; i++) {
883 cpl_vector_set(pos, 0, i);
887 double lambda = cpl_polynomial_eval(pwave, pos);
888 if (lambda < 3000. || lambda > 11000. || !isfinite(lambda)) {
899 float dx = (xcenter - i) / width
900 * (slice_width ? slice_width[islice] : kMuseSliceNominalWidth);
901 #if DEBUG_PIXTABLE_CREATION 902 if (fabs(dx) > 37.5) {
903 cpl_msg_debug(__func__,
"%d - %f -> %f", i, xcenter, dx);
907 #if CREATE_MINIMAL_PIXTABLE 909 if (lambda < 6495. || lambda > 6505. || fabs(dx) > 10.) {
915 cpl_size irow = itablerow++;
916 #if !PIXTABLE_CREATE_CCDSIZED 918 #if DEBUG_PIXTABLE_CREATION 919 printf(
"pixel table before enlargement:\n");
920 cpl_table_dump(pt->
table, irow-5, 10, stdout);
926 const cpl_size nr = 1000000;
927 cpl_msg_debug(__func__,
"expand table to %"CPL_SIZE_FORMAT
" rows " 928 "(add %"CPL_SIZE_FORMAT
" lines)!", irow + nr, nr);
929 cpl_table_set_size(pt->
table, irow + nr);
947 cdata_origin = (uint32_t *)cpl_table_get_data_int(pt->
table,
949 #if DEBUG_PIXTABLE_CREATION 950 printf(
"pixel table after filling new rows:\n");
951 cpl_table_dump(pt->
table, irow-5, 10, stdout);
958 double angle = slice_angle ? slice_angle[islice] * CPL_MATH_RAD_DEG
960 cdata_xpos[irow] = aGeoTable
961 ? dx * cos(angle) + slice_x[islice]
962 : dx + islice * kMuseSliceHiLikelyWidth
963 + kMuseSliceHiLikelyWidth / 2.;
964 cdata_ypos[irow] = aGeoTable
965 ? dx * sin(angle) + slice_y[islice]
967 #if DEBUG_PIXTABLE_CREATION 968 if (!isfinite(cdata_xpos[irow]) ||
969 cdata_xpos[irow] < -200 || cdata_xpos[irow] > 4000) {
970 cpl_msg_debug(__func__,
"weird data in x: %e %e",
971 cdata_xpos[irow], cdata_ypos[irow]);
973 if (!isfinite(cdata_ypos[irow]) ||
974 cdata_ypos[irow] < -200 || cdata_ypos[irow] > 200) {
975 cpl_msg_debug(__func__,
"weird data in y: %e %e",
976 cdata_xpos[irow], cdata_ypos[irow]);
979 cdata_lambda[irow] = lambda;
982 cdata_data[irow] = pixdata[(i-1) + (j-1)*xsize];
983 cdata_dq[irow] = pixdq[(i-1) + (j-1)*xsize];
984 cdata_stat[irow] = pixstat[(i-1) + (j-1)*xsize];
986 cdata_origin[irow] = muse_pixtable_origin_encode_fast(i, j, ifu,
994 cpl_polynomial_delete(pwave);
995 cpl_vector_delete(pos);
997 cpl_table_delete(geopos);
998 cpl_msg_debug(__func__,
"IFU %hhu took %gs (CPU time), %gs (wall-clock)",
999 ifu, cpl_test_get_cputime() - cputime,
1000 cpl_test_get_walltime() - walltime);
1004 cpl_msg_debug(__func__,
"Trimming pixel table of IFU %hhu to %"CPL_SIZE_FORMAT
1005 " of %"CPL_SIZE_FORMAT
" rows", ifu, itablerow,
1007 #if DEBUG_PIXTABLE_CREATION 1008 printf(
"end of used part of pixel table before trimming:\n");
1009 cpl_table_dump(pt->
table, itablerow-5, 10, stdout);
1012 cpl_table_set_size(pt->
table, itablerow);
1017 #if DEBUG_PIXTABLE_CREATION 1018 printf(
"beginning of pixel table before returning:\n");
1019 cpl_table_dump(pt->
table, 0, 5, stdout);
1021 printf(
"end of pixel table before returning:\n");
1046 if (aPixtable == NULL) {
1050 pt->
table = cpl_table_duplicate(aPixtable->
table);
1051 pt->
header = cpl_propertylist_duplicate(aPixtable->
header);
1074 cpl_table_delete(aPixtable->
table);
1075 aPixtable->
table = NULL;
1078 cpl_propertylist_delete(aPixtable->
header);
1079 aPixtable->
header = NULL;
1082 cpl_table_delete(aPixtable->
ffspec);
1083 aPixtable->
ffspec = NULL;
1085 cpl_free(aPixtable);
1116 cpl_table *aTrace, cpl_table *aWave,
float aSampling)
1118 cpl_ensure_code(aPixtable, CPL_ERROR_NULL_INPUT);
1122 cpl_table_delete(aPixtable->
ffspec);
1128 return cpl_error_get_code();
1137 cpl_table_erase_column(aPixtable->
ffspec,
"stat");
1138 cpl_table_erase_column(aPixtable->
ffspec,
"dq");
1140 return CPL_ERROR_NONE;
1156 static cpl_error_code
1157 muse_pixtable_save_ffspec(
muse_pixtable *aPixtable,
const char *aFilename)
1159 cpl_ensure_code(aPixtable, CPL_ERROR_NULL_INPUT);
1162 if (!aPixtable->
ffspec) {
1165 return CPL_ERROR_NONE;
1169 cpl_propertylist *hext = cpl_propertylist_new();
1171 cpl_error_code rc = cpl_table_save(aPixtable->
ffspec, NULL, hext, aFilename,
1173 cpl_propertylist_delete(hext);
1200 static cpl_error_code
1201 muse_pixtable_save_image(
muse_pixtable *aPixtable,
const char *aFilename)
1203 const char *
id =
"muse_pixtable_save";
1204 cpl_ensure_code(aPixtable, CPL_ERROR_NULL_INPUT);
1206 cpl_ensure_code(nrow > 0, CPL_ERROR_ILLEGAL_INPUT);
1208 cpl_errorstate state = cpl_errorstate_get();
1209 cpl_array *columns = cpl_table_get_column_names(aPixtable->
table);
1210 int icol, ncol = cpl_array_get_size(columns);
1211 for (icol = 0; icol < ncol; icol++) {
1212 const char *colname = cpl_array_get_string(columns, icol);
1214 cpl_type type = cpl_table_get_column_type(aPixtable->
table, colname);
1215 cpl_image *image = NULL;
1217 case CPL_TYPE_FLOAT: {
1218 float *data = cpl_table_get_data_float(aPixtable->
table, colname);
1219 image = cpl_image_wrap_float(1, nrow, data);
1222 case CPL_TYPE_INT: {
1223 int *data = cpl_table_get_data_int(aPixtable->
table, colname);
1224 image = cpl_image_wrap_int(1, nrow, data);
1228 cpl_error_set_message(
id, CPL_ERROR_UNSUPPORTED_MODE,
"type \"%s\" (of " 1229 "column %s) is not supported for MUSE pixel tables",
1230 cpl_type_get_name(type), colname);
1235 cpl_propertylist *hext = cpl_propertylist_new();
1236 cpl_propertylist_append_string(hext,
"EXTNAME", colname);
1237 const char *unit = cpl_table_get_column_unit(aPixtable->
table, colname);
1239 cpl_propertylist_append_string(hext,
"BUNIT", unit);
1241 cpl_image_save(image, aFilename, CPL_TYPE_UNSPECIFIED, hext, CPL_IO_EXTEND);
1242 cpl_image_unwrap(image);
1243 cpl_propertylist_delete(hext);
1245 cpl_array_delete(columns);
1248 muse_pixtable_save_ffspec(aPixtable, aFilename);
1250 return cpl_errorstate_is_equal(state) ? CPL_ERROR_NONE : cpl_error_get_code();
1278 cpl_ensure_code(aPixtable, CPL_ERROR_NULL_INPUT);
1284 cpl_error_code rc = cpl_propertylist_save(aPixtable->
header, aFilename,
1286 if (rc != CPL_ERROR_NONE) {
1287 cpl_error_set_message(__func__, rc,
"could not save FITS header of pixel " 1288 "table \"%s\"", aFilename);
1292 cpl_boolean astable = getenv(
"MUSE_PIXTABLE_SAVE_AS_TABLE")
1293 && atoi(getenv(
"MUSE_PIXTABLE_SAVE_AS_TABLE")) > 0;
1295 cpl_msg_debug(__func__,
"Saving pixel table \"%s\" as binary table",
1297 rc = cpl_table_save(aPixtable->
table, NULL, NULL, aFilename, CPL_IO_EXTEND);
1299 muse_pixtable_save_ffspec(aPixtable, aFilename);
1301 rc = muse_pixtable_save_image(aPixtable, aFilename);
1333 muse_pixtable_load_window_image(
const char *aFilename,
1334 cpl_size aStart, cpl_size aNRows)
1336 const char *
id =
"muse_pixtable_load";
1339 cpl_size y1 = aStart + 1,
1340 y2 = aStart + aNRows;
1343 cpl_propertylist *hdata = cpl_propertylist_load(aFilename, ext);
1349 cpl_propertylist_delete(hdata);
1353 cpl_table *table = cpl_table_new(nrow);
1354 int iext, next = cpl_fits_count_extensions(aFilename);
1355 for (iext = 1; iext <= next; iext++) {
1357 cpl_propertylist *hext = cpl_propertylist_load(aFilename, iext);
1361 cpl_propertylist_delete(hext);
1366 cpl_errorstate ps = cpl_errorstate_get();
1367 cpl_image *column = cpl_image_load_window(aFilename, CPL_TYPE_UNSPECIFIED,
1368 0, iext, 1, y1, 1, y2);
1369 if (!column || !cpl_errorstate_is_equal(ps)) {
1370 cpl_image_delete(column);
1371 cpl_error_set_message(
id, cpl_error_get_code(),
"could not load extension" 1372 " %d of pixel table \"%s\"", iext, aFilename);
1373 cpl_propertylist_delete(hext);
1376 cpl_size nrows = cpl_image_get_size_x(column)
1377 * cpl_image_get_size_y(column);
1379 cpl_table_set_size(table, nrows);
1381 }
else if (nrows != nrow) {
1382 cpl_error_set_message(
id, CPL_ERROR_INCOMPATIBLE_INPUT,
"size of column " 1383 "%s does not match", colname);
1384 cpl_propertylist_delete(hext);
1385 cpl_image_delete(column);
1388 cpl_type type = cpl_image_get_type(column);
1390 case CPL_TYPE_FLOAT:
1391 cpl_table_wrap_float(table, cpl_image_unwrap(column), colname);
1394 cpl_table_wrap_int(table, cpl_image_unwrap(column), colname);
1397 cpl_error_set_message(
id, CPL_ERROR_UNSUPPORTED_MODE,
"type \"%s\" (of " 1398 "column %s) is not supported for MUSE pixel tables",
1399 cpl_type_get_name(type), colname);
1401 cpl_errorstate state = cpl_errorstate_get();
1403 if (!cpl_errorstate_is_equal(state)) {
1404 cpl_errorstate_set(state);
1407 cpl_table_set_column_unit(table, colname, unit);
1409 cpl_propertylist_delete(hext);
1430 static cpl_error_code
1431 muse_pixtable_load_ffspec(
const char *aFilename,
muse_pixtable *aPixtable)
1433 const char *
id =
"muse_pixtable_load";
1434 cpl_ensure_code(aFilename && aPixtable, CPL_ERROR_NULL_INPUT);
1440 return CPL_ERROR_NONE;
1443 cpl_errorstate es = cpl_errorstate_get();
1444 aPixtable->
ffspec = cpl_table_load(aFilename, iext, 1);
1445 if (!cpl_errorstate_is_equal(es)) {
1446 cpl_msg_warning(
id,
"Pixel table flat-field spectrum extension %s " 1447 "exists in \"%s\", but cannot be loaded!",
1451 cpl_table_delete(aPixtable->
ffspec);
1452 aPixtable->
ffspec = NULL;
1455 cpl_errorstate_set(es);
1458 return CPL_ERROR_NONE;
1489 cpl_size aStart, cpl_size aNRows)
1495 cpl_errorstate prestate = cpl_errorstate_get();
1496 pt->
header = cpl_propertylist_load(aFilename, 0);
1497 cpl_ensure(cpl_errorstate_is_equal(prestate) && pt->
header,
1498 cpl_error_get_code(), NULL);
1500 cpl_msg_error(__func__,
"unknown pixel table type found in \"%s\"", aFilename);
1507 cpl_propertylist *hext = cpl_propertylist_load(aFilename, 1);
1508 cpl_boolean asimage = !strcmp(cpl_propertylist_get_string(hext,
"XTENSION"),
1510 cpl_propertylist_delete(hext);
1514 cpl_msg_info(__func__,
"Loading pixel table \"%s\" (image format)",
1516 pt->
table = muse_pixtable_load_window_image(aFilename, aStart, aNRows);
1518 cpl_msg_info(__func__,
"Loading pixel table \"%s\" (bintable format)",
1520 pt->
table = cpl_table_load_window(aFilename, 1, 0, NULL, aStart, aNRows);
1522 if (!cpl_errorstate_is_equal(prestate) || !pt->
table) {
1523 cpl_msg_error(__func__,
"Failed to load table part of pixel table \"%s\"",
1529 if (rc != CPL_ERROR_NONE) {
1530 cpl_error_set_message(__func__, rc,
"pixel table \"%s\" does not contain " 1531 "all expected columns", aFilename);
1535 muse_pixtable_load_ffspec(aFilename, pt);
1564 cpl_errorstate prestate = cpl_errorstate_get();
1565 cpl_propertylist *theader = cpl_propertylist_load(aFilename, 1);
1566 cpl_ensure(cpl_errorstate_is_equal(prestate) && theader,
1567 cpl_error_get_code(), NULL);
1568 cpl_size nrow = cpl_propertylist_get_long_long(theader,
"NAXIS2");
1569 cpl_propertylist_delete(theader);
1596 double aLambdaMin,
double aLambdaMax)
1604 if (rc != CPL_ERROR_NONE) {
1609 cpl_msg_error(__func__,
"Pixel table contains no entries after cutting to " 1610 "%.3f..%.3f Angstrom", aLambdaMin, aLambdaMax);
1611 cpl_error_set(__func__, CPL_ERROR_DATA_NOT_FOUND);
1668 double aLambdaMin,
double aLambdaMax)
1670 cpl_ensure(aExposureList, CPL_ERROR_NULL_INPUT, NULL);
1673 if (cpl_table_has_column(aExposureList,
"00")) {
1674 const char *filename = cpl_table_get_string(aExposureList,
"00", 0);
1685 cpl_array *lambdas = cpl_array_new((kMuseLambdaMaxX - kMuseLambdaMinX)
1686 / kMuseSpectralSamplingA + 1,
1689 int j, nwl = cpl_array_get_size(lambdas);
1690 for (j = 0; j < nwl; j++) {
1691 cpl_array_set_double(lambdas, j, kMuseLambdaMinX
1692 + j * kMuseSpectralSamplingA);
1695 cpl_boolean isfirst = CPL_TRUE;
1696 double fluxlref = 0,
1698 int i, nifu = 0, nflats = 0;
1699 for (i = 1; i <= kMuseNumIFUs; i++) {
1700 char *colname = cpl_sprintf(
"%02d", i);
1701 const char *filename = cpl_table_get_string(aExposureList, colname, 0);
1704 cpl_msg_warning(__func__,
"Channel for IFU %02d is missing", i);
1711 cpl_msg_error(__func__,
"failed to load pixel table from \"%s\"",
1713 cpl_array_delete(lambdas);
1721 cpl_msg_debug(__func__,
"loaded pixel table with %"CPL_SIZE_FORMAT
" rows",
1723 isfirst = CPL_FALSE;
1724 cpl_errorstate prestate = cpl_errorstate_get();
1725 fluxsref = cpl_propertylist_get_double(pt->
header, MUSE_HDR_FLAT_FLUX_SKY);
1726 fluxlref = cpl_propertylist_get_double(pt->
header, MUSE_HDR_FLAT_FLUX_LAMP);
1727 if (fluxsref == 0. && fluxlref == 0. && !cpl_errorstate_is_equal(prestate)) {
1731 cpl_msg_debug(__func__,
"\"%s\" was previously merged (got \"%s\" when" 1732 " asking for flat-field fluxes)", filename,
1733 cpl_error_get_message());
1734 cpl_errorstate_set(prestate);
1737 if (fluxsref == 0. && fluxlref > 0. && !cpl_errorstate_is_equal(prestate)) {
1739 cpl_msg_warning(__func__,
"only found reference lamp-flat flux (%e) in " 1740 "\"%s\", flux levels may vary between IFUs!", fluxlref,
1742 cpl_errorstate_set(prestate);
1744 cpl_msg_debug(__func__,
"reference flat fluxes sky: %e lamp: %e",
1745 fluxsref, fluxlref);
1747 cpl_propertylist_erase(pt->
header, MUSE_HDR_FLAT_FLUX_SKY);
1748 cpl_propertylist_erase(pt->
header, MUSE_HDR_FLAT_FLUX_LAMP);
1756 cpl_table_delete(pt->
ffspec);
1767 cpl_errorstate state = cpl_errorstate_get();
1768 double fluxs = cpl_propertylist_get_double(onept->
header,
1769 MUSE_HDR_FLAT_FLUX_SKY),
1770 fluxl = cpl_propertylist_get_double(onept->
header,
1771 MUSE_HDR_FLAT_FLUX_LAMP),
1773 if (fluxsref > 0. && fluxs > 0.) {
1774 scale = fluxs / fluxsref;
1775 }
else if (fluxlref > 0. && fluxl > 0.) {
1776 scale = fluxl / fluxlref;
1777 if (!cpl_errorstate_is_equal(state)) {
1778 cpl_msg_warning(__func__,
"only found relative lamp-flat flux (%e) in " 1779 "\"%s\", flux levels may vary between IFUs!", fluxl,
1781 cpl_errorstate_set(state);
1793 cpl_array_add(ffspec, ffout);
1795 cpl_array_delete(ffout);
1801 cpl_msg_debug(__func__,
"big pixel table now has %"CPL_SIZE_FORMAT
" entries," 1802 " scale was %e (flat fluxes sky: %e lamp: %e)",
1812 if (nflats > 0 && nifu != nflats) {
1813 cpl_error_set_message(__func__, CPL_ERROR_ILLEGAL_INPUT,
"Only %d of %d " 1814 "pixel tables of this exposure came with a flat-field" 1815 " spectrum, cannot continue!", nflats, nifu);
1816 cpl_array_delete(lambdas);
1817 cpl_array_delete(ffspec);
1825 cpl_array_divide_scalar(ffspec, nflats);
1826 cpl_msg_debug(__func__,
"Average of flat-field spectrum: %.4f",
1827 cpl_array_get_mean(ffspec));
1831 MUSE_PIXTABLE_OPERATION_MULTIPLY);
1836 MUSE_HDR_PT_FFCORR_COMMENT);
1840 pt->
ffspec = cpl_table_new(cpl_array_get_size(lambdas));
1845 cpl_array_delete(ffspec);
1849 cpl_table_erase_invalid(pt->
ffspec);
1851 cpl_array_delete(lambdas);
1856 cpl_error_set_message(__func__, CPL_ERROR_FILE_NOT_FOUND,
1857 "None of the pixel tables could be loaded");
1865 cpl_propertylist_erase_regexp(pt->
header,
"ESO DET (CHIP|OUT) ", 0);
1866 cpl_propertylist_erase_regexp(pt->
header,
"ESO DET2 ", 0);
1870 MUSE_HDR_PT_MERGED_COMMENT);
1891 const char *type = cpl_propertylist_get_string(aPixtable->
header,
1894 cpl_msg_debug(__func__,
"pixel table type \"%s\"", type);
1899 if (!strncmp(type, MUSE_PIXTABLE_STRING_FULL,
1900 strlen(MUSE_PIXTABLE_STRING_FULL) + 1)) {
1902 }
else if (!strncmp(type, MUSE_PIXTABLE_STRING_SIMPLE,
1903 strlen(MUSE_PIXTABLE_STRING_SIMPLE) + 1)) {
1924 cpl_ensure(aPixtable, CPL_ERROR_NULL_INPUT, 0);
1925 cpl_ensure(aPixtable->
table, CPL_ERROR_NULL_INPUT, 0);
1928 return cpl_table_get_nrow(aPixtable->
table);
1952 cpl_ensure_code(aPixtable && aPixtable->
table && aPixtable->
header,
1953 CPL_ERROR_NULL_INPUT);
1955 == CPL_ERROR_NONE, CPL_ERROR_DATA_NOT_FOUND);
1958 return CPL_ERROR_NONE;
1964 uint32_t *origin = (uint32_t *)cpl_table_get_data_int(aPixtable->
table,
1967 float xlo = FLT_MAX, xhi = -FLT_MAX,
1968 ylo = FLT_MAX, yhi = -FLT_MAX,
1969 llo = FLT_MAX, lhi = -FLT_MAX;
1970 int ifulo = INT_MAX, ifuhi = 0,
1971 slicelo = INT_MAX, slicehi = 0;
1973 for (i = 0; i < nrow; i++) {
1974 if (cdata_xpos[i] > xhi) xhi = cdata_xpos[i];
1975 if (cdata_xpos[i] < xlo) xlo = cdata_xpos[i];
1976 if (cdata_ypos[i] > yhi) yhi = cdata_ypos[i];
1977 if (cdata_ypos[i] < ylo) ylo = cdata_ypos[i];
1978 if (cdata_lambda[i] > lhi) lhi = cdata_lambda[i];
1979 if (cdata_lambda[i] < llo) llo = cdata_lambda[i];
1980 int ifu = muse_pixtable_origin_get_ifu_fast(origin[i]),
1981 slice = muse_pixtable_origin_get_slice_fast(origin[i]);
1982 if (ifu > ifuhi) ifuhi = ifu;
1983 if (ifu < ifulo) ifulo = ifu;
1984 if (slice > slicehi) slicehi = slice;
1985 if (slice < slicelo) slicelo = slice;
1987 char *dodebug = getenv(
"MUSE_DEBUG_PIXTABLE_LIMITS");
1988 if (dodebug && atoi(dodebug)) {
1989 cpl_msg_debug(__func__,
"x: %f...%f, y: %f...%f, lambda: %f...%f, " 1990 "ifu: %d...%d, slice: %d...%d",
1991 xlo, xhi, ylo, yhi, llo, lhi, ifulo, ifuhi, slicelo, slicehi);
1993 cpl_propertylist_erase_regexp(aPixtable->
header, MUSE_HDR_PT_LIMITS_REGEXP, 0);
2011 return CPL_ERROR_NONE;
2033 cpl_ensure_code(aPixtable && aPixtable->
table, CPL_ERROR_NULL_INPUT);
2034 cpl_errorstate prestate = cpl_errorstate_get();
2037 cpl_error_code rc = CPL_ERROR_NONE;
2038 if (!cpl_errorstate_is_equal(prestate)) {
2039 rc = cpl_error_get_code();
2080 const cpl_array *aLambdas,
const cpl_array *aFlux,
2083 cpl_ensure_code(aPixtable && aPixtable->
table, CPL_ERROR_NULL_INPUT);
2084 cpl_ensure_code(aLambdas && aFlux, CPL_ERROR_NULL_INPUT);
2085 cpl_ensure_code(cpl_array_get_size(aLambdas) > 0 &&
2086 cpl_array_get_size(aLambdas) == cpl_array_get_size(aFlux),
2087 CPL_ERROR_ILLEGAL_INPUT);
2088 cpl_ensure_code(cpl_array_get_type(aLambdas) == CPL_TYPE_DOUBLE &&
2089 cpl_array_get_type(aFlux) == CPL_TYPE_DOUBLE,
2090 CPL_ERROR_INCOMPATIBLE_INPUT);
2100 switch (aOperation) {
2101 case MUSE_PIXTABLE_OPERATION_SUBTRACT:
2102 cpl_msg_debug(__func__,
"Subtracting spectrum from pixel table with %" 2103 CPL_SIZE_FORMAT
" slices...", nslices);
2105 case MUSE_PIXTABLE_OPERATION_MULTIPLY:
2106 cpl_msg_debug(__func__,
"Multiplying pixel table of %"CPL_SIZE_FORMAT
2107 " slices with spectrum...", nslices);
2109 case MUSE_PIXTABLE_OPERATION_DIVIDE:
2110 cpl_msg_debug(__func__,
"Dividing pixel table of %"CPL_SIZE_FORMAT
2111 " slices with spectrum...", nslices);
2115 return cpl_error_set(__func__, CPL_ERROR_UNSUPPORTED_MODE);
2119 #pragma omp parallel for default(none) \ 2120 shared(aFlux, aLambdas, aOperation, nslices, slicepts) 2121 for (islice = 0; islice < nslices; islice++) {
2123 cpl_propertylist *order = cpl_propertylist_new();
2125 cpl_table_sort(thispt->
table, order);
2126 cpl_propertylist_delete(order);
2142 if (aOperation == MUSE_PIXTABLE_OPERATION_SUBTRACT) {
2143 cpl_array_subtract(datapt, fint);
2144 }
else if (aOperation == MUSE_PIXTABLE_OPERATION_DIVIDE) {
2145 cpl_array_divide(datapt, fint);
2147 cpl_array_divide(statpt, fint);
2148 cpl_array_divide(statpt, fint);
2150 cpl_array_multiply(datapt, fint);
2152 cpl_array_multiply(statpt, fint);
2153 cpl_array_multiply(statpt, fint);
2155 cpl_array_delete(fint);
2157 cpl_array_unwrap(datapt);
2158 cpl_array_unwrap(statpt);
2159 cpl_array_unwrap(lambdapt);
2160 cpl_table_erase_column(thispt->
table,
"lbda_d");
2164 return CPL_ERROR_NONE;
2178 static cpl_error_code
2181 cpl_ensure_code(aPixtable && aPixtable->
header && aPixtable->
table,
2182 CPL_ERROR_NULL_INPUT);
2183 if (cpl_table_count_selected(aPixtable->
table) < 1) {
2184 return CPL_ERROR_NONE;
2186 cpl_array *sel = cpl_table_where_selected(aPixtable->
table);
2187 cpl_size narray = cpl_array_get_size(sel),
2190 const cpl_size *asel = cpl_array_get_data_cplsize_const(sel);
2191 unsigned int nexp = 0;
2196 if (!cpl_propertylist_has(aPixtable->
header, kwfst) ||
2197 !cpl_propertylist_has(aPixtable->
header, kwlst)) {
2202 ifst = cpl_propertylist_get_long_long(aPixtable->
header, kwfst);
2203 ilst = cpl_propertylist_get_long_long(aPixtable->
header, kwlst);
2205 cpl_size i, nsel = 0;
2206 for (i = 0; i < narray; i++) {
2207 if (asel[i] >= ifst && asel[i] <= ilst) {
2211 cpl_size ifst2 = ifst - nselprev,
2212 ilst2 = ilst - nsel - nselprev;
2213 cpl_msg_debug(__func__,
"exp %d old %"CPL_SIZE_FORMAT
"..%"CPL_SIZE_FORMAT
2214 ", %"CPL_SIZE_FORMAT
" selected (previous: %"CPL_SIZE_FORMAT
2215 "), new %"CPL_SIZE_FORMAT
"..%"CPL_SIZE_FORMAT, nexp,
2216 ifst, ilst, nsel, nselprev, ifst2, ilst2);
2223 }
while (ilst >= ifst);
2224 cpl_array_delete(sel);
2225 return CPL_ERROR_NONE;
2251 cpl_ensure_code(aPixtable && aPixtable->
table && aPixtable->
header,
2252 CPL_ERROR_NULL_INPUT);
2256 return CPL_ERROR_NONE;
2258 #pragma omp critical(cpl_table_select) 2260 cpl_table_unselect_all(aPixtable->
table);
2262 CPL_LESS_THAN, aLow);
2264 CPL_GREATER_THAN, aHigh);
2266 cpl_table_erase_selected(aPixtable->
table);
2271 #pragma omp critical(cpl_table_select) 2273 cpl_table_unselect_all(aPixtable->
ffspec);
2276 aLow - 2. * kMuseSpectralSamplingA);
2279 aHigh + 2. * kMuseSpectralSamplingA);
2280 cpl_table_erase_selected(aPixtable->
ffspec);
2301 cpl_ensure_code(aPixtable && aPixtable->
table && aPixtable->
header,
2302 CPL_ERROR_NULL_INPUT);
2306 return CPL_ERROR_NONE;
2313 #pragma omp critical(cpl_table_select) 2315 cpl_table_unselect_all(aPixtable->
table);
2317 CPL_LESS_THAN, aLo - ptxoff);
2319 CPL_GREATER_THAN, aHi - ptxoff);
2321 cpl_table_erase_selected(aPixtable->
table);
2341 cpl_ensure_code(aPixtable && aPixtable->
table && aPixtable->
header,
2342 CPL_ERROR_NULL_INPUT);
2346 return CPL_ERROR_NONE;
2353 #pragma omp critical(cpl_table_select) 2355 cpl_table_unselect_all(aPixtable->
table);
2357 CPL_LESS_THAN, aLo - ptyoff);
2359 CPL_GREATER_THAN, aHi - ptyoff);
2361 cpl_table_erase_selected(aPixtable->
table);
2383 unsigned short aSlice)
2385 cpl_ensure_code(aPixtable, CPL_ERROR_NULL_INPUT);
2387 cpl_ensure_code(nrow > 0, CPL_ERROR_DATA_NOT_FOUND);
2389 cpl_table_unselect_all(aPixtable->
table);
2390 uint32_t *origin = (uint32_t *)cpl_table_get_data_int(aPixtable->
table,
2393 for (irow = 0; irow < nrow; irow++) {
2396 if (ifu == aIFU && slice == aSlice) {
2397 cpl_table_select_row(aPixtable->
table, irow);
2400 cpl_size nsel = cpl_table_count_selected(aPixtable->
table);
2401 cpl_error_code rc = cpl_table_erase_selected(aPixtable->
table);
2402 cpl_msg_debug(__func__,
"Erased %"CPL_SIZE_FORMAT
" rows from pixel table",
2436 const cpl_propertylist *aWCS,
2437 const cpl_table *aOffsets)
2439 cpl_ensure_code(aPixtable && aPixtable->
table, CPL_ERROR_NULL_INPUT);
2440 cpl_ensure_code(aMask && aMask->
mask && aMask->
header, CPL_ERROR_NULL_INPUT);
2443 cpl_errorstate state = cpl_errorstate_get();
2445 if (!maskwcs || !cpl_errorstate_is_equal(state)) {
2446 cpl_msg_error(__func__,
"Selecting pixel table rows using mask failed due " 2447 "to faulty WCS in mask header: %s", cpl_error_get_message());
2449 return cpl_error_get_code();
2458 maskwcs->
iscelsph = (ctype1 && strlen(ctype1) >= 5 && ctype1[4] ==
'-')
2459 && (ctype2 && strlen(ctype2) >= 5 && ctype2[4] ==
'-');
2461 if (maskwcs->
iscelsph && (!strstr(ctype1,
"-TAN") || !strstr(ctype2,
"-TAN"))) {
2462 cpl_msg_warning(__func__,
"Cannot use mask WCS for pixel selection, " 2463 "unsupported celestial WCS (%s / %s)", ctype1, ctype2);
2464 return CPL_ERROR_UNSUPPORTED_MODE;
2467 if (maskwcs->
iscelsph && ((cunit1 && strncmp(cunit1,
"deg", 4)) ||
2468 (cunit2 && strncmp(cunit2,
"deg", 4)))) {
2469 cpl_msg_warning(__func__,
"Cannot use mask WCS for pixel selection, " 2470 "celestial gnomonic WCS with unsupported units (%s / %s)",
2472 return CPL_ERROR_UNSUPPORTED_MODE;
2479 double ra = 0., dec = 0.;
2486 cpl_msg_warning(__func__,
"Using default MUSE %cFM astrometry, pixel " 2487 "selection using mask will be inaccurate!", mode[0]);
2490 cpl_propertylist_delete(wcs);
2494 cpl_msg_warning(__func__,
"Using mask with celestial WCS for pixel " 2495 "selection, but no %s was given. Results will likely " 2496 "be inaccurate!", MUSE_TAG_OFFSET_LIST);
2503 maskwcs->crval1 /= CPL_MATH_DEG_RAD;
2504 maskwcs->
crval2 /= CPL_MATH_DEG_RAD;
2510 cpl_size nx = cpl_mask_get_size_x(aMask->
mask),
2511 ny = cpl_mask_get_size_y(aMask->
mask);
2512 const cpl_binary *maskdata = cpl_mask_get_data_const(aMask->
mask);
2514 cpl_size irow, nrows = cpl_table_get_nrow(aPixtable->
table),
2515 nsel = cpl_table_count_selected(aPixtable->
table),
2516 nenabled = cpl_mask_count(aMask->
mask),
2518 cpl_msg_debug(__func__,
"Mask contains %"CPL_SIZE_FORMAT
" (%.2f %%) enabled " 2519 "pixels of %"CPL_SIZE_FORMAT
" total [%s WCS, %s/%s, units " 2520 "%s/%s]", nenabled, 100.*nenabled/nx/ny, nx*ny,
2521 maskwcs->
iscelsph ?
"celestial (gnomonic)" :
"linear",
2522 ctype1, ctype2, cunit1, cunit2);
2523 #if PIXTABLE_MASK_PARALLEL 2524 #pragma omp parallel for default(none) \ 2525 shared(aPixtable, dec, maskdata, maskwcs, narea, nrows, nsel, nx, ny,\ 2528 for (irow = 0; irow < nrows; irow++) {
2535 (xpos[irow] + ra) * CPL_MATH_RAD_DEG,
2536 (ypos[irow] + dec) * CPL_MATH_RAD_DEG,
2543 if ((ix < 1) || (ix > nx) || (iy < 1) || (iy > ny)) {
2546 #if PIXTABLE_MASK_PARALLEL 2551 if (maskdata[(ix-1) + (iy-1) * nx] != CPL_BINARY_1) {
2552 #if PIXTABLE_MASK_PARALLEL 2553 #pragma omp critical 2556 cpl_table_unselect_row(aPixtable->
table, irow);
2566 cpl_msg_debug(__func__,
"Mask selected %"CPL_SIZE_FORMAT
" (%.2f %%/%.2f %%) " 2567 "pixels of %"CPL_SIZE_FORMAT
" total/%"CPL_SIZE_FORMAT
" in mask " 2568 "area", nsel, 100.*nsel/nrows, 100.*nsel/narea, nrows, narea);
2569 return CPL_ERROR_NONE;
2602 unsigned char aDisplayHeader)
2604 cpl_ensure_code(aPixtable && aPixtable->
table && aPixtable->
header,
2605 CPL_ERROR_NULL_INPUT);
2607 cpl_ensure_code(aStart >= 0 && aStart < nrows && aCount >= 0,
2608 CPL_ERROR_ILLEGAL_INPUT);
2609 cpl_size last = aStart + aCount;
2610 if (last > nrows - 1) {
2614 double ptxoff = 0., ptyoff = 0.;
2628 cpl_errorstate es = cpl_errorstate_get();
2630 cpl_errorstate_set(es);
2632 uint32_t *cdata_origin = (uint32_t *)cpl_table_get_data_int(aPixtable->
table,
2634 cpl_ensure_code(cdata_xpos && cdata_ypos && cdata_lambda &&
2635 cdata_data && cdata_dq && cdata_stat,
2636 CPL_ERROR_BAD_FILE_FORMAT);
2639 if (aDisplayHeader) {
2640 printf(
"# xpos ypos lambda data dq stat" 2641 " weight exposure IFU xCCD yCCD xRaw yRaw slice\n");
2643 if (aDisplayHeader == 1) {
2644 printf(
"#%13s %13s %9s %11s flag %11s ---------- No No pix " 2645 " pix pix pix No\n# flux in [%s]\n# flux**2 in [%s]\n",
2649 "(flux)",
"(flux**2)",
2655 for (i = aStart; i < last; i++) {
2657 y = muse_pixtable_origin_get_y_fast(cdata_origin[i]),
2661 printf(
"%14.7e %14.7e %9.3f ", cdata_xpos[i] + ptxoff, cdata_ypos[i] + ptyoff,
2664 printf(
"%14.8f %14.8f %9.3f ", cdata_xpos[i], cdata_ypos[i], cdata_lambda[i]);
2666 printf(
"%12.5e 0x%08x %11.5e %10.4e %2d %2d %4d %4d %4d %4d %2d\n",
2667 cdata_data[i], cdata_dq[i], cdata_stat[i],
2668 cdata_weight ? cdata_weight[i] : 0.,
2670 cdata_origin ? muse_pixtable_origin_get_ifu_fast(cdata_origin[i])
2673 cdata_origin ? muse_pixtable_origin_get_slice_fast(cdata_origin[i])
2677 return CPL_ERROR_NONE;
2707 const char *unitx = cpl_table_get_column_unit(aPixtable->
table,
2709 *unity = cpl_table_get_column_unit(aPixtable->
table,
2714 cpl_ensure(!strncmp(unitx, unity, 4), CPL_ERROR_INCOMPATIBLE_INPUT,
2716 if (!strncmp(unitx,
"deg", 4)) {
2719 if (!strncmp(unitx,
"pix", 4)) {
2722 if (!strncmp(unitx,
"rad", 4)) {
2725 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT);
2741 cpl_ensure(aPixtable, CPL_ERROR_NULL_INPUT, CPL_FALSE);
2742 cpl_errorstate prestate = cpl_errorstate_get();
2743 cpl_boolean flag = cpl_propertylist_get_bool(aPixtable->
header,
2745 cpl_errorstate_set(prestate);
2761 cpl_ensure(aPixtable, CPL_ERROR_NULL_INPUT, CPL_FALSE);
2762 cpl_errorstate prestate = cpl_errorstate_get();
2763 cpl_boolean flag = cpl_propertylist_get_bool(aPixtable->
header,
2765 cpl_errorstate_set(prestate);
2781 cpl_ensure(aPixtable, CPL_ERROR_NULL_INPUT, CPL_FALSE);
2798 cpl_ensure_code(aPixtable, CPL_ERROR_NULL_INPUT);
2800 unsigned int *dq = (
unsigned int *)cpl_table_get_data_int(aPixtable->
table,
2804 #pragma omp parallel for default(none) \ 2805 shared(dq, inverse, nrow) 2806 for (i = 0; i < nrow; i++) {
2809 return CPL_ERROR_NONE;
2833 cpl_ensure(aPixtable && aPixtable->
header, CPL_ERROR_NULL_INPUT, NULL);
2837 cpl_ensure(expnum == explast, CPL_ERROR_ILLEGAL_INPUT, NULL);
2847 unsigned short ifu = 0,
2850 for (ipt = 0; ipt < npt; ipt++) {
2854 uint32_t *corigin = (uint32_t *)cpl_table_get_data_int(pts[ipt]->table,
2859 if (ifu != muse_pixtable_origin_get_ifu_fast(corigin[0])) {
2861 image->
header = cpl_propertylist_duplicate(pts[ipt]->header);
2862 cpl_propertylist_erase_regexp(image->
header,
"^ESO DRS MUSE PIXTABLE", 0);
2863 image->
data = cpl_image_new(kMuseOutputXRight, kMuseOutputYTop, CPL_TYPE_FLOAT);
2864 image->
dq = cpl_image_new(kMuseOutputXRight, kMuseOutputYTop, CPL_TYPE_INT);
2866 cpl_image_fill_noise_uniform(image->
dq, EURO3D_MISSDATA, EURO3D_MISSDATA + 0.1);
2867 image->
stat = cpl_image_new(kMuseOutputXRight, kMuseOutputYTop, CPL_TYPE_FLOAT);
2868 cpl_msg_debug(__func__,
"new image (index %hu in list)", ilist);
2872 cpl_msg_error(__func__,
"ipt = %d: no image!", ipt);
2875 float *idata = cpl_image_get_data_float(image->
data),
2876 *istat = cpl_image_get_data_float(image->
stat);
2877 int *idq = cpl_image_get_data_int(image->
dq);
2879 ifu = muse_pixtable_origin_get_ifu_fast(corigin[0]);
2880 unsigned short slice = muse_pixtable_origin_get_slice_fast(corigin[0]);
2883 x1 = INT_MAX, x2 = 0,
2885 for (irow = 0; irow < nrow; irow++) {
2887 unsigned int x = muse_pixtable_origin_get_x_fast(corigin[irow], xoff) - 1,
2888 y = muse_pixtable_origin_get_y_fast(corigin[irow]) - 1;
2889 idata[x + y*kMuseOutputXRight] = cdata[irow];
2890 idq[x + y*kMuseOutputXRight] = cdq[irow];
2891 istat[x + y*kMuseOutputXRight] = cstat[irow];
2900 char *keyword = cpl_sprintf(
"ESO DRS MUSE SLICE%hu CENTER", slice);
2901 cpl_propertylist_update_float(image->
header, keyword, (x2 + x1) / 2. + 1.);
2903 cpl_msg_debug(__func__,
"IFU %hu %s = %.1f", ifu, keyword,
2904 (x2 + x1) / 2. + 1.);
2943 cpl_ensure_code(aPixtable && aPixtable->
header && aList, CPL_ERROR_NULL_INPUT);
2947 cpl_ensure_code(expnum == explast, CPL_ERROR_ILLEGAL_INPUT);
2956 return cpl_error_set(__func__, CPL_ERROR_INCOMPATIBLE_INPUT);
2960 unsigned short ifu = 0,
2963 for (ipt = 0; ipt < npt; ipt++) {
2966 uint32_t *corigin = (uint32_t *)cpl_table_get_data_int(pts[ipt]->table,
2969 if (ifu != muse_pixtable_origin_get_ifu_fast(corigin[0])) {
2973 cpl_msg_error(__func__,
"ipt = %d: no image!", ipt);
2976 float *idata = cpl_image_get_data_float(image->
data),
2977 *istat = cpl_image_get_data_float(image->
stat);
2978 ifu = muse_pixtable_origin_get_ifu_fast(corigin[0]);
2979 unsigned short slice = muse_pixtable_origin_get_slice_fast(corigin[0]);
2983 for (irow = 0; irow < nrow; irow++) {
2985 unsigned int x = muse_pixtable_origin_get_x_fast(corigin[irow], xoff) - 1,
2986 y = muse_pixtable_origin_get_y_fast(corigin[irow]) - 1;
2987 cdata[irow] = idata[x + y*kMuseOutputXRight];
2988 cstat[irow] = istat[x + y*kMuseOutputXRight];
2993 return CPL_ERROR_NONE;
3011 cpl_ensure(aPixtable && aPixtable->
table && aPixtable->
header,
3012 CPL_ERROR_NULL_INPUT, NULL);
3014 pt->
header = cpl_propertylist_duplicate(aPixtable->
header);
3016 #pragma omp critical(cpl_table_select) 3018 cpl_table_select_all(aPixtable->
table);
3020 CPL_NOT_LESS_THAN, aLow);
3022 CPL_NOT_GREATER_THAN, aHigh);
3023 pt->
table = cpl_table_extract_selected(aPixtable->
table);
3024 cpl_table_select_all(aPixtable->
table);
3048 cpl_ensure(aPixtable, CPL_ERROR_NULL_INPUT, NULL);
3049 cpl_size n_rows = cpl_table_get_nrow(aPixtable->
table);
3050 unsigned int ifu_slice_mask = (0x1f << MUSE_ORIGIN_SHIFT_IFU) | 0x3f;
3051 cpl_table_duplicate_column(aPixtable->
table,
"ifuslice",
3053 unsigned int *slicedata = (
unsigned int *)
3054 cpl_table_get_data_int(aPixtable->
table,
"ifuslice");
3056 unsigned int last_ifu_slice = 0;
3057 int is_sorted = CPL_TRUE;
3058 for (i_row = 0; i_row < n_rows; i_row++) {
3059 slicedata[i_row] &= ifu_slice_mask;
3060 if (is_sorted && slicedata[i_row] < last_ifu_slice) {
3061 is_sorted = CPL_FALSE;
3063 last_ifu_slice = slicedata[i_row];
3067 cpl_propertylist *order = cpl_propertylist_new();
3068 cpl_propertylist_append_bool(order,
"ifuslice", CPL_FALSE);
3070 cpl_msg_debug(__func__,
"sorting pixel table: quick sort, %"CPL_SIZE_FORMAT
3071 " entries", n_rows);
3072 cpl_table_sort(aPixtable->
table, order);
3073 cpl_propertylist_delete(order);
3075 cpl_propertylist_erase_regexp(aPixtable->
header, MUSE_HDR_PT_EXP_REGEXP, 0);
3076 cpl_msg_debug(__func__,
"pixel table sorted.");
3080 cpl_size n_col = cpl_table_get_ncol(aPixtable->
table);
3081 cpl_array *colnames = cpl_table_get_column_names(aPixtable->
table);
3083 cpl_size n_slices = 0;
3084 while (i_row < n_rows) {
3085 unsigned int ifu_slice = slicedata[i_row];
3087 for (j_row = i_row+1; j_row < n_rows && slicedata[j_row] == ifu_slice;
3090 cpl_size nrows_slice = j_row - i_row;
3092 slice_pixtable->
table = cpl_table_new(nrows_slice);
3094 for (i_col = 0; i_col < n_col; i_col++) {
3095 const char *cname = cpl_array_get_string(colnames, i_col);
3096 if (strcmp(cname,
"ifuslice") == 0)
3098 cpl_type ctype = cpl_table_get_column_type(aPixtable->
table, cname);
3099 if (ctype == CPL_TYPE_INT) {
3100 int *cdata = cpl_table_get_data_int(aPixtable->
table, cname);
3101 cpl_table_wrap_int(slice_pixtable->
table, cdata + i_row, cname);
3102 }
else if (ctype == CPL_TYPE_FLOAT) {
3103 float *cdata = cpl_table_get_data_float(aPixtable->
table, cname);
3104 cpl_table_wrap_float(slice_pixtable->
table, cdata + i_row, cname);
3105 }
else if (ctype == CPL_TYPE_DOUBLE) {
3106 double *cdata = cpl_table_get_data_double(aPixtable->
table, cname);
3107 cpl_table_wrap_double(slice_pixtable->
table, cdata + i_row, cname);
3108 }
else if (ctype == CPL_TYPE_STRING) {
3109 char **cdata = cpl_table_get_data_string(aPixtable->
table, cname);
3110 cpl_table_wrap_string(slice_pixtable->
table, cdata + i_row, cname);
3112 const char *unit = cpl_table_get_column_unit(aPixtable->
table, cname);
3113 cpl_table_set_column_unit(slice_pixtable->
table, cname, unit);
3116 slice_pixtable->
header = cpl_propertylist_duplicate(aPixtable->
header);
3118 slice_tables = cpl_realloc(slice_tables,
3120 slice_tables[n_slices] = slice_pixtable;
3122 slice_tables[n_slices] = NULL;
3125 cpl_array_delete(colnames);
3126 cpl_table_erase_column(aPixtable->
table,
"ifuslice");
3128 return slice_tables;
3146 cpl_ensure(aPixtables, CPL_ERROR_NULL_INPUT, -1);
3148 while (aPixtables[n] != NULL) {
3172 for (t = aPixtables; *t != NULL; t++) {
3173 cpl_array *colnames = cpl_table_get_column_names((*t)->table);
3174 cpl_size n_col = cpl_table_get_ncol((*t)->table);
3176 for (i_col = 0; i_col < n_col; i_col++) {
3177 const char *cname = cpl_array_get_string(colnames, i_col);
3178 cpl_table_unwrap((*t)->table, cname);
3180 cpl_array_delete(colnames);
3181 cpl_table_delete((*t)->table);
3182 cpl_propertylist_delete((*t)->header);
3185 cpl_free(aPixtables);
#define MUSE_PIXTABLE_XPOS
cpl_polynomial ** muse_trace_table_get_polys_for_slice(const cpl_table *aTable, const unsigned short aSlice)
construct polynomial from the trace table entry for the given slice
#define MUSE_PIXTABLE_FFDATA
muse_pixtable_wcs
State of the astrometric calibration of a MUSE pixel table.
unsigned int muse_pixtable_get_expnum(muse_pixtable *aPixtable, cpl_size aRow)
Get the exposure number of a given row in a pixel table.
cpl_array * muse_cplarray_interpolate_table_linear(const cpl_array *aTargetAbscissa, const cpl_table *aSrcTable, const char *aSrcAbscissa, const char *aSrcOrdinate)
Linear interpolation of a 1d column.
cpl_error_code muse_wave_table_get_orders(const cpl_table *aWave, unsigned short *aXOrder, unsigned short *aYOrder)
Determine the x- and y-order of the polynomial stored in a wavelength calibration table...
Structure definition for a collection of muse_images.
int muse_trace_table_get_order(const cpl_table *aTable)
determine order of tracing polynomial from table
#define MUSE_HDR_PT_EXP_FST
FITS header keyword defining the first row index for a given exposure.
void muse_pixtable_extracted_delete(muse_pixtable **aPixtables)
Delete a pixel table array.
cpl_polynomial * muse_wave_table_get_poly_for_slice(const cpl_table *aTable, const unsigned short aSlice)
Construct polynomial from the wavelength calibration table entry for the given slice.
const char * muse_pfits_get_extname(const cpl_propertylist *aHeaders)
find out the extension name
const char * muse_pfits_get_insmode(const cpl_propertylist *aHeaders)
find out the observation mode
muse_pixtable * muse_pixtable_load(const char *aFilename)
Load the table itself and the FITS headers of a MUSE pixel table from a file.
unsigned short muse_pixtable_origin_get_slice(uint32_t aOrigin)
Get the slice number from the encoded 32bit origin number.
muse_pixtable * muse_pixtable_duplicate(muse_pixtable *aPixtable)
Make a copy of the pixtanle.
#define MUSE_HDR_PT_XLO
FITS header keyword contains the lower limit of the data in x-direction.
cpl_size muse_pixtable_extracted_get_size(muse_pixtable **aPixtables)
Get the size of an array of extracted pixel tables.
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.
unsigned int muse_pixtable_origin_set_offset(muse_pixtable *aPixtable, cpl_polynomial *aLTrace, unsigned short aIFU, unsigned short aSlice)
Set the slice offset from the pixel table header.
unsigned char muse_utils_get_ifu(const cpl_propertylist *aHeaders)
Find out the IFU/channel from which this header originated.
double muse_pfits_get_ra(const cpl_propertylist *aHeaders)
find out the right ascension
cpl_size muse_pfits_get_naxis(const cpl_propertylist *aHeaders, unsigned int aAxis)
find out the size of a given axis
#define MUSE_HDR_PT_FLUXCAL
muse_pixtable ** muse_pixtable_extracted_get_slices(muse_pixtable *aPixtable)
Extract one pixel table per IFU and slice.
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_size muse_pixtable_get_nrow(const muse_pixtable *aPixtable)
get the number of rows within the pixel table
#define MUSE_HDR_PT_LHI
FITS header keyword contains the upper limit of the data in spectral direction.
#define MUSE_HDR_PT_ILO
FITS header keyword contains the lowest IFU number in the data.
int muse_pixtable_get_type(muse_pixtable *aPixtable)
Determine the type of pixel table.
#define MUSE_HDR_PT_EXP_LST
FITS header keyword defining the last row index for a given exposure.
cpl_error_code muse_pixtable_erase_ifu_slice(muse_pixtable *aPixtable, unsigned char aIFU, unsigned short aSlice)
Erase pixel table rows related to one slice of one IFU.
static void muse_wcs_pixel_from_projplane_fast(muse_wcs *aWCS, double aX, double aY, double *aXOut, double *aYOut)
Convert from projection plane coordinates to pixel coordinates.
cpl_error_code muse_pixtable_dump(muse_pixtable *aPixtable, cpl_size aStart, cpl_size aCount, unsigned char aDisplayHeader)
Dump a MUSE pixel table to the screen, resolving the origin column.
cpl_image * stat
the statistics extension
#define MUSE_HDR_PT_FFCORR
#define MUSE_HDR_PT_TYPE
Pixel table "type" stored in the FITS header.
const char * muse_pfits_get_bunit(const cpl_propertylist *aHeaders)
find out the unit string
#define MUSE_HDR_PT_MERGED
Structure definition of MUSE three extension FITS file.
cpl_table * table
The pixel table.
const char * muse_pfits_get_cunit(const cpl_propertylist *aHeaders, unsigned int aAxis)
find out the WCS axis unit string
cpl_propertylist * header
the FITS header
cpl_error_code muse_pixtable_origin_copy_offsets(muse_pixtable *aOut, muse_pixtable *aFrom, unsigned int aNum)
Copy MUSE_HDR_PT_IFU_SLICE_OFFSET keywords between pixel tables.
cpl_error_code muse_pixtable_origin_decode_all(muse_pixtable *aPixtable, unsigned short **aX, unsigned short **aY, unsigned char **aIFU, unsigned char **aSlice)
Fill arrays with decoded entries from the origin column.
cpl_error_code muse_pixtable_reset_dq(muse_pixtable *aPixtable, unsigned int aDQ)
Reset a given bad pixel status (DQ flag) for all pixels in the table.
cpl_error_code muse_cpltable_check(const cpl_table *aTable, const muse_cpltable_def *aDef)
Check whether the table contains the fields of the definition.
#define MUSE_PIXTABLE_DATA
unsigned int muse_imagelist_get_size(muse_imagelist *aList)
Return the number of stored images.
muse_imagelist * muse_pixtable_to_imagelist(muse_pixtable *aPixtable)
Project a pixel table with data from one IFU back onto its image.
void muse_trace_polys_delete(cpl_polynomial *aPolys[])
Delete the multi-polynomial array created in relation to tracing.
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.
#define MUSE_HDR_PT_SHI
FITS header keyword contains the highest slice number in the data.
cpl_image * dq
the data quality extension
cpl_error_code muse_pixtable_append_ff(muse_pixtable *aPixtable, muse_image *aFF, cpl_table *aTrace, cpl_table *aWave, float aSampling)
Create flat-field spectrum and append to pixel table.
cpl_error_code muse_pixtable_restrict_wavelength(muse_pixtable *aPixtable, double aLow, double aHigh)
Restrict a pixel table to a certain wavelength range.
cpl_table * muse_cpltable_new(const muse_cpltable_def *aDef, cpl_size aLength)
Create an empty table according to the specified definition.
cpl_boolean muse_pixtable_is_skysub(muse_pixtable *aPixtable)
Determine whether the pixel table is sky subtracted.
unsigned int muse_pixtable_origin_get_x(uint32_t aOrigin, muse_pixtable *aPixtable, cpl_size aRow)
Get the horizontal coordinate from the encoded 32bit origin number.
muse_wcs * muse_wcs_new(cpl_propertylist *aHeader)
Create a new WCS structure from a given FITS header.
#define MUSE_PIXTABLE_WEIGHT
Structure definition of MUSE pixel table.
#define MUSE_HDR_PT_IFU_SLICE_OFFSET
FITS header keyword for the horizontal slice offset on the CCD.
#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.
#define MUSE_PIXTABLE_FF_EXT
muse_pixtable_wcs muse_pixtable_wcs_check(muse_pixtable *aPixtable)
Check the state of the world coordinate system of a pixel table.
#define MUSE_HDR_PT_YLO
FITS header keyword contains the lower limit of the data in y-direction.
static void muse_wcs_pixel_from_celestial_fast(muse_wcs *aWCS, double aRA, double aDEC, double *aX, double *aY)
Convert from celestial spherical coordinates to pixel coordinates.
cpl_propertylist * muse_wcs_create_default(const cpl_propertylist *aHeader)
Create FITS headers containing a default (relative) WCS.
#define MUSE_HDR_PT_SKYSUB
cpl_boolean muse_pixtable_is_fluxcal(muse_pixtable *aPixtable)
Determine whether the pixel table is flux calibrated.
#define MUSE_HDR_PT_ILLUM_REGEXP
cpl_table * ffspec
A flat-field spectrum.
cpl_array * muse_cplarray_interpolate_linear(const cpl_array *aTargetAbscissa, const cpl_array *aSourceAbscissa, const cpl_array *aSourceOrdinate)
Linear interpolation of a 1d array.
#define MUSE_HDR_PT_IHI
FITS header keyword contains the highest IFU number in the data.
unsigned int muse_pixtable_origin_get_offset(muse_pixtable *aPixtable, unsigned int aExpNum, unsigned short aIFU, unsigned short aSlice)
Get the slice offset from the pixel table header.
uint32_t muse_pixtable_origin_encode(unsigned int aX, unsigned int aY, unsigned short aIFU, unsigned short aSlice, unsigned int aOffset)
Encode the three CCD coordinates defining the origin of one MUSE pixel into a 32bit integer...
double muse_pfits_get_dec(const cpl_propertylist *aHeaders)
find out the declination
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.
muse_pixtable * muse_pixtable_load_window(const char *aFilename, cpl_size aStart, cpl_size aNRows)
Load a range of rows from the table and all the FITS headers of a MUSE pixel table from a file...
muse_pixtable_operation
Type of operation to apply to a MUSE pixel table.
muse_pixtable * muse_pixtable_extract_wavelength(muse_pixtable *aPixtable, double aLow, double aHigh)
Create a new pixtable with values within the selected wavelengths.
muse_pixtable * muse_pixtable_create(muse_image *aImage, cpl_table *aTrace, cpl_table *aWave, cpl_table *aGeoTable)
Create the pixel table for one CCD.
muse_pixtable * muse_pixtable_load_restricted_wavelength(const char *aFilename, double aLambdaMin, double aLambdaMax)
Load a pixel table from file and cut down the wavelength range.
#define MUSE_PIXTABLE_ORIGIN
cpl_error_code muse_cplpropertylist_update_long_long(cpl_propertylist *aHeader, const char *aKeyword, cpl_size aValue)
Update an integer-like property irrespective of the real type.
#define MUSE_HDR_PT_LLO
FITS header keyword contains the lower limit of the data in spectral direction.
const char * muse_pfits_get_ctype(const cpl_propertylist *aHeaders, unsigned int aAxis)
find out the WCS axis type string
cpl_error_code muse_pixtable_save(muse_pixtable *aPixtable, const char *aFilename)
Save a MUSE pixel table to a file on disk.
cpl_error_code muse_cpltable_copy_array(cpl_table *aTable, const char *aColumn, const cpl_array *aArray)
Copy an array into a table.
unsigned short muse_pixtable_origin_get_ifu(uint32_t aOrigin)
Get the IFU number from the encoded 32bit origin number.
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_pixtable_restrict_xpos(muse_pixtable *aPixtable, double aLo, double aHi)
Restrict a pixel table to a certain x coordinate range.
#define MUSE_PIXTABLE_STAT
cpl_error_code muse_pixtable_from_imagelist(muse_pixtable *aPixtable, muse_imagelist *aList)
Get pixel table values back from a per-IFU imagelist.
Handling of "mask" files.
muse_imagelist * muse_imagelist_new(void)
Create a new (empty) MUSE image list.
const muse_cpltable_def muse_pixtable_def[]
MUSE pixel table definition.
#define MUSE_PIXTABLE_LAMBDA
cpl_table * muse_geo_table_extract_ifu(const cpl_table *aTable, const unsigned char aIFU)
Extract the part of a geometry table dealing with a given IFU.
cpl_error_code muse_quadrants_coords_to_raw(cpl_propertylist *aHeader, int *aX, int *aY)
Convert coordinates of a trimmed image to raw-image coordinates.
#define MUSE_HDR_PT_SLO
FITS header keyword contains the lowest slice number in the data.
cpl_propertylist * header
the FITS header
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.
#define MUSE_HDR_PT_RVCORR
Definition of a cpl table structure.
muse_image * muse_image_new(void)
Allocate memory for a new muse_image object.
cpl_error_code muse_wcs_position_celestial(muse_pixtable *aPixtable, double aRA, double aDEC)
Convert native to celestial spherical coordinates in a pixel table.
cpl_table * muse_resampling_spectrum(muse_pixtable *aPixtable, double aBinwidth)
Resample the selected pixels of a pixel table into a spectrum.
unsigned int muse_pixtable_origin_get_y(uint32_t aOrigin)
Get the vertical coordinate from the encoded 32bit origin number.
cpl_mask * mask
The mask data.
#define MUSE_PIXTABLE_YPOS
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
cpl_error_code muse_pixtable_restrict_ypos(muse_pixtable *aPixtable, double aLo, double aHi)
Restrict a pixel table to a certain y coordinate range.
#define MUSE_HDR_PT_YHI
FITS header keyword contains the upper limit of the data in y-direction.
cpl_error_code muse_imagelist_set(muse_imagelist *aList, muse_image *aImage, unsigned int aIdx)
Set the muse_image of given list index.
cpl_error_code muse_pixtable_compute_limits(muse_pixtable *aPixtable)
(Re-)Compute the limits of the coordinate columns of a pixel table.
static cpl_error_code muse_pixtable_fix_exp_headers(muse_pixtable *aPixtable)
Fix the exposure ranges in the header of a pixel table.
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.
#define MUSE_HDR_PT_XHI
FITS header keyword contains the upper limit of the data in x-ion.
cpl_boolean muse_pixtable_is_rvcorr(muse_pixtable *aPixtable)
Determine whether the pixel table is radial-velocity corrected.