X-shooter Pipeline Reference Manual 3.8.15
test-xsh_ifu_trace_slices.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-01-16 21:09:42 $
23 * $Revision: 1.4 $
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
45#include <xsh_error.h>
46#include <xsh_msg.h>
47#include <xsh_dfs.h>
48#include <xsh_pfits.h>
49#include <xsh_utils_image.h>
50#include <tests.h>
51
52#include <cpl.h>
53#include <math.h>
54
55/*---------------------------------------------------------------------------
56 Defines
57 ---------------------------------------------------------------------------*/
58#define MODULE_ID "XSH_IFU_TRACE_SLICES"
59
60#define SYNTAX "Computes the ifu slices positio \n"\
61 "use : ./test_xsh_ifu_trace_slices IFU_FLAT.fits SLIT_FLATS.fits ORDER_TAB_CENTR\n"
62
63
64
65
66/*--------------------------------------------------------------------------*/
73/*--------------------------------------------------------------------------*/
74int main( int argc, char** argv)
75{
76 char *ifu_flat_name = NULL;
77 char *slit_flat_name = NULL;
78
79
80 cpl_image* lx_ima=NULL;
81 cpl_image* ly_ima=NULL;
82 cpl_image* scharr_x_ima=NULL;
83 cpl_image* scharr_y_ima=NULL;
84 cpl_image* ifu_flat_ima=NULL;
85 cpl_image* slit_flat_ima=NULL;
86 cpl_image* ratio_ima=NULL;
87 //int sx=0;
88 //int sy=0;
89 double max=0;
90 /* Initialize libraries */
92 cpl_msg_set_level( CPL_MSG_DEBUG);
94
95 /* Analyse parameters */
96 if (argc > 1){
97 ifu_flat_name = argv[1];
98 slit_flat_name = argv[2];
99 }
100 else{
101 printf(SYNTAX);
102 return 0;
103 }
104
105 XSH_ASSURE_NOT_NULL( ifu_flat_name);
106 XSH_ASSURE_NOT_NULL( slit_flat_name);
107
108 check(ifu_flat_ima=cpl_image_load(ifu_flat_name,CPL_TYPE_FLOAT,0,0));
109 check(slit_flat_ima=cpl_image_load(slit_flat_name,CPL_TYPE_FLOAT,0,0));
110 //sx=cpl_image_get_size_x(ifu_flat_ima);
111 //sy=cpl_image_get_size_y(ifu_flat_ima);
112
113 check(lx_ima=xsh_sobel_lx(ifu_flat_ima));
114 check(ly_ima=xsh_sobel_ly(ifu_flat_ima));
115 check(cpl_image_save(lx_ima,"lx.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
116 check(cpl_image_save(ly_ima,"ly.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
117
118
119 check(scharr_x_ima=xsh_scharr_x(ifu_flat_ima));
120 check(scharr_y_ima=xsh_scharr_y(ifu_flat_ima));
121
122 check(cpl_image_save(scharr_x_ima,"scharr_x.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
123 check(cpl_image_save(scharr_y_ima,"scharr_y.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
124
125 /* this is not robust despite more useful
126 for(j=1;j<sy-1;j++) {
127 check(max=cpl_image_get_max_window(scharr_x_ima,0,j,sx,j));
128 check(cpl_image_divide_scalar(scharr_x_ima,max));
129 }
130 */
131
132 check(max=cpl_image_get_max(scharr_x_ima));
133 check(cpl_image_divide_scalar(scharr_x_ima,max));
134
135 /* this is not robust despite more useful
136 for(j=1;j<sy-1;j++) {
137 check(max=cpl_image_get_max_window(scharr_y_ima,0,j,sy,j));
138 check(cpl_image_divide_scalar(scharr_y_ima,max));
139 }
140 */
141
142 check(max=cpl_image_get_max(scharr_y_ima));
143 check(cpl_image_divide_scalar(scharr_y_ima,max));
144
145
146 check(cpl_image_save(scharr_x_ima,"scharr_x_n.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
147 check(cpl_image_save(scharr_y_ima,"scharr_y_n.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
148
149
150 check(cpl_image_divide(ifu_flat_ima,slit_flat_ima));
151 xsh_free_image(&lx_ima);
152 xsh_free_image(&ly_ima);
153
154 check(lx_ima=xsh_sobel_lx(ifu_flat_ima));
155 check(ly_ima=xsh_sobel_ly(ifu_flat_ima));
156
157 xsh_free_image(&scharr_x_ima);
158 xsh_free_image(&scharr_y_ima);
159 check(scharr_x_ima=xsh_scharr_x(ifu_flat_ima));
160 check(scharr_y_ima=xsh_scharr_y(ifu_flat_ima));
161
162
163
164 check(cpl_image_save(lx_ima,"lx_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
165 check(cpl_image_save(ly_ima,"ly_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
166 check(cpl_image_save(scharr_x_ima,"scharr_x_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
167 check(cpl_image_save(scharr_y_ima,"scharr_y_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
168
169 check(cpl_image_save(ifu_flat_ima,"ifu_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
170
171cleanup:
172 xsh_free_image(&ifu_flat_ima);
173 xsh_free_image(&slit_flat_ima);
174 xsh_free_image(&ratio_ima);
175 xsh_free_image(&lx_ima);
176 xsh_free_image(&ly_ima);
177 xsh_free_image(&scharr_x_ima);
178 xsh_free_image(&scharr_y_ima);
179
180
181 if (cpl_error_get_code() != CPL_ERROR_NONE) {
182 xsh_error_dump(CPL_MSG_ERROR);
183 return 1;
184 } else {
185 return 0;
186 }
187
188}
189
int main()
Unit test of xsh_bspline_interpol.
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
#define MODULE_ID
#define SYNTAX
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
Definition: xsh_utils.c:2116
int xsh_debug_level_set(int level)
set debug level
Definition: xsh_utils.c:3125
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
#define max(a, b)
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138
cpl_image * xsh_sobel_lx(cpl_image *in)
Compute X Sobel filter transformation.
cpl_image * xsh_scharr_y(cpl_image *in)
Compute Y Scharr filter transformation.
cpl_image * xsh_sobel_ly(cpl_image *in)
Compute Y Sobel filter transformation.
cpl_image * xsh_scharr_x(cpl_image *in)
Compute X Scharr filter transformation.