MUSE Pipeline Reference Manual  2.1.1
muse_exp_combine.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-2014 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_exp_combine_z.h"
33 
34 /*---------------------------------------------------------------------------*
35  * Functions code *
36  *---------------------------------------------------------------------------*/
37 
38 /*----------------------------------------------------------------------------*/
47 /*----------------------------------------------------------------------------*/
48 int
49 muse_exp_combine_compute(muse_processing *aProcessing,
51 {
52  /* sort input pixel tables into different exposures */
53  cpl_table *exposures = muse_processing_sort_exposures(aProcessing);
54  int nexposures = cpl_table_get_nrow(exposures);
55  if (nexposures < 2) {
56  cpl_msg_error(__func__, "This recipe only makes sense with multiple "
57  "exposures!");
58  cpl_table_delete(exposures);
59  return -1;
60  }
61  const char *savevalid = "cube,combined";
62  if (!muse_postproc_check_save_param(aParams->save, savevalid)) {
63  return -1;
64  }
65  /* load the optional offsets table */
66  cpl_table *offsets = muse_processing_load_ctable(aProcessing, MUSE_TAG_OFFSET_LIST, 0);
67  if (offsets && muse_cpltable_check(offsets, muse_offset_list_def) != CPL_ERROR_NONE) {
68  cpl_msg_warning(__func__, "Input %s has unexpected format, proceeding "
69  "without offset and flux scales!", MUSE_TAG_OFFSET_LIST);
70  cpl_table_delete(offsets);
71  offsets = NULL;
72  } /* if offsets have wrong format */
73 
74  /* now process all the pixel tables, do it separately for each exposure */
75  /* allocate one additional element for NULL termination */
76  muse_pixtable **pixtables = cpl_calloc(nexposures + 1, sizeof(muse_pixtable *));
77  int i;
78  for (i = 0; i < nexposures; i++) {
79  cpl_table *thisexp = cpl_table_extract(exposures, i, 1);
80  pixtables[i] = muse_pixtable_load_merge_channels(thisexp,
81  aParams->lambdamin,
82  aParams->lambdamax);
83  cpl_table_delete(thisexp);
84  if (pixtables[i]) {
85  /* erase pre-existing QC parameters */
86  cpl_propertylist_erase_regexp(pixtables[i]->header, "ESO QC ", 0);
87  } /* if */
88  } /* for i (exposures) */
89  cpl_table_delete(exposures);
90 
91  do { /* loop to break out of in case of error */
92  /* now combine the exposures */
94  cpl_error_code rc = muse_xcombine_weights(pixtables, weight);
95  if (rc != CPL_ERROR_NONE) {
96  cpl_msg_error(__func__, "weighting the pixel tables didn't work: %s",
97  cpl_error_get_message());
98  break;
99  }
100  /* combine individual pixel tables and delete them */
101  muse_pixtable *bigpixtable = muse_xcombine_tables(pixtables, offsets);
102  if (!bigpixtable) {
103  cpl_msg_error(__func__, "combining the pixel tables didn't work: %s",
104  cpl_error_get_message());
105  break;
106  }
107  cpl_free(pixtables);
108 
109  if (strstr(aParams->save, "cube")) {
110  muse_resampling_type resample
113  rp->dx = aParams->dx;
114  rp->dy = aParams->dy;
115  rp->dlambda = aParams->dlambda;
116  rp->crtype = muse_postproc_get_cr_type(aParams->crtype_s);
117  rp->crsigma = aParams->crsigma;
118  rp->ld = aParams->ld;
119  rp->rc = aParams->rc;
121  cpl_propertylist *outwcs = muse_postproc_cube_load_output_wcs(aProcessing);
122  muse_resampling_params_set_wcs(rp, outwcs);
123  cpl_propertylist_delete(outwcs);
125  rc = muse_postproc_cube_resample_and_collapse(aProcessing, bigpixtable,
126  format, rp, aParams->filter);
128  } /* if save contains cube */
129  if (strstr(aParams->save, "combined")) {
130  muse_processing_save_table(aProcessing, -1, bigpixtable, NULL,
131  MUSE_TAG_PIXTABLE_COMBINED,
133  }
134  muse_pixtable_delete(bigpixtable);
135  cpl_table_delete(offsets);
136  return rc == CPL_ERROR_NONE ? 0 : -1;
137  } while (0); /* end of "error-free" loop, error handling follows */
138  for (i = 0; i < nexposures; i++) {
139  muse_pixtable_delete(pixtables[i]);
140  } /* for i (exposures) */
141  cpl_free(pixtables);
142  cpl_table_delete(offsets);
143  return -1;
144 } /* muse_exp_combine_compute() */
cpl_propertylist * muse_postproc_cube_load_output_wcs(muse_processing *aProcessing)
Find a file with a usable output WCS in the input frameset.
int ld
Number of adjacent pixels to take into account during resampling in all three directions (loop distan...
const char * crtype_s
Type of statistics used for detection of cosmic rays during final resampling. "iraf" uses the varianc...
cpl_error_code muse_resampling_params_set_wcs(muse_resampling_params *aParams, const cpl_propertylist *aWCS)
Set an output WCS (and wavelength scale) in the resampling parameters.
muse_xcombine_types muse_postproc_get_weight_type(const char *aWeightString)
Select correct weighting type for weight string.
const char * resample_s
The resampling technique to use for the final output cube. (as string)
const char * pixfrac
Pixel down-scaling factor for the "drizzle" resampling method. Up to three, comma-separated, floating-point values can be given. If only one value is given, it applies to all dimensions, two values are interpreted as spatial and spectral direction, respectively, while three are taken as horizontal, vertical, and spectral.
muse_resampling_crstats_type muse_postproc_get_cr_type(const char *aCRTypeString)
Select correct cosmic ray rejection type for crtype string.
double crsigma
Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative va...
const muse_cpltable_def muse_offset_list_def[]
const char * format_s
Type of output file format, "Cube" is a standard FITS cube with NAXIS=3 and multiple extensions (for ...
cpl_error_code muse_postproc_cube_resample_and_collapse(muse_processing *aProcessing, muse_pixtable *aPixtable, muse_cube_type aFormat, muse_resampling_params *aParams, const char *aFilter)
High level function to resample to a datacube and collapse that to an image of the field of view and ...
cpl_error_code muse_xcombine_weights(muse_pixtable **aPixtables, muse_xcombine_types aWeighting)
compute the weights for combination of two or more exposures
cpl_error_code muse_cpltable_check(const cpl_table *aTable, const muse_cpltable_def *aDef)
Check whether the table contains the fields of the definition.
muse_resampling_crstats_type crtype
double dy
Vertical step size for resampling (in arcsec or pixel). The following defaults are taken when this va...
Structure definition of MUSE pixel table.
Structure to hold the parameters of the muse_exp_combine recipe.
muse_cube_type muse_postproc_get_cube_format(const char *aFormatString)
Select correct cube format for format string.
cpl_boolean muse_postproc_check_save_param(const char *aSave, const char *aValid)
Check the –save parameter contents against allowed options.
const char * weight_s
Type of weighting scheme to use when combining multiple exposures. "exptime" just uses the exposure t...
muse_resampling_params * muse_resampling_params_new(muse_resampling_type aMethod)
Create the resampling parameters structure.
double lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
const char * filter
The filter name(s) to be used for the output field-of-view image. Each name has to correspond to an E...
muse_pixtable * muse_xcombine_tables(muse_pixtable **aPixtables, const cpl_table *aOffsets)
combine the pixel tables of several exposures into one
muse_cube_type
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
const char * save
Select output product(s) to save. Can contain one or more of "cube" (output cube and associated image...
double dlambda
Wavelength step size (in Angstrom). Natural instrument sampling is used, if this is 0...
double dx
Horizontal step size for resampling (in arcsec or pixel). The following defaults are taken when this ...
cpl_error_code muse_resampling_params_set_pixfrac(muse_resampling_params *aParams, const char *aString)
Set resampling pixfrac given a string that can contain up to three floating-point values...
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_pixtable * muse_pixtable_load_merge_channels(cpl_table *aExposureList, double aLambdaMin, double aLambdaMax)
Load and merge the pixel tables of the 24 MUSE sub-fields.
muse_resampling_type muse_postproc_get_resampling_type(const char *aResampleString)
Select correct resampling type for resample string.
double rc
Critical radius for the "renka" resampling method.
cpl_error_code muse_processing_save_table(muse_processing *aProcessing, int aIFU, void *aTable, cpl_propertylist *aHeader, const char *aTag, muse_table_type aType)
Save a computed table to disk.
muse_resampling_type
Resampling types.
Resampling parameters.
void muse_resampling_params_delete(muse_resampling_params *aParams)
Delete a resampling parameters structure.
cpl_table * muse_processing_sort_exposures(muse_processing *aProcessing)
Sort input frames (containing lists of pixel table filenames) into different exposures.
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
muse_xcombine_types
Xposure combination types.
Definition: muse_xcombine.h:44