68#define MODULE_ID "XSH_REMOVE_CRH_MULTIPLE"
71#define CR_PIX_VALUE 32000.
87 {
"nimg", required_argument, 0,
NIMG_OPT},
88 {
"nbcr", required_argument, 0,
NBCR_OPT},
89 {
"size", required_argument, 0,
SIZE_OPT},
90 {
"bgmin", required_argument, 0,
BGMIN_OPT},
91 {
"bgmax", required_argument, 0,
BGMAX_OPT},
92 {
"sigma", required_argument, 0,
SIGMA_OPT},
93 {
"debug", required_argument, 0,
DEBUG_OPT},
115static void Help(
void ) ;
126 cpl_propertylist * header = NULL ;
127 cpl_frameset* result = NULL;
130 result = cpl_frameset_new() ;
137 cpl_image * image = NULL;
144 cpl_frame * frame = cpl_frame_new() ;
149 cpl_image_fill_noise_uniform ( image,
bgMin,
bgMax ) ;
154 for ( j=0 ; j<
nbCr ; j++ ) {
156 xsh_msg(
"CR at %d,%d [%d]", ix, iy, i ) ;
160 sprintf( iname,
"test_crh_%02d.fits", i ) ;
161 cpl_image_save(image, iname, CPL_BPP_IEEE_DOUBLE, header,
165 cpl_frame_set_filename( frame, iname ) ;
166 cpl_frame_set_tag( frame,
"BIAS_UVB" ) ;
167 cpl_frame_set_level( frame, CPL_FRAME_LEVEL_TEMPORARY);
168 cpl_frame_set_group( frame, CPL_FRAME_GROUP_RAW ) ;
170 cpl_frameset_insert( result, frame ) ;
186 xsh_msg(
"Entering VerifCr function" ) ;
191 assure( medframe != NULL, CPL_ERROR_ILLEGAL_INPUT,
192 "medFrame is NULL in call to verifCr" ) ;
196 "Cant load medframe" ) ;
203 xsh_msg(
"Nb of Cosmics found: %d - Should be %d", crcount,
totCr ) ;
206 if ( crcount ==
totCr ) ret = 1 ;
208 fname = cpl_frame_get_filename( medframe ) ;
209 xsh_msg(
" File name: %s", fname ) ;
211 int nbextensions = 0 ;
213 nbextensions = cpl_frame_get_nextensions(medframe );
214 assure(nbextensions == 2, CPL_ERROR_ILLEGAL_INPUT,
215 "Unrecognized format of file '%s'. No enough extensions. %d found.",
216 fname, nbextensions);
221 median = cpl_image_load( fname, CPL_TYPE_DOUBLE, 0, 0 ) ;
222 assure( median != NULL, cpl_error_get_code(),
223 "Cant load Median" ) ;
228 bpmap = cpl_image_load( fname, CPL_TYPE_INT, 0, 2 );
229 assure( bpmap != NULL, cpl_error_get_code(),
230 "Cant load Bpmap" ) ;
236 for( ix = 1 ; ix<=
imgSize ; ix++ )
237 for ( iy = 1 ; iy <=
imgSize ; iy++ ) {
238 double value = cpl_image_get( median, ix, iy, &rej ) ;
239 double bpval = cpl_image_get( bpmap, ix, iy, &rej ) ;
241 xsh_msg(
" Median[%d,%d] = %lf [REJECTED]", ix, iy, value ) ;
243 xsh_msg(
" Median[%d,%d] = %lf", ix, iy, value ) ;
247 xsh_msg(
"Nb of Bad pixels in BpMap: %d", crcount ) ;
260 puts(
"Unitary test of xsh_remove_crh_multiple" ) ;
261 puts(
"Usage: test_remove_crh [options]" ) ;
263 puts(
" --nbcr=<nn> : Number of Cosmic Rays (default 1)" ) ;
264 puts(
" --nimg=<nn> : Number of dark images (default 4)" ) ;
265 puts(
" --size=<n> test-xsh_remove_crh_multiple.c : Nb of pixels along the 2 axes (default 10)" ) ;
266 puts(
" --bgmin=<f> : Minimum value for background (default 80)" ) ;
267 puts(
" --bgmax=<f> : Maximum value for background (default 90)" ) ;
268 puts(
" --sigma=<f> : Sigma value for clipping (default 2.5)" ) ;
269 puts(
" --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
270 puts(
" --help : What you see" ) ;
279 int option_index = 0;
281 while (( opt = getopt_long (argc, argv,
"debug:help",
285 sscanf( optarg,
"%64d", &
nbCr ) ;
288 sscanf( optarg,
"%64d", &
nbImages ) ;
291 sscanf( optarg,
"%64d", &
imgSize ) ;
294 sscanf( optarg,
"%64lf", &
bgMin ) ;
297 sscanf( optarg,
"%64lf", &
bgMax ) ;
300 sscanf( optarg,
"%64lf", &
sigma ) ;
303 if ( strcmp( optarg,
"LOW")==0){
306 else if ( strcmp( optarg,
"HIGH")==0){
326int main(
int argc,
char **argv )
332 cpl_frame * medFrame = NULL ;
333 cpl_frameset *set = NULL;
334 cpl_frameset *raws = NULL;
335 cpl_frameset *calib = NULL;
338 const int decode_bp=2140143615;
342 cpl_msg_set_level(CPL_MSG_DEBUG);
353 if ( (argc-optind) >= 1 ) {
354 sprintf(sof_name,
"%s", argv[optind]);
356 xsh_msg(
"SOF name %s", sof_name);
379 "Error in createFakeFrames" ) ;
384 "Error in xsh_prepare" ) ;
386 strcpy( crh_tag,
"test_remove_crh" ) ;
391 crh_tag,&stack_param,NULL,
394 if ( (argc-optind) < 1 ) {
397 "Verification failed" ) ;
398 xsh_msg(
"Remove CRH Multiple OK" ) ;
409 if (cpl_error_get_code() != CPL_ERROR_NONE) {
int main()
Unit test of xsh_bspline_interpol.
static void HandleOptions(int argc, char **argv)
static int verifCr(cpl_frame *medframe)
static xsh_instrument * instrument
static struct option long_options[]
static xsh_clipping_param crh_clipping
static cpl_frameset * createFakeFrames(XSH_INSTRCONFIG *iconfig)
cpl_frameset * sof_to_frameset(const char *sof_name)
cpl_propertylist * mkHeader(XSH_INSTRCONFIG *iconfig, int nx, int ny, double exptime)
int xsh_bpmap_count(cpl_image *bpmap, int nx, int ny)
xsh_pre * xsh_pre_load(cpl_frame *frame, xsh_instrument *instr)
Load a xsh_pre structure from a frame.
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
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 ...
#define assure(CONDITION, ERROR_CODE,...)
#define xsh_error_dump(level)
#define check_msg(COMMAND,...)
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.
XSH_INSTRCONFIG * xsh_instrument_get_config(xsh_instrument *i)
Get the instrument default set of keywords.
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.
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_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
int xsh_debug_level_set(int level)
set debug level
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
#define TESTS_CLEAN_WORKSPACE(DRL_ID)
#define TESTS_INIT_WORKSPACE(DRL_ID)
#define TESTS_INIT(DRL_ID)
void xsh_dfs_split_in_group(cpl_frameset *input, cpl_frameset *raws, cpl_frameset *calib)
split input sof in groups: raw and calib
xsh_instrument * xsh_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset and return the instrument detected.
#define XSH_NEW_FRAMESET(POINTER)