79 const cpl_image* img=NULL;
82 cpl_vector* levels=NULL;
88 cpl_error_ensure(iml != NULL, CPL_ERROR_NULL_INPUT,
return(levels),
89 "Null input image list");
90 cpl_error_ensure(
kappa >= 0, CPL_ERROR_ILLEGAL_INPUT,
return(levels),
93 size=cpl_imagelist_get_size(iml);
94 levels=cpl_vector_new(
size);
95 pval=cpl_vector_get_data(levels);
98 img=cpl_imagelist_get_const(iml,i);
100 cpl_image_get_size_y(img),
128 size=cpl_imagelist_get_size(*iml);
129 pval=cpl_vector_get_data(values);
131 for(i=0;i<
size;i++) {
132 img=cpl_imagelist_get(*iml,i);
133 cpl_image_subtract_scalar(img,pval[i]);
134 cpl_imagelist_set(*iml,img,i);
137 return cpl_error_get_code();
155irplib_vector_ksigma(cpl_vector *values,
156 const double klow,
const double khigh,
int kiter)
158 cpl_vector *accepted;
161 double *
data = cpl_vector_get_data(values);
162 int n = cpl_vector_get_size(values);
172 mean = cpl_vector_get_median(values);
174 for (i = 0; i <
n; i++) {
181 for (i = 0; i < ngood; i++) {
197 accepted = cpl_vector_wrap(count,
data);
198 mean = cpl_vector_get_mean(accepted);
200 sigma = cpl_vector_get_stdev(accepted);
202 cpl_vector_unwrap(accepted);
204 if (count == ngood) {
234irplib_imagelist_ksigma_stack(
const cpl_imagelist *imlist,
235 double klow,
double khigh,
int kiter)
237 int ni,
nx,
ny, npix;
238 cpl_image *out_ima=NULL;
239 cpl_imagelist *loc_iml=NULL;
240 float *pout_ima=NULL;
241 cpl_image *image=NULL;
242 const float **
data=NULL;
244 cpl_vector *time_line=NULL;
246 double *ptime_line=NULL;
248 double mean_of_medians=0;
250 cpl_error_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT,
return(out_ima),
251 "Null input image list");
253 ni = cpl_imagelist_get_size(imlist);
254 loc_iml = cpl_imagelist_duplicate(imlist);
255 image = cpl_imagelist_get(loc_iml, 0);
256 nx = cpl_image_get_size_x(image);
257 ny = cpl_image_get_size_y(image);
260 out_ima = cpl_image_new(
nx,
ny, CPL_TYPE_FLOAT);
261 pout_ima = cpl_image_get_data_float(out_ima);
263 time_line = cpl_vector_new(ni);
265 ptime_line = cpl_vector_get_data(time_line);
267 data = cpl_calloc(
sizeof(
float *), ni);
268 med = cpl_calloc(
sizeof(
double), ni);
270 for (i = 0; i < ni; i++) {
271 image = cpl_imagelist_get(loc_iml, i);
272 med[i]=cpl_image_get_median(image);
273 cpl_image_subtract_scalar(image,med[i]);
274 data[i] = cpl_image_get_data_float(image);
275 mean_of_medians+=med[i];
280 for (i = 0; i < npix; i++) {
281 for (j = 0; j < ni; j++) {
282 ptime_line[j] =
data[j][i];
284 pout_ima[i] = irplib_vector_ksigma(time_line, klow, khigh, kiter);
287 cpl_image_add_scalar(out_ima,mean_of_medians);
292 cpl_vector_delete(time_line);
293 cpl_imagelist_delete(loc_iml);
319 const double tolerance,
const double klow,
const double khigh)
322 cpl_image* master=NULL;
323 cpl_vector* levels=NULL;
325 cpl_imagelist* iml=NULL;
328 iml=cpl_imagelist_duplicate(images);
330 mean=cpl_vector_get_mean(levels);
336 master = cpl_imagelist_collapse_sigclip_create(iml,klow,khigh,.1,CPL_COLLAPSE_MEAN,NULL);
337 cpl_image_add_scalar(master,mean);
339 cpl_vector_delete(levels);
340 cpl_imagelist_delete(iml);
366 cpl_image* master=NULL;
367 cpl_vector* levels=NULL;
369 cpl_imagelist* iml=NULL;
371 cpl_ensure(images != NULL, CPL_ERROR_NULL_INPUT,NULL);
373 iml=cpl_imagelist_duplicate(images);
376 mean=cpl_vector_get_mean(levels);
385 cpl_image_add_scalar(master,mean);
386 cpl_vector_delete(levels);
387 cpl_imagelist_delete(iml);
395 cpl_propertylist** raw_headers,
const cpl_image* master_bias,
396 double* mean_exptime) {
400 cpl_imagelist* preproc_images = NULL;
402 cpl_image* current_dark = NULL;
403 double min_exptime = 0;
404 double max_exptime = 0;
406 preproc_images = cpl_imagelist_new();
407 for (i = 0; i < cpl_imagelist_get_size(raw_images); i++) {
408 double exposure_time = 0.0;
409 const cpl_propertylist *current_header;
411 current_dark = cpl_image_duplicate(cpl_imagelist_get_const(raw_images, i));
412 current_header = raw_headers[i];
415 if (master_bias != NULL) {
417 cpl_image_subtract(current_dark, master_bias);
424 if (i == 0 || exposure_time < min_exptime) {
425 min_exptime = exposure_time;
427 if (i == 0 || exposure_time > max_exptime) {
428 max_exptime = exposure_time;
439 cpl_imagelist_set(preproc_images, current_dark, i);
448 cpl_msg_info(cpl_func,
449 "Exposure times range from %e s to %e s (%e %% variation)", min_exptime,
450 max_exptime, 100 * (max_exptime - min_exptime) / min_exptime);
452 if ((max_exptime - min_exptime) / min_exptime > .001) {
453 cpl_msg_warning(cpl_func,
"Exposure times differ by %e %%",
454 100 * (max_exptime - min_exptime) / min_exptime);
458 *mean_exptime=0.5 * (max_exptime + min_exptime);
459 return preproc_images;
cpl_imagelist * xsh_irplib_mkmaster_dark_fill_imagelist(const cpl_imagelist *raw_images, cpl_propertylist **raw_headers, const cpl_image *master_bias, double *mean_exptime)
cpl_image * xsh_irplib_mkmaster_median(cpl_imagelist *images, const double kappa, const int nclip, const double tolerance)
Computes master frame by clean stack median of the input imagelist.
static cpl_error_code irplib_imagelist_subtract_values(cpl_imagelist **iml, cpl_vector *values)
Subtract from input imagelist values specified in input vector.
cpl_vector * xsh_irplib_imagelist_get_clean_mean_levels(const cpl_imagelist *iml, const double kappa, const int nclip, const double tolerance)
find out the character string associated to the DIT keyword in a propertylist
cpl_image * xsh_irplib_mkmaster_mean(cpl_imagelist *images, const double kappa, const int nclip, const double tolerance, const double klow, const double khigh)
Computes master frame by clean stack mean of the input imagelist.
double xsh_pfits_get_exptime(const cpl_propertylist *plist)
find out the exposure time
static cpl_error_code TYPE_ADD() xsh_ksigma_clip(const CPL_TYPE *pi, cpl_binary *pm, int llx, int lly, int urx, int ury, int nx, double var_sum, int npixs, double kappa, int nclip, double tolerance, double *mean, double *stdev)
cpl_image * xsh_imagelist_collapse_median_create(cpl_imagelist *iml)
Compute median on imagelist.