X-shooter Pipeline Reference Manual 3.8.15
xsh_prepare.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 European Southern Observatory *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18 * */
19
20/*
21 * $Author: amodigli $
22 * $Date: 2012-04-26 14:11:42 $
23 * $Revision: 1.45 $
24 * $Name: not supported by cvs2svn $
25 */
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
43/*----------------------------------------------------------------------------
44 Includes
45 ----------------------------------------------------------------------------*/
46
47#include <xsh_drl.h>
48#include <xsh_data_pre.h>
49#include <xsh_data_instrument.h>
50#include <xsh_dfs.h>
51#include <xsh_pfits.h>
52#include <xsh_error.h>
53#include <xsh_msg.h>
54#include <cpl.h>
55
56/*----------------------------------------------------------------------------
57 Typedefs
58 ---------------------------------------------------------------------------*/
59
60/*----------------------------------------------------------------------------
61 Functions prototypes
62 ---------------------------------------------------------------------------*/
63
64
65/*----------------------------------------------------------------------------
66 Implementation
67 ---------------------------------------------------------------------------*/
68
80cpl_frame*
81xsh_bpmap_2pre(cpl_frame* bpmap,const char* prefix, xsh_instrument* inst)
82{
83 cpl_frame* result=NULL;
84 xsh_pre* pre=NULL;
85 char* tag=NULL;
86 char* name=NULL;
87
88 pre= xsh_pre_create(bpmap,NULL,NULL,inst,0,false);
89 tag=cpl_sprintf("%s_%s",prefix,xsh_instrument_arm_tostring(inst));
90 name=cpl_sprintf("%s.fits",tag);
91
92 if(strstr(tag,XSH_BP_MAP_NL)!=NULL) {
94 }
95 result=xsh_pre_save(pre,name,tag,1 );
96
97 xsh_pre_free(&pre);
98 XSH_FREE(tag);
99 XSH_FREE(name);
100 return result;
101}
102/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
122void xsh_prepare( cpl_frameset* frames, cpl_frame * bpmap,
123 cpl_frame* mbias, const char* prefix, xsh_instrument* instr,
124 const int pre_overscan_corr,const bool flag_neg_and_thresh_pix)
125{
126 xsh_pre* pre = NULL;
127 cpl_frame *current = NULL;
128 cpl_frame* product = NULL;
129 xsh_pre* bias = NULL;
130 cpl_image* bias_data = NULL;
131 char result_name[256];
132 char result_tag[256];
133 int i,size;
134
135 /* check input parameters */
136 XSH_ASSURE_NOT_NULL( frames);
137 XSH_ASSURE_NOT_NULL( prefix);
138 XSH_ASSURE_NOT_NULL( instr);
139
140 check( size = cpl_frameset_get_size( frames) );
141
142 // Special for unitary tests (without master bias frame)
143 if ( mbias == (cpl_frame *)-1 ) {
144 bias_data = (cpl_image *)-1 ;
145 }
146 else if ( mbias != NULL ) {
147 /* load data */
148 check( bias = xsh_pre_load( mbias, instr));
149 check( bias_data = xsh_pre_get_data( bias));
150 } else if ( mbias == NULL ) {
151 bias_data = (cpl_image *)-1 ;
152 }
153 for( i=0; i<size; i++ ) {
154
155 check( current = cpl_frameset_get_frame( frames, i));
156
157 xsh_msg_dbg_medium("Load frame %s", cpl_frame_get_filename( current));
158
159 check( pre = xsh_pre_create( current, bpmap, bias_data, instr,
160 pre_overscan_corr,flag_neg_and_thresh_pix));
161
162 /* save result */
163 if(strcmp(prefix,XSH_FLAT)==0) {
165 sprintf( result_name, "%s_QTH_PRE_%d.fits", prefix, i);
166 } else if(xsh_instrument_get_lamp(instr)==XSH_LAMP_D2) {
167 sprintf( result_name, "%s_D2_PRE_%d.fits", prefix, i);
168 } else {
169 sprintf( result_name, "%s_PRE_%d.fits", prefix, i);
170 }
171 } else {
172 sprintf( result_name, "%s_PRE_%d.fits", prefix, i);
173 }
174 sprintf( result_tag, "%s_PRE_%d", prefix, i);
175 xsh_msg_dbg_medium( "Save frame %s", result_name);
176
177 check( product = xsh_pre_save( pre, result_name,result_tag,1 ));
178 xsh_pre_free( &pre);
179 /* update the frame */
180 check( cpl_frame_set_filename( current,
181 cpl_frame_get_filename( product) ) );
182 check( cpl_frame_set_type( current,
183 cpl_frame_get_type( product)));
184 check( cpl_frame_set_level( current,
185 cpl_frame_get_level( product)));
186 xsh_free_frame( &product);
187 }
188
189 cleanup:
190 if( cpl_error_get_code() != CPL_ERROR_NONE) {
191 xsh_pre_free( &pre);
192 xsh_free_frame( &product);
193 }
194 xsh_pre_free( &bias);
195 return;
196}
197
198/*---------------------------------------------------------------------------*/
220/*---------------------------------------------------------------------------*/
221cpl_frame * xsh_preframe_extract( cpl_frame* frame, int xmin, int ymin,
222 int xmax, int ymax, const char* name, xsh_instrument *instr)
223{
224 xsh_pre *pre = NULL;
225 cpl_frame *result = NULL;
226 const char* tag = NULL;
227
228 /* check input parameters */
229 XSH_ASSURE_NOT_NULL( frame);
230 XSH_ASSURE_NOT_NULL( name);
231 XSH_ASSURE_NOT_NULL( instr);
232
233 check( tag = cpl_frame_get_tag( frame));
234 check( pre = xsh_pre_load( frame, instr));
235 check( xsh_pre_extract( pre, xmin , ymin, xmax, ymax));
236 check( result = xsh_pre_save( pre, name, tag, 1));
237 check( cpl_frame_set_tag( result, tag));
238
239 cleanup:
240 if( cpl_error_get_code() != CPL_ERROR_NONE) {
241 xsh_free_frame( &result);
242 }
243 xsh_pre_free( &pre);
244 return result;
245}
void xsh_bpmap_bitwise_to_flag(cpl_image *bpmap, int flag)
cpl_image * xsh_pre_get_data(xsh_pre *pre)
Get data.
xsh_pre * xsh_pre_load(cpl_frame *frame, xsh_instrument *instr)
Load a xsh_pre structure from a frame.
Definition: xsh_data_pre.c:849
void xsh_pre_extract(xsh_pre *pre, int xmin, int ymin, int xmax, int ymax)
Create a sub pre image.
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
Definition: xsh_data_pre.c:823
xsh_pre * xsh_pre_create(cpl_frame *raw, cpl_frame *bpmap, cpl_image *bias_data, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
Create a XSH_PRE from a raw frame.
Definition: xsh_data_pre.c:450
cpl_frame * xsh_pre_save(const xsh_pre *pre, const char *filename, const char *tag, int temp)
Save PRE on disk.
cpl_frame * xsh_preframe_extract(cpl_frame *frame, int xmin, int ymin, int xmax, int ymax, const char *name, xsh_instrument *instr)
This function create a sub frame from PRE frame. the sub frame is described by a box.
Definition: xsh_prepare.c:221
cpl_frame * xsh_bpmap_2pre(cpl_frame *bpmap, const char *prefix, xsh_instrument *inst)
This function transform a BP map from raw to pre format.
Definition: xsh_prepare.c:81
void xsh_prepare(cpl_frameset *frames, cpl_frame *bpmap, cpl_frame *mbias, const char *prefix, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
This function transform RAW frames dataset in PRE frames dataset attaching the default bad pixel map ...
Definition: xsh_prepare.c:122
#define check(COMMAND)
Definition: xsh_error.h:71
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
XSH_LAMP xsh_instrument_get_lamp(xsh_instrument *i)
Get a lamp on instrument structure.
int size
#define xsh_msg_dbg_medium(...)
Definition: xsh_msg.h:44
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
cpl_image * data
Definition: xsh_data_pre.h:65
#define QFLAG_NON_LINEAR_PIXEL
@ XSH_LAMP_D2
@ XSH_LAMP_QTH
#define XSH_FLAT
Definition: xsh_dfs.h:222
#define XSH_BP_MAP_NL
Definition: xsh_dfs.h:360
#define XSH_FREE(POINTER)
Definition: xsh_utils.h:92