33 #include "muse_datacube.h" 35 #include "muse_flux.h" 36 #include "muse_pfits.h" 37 #include "muse_quality.h" 38 #include "muse_utils.h" 72 muse_datacube_collapse_filter_buffer(
const muse_table *aFilter,
73 double aCRVAL,
double aCRPIX,
double aCDELT,
74 cpl_boolean aIsLog,
int *aL1,
int *aL2,
77 if (!aFilter || !aL1 || !aL2) {
80 if (!aFilter->
table) {
83 double *fdata = (
double *)cpl_calloc(*aL2,
sizeof(
double));
86 cpl_msg_debug(__func__,
" lambda throughput");
89 for (l = 0; l < *aL2; l++) {
90 double lambda = (l + 1. - aCRPIX) * aCDELT + aCRVAL;
92 lambda = aCRVAL * exp((l + 1. - aCRPIX) * aCDELT / aCRVAL);
97 cpl_msg_debug(__func__,
" %8.3f %8.5f", lambda, fdata[l]);
103 while (l < *aL2 && fabs(fdata[l]) < DBL_EPSILON) {
107 while (l > *aL1 && fabs(fdata[l]) < DBL_EPSILON) {
110 double lbda1 = (*aL1 + 1. - aCRPIX) * aCDELT + aCRVAL,
111 lbda2 = (*aL2 + 1. - aCRPIX) * aCDELT + aCRVAL;
113 lbda1 = aCRVAL * exp((*aL1 + 1. - aCRPIX) * aCDELT / aCRVAL);
114 lbda2 = aCRVAL * exp((*aL2 + 1. - aCRPIX) * aCDELT / aCRVAL);
117 cpl_msg_debug(__func__,
"Filter wavelength range %.1f..%.1fA (cube planes " 118 "%d..%d), %.2f%% of filter area covered by data.", lbda1, lbda2,
119 *aL1, *aL2, fraction * 100.);
121 *aFraction = fraction;
153 cpl_ensure(aEuro3D && aEuro3D->
dtable && aEuro3D->
hdata, CPL_ERROR_NULL_INPUT,
160 const char *unitx = cpl_table_get_column_unit(aEuro3D->
dtable,
"XPOS"),
161 *unity = cpl_table_get_column_unit(aEuro3D->
dtable,
"YPOS");
162 cpl_ensure(unitx && unity, CPL_ERROR_DATA_NOT_FOUND, NULL);
164 if (!strncmp(unitx, unity, 4) && !strncmp(unitx,
"deg", 4)) {
168 double xmin = cpl_table_get_column_min(aEuro3D->
dtable,
"XPOS"),
169 xmax = cpl_table_get_column_max(aEuro3D->
dtable,
"XPOS"),
170 ymin = cpl_table_get_column_min(aEuro3D->
dtable,
"YPOS"),
171 ymax = cpl_table_get_column_max(aEuro3D->
dtable,
"YPOS");
172 double x1, x2, y1, y2;
174 wcs->crval1 /= CPL_MATH_DEG_RAD;
175 wcs->
crval2 /= CPL_MATH_DEG_RAD;
177 ymin / CPL_MATH_DEG_RAD, &x1, &y1);
179 ymax / CPL_MATH_DEG_RAD, &x2, &y2);
186 int zmin = cpl_table_get_column_min(aEuro3D->
dtable,
"SPEC_STA"),
187 zmax = cpl_table_get_column_max(aEuro3D->
dtable,
"SPEC_STA"),
188 nx = lround(fabs(x2 - x1)) + 1,
189 ny = lround(fabs(y2 - y1)) + 1,
190 nz = zmax - zmin + 1;
193 cpl_size zmaxpos = -1;
194 cpl_table_get_column_maxpos(aEuro3D->
dtable,
"SPEC_STA", &zmaxpos);
195 const cpl_array *amax = cpl_table_get_array(aEuro3D->
dtable,
"DATA_SPE",
197 int l, nsize = cpl_array_get_size(amax);
198 for (l = nsize - 1; l > 0; l--) {
200 if (cpl_array_is_valid(amax, l) == 1) {
205 int nspec = cpl_table_get_nrow(aEuro3D->
dtable);
206 cpl_msg_debug(__func__,
"Euro3D dimensions: %dx%dx%d (z = %d - %d, valid %d)," 207 " %d spectra", nx, ny, nz, zmax, zmin, l + 1, nspec);
210 double crvals = cpl_propertylist_get_double(aEuro3D->
hdata,
"CRVALS"),
211 cdelts = cpl_propertylist_get_double(aEuro3D->
hdata,
"CDELTS");
212 const char *ctypes = cpl_propertylist_get_string(aEuro3D->
hdata,
"CTYPES");
213 cpl_boolean loglambda = ctypes && (!strncmp(ctypes,
"AWAV-LOG", 9) ||
214 !strncmp(ctypes,
"WAVE-LOG", 9));
215 cpl_msg_debug(__func__,
"spectral WCS: %f / %f %s", crvals, cdelts,
216 loglambda ?
"log" :
"linear");
218 double *fdata = NULL;
219 double ffraction = 1.;
221 fdata = muse_datacube_collapse_filter_buffer(aFilter, crvals, zmin,
222 cdelts, loglambda, &l1, &l2,
228 image->
header = cpl_propertylist_duplicate(aEuro3D->
header);
233 image->
data = cpl_image_new(nx, ny, CPL_TYPE_FLOAT);
234 float *outdata = cpl_image_get_data_float(image->
data);
235 image->
dq = cpl_image_new(nx, ny, CPL_TYPE_INT);
237 cpl_image_add_scalar(image->
dq, EURO3D_MISSDATA);
238 int *outdq = cpl_image_get_data_int(image->
dq);
242 cpl_boolean usevariance = CPL_FALSE;
243 if (getenv(
"MUSE_COLLAPSE_USE_VARIANCE") &&
244 atoi(getenv(
"MUSE_COLLAPSE_USE_VARIANCE")) > 0) {
245 usevariance = CPL_TRUE;
250 #pragma omp parallel for default(none) private(l) \ 251 shared(aEuro3D, fdata, l1, l2, noutside, nspec, nx, ny, outdata, \ 252 outdq, usevariance, wcs) 253 for (k = 0; k < nspec; k++) {
255 double xpos = cpl_table_get(aEuro3D->
dtable,
"XPOS", k, &err),
256 ypos = cpl_table_get(aEuro3D->
dtable,
"YPOS", k, &err);
258 cpl_msg_warning(__func__,
"spectrum %d in Euro3D table does not have " 259 "position information!", k + 1);
266 ypos * CPL_MATH_RAD_DEG, &xpx, &ypx);
270 int i = lround(xpx) - 1,
272 if (i >= nx || j >= ny) {
278 int nstart = cpl_table_get_int(aEuro3D->
dtable,
"SPEC_STA", k, &err);
279 const cpl_array *adata = cpl_table_get_array(aEuro3D->
dtable,
"DATA_SPE", k),
280 *adq = cpl_table_get_array(aEuro3D->
dtable,
"QUAL_SPE", k),
283 astat = cpl_table_get_array(aEuro3D->
dtable,
"STAT_SPE", k);
286 double sumdata = 0., sumweight = 0.;
287 for (l = l1; l < l2; l++) {
289 int idx = l - nstart + 1;
292 double fweight = fdata ? fdata[l] : 1.;
293 cpl_errorstate prestate = cpl_errorstate_get();
294 int dq = cpl_array_get_int(adq, idx, &err);
296 cpl_errorstate_set(prestate);
300 double variance = 1.;
302 variance = astat ? cpl_array_get(astat, idx, &err) : 1.;
304 variance *= variance;
308 if (err || !isnormal(variance)) {
312 double data = cpl_array_get(adata, idx, &err);
314 sumdata += data * fweight / variance;
315 sumweight += fweight / variance;
317 if (isnormal(sumweight)) {
318 outdata[i + j*nx] = sumdata / sumweight;
319 outdq[i + j*nx] = EURO3D_GOODPIXEL;
321 outdq[i + j*nx] = EURO3D_MISSDATA;
327 cpl_msg_warning(__func__,
"Skipped %d spaxels, due to their location " 328 "outside the recostructed image!", noutside);
359 cpl_ensure(aCube && aCube->
data && aCube->
header,
360 CPL_ERROR_NULL_INPUT, NULL);
361 cpl_ensure(cpl_image_get_type(cpl_imagelist_get(aCube->
data, 0)) == CPL_TYPE_FLOAT,
362 CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
364 cpl_ensure(cpl_image_get_type(cpl_imagelist_get(aCube->
dq, 0)) == CPL_TYPE_INT,
365 CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
368 cpl_ensure(cpl_image_get_type(cpl_imagelist_get(aCube->
stat, 0)) == CPL_TYPE_FLOAT,
369 CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
373 int nx = cpl_image_get_size_x(cpl_imagelist_get(aCube->
data, 0)),
374 ny = cpl_image_get_size_y(cpl_imagelist_get(aCube->
data, 0)),
375 nz = cpl_imagelist_get_size(aCube->
data);
381 cpl_boolean loglambda = ctype3 && (!strncmp(ctype3,
"AWAV-LOG", 9) ||
382 !strncmp(ctype3,
"WAVE-LOG", 9));
384 double *fdata = NULL;
385 double ffraction = 1.;
387 fdata = muse_datacube_collapse_filter_buffer(aFilter, crval3, crpix3,
388 cd33, loglambda, &l1, &l2,
394 image->
header = cpl_propertylist_duplicate(aCube->
header);
395 cpl_propertylist_erase_regexp(image->
header,
"^C...*3$|^CD3_.$", 0);
399 image->
data = cpl_image_new(nx, ny, CPL_TYPE_FLOAT);
400 float *outdata = cpl_image_get_data_float(image->
data);
401 image->
dq = cpl_image_new(nx, ny, CPL_TYPE_INT);
402 int *outdq = cpl_image_get_data_int(image->
dq);
406 cpl_boolean usevariance = CPL_FALSE;
407 if (getenv(
"MUSE_COLLAPSE_USE_VARIANCE") &&
408 atoi(getenv(
"MUSE_COLLAPSE_USE_VARIANCE")) > 0) {
409 usevariance = CPL_TRUE;
414 #pragma omp parallel for default(none) \ 415 shared(aCube, nx, ny, l1, l2, fdata, outdata, outdq, usevariance) 416 for (i = 0; i < nx; i++) {
418 for (j = 0; j < ny; j++) {
419 double sumdata = 0., sumweight = 0.;
421 for (l = l1; l < l2; l++) {
423 double fweight = fdata ? fdata[l] : 1.;
424 float *pdata = cpl_image_get_data_float(cpl_imagelist_get(aCube->
data, l)),
426 if (!isfinite(pdata[i + j*nx])) {
430 int *pdq = cpl_image_get_data_int(cpl_imagelist_get(aCube->
dq, l));
431 if (pdq && pdq[i + j*nx]) {
436 double variance = 1.;
438 pstat = cpl_image_get_data_float(cpl_imagelist_get(aCube->
stat, l));
439 variance = pstat ? pstat[i + j*nx] : 1.;
440 if (!isnormal(variance)) {
445 sumdata += pdata[i + j*nx] * fweight / variance;
446 sumweight += fweight / variance;
448 if (isnormal(sumweight)) {
449 outdata[i + j*nx] = sumdata / sumweight;
450 outdq[i + j*nx] = EURO3D_GOODPIXEL;
452 outdq[i + j*nx] = EURO3D_MISSDATA;
482 cpl_ensure_code(aFilename, CPL_ERROR_NULL_INPUT);
483 cpl_error_code rc = CPL_ERROR_NONE;
484 if (!aImages || !aNames) {
488 for (i = 0; i < nimages; i++) {
495 cpl_propertylist *header = cpl_propertylist_new();
496 cpl_errorstate es = cpl_errorstate_get();
498 *ucomment = cpl_propertylist_get_comment(image->
header,
"BUNIT");
499 if (!cpl_errorstate_is_equal(es) && !unit) {
500 cpl_errorstate_set(es);
502 char dataext[KEYWORD_LENGTH], obj[KEYWORD_LENGTH],
503 *dqext = NULL, *statext = NULL;
504 snprintf(dataext, KEYWORD_LENGTH,
"%s", cpl_array_get_string(aNames, i));
506 dqext = cpl_sprintf(
"%s_%s", cpl_array_get_string(aNames, i), EXTNAME_DQ);
509 statext = cpl_sprintf(
"%s_%s", cpl_array_get_string(aNames, i), EXTNAME_STAT);
511 snprintf(obj, KEYWORD_LENGTH,
"%s", cpl_array_get_string(aNames, i));
512 cpl_propertylist_append_string(header,
"EXTNAME", dataext);
513 cpl_propertylist_set_comment(header,
"EXTNAME",
"reconstructed image (data values)");
516 cpl_propertylist_append_string(header,
"BUNIT", unit);
517 cpl_propertylist_set_comment(header,
"BUNIT", ucomment);
521 cpl_propertylist_copy_property_regexp(header, image->
header,
525 rc = cpl_image_save(image->
data, aFilename, CPL_TYPE_UNSPECIFIED, header,
529 cpl_propertylist_update_string(header,
"EXTNAME", dqext);
530 cpl_propertylist_set_comment(header,
"EXTNAME",
"reconstructed image (bad pixel status values)");
531 cpl_propertylist_erase(header,
"BUNIT");
532 snprintf(obj, KEYWORD_LENGTH,
"%s, %s", cpl_array_get_string(aNames, i),
536 rc = cpl_image_save(image->
dq, aFilename, CPL_TYPE_INT, header,
540 cpl_propertylist_update_string(header,
"EXTNAME", statext);
541 cpl_propertylist_set_comment(header,
"EXTNAME",
"reconstructed image (variance)");
543 char *ustat = cpl_sprintf(
"(%s)**2", unit);
544 cpl_propertylist_append_string(header,
"BUNIT", ustat);
547 snprintf(obj, KEYWORD_LENGTH,
"%s, %s", cpl_array_get_string(aNames, i),
551 rc = cpl_image_save(image->
stat, aFilename, CPL_TYPE_UNSPECIFIED, header,
555 cpl_propertylist_delete(header);
582 cpl_ensure_code(aEuro3D && aFilename, CPL_ERROR_NULL_INPUT);
585 cpl_error_code rc = cpl_table_save(aEuro3D->
dtable, aEuro3D->
header,
586 aEuro3D->
hdata, aFilename, CPL_IO_CREATE);
587 if (rc != CPL_ERROR_NONE) {
588 cpl_msg_warning(__func__,
"failed to save data part of the Euro3D table: " 589 "%s", cpl_error_get_message());
592 rc = cpl_table_save(aEuro3D->
gtable, NULL, aEuro3D->
hgroup, aFilename,
594 if (rc != CPL_ERROR_NONE) {
595 cpl_msg_warning(__func__,
"failed to save group part of the Euro3D table: " 596 "%s", cpl_error_get_message());
625 cpl_table_delete(aEuro3D->
dtable);
626 cpl_table_delete(aEuro3D->
gtable);
627 cpl_propertylist_delete(aEuro3D->
header);
628 cpl_propertylist_delete(aEuro3D->
hdata);
629 cpl_propertylist_delete(aEuro3D->
hgroup);
631 cpl_array_delete(aEuro3D->
recnames);
646 static cpl_error_code
649 cpl_ensure_code(aCube, CPL_ERROR_NULL_INPUT);
651 return CPL_ERROR_NONE;
654 for (k = 0; k < nimages; k++) {
662 return CPL_ERROR_NONE;
682 cpl_ensure_code(aCube && aCube->
data && aCube->
stat && aCube->
dq,
683 CPL_ERROR_NULL_INPUT);
686 int l, nx = cpl_image_get_size_x(cpl_imagelist_get(aCube->
data, 0)),
687 ny = cpl_image_get_size_y(cpl_imagelist_get(aCube->
data, 0)),
688 nz = cpl_imagelist_get_size(aCube->
data);
689 #pragma omp parallel for default(none) \ 690 shared(aCube, nx, ny, nz) 691 for (l = 0; l < nz; l++) {
693 for (i = 0; i < nx; i++) {
695 for (j = 0; j < ny; j++) {
696 float *pdata = cpl_image_get_data_float(cpl_imagelist_get(aCube->
data, l)),
697 *pstat = cpl_image_get_data_float(cpl_imagelist_get(aCube->
stat, l));
698 int *pdq = cpl_image_get_data_int(cpl_imagelist_get(aCube->
dq, l));
699 if (pdq[i + j*nx] == EURO3D_GOODPIXEL) {
703 pdata[i + j*nx] = NAN;
704 pstat[i + j*nx] = NAN;
710 cpl_imagelist_delete(aCube->
dq);
714 muse_datacube_convert_dq_recimages(aCube);
716 return CPL_ERROR_NONE;
752 cpl_ensure_code(aCube && aCube->
header && aFilename, CPL_ERROR_NULL_INPUT);
755 cpl_propertylist *header = cpl_propertylist_new();
757 cpl_propertylist_copy_property_regexp(header, aCube->
header,
759 cpl_error_code rc = cpl_propertylist_save(header, aFilename, CPL_IO_CREATE);
760 cpl_propertylist_delete(header);
763 header = cpl_propertylist_new();
764 cpl_propertylist_append_string(header,
"EXTNAME", EXTNAME_DATA);
765 cpl_propertylist_set_comment(header,
"EXTNAME", EXTNAME_DATA_COMMENT);
768 cpl_propertylist_copy_property_regexp(header, aCube->
header,
771 aCube->
dq ?
"DQ" : NULL, aCube->
stat ?
"STAT" : NULL);
772 rc = cpl_imagelist_save(aCube->
data, aFilename, CPL_TYPE_FLOAT, header,
774 cpl_propertylist_delete(header);
776 if (rc == CPL_ERROR_NONE && aCube->
dq) {
777 header = cpl_propertylist_new();
778 cpl_propertylist_append_string(header,
"EXTNAME", EXTNAME_DQ);
779 cpl_propertylist_set_comment(header,
"EXTNAME", EXTNAME_DQ_COMMENT);
782 cpl_propertylist_copy_property_regexp(header, aCube->
header,
785 aCube->
stat ?
"STAT" : NULL);
786 rc = cpl_imagelist_save(aCube->
dq, aFilename, CPL_TYPE_INT, header,
788 cpl_propertylist_delete(header);
791 if (rc == CPL_ERROR_NONE && aCube->
stat) {
792 header = cpl_propertylist_new();
793 cpl_propertylist_append_string(header,
"EXTNAME", EXTNAME_STAT);
794 cpl_propertylist_set_comment(header,
"EXTNAME", EXTNAME_STAT_COMMENT);
797 kMuseFluxUnitString, strlen(kMuseFluxUnitString) + 1)) {
799 cpl_propertylist_append_string(header,
"BUNIT", kMuseFluxStatString);
803 cpl_propertylist_copy_property_regexp(header, aCube->
header,
807 rc = cpl_imagelist_save(aCube->
stat, aFilename, CPL_TYPE_FLOAT, header,
809 cpl_propertylist_delete(header);
825 static cpl_propertylist *
826 muse_datacube_load_header(
const char *aFilename)
828 cpl_ensure(aFilename, CPL_ERROR_NULL_INPUT, NULL);
829 int extdata = cpl_fits_find_extension(aFilename,
"DATA");
830 cpl_ensure(extdata >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
831 cpl_ensure(extdata > 0, CPL_ERROR_DATA_NOT_FOUND, NULL);
833 cpl_propertylist *header = cpl_propertylist_load(aFilename, 0);
834 cpl_propertylist *hdata = cpl_propertylist_load(aFilename, extdata);
835 cpl_propertylist_copy_property_regexp(header, hdata,
837 cpl_propertylist_delete(hdata);
875 cpl_ensure(aFilename, CPL_ERROR_NULL_INPUT, NULL);
878 cpl_errorstate state = cpl_errorstate_get();
879 cube->
header = muse_datacube_load_header(aFilename);
880 if (!cpl_errorstate_is_equal(state) || !cube->
header) {
881 cpl_msg_error(__func__,
"Loading cube-like headers from \"%s\" failed!",
886 int ext = cpl_fits_find_extension(aFilename,
"DATA");
887 cube->
data = cpl_imagelist_load(aFilename, CPL_TYPE_FLOAT, ext);
889 ext = cpl_fits_find_extension(aFilename,
"DQ");
891 cube->
stat = cpl_imagelist_load(aFilename, CPL_TYPE_INT, ext);
893 ext = cpl_fits_find_extension(aFilename,
"STAT");
895 cube->
stat = cpl_imagelist_load(aFilename, CPL_TYPE_FLOAT, ext);
897 int next = cpl_fits_count_extensions(aFilename);
898 while (++ext <= next) {
901 image->
header = cpl_propertylist_load(aFilename, ext);
902 image->
data = cpl_image_load(aFilename, CPL_TYPE_UNSPECIFIED, 0, ext);
905 char *extname2 = cpl_sprintf(
"%s_DQ", extname);
906 int ext2 = cpl_fits_find_extension(aFilename, extname2);
909 image->
dq = cpl_image_load(aFilename, CPL_TYPE_INT, 0, ext2);
912 extname2 = cpl_sprintf(
"%s_STAT", extname);
913 ext2 = cpl_fits_find_extension(aFilename, extname2);
916 image->
stat = cpl_image_load(aFilename, CPL_TYPE_UNSPECIFIED, 0, ext2);
921 cube->
recnames = cpl_array_new(1, CPL_TYPE_STRING);
926 cpl_array_set_string(cube->
recnames, cpl_array_get_size(cube->
recnames) - 1,
962 cpl_ensure_code(aCube && aAppend, CPL_ERROR_NULL_INPUT);
964 cpl_size ndata = cpl_imagelist_get_size(aCube->
data),
965 nstat = cpl_imagelist_get_size(aCube->
stat);
966 cpl_ensure_code(ndata == nstat, CPL_ERROR_ILLEGAL_INPUT);
967 cpl_size i, n = cpl_imagelist_get_size(aAppend->
data);
968 cpl_ensure_code(n == cpl_imagelist_get_size(aAppend->
stat),
969 CPL_ERROR_ILLEGAL_INPUT);
972 cpl_size nx1 = cpl_image_get_size_x(cpl_imagelist_get(aCube->
data, ndata - 1)),
973 ny1 = cpl_image_get_size_y(cpl_imagelist_get(aCube->
data, ndata - 1)),
974 nx2 = cpl_image_get_size_x(cpl_imagelist_get(aAppend->
data, 0)),
975 ny2 = cpl_image_get_size_y(cpl_imagelist_get(aAppend->
data, 0));
976 cpl_ensure_code(nx1 == nx2 && ny1 == ny2, CPL_ERROR_ILLEGAL_INPUT);
979 cpl_ensure_code(ctype1 && ctype2, CPL_ERROR_UNSUPPORTED_MODE);
980 cpl_ensure_code((!strncmp(ctype1,
"AWAV", 5) && !strncmp(ctype2,
"AWAV", 5)) ||
981 (!strncmp(ctype1,
"WAVE", 5) && !strncmp(ctype2,
"WAVE", 5)),
982 CPL_ERROR_UNSUPPORTED_MODE);
991 lbda1 = ((ndata - 1) + 1. - pix1) * cd1 + val1,
992 lbda2 = (0 + 1. - pix2) * cd2 + val2;
994 cpl_msg_debug(__func__,
"lambdas: %f %f (%f %f)", lbda1, lbda2, cd1, cd2);
995 cpl_ensure_code(fabs(cd1 - cd2) < DBL_EPSILON &&
996 fabs(lbda2 - cd2 - lbda1) < DBL_EPSILON,
997 CPL_ERROR_ILLEGAL_INPUT);
1008 cpl_boolean usedq = CPL_FALSE;
1009 if (aCube->
dq && cpl_imagelist_get_size(aCube->
dq) == ndata &&
1010 aAppend->
dq && cpl_imagelist_get_size(aAppend->
dq) == n) {
1013 cpl_imagelist_delete(aCube->
dq);
1018 for (i = 0; i < n; i++) {
1019 cpl_imagelist_set(aCube->
data,
1020 cpl_image_duplicate(cpl_imagelist_get(aAppend->
data, i)),
1021 cpl_imagelist_get_size(aCube->
data));
1023 cpl_imagelist_set(aCube->
dq,
1024 cpl_image_duplicate(cpl_imagelist_get(aAppend->
dq, i)),
1025 cpl_imagelist_get_size(aCube->
dq));
1027 cpl_imagelist_set(aCube->
stat,
1028 cpl_image_duplicate(cpl_imagelist_get(aAppend->
stat, i)),
1029 cpl_imagelist_get_size(aCube->
stat));
1031 return CPL_ERROR_NONE;
1055 cpl_imagelist_delete(aCube->
data);
1057 cpl_imagelist_delete(aCube->
dq);
1059 cpl_imagelist_delete(aCube->
stat);
1063 cpl_propertylist_delete(aCube->
header);
Structure definition of a MUSE datacube.
Structure definition for a collection of muse_images.
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_extname(const cpl_propertylist *aHeaders)
find out the extension name
cpl_error_code muse_datacube_concat(muse_datacube *aCube, const muse_datacube *aAppend)
Concatenate one datacube at the end of another one.
double muse_pfits_get_crval(const cpl_propertylist *aHeaders, unsigned int aAxis)
find out the WCS coordinate at the reference point
A structure containing a spatial two-axis WCS.
cpl_error_code muse_euro3dcube_save(muse_euro3dcube *aEuro3D, const char *aFilename)
Save a Euro3D cube object to a file.
cpl_image * data
the data extension
muse_datacube * muse_datacube_load(const char *aFilename)
Load header, DATA and optionally STAT and DQ extensions as well as the reconstructed images of a MUSE...
cpl_error_code muse_utils_filter_copy_properties(cpl_propertylist *aHeader, const muse_table *aFilter, double aFraction)
Add/propagate filter properties to header of collapsed image.
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_image * stat
the statistics extension
void muse_datacube_delete(muse_datacube *aCube)
Deallocate memory associated to a muse_datacube object.
void muse_imagelist_delete(muse_imagelist *aList)
Free the memory of the MUSE image list.
cpl_propertylist * hgroup
the group FITS header
cpl_array * recnames
the reconstructed image filter names
const char * muse_pfits_get_bunit(const cpl_propertylist *aHeaders)
find out the unit string
muse_imagelist * recimages
the reconstructed image data
cpl_propertylist * header
the primary FITS header
Structure definition of MUSE three extension FITS file.
cpl_array * recnames
the reconstructed image filter names
cpl_propertylist * header
the FITS header
cpl_error_code muse_utils_set_hduclass(cpl_propertylist *aHeader, const char *aClass2, const char *aExtData, const char *aExtDQ, const char *aExtStat)
Set HDU headers for the ESO FITS data format.
cpl_error_code muse_datacube_save(muse_datacube *aCube, const char *aFilename)
Save the three cube extensions and the FITS headers of a MUSE datacube to a file. ...
unsigned int muse_imagelist_get_size(muse_imagelist *aList)
Return the number of stored images.
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
double muse_flux_response_interpolate(const cpl_table *aResponse, double aLambda, double *aError, muse_flux_interpolation_type aType)
Compute linearly interpolated response of some kind at given wavelength.
muse_wcs * muse_wcs_new(cpl_propertylist *aHeader)
Create a new WCS structure from a given FITS header.
cpl_error_code muse_datacube_convert_dq(muse_datacube *aCube)
Convert the DQ extension of a datacube to NANs in DATA and STAT.
#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.
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_table * table
The table.
cpl_error_code muse_datacube_save_recimages(const char *aFilename, muse_imagelist *aImages, cpl_array *aNames)
Save reconstructed images of a cube in extra extensions.
void muse_euro3dcube_delete(muse_euro3dcube *aEuro3D)
Deallocate memory associated to a muse_euro3dcube object.
cpl_imagelist * data
the cube containing the actual data values
Structure definition of a Euro3D datacube.
Structure to store a table together with a property list.
double muse_utils_filter_fraction(const muse_table *aFilter, double aLambda1, double aLambda2)
Compute fraction of filter area covered by the data range.
cpl_imagelist * dq
the optional cube containing the bad pixel status
cpl_table * dtable
the table containing the actual Euro3D data
const char * muse_pfits_get_ctype(const cpl_propertylist *aHeaders, unsigned int aAxis)
find out the WCS axis type string
cpl_propertylist * hdata
the data FITS header
cpl_table * gtable
the table containing the Euro3D groups
cpl_propertylist * header
the FITS header
muse_imagelist * muse_imagelist_new(void)
Create a new (empty) MUSE image list.
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_error_code muse_imagelist_set(muse_imagelist *aList, muse_image *aImage, unsigned int aIdx)
Set the muse_image of given list index.
muse_imagelist * recimages
the reconstructed image data
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.
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).
cpl_imagelist * stat
the cube containing the data variance