X-shooter Pipeline Reference Manual 3.8.15
test-xsh_startup.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: 2011-12-02 14:13:14 $
23 * $Revision: 1.4 $
24 * $Name: not supported by cvs2svn $
25 */
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30
31/*----------------------------------------------------------------------------*/
36/*----------------------------------------------------------------------------*//*--------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------
40 Includes
41 ---------------------------------------------------------------------------*/
42#include <xsh_utils.h>
43#include <xsh_error.h>
44#include <xsh_fit.h>
45#include <xsh_msg.h>
46#include <tests.h>
47#include <cpl.h>
48#include <math.h>
49
50#include <time.h>
51#include <sys/time.h>
52/*---------------------------------------------------------------------------
53 Defines
54 ---------------------------------------------------------------------------*/
55#define MODULE_ID "XSH_STARTUP"
56
57
58static void xsh_gfit_tests(void);
59
60/*--------------------------------------------------------------------------*/
66/*--------------------------------------------------------------------------*/
67int main(void)
68{
71
73
74 cleanup:
76 if (cpl_error_get_code() != CPL_ERROR_NONE) {
77 xsh_error_dump(CPL_MSG_ERROR);
78 return 1;
79 } else {
80 return 0;
81 }
82}
83
84
85static void xsh_gfit_tests(void)
86{
87 cpl_image* img_raw=NULL;
88 cpl_image* img_raw1=NULL;
89 cpl_image* img_noise=NULL;
90 double sx=128;
91 double sy=128;
92 double sigx=4;
93 double sigy=4;
94 double sigx1=2;
95 double sigy1=2;
96
97 int xc=sx/2;
98 int yc=sy/2;
99 int offx1=20;
100 int offy1=20;
101
102 int xc1=sx/2+offx1;
103 int yc1=sy/2+offy1;
104 double flux1=5.e4;
105 double flux=5.e4;
106
107 double noise=1.e2;
108 double min=-noise;
109 double max=+noise;
110 const char* name="raw_ima.fits";
111 int offx=12;
112 int offy=12;
113 int size=20;
114 int xg=(int)(xc+offx);
115 int yg=(int)(yc+offy);
116 double fwhm_x=0;
117 double fwhm_y=0;
118 double xcen=0;
119 double ycen=0;
120 double sig_x=0;
121 double sig_y=0;
122 double norm=0;
123
124 check(img_raw=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
125 check(img_raw1=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
126 check(img_noise=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
127
128
129 check(cpl_image_fill_gaussian(img_raw,xc,yc,flux,sigx,sigy));
130 check(cpl_image_fill_gaussian(img_raw1,xc1,yc1,flux1,sigx1,sigy1));
131 check(cpl_image_fill_noise_uniform(img_noise,min,max));
132 check(cpl_image_add(img_raw,img_noise));
133 check(cpl_image_add(img_raw,img_raw1));
134
135 check(cpl_image_save(img_raw,name,CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
136
137 //check(cpl_image_fit_gaussian(img_raw,xg,yg,size,&norm,&xcen,&ycen,
138 // &sig_x,&sig_y,&fwhm_x,&fwhm_y));
139 check(xsh_image_find_barycenter(img_raw,xg,yg,size,&norm,&xcen,&ycen,
140 &sig_x,&sig_y,&fwhm_x,&fwhm_y));
141 xsh_msg("xc=%d yc=%d xg=%d yg=%d xcen=%f ycen=%f S/N=%f",
142 xc,yc,xg,yg,xcen,ycen,norm/noise);
143
144 xsh_free_image(&img_raw);
145 xsh_free_image(&img_raw1);
146 xsh_free_image(&img_noise);
147
148 cleanup:
149 return;
150}
151
152
153
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
cpl_error_code xsh_image_find_barycenter(const cpl_image *im, int xpos, int ypos, int size, double *norm, double *xcen, double *ycen, double *sig_x, double *sig_y, double *fwhm_x, double *fwhm_y)
Apply a gaussian fit on an image sub window.
Definition: xsh_fit.c:696
int size
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
#define MODULE_ID
static void xsh_gfit_tests(void)
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
Definition: xsh_utils.c:2116
#define TESTS_CLEAN_WORKSPACE(DRL_ID)
Definition: tests.h:139
#define TESTS_INIT_WORKSPACE(DRL_ID)
Definition: tests.h:133
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
#define max(a, b)