VIRCAM Pipeline  2.3.12
casu_darkcor.c
1 /* $Id: casu_darkcor.c,v 1.2 2015/08/07 13:06:54 jim Exp $
2  *
3  * This file is part of the CASU Pipeline utilities
4  * Copyright (C) 2015 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: jim $
23  * $Date: 2015/08/07 13:06:54 $
24  * $Revision: 1.2 $
25  * $Name: $
26  */
27 
28 /* Includes */
29 
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 #include <cpl.h>
35 #include "casu_mods.h"
36 #include "catalogue/casu_utils.h"
37 #include "catalogue/casu_fits.h"
38 
41 /*---------------------------------------------------------------------------*/
84 /*---------------------------------------------------------------------------*/
85 
86 extern int casu_darkcor(casu_fits *infile, casu_fits *darksrc, float darkscl,
87  int *status) {
88  long n,i;
89  float *idata,*ddata;
90  cpl_image *im,*dm;
91  cpl_propertylist *oplist;
92  const char *fctid = "casu_darkcor";
93 
94  /* Inherited status */
95 
96  if (*status != CASU_OK)
97  return(*status);
98 
99  /* See if this file has already been done */
100 
101  oplist = casu_fits_get_ehu(infile);
102  if (cpl_propertylist_has(oplist,"ESO DRS DARKCOR"))
103  return(*status);
104 
105  /* Get the images and check the dimension to make sure they match */
106 
107  im = casu_fits_get_image(infile);
108  dm = casu_fits_get_image(darksrc);
109  if (casu_compare_dims(im,dm) != CASU_OK) {
110  cpl_msg_error(fctid,"Object and dark data array dimensions don't match");
111  FATAL_ERROR
112  }
113 
114  /* If the scale factor is 1, then just use the cpl image routine to do
115  the arithmetic */
116 
117  if (darkscl == 1.0) {
118  if (cpl_image_subtract(im,dm) != CPL_ERROR_NONE)
119  FATAL_ERROR
120 
121  /* Otherwise, do it by hand */
122 
123  } else {
124  idata = cpl_image_get_data_float(im);
125  ddata = cpl_image_get_data_float(dm);
126  if (idata == NULL || ddata == NULL)
127  FATAL_ERROR;
128  n = (long)cpl_image_get_size_x(im)*(long)cpl_image_get_size_y(im);
129  for (i = 0; i < n; i++)
130  idata[i] -= darkscl*ddata[i];
131  }
132 
133  /* Now put some stuff in the DRS extension... */
134 
135  oplist = casu_fits_get_ehu(infile);
136  if (oplist != NULL) {
137  if (casu_fits_get_fullname(darksrc) != NULL)
138  cpl_propertylist_update_string(oplist,"ESO DRS DARKCOR",
139  casu_fits_get_fullname(darksrc));
140  else
141  cpl_propertylist_update_string(oplist,"ESO DRS DARKCOR",
142  "Memory File");
143  cpl_propertylist_set_comment(oplist,"ESO DRS DARKCOR",
144  "Image used for dark correction");
145  cpl_propertylist_update_float(oplist,"ESO DRS DARKSCL",darkscl);
146  cpl_propertylist_set_comment(oplist,"ESO DRS DARKSCL",
147  "Scaling factor used in dark correction");
148  } else
149  WARN_RETURN
150 
151  /* Get out of here */
152 
153  GOOD_STATUS
154 }
155 
156 
159 /*
160 
161 $Log: casu_darkcor.c,v $
162 Revision 1.2 2015/08/07 13:06:54 jim
163 Fixed copyright to ESO
164 
165 Revision 1.1.1.1 2015/06/12 10:44:32 jim
166 Initial import
167 
168 Revision 1.3 2015/01/29 11:46:18 jim
169 modified comments
170 
171 Revision 1.2 2013/11/21 09:38:13 jim
172 detabbed
173 
174 Revision 1.1.1.1 2013-08-27 12:07:48 jim
175 Imported
176 
177 
178 */
cpl_image * casu_fits_get_image(casu_fits *p)
Definition: casu_fits.c:436
char * casu_fits_get_fullname(casu_fits *p)
Definition: casu_fits.c:680
cpl_propertylist * casu_fits_get_ehu(casu_fits *p)
Definition: casu_fits.c:576
int casu_darkcor(casu_fits *infile, casu_fits *darksrc, float darkscl, int *status)
Correct input data for dark current.
Definition: casu_darkcor.c:86
int casu_compare_dims(cpl_image *im1, cpl_image *im2)
Compare dimensions of two 2d images.
Definition: casu_utils.c:713