00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 #include <config.h>
00028 #endif
00029
00030
00037
00040
00041
00042
00043
00044 #include <math.h>
00045 #include <xsh_drl.h>
00046
00047 #include <xsh_badpixelmap.h>
00048 #include <xsh_data_pre.h>
00049 #include <xsh_data_order.h>
00050 #include <xsh_data_wavemap.h>
00051 #include <xsh_data_localization.h>
00052 #include <xsh_data_rec.h>
00053 #include <xsh_dfs.h>
00054 #include <xsh_pfits.h>
00055 #include <xsh_error.h>
00056 #include <xsh_msg.h>
00057 #include <xsh_fit.h>
00058 #include <xsh_badpixelmap.h>
00059
00060 #include <cpl.h>
00061
00062
00063
00064
00065
00066
00067
00068
00069 static void save_pre_frame( cpl_frame * frame, xsh_instrument * instrument,
00070 cpl_frame *B_frame)
00071 {
00072 xsh_pre *pre = NULL;
00073 cpl_frame * res_frame = NULL ;
00074 const char * fname = NULL ;
00075 cpl_propertylist *list_B = NULL;
00076 const char * name_B = NULL;
00077 double ra_off_B, dec_off_B;
00078 double ra_cumoff_B, dec_cumoff_B;
00079
00080
00081 fname = cpl_frame_get_filename( frame);
00082 name_B = cpl_frame_get_filename( B_frame);
00083 check( pre = xsh_pre_load( frame, instrument));
00084 check( list_B = cpl_propertylist_load( name_B, 0));
00085
00086 check( ra_off_B = xsh_pfits_get_ra_reloffset( list_B));
00087 check( dec_off_B = xsh_pfits_get_dec_reloffset( list_B));
00088
00089 check( ra_cumoff_B = xsh_pfits_get_ra_cumoffset( list_B));
00090 check( dec_cumoff_B = xsh_pfits_get_dec_cumoffset( list_B));
00091
00092 check( xsh_pfits_set_b_ra_reloffset( pre->data_header, ra_off_B));
00093 check( xsh_pfits_set_b_dec_reloffset( pre->data_header, dec_off_B));
00094
00095 check( xsh_pfits_set_b_ra_cumoffset( pre->data_header, ra_cumoff_B));
00096 check( xsh_pfits_set_b_dec_cumoffset( pre->data_header, dec_cumoff_B));
00097
00098
00099 check( res_frame = xsh_pre_save( pre, fname, "FRAME_PRE_FORMAT", 1));
00100
00101 cleanup:
00102 xsh_pre_free( &pre);
00103 xsh_free_propertylist( &list_B);
00104 xsh_free_frame( &res_frame);
00105 return;
00106 }
00107
00119 #if 0
00120 cpl_frameset * xsh_subtract_sky_nod( cpl_frameset * org_raws, int nraws,
00121 xsh_instrument * instrument )
00122 {
00123 int i, npairs ;
00124 cpl_frameset * result = NULL ;
00125 char arm_name[16] ;
00126 cpl_frameset * raws = NULL ;
00127
00128
00129 check( raws = xsh_order_frameset_by_date( org_raws ) ) ;
00130
00131 check( result = cpl_frameset_new() ) ;
00132 sprintf( arm_name, "%s_", xsh_instrument_arm_tostring( instrument ) ) ;
00133
00134 for( npairs = 0, i = 0 ; i<nraws ; i += 4 ) {
00135 char * a_b_name, * b_a_name, str[16] ;
00136 cpl_frame * a = NULL, * b = NULL ;
00137 cpl_frame * a_b = NULL, * b_a = NULL ;
00138 double nodthrow = 0, jitterbox = 0, reloffset = 0, cumoffset = 0 ;
00139
00140 if ( i == 0 ) check(a = cpl_frameset_get_first( raws )) ;
00141 else check(a = cpl_frameset_get_next( raws )) ;
00142
00143 check(b = cpl_frameset_get_next( raws ) );
00144 xsh_msg( "1-st pair: A='%s'", cpl_frame_get_filename( a ) ) ;
00145
00146 xsh_msg( " B='%s'", cpl_frame_get_filename( b ) ) ;
00147 sprintf( str, "%d", npairs ) ;
00148
00149 a_b_name = xsh_stringcat_any( "A_B_SUBTRACTED_NOD_", arm_name, str,
00150 ".fits",NULL );
00151 b_a_name = xsh_stringcat_any( "B_A_SUBTRACTED_NOD_", arm_name, str,
00152 ".fits", NULL );
00153 check( a_b = xsh_pre_frame_subtract( a, b, a_b_name, instrument )) ;
00154 save_pre_frame( a_b, instrument ) ;
00155 xsh_rec_get_nod_kw( a_b, &nodthrow, &jitterbox, &reloffset, &cumoffset ) ;
00156 xsh_msg( " A-B: Nodthrow: %lf, Jitterbox: %lf, Reloffset: %lf, Cumoffset: %lf",
00157 nodthrow, jitterbox, reloffset, cumoffset) ;
00158 check( b_a = xsh_pre_frame_subtract( b, a, b_a_name, instrument )) ;
00159 save_pre_frame( b_a, instrument ) ;
00160 xsh_rec_get_nod_kw( b_a, &nodthrow, &jitterbox, &reloffset, &cumoffset ) ;
00161 xsh_msg( " B-A: Nodthrow: %lf, Jitterbox: %lf, Reloffset: %lf, Cumoffset: %lf",
00162 nodthrow, jitterbox, reloffset, cumoffset) ;
00163
00164 check(cpl_frameset_insert( result, a_b )) ;
00165 check(cpl_frameset_insert( result, b_a )) ;
00166
00167 if ( nraws == 2 ) break ;
00168
00169
00170 npairs++ ;
00171 check(b = cpl_frameset_get_next( raws )) ;
00172 check(a = cpl_frameset_get_next( raws ) );
00173 xsh_msg( "2-nd pair: A='%s'", cpl_frame_get_filename( a ) ) ;
00174 xsh_msg( " B='%s'", cpl_frame_get_filename( b ) ) ;
00175 sprintf( str, "%d", npairs ) ;
00176 a_b_name = xsh_stringcat_any( "A_B_SUBTRACTED_NOD_", arm_name, str,
00177 ".fits",NULL );
00178 b_a_name = xsh_stringcat_any( "B_A_SUBTRACTED_NOD_", arm_name, str,
00179 ".fits", NULL );
00180 check( a_b = xsh_pre_frame_subtract( a, b, a_b_name, instrument )) ;
00181 save_pre_frame( a_b, instrument ) ;
00182 xsh_rec_get_nod_kw( a_b, &nodthrow, &jitterbox, &reloffset, &cumoffset ) ;
00183 xsh_msg( " A-B: Nodthrow: %lf, Jitterbox: %lf, Reloffset: %lf, Cumoffset: %lf",
00184 nodthrow, jitterbox, reloffset, cumoffset) ;
00185 check( b_a = xsh_pre_frame_subtract( b, a, b_a_name, instrument )) ;
00186 save_pre_frame( b_a, instrument ) ;
00187 xsh_rec_get_nod_kw( b_a, &nodthrow, &jitterbox, &reloffset, &cumoffset ) ;
00188 xsh_msg( " B-A: Nodthrow: %lf, Jitterbox: %lf, Reloffset: %lf, Cumoffset: %lf",
00189 nodthrow, jitterbox, reloffset, cumoffset) ;
00190
00191 check(cpl_frameset_insert( result, a_b )) ;
00192 check(cpl_frameset_insert( result, b_a )) ;
00193 }
00194 xsh_msg_dbg_high( "Done OK" ) ;
00195
00196 cleanup:
00197 return result ;
00198
00199 }
00200 #else
00201
00202
00203 cpl_frameset* xsh_subtract_sky_nod( cpl_frameset *raws_ord_set,
00204 xsh_instrument *instrument, int mode_fast)
00205 {
00206 int i, size;
00207 cpl_frameset* result = NULL;
00208 const char* arm_name = NULL;
00209
00210
00211 XSH_ASSURE_NOT_NULL( raws_ord_set);
00212 XSH_ASSURE_NOT_NULL( instrument);
00213
00214 check( arm_name = xsh_instrument_arm_tostring( instrument));
00215 check( size = cpl_frameset_get_size( raws_ord_set));
00216 result = cpl_frameset_new();
00217
00218 for( i = 0; i< size; i += 2) {
00219 char frame_name[256];
00220 cpl_frame * a = NULL, * b = NULL, *a_b = NULL, *b_a = NULL;
00221
00222 check( a = cpl_frameset_get_frame( raws_ord_set, i)) ;
00223 check( b = cpl_frameset_get_frame( raws_ord_set, i+1));
00224 sprintf( frame_name, "SUBTRACTED_NOD_AB_%d_%s.fits", i/2, arm_name);
00225
00226 check( a_b = xsh_pre_frame_subtract( a, b, frame_name, instrument)) ;
00227 save_pre_frame( a_b, instrument, b);
00228 check(cpl_frameset_insert( result, a_b)) ;
00229 if (mode_fast != CPL_TRUE){
00230 sprintf( frame_name, "SUBTRACTED_NOD_BA_%d_%s.fits", i/2, arm_name);
00231 check( b_a = xsh_pre_frame_subtract( b, a, frame_name, instrument)) ;
00232 save_pre_frame( b_a, instrument, b);
00233 check(cpl_frameset_insert( result, b_a)) ;
00234 }
00235 }
00236
00237 cleanup:
00238 if ( cpl_error_get_code() != CPL_ERROR_NONE){
00239 xsh_free_frameset( &result);
00240 }
00241 return result ;
00242
00243 }
00244
00245 #endif
00246