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
00045
00082
00083
00084 extern int vircam_destripe(vir_fits *in, vir_mask *inbpm, int *status) {
00085 float *data,*d,medprofile,profilerms,*wptr,val;
00086 unsigned char *bpm,*b,*rb;
00087 long i,j,nx,ny;
00088 cpl_propertylist *plist;
00089
00090
00091
00092 if (*status != VIR_OK)
00093 return(*status);
00094
00095
00096
00097 data = cpl_image_get_data(vircam_fits_get_image(in));
00098 if (inbpm != NULL)
00099 bpm = vircam_mask_get_data(inbpm);
00100 else
00101 bpm = NULL;
00102
00103
00104
00105 nx = (long)cpl_image_get_size_x(vircam_fits_get_image(in));
00106 ny = (long)cpl_image_get_size_y(vircam_fits_get_image(in));
00107
00108
00109
00110 wptr = cpl_malloc(nx*sizeof(*wptr));
00111 rb = cpl_calloc(nx,sizeof(*rb));
00112
00113
00114
00115 d = data;
00116 b = bpm;
00117 for (i = 0; i < ny; i++) {
00118
00119
00120
00121 val = vircam_med(d,b,nx);
00122 if (val == CX_MAXFLOAT) {
00123 wptr[i] = 0.0;
00124 rb[i] = 1;
00125 } else {
00126 wptr[i] = val;
00127 }
00128 d += nx;
00129 if (b != NULL)
00130 b += nx;
00131 }
00132
00133
00134
00135
00136 vircam_medsig(wptr,rb,ny,&medprofile,&profilerms);
00137 for (i = 0; i < ny; i++) {
00138 if (rb[i]) {
00139 wptr[i] = 0.0;
00140 } else {
00141 wptr[i] -= medprofile;
00142 }
00143 }
00144 cpl_free(rb);
00145
00146
00147
00148 d = data;
00149 for (i = 0; i < ny; i++) {
00150 for (j = 0; j < nx; j++)
00151 d[j] -= wptr[i];
00152 d += nx;
00153 }
00154
00155
00156
00157 plist = vircam_fits_get_ehu(in);
00158 cpl_propertylist_update_bool(plist,"ESO DRS STRIPECOR",TRUE);
00159 cpl_propertylist_set_comment(plist,"ESO DRS STRIPECOR",
00160 "Stripe correction done");
00161 cpl_propertylist_update_float(plist,"ESO DRS STRIPERMS",profilerms);
00162 cpl_propertylist_set_comment(plist,"ESO DRS STRIPERMS",
00163 "RMS of the removed stripe profile");
00164
00165
00166
00167 freespace(wptr);
00168 GOOD_STATUS
00169 }
00170
00171
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201