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
00028
00029
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033
00034 #include <cpl.h>
00035 #include <cxtypes.h>
00036 #include <math.h>
00037
00038 #include "vircam_mods.h"
00039 #include "vircam_utils.h"
00040 #include "vircam_stats.h"
00041 #include "vircam_mask.h"
00042 #include "vircam_filt.h"
00043
00046
00083
00084
00085 extern int vircam_destripe(vir_fits *in, vir_mask *inbpm, int *status) {
00086 float *data,*d,medprofile,profilerms,*wptr,val,rms,lcut,hcut;
00087 float skymed,skynoise,*copy;
00088 unsigned char *bpm,*b,*rb,*ob;
00089 long i,j,nx,ny;
00090 cpl_propertylist *plist;
00091
00092
00093
00094 if (*status != VIR_OK)
00095 return(*status);
00096
00097
00098
00099 data = cpl_image_get_data(vircam_fits_get_image(in));
00100 if (inbpm != NULL)
00101 bpm = vircam_mask_get_data(inbpm);
00102 else
00103 bpm = NULL;
00104
00105
00106
00107 nx = (long)cpl_image_get_size_x(vircam_fits_get_image(in));
00108 ny = (long)cpl_image_get_size_y(vircam_fits_get_image(in));
00109
00110
00111
00112 vircam_qmedsig(data,bpm,nx*ny,3.0,3,-65535.0,65535.0,&skymed,&skynoise);
00113
00114
00115
00116 wptr = cpl_malloc(ny*sizeof(*wptr));
00117 copy = cpl_malloc(ny*sizeof(*copy));
00118 rb = cpl_calloc(ny,sizeof(*rb));
00119
00120
00121
00122 d = data;
00123 b = bpm;
00124 for (i = 0; i < ny; i++) {
00125
00126
00127
00128
00129 lcut = -1.0e10;
00130 hcut = 1.0e10;
00131 for (j = 0; j < 3; j++) {
00132 vircam_medmadcut(d,b,nx,lcut,hcut,&val,&rms);
00133 if (val == CX_MAXFLOAT) {
00134 break;
00135 } else {
00136 lcut = val - 3.0*skynoise;
00137 hcut = val + 3.0*skynoise;
00138 }
00139 }
00140 rb[i] = (val == CX_MAXFLOAT);
00141 wptr[i] = (rb[i] ? 0.0 : val);
00142 copy[i] = wptr[i];
00143 d += nx;
00144 if (b != NULL)
00145 b += nx;
00146 }
00147
00148
00149
00150
00151 vircam_medmad(wptr,rb,ny,&medprofile,&profilerms);
00152 profilerms *= 1.48;
00153 if (profilerms > 5.0) {
00154 ob = cpl_calloc(ny,sizeof(*ob));
00155 vircam_dostat(copy,rb,ob,ny,25,MEDIANCALC);
00156 vircam_dostat(copy,rb,ob,ny,5,MEANCALC);
00157 for (i = 0; i < ny; i++) {
00158 if (! ob[i])
00159 wptr[i] -= copy[i];
00160 else
00161 wptr[i] = 0.0;
00162 }
00163 freespace(ob);
00164 } else {
00165 for (i = 0; i < ny; i++) {
00166 if (rb[i]) {
00167 wptr[i] = 0.0;
00168 } else {
00169 wptr[i] -= medprofile;
00170 }
00171 }
00172 }
00173 freespace(rb);
00174 freespace(copy);
00175
00176
00177
00178 d = data;
00179 for (i = 0; i < ny; i++) {
00180 for (j = 0; j < nx; j++)
00181 d[j] -= wptr[i];
00182 d += nx;
00183 }
00184
00185
00186
00187 plist = vircam_fits_get_ehu(in);
00188 cpl_propertylist_update_bool(plist,"ESO DRS STRIPECOR",TRUE);
00189 cpl_propertylist_set_comment(plist,"ESO DRS STRIPECOR",
00190 "Stripe correction done");
00191 cpl_propertylist_update_float(plist,"ESO DRS STRIPERMS",profilerms);
00192 cpl_propertylist_set_comment(plist,"ESO DRS STRIPERMS",
00193 "RMS of the removed stripe profile");
00194
00195
00196
00197 freespace(wptr);
00198 GOOD_STATUS
00199 }
00200
00201
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253