MUSE Pipeline Reference Manual  1.0.2
muse_scipost_combine_pixtables.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 <muse.h>
30 #include "muse_scipost_combine_pixtables_z.h"
31 
32 /*----------------------------------------------------------------------------*/
41 /*----------------------------------------------------------------------------*/
42 int
43 muse_scipost_combine_pixtables_compute(muse_processing *aProcessing,
45 {
46  /* setup and check weighting scheme */
48 
49  /* sort input pixel tables into different exposures */
50  cpl_table *exposures = muse_processing_sort_exposures(aProcessing);
51  if (!exposures) {
52  cpl_msg_error(__func__, "no science exposures found in input");
53  return -1;
54  }
55  int nexposures = cpl_table_get_nrow(exposures);
56 
57  /* now process all the pixel tables, do it separately for each exposure */
58  /* allocate one additional element for NULL termination */
59  muse_pixtable **pixtables = cpl_calloc(nexposures + 1, sizeof(muse_pixtable *));
60  int i;
61  for (i = 0; i < nexposures; i++) {
62  cpl_table *thisexp = cpl_table_extract(exposures, i, 1);
63  pixtables[i] = muse_pixtable_load_merge_channels(thisexp,
64  aParams->lambdamin,
65  aParams->lambdamax);
66  cpl_table_delete(thisexp);
67  /* erase pre-existing QC parameters */
68  cpl_propertylist_erase_regexp(pixtables[i]->header, "ESO QC ", 0);
69  }
70  cpl_table_delete(exposures);
71 
72  do { /* loop to break out of in case of error */
73  /* now combine the possibly more than one exposures */
74  muse_pixtable *bigpixtable = NULL;
75  if (nexposures > 1) {
76  cpl_error_code rc = muse_xcombine_weights(pixtables, weight);
77  if (rc != CPL_ERROR_NONE) {
78  cpl_msg_error(__func__, "weighting the pixel tables didn't work: %s",
79  cpl_error_get_message());
80  break;
81  }
82  /* combine individual pixel tables and delete them */
83  bigpixtable = muse_xcombine_tables(pixtables);
84  if (!bigpixtable) {
85  cpl_msg_error(__func__, "combining the pixel tables didn't work: %s",
86  cpl_error_get_message());
87  break;
88  }
89  } else {
90  bigpixtable = pixtables[0];
91  }
92  cpl_free(pixtables);
93 
94  muse_processing_save_table(aProcessing, -1, bigpixtable, NULL,
95  MUSE_TAG_PIXTABLE_COMBINED,
97  muse_pixtable_delete(bigpixtable);
98  return 0;
99  } while (0); /* end of "error-free" loop, error handling follows */
100  for (i = 0; i < nexposures; i++) {
101  muse_pixtable_delete(pixtables[i]);
102  } /* for i (exposures) */
103  cpl_free(pixtables);
104  return -1;
105 } /* muse_scipost_combine_pixtables_compute() */
Structure to hold the parameters of the muse_scipost_combine_pixtables recipe.
muse_xcombine_types muse_postproc_get_weight_type(const char *aWeightString)
Select correct weighting type for weight string.
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
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
const char * weight_s
Type of weighting scheme to use when combining multiple exposures. "exptime" just uses the exposure t...
Structure definition of MUSE pixel table.
double lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
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_pixtable * muse_xcombine_tables(muse_pixtable **aPixtables)
combine the pixel tables of several exposures into one
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.
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