MUSE Pipeline Reference Manual  2.5.2
muse_datacube.c
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set sw=2 sts=2 et cin: */
3 /*
4  * This file is part of the MUSE Instrument Pipeline
5  * Copyright (C) 2005-2015 European Southern Observatory
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 
26 /*----------------------------------------------------------------------------*
27  * Includes *
28  *----------------------------------------------------------------------------*/
29 #include <cpl.h>
30 #include <math.h>
31 #include <string.h>
32 
33 #include "muse_datacube.h"
34 
35 #include "muse_flux.h"
36 #include "muse_pfits.h"
37 #include "muse_quality.h"
38 #include "muse_utils.h"
39 #include "muse_wcs.h"
40 
41 /*----------------------------------------------------------------------------*/
48 /*----------------------------------------------------------------------------*/
49 
52 /*---------------------------------------------------------------------------*/
70 /*---------------------------------------------------------------------------*/
71 static double *
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,
75  double *aFraction)
76 {
77  if (!aFilter || !aL1 || !aL2) {
78  return NULL;
79  }
80  if (!aFilter->table) {
81  return NULL;
82  }
83  double *fdata = (double *)cpl_calloc(*aL2, sizeof(double));
84 
85 #if 0
86  cpl_msg_debug(__func__, " lambda throughput");
87 #endif
88  int l;
89  for (l = 0; l < *aL2; l++) {
90  double lambda = (l + 1. - aCRPIX) * aCDELT + aCRVAL;
91  if (aIsLog) {
92  lambda = aCRVAL * exp((l + 1. - aCRPIX) * aCDELT / aCRVAL);
93  }
94  fdata[l] = muse_flux_response_interpolate(aFilter->table, lambda, NULL,
96 #if 0
97  cpl_msg_debug(__func__, " %8.3f %8.5f", lambda, fdata[l]);
98 #endif
99  } /* for l (z / wavelengths) */
100 
101  /* try to find filter edges */
102  l = 0;
103  while (l < *aL2 && fabs(fdata[l]) < DBL_EPSILON) {
104  *aL1 = l++;
105  }
106  l = *aL2 - 1;
107  while (l > *aL1 && fabs(fdata[l]) < DBL_EPSILON) {
108  *aL2 = l--;
109  }
110  double lbda1 = (*aL1 + 1. - aCRPIX) * aCDELT + aCRVAL,
111  lbda2 = (*aL2 + 1. - aCRPIX) * aCDELT + aCRVAL;
112  if (aIsLog) {
113  lbda1 = aCRVAL * exp((*aL1 + 1. - aCRPIX) * aCDELT / aCRVAL);
114  lbda2 = aCRVAL * exp((*aL2 + 1. - aCRPIX) * aCDELT / aCRVAL);
115  }
116  double fraction = muse_utils_filter_fraction(aFilter, lbda1, lbda2);
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.);
120  if (aFraction) {
121  *aFraction = fraction;
122  }
123 
124  return fdata;
125 } /* muse_datacube_collapse_filter_buffer() */
126 
127 /*---------------------------------------------------------------------------*/
149 /*---------------------------------------------------------------------------*/
150 muse_image *
152 {
153  cpl_ensure(aEuro3D && aEuro3D->dtable && aEuro3D->hdata, CPL_ERROR_NULL_INPUT,
154  NULL);
155 
156  /* guess dimensions of the output image from the Euro3D data */
157  muse_wcs *wcs = muse_wcs_new(aEuro3D->header);
158  /* similar test as in muse_pixtable_wcs_check() */
159  wcs->iscelsph = CPL_FALSE;
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);
163  /* should be equal in the first three characters */
164  if (!strncmp(unitx, unity, 4) && !strncmp(unitx, "deg", 4)) {
165  wcs->iscelsph = CPL_TRUE;
166  }
167  /* extreme coordinates in pixel or celestial coordinates */
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; /* pixel coordinates */
173  if (wcs->iscelsph) {
174  wcs->crval1 /= CPL_MATH_DEG_RAD; /* convert to radians */
175  wcs->crval2 /= CPL_MATH_DEG_RAD;
176  muse_wcs_pixel_from_celestial_fast(wcs, xmin / CPL_MATH_DEG_RAD,
177  ymin / CPL_MATH_DEG_RAD, &x1, &y1);
178  muse_wcs_pixel_from_celestial_fast(wcs, xmax / CPL_MATH_DEG_RAD,
179  ymax / CPL_MATH_DEG_RAD, &x2, &y2);
180  } else {
181  x1 = xmin;
182  x2 = xmax;
183  y1 = ymin;
184  y2 = ymax;
185  }
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;
191 
192  /* count how many valid elements really are in the most shifted spectrum */
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",
196  zmaxpos);
197  int l, nsize = cpl_array_get_size(amax);
198  for (l = nsize - 1; l > 0; l--) {
199  /* find last valid element */
200  if (cpl_array_is_valid(amax, l) == 1) {
201  break;
202  }
203  }
204  nz += l + 1; /* add the number of valid elements in spectral direction */
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);
208 
209  /* resample the filter curve on the wavelength grid */
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");
217  int l1 = 0, l2 = nz; /* loop boundaries for filter operation */
218  double *fdata = NULL;
219  double ffraction = 1.; /* filter fraction */
220  if (aFilter) {
221  fdata = muse_datacube_collapse_filter_buffer(aFilter, crvals, zmin,
222  cdelts, loglambda, &l1, &l2,
223  &ffraction);
224  }
225 
226  /* create output muse_image, but only with two image extensions */
227  muse_image *image = muse_image_new();
228  image->header = cpl_propertylist_duplicate(aEuro3D->header);
229  /* the axis3 WCS was already erased in muse_resampling_euro3d() */
230  if (aFilter) {
231  muse_utils_filter_copy_properties(image->header, aFilter, ffraction);
232  }
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);
236  /* pre-fill with Euro3D status for missing data */
237  cpl_image_add_scalar(image->dq, EURO3D_MISSDATA);
238  int *outdq = cpl_image_get_data_int(image->dq);
239  /* image->stat remains NULL, variance information is lost by collapsing */
240 
241  /* check if we need to use the variance for weighting */
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;
246  }
247 
248  /* loop through all spaxels and over all wavelengths */
249  int k, noutside = 0;
250  #pragma omp parallel for default(none) private(l) /* as req. by Ralf */ \
251  shared(aEuro3D, fdata, l1, l2, noutside, nspec, nx, ny, outdata, \
252  outdq, usevariance, wcs)
253  for (k = 0; k < nspec; k++) {
254  int err;
255  double xpos = cpl_table_get(aEuro3D->dtable, "XPOS", k, &err),
256  ypos = cpl_table_get(aEuro3D->dtable, "YPOS", k, &err);
257  if (err) {
258  cpl_msg_warning(__func__, "spectrum %d in Euro3D table does not have "
259  "position information!", k + 1);
260  continue;
261  }
262  /* coordinate in the output image (indices starting at 0) */
263  double xpx, ypx;
264  if (wcs->iscelsph) {
265  muse_wcs_pixel_from_celestial_fast(wcs, xpos * CPL_MATH_RAD_DEG,
266  ypos * CPL_MATH_RAD_DEG, &xpx, &ypx);
267  } else {
268  muse_wcs_pixel_from_projplane_fast(wcs, xpos, ypos, &xpx, &ypx);
269  }
270  int i = lround(xpx) - 1,
271  j = lround(ypx) - 1;
272  if (i >= nx || j >= ny) {
273  /* should not happen, but skip this spectrum to avoid segfault */
274  noutside++;
275  continue;
276  }
277 
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),
281  *astat = NULL;
282  if (usevariance) {
283  astat = cpl_table_get_array(aEuro3D->dtable, "STAT_SPE", k);
284  }
285 
286  double sumdata = 0., sumweight = 0.;
287  for (l = l1; l < l2; l++) {
288  /* array index for this wavelength */
289  int idx = l - nstart + 1;
290 
291  /* filter weight with fallback for operation without filter */
292  double fweight = fdata ? fdata[l] : 1.;
293  cpl_errorstate prestate = cpl_errorstate_get();
294  int dq = cpl_array_get_int(adq, idx, &err);
295  if (dq || err) { /* if pixel marked bad or inaccessible */
296  cpl_errorstate_set(prestate);
297  continue; /* ignore bad pixels of any kind */
298  }
299  /* make the variance information optional */
300  double variance = 1.;
301  if (usevariance) {
302  variance = astat ? cpl_array_get(astat, idx, &err) : 1.;
303  /* use ^2 as for Euro3D we store errors not variances directly */
304  variance *= variance;
305  if (err > 0) {
306  variance = DBL_MAX;
307  }
308  if (err || !isnormal(variance)) {
309  continue;
310  }
311  }
312  double data = cpl_array_get(adata, idx, &err);
313  /* weight by inverse variance */
314  sumdata += data * fweight / variance;
315  sumweight += fweight / variance;
316  } /* for l (z / wavelengths) */
317  if (isnormal(sumweight)) {
318  outdata[i + j*nx] = sumdata / sumweight;
319  outdq[i + j*nx] = EURO3D_GOODPIXEL;
320  } else { /* leave bad/missing pixels zero, but mark them bad */
321  outdq[i + j*nx] = EURO3D_MISSDATA;
322  }
323  } /* for k (all spaxels) */
324  cpl_free(wcs);
325  cpl_free(fdata); /* won't crash on NULL */
326  if (noutside > 0) {
327  cpl_msg_warning(__func__, "Skipped %d spaxels, due to their location "
328  "outside the recostructed image!", noutside);
329  }
330 
331  return image;
332 } /* muse_euro3dcube_collapse() */
333 
334 /*---------------------------------------------------------------------------*/
355 /*---------------------------------------------------------------------------*/
356 muse_image *
358 {
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);
363  if (aCube->dq) {
364  cpl_ensure(cpl_image_get_type(cpl_imagelist_get(aCube->dq, 0)) == CPL_TYPE_INT,
365  CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
366  }
367  if (aCube->stat) {
368  cpl_ensure(cpl_image_get_type(cpl_imagelist_get(aCube->stat, 0)) == CPL_TYPE_FLOAT,
369  CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
370  }
371 
372  /* find in/output dimensions */
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);
376  /* resample the filter curve on the wavelength grid */
377  double crpix3 = muse_pfits_get_crpix(aCube->header, 3),
378  crval3 = muse_pfits_get_crval(aCube->header, 3),
379  cd33 = muse_pfits_get_cd(aCube->header, 3, 3);
380  const char *ctype3 = muse_pfits_get_ctype(aCube->header, 3);
381  cpl_boolean loglambda = ctype3 && (!strncmp(ctype3, "AWAV-LOG", 9) ||
382  !strncmp(ctype3, "WAVE-LOG", 9));
383  int l1 = 0, l2 = nz; /* loop boundaries for filter operation */
384  double *fdata = NULL;
385  double ffraction = 1.; /* filter fraction */
386  if (aFilter) {
387  fdata = muse_datacube_collapse_filter_buffer(aFilter, crval3, crpix3,
388  cd33, loglambda, &l1, &l2,
389  &ffraction);
390  }
391 
392  /* create output muse_image, but only with two image extensions */
393  muse_image *image = muse_image_new();
394  image->header = cpl_propertylist_duplicate(aCube->header);
395  cpl_propertylist_erase_regexp(image->header, "^C...*3$|^CD3_.$", 0);
396  if (aFilter) {
397  muse_utils_filter_copy_properties(image->header, aFilter, ffraction);
398  }
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);
403  /* image->stat remains NULL, variance information is lost by collapsing */
404 
405  /* check if we need to use the variance for weighting */
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;
410  }
411 
412  /* loop through all pixels in all wavelength planes */
413  int i;
414  #pragma omp parallel for default(none) /* as req. by Ralf */ \
415  shared(aCube, nx, ny, l1, l2, fdata, outdata, outdq, usevariance)
416  for (i = 0; i < nx; i++) {
417  int j;
418  for (j = 0; j < ny; j++) {
419  double sumdata = 0., sumweight = 0.;
420  int l;
421  for (l = l1; l < l2; l++) {
422  /* filter weight with fallback for operation without filter */
423  double fweight = fdata ? fdata[l] : 1.;
424  float *pdata = cpl_image_get_data_float(cpl_imagelist_get(aCube->data, l)),
425  *pstat = NULL;
426  if (!isfinite(pdata[i + j*nx])) {
427  continue;
428  }
429  if (aCube->dq) {
430  int *pdq = cpl_image_get_data_int(cpl_imagelist_get(aCube->dq, l));
431  if (pdq && pdq[i + j*nx]) {
432  continue; /* ignore bad pixels of any kind */
433  }
434  }
435  /* make the variance information optional */
436  double variance = 1.;
437  if (usevariance) {
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)) {
441  continue;
442  }
443  }
444  /* weight by inverse variance */
445  sumdata += pdata[i + j*nx] * fweight / variance;
446  sumweight += fweight / variance;
447  } /* for l (z / wavelengths) */
448  if (isnormal(sumweight)) {
449  outdata[i + j*nx] = sumdata / sumweight;
450  outdq[i + j*nx] = EURO3D_GOODPIXEL;
451  } else { /* leave bad/missing pixels zero, but mark them bad */
452  outdq[i + j*nx] = EURO3D_MISSDATA;
453  }
454  } /* for j (y pixels) */
455  } /* for i (x pixels) */
456 
457  cpl_free(fdata); /* won't crash on NULL */
458 
459  return image;
460 } /* muse_datacube_collapse() */
461 
462 /*---------------------------------------------------------------------------*/
477 /*---------------------------------------------------------------------------*/
478 cpl_error_code
479 muse_datacube_save_recimages(const char *aFilename, muse_imagelist *aImages,
480  cpl_array *aNames)
481 {
482  cpl_ensure_code(aFilename, CPL_ERROR_NULL_INPUT);
483  cpl_error_code rc = CPL_ERROR_NONE;
484  if (!aImages || !aNames) {
485  return rc; /* this is a valid case, return without error */
486  }
487  unsigned int i, nimages = muse_imagelist_get_size(aImages);
488  for (i = 0; i < nimages; i++) {
489  muse_image *image = muse_imagelist_get(aImages, i);
490  if (!image) {
491  continue;
492  }
493 
494  /* create small header with EXTNAME=filtername and WCS for images */
495  cpl_propertylist *header = cpl_propertylist_new();
496  cpl_errorstate es = cpl_errorstate_get();
497  const char *unit = muse_pfits_get_bunit(image->header),
498  *ucomment = cpl_propertylist_get_comment(image->header, "BUNIT");
499  if (!cpl_errorstate_is_equal(es) && !unit) {
500  cpl_errorstate_set(es); /* swallow errors, if there is no unit to propagate */
501  }
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));
505  if (image->dq) {
506  dqext = cpl_sprintf("%s_%s", cpl_array_get_string(aNames, i), EXTNAME_DQ);
507  }
508  if (image->stat) {
509  statext = cpl_sprintf("%s_%s", cpl_array_get_string(aNames, i), EXTNAME_STAT);
510  }
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)");
514  /* propagate the unit in the same way as in muse_image_save() */
515  if (unit) {
516  cpl_propertylist_append_string(header, "BUNIT", unit);
517  cpl_propertylist_set_comment(header, "BUNIT", ucomment);
518  }
519  /* update the OBJECT header with the filter name */
520  muse_utils_copy_modified_header(image->header, header, "OBJECT", obj);
521  cpl_propertylist_copy_property_regexp(header, image->header,
522  MUSE_WCS_KEYS"|"MUSE_HDR_FILTER_REGEXP,
523  0);
524  muse_utils_set_hduclass(header, "DATA", dataext, dqext, statext);
525  rc = cpl_image_save(image->data, aFilename, CPL_TYPE_UNSPECIFIED, header,
526  CPL_IO_EXTEND);
527 
528  if (image->dq) {
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"); /* no unit for data quality */
532  snprintf(obj, KEYWORD_LENGTH, "%s, %s", cpl_array_get_string(aNames, i),
533  EXTNAME_DQ);
534  muse_utils_copy_modified_header(image->header, header, "OBJECT", obj);
535  muse_utils_set_hduclass(header, "QUALITY", dataext, dqext, statext);
536  rc = cpl_image_save(image->dq, aFilename, CPL_TYPE_INT, header,
537  CPL_IO_EXTEND);
538  }
539  if (image->stat) {
540  cpl_propertylist_update_string(header, "EXTNAME", statext);
541  cpl_propertylist_set_comment(header, "EXTNAME", "reconstructed image (variance)");
542  if (unit) {
543  char *ustat = cpl_sprintf("(%s)**2", unit); /* variance in squared units */
544  cpl_propertylist_append_string(header, "BUNIT", ustat);
545  cpl_free(ustat);
546  }
547  snprintf(obj, KEYWORD_LENGTH, "%s, %s", cpl_array_get_string(aNames, i),
548  EXTNAME_STAT);
549  muse_utils_copy_modified_header(image->header, header, "OBJECT", obj);
550  muse_utils_set_hduclass(header, "ERROR", dataext, dqext, statext);
551  rc = cpl_image_save(image->stat, aFilename, CPL_TYPE_UNSPECIFIED, header,
552  CPL_IO_EXTEND);
553  }
554 
555  cpl_propertylist_delete(header);
556  cpl_free(dqext);
557  cpl_free(statext);
558  } /* for i (all reconstructed images) */
559 
560  return rc;
561 } /* muse_datacube_save_recimages */
562 
563 /*---------------------------------------------------------------------------*/
578 /*---------------------------------------------------------------------------*/
579 cpl_error_code
580 muse_euro3dcube_save(muse_euro3dcube *aEuro3D, const char *aFilename)
581 {
582  cpl_ensure_code(aEuro3D && aFilename, CPL_ERROR_NULL_INPUT);
583 
584  /* save primary header and the data table in the first extension */
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());
590  }
591  /* save group header and data in the second extension */
592  rc = cpl_table_save(aEuro3D->gtable, NULL, aEuro3D->hgroup, aFilename,
593  CPL_IO_EXTEND);
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());
597  }
598 
599  rc = muse_datacube_save_recimages(aFilename, aEuro3D->recimages,
600  aEuro3D->recnames);
601  return rc;
602 } /* muse_euro3dcube_save() */
603 
604 /*---------------------------------------------------------------------------*/
614 /*---------------------------------------------------------------------------*/
615 void
617 {
618  /* if the euro3d object doesn't exists at all, we don't need to do anything */
619  if (!aEuro3D) {
620  return;
621  }
622 
623  /* checks for the existence of the sub-images *
624  * are done in the CPL functions */
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);
632  cpl_free(aEuro3D);
633 } /* muse_euro3dcube_delete() */
634 
635 /*---------------------------------------------------------------------------*/
645 /*---------------------------------------------------------------------------*/
646 static cpl_error_code
647 muse_datacube_convert_dq_recimages(muse_datacube *aCube)
648 {
649  cpl_ensure_code(aCube, CPL_ERROR_NULL_INPUT);
650  if (!aCube->recimages) {
651  return CPL_ERROR_NONE; /* valid case, return without error */
652  }
653  unsigned int k, nimages = muse_imagelist_get_size(aCube->recimages);
654  for (k = 0; k < nimages; k++) {
655  muse_image *image = muse_imagelist_get(aCube->recimages, k);
656  if (!image->dq) { /* no point trying to convert... */
657  continue;
658  }
659  muse_image_dq_to_nan(image);
660  } /* for k (all reconstructed images) */
661 
662  return CPL_ERROR_NONE;
663 } /* muse_datacube_convert_dq_recimages() */
664 
665 /*---------------------------------------------------------------------------*/
678 /*---------------------------------------------------------------------------*/
679 cpl_error_code
681 {
682  cpl_ensure_code(aCube && aCube->data && aCube->stat && aCube->dq,
683  CPL_ERROR_NULL_INPUT);
684 
685  /* loop through all wavelength planes and then all pixels per plane */
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) /* as req. by Ralf */ \
690  shared(aCube, nx, ny, nz)
691  for (l = 0; l < nz; l++) {
692  int i;
693  for (i = 0; i < nx; i++) {
694  int j;
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) {
700  continue; /* nothing to do for good pixels */
701  }
702  /* set bad pixels of any type to not-a-number in both extensions */
703  pdata[i + j*nx] = NAN; /* supposed to be quiet NaN */
704  pstat[i + j*nx] = NAN;
705  } /* for j (y direction) */
706  } /* for i (x direction) */
707  } /* for l (wavelength planes) */
708 
709  /* deallocate DQ and set it to NULL to be able to check for it */
710  cpl_imagelist_delete(aCube->dq);
711  aCube->dq = NULL;
712 
713  /* do the same for the reconstructed images, if there are any */
714  muse_datacube_convert_dq_recimages(aCube);
715 
716  return CPL_ERROR_NONE;
717 } /* muse_datacube_convert_dq() */
718 
719 /*---------------------------------------------------------------------------*/
748 /*---------------------------------------------------------------------------*/
749 cpl_error_code
750 muse_datacube_save(muse_datacube *aCube, const char *aFilename)
751 {
752  cpl_ensure_code(aCube && aCube->header && aFilename, CPL_ERROR_NULL_INPUT);
753 
754  /* save headers into primary area */
755  cpl_propertylist *header = cpl_propertylist_new();
756  /* copy all headers, except the main WCS keys */
757  cpl_propertylist_copy_property_regexp(header, aCube->header,
758  MUSE_WCS_KEYS, 1);
759  cpl_error_code rc = cpl_propertylist_save(header, aFilename, CPL_IO_CREATE);
760  cpl_propertylist_delete(header);
761 
762  /* save data */
763  header = cpl_propertylist_new();
764  cpl_propertylist_append_string(header, "EXTNAME", EXTNAME_DATA);
765  cpl_propertylist_set_comment(header, "EXTNAME", EXTNAME_DATA_COMMENT);
766  muse_utils_copy_modified_header(aCube->header, header, "OBJECT",
767  EXTNAME_DATA);
768  cpl_propertylist_copy_property_regexp(header, aCube->header,
769  MUSE_WCS_KEYS"|^BUNIT", 0);
770  muse_utils_set_hduclass(header, "DATA", "DATA",
771  aCube->dq ? "DQ" : NULL, aCube->stat ? "STAT" : NULL);
772  rc = cpl_imagelist_save(aCube->data, aFilename, CPL_TYPE_FLOAT, header,
773  CPL_IO_EXTEND);
774  cpl_propertylist_delete(header);
775  /* save bad pixels, if available */
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);
780  muse_utils_copy_modified_header(aCube->header, header, "OBJECT",
781  EXTNAME_DQ);
782  cpl_propertylist_copy_property_regexp(header, aCube->header,
783  MUSE_WCS_KEYS, 0);
784  muse_utils_set_hduclass(header, "QUALITY", "DATA", "DQ",
785  aCube->stat ? "STAT" : NULL);
786  rc = cpl_imagelist_save(aCube->dq, aFilename, CPL_TYPE_INT, header,
787  CPL_IO_EXTEND);
788  cpl_propertylist_delete(header);
789  }
790  /* save variance, if available */
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);
795  /* add the correct BUNIT, depending on the data units */
796  if (!strncmp(muse_pfits_get_bunit(aCube->header),
797  kMuseFluxUnitString, strlen(kMuseFluxUnitString) + 1)) {
798  /* flux calibrated data */
799  cpl_propertylist_append_string(header, "BUNIT", kMuseFluxStatString);
800  }
801  muse_utils_copy_modified_header(aCube->header, header, "OBJECT",
802  EXTNAME_STAT);
803  cpl_propertylist_copy_property_regexp(header, aCube->header,
804  MUSE_WCS_KEYS, 0);
805  muse_utils_set_hduclass(header, "ERROR", "DATA", aCube->dq ? "DQ" : NULL,
806  "STAT");
807  rc = cpl_imagelist_save(aCube->stat, aFilename, CPL_TYPE_FLOAT, header,
808  CPL_IO_EXTEND);
809  cpl_propertylist_delete(header);
810  }
811 
812  rc = muse_datacube_save_recimages(aFilename, aCube->recimages, aCube->recnames);
813  return rc;
814 } /* muse_datacube_save() */
815 
816 /*---------------------------------------------------------------------------*/
817 /*
818  @private
819  @error{set CPL_ERROR_NULL_INPUT\, return NULL, aFilename is NULL}
820  @error{set CPL_ERROR_ILLEGAL_INPUT\, return NULL, aFilename does not exist}
821  @error{set CPL_ERROR_DATA_NOT_FOUND\, return NULL,
822  aFilename does not contain a DATA extension}
823  */
824 /*---------------------------------------------------------------------------*/
825 static cpl_propertylist *
826 muse_datacube_load_header(const char *aFilename)
827 {
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);
832 
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,
836  MUSE_WCS_KEYS"|BUNIT", 0);
837  cpl_propertylist_delete(hdata);
838  return header;
839 } /* muse_datacube_load_header() */
840 
841 /*---------------------------------------------------------------------------*/
871 /*---------------------------------------------------------------------------*/
873 muse_datacube_load(const char *aFilename)
874 {
875  cpl_ensure(aFilename, CPL_ERROR_NULL_INPUT, NULL);
876  muse_datacube *cube = cpl_calloc(1, sizeof(muse_datacube));
877  /* load primary header and merge in relevant entries from the DATA header */
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!",
882  aFilename);
883  cpl_free(cube);
884  return NULL;
885  }
886  int ext = cpl_fits_find_extension(aFilename, "DATA");
887  cube->data = cpl_imagelist_load(aFilename, CPL_TYPE_FLOAT, ext);
888  /* DQ is usually not written to disk, but see if it's there and load it, if so */
889  ext = cpl_fits_find_extension(aFilename, "DQ");
890  if (ext > 0) {
891  cube->stat = cpl_imagelist_load(aFilename, CPL_TYPE_INT, ext);
892  }
893  ext = cpl_fits_find_extension(aFilename, "STAT");
894  if (ext > 0) {
895  cube->stat = cpl_imagelist_load(aFilename, CPL_TYPE_FLOAT, ext);
896  }
897  int next = cpl_fits_count_extensions(aFilename);
898  while (++ext <= next) {
899  /* there is (one more) collapsed image, load it */
900  muse_image *image = muse_image_new();
901  image->header = cpl_propertylist_load(aFilename, ext);
902  image->data = cpl_image_load(aFilename, CPL_TYPE_UNSPECIFIED, 0, ext);
903  /* search for an load DQ and STAT extensions of this image, if present */
904  const char *extname = muse_pfits_get_extname(image->header);
905  char *extname2 = cpl_sprintf("%s_DQ", extname);
906  int ext2 = cpl_fits_find_extension(aFilename, extname2);
907  cpl_free(extname2);
908  if (ext2 > 0) {
909  image->dq = cpl_image_load(aFilename, CPL_TYPE_INT, 0, ext2);
910  ext = ext2; /* skip this as a normal reconstructed image */
911  }
912  extname2 = cpl_sprintf("%s_STAT", extname);
913  ext2 = cpl_fits_find_extension(aFilename, extname2);
914  cpl_free(extname2);
915  if (ext2 > 0) {
916  image->stat = cpl_image_load(aFilename, CPL_TYPE_UNSPECIFIED, 0, ext2);
917  ext = ext2; /* skip this as a normal reconstructed image */
918  }
919 
920  if (!cube->recnames) {
921  cube->recnames = cpl_array_new(1, CPL_TYPE_STRING);
922  } else {
923  cpl_array_set_size(cube->recnames, cpl_array_get_size(cube->recnames) + 1);
924  }
925  /* append name of this reconstructed image at the end of the names array */
926  cpl_array_set_string(cube->recnames, cpl_array_get_size(cube->recnames) - 1,
927  extname);
928  if (!cube->recimages) {
929  cube->recimages = muse_imagelist_new();
930  }
931  /* append the image to the end of the reconstructed image list */
932  muse_imagelist_set(cube->recimages, image,
934  }
935  return cube;
936 } /* muse_datacube_load() */
937 
938 /*---------------------------------------------------------------------------*/
958 /*---------------------------------------------------------------------------*/
959 cpl_error_code
961 {
962  cpl_ensure_code(aCube && aAppend, CPL_ERROR_NULL_INPUT);
963 
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);
970 
971  /* check sizes of the image planes */
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);
977  const char *ctype1 = muse_pfits_get_ctype(aCube->header, 3),
978  *ctype2 = muse_pfits_get_ctype(aCube->header, 3);
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);
983  /* compute wavelengths of last plane of first cube and first plane *
984  * of the cube to append, to check that they are adjacent */
985  double pix1 = muse_pfits_get_crpix(aCube->header, 3),
986  val1 = muse_pfits_get_crval(aCube->header, 3),
987  cd1 = muse_pfits_get_cd(aCube->header, 3, 3),
988  pix2 = muse_pfits_get_crpix(aAppend->header, 3),
989  val2 = muse_pfits_get_crval(aAppend->header, 3),
990  cd2 = muse_pfits_get_cd(aAppend->header, 3, 3),
991  lbda1 = ((ndata - 1) + 1. - pix1) * cd1 + val1,
992  lbda2 = (0 + 1. - pix2) * cd2 + val2;
993  /* AWAV-LOG and WAVE-LOG axes need more complex handling, so exclude them above */
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);
998 
999  /* reconstructed images are now obsolete, remove them */
1000  cpl_array_delete(aCube->recnames);
1001  aCube->recnames = NULL;
1003  aCube->recimages = NULL;
1004 
1005  /* Check if there is a usable DQ component in both cubes. If so, *
1006  * propagate them as the other two components, otherwise delete *
1007  * the incoming DQ of the first (= output) cube. */
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) {
1011  usedq = CPL_TRUE;
1012  } else {
1013  cpl_imagelist_delete(aCube->dq);
1014  aCube->dq = NULL;
1015  }
1016 
1017  /* append the CPL imagelists */
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));
1022  if (usedq) {
1023  cpl_imagelist_set(aCube->dq,
1024  cpl_image_duplicate(cpl_imagelist_get(aAppend->dq, i)),
1025  cpl_imagelist_get_size(aCube->dq));
1026  }
1027  cpl_imagelist_set(aCube->stat,
1028  cpl_image_duplicate(cpl_imagelist_get(aAppend->stat, i)),
1029  cpl_imagelist_get_size(aCube->stat));
1030  }
1031  return CPL_ERROR_NONE;
1032 } /* muse_datacube_concat() */
1033 
1034 /*---------------------------------------------------------------------------*/
1044 /*---------------------------------------------------------------------------*/
1045 void
1047 {
1048  /* if the cube does not exists at all, we don't need to do anything */
1049  if (!aCube) {
1050  return;
1051  }
1052 
1053  /* checks for the existence of the sub-images *
1054  * are done in the CPL functions */
1055  cpl_imagelist_delete(aCube->data);
1056  aCube->data = NULL;
1057  cpl_imagelist_delete(aCube->dq);
1058  aCube->dq = NULL;
1059  cpl_imagelist_delete(aCube->stat);
1060  aCube->stat = NULL;
1061 
1062  /* delete the FITS header, too */
1063  cpl_propertylist_delete(aCube->header);
1064  aCube->header = NULL;
1065 
1066  /* remove reconstructed image data, if present */
1068  cpl_array_delete(aCube->recnames);
1069  cpl_free(aCube);
1070 } /* muse_datacube_delete() */
1071 
Structure definition of a MUSE datacube.
Definition: muse_datacube.h:48
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
Definition: muse_pfits.c:446
const char * muse_pfits_get_extname(const cpl_propertylist *aHeaders)
find out the extension name
Definition: muse_pfits.c:205
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
Definition: muse_pfits.c:423
A structure containing a spatial two-axis WCS.
Definition: muse_wcs.h:105
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
Definition: muse_image.h:46
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.
Definition: muse_utils.c:934
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.
Definition: muse_wcs.h:246
cpl_image * stat
the statistics extension
Definition: muse_image.h:64
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
Definition: muse_pfits.c:223
muse_imagelist * recimages
the reconstructed image data
cpl_propertylist * header
the primary FITS header
Structure definition of MUSE three extension FITS file.
Definition: muse_image.h:40
cpl_array * recnames
the reconstructed image filter names
Definition: muse_datacube.h:71
cpl_propertylist * header
the FITS header
Definition: muse_image.h:72
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.
Definition: muse_utils.c:2611
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
Definition: muse_image.h:56
double muse_pfits_get_crpix(const cpl_propertylist *aHeaders, unsigned int aAxis)
find out the WCS reference point
Definition: muse_pfits.c:401
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.
Definition: muse_flux.c:338
muse_wcs * muse_wcs_new(cpl_propertylist *aHeader)
Create a new WCS structure from a given FITS header.
Definition: muse_wcs.c:1897
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
Definition: muse_wcs.h:48
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.
Definition: muse_wcs.h:177
cpl_table * table
The table.
Definition: muse_table.h:49
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
Definition: muse_datacube.h:76
Structure definition of a Euro3D datacube.
Definition: muse_datacube.h:97
Structure to store a table together with a property list.
Definition: muse_table.h:43
double muse_utils_filter_fraction(const muse_table *aFilter, double aLambda1, double aLambda2)
Compute fraction of filter area covered by the data range.
Definition: muse_utils.c:893
cpl_imagelist * dq
the optional cube containing the bad pixel status
Definition: muse_datacube.h:81
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
Definition: muse_pfits.c:469
cpl_propertylist * hdata
the data FITS header
cpl_table * gtable
the table containing the Euro3D groups
cpl_propertylist * header
the FITS header
Definition: muse_datacube.h:57
muse_imagelist * muse_imagelist_new(void)
Create a new (empty) MUSE image list.
cpl_boolean iscelsph
Definition: muse_wcs.h:112
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.
Definition: muse_image.c:66
double crval2
Definition: muse_wcs.h:107
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
Definition: muse_datacube.h:64
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.
Definition: muse_utils.c:2570
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).
Definition: muse_image.c:904
cpl_imagelist * stat
the cube containing the data variance
Definition: muse_datacube.h:86