MUSE Pipeline Reference Manual  2.5.2
muse_twilight.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) 2014-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 <string.h>
30 
31 #include <muse.h>
32 #include "muse_twilight_z.h"
33 
34 /*---------------------------------------------------------------------------*
35  * Functions code *
36  *---------------------------------------------------------------------------*/
37 
38 /*---------------------------------------------------------------------------*/
45 /*---------------------------------------------------------------------------*/
46 static cpl_error_code
47 muse_twilight_qc_header(muse_image *aImage, muse_imagelist *aList)
48 {
49  cpl_ensure_code(aImage && aList, CPL_ERROR_NULL_INPUT);
50  unsigned char ifu = muse_utils_get_ifu(aImage->header);
51  cpl_msg_debug(__func__, "Adding QC keywords for IFU %hhu", ifu);
52 
53  unsigned stats = CPL_STATS_MEDIAN | CPL_STATS_MEAN | CPL_STATS_STDEV
54  | CPL_STATS_MIN | CPL_STATS_MAX;
55 
56  /* write the image statistics for input skyflat field exposures */
57  unsigned int k;
58  for (k = 0; k < muse_imagelist_get_size(aList); k++) {
59  char *keyword = cpl_sprintf(QC_TWILIGHTm_PREFIXi, ifu, k+1);
61  aImage->header, keyword, stats);
62  cpl_free(keyword);
63  keyword = cpl_sprintf(QC_TWILIGHTm_PREFIXi" "QC_BASIC_NSATURATED, ifu, k+1);
64  int nsaturated = cpl_propertylist_get_int(muse_imagelist_get(aList, k)->header,
65  MUSE_HDR_TMP_NSAT);
66  cpl_propertylist_update_int(aImage->header, keyword, nsaturated);
67  cpl_free(keyword);
68  } /* for k (all images in list) */
69 
70  /* properties of the resulting master frame */
71  char *kw = cpl_sprintf(QC_TWILIGHTm_MASTER_PREFIX, ifu);
72  stats |= CPL_STATS_FLUX;
73  muse_basicproc_stats_append_header(aImage->data, aImage->header, kw, stats);
74  cpl_free(kw);
75  return CPL_ERROR_NONE;
76 } /* muse_twilight_qc_header() */
77 
78 /*----------------------------------------------------------------------------*/
125 /*----------------------------------------------------------------------------*/
126 static muse_datacube *
127 muse_twilight_reconstruct(muse_processing *aProcessing,
128  muse_twilight_params_t *aParams,
129  muse_basicproc_params *aBPars,
130  muse_combinepar *aCPars,
131  muse_resampling_params *aRPars)
132 {
133  cpl_ensure(aProcessing && aParams, CPL_ERROR_NULL_INPUT, NULL);
134  double lmin = aParams->lambdamin,
135  lmax = aParams->lambdamax;
136  cpl_ensure(lmax > lmin, CPL_ERROR_ILLEGAL_INPUT, NULL);
137  /* the geometry table is common for all IFUs */
138  cpl_table *geo = muse_processing_load_ctable(aProcessing, MUSE_TAG_GEOMETRY_TABLE, 0);
139  cpl_ensure(geo, CPL_ERROR_FILE_NOT_FOUND, NULL);
140 
141  muse_pixtable **pts = cpl_calloc(kMuseNumIFUs, sizeof(muse_pixtable));
142  unsigned char nifu;
143  #pragma omp parallel for default(none) /* as req. by Ralf */ \
144  shared(aBPars, aCPars, aProcessing, geo, pts)
145  for (nifu = 1; nifu <= kMuseNumIFUs; nifu++) {
146  cpl_table *trace = muse_processing_load_ctable(aProcessing, MUSE_TAG_TRACE_TABLE, nifu),
147  *wavecal = muse_processing_load_ctable(aProcessing, MUSE_TAG_WAVECAL_TABLE, nifu);
148  if (!trace || !wavecal) {
149  cpl_msg_warning(__func__, "Calibrations could not be loaded for IFU "
150  "%2hhu:%s%s", nifu, !trace ? " "MUSE_TAG_TRACE_TABLE : "",
151  !wavecal ? " "MUSE_TAG_WAVECAL_TABLE : "");
152  cpl_table_delete(trace);
153  cpl_table_delete(wavecal);
154  continue; /* skip this IFU */
155  }
156  /* load and pre-process all raw files */
157  cpl_msg_debug(__func__, "load raw files of IFU %2hhu", nifu);
158  muse_imagelist *images = muse_basicproc_load(aProcessing, nifu, aBPars);
159  if (!images) {
160  cpl_msg_warning(__func__, "Basic processing failed for IFU %2hhu: %s",
161  nifu, cpl_error_get_message());
162  cpl_table_delete(trace);
163  cpl_table_delete(wavecal);
164  continue;
165  }
166  /* search for ILLUM exposure(s) in input list, *
167  * prepare them and remove all from the list */
168  cpl_table *tattached = muse_basicproc_get_illum(images, trace, wavecal, geo);
169  /* combine the raw exposures into a master image */
170  cpl_msg_debug(__func__, "combine raw files of IFU %2hhu", nifu);
171  muse_image *masterimage = muse_combine_images(aCPars, images);
172  muse_twilight_qc_header(masterimage, images);
173  muse_imagelist_delete(images);
174  if (!masterimage) {
175  cpl_msg_warning(__func__, "Combining individual images failed for IFU %2hhu: %s",
176  nifu, cpl_error_get_message());
177  cpl_table_delete(tattached);
178  cpl_table_delete(trace);
179  cpl_table_delete(wavecal);
180  continue;
181  }
182 
183  /* apply bad-pixel interpolation on this image, so that the *
184  * per-IFU integrated fluxes are independent of bad pixels */
185  int nbad = muse_quality_image_reject_using_dq(masterimage->data,
186  masterimage->dq,
187  masterimage->stat);
188  cpl_detector_interpolate_rejected(masterimage->data);
189  /* doing this for the variance is ugly but we cannot do much else */
190  cpl_detector_interpolate_rejected(masterimage->stat);
191  /* still leave them marked in the DQ extension */
192  cpl_msg_debug(__func__, "interpolated over %d bad pixels in IFU %2hhu",
193  nbad, nifu);
194 
195  /* create pixel table for this master image */
196  cpl_msg_debug(__func__, "create pixel table for IFU %2hhu", nifu);
197  pts[nifu - 1] = muse_pixtable_create(masterimage, trace, wavecal, geo);
198  cpl_table_delete(trace);
199  cpl_table_delete(wavecal);
200  /* propagate the QC parameters from the image header */
201  if (pts[nifu - 1]) {
202  cpl_propertylist_copy_property_regexp(pts[nifu - 1]->header,
203  masterimage->header,
204  QC_TWILIGHT_REGEXP, 0);
205  if (tattached) { /* test before, to not throw an error */
206  muse_basicproc_apply_illum(pts[nifu - 1], tattached);
207  } /* if attached flat given */
208  } /* if pixel table created */
209  muse_image_delete(masterimage);
210  cpl_table_delete(tattached);
211 
212  /* in AO mode we also need to mask the NaD notch filter range */
213  if (muse_pfits_get_mode(pts[nifu - 1]->header) > MUSE_MODE_WFM_NONAO_N) {
214  muse_basicproc_mask_notch_filter(pts[nifu - 1], nifu);
215  } /* if AO mode */
216  } /* for nifu (all IFUs) */
217  cpl_table_delete(geo);
218 
219  muse_pixtable *pt = pts[0];
220  muse_pixtable_restrict_wavelength(pt, lmin, lmax);
221  if (muse_pixtable_get_nrow(pt) < 1) {
222  cpl_error_set_message(__func__, CPL_ERROR_ILLEGAL_OUTPUT,
223  "After cutting to %.2f..%.2f Angstrom in wavelength "
224  "no pixels for cube reconstruction are left!", lmin,
225  lmax);
226  for (nifu = 1; nifu <= kMuseNumIFUs; nifu++) {
227  muse_pixtable_delete(pts[nifu - 1]);
228  } /* for nifu (all IFUs) */
229  cpl_free(pts);
230  return NULL;
231  } /* if */
232 
233  cpl_array *scales = NULL;
234  if (getenv("MUSE_TWILIGHT_SCALES")) {
235  scales = muse_cplarray_new_from_delimited_string(getenv("MUSE_TWILIGHT_SCALES"), ",");
236  double scale = atof(cpl_array_get_string(scales, 0));
237  cpl_table_divide_scalar(pt->table, MUSE_PIXTABLE_DATA, scale);
238  cpl_table_divide_scalar(pt->table, MUSE_PIXTABLE_STAT, scale*scale);
239  int nscales = cpl_array_get_size(scales);
240  if (nscales != kMuseNumIFUs) {
241  cpl_msg_warning(__func__, "%d external scales found instead of %d! Not "
242  "using them.", nscales, kMuseNumIFUs);
243  cpl_array_delete(scales);
244  scales = NULL;
245  } else {
246  cpl_msg_info(__func__, "Using %d external scales.", nscales);
247  }
248 #if 1
249  cpl_array_dump(scales, 0, 30, stdout);
250  fflush(stdout);
251 #endif
252  } /* if */
253 
254  double fluxref = cpl_table_get_column_mean(pt->table, MUSE_PIXTABLE_DATA)
256  cpl_msg_debug(__func__, "pixel table of IFU 1, fluxref = %e, %"CPL_SIZE_FORMAT
257  " rows", fluxref, muse_pixtable_get_nrow(pt));
258  /* merge all pixel tables a la muse_pixtable_load_merge_channels() *
259  * but first restricting the wavelength range and with flux *
260  * correction using the data we have in the table */
261  cpl_propertylist_append_double(pt->header, MUSE_HDR_FLAT_FLUX_SKY"1", fluxref);
262  char *kw = cpl_sprintf(QC_TWILIGHTm_INTFLUX, (unsigned char)1);
263  cpl_propertylist_append_float(pt->header, kw, fluxref);
264  cpl_free(kw);
265  for (nifu = 2; nifu <= kMuseNumIFUs; nifu++) {
266  if (!pts[nifu - 1]) {
267  continue;
268  } /* if */
269  muse_pixtable_restrict_wavelength(pts[nifu - 1], lmin, lmax);
270  if (muse_pixtable_get_nrow(pts[nifu - 1]) < 1) {
271  continue;
272  } /* if */
273  double flux = cpl_table_get_column_mean(pts[nifu - 1]->table, MUSE_PIXTABLE_DATA)
274  * muse_pixtable_get_nrow(pts[nifu - 1]),
275  scale = 1.;
276  if (nifu == 24 &&
277  muse_pfits_get_mode(pts[nifu - 1]->header) == MUSE_MODE_NFM_AO_N) {
278  /* CHAN24 in NFM is vignetted, special handling */
279  kw = cpl_sprintf(MUSE_HDR_FLAT_FLUX_SKY"%hhu", 23);
280  double flux23 = cpl_propertylist_get_double(pt->header, kw);
281  cpl_free(kw);
282  cpl_msg_debug(__func__, "NFM: using flux (%.3g) from CHAN23 for "
283  "normalization (instead of %.3g)", flux23, flux);
284  flux = flux23;
285  } /* if IFU 24 and NFM */
286  if (scales) {
287  scale = atof(cpl_array_get_string(scales, nifu - 1));
288  /* also recomputed the flux that is then saved in the header */
289  flux = scale * fluxref;
290  } else {
291  scale = flux / fluxref;
292  } /* else */
293  kw = cpl_sprintf(MUSE_HDR_FLAT_FLUX_SKY"%hhu", nifu);
294  cpl_propertylist_append_double(pt->header, kw, flux);
295  cpl_free(kw);
296  cpl_msg_debug(__func__, "merging pixel table of IFU %2hhu, flux = %e, scale = %f",
297  nifu, flux, scale);
298  cpl_table_divide_scalar(pts[nifu - 1]->table, MUSE_PIXTABLE_DATA, scale);
299  cpl_table_divide_scalar(pts[nifu - 1]->table, MUSE_PIXTABLE_STAT, scale*scale);
300  cpl_table_insert(pt->table, pts[nifu - 1]->table, muse_pixtable_get_nrow(pt));
301  /* again, propagate the QC parameters to the merged pixel table */
302  cpl_propertylist_copy_property_regexp(pt->header, pts[nifu - 1]->header,
303  QC_TWILIGHT_REGEXP, 0);
304  /* add the pixel-table based flux as QC as well */
305  kw = cpl_sprintf(QC_TWILIGHTm_INTFLUX, nifu);
306  cpl_propertylist_append_float(pt->header, kw, flux);
307  cpl_free(kw);
308  muse_pixtable_delete(pts[nifu - 1]);
309  } /* for nifu (all IFUs) */
310  cpl_free(pts);
311  /* reset limits in the header, necessary due to manual operation on table data */
313  cpl_array_delete(scales);
314 
315  /* now just reconstruct the cube and collapse over the full range */
316  muse_datacube *cube = muse_resampling_cube(pt, aRPars, NULL);
318  if (!cube) {
319  return NULL;
320  }
321  /* also create a corresponding white-light image */
322  muse_image *white = muse_datacube_collapse(cube, NULL);
323  cube->recimages = muse_imagelist_new();
324  cube->recnames = cpl_array_new(1, CPL_TYPE_STRING);
325  muse_imagelist_set(cube->recimages, white, 0);
326  cpl_array_set_string(cube->recnames, 0, "white");
327 
328  /* want NANs instead of zeros, and save space */
330 
331  return cube;
332 } /* muse_twilight_reconstruct() */
333 
334 /*----------------------------------------------------------------------------*/
358 /*----------------------------------------------------------------------------*/
359 static cpl_image *
360 muse_twilight_image_normalize_and_fit(muse_image *aImage,
361  unsigned int aXOrder,
362  unsigned int aYOrder,
363  const cpl_mask *aBPM,
364  const cpl_mask *aVign)
365 {
366  cpl_ensure(aImage && aImage->data, CPL_ERROR_NULL_INPUT, NULL);
367 
368  /* reject values from the white-light mask, and extra infinite pixels */
369  if (aBPM) {
370  cpl_image_reject_from_mask(aImage->data, aBPM);
371  }
372  cpl_image_reject_value(aImage->data, CPL_VALUE_NOTFINITE | CPL_VALUE_ZERO);
373 
374  /* filter the image to remove outliers (like strongly deviant slices) */
375  /* use a 5x7 median filter */
376  cpl_image *filtered = cpl_image_duplicate(aImage->data);
377  cpl_mask *mask = cpl_mask_new(5, 7);
378  cpl_mask_not(mask);
379  cpl_errorstate prestate = cpl_errorstate_get();
380  cpl_image_filter_mask(filtered, aImage->data, mask, CPL_FILTER_MEDIAN,
381  CPL_BORDER_FILTER);
382  cpl_mask_delete(mask);
383  if (!cpl_errorstate_is_equal(prestate)) {
384  cpl_msg_warning(__func__, "filtering cube plane failed: %s",
385  cpl_error_get_message());
386  }
387 
388  /* compute the mean of the good pixels and use that to normalize the image */
389  double mean = cpl_image_get_mean(filtered);
390  cpl_msg_debug(__func__, "mean = %f", mean);
391  cpl_image_multiply_scalar(filtered, 1. / mean);
392 
393  /* mask out the vignetted area (if given), before applying the fit */
394  cpl_mask *bpm = cpl_image_get_bpm(filtered);
395  if (aVign) {
396  cpl_mask_or(bpm, aVign);
397  }
398  cpl_image *fit = muse_utils_image_fit_polynomial(filtered,
399  aXOrder, aYOrder);
400  /* normalize again */
401  mean = cpl_image_get_mean(fit);
402  cpl_msg_debug(__func__, "mean(fit) = %f", mean);
403  cpl_image_multiply_scalar(fit, 1. / mean);
404  cpl_image_delete(filtered);
405  return fit;
406 } /* muse_twilight_image_normalize_and_fit() */
407 
408 /*---------------------------------------------------------------------------*/
415 /*---------------------------------------------------------------------------*/
416 int
417 muse_twilight_compute(muse_processing *aProcessing,
418  muse_twilight_params_t *aParams)
419 {
420  muse_datacube *cube = NULL,
421  *cubefit = cpl_calloc(1, sizeof(muse_datacube));
422  cubefit->data = cpl_imagelist_new();
423  if (getenv("MUSE_TWILIGHT_SKIP")) {
424  char *fn = getenv("MUSE_TWILIGHT_SKIP");
425  cube = muse_datacube_load(fn);
426  cpl_msg_warning(__func__, "Skipping active: loaded previously generated "
427  "cube from \"%s\"", fn);
428  /* ensure that the first collapse image is "white" */
429  if (!cube->recimages) { /* no reconstructed images at all */
430  /* create the white-light image */
431  cube->recimages = muse_imagelist_new();
432  cube->recnames = cpl_array_new(1, CPL_TYPE_STRING);
433  muse_image *white = muse_datacube_collapse(cube, NULL);
434  muse_imagelist_set(cube->recimages, white, 0);
435  cpl_array_set_string(cube->recnames, 0, "white");
436  } else if (!cube->recnames ||
437  (cube->recnames &&
438  strncmp("white", cpl_array_get_string(cube->recnames, 0), 6))) {
439  /* replace first reconstructed image with white-light */
440  muse_image *white = muse_datacube_collapse(cube, NULL);
441  muse_imagelist_set(cube->recimages, white, 0);
442  cpl_array_set_string(cube->recnames, 0, "white");
443  } /* else */
444 
445  /* add something to the usedframes in aProcessing for saving below to work */
446  cpl_frameset *frames = muse_frameset_find_tags(aProcessing->inframes,
447  aProcessing->intags, -1, 0);
448  cpl_size iframe, nframes = cpl_frameset_get_size(frames);
449  for (iframe = 0; iframe < nframes; iframe++) {
450  cpl_frame *frame = cpl_frameset_get_position(frames, iframe);
451  muse_processing_append_used(aProcessing, frame, CPL_FRAME_GROUP_RAW, 1);
452  } /* for iframe (all raw inputs) */
453  cpl_frameset_delete(frames);
454  cpl_msg_warning(__func__, "Skipping active: faked used frames using only "
455  "raw inputs:");
456  cpl_frameset_dump(aProcessing->usedframes, stdout);
457  fflush(stdout);
458  cubefit->header = cpl_propertylist_duplicate(cube->header);
459  } /* if skip */
460 
461  cpl_error_code rc = CPL_ERROR_NONE;
462  if (!cube) { /* skipping did not happen */
464  "muse.muse_twilight");
465  muse_combinepar *cpars = muse_combinepar_new(aProcessing->parameters,
466  "muse.muse_twilight");
467  muse_resampling_type resample
470  rp->crtype = muse_postproc_get_cr_type(aParams->crtype_s);
471  rp->crsigma = aParams->crsigma;
472  rp->dlambda = aParams->dlambda;
473  rp->pfx = 1.;
474  rp->pfy = 1.;
475  rp->pfl = 1.;
476  cube = muse_twilight_reconstruct(aProcessing, aParams, bpars, cpars, rp);
478  muse_combinepar_delete(cpars);
480  if (!cube) {
481  muse_datacube_delete(cubefit);
482  return -1;
483  }
484  /* duplicate the cube header and its WCS before saving destroys the WCS */
485  cubefit->header = cpl_propertylist_duplicate(cube->header);
486  rc = muse_processing_save_cube(aProcessing, -1, cube,
487  MUSE_TAG_CUBE_SKYFLAT,
489  /* the QC parameters are saved with the unprocessed cube, now delete them */
490  cpl_propertylist_erase_regexp(cubefit->header, QC_TWILIGHT_REGEXP, 0);
491  } /* if no skipping */
492 
493  /* now mark empty areas in the white-light image as bad; just *
494  * access the first reconstructed image, since the white-light *
495  * image is the only one created by muse_twilight_reconstruct() */
496  muse_image *wmuse = muse_imagelist_get(cube->recimages, 0);
497  if (!wmuse) {
498  muse_datacube_delete(cube);
499  cpl_error_set_message(__func__, CPL_ERROR_ILLEGAL_OUTPUT,
500  "White-light image is missing!");
501  muse_datacube_delete(cubefit);
502  return -1;
503  }
504  cpl_image *white = cpl_image_duplicate(wmuse->data);
505  cpl_image_reject_value(white, CPL_VALUE_NOTFINITE | CPL_VALUE_ZERO);
506  cpl_mask *bpm = cpl_image_get_bpm(white),
507  *bpm2 = cpl_mask_duplicate(bpm);
508  /* force a rejection of the vertical border pixels */
509  cpl_mask *border = cpl_mask_new(1, cpl_mask_get_size_y(bpm2));
510  cpl_mask_not(border);
511  cpl_mask_copy(bpm2, border, 1, 1);
512  cpl_mask_copy(bpm2, border, cpl_mask_get_size_x(bpm2), 1);
513  cpl_mask_delete(border);
514  /* use dilation to make the mask wider, i.e. to *
515  * exclude more of the (usually bad) border */
516  cpl_mask *kernel = cpl_mask_new(5, 1);
517  cpl_mask_not(kernel);
518  cpl_mask_filter(bpm2, bpm, kernel, CPL_FILTER_DILATION, CPL_BORDER_NOP);
519  cpl_mask_delete(kernel);
520  bpm = cpl_image_set_bpm(white, bpm2);
521  cpl_mask_delete(bpm);
522  bpm = bpm2; /* easier handle to remember */
523 
524  /* boolean value for the principle instrument mode, since that *
525  * determines how we treat the vignetting (positive or negative) */
526  cpl_boolean isWFM = muse_pfits_get_mode(cube->header) != MUSE_MODE_NFM_AO_N;
527 
528  /* get or create a vignetting mask */
529  muse_mask *maskimage = NULL;
530  if (isWFM) {
531  cpl_msg_debug(__func__, "WFM: use given %s, if any...", MUSE_TAG_VIGN_MASK);
532  /* apply a mask, if one was given, on top of the one that the image already has */
533  maskimage = muse_processing_load_mask(aProcessing, MUSE_TAG_VIGN_MASK);
534  if (maskimage) {
535  /* adapt the mask to the size of the actual cube */
536  cpl_mask *mask = muse_cplmask_adapt_to_image(maskimage->mask,
537  cpl_imagelist_get(cube->data, 0));
538  cpl_mask_delete(maskimage->mask);
539  maskimage->mask = mask;
540  }
541  } else {
542  /* for NFM, create an internal mask that fills the whole width of *
543  * the cube and the top nmasktop pixels (default: 22 ~ 1.8 IFUs) */
544  cpl_msg_info(__func__, "NFM: creating internal %s...", MUSE_TAG_VIGN_MASK);
545  maskimage = muse_mask_new();
546  int nx = cpl_image_get_size_x(white),
547  ny = cpl_image_get_size_y(white),
548  nmasktop = aParams->vignnfmmask > 0 && aParams->vignnfmmask < ny
549  ? aParams->vignnfmmask : 22;
550  maskimage->header = cpl_propertylist_duplicate(cube->header);
551  maskimage->mask = cpl_mask_new(nx, ny);
552  /* mark the top pixels as masked */
553  int j;
554  for (j = ny - nmasktop; j <= ny; j++) {
555  int i;
556  for (i = 1; i <= nx; i++) {
557  cpl_mask_set(maskimage->mask, i, j, CPL_BINARY_1);
558  } /* for i (all mask columns) */
559  } /* for j (all top mask pixels) */
560  }
561  /* and we can normalize, fit, and then normalize again, every plane in the cube */
562  muse_image *image = muse_image_new();
563  int ipl, npl = cpl_imagelist_get_size(cube->data);
564  for (ipl = 0; ipl < npl; ipl++) {
565  image->data = cpl_imagelist_get(cube->data, ipl);
566  image->stat = cpl_imagelist_get(cube->stat, ipl);
567  cpl_mask *vignmask = maskimage ? maskimage->mask : NULL;
568  cpl_image *fit = muse_twilight_image_normalize_and_fit(image,
569  aParams->xorder,
570  aParams->yorder,
571  bpm, vignmask);
572  cpl_imagelist_set(cubefit->data, fit, ipl);
573  } /* for ipl (all cube image planes) */
574  image->data = NULL;
575  image->stat = NULL;
576  muse_image_delete(image);
577  muse_datacube_delete(cube);
578 
579 #if 0 /* extra debug output for the globally fitted cube, without vignetted area */
580  rc = muse_processing_save_cube(aProcessing, -1, cubefit,
581  "TWILIGHT_CUBE_FIT", MUSE_CUBE_TYPE_FITS);
582 #endif
583 
584  muse_image *whitefit = muse_datacube_collapse(cubefit, NULL);
585  cpl_image_delete(whitefit->dq);
586  whitefit->dq = NULL;
587  cpl_propertylist_update_string(whitefit->header, "OBJECT",
588  "white from global fit");
589  cubefit->recimages = muse_imagelist_new();
590  muse_imagelist_set(cubefit->recimages, whitefit, 0);
591  cubefit->recnames = cpl_array_new(1, CPL_TYPE_STRING);
592  cpl_array_set_string(cubefit->recnames, 0, "white_global_fit");
593 
594  /* normalize the non-smoothed white-light image and divide it by *
595  * the smoothed version; then fit the masked (vignetted) area */
596  double mean = cpl_image_get_mean(white);
597  cpl_image_divide_scalar(white, mean);
598  cpl_image *wdiv = cpl_image_divide_create(white, whitefit->data);
599  /* append to reconstructed images */
600  image = muse_image_new();
601  image->header = cpl_propertylist_new();
602  cpl_propertylist_append_string(image->header, "OBJECT", "normalized "
603  "white-light divided by white global fit");
604  cpl_propertylist_append_string(image->header, "BUNIT", "1"); /* unitless */
605  image->data = wdiv;
606  image->dq = cpl_image_new_from_mask(cpl_image_get_bpm(wdiv));
607  muse_imagelist_set(cubefit->recimages, image,
608  muse_imagelist_get_size(cubefit->recimages));
609  cpl_array_set_size(cubefit->recnames,
610  cpl_array_get_size(cubefit->recnames) + 1);
611  cpl_array_set_string(cubefit->recnames, cpl_array_get_size(cubefit->recnames) - 1,
612  "white_div_global");
613  /* keep mask due to non-rectangular FOV around */
614  cpl_mask *fovmask = cpl_mask_duplicate(cpl_image_get_bpm(white));
615  if (maskimage) {
616  bpm = cpl_image_get_bpm(white);
617  cpl_mask_or(bpm, maskimage->mask);
618  } /* if maskimage */
619  cpl_image_delete(white);
620 
621  /* now invert the mask image (we need to fit the region that it contains!) */
622  if (maskimage) {
623  /* create mask of only the vignetted area */
624  cpl_mask *vignmask = cpl_mask_duplicate(fovmask);
625  cpl_mask_not(maskimage->mask);
626  cpl_mask_or(vignmask, maskimage->mask);
627  cpl_image *wdiv2 = cpl_image_duplicate(wdiv);
628  cpl_image_reject_from_mask(wdiv2, vignmask);
629 
630  /* search for pixels strongly deviating from unity and reject them */
631  if (isWFM && aParams->vignmaskedges > 0.) {
632  cpl_msg_info(__func__, "Excluding strong edges (stronger than %.1f%%) "
633  "from the vignetted area", aParams->vignmaskedges * 100.);
634  cpl_image *wdivX = cpl_image_duplicate(wdiv2);
635  cpl_mask *wdivXmask = cpl_mask_duplicate(cpl_image_get_bpm(wdivX));
636  cpl_image_fill_rejected(wdivX, 1.);
637  cpl_image_accept_all(wdivX);
638  int i, nx = cpl_image_get_size_x(wdivX),
639  j, ny = cpl_image_get_size_y(wdivX);
640  /* first column-wise */
641  for (i = 1; i <= nx; i++) {
642  for (j = 2; j <= ny; j++) {
643  int err;
644  double v1 = cpl_image_get(wdivX, i, j - 1, &err),
645  v2 = cpl_image_get(wdivX, i, j, &err);
646  if (fabs(v2 - v1) < aParams->vignmaskedges) {
647  continue;
648  }
649  /* large difference found */
650  cpl_msg_debug(__func__, "%03d %03d v1 %f V2 %f --> delta %f",
651  i, j, v1, v2, fabs(v2 - v1));
652  double dv1 = fabs(v1 - 1.),
653  dv2 = fabs(v2 - 1.);
654  if (dv1 > dv2) {
655  cpl_mask_set(wdivXmask, i, j - 1, CPL_BINARY_1);
656  } else {
657  cpl_mask_set(wdivXmask, i, j, CPL_BINARY_1);
658  }
659  }
660  }
661  /* now row-wise */
662  for (j = 1; j <= ny; j++) {
663  for (i = 2; i <= nx; i++) {
664  int err;
665  double v1 = cpl_image_get(wdivX, i - 1, j, &err),
666  v2 = cpl_image_get(wdivX, i, j, &err);
667  if (fabs(v2 - v1) < aParams->vignmaskedges) {
668  continue;
669  }
670  /* large difference found */
671  cpl_msg_debug(__func__, "%03d %03d v1 %f V2 %f --> delta %f",
672  i, j, v1, v2, fabs(v2 - v1));
673  double dv1 = fabs(v1 - 1.),
674  dv2 = fabs(v2 - 1.);
675  if (dv1 > dv2) {
676  cpl_mask_set(wdivXmask, i - 1, j, CPL_BINARY_1);
677  } else {
678  cpl_mask_set(wdivXmask, i, j, CPL_BINARY_1);
679  }
680  }
681  }
682  /* transfer the edited mask to the divided image for the smoothing */
683  cpl_image_reject_from_mask(wdiv2, wdivXmask);
684 
685  /* append to reconstructed images, before throwing away */
686  image = muse_image_new();
687  image->header = cpl_propertylist_new();
688  cpl_propertylist_append_string(image->header, "OBJECT",
689  "white-light divided by white global, mask excl edges");
690  cpl_propertylist_append_string(image->header, "BUNIT", "1"); /* unitless */
691  image->data = wdivX;
692  image->dq = cpl_image_new_from_mask(wdivXmask);
693  cpl_mask_delete(wdivXmask);
694  muse_imagelist_set(cubefit->recimages, image,
695  muse_imagelist_get_size(cubefit->recimages));
696  cpl_array_set_size(cubefit->recnames,
697  cpl_array_get_size(cubefit->recnames) + 1);
698  cpl_array_set_string(cubefit->recnames, cpl_array_get_size(cubefit->recnames) - 1,
699  "white_div_global_excl_edges");
700  } /* if vignmaskedges positive */
701 
702  /* do the smoothing in one of the several possible ways */
703  cpl_image *fit = NULL;
704  if (aParams->vignsmooth == MUSE_TWILIGHT_PARAM_VIGNSMOOTH_GAUSSIAN) {
705  /* possibly reset to defaults (see muse_twilight.xml) */
706  if (aParams->vignxpar < 0.) {
707  aParams->vignxpar = 10;
708  }
709  if (aParams->vignypar < 0.) {
710  aParams->vignypar = 10;
711  }
712  /* use Gaussian filter to smooth the vignetted area */
713  double fwhm = ((double)aParams->vignxpar + (double)aParams->vignypar) / 2.;
714  cpl_msg_info(__func__, "Running %.1f pix FWHM Gaussian filter...", fwhm);
715  fit = cpl_image_duplicate(wdiv2);
716  /* create odd halfwidth of about fwhm */
717  int hw = lround(fwhm);
718  hw = hw % 2 ? hw : hw + 1;
719  cpl_msg_debug(__func__, "using width 2 x %d + 1 for Gaussian matrix", hw);
720  cpl_matrix *gauss = muse_matrix_new_gaussian_2d(hw, hw,
721  fwhm * CPL_MATH_SIG_FWHM);
722  cpl_errorstate prestate = cpl_errorstate_get();
723  cpl_image_filter(fit, wdiv2, gauss, CPL_FILTER_LINEAR, CPL_BORDER_FILTER);
724  cpl_matrix_delete(gauss);
725  cpl_image_reject_from_mask(fit, cpl_image_get_bpm(wdiv2)); /* re-reject! */
726  if (isWFM) {
727  /* WFM had vignetting in lamp-flats, so valid values are > 1 */
728  cpl_image_threshold(fit, 1., FLT_MAX, 1., FLT_MAX);
729  } else {
730  /* NFM had vignetting in sky exposures, valid values are < 1 */
731  cpl_image_threshold(fit, -FLT_MAX, 1., -FLT_MAX, 1.);
732  }
733  if (!cpl_errorstate_is_equal(prestate)) {
734  cpl_msg_warning(__func__, "filtering vignetted area failed: %s",
735  cpl_error_get_message());
736  }
737  } else if (aParams->vignsmooth == MUSE_TWILIGHT_PARAM_VIGNSMOOTH_MEDIAN) {
738  /* possibly reset to defaults (see muse_twilight.xml) */
739  if (aParams->vignxpar < 0.) {
740  aParams->vignxpar = 5;
741  }
742  if (aParams->vignypar < 0.) {
743  aParams->vignypar = 5;
744  }
745  cpl_msg_info(__func__, "Running %dx%d median filter...",
746  aParams->vignxpar, aParams->vignypar);
747  fit = cpl_image_duplicate(wdiv2);
748  cpl_mask *mask = cpl_mask_new(aParams->vignxpar, aParams->vignypar);
749  cpl_mask_not(mask);
750  cpl_errorstate prestate = cpl_errorstate_get();
751  cpl_image_filter_mask(fit, wdiv2, mask, CPL_FILTER_MEDIAN,
752  CPL_BORDER_FILTER);
753  cpl_mask_delete(mask);
754  if (isWFM) {
755  /* again, replace values less than 1 */
756  cpl_image_threshold(fit, 1., FLT_MAX, 1., FLT_MAX);
757  } else {
758  cpl_image_threshold(fit, -FLT_MAX, 1., -FLT_MAX, 1.);
759  }
760  if (!cpl_errorstate_is_equal(prestate)) {
761  cpl_msg_warning(__func__, "filtering vignetted ared failed: %s",
762  cpl_error_get_message());
763  }
764  } else { /* MUSE_TWILIGHT_PARAM_VIGNSMOOTH_POLYFIT */
765  if (aParams->vignxpar < 0.) {
766  aParams->vignxpar = 4;
767  }
768  if (aParams->vignypar < 0.) {
769  aParams->vignypar = 4;
770  }
771  cpl_msg_info(__func__, "Running polyfit (orders %dx%d) ...",
772  aParams->vignxpar, aParams->vignypar);
773  /* since we want to correct only vignetting, everything in this image *
774  * should be one or above (for WFM) or one or below (for NFM), so *
775  * that we should unlikely values */
776  cpl_image *wdiv3 = cpl_image_duplicate(wdiv2);
777  if (isWFM) {
778  cpl_image_threshold(wdiv3, 1., FLT_MAX, 1., FLT_MAX);
779  } else {
780  cpl_image_threshold(wdiv3, -FLT_MAX, 1., -FLT_MAX, 1.);
781  }
782 
783  /* do the fit */
784  fit = muse_utils_image_fit_polynomial(wdiv3, aParams->vignxpar,
785  aParams->vignypar);
786  cpl_image_delete(wdiv3);
787  if (isWFM) {
788  cpl_image_threshold(fit, 1., FLT_MAX, 1., FLT_MAX);
789  } else {
790  cpl_image_threshold(fit, -FLT_MAX, 1., -FLT_MAX, 1.);
791  }
792  } /* else */
793 
794  if (isWFM) {
795  /* set the original rejection mask again */
796  cpl_image_reject_from_mask(fit, vignmask);
797  } else {
798  /* for NFM, reject using the originally created mask, but check *
799  * row levels before doing so: there might be a row below 1 at *
800  * the bottom of the fit region */
801  cpl_mask *mask = cpl_mask_duplicate(maskimage->mask);
802  /* the mask currently marks the non-vignetted area, so invert it */
803  cpl_mask_not(mask);
804  int j, nx = cpl_mask_get_size_x(mask),
805  ny = cpl_mask_get_size_y(mask);
806  double maxval = -DBL_MAX;
807  for (j = ny; j >= 1; j--) {
808  int nmasked = cpl_mask_count_window(mask, 1, j, nx, j);
809  if (nmasked <= 0) {
810  continue;
811  } /* if */
812  double avg = cpl_image_get_mean_window(fit, 1, j, nx, j),
813  stdev = cpl_image_get_stdev_window(fit, 1, j, nx, j),
814  median = cpl_image_get_median_window(fit, 1, j, nx, j);
815  cpl_msg_debug(__func__, "row %d (%d): %.5f +/- %.5f (%.5f)", j, nmasked,
816  avg, stdev, median);
817  if (maxval < avg) {
818  maxval = avg;
819  } /* if */
820  if (fabs(maxval - 1.) < 0.1 && avg < maxval) {
821  cpl_msg_debug(__func__, " (below max, removing from mask)");
822  int i;
823  for (i = 1; i <= nx; i++) {
824  cpl_mask_set(mask, i, j, CPL_BINARY_0);
825  } /* for i (all mask columns) */
826  } /* if */
827  } /* for j (all mask rows) */
828  /* now we again need the non-vignetted area, so invert it */
829  cpl_mask_not(mask);
830  cpl_image_reject_from_mask(fit, mask);
831  cpl_mask_delete(mask);
832  }
833  /* fill everything but the fitted area with ones, so that we *
834  * don't add rubbish when now dividing by this vignetting fix */
835  cpl_image_fill_rejected(fit, 1.);
836 
837  /* append to reconstructed images */
838  image = muse_image_new();
839  image->header = cpl_propertylist_new();
840  cpl_propertylist_append_string(image->header, "OBJECT", "vignetting fit");
841  /* no sensible unit for this image */
842  cpl_propertylist_append_string(image->header, "BUNIT", "");
843  image->data = fit;
844  image->dq = cpl_image_new_from_mask(cpl_image_get_bpm(fit));
845  muse_imagelist_set(cubefit->recimages, image,
846  muse_imagelist_get_size(cubefit->recimages));
847  cpl_array_set_size(cubefit->recnames,
848  cpl_array_get_size(cubefit->recnames) + 1);
849  cpl_array_set_string(cubefit->recnames, cpl_array_get_size(cubefit->recnames) - 1,
850  "vign_fit");
851 
852  /* divide by the result to assess how well it worked, and append to recimages */
853  image = muse_image_new();
854  image->header = cpl_propertylist_new();
855  cpl_propertylist_append_string(image->header, "OBJECT",
856  "white image corrected by vignetting fit");
857  /* unit again like white image */
858  cpl_propertylist_append_string(image->header, "BUNIT", "count");
859  image->data = cpl_image_divide_create(wdiv2, fit);
860  image->dq = cpl_image_new_from_mask(cpl_image_get_bpm(image->data));
861  muse_imagelist_set(cubefit->recimages, image,
862  muse_imagelist_get_size(cubefit->recimages));
863  cpl_array_set_size(cubefit->recnames,
864  cpl_array_get_size(cubefit->recnames) + 1);
865  cpl_array_set_string(cubefit->recnames, cpl_array_get_size(cubefit->recnames) - 1,
866  "white_cor");
867  cpl_image_delete(wdiv2);
868 
869  /* apply the vignetting fit on top of the twilight cube */
870  cpl_msg_info(__func__, "Combining smooth field of view and vignetted region"
871  " in %d planes", npl);
872  for (ipl = 0; ipl < npl; ipl++) {
873  cpl_image *cimage = cpl_imagelist_get(cubefit->data, ipl);
874  cpl_image_accept_all(cimage);
875  double mean1 = cpl_image_get_mean(cimage);
876  cpl_image_multiply(cimage, fit);
877  /* since the image multiplication merges the bad pixel masks, we need *
878  * to reset them again before computing the normalization factor */
879  cpl_image_accept_all(cimage);
880  double mean2 = cpl_image_get_mean(cimage);
881  cpl_image_multiply_scalar(cimage, 1. / mean2);
882  double mean3 = cpl_image_get_mean(cimage);
883  if (fabs(mean3 - 1.) > FLT_EPSILON) {
884  cpl_msg_warning(__func__, "normalization failed in plane %d: mean("
885  "plane) = %f -> %f -> %f", ipl + 1, mean1, mean2, mean3);
886  } /* if */
887  } /* for ipl (all cube image planes) */
888  cpl_mask_delete(vignmask);
889  } /* if maskimage */
890  cpl_mask_delete(fovmask);
891  muse_mask_delete(maskimage);
892 
893  rc = muse_processing_save_cube(aProcessing, -1, cubefit,
894  MUSE_TAG_TWILIGHT_CUBE,
896  muse_datacube_delete(cubefit);
897 
898  return rc == CPL_ERROR_NONE ? 0 : -1;
899 } /* muse_twilight_compute() */
double crsigma
Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative va...
muse_imagelist * muse_basicproc_load(muse_processing *aProcessing, unsigned char aIFU, muse_basicproc_params *aBPars)
Load the raw input files from disk and do basic processing.
Structure definition of a MUSE datacube.
Definition: muse_datacube.h:48
int vignnfmmask
The height of the vignetted region at the top of the MUSE field in NFM. This is the region modeled se...
Structure definition for a collection of muse_images.
void muse_image_delete(muse_image *aImage)
Deallocate memory associated to a muse_image object.
Definition: muse_image.c:85
unsigned char muse_utils_get_ifu(const cpl_propertylist *aHeaders)
Find out the IFU/channel from which this header originated.
Definition: muse_utils.c:98
cpl_image * data
the data extension
Definition: muse_image.h:46
cpl_size muse_pixtable_get_nrow(const muse_pixtable *aPixtable)
get the number of rows within the pixel table
void muse_mask_delete(muse_mask *aMask)
Deallocate memory associated to a muse_mask object.
Definition: muse_mask.c:78
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...
muse_resampling_crstats_type muse_postproc_get_cr_type(const char *aCRTypeString)
Select correct cosmic ray rejection type for crtype string.
muse_datacube * muse_resampling_cube(muse_pixtable *aPixtable, muse_resampling_params *aParams, muse_pixgrid **aGrid)
Resample a pixel table onto a regular grid structure representing a FITS NAXIS=3 datacube.
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.
const char * crtype_s
Type of statistics used for detection of cosmic rays during final resampling. "iraf" uses the varianc...
muse_basicproc_params * muse_basicproc_params_new(cpl_parameterlist *aParameters, const char *aPrefix)
Create a new structure of basic processing parameters.
muse_image * muse_combine_images(muse_combinepar *aCPars, muse_imagelist *aImages)
Combine several images into one.
Definition: muse_combine.c:741
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_table * table
The pixel table.
void muse_basicproc_params_delete(muse_basicproc_params *aBPars)
Free a structure of basic processing parameters.
cpl_propertylist * header
the FITS header
Definition: muse_image.h:72
#define MUSE_PIXTABLE_DATA
Definition: muse_pixtable.h:48
unsigned int muse_imagelist_get_size(muse_imagelist *aList)
Return the number of stored images.
cpl_frameset * usedframes
void muse_combinepar_delete(muse_combinepar *aCPars)
Clear the combination parameters.
Definition: muse_combine.c:715
muse_resampling_crstats_type crtype
cpl_image * dq
the data quality extension
Definition: muse_image.h:56
cpl_error_code muse_pixtable_restrict_wavelength(muse_pixtable *aPixtable, double aLow, double aHigh)
Restrict a pixel table to a certain wavelength range.
cpl_array * muse_cplarray_new_from_delimited_string(const char *aString, const char *aDelim)
Convert a delimited string into an array of strings.
Structure definition of MUSE pixel table.
cpl_error_code muse_datacube_convert_dq(muse_datacube *aCube)
Convert the DQ extension of a datacube to NANs in DATA and STAT.
muse_image * muse_imagelist_get(muse_imagelist *aList, unsigned int aIdx)
Get the muse_image of given list index.
int vignxpar
Parameter used by the vignetting smoothing: x order for polyfit (default, recommended 4)...
double vignmaskedges
Pixels on edges stronger than this fraction in the normalized image are excluded from the fit to the ...
int vignypar
Parameter used by the vignetting smoothing: y order for polyfit (default, recommended 4)...
muse_resampling_params * muse_resampling_params_new(muse_resampling_type aMethod)
Create the resampling parameters structure.
Structure to hold the parameters of the muse_twilight recipe.
cpl_error_code muse_processing_save_cube(muse_processing *aProcessing, int aIFU, void *aCube, const char *aTag, muse_cube_type aType)
Save a MUSE datacube to disk.
double dlambda
Sampling for twilight reconstruction, this should result in planes of equal wavelength coverage...
int vignsmooth
Type of smoothing to use for the vignetted region given by the VIGNETTING_MASK (for WFM...
muse_combinepar * muse_combinepar_new(cpl_parameterlist *aParameters, const char *aPrefix)
Create a new set of combination parameters.
Definition: muse_combine.c:672
double lambdamin
Minimum wavelength for twilight reconstruction.
cpl_imagelist * data
the cube containing the actual data values
Definition: muse_datacube.h:76
void muse_processing_append_used(muse_processing *aProcessing, cpl_frame *aFrame, cpl_frame_group aGroup, int aDuplicate)
Add a frame to the set of used frames.
int yorder
Polynomial order to use in y direction to fit the full field of view.
muse_mask * muse_processing_load_mask(muse_processing *aProcessing, const char *aTag)
Load a mask file and its FITS header.
int xorder
Polynomial order to use in x direction to fit the full field of view.
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_mask * muse_mask_new(void)
Allocate memory for a new muse object.
Definition: muse_mask.c:61
cpl_error_code muse_basicproc_stats_append_header(cpl_image *aImage, cpl_propertylist *aHeader, const char *aPrefix, unsigned aStats)
Compute image statistics of an image and add them to a header.
cpl_table * muse_basicproc_get_illum(muse_imagelist *aImages, cpl_table *aTrace, cpl_table *aWave, cpl_table *aGeo)
Get an illum/attached flat-field from an imagelist and prepare it for use.
cpl_propertylist * header
the FITS header
Definition: muse_datacube.h:57
cpl_table * muse_processing_load_ctable(muse_processing *aProcessing, const char *aTag, unsigned char aIFU)
Load a CPL table according to its tag and IFU/channel number.
muse_resampling_type muse_postproc_get_resampling_type(const char *aResampleString)
Select correct resampling type for resample string.
#define MUSE_PIXTABLE_STAT
Definition: muse_pixtable.h:50
cpl_image * muse_utils_image_fit_polynomial(const cpl_image *aImage, unsigned short aXOrder, unsigned short aYOrder)
Create a smooth version of a 2D image by fitting it with a 2D polynomial.
Definition: muse_utils.c:1147
Handling of "mask" files.
Definition: muse_mask.h:43
cpl_array * intags
muse_imagelist * muse_imagelist_new(void)
Create a new (empty) MUSE image list.
cpl_frameset * inframes
cpl_error_code muse_basicproc_mask_notch_filter(muse_pixtable *aPT, unsigned char aIFU)
Mask the range of the NaD notch filter in the given pixel table.
Structure of basic processing parameters.
muse_resampling_type
Resampling types.
cpl_propertylist * header
the FITS header
Definition: muse_mask.h:56
Resampling parameters.
void muse_resampling_params_delete(muse_resampling_params *aParams)
Delete a resampling parameters structure.
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
cpl_matrix * muse_matrix_new_gaussian_2d(int aXHalfwidth, int aYHalfwidth, double aSigma)
Create a matrix that contains a normalized 2D Gaussian.
Definition: muse_utils.c:1099
cpl_error_code muse_basicproc_apply_illum(muse_pixtable *aPT, cpl_table *aAttached)
Apply an illum/attached flat-field to a pixel table.
double lambdamax
Maximum wavelength for twilight reconstruction.
cpl_mask * mask
The mask data.
Definition: muse_mask.h:49
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
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.
int muse_quality_image_reject_using_dq(cpl_image *aData, cpl_image *aDQ, cpl_image *aStat)
Reject pixels of one or two images on a DQ image.
Definition: muse_quality.c:628
muse_ins_mode muse_pfits_get_mode(const cpl_propertylist *aHeaders)
find out the observation mode
Definition: muse_pfits.c:1352
muse_imagelist * recimages
the reconstructed image data
Definition: muse_datacube.h:64
cpl_mask * muse_cplmask_adapt_to_image(const cpl_mask *aMask, const cpl_image *aImage)
Adapt mask with masked region in one quadrant to size of an image.
cpl_parameterlist * parameters
cpl_imagelist * stat
the cube containing the data variance
Definition: muse_datacube.h:86
cpl_propertylist * header
The FITS header.
cpl_frameset * muse_frameset_find_tags(const cpl_frameset *aFrames, const cpl_array *aTags, unsigned char aIFU, cpl_boolean aInvert)
return frameset containing data from an IFU/channel with the given tag(s)
Definition: muse_utils.c:253
const char * resample_s
The resampling technique to use for the final output cube. (as string)