MUSE Pipeline Reference Manual  2.1.1
muse_scipost_correct_dar.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 #include <muse.h>
31 #include "muse_scipost_correct_dar_z.h"
32 
33 /*---------------------------------------------------------------------------*
34  * Functions code *
35  *---------------------------------------------------------------------------*/
36 
37 /*----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------*/
47 int
48 muse_scipost_correct_dar_compute(muse_processing *aProcessing,
50 {
51  cpl_frameset *inframes = muse_frameset_find_tags(aProcessing->inframes,
52  aProcessing->intags, 0,
53  CPL_FALSE);
54  cpl_error_code rc = CPL_ERROR_NONE;
55  cpl_size iframe, nframes = cpl_frameset_get_size(inframes);
56  for (iframe = 0; iframe < nframes; iframe++) {
57  cpl_frame *frame = cpl_frameset_get_position(inframes, iframe);
58  const char *fn = cpl_frame_get_filename(frame);
60  aParams->lambdamin,
61  aParams->lambdamax);
62  if (pixtable == NULL) {
63  cpl_msg_error(__func__, "NULL pixel table for %s", fn);
64  rc = CPL_ERROR_NULL_INPUT;
65  break;
66  }
67  muse_processing_append_used(aProcessing, frame, CPL_FRAME_GROUP_RAW, 1);
68 
69  /* erase pre-existing QC parameters */
70  cpl_propertylist_erase_regexp(pixtable->header, "ESO QC ", 0);
71  rc = muse_dar_correct(pixtable, aParams->lambdaref);
72  if (rc != CPL_ERROR_NONE) {
73  cpl_msg_error(__func__, "while muse_dar_correct(%s)",
74  cpl_frame_get_filename(frame));
75  muse_pixtable_delete(pixtable);
76  break;
77  }
78  /* check and possibly correct the DAR quality, if requested to do so */
79  if (aParams->darcheck != MUSE_SCIPOST_CORRECT_DAR_PARAM_DARCHECK_NONE) {
80  cpl_boolean dorefine = aParams->darcheck
81  == MUSE_SCIPOST_CORRECT_DAR_PARAM_DARCHECK_CORRECT;
82  cpl_msg_info(__func__, "Carrying out DAR %s", dorefine ? "correction" : "check");
83  double maxshift = 0;
84  rc = muse_dar_check(pixtable, &maxshift, dorefine, NULL);
85  if (rc != CPL_ERROR_NONE) {
86  cpl_msg_error(__func__, "Maximum detected shift %f\'\' (failure for "
87  "\"%s\"; rc = %d: %s)", maxshift,
88  cpl_frame_get_filename(frame), rc, cpl_error_get_message());
89  muse_pixtable_delete(pixtable);
90  break;
91  } else {
92  cpl_msg_info(__func__, "Maximum detected shift %f\'\'", maxshift);
93  }
94  } /* if DAR checking */
95  muse_processing_save_table(aProcessing, 0, pixtable, NULL,
96  MUSE_TAG_PIXTABLE_REDUCED,
98  muse_pixtable_delete(pixtable);
99  } /* for iframe (all input frames) */
100  cpl_frameset_delete(inframes);
101 
102  return rc;
103 } /* muse_scipost_correct_dar_compute() */
cpl_error_code muse_dar_correct(muse_pixtable *aPixtable, double aLambdaRef)
Correct the pixel coordinates of all pixels of a given pixel table for differential atmospheric refra...
Definition: muse_dar.c:139
cpl_error_code muse_dar_check(muse_pixtable *aPixtable, double *aMaxShift, cpl_boolean aCorrect, muse_datacube **aCube)
check that the continuum of objects in the frame is well-aligned perpendicular to the spatial axis...
Definition: muse_dar.c:472
Structure definition of MUSE pixel table.
double lambdaref
Reference wavelength used for correction of differential atmospheric refraction. The R-band (peak wav...
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 hold the parameters of the muse_scipost_correct_dar recipe.
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_array * intags
cpl_frameset * inframes
int darcheck
Carry out a check of the theoretical DAR correction using source centroiding. If "correct" it will al...
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
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 lambdamax
Cut off the data above 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