X-shooter Pipeline Reference Manual 3.8.15
test-xsh_create_master_dark.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: 2013-01-31 08:05:57 $
23 * $Revision: 1.22 $
24 * $Name: not supported by cvs2svn $
25 */
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*--------------------------------------------------------------------------*/
36/*--------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------
40 Includes
41 ---------------------------------------------------------------------------*/
42
43
44#include <xsh_data_pre.h>
45#include <xsh_error.h>
46#include <xsh_msg.h>
47#include <xsh_data_instrument.h>
48#include <xsh_dfs.h>
49#include <xsh_pfits.h>
50#include <tests.h>
51#include <cpl.h>
52#include <math.h>
53#include <string.h>
54
55/*---------------------------------------------------------------------------
56 Defines
57 ---------------------------------------------------------------------------*/
58#define MODULE_ID "XSH_CREATE_MASTER_DARK"
59/*---------------------------------------------------------------------------
60 Functions prototypes
61 ---------------------------------------------------------------------------*/
62
63/*--------------------------------------------------------------------------*/
70/*--------------------------------------------------------------------------*/
71
72int main(void)
73{
75 cpl_frame* frame = NULL;
76 cpl_frame* med_frame = NULL;
77 cpl_frame* mbias = NULL;
78 cpl_frameset* set = NULL;
79 xsh_pre* pre = NULL;
80 float mean = 0.0,median = 0.0, stdev = 0.0;
81 xsh_clipping_param crh_clipping = {0.3, 4, 2, 0.7, 0};
82 xsh_hot_cold_pix_param hp_clip_param = {0, 3.0, 3, 3.0, 3};
83 xsh_fpn_param fpn_param = {1,1,9,9,4,10};
84 xsh_ron_param ron_param = {"ALL",
85 4,100,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,25};
86 xsh_struct_param struct_param = {-1,-1};
87 const char* MBIAS_RECIPE_ID="xsh_mbias";
88 cpl_parameterlist* parameters=NULL;
89 xsh_stack_param stack_param = {"median",5.,5.};
90 const char* ftag=NULL;
91 cpl_frame* product=NULL;
92 char* name=NULL;
93 cpl_propertylist* header=NULL;
94 cpl_image* ima=NULL;
95 int nframes=5;
96 const int decode_bp=2147483647;
97 /* Initialize libraries */
100
101 /* Create valid instrument */
107
109
110 /* Set generic parameters (common to all recipes) */
111 parameters = cpl_parameterlist_new();
112 check(xsh_parameters_generic( MBIAS_RECIPE_ID, parameters ));
113
114 /* crh clipping params */
115 check(xsh_parameters_clipping_crh_create(MBIAS_RECIPE_ID,parameters,crh_clipping));
116
117 check(xsh_parameters_hot_cold_pix_create(MBIAS_RECIPE_ID,parameters,hp_clip_param));
118
119
120 check(xsh_parameters_fpn_create(MBIAS_RECIPE_ID,parameters,fpn_param));
121 check(xsh_parameters_ron_create(MBIAS_RECIPE_ID,parameters,ron_param));
122 check(xsh_parameters_struct_create(MBIAS_RECIPE_ID,parameters,struct_param));
123
124
125 /* Create a frame and add it to frameset*/
126 /* Create a frame and add it to frameset*/
127 set = cpl_frameset_new();
128 for(int i=0;i<nframes;i++) {
129 name=cpl_sprintf("frame%d.fits",i);
130 frame = xsh_test_create_frame(name,20,20,
131 XSH_DARK_UVB,CPL_FRAME_GROUP_RAW, instrument);
132 cpl_frameset_insert(set,cpl_frame_duplicate(frame));
133 xsh_free_frame(&frame);
134 cpl_free(name);
135 }
136
138 /* Create a PRE frame */
139 check(xsh_prepare(set,NULL, NULL, "PRE",instrument,0,CPL_FALSE));
140
141 /* Remove cosmics */
142 check (med_frame = xsh_remove_crh_multiple( set, "remove_crh.fits",
143 &stack_param,NULL,
145 NULL,NULL,0 ));
146 /* Convert this frame in MASTER BIAS */
147 check(mbias = xsh_create_master_bias2(set,&stack_param,instrument,ftag,0));
148 check(product=xsh_compute_qc_on_master_bias(set,mbias,instrument,parameters));
149 name=cpl_strdup(cpl_frame_get_filename(product));
150 header=cpl_propertylist_load(name,0);
151 ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
152 xsh_free_frame(&product);
153 check(product=xsh_frame_product(name,ftag,
154 CPL_FRAME_TYPE_IMAGE,
155 CPL_FRAME_GROUP_PRODUCT,
156 CPL_FRAME_LEVEL_FINAL));
157 cpl_free(name);
158
159 /* Check the format of new frame */
160 //check(pre = xsh_pre_load(mbias,instrument));
161
162 /* check the header */
163 assure( strcmp(xsh_pfits_get_pcatg(header),"MASTER_BIAS_UVB")
164 == 0,CPL_ERROR_ILLEGAL_OUTPUT,"Wrong pcatg keyword");
165 /* QC parameters */
166 check(mean = xsh_pfits_get_qc_mbiasavg (header));
167 check(median = xsh_pfits_get_qc_mbiasmed(header));
168 check(stdev = xsh_pfits_get_qc_mbiasrms (header));
169
170 assure( mean - cpl_image_get_mean(ima) < XSH_FLOAT_PRECISION,
171 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong mean value in QC");
172 assure( median - cpl_image_get_median(ima) < XSH_FLOAT_PRECISION,
173 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong median value in QC");
174 assure( stdev - cpl_image_get_stdev(ima) < XSH_FLOAT_PRECISION,
175 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong rms value in QC");
176 xsh_msg("header is ok");
177
178 /* verify tag and group */
179 assure(cpl_frame_get_group(product) == CPL_FRAME_GROUP_PRODUCT,
180 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong group for MASTER BIAS frame");
181 assure(strcmp(cpl_frame_get_tag(product),XSH_MASTER_BIAS_UVB) == 0,
182 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong tag (%s) for MASTER BIAS frame ",
183 cpl_frame_get_tag(product));
184 xsh_msg("frame is ok");
185cleanup:
186 xsh_free_parameterlist(&parameters);
187 xsh_free_frame(&med_frame);
188 xsh_pre_free(&pre);
189 xsh_free_frameset(&set);
190 xsh_free_frame(&mbias);
191 xsh_free_frame(&product);
192 xsh_free_propertylist(&header);
193 xsh_free_image(&ima);
194
198 if (cpl_error_get_code() != CPL_ERROR_NONE) {
199 xsh_error_dump(CPL_MSG_ERROR);
200 return 1;
201 } else {
202 return 0;
203 }
204}
205
cpl_frame * xsh_compute_qc_on_master_bias(cpl_frameset *raws, cpl_frame *frame, xsh_instrument *instr, cpl_parameterlist *params)
Computes QC on a master bias frame.
cpl_frame * xsh_create_master_bias2(cpl_frameset *rawFrames, xsh_stack_param *stack_par, xsh_instrument *instr, const char *result_tag, const int method_code)
Creates master bias.
int main()
Unit test of xsh_bspline_interpol.
static xsh_instrument * instrument
static xsh_clipping_param crh_clipping
#define MODULE_ID
cpl_frame * xsh_test_create_frame(const char *name, int nx, int ny, const char *tag, cpl_frame_group group, xsh_instrument *instrument)
Definition: tests.c:119
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
Definition: xsh_data_pre.c:823
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 assure(CONDITION, ERROR_CODE,...)
Definition: xsh_error.h:54
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
void xsh_instrument_set_mode(xsh_instrument *i, XSH_MODE mode)
Set a mode on instrument structure.
void xsh_instrument_set_recipe_id(xsh_instrument *instrument, const char *recipe_id)
Set the recipe_id into the instrument structure.
void xsh_instrument_set_arm(xsh_instrument *i, XSH_ARM arm)
Set an arm on instrument structure.
void xsh_instrument_set_lamp(xsh_instrument *i, XSH_LAMP lamp)
Set a lamp on instrument structure.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
xsh_instrument * xsh_instrument_new(void)
create new instrument structure
void xsh_instrument_set_decode_bp(xsh_instrument *i, const int decode_bp)
Set bad pixel code.
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
const char * xsh_pfits_get_pcatg(const cpl_propertylist *plist)
find out the pcatg
Definition: xsh_pfits.c:1627
double xsh_pfits_get_qc_mbiasavg(const cpl_propertylist *plist)
find out the QC.MBIASAVG value
Definition: xsh_pfits_qc.c:114
double xsh_pfits_get_qc_mbiasrms(const cpl_propertylist *plist)
find out the QC.MBIASRMS value
Definition: xsh_pfits_qc.c:154
double xsh_pfits_get_qc_mbiasmed(const cpl_propertylist *plist)
find out the QC.MBIASMED value
Definition: xsh_pfits_qc.c:134
cpl_frame * xsh_remove_crh_multiple(cpl_frameset *rawFrames, const char *name, xsh_stack_param *stack_param, xsh_clipping_param *crh_clipping, xsh_instrument *inst, cpl_imagelist **, cpl_image **, const int save_tmp)
void xsh_free_parameterlist(cpl_parameterlist **p)
Deallocate a parameter list and set the pointer to NULL.
Definition: xsh_utils.c:2224
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
Definition: xsh_utils.c:2116
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
Definition: xsh_utils.c:2254
void xsh_free_temporary_files(void)
Free temprary files list.
Definition: xsh_utils.c:1451
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
#define TESTS_CLEAN_WORKSPACE(DRL_ID)
Definition: tests.h:139
#define TESTS_INIT_WORKSPACE(DRL_ID)
Definition: tests.h:133
#define XSH_FLOAT_PRECISION
Definition: tests.h:150
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_LAMP_QTH
@ XSH_ARM_UVB
@ XSH_MODE_IFU
cpl_frame * xsh_frame_product(const char *fname, const char *tag, cpl_frame_type type, cpl_frame_group group, cpl_frame_level level)
Creates a frame with given characteristics.
Definition: xsh_dfs.c:930
#define XSH_MASTER_BIAS
Definition: xsh_dfs.h:549
#define XSH_MASTER_BIAS_UVB
Definition: xsh_dfs.h:681
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
Definition: xsh_dfs.h:1548
#define XSH_DARK_UVB
Definition: xsh_dfs.h:398
void xsh_parameters_ron_create(const char *recipe_id, cpl_parameterlist *list, xsh_ron_param p)
create the RON determination parameters in a parameters list
void xsh_parameters_hot_cold_pix_create(const char *recipe_id, cpl_parameterlist *list, xsh_hot_cold_pix_param p)
create the crh clipping parameters in a parameters list
void xsh_parameters_clipping_crh_create(const char *recipe_id, cpl_parameterlist *list, xsh_clipping_param p)
create the crh clipping parameters in a parameters list
void xsh_parameters_fpn_create(const char *recipe_id, cpl_parameterlist *list, xsh_fpn_param p)
create the FPN parameters in a parameters list
void xsh_parameters_struct_create(const char *recipe_id, cpl_parameterlist *list, xsh_struct_param p)
create the structX/Y region definition parameters in a parameters list
void xsh_parameters_generic(const char *recipe_id, cpl_parameterlist *plist)