MUSE Pipeline Reference Manual  1.0.2
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 
66  /* now process all the pixel tables, do it separately for each exposure */
67  /* allocate one additional element for NULL termination */
68  muse_pixtable **pixtables = cpl_calloc(nexposures + 1, sizeof(muse_pixtable *));
69  int i;
70  for (i = 0; i < nexposures; i++) {
71  cpl_table *thisexp = cpl_table_extract(exposures, i, 1);
72  pixtables[i] = muse_pixtable_load_merge_channels(thisexp,
73  aParams->lambdamin,
74  aParams->lambdamax);
75  cpl_table_delete(thisexp);
76  /* erase pre-existing QC parameters */
77  cpl_propertylist_erase_regexp(pixtables[i]->header, "ESO QC ", 0);
78  } /* for i (exposures) */
79  cpl_table_delete(exposures);
80 
81  do { /* loop to break out of in case of error */
82  /* now combine the exposures */
84  cpl_error_code rc = muse_xcombine_weights(pixtables, weight);
85  if (rc != CPL_ERROR_NONE) {
86  cpl_msg_error(__func__, "weighting the pixel tables didn't work: %s",
87  cpl_error_get_message());
88  break;
89  }
90  /* combine individual pixel tables and delete them */
91  muse_pixtable *bigpixtable = muse_xcombine_tables(pixtables);
92  if (!bigpixtable) {
93  cpl_msg_error(__func__, "combining the pixel tables didn't work: %s",
94  cpl_error_get_message());
95  break;
96  }
97  cpl_free(pixtables);
98 
99  if (strstr(aParams->save, "cube")) {
100  muse_resampling_type resample
103  rp->dx = aParams->dx;
104  rp->dy = aParams->dy;
105  rp->dlambda = aParams->dlambda;
106  rp->crtype = muse_postproc_get_cr_type(aParams->crtype_s);
107  rp->crsigma = aParams->crsigma;
108  rp->ld = aParams->ld;
109  rp->rc = aParams->rc;
110  rp->pfx = aParams->pixfrac;
111  rp->pfy = aParams->pixfrac;
112  rp->pfl = aParams->pixfrac;
113  cpl_propertylist *outwcs = muse_postproc_cube_load_output_wcs(aProcessing);
114  muse_resampling_params_set_wcs(rp, outwcs);
115  cpl_propertylist_delete(outwcs);
117  rc = muse_postproc_cube_resample_and_collapse(aProcessing, bigpixtable,
118  format, rp, aParams->filter);
120  } /* if save contains cube */
121  if (strstr(aParams->save, "combined")) {
122  muse_processing_save_table(aProcessing, -1, bigpixtable, NULL,
123  MUSE_TAG_PIXTABLE_COMBINED,
125  }
126  muse_pixtable_delete(bigpixtable);
127  return rc == CPL_ERROR_NONE ? 0 : -1;
128  } while (0); /* end of "error-free" loop, error handling follows */
129  for (i = 0; i < nexposures; i++) {
130  muse_pixtable_delete(pixtables[i]);
131  } /* for i (exposures) */
132  cpl_free(pixtables);
133  return -1;
134 } /* 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)
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 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
Definition: muse_xcombine.c:81
muse_resampling_crstats_type crtype
double dy
Vertical step size for resampling (in arcsec or pixel). The following defaults are taken when this va...
double pixfrac
Pixel down-scaling factor for the "drizzle" resampling method.
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_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 ...
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.
muse_pixtable * muse_xcombine_tables(muse_pixtable **aPixtables)
combine the pixel tables of several exposures into one
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