X-shooter Pipeline Reference Manual 3.8.15
xsh_subtract_sky_nod.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 $
23 * $Revision: 1.19 $
24 */
25
26#ifdef HAVE_CONFIG_H
27#include <config.h>
28#endif
29
30/*----------------------------------------------------------------------------*/
37/*----------------------------------------------------------------------------*/
40/*-----------------------------------------------------------------------------
41 Includes
42 -----------------------------------------------------------------------------*/
43
44#include <math.h>
45#include <xsh_drl.h>
46
47#include <xsh_badpixelmap.h>
48#include <xsh_data_pre.h>
49#include <xsh_data_order.h>
50#include <xsh_data_wavemap.h>
52#include <xsh_data_rec.h>
53#include <xsh_dfs.h>
54#include <xsh_pfits.h>
55#include <xsh_error.h>
56#include <xsh_msg.h>
57#include <xsh_fit.h>
58#include <xsh_badpixelmap.h>
59
60#include <cpl.h>
61
62/*-----------------------------------------------------------------------------
63 Functions prototypes
64 -----------------------------------------------------------------------------*/
65
66/*-----------------------------------------------------------------------------
67 Implementation
68 -----------------------------------------------------------------------------*/
69static void save_pre_frame( cpl_frame * frame, xsh_instrument * instrument,
70 cpl_frame *B_frame)
71{
72 xsh_pre *pre = NULL;
73 cpl_frame * res_frame = NULL ;
74 const char * fname = NULL ;
75 cpl_propertylist *list_B = NULL;
76 const char * name_B = NULL;
77 double ra_off_B, dec_off_B;
78 double ra_cumoff_B, dec_cumoff_B;
79
80 /* Load pre frame */
81 fname = cpl_frame_get_filename( frame);
82 name_B = cpl_frame_get_filename( B_frame);
83 check( pre = xsh_pre_load( frame, instrument));
84 check( list_B = cpl_propertylist_load( name_B, 0));
85
86 check( ra_off_B = xsh_pfits_get_ra_reloffset( list_B));
87 check( dec_off_B = xsh_pfits_get_dec_reloffset( list_B));
88
89 check( ra_cumoff_B = xsh_pfits_get_ra_cumoffset( list_B));
90 check( dec_cumoff_B = xsh_pfits_get_dec_cumoffset( list_B));
91
94
96 check( xsh_pfits_set_b_dec_cumoffset( pre->data_header, dec_cumoff_B));
97
98 /* Save it */
99 check( res_frame = xsh_pre_save( pre, fname, "FRAME_PRE_FORMAT", 1));
100
101 cleanup:
102 xsh_pre_free( &pre);
103 xsh_free_propertylist( &list_B);
104 xsh_free_frame( &res_frame);
105 return;
106}
107
120/*****************************************************************************/
121/*****************************************************************************/
122cpl_frameset* xsh_subtract_sky_nod( cpl_frameset *raws_ord_set,
123 xsh_instrument *instrument, int mode_fast)
124{
125 int i, size;
126 cpl_frameset* result = NULL;
127 const char* arm_name = NULL;
128 //char * a_b_name = NULL;
129
130 XSH_ASSURE_NOT_NULL( raws_ord_set);
132
134 check( size = cpl_frameset_get_size( raws_ord_set));
135 result = cpl_frameset_new();
136
137 for( i = 0; i< size; i += 2) {
138 char frame_name[256];
139 cpl_frame * a = NULL, * b = NULL, *a_b = NULL, *b_a = NULL;
140
141 check( a = cpl_frameset_get_frame( raws_ord_set, i)) ;
142 check( b = cpl_frameset_get_frame( raws_ord_set, i+1));
143 sprintf( frame_name, "SUBTRACTED_NOD_AB_%d_%s.fits", i/2, arm_name);
144
145 check( a_b = xsh_pre_frame_subtract( a, b, frame_name, instrument,1)) ;
146 save_pre_frame( a_b, instrument, b);
147 check(cpl_frameset_insert( result, a_b)) ;
148 xsh_add_temporary_file(frame_name);
149 if (mode_fast != CPL_TRUE){
150 /* check why the full subtraction is done again and we do not use B-A=-(A-B) */
151 sprintf( frame_name, "SUBTRACTED_NOD_BA_%d_%s.fits", i/2, arm_name);
152 check( b_a = xsh_pre_frame_subtract( b, a, frame_name, instrument,0)) ;
153 save_pre_frame( b_a, instrument, b);
154 check(cpl_frameset_insert( result, b_a)) ;
155 }
156 }
157
158 cleanup:
159 if ( cpl_error_get_code() != CPL_ERROR_NONE){
160 xsh_free_frameset( &result);
161 }
162 return result ;
163
164}
165/*****************************************************************************/
166
static xsh_instrument * instrument
xsh_pre * xsh_pre_load(cpl_frame *frame, xsh_instrument *instr)
Load a xsh_pre structure from a frame.
Definition: xsh_data_pre.c:849
cpl_frame * xsh_pre_frame_subtract(cpl_frame *one, cpl_frame *two, const char *filename, xsh_instrument *instr, const int clean_tmp)
Subtract 2 frames (in XSH_PRE format) Just loads the 2 frames, subtract (xsh_pre_subtract) and save r...
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
Definition: xsh_data_pre.c:823
cpl_frame * xsh_pre_save(const xsh_pre *pre, const char *filename, const char *tag, int temp)
Save PRE on disk.
#define check(COMMAND)
Definition: xsh_error.h:71
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
int size
void xsh_pfits_set_b_ra_reloffset(cpl_propertylist *plist, double value)
Definition: xsh_pfits.c:3675
double xsh_pfits_get_ra_cumoffset(const cpl_propertylist *plist)
Definition: xsh_pfits.c:3585
void xsh_pfits_set_b_dec_cumoffset(cpl_propertylist *plist, double value)
Definition: xsh_pfits.c:3712
void xsh_pfits_set_b_dec_reloffset(cpl_propertylist *plist, double value)
Definition: xsh_pfits.c:3687
double xsh_pfits_get_dec_cumoffset(const cpl_propertylist *plist)
Definition: xsh_pfits.c:3600
double xsh_pfits_get_dec_reloffset(const cpl_propertylist *plist)
Definition: xsh_pfits.c:3543
void xsh_pfits_set_b_ra_cumoffset(cpl_propertylist *plist, double value)
Definition: xsh_pfits.c:3700
double xsh_pfits_get_ra_reloffset(const cpl_propertylist *plist)
Definition: xsh_pfits.c:3528
static void save_pre_frame(cpl_frame *frame, xsh_instrument *instrument, cpl_frame *B_frame)
cpl_frameset * xsh_subtract_sky_nod(cpl_frameset *raws_ord_set, xsh_instrument *instrument, int mode_fast)
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
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
Definition: xsh_utils.c:1432
cpl_propertylist * data_header
Definition: xsh_data_pre.h:66