88 cpl_vector *tellmask_vect = NULL;
90 const char *s1d_name = NULL;
91 const char *tag = NULL;
92 cpl_frame *result = NULL;
96 check( tag = cpl_frame_get_tag( s1d_frame));
97 check( s1d_name = cpl_frame_get_filename( s1d_frame));
103 if ( tellmask_frame != NULL){
104 const char* tellmask_name = NULL;
106 check( tellmask_name = cpl_frame_get_filename( tellmask_frame));
107 xsh_msg(
"Use telluric mask %s", tellmask_name);
109 check( tellmask_vect = cpl_vector_load( tellmask_name, 0));
110 check( tellmask_size = cpl_vector_get_size( tellmask_vect));
114 for( i=0; i<
size; i++){
117 mask_val = cpl_vector_get( tellmask_vect, i);
156 cpl_frame *result = NULL;
158 double *flux_data = NULL;
159 cpl_vector *flux_vect = NULL;
160 cpl_vector *smooth_vect = NULL;
161 double *diff_data = NULL;
162 cpl_vector *diff_vect = NULL;
163 cpl_vector *std_vect = NULL;
164 cpl_vector *std_box_vect = NULL;
165 cpl_vector *tellmask = NULL;
167 double wmin=0, wstep=0;
172 int *tellflag = NULL;
173 const char* tellist_name = NULL;
174 cpl_table *tellist_table = NULL;
181 XSH_REGDEBUG(
"File %s list %s filter %d threshold %f", cpl_frame_get_filename( s1d_frame),
182 cpl_frame_get_filename( telllist_frame), filter_hsize,
threshold);
191 check( flux_vect = cpl_vector_wrap(
size, flux_data));
193 check( smooth_vect = cpl_vector_filter_median_create( flux_vect,
195 check( diff_vect = cpl_vector_new(
size));
197 for( i=0; i<
size; i++){
198 double smooth_val, dval;
200 smooth_val = cpl_vector_get( smooth_vect, i);
201 dval = (flux_data[i]-smooth_val)/smooth_val;
202 cpl_vector_set( diff_vect, i, dval);
206 check( std_vect = cpl_vector_new(
size));
207 check( diff_data = cpl_vector_get_data( diff_vect));
209 for(i=0; i< (
size-2*filter_hsize-1); i++){
212 std_box_vect = cpl_vector_wrap( filter_hsize*2+1, diff_data+i-filter_hsize);
213 dval = cpl_vector_get_stdev( std_box_vect);
214 cpl_vector_set( std_vect, i, dval);
218 tellmask = cpl_vector_new(
size);
223 if ( telllist_frame != NULL){
224 int it=0, table_size;
227 double factor_min, factor_max;
230 check( tellist_name = cpl_frame_get_filename( telllist_frame));
233 table_size = cpl_table_get_nrow( tellist_table);
248 factor_min = (r2-1)/(r1-1)*r1/r2;
249 factor_max = (r2+1)/(r1+1)*r1/r2;
252 double wave, wtellmin, wtellmax;
262 wtellmin *= factor_min;
263 wtellmax *= factor_max;
266 if ( wave >= wtellmin){
267 if ( wave <= wtellmax){
272 if ( it < table_size-1){
288 for(i=0; i<
size; i++){
294 noise = cpl_vector_get( std_vect, i);
299 cpl_vector_set( tellmask, i,1.0);
302 cpl_vector_set( tellmask, i,0.0);
308 FILE* debug_file = NULL;
310 debug_file = fopen(
"out.dat",
"w+");
312 fprintf( debug_file,
"#lambda flux smooth diff flag is_tell\n");
314 for(i=0; i<
size; i++){
317 mask_val = cpl_vector_get( tellmask, i);
318 fprintf( debug_file,
"%f %f %f %f %f %d\n", wmin+wstep*i, flux_data[i],
319 cpl_vector_get( smooth_vect, i), cpl_vector_get( std_vect, i),
320 mask_val*100, tellflag[i]*100);
328 sprintf( mask_name,
"TELL_MASK.fits");
333 result = cpl_frame_new ();
335 check( cpl_frame_set_filename ( result, mask_name));
336 check( cpl_frame_set_tag( result,tag));
337 check( cpl_frame_set_type( result, CPL_FRAME_TYPE_IMAGE));
338 check( cpl_frame_set_group ( result, CPL_FRAME_GROUP_PRODUCT)) ;
340 check( cpl_frame_set_level( result, CPL_FRAME_LEVEL_TEMPORARY));
345 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
cpl_frame * xsh_compute_absorp(cpl_frame *s1d_frame, cpl_frame *telllist_frame, int filter_hsize, double threshold, xsh_instrument *instr)
Compute the shift in slit between reference wavelength and others for all the slitlets.
void xsh_mark_tell(cpl_frame *s1d_frame, cpl_frame *tellmask_frame)
Mark telluric in spectrum.
int xsh_spectrum_get_size_lambda(xsh_spectrum *s)
Get lambda axis size of spectrum.
xsh_spectrum * xsh_spectrum_load(cpl_frame *s1d_frame)
Load a 1D spectrum structure.
int * xsh_spectrum_get_qual(xsh_spectrum *s)
Get qual of spectrum.
int xsh_spectrum_get_size(xsh_spectrum *s)
Get size of spectrum.
cpl_frame * xsh_spectrum_save(xsh_spectrum *s, const char *filename, const char *tag)
save a spectrum
double * xsh_spectrum_get_flux(xsh_spectrum *s)
Get flux of spectrum.
void xsh_spectrum_free(xsh_spectrum **s)
free memory associated to an 1D spectrum
#define XSH_REGDEBUG(...)
#define XSH_ASSURE_NOT_ILLEGAL(cond)
#define XSH_ASSURE_NOT_NULL(pointer)
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
double xsh_resolution_get(xsh_instrument *instrument, double slit)
Get the resoltion.
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
#define xsh_msg(...)
Print a message on info level.
double xsh_pfits_get_slit_width(const cpl_propertylist *plist, xsh_instrument *instrument)
find out the INS OPTIx NAME value (the width of the slit)
void xsh_unwrap_vector(cpl_vector **v)
Unwrap a vector and set the pointer to NULL.
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
cpl_error_code xsh_sort_table_1(cpl_table *t, const char *column, cpl_boolean reverse)
Sort a table by one column.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
cpl_propertylist * flux_header
#define QFLAG_TELLURIC_UNCORRECTED
#define GUESS_TELL_MASK_RESOLUTION_NIR
#define GUESS_TELL_MASK_RESOLUTION_UVB
#define LSTART_COLUMN_NAME
#define GUESS_TELL_MASK_RESOLUTION_VIS
#define XSH_FREE(POINTER)
#define XSH_CALLOC(POINTER, TYPE, SIZE)
#define XSH_TABLE_LOAD(TABLE, NAME)
#define XSH_TABLE_FREE(TABLE)