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
00027 #ifdef HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00040
00043
00044
00045
00046
00047 #include <xsh_drl.h>
00048 #include <xsh_data_pre.h>
00049 #include <xsh_data_instrument.h>
00050 #include <xsh_dfs.h>
00051 #include <xsh_pfits.h>
00052 #include <xsh_error.h>
00053 #include <xsh_msg.h>
00054 #include <cpl.h>
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00080 cpl_frame*
00081 xsh_bpmap_2pre(cpl_frame* bpmap,const char* prefix, xsh_instrument* inst)
00082 {
00083 cpl_frame* result=NULL;
00084 xsh_pre* pre=NULL;
00085 char* tag=NULL;
00086 char* name=NULL;
00087
00088 pre= xsh_pre_create(bpmap,NULL,NULL,inst,0,false);
00089 tag=cpl_sprintf("%s_%s",prefix,xsh_instrument_arm_tostring(inst));
00090 name=cpl_sprintf("%s.fits",tag);
00091
00092 if(strstr(tag,XSH_BP_MAP_NL)!=NULL) {
00093 xsh_bpmap_bitwise_to_flag(pre->data,QFLAG_NON_LINEAR_PIXEL);
00094 }
00095 result=xsh_pre_save(pre,name,tag,1 );
00096
00097 xsh_pre_free(&pre);
00098 XSH_FREE(tag);
00099 XSH_FREE(name);
00100 return result;
00101 }
00102
00121
00122 void xsh_prepare( cpl_frameset* frames, cpl_frame * bpmap,
00123 cpl_frame* mbias, const char* prefix, xsh_instrument* instr,
00124 const int pre_overscan_corr,const bool flag_neg_and_thresh_pix)
00125 {
00126 xsh_pre* pre = NULL;
00127 cpl_frame *current = NULL;
00128 cpl_frame* product = NULL;
00129 xsh_pre* bias = NULL;
00130 cpl_image* bias_data = NULL;
00131 char result_name[256];
00132 char result_tag[256];
00133 int i,size;
00134
00135
00136 XSH_ASSURE_NOT_NULL( frames);
00137 XSH_ASSURE_NOT_NULL( prefix);
00138 XSH_ASSURE_NOT_NULL( instr);
00139
00140 check( size = cpl_frameset_get_size( frames) );
00141
00142
00143 if ( mbias == (cpl_frame *)-1 ) {
00144 bias_data = (cpl_image *)-1 ;
00145 }
00146 else if ( mbias != NULL ) {
00147
00148 check( bias = xsh_pre_load( mbias, instr));
00149 check( bias_data = xsh_pre_get_data( bias));
00150 } else if ( mbias == NULL ) {
00151 bias_data = (cpl_image *)-1 ;
00152 }
00153 for( i=0; i<size; i++ ) {
00154
00155 check( current = cpl_frameset_get_frame( frames, i));
00156
00157 xsh_msg_dbg_medium("Load frame %s", cpl_frame_get_filename( current));
00158
00159 check( pre = xsh_pre_create( current, bpmap, bias_data, instr,
00160 pre_overscan_corr,flag_neg_and_thresh_pix));
00161
00162
00163 if(strcmp(prefix,XSH_FLAT)==0) {
00164 if(xsh_instrument_get_lamp(instr)==XSH_LAMP_QTH) {
00165 sprintf( result_name, "%s_QTH_PRE_%d.fits", prefix, i);
00166 } else if(xsh_instrument_get_lamp(instr)==XSH_LAMP_D2) {
00167 sprintf( result_name, "%s_D2_PRE_%d.fits", prefix, i);
00168 } else {
00169 sprintf( result_name, "%s_PRE_%d.fits", prefix, i);
00170 }
00171 } else {
00172 sprintf( result_name, "%s_PRE_%d.fits", prefix, i);
00173 }
00174 sprintf( result_tag, "%s_PRE_%d", prefix, i);
00175 xsh_msg_dbg_medium( "Save frame %s", result_name);
00176
00177 check( product = xsh_pre_save( pre, result_name,result_tag,1 ));
00178 xsh_pre_free( &pre);
00179
00180 check( cpl_frame_set_filename( current,
00181 cpl_frame_get_filename( product) ) );
00182 check( cpl_frame_set_type( current,
00183 cpl_frame_get_type( product)));
00184 check( cpl_frame_set_level( current,
00185 cpl_frame_get_level( product)));
00186 xsh_free_frame( &product);
00187 }
00188
00189 cleanup:
00190 if( cpl_error_get_code() != CPL_ERROR_NONE) {
00191 xsh_pre_free( &pre);
00192 xsh_free_frame( &product);
00193 }
00194 xsh_pre_free( &bias);
00195 return;
00196 }
00197
00198
00220
00221 cpl_frame * xsh_preframe_extract( cpl_frame* frame, int xmin, int ymin,
00222 int xmax, int ymax, const char* name, xsh_instrument *instr)
00223 {
00224 xsh_pre *pre = NULL;
00225 cpl_frame *result = NULL;
00226 const char* tag = NULL;
00227
00228
00229 XSH_ASSURE_NOT_NULL( frame);
00230 XSH_ASSURE_NOT_NULL( name);
00231 XSH_ASSURE_NOT_NULL( instr);
00232
00233 check( tag = cpl_frame_get_tag( frame));
00234 check( pre = xsh_pre_load( frame, instr));
00235 check( xsh_pre_extract( pre, xmin , ymin, xmax, ymax));
00236 check( result = xsh_pre_save( pre, name, tag, 1));
00237 check( cpl_frame_set_tag( result, tag));
00238
00239 cleanup:
00240 if( cpl_error_get_code() != CPL_ERROR_NONE) {
00241 xsh_free_frame( &result);
00242 }
00243 xsh_pre_free( &pre);
00244 return result;
00245 }