X-shooter Pipeline Reference Manual 3.8.15
test-xsh_create_master_bias.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_parameters.h>
49#include <xsh_dfs.h>
50#include <xsh_pfits.h>
51#include <tests.h>
52#include <cpl.h>
53#include <math.h>
54#include <string.h>
55
56/*---------------------------------------------------------------------------
57 Defines
58 ---------------------------------------------------------------------------*/
59#define MODULE_ID "XSH_CREATE_MASTER_BIAS"
60/*---------------------------------------------------------------------------
61 Functions prototypes
62 ---------------------------------------------------------------------------*/
63
64/*--------------------------------------------------------------------------*/
71/*--------------------------------------------------------------------------*/
72
73int main(void)
74{
76 cpl_frame* frame = NULL;
77 cpl_frame* med_frame = NULL;
78 cpl_frame* mbias = NULL;
79 cpl_frameset* set = NULL;
80 cpl_image* ima=NULL;
81 cpl_frame* product=NULL;
82 char* name=NULL;
83 cpl_propertylist* header=NULL;
84 float mean = 0.0,median = 0.0, stdev = 0.0;
85 xsh_clipping_param crh_clipping = {0.,4., 2, 0.7, 0};
86 xsh_hot_cold_pix_param hp_clip_param = {0, 3.0, 3, 3.0, 3};
87 xsh_fpn_param fpn_param = {-1,-1,-1,-1,4,10};
88 xsh_ron_param ron_param = {"ALL",
89 4,100,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,25};
90 xsh_struct_param struct_param = {-1,-1};
91 cpl_parameterlist* parameters=NULL;
92 xsh_stack_param stack_param = {"median",5.,5.};
93 const char* RECIPE_ID="xsh_mbias";
94 const char* ftag=NULL;
95 const int decode_bp=2147483647;
96
97 int nframes=5;
98 /* Initialize libraries */
101
102 /* Create valid instrument */
108
110
111 /* Create a frame and add it to frameset*/
112 set = cpl_frameset_new();
113 for(int i=0;i<nframes;i++) {
114 name=cpl_sprintf("frame%d.fits",i);
115 frame = xsh_test_create_frame(name,20,20,
116 XSH_BIAS_UVB,CPL_FRAME_GROUP_RAW, instrument);
117 cpl_frameset_insert(set,cpl_frame_duplicate(frame));
118 xsh_free_frame(&frame);
119 cpl_free(name);
120 }
121
122 /* Set generic parameters (common to all recipes) */
123 parameters = cpl_parameterlist_new();
124 check(xsh_parameters_generic( RECIPE_ID, parameters ));
125
126 /* crh clipping params */
128
129 check(xsh_parameters_hot_cold_pix_create(RECIPE_ID,parameters,hp_clip_param));
130
131
132 check(xsh_parameters_fpn_create(RECIPE_ID,parameters,fpn_param));
133 check(xsh_parameters_ron_create(RECIPE_ID,parameters,ron_param));
134 check(xsh_parameters_struct_create(RECIPE_ID,parameters,struct_param));
135
136
138
139 /* Create a PRE frame */
140 check(xsh_prepare(set,NULL, NULL, "PRE",instrument,0,CPL_FALSE));
141 /* Remove cosmics */
142 check (med_frame = xsh_remove_crh_multiple( set, "remove_crh",
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
150 name=cpl_strdup(cpl_frame_get_filename(product));
151 header=cpl_propertylist_load(name,0);
152 ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
153 xsh_free_frame(&product);
154 check(product=xsh_frame_product(name,ftag,
155 CPL_FRAME_TYPE_IMAGE,
156 CPL_FRAME_GROUP_PRODUCT,
157 CPL_FRAME_LEVEL_FINAL));
158 cpl_free(name);
159
160 /* Check the format of new frame */
161 /* check the header */
162 assure( strcmp(xsh_pfits_get_pcatg(header),"MASTER_BIAS_UVB")
163 == 0,CPL_ERROR_ILLEGAL_OUTPUT,"Wrong pcatg keyword");
164 /* QC parameters */
165 check(mean = xsh_pfits_get_qc_mbiasavg (header));
166 check(median = xsh_pfits_get_qc_mbiasmed(header));
167 check(stdev = xsh_pfits_get_qc_mbiasrms (header));
168
169 assure( mean - cpl_image_get_mean(ima) < XSH_FLOAT_PRECISION,
170 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong mean value in QC");
171 assure( median - cpl_image_get_median(ima) < XSH_FLOAT_PRECISION,
172 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong median value in QC");
173 assure( stdev - cpl_image_get_stdev(ima) < XSH_FLOAT_PRECISION,
174 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong rms value in QC");
175 xsh_msg("header is ok");
176
177 /* verify tag and group */
178 assure(cpl_frame_get_group(product) == CPL_FRAME_GROUP_PRODUCT,
179 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong group for MASTER BIAS frame");
180 assure(strcmp(cpl_frame_get_tag(product),XSH_MASTER_BIAS_UVB) == 0,
181 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong tag (%s) for MASTER BIAS frame ",
182 cpl_frame_get_tag(product));
183 xsh_msg("frame is ok");
184cleanup:
185 xsh_free_parameterlist(&parameters);
186 xsh_free_frame(&med_frame);
187 xsh_free_frame(&product);
188
189 xsh_free_propertylist(&header);
190 xsh_free_image(&ima);
191
192 xsh_free_frameset(&set);
193 xsh_free_frame(&mbias);
197 if (cpl_error_get_code() != CPL_ERROR_NONE) {
198 xsh_error_dump(CPL_MSG_ERROR);
199 return 1;
200 } else {
201 return 0;
202 }
203}
204
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.
static xsh_instrument * instrument
static xsh_clipping_param crh_clipping
int main(void)
Unit test of XSH_CREATE_MASTER.
#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
#define RECIPE_ID
Definition: xsh_2dmap.c:77
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_BIAS_UVB
Definition: xsh_dfs.h:394
#define XSH_MASTER_BIAS_UVB
Definition: xsh_dfs.h:681
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
Definition: xsh_dfs.h:1548
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)