File: xsh_subtract_sky_nod.c

package info (click to toggle)
cpl-plugin-xshoo 3.5.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 20,920 kB
  • sloc: ansic: 170,001; sh: 4,369; python: 2,391; makefile: 1,211
file content (167 lines) | stat: -rw-r--r-- 6,107 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*                                                                            *
 *   This file is part of the ESO X-shooter Pipeline                          *
 *   Copyright (C) 2006 European Southern Observatory                         *
 *                                                                            *
 *   This library is free software; you can redistribute it and/or modify     *
 *   it under the terms of the GNU General Public License as published by     *
 *   the Free Software Foundation; either version 2 of the License, or        *
 *   (at your option) any later version.                                      *
 *                                                                            *
 *   This program is distributed in the hope that it will be useful,          *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *   GNU General Public License for more details.                             *
 *                                                                            *
 *   You should have received a copy of the GNU General Public License        *
 *   along with this program; if not, write to the Free Software              *
 *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
 *                                                                            */

/*
 * $Author: amodigli $
 * $Date $
 * $Revision: 1.19 $
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

/*----------------------------------------------------------------------------*/
/**
 * @defgroup xsh_subtract_sky_nod  Subtract Sky NOD Frames
 * @ingroup drl_functions
 *
 * Function ...
 */
/*----------------------------------------------------------------------------*/
/**@{*/

/*-----------------------------------------------------------------------------
  Includes
  -----------------------------------------------------------------------------*/

#include <math.h>
#include <xsh_drl.h>

#include <xsh_badpixelmap.h>
#include <xsh_data_pre.h>
#include <xsh_data_order.h>
#include <xsh_data_wavemap.h>
#include <xsh_data_localization.h>
#include <xsh_data_rec.h>
#include <xsh_dfs.h>
#include <xsh_pfits.h>
#include <xsh_error.h>
#include <xsh_msg.h>
#include <xsh_fit.h>
#include <xsh_badpixelmap.h>

#include <cpl.h>

/*-----------------------------------------------------------------------------
  Functions prototypes
  -----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
  Implementation
  -----------------------------------------------------------------------------*/
static void save_pre_frame( cpl_frame * frame, xsh_instrument * instrument,
  cpl_frame *B_frame)
{
  xsh_pre *pre = NULL;
  cpl_frame * res_frame = NULL ;
  const char * fname = NULL ;
  cpl_propertylist *list_B = NULL;
  const char * name_B = NULL;
  double ra_off_B, dec_off_B;
  double ra_cumoff_B, dec_cumoff_B;

  /* Load pre frame */
  fname = cpl_frame_get_filename( frame);
  name_B = cpl_frame_get_filename( B_frame);
  check( pre = xsh_pre_load( frame, instrument));
  check( list_B = cpl_propertylist_load( name_B, 0));
  
  check( ra_off_B = xsh_pfits_get_ra_reloffset( list_B));
  check( dec_off_B = xsh_pfits_get_dec_reloffset( list_B));

  check( ra_cumoff_B = xsh_pfits_get_ra_cumoffset( list_B));
  check( dec_cumoff_B = xsh_pfits_get_dec_cumoffset( list_B));

  check( xsh_pfits_set_b_ra_reloffset( pre->data_header, ra_off_B));
  check( xsh_pfits_set_b_dec_reloffset( pre->data_header, dec_off_B));

  check( xsh_pfits_set_b_ra_cumoffset( pre->data_header, ra_cumoff_B));
  check( xsh_pfits_set_b_dec_cumoffset( pre->data_header, dec_cumoff_B));

  /* Save it */
  check( res_frame = xsh_pre_save( pre, fname, "FRAME_PRE_FORMAT", 1));

  cleanup:
    xsh_pre_free( &pre);
    xsh_free_propertylist( &list_B);
    xsh_free_frame( &res_frame);
    return;
}

/** 
 * Subtract A to B frames. Note that the order of input frames MUST be
 *   AB[B1A1...]. In the output frameset, we always have A-B, B-A, A1-B1, B1-A1
 *   in this order.
 * 
 * @param raws_ord_set Raw frames frameset
 * @param instrument Pointer to instrument structure
 * @param mode_fast specify of fast mode is set
 * @return Frameset of A-B and B-A frames
 */


/*****************************************************************************/
/*****************************************************************************/
cpl_frameset* xsh_subtract_sky_nod( cpl_frameset *raws_ord_set, 
  xsh_instrument *instrument, int mode_fast)
{
  int i, size;
  cpl_frameset* result = NULL;
  const char* arm_name = NULL;
  //char * a_b_name = NULL;

  XSH_ASSURE_NOT_NULL( raws_ord_set);
  XSH_ASSURE_NOT_NULL( instrument);

  check( arm_name = xsh_instrument_arm_tostring( instrument));
  check( size = cpl_frameset_get_size( raws_ord_set));
  result = cpl_frameset_new();

  for( i = 0; i< size; i += 2) {
    char frame_name[256];
    cpl_frame * a = NULL, * b = NULL, *a_b = NULL, *b_a = NULL;

    check( a = cpl_frameset_get_frame( raws_ord_set, i)) ;
    check( b = cpl_frameset_get_frame( raws_ord_set, i+1));
    sprintf( frame_name, "SUBTRACTED_NOD_AB_%d_%s.fits", i/2, arm_name);

    check( a_b = xsh_pre_frame_subtract( a, b, frame_name, instrument,1)) ;
    save_pre_frame( a_b, instrument, b);
    check(cpl_frameset_insert( result, a_b)) ;
    xsh_add_temporary_file(frame_name);
    if (mode_fast != CPL_TRUE){
      /* check why the full subtraction is done again and we do not use B-A=-(A-B) */
      sprintf( frame_name, "SUBTRACTED_NOD_BA_%d_%s.fits", i/2, arm_name);
      check( b_a = xsh_pre_frame_subtract( b, a, frame_name, instrument,0)) ;
      save_pre_frame( b_a, instrument, b);
      check(cpl_frameset_insert( result, b_a)) ;
    }
  }

 cleanup:
    if ( cpl_error_get_code() != CPL_ERROR_NONE){
      xsh_free_frameset( &result);
    }
    return result ;

}
/*****************************************************************************/

/**@}*/