MUSE Pipeline Reference Manual  2.1.1
muse_scipost_calibrate_flux.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 
30 #include <muse.h>
31 #include "muse_scipost_calibrate_flux_z.h"
32 
33 /*---------------------------------------------------------------------------*
34  * Functions code *
35  *---------------------------------------------------------------------------*/
36 
37 /*----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------*/
47 int
48 muse_scipost_calibrate_flux_compute(muse_processing *aProcessing,
50 {
51  UNUSED_ARGUMENT(aParams); /* this recipe doesn't have parameters */
52 
53  muse_table *response = muse_processing_load_table(aProcessing,
54  MUSE_TAG_STD_RESPONSE, 0),
55  *telluric = muse_processing_load_table(aProcessing,
56  MUSE_TAG_STD_TELLURIC, 0);
57  cpl_table *extinction = muse_processing_load_ctable(aProcessing,
58  MUSE_TAG_EXTINCT_TABLE, 0);
59 
60  cpl_frameset *inframes = muse_frameset_find_tags(aProcessing->inframes,
61  aProcessing->intags, 0,
62  CPL_FALSE);
63  cpl_error_code rc = CPL_ERROR_NONE;
64  cpl_size iframe, nframes = cpl_frameset_get_size(inframes);
65  for (iframe = 0; iframe < nframes; iframe++) {
66  cpl_frame *frame = cpl_frameset_get_position(inframes, iframe);
67  const char *fn = cpl_frame_get_filename(frame);
69  aParams->lambdamin,
70  aParams->lambdamax);
71  if (pixtable == NULL) {
72  cpl_msg_error(__func__, "NULL pixel table for %s", fn);
73  rc = CPL_ERROR_NULL_INPUT;
74  break;
75  }
76  muse_processing_append_used(aProcessing, frame, CPL_FRAME_GROUP_RAW, 1);
77  /* erase pre-existing QC parameters */
78  cpl_propertylist_erase_regexp(pixtable->header, "ESO QC ", 0);
79  /* See if we need to revert the flat-field spectrum correction, *
80  * to match pixel table and response curve, before applying it. */
81  muse_postproc_revert_ffspec_maybe(pixtable, response);
82  rc = muse_flux_calibrate(pixtable, response, extinction, telluric);
83  if (rc != CPL_ERROR_NONE) {
84  cpl_msg_error(__func__, "while muse_flux_calibrate(%s)",
85  cpl_frame_get_filename(frame));
86  muse_pixtable_delete(pixtable);
87  break;
88  }
89  muse_processing_save_table(aProcessing, 0, pixtable, NULL,
90  MUSE_TAG_PIXTABLE_REDUCED,
92  muse_pixtable_delete(pixtable);
93  } /* for iframe (all input frames) */
94  cpl_frameset_delete(inframes);
95 
96  muse_table_delete(response);
97  muse_table_delete(telluric);
98  cpl_table_delete(extinction);
99 
100  return rc;
101 } /* muse_scipost_calibrate_flux_compute() */
cpl_error_code muse_postproc_revert_ffspec_maybe(muse_pixtable *aPt, const muse_table *aResponse)
Revert correction of on-sky data with the flat-field spectrum.
double lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
cpl_error_code muse_flux_calibrate(muse_pixtable *aPixtable, const muse_table *aResponse, const cpl_table *aExtinction, const muse_table *aTelluric)
Convert the input pixel table from counts to fluxes.
Definition: muse_flux.c:3083
Structure definition of MUSE pixel table.
muse_table * muse_processing_load_table(muse_processing *aProcessing, const char *aTag, unsigned char aIFU)
Load a MUSE table according to its tag and IFU/channel number.
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.
Structure to store a table together with a property list.
Definition: muse_table.h:43
void muse_table_delete(muse_table *aTable)
Deallocate memory associated to a muse_table object.
Definition: muse_table.c:80
muse_pixtable * muse_pixtable_load_restricted_wavelength(const char *aFilename, double aLambdaMin, double aLambdaMax)
Load a pixel table from file and cut down the wavelength range.
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.
cpl_array * intags
cpl_frameset * inframes
Structure to hold the parameters of the muse_scipost_calibrate_flux recipe.
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.
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
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