X-shooter Pipeline Reference Manual 3.8.15
test-xsh_subtract_background.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-08-16 11:45:53 $
23 * $Revision: 1.13 $
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#include <xsh_data_instrument.h>
44#include <xsh_pfits.h>
45#include <xsh_msg.h>
46#include <xsh_utils.h>
47#include <tests.h>
48#include <cpl.h>
49#include <math.h>
50
51#include <getopt.h>
52/*---------------------------------------------------------------------------
53 Defines
54 ---------------------------------------------------------------------------*/
55#define MODULE_ID "XSH_SUBTRACT_BACKGROUND"
56
57
58enum {
61};
62
63static const char * Options = "" ;
64
65static struct option long_options[] = {
66 {"nb-y", required_argument, 0, NB_Y_OPT},
67 {"radius-x", required_argument, 0, RADIUS_X_OPT},
68 {"radius-y", required_argument, 0, RADIUS_Y_OPT},
69 {"help", 0, 0, HELP_OPT},
70 {0, 0, 0, 0}
71};
72
73
74
75static void Help( void )
76{
77 puts( "Unitary test of xsh_subtract_background" ) ;
78 puts( "Usage: test_xsh_subtract_background [options] <input_files>" ) ;
79 puts( "Options" ) ;
80 puts( " --nb-y=<n> : Number of points of the grid in y direction" ) ;
81 puts( " --radius-x=<n> : Half size of the subwindow in x direction" ) ;
82 puts( " --radius-y=<n> : Half size of the subwindow in y direction" ) ;
83 puts( " --help : What you see" ) ;
84 puts( "\nInput Files" ) ;
85 puts( "The input files argument MUST be in this order:" ) ;
86 puts( " 1. Science frame in PRE format" ) ;
87 puts( " 2. SOF [ORDER_TAB_EDGES]\n" ) ;
88 TEST_END();
89}
90
91static void HandleOptions( int argc, char **argv,
92 xsh_background_param *backg_par)
93{
94 int opt ;
95 int option_index = 0;
96
97
98 while (( opt = getopt_long (argc, argv, Options,
99 long_options, &option_index)) != EOF ){
100 switch ( opt ) {
101 case NB_Y_OPT:
102 backg_par->sampley = atoi( optarg);
103 break;
104 case RADIUS_X_OPT:
105 backg_par->radius_x = atoi( optarg);
106 break;
107 case RADIUS_Y_OPT:
108 backg_par->radius_y = atoi( optarg);
109 break;
110 default: Help() ; exit( 0 ) ;
111 }
112 }
113}
114/*---------------------------------------------------------------------------
115 Functions prototypes
116 ---------------------------------------------------------------------------*/
117
118/*--------------------------------------------------------------------------*/
125/*--------------------------------------------------------------------------*/
126
127int main( int argc, char **argv)
128{
129 int ret = 0;
130
132
133 const char *sof_name = NULL;
134 cpl_frameset *set = NULL;
135 const char * sci_name = NULL ;
136
137 cpl_frame* flat_frame = NULL;
138 cpl_frame* flat_rmbckg = NULL;
139 cpl_frame* guess_order_tab_frame = NULL;
140
142 cpl_frame* frame_grid=NULL;
143 cpl_frame* frame_back=NULL;
144
145
147 cpl_msg_set_level(CPL_MSG_DEBUG);
149
150 backg.sampley = 800;
151 backg.radius_x = 2;
152 backg.radius_y = 2;
153 backg.debug = CPL_TRUE;
154
155 HandleOptions( argc, argv, &backg);
156
157 if ( (argc - optind) >=2 ) {
158 sci_name = argv[optind];
159 sof_name = argv[optind+1];
160 }
161 else {
162 Help();
163 exit(0);
164 }
165
166 /* Create frameset from sof */
167 check( set = sof_to_frameset( sof_name));
168 /* Validate frame set */
170
171 check( guess_order_tab_frame = xsh_find_order_tab_edges( set, instrument));
172 TESTS_XSH_FRAME_CREATE( flat_frame, "FLAT", sci_name);
173
174 xsh_msg("FRAME : %s",
175 cpl_frame_get_filename( flat_frame));
176 xsh_msg("ORDERLIST : %s",
177 cpl_frame_get_filename( guess_order_tab_frame));
178
179 xsh_msg(" Parameters ");
180 xsh_msg(" sample Y %d", backg.sampley);
181 xsh_msg(" radius X %d", backg.radius_x);
182 xsh_msg(" radius Y %d", backg.radius_y);
183
184 check( flat_rmbckg = xsh_subtract_background( flat_frame,
185 guess_order_tab_frame, &backg, instrument, "",
186 &frame_grid, &frame_back,1,1,1));
187
188 cleanup:
189 if (cpl_error_get_code() != CPL_ERROR_NONE) {
190 xsh_error_dump(CPL_MSG_ERROR);
191 ret = 1;
192 }
193 xsh_free_frameset( &set);
195 xsh_free_frame( &flat_frame);
196 xsh_free_frame( &flat_rmbckg);
197 xsh_free_frame( &frame_grid);
198 xsh_free_frame( &frame_back);
199
200 TEST_END();
201 return ret;
202}
203
int main()
Unit test of xsh_bspline_interpol.
static xsh_instrument * instrument
static const char * Options
static void HandleOptions(int argc, char **argv, xsh_background_param *backg_par)
#define MODULE_ID
static struct option long_options[]
cpl_frameset * sof_to_frameset(const char *sof_name)
Definition: tests.c:576
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
cpl_frame * xsh_subtract_background(cpl_frame *frame, cpl_frame *ordertable, xsh_background_param *bckg, xsh_instrument *instr, const char *prefix, cpl_frame **grid_frame, cpl_frame **frame_backg, const int save_bkg, const int save_grid, const int save_sub_bkg)
Subtract the inter-order background from PRE frame.
Definition: xsh_subtract.c:947
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
int xsh_debug_level_set(int level)
set debug level
Definition: xsh_utils.c:3125
static void Help(void)
#define TESTS_XSH_FRAME_CREATE(frame, tag, name)
Definition: tests.h:123
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
cpl_frame * xsh_find_order_tab_edges(cpl_frameset *frames, xsh_instrument *instr)
Find an order tab EDGES.
Definition: xsh_dfs.c:3595
xsh_instrument * xsh_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset and return the instrument detected.
Definition: xsh_dfs.c:1046
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138