VISIR Pipeline Reference Manual  4.1.0
visir_util_apply_calib.c
1 /* $Id: visir_util_apply_calib.c,v 1.3 2013-05-23 14:34:43 jtaylor Exp $
2  *
3  * This file is part of the VISIR Pipeline
4  * Copyright (C) 2012 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: jtaylor $
23  * $Date: 2013-05-23 14:34:43 $
24  * $Revision: 1.3 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 /*-----------------------------------------------------------------------------
33  Includes
34  -----------------------------------------------------------------------------*/
35 
36 #include "visir_recipe.h"
37 #include <cxlist.h>
38 
39 #include <string.h>
40 
41 
42 /*-----------------------------------------------------------------------------
43  Defines
44  -----------------------------------------------------------------------------*/
45 
46 #define RECIPE_STRING "visir_util_apply_calib"
47 
48 /*-----------------------------------------------------------------------------
49  Private Functions prototypes
50  -----------------------------------------------------------------------------*/
51 
52 // FIXME:
53 cpl_recipe_define(visir_util_apply_calib, VISIR_BINARY_VERSION,
54  "Julian Taylor", PACKAGE_BUGREPORT, "2012",
55  "Attempt to remove stripes in spectral data",
56  "The files listed in the Set Of Frames (sof-file) "
57  "must be tagged:\n"
58  "VISIR-chopnod-corrected-file.fits "
59  "\nThe product(s) will have a FITS card\n"
60  "'HIERARCH ESO PRO CATG' with a value of:\n");
61 
62 /*----------------------------------------------------------------------------*/
66 /*----------------------------------------------------------------------------*/
67 
68 /*-----------------------------------------------------------------------------
69  Functions code
70  -----------------------------------------------------------------------------*/
71 
72 static inline cpl_boolean
73 plist_strcmp(const cpl_propertylist * plist,
74  const char * key, const char * val)
75 {
76  if (!cpl_propertylist_has(plist, key))
77  return CPL_FALSE;
78  return strcmp(cpl_propertylist_get_string(plist, key), val) == 0;
79 }
80 
81 
82 /*----------------------------------------------------------------------------*/
90 /*----------------------------------------------------------------------------*/
91 static cpl_error_code
92 visir_util_apply_calib_fill_parameterlist(cpl_parameterlist * self)
93 {
94  if (self) {}
95  return CPL_ERROR_NONE;
96 }
97 
98 
99 static cpl_error_code
100 get_img_conv(double * conv, double * error,
101  irplib_framelist * phot_frames)
102 {
103  cpl_vector * v = NULL;
104  double derror = 0.;
105  cpl_errorstate cleanstate = cpl_errorstate_get();
106  irplib_framelist * one_frames = NULL;
107  irplib_framelist * cmb_frames = NULL;
108  cpl_propertylist * cmb_plist;
109 
110  cpl_ensure_code(conv, CPL_ERROR_NULL_INPUT);
111 
112  skip_if(irplib_framelist_load_propertylist_all(phot_frames, 0,
113  "ESO QC", 0));
114 
115  cmb_frames = irplib_framelist_extract(phot_frames,
116  VISIR_IMG_PHOT_COMBINED_PROCATG);
117 
118  skip_if(irplib_framelist_contains(cmb_frames, "ESO QC CONVER",
119  CPL_TYPE_DOUBLE, CPL_FALSE, 0.));
120  cmb_plist = irplib_framelist_get_propertylist(cmb_frames, 0);
121 
122  one_frames = irplib_framelist_extract(phot_frames,
123  VISIR_IMG_PHOT_ONEBEAM_PROCATG);
124  if (one_frames == NULL)
125  cpl_errorstate_set(cleanstate);
126  else {
127  skip_if(irplib_framelist_contains(one_frames, "ESO QC CONVER",
128  CPL_TYPE_DOUBLE, CPL_FALSE, 0.));
129 
130  v = cpl_vector_new(irplib_framelist_get_size(one_frames));
131 
132  for (int i = 0; i < irplib_framelist_get_size(one_frames); i++) {
133  const cpl_propertylist * plist =
135  double conver = cpl_propertylist_get_double(plist, "ESO QC CONVER");
136  skip_if(0);
137 
138  cpl_vector_set(v, i, conver);
139  }
140  }
141 
142  *conv = cpl_propertylist_get_double(cmb_plist, "ESO QC CONVER");
143 
144  if (derror >= 0)
145  cpl_msg_info(cpl_func, "Conversion factor: %g +- %g", *conv, derror);
146  else
147  cpl_msg_info(cpl_func, "Conversion factor: %g", *conv);
148 
149  if (error)
150  *error = derror;
151 
152  end_skip;
153 
154  cpl_vector_delete(v);
155  irplib_framelist_delete(cmb_frames);
156  irplib_framelist_delete(one_frames);
157 
158  return cpl_error_get_code();
159 }
160 
161 static cpl_error_code
162 update_error(cpl_image * eimg_, const cpl_image * img_,
163  const double conv, const double cerror)
164 {
165  cpl_image * img = cpl_image_cast(img_, CPL_TYPE_DOUBLE);
166  cpl_image * eimg = cpl_image_cast(eimg_, CPL_TYPE_DOUBLE);
167  size_t nx = cpl_image_get_size_x(img);
168  size_t npix = nx * cpl_image_get_size_y(img);
169  double * eimgd = cpl_image_get_data_double(eimg);
170  const double * imgd = cpl_image_get_data_double_const(img);
171 
172  cpl_ensure_code(conv != 0. && cerror >= 0., CPL_ERROR_ILLEGAL_INPUT);
173  skip_if(imgd == NULL || eimgd == NULL);
174 
175  for (size_t i = 0; i < npix; i++) {
176  /* gaussian propagation */
177  double da = eimgd[i] / conv;
178  double db = cerror * imgd[i] / (conv * conv);
179  cpl_image_set(eimg_, i % nx + 1, i / nx + 1, hypot(da, db));
180  }
181 
182  end_skip;
183  cpl_image_delete(img);
184  cpl_image_delete(eimg);
185 
186  return cpl_error_get_code();
187 }
188 
189 typedef struct {
190  cpl_image * img;
191  cpl_table * tbl;
192  cpl_propertylist * plist;
193 } visir_plane;
194 
195 static visir_plane *
196 visir_plane_new(cpl_image * img, cpl_table * tbl, cpl_propertylist * plist)
197 {
198  visir_plane * pl = cpl_calloc(1, sizeof(visir_plane));
199  pl->img = img;
200  pl->tbl = tbl;
201  pl->plist = plist;
202  return pl;
203 }
204 
205 static void visir_plane_delete(visir_plane * pl)
206 {
207  if (pl) {
208  cpl_image_delete(pl->img);
209  cpl_table_delete(pl->tbl);
210  cpl_propertylist_delete(pl->plist);
211  cpl_free(pl);
212  }
213 }
214 
215 
216 static cx_list *
217 planelist_from_frame(const cpl_frame * frame)
218 {
219  cpl_size next = cpl_frame_get_nextensions(frame);
220  const char * fn = cpl_frame_get_filename(frame);
221  cpl_errorstate cleanstate = cpl_errorstate_get();
222  cx_list * planelist = NULL;
223  cpl_propertylist * plist = NULL;
224  cpl_image * img = NULL;
225  cpl_table * tbl = NULL;
226 
227  plist = cpl_propertylist_load(fn, 0);
228  skip_if(plist == NULL);
229  planelist = cx_list_new();
230 
231  img = cpl_image_load(fn, CPL_TYPE_UNSPECIFIED, 0, 0);
232  if (img == NULL)
233  cpl_errorstate_set(cleanstate);
234 
235  cx_list_push_back(planelist, visir_plane_new(img, NULL, plist));
236  img = NULL;
237  tbl = NULL;
238  plist = NULL;
239 
240  for (cpl_size e = 1; e < next + 1; e++) {
241  img = cpl_image_load(fn, CPL_TYPE_UNSPECIFIED, 0, e);
242  if (img == 0) {
243  cpl_errorstate_set(cleanstate);
244  tbl = cpl_table_load(fn, e, 0);
245  }
246  skip_if(0);
247  plist = cpl_propertylist_load(fn, e);
248  skip_if(plist == NULL);
249  cx_list_push_back(planelist, visir_plane_new(img, tbl, plist));
250  img = NULL;
251  tbl = NULL;
252  plist = NULL;
253  }
254 
255  end_skip;
256  cpl_image_delete(img);
257  cpl_propertylist_delete(plist);
258 
259  if (cpl_error_get_code() != CPL_ERROR_NONE) {
260  cx_list_destroy(planelist, (visir_free)visir_plane_delete);
261  return NULL;
262  }
263  else
264  return planelist;
265 }
266 
267 
268 static cpl_error_code
269 apply_img_calib(cpl_frameset *framelist, const cpl_parameterlist * parlist,
270  irplib_framelist * objects,
271  const double conv, const double error)
272 {
273  cpl_frameset * usedframes = cpl_frameset_new();
274  cx_list * planes = NULL;
275 
276  for (int i = 0; i < irplib_framelist_get_size(objects); i++) {
277  cpl_frame * frm = irplib_framelist_get(objects, i);
278  cpl_image * eimg = NULL;
279  char buffer[300];
280  visir_plane * skip[] = {NULL, NULL};
281 
282  planes = planelist_from_frame(frm);
283  skip_if(planes == NULL);
284 
285  cpl_frame_set_group(frm, CPL_FRAME_GROUP_RAW);
286  cpl_frameset_insert(usedframes, cpl_frame_duplicate(frm));
287  skip_if(0);
288 
289  visir_plane * first = cx_list_front(planes);
290  cpl_image * simg =
291  cpl_image_multiply_scalar_create(first->img, 1. / conv);
292  skip_if(simg == NULL);
293  cpl_propertylist_update_string(first->plist, "BUNIT", "Jy");
294 
295  sprintf(buffer, "visir_calibrated_%03d.fits", i + 1);
296  irplib_dfs_save_image(framelist, parlist, usedframes, simg,
297  CPL_TYPE_FLOAT, RECIPE_STRING,
298  cpl_frame_get_tag(frm), first->plist,
299  NULL, visir_pipe_id, buffer);
300  cpl_image_delete(simg);
301  skip_if(0);
302 
303  /* propagate the error */
304  FOR_EACH_T(visir_plane * pl, planes) {
305  if (plist_strcmp(pl->plist, "EXTNAME", VISIR_EXTN_ERROR)) {
306  eimg = pl->img;
307 
308  update_error(eimg, first->img, conv, error);
309  cpl_propertylist_update_string(pl->plist, "BUNIT", "Jy");
310 
311  cpl_image_save(eimg, buffer, CPL_TYPE_FLOAT,
312  pl->plist, CPL_IO_EXTEND);
313  skip[0] = pl;
314  }
315  skip_if(0);
316  }
317  /* fix the weight map */
318  FOR_EACH_T(visir_plane * pl, planes) {
319  if (plist_strcmp(pl->plist, "EXTNAME", VISIR_EXTN_WEIGHT)) {
320  cpl_image * wgt = cpl_image_power_create(eimg, -2);
321  cpl_image_fill_rejected(wgt, 0);
322 
323  cpl_image_save(wgt, buffer, CPL_TYPE_FLOAT,
324  pl->plist, CPL_IO_EXTEND);
325  cpl_image_delete(wgt);
326  skip[1] = pl;
327  }
328  skip_if(0);
329  }
330  /* propagate the rest */
331  FOR_EACH_T(visir_plane * pl, planes) {
332  if (pl == first || pl == skip[0] || pl == skip[1])
333  continue;
334 
335  if (pl->img)
336  cpl_image_save(pl->img, buffer, CPL_TYPE_UNSPECIFIED,
337  pl->plist, CPL_IO_EXTEND);
338  else if (pl->tbl)
339  cpl_table_save(pl->tbl, NULL, pl->plist, buffer,
340  CPL_IO_EXTEND);
341  else
342  cpl_propertylist_save(pl->plist, buffer, CPL_IO_EXTEND);
343  skip_if(0);
344  }
345  cx_list_destroy(planes, (visir_free)visir_plane_delete);
346  planes = NULL;
347  }
348 
349  end_skip;
350  cx_list_destroy(planes, (visir_free)visir_plane_delete);
351 
352  cpl_frameset_delete(usedframes);
353 
354  return cpl_error_get_code();
355 }
356 
357 static cpl_error_code
358 propagate_all(cpl_frameset * framelist, const cpl_parameterlist * parlist,
359  irplib_framelist * allframes)
360 {
361  cpl_frameset * usedframes = cpl_frameset_new();
362  cx_list * planes = NULL;
363 
364  for (int i = 0; i < irplib_framelist_get_size(allframes); i++) {
365  cpl_frame * frm = irplib_framelist_get(allframes, i);
366  char buffer[300];
367  sprintf(buffer, "visir_result_%03d.fits", i + 1);
368 
369  cpl_frame_set_group(frm, CPL_FRAME_GROUP_RAW);
370  cpl_frameset_insert(usedframes, cpl_frame_duplicate(frm));
371 
372  planes = planelist_from_frame(frm);
373  skip_if(planes == NULL);
374  visir_plane * first = cx_list_front(planes);
375 
376  if (first->img)
377  irplib_dfs_save_image(framelist, parlist, usedframes, first->img,
378  CPL_TYPE_UNSPECIFIED, RECIPE_STRING,
379  cpl_frame_get_tag(frm), first->plist,
380  NULL, visir_pipe_id, buffer);
381  else
382  irplib_dfs_save_propertylist(framelist, parlist, usedframes,
383  RECIPE_STRING,
384  cpl_frame_get_tag(frm),
385  first->plist, NULL,
386  visir_pipe_id, buffer);
387  skip_if(0);
388 
389  FOR_EACH_T(visir_plane * pl, planes) {
390  if (pl == first)
391  continue;
392  if (pl->img)
393  cpl_image_save(pl->img, buffer, CPL_TYPE_UNSPECIFIED,
394  pl->plist, CPL_IO_EXTEND);
395  else if (pl->tbl)
396  cpl_table_save(pl->tbl, NULL, pl->plist, buffer,
397  CPL_IO_EXTEND);
398  else
399  cpl_propertylist_save(pl->plist, buffer, CPL_IO_EXTEND);
400  skip_if(0);
401  }
402 
403  cx_list_destroy(planes, (visir_free)visir_plane_delete);
404  planes = NULL;
405  }
406 
407  end_skip;
408  cpl_frameset_delete(usedframes);
409  cx_list_destroy(planes, (visir_free)visir_plane_delete);
410 
411  return cpl_error_get_code();
412 }
413 
414 
415 static cpl_table *
416 calibrate_frame(const cpl_frame * frm, const cpl_bivector * std,
417  const cpl_bivector * stde)
418 {
419  const char * dfn = cpl_frame_get_filename(frm);
420  const cpl_vector * swlen = cpl_bivector_get_x_const(std);
421  cpl_bivector * intstd = NULL;
422  cpl_bivector * intstde = NULL;
423  cpl_table * obj = cpl_table_load(dfn, 1, 0);
424  skip_if(obj == NULL);
425  const size_t n = cpl_table_get_nrow(obj);
426 
427  /* get region where calib and object wavelength overlap */
428  cpl_vector * objv =
429  cpl_vector_wrap(n, cpl_table_get_data_double(obj, "WLEN"));
430 
431  const double smin = cpl_vector_get(swlen, 0);
432  const double smax = cpl_vector_get(swlen, cpl_vector_get_size(swlen) - 1);
433  const size_t l = visir_lower_bound(objv, smin);
434  const size_t u = visir_upper_bound(objv, smax);
435 
436  if (u - l == 0) {
437  cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
438  "Calibration data has no wavelength overlap "
439  "with object");
440  cpl_vector_unwrap(objv);
441  skip_if(1);
442  }
443  cpl_msg_info(cpl_func, "Overlapping wavelength: %.4g [mu] (%zu) to "
444  "%.4g [mu] (%zu)", cpl_vector_get(objv, l) * 1e6, l,
445  cpl_vector_get(objv, u - 1) * 1e6, u);
446  cpl_vector_unwrap(objv);
447 
448  {
449  /* prepare data and error on same grid as object */
450  intstd = cpl_bivector_new(u - l);
451  intstde = cpl_bivector_new(u - l);
452  skip_if(intstd == NULL);
453  skip_if(intstde == NULL);
454  /* copy object wavelength grid */
455  memcpy(cpl_bivector_get_x_data(intstd),
456  cpl_table_get_data_double_const(obj, "WLEN") + l,
457  sizeof(double) * (u - l));
458  memcpy(cpl_bivector_get_x_data(intstde),
459  cpl_table_get_data_double_const(obj, "WLEN") + l,
460  sizeof(double) * (u - l));
461 
462  /* interpolate standard star data to object wavelength grid */
463  skip_if(cpl_bivector_interpolate_linear(intstd, std));
464  skip_if(cpl_bivector_interpolate_linear(intstde, stde));
465  }
466 
467  skip_if(0);
468 
469  /* calibrate the data, marking out of bound as invalid */
470  cpl_table_duplicate_column(obj, "SPC_CALIBRATED",
471  obj, "SPC_EXTRACTED");
472  skip_if(0);
473  {
474  double * d = cpl_table_get_data_double(obj, "SPC_CALIBRATED");
475  double * v = cpl_vector_get_data(cpl_bivector_get_y(intstd));
476  for (size_t i = 0; i < n; i++) {
477  if (i < l || i >= u)
478  cpl_table_set_invalid(obj, "SPC_CALIBRATED", i);
479  else
480  d[i] /= v[i - l];
481  }
482  }
483 
484  cpl_table_new_column(obj, "SPC_CALIBRATED_ERROR", CPL_TYPE_DOUBLE);
485  skip_if(0);
486 
487  {
488  double * ed = cpl_table_get_data_double(obj, "SPC_ERROR");
489  double * vd = cpl_table_get_data_double(obj, "SPC_EXTRACTED");
490  double * svd = cpl_bivector_get_y_data(intstd);
491  double * sed = cpl_bivector_get_y_data(intstde);
492  for (size_t j = 0; j < n; j++) {
493  if (j < l || j >= u)
494  cpl_table_set_invalid(obj, "SPC_CALIBRATED_ERROR", j);
495  else {
496  double da = ed[j] / svd[j - l];
497  double db = sed[j - l] * vd[j] / (svd[j - l] * svd[j - l]);
498  cpl_table_set_double(obj, "SPC_CALIBRATED_ERROR",
499  j, hypot(da, db));
500  }
501  }
502  }
503 
504  skip_if(0);
505 
506  end_skip;
507 
508  cpl_bivector_delete(intstd);
509  cpl_bivector_delete(intstde);
510 
511  return obj;
512 }
513 
514 static cpl_error_code
515 get_spec_std(cpl_frameset * framelist,
516  const irplib_framelist * stdtab,
517  const irplib_framelist * objtab,
518  const cpl_parameterlist * parlist,
519  const char * procatg)
520 {
521  const cpl_frame * frm;
522  cpl_bivector * std = NULL;
523  cpl_bivector * stde = NULL;
524  skip_if(stdtab == NULL);
525  skip_if(objtab == NULL);
526  cpl_ensure_code(irplib_framelist_get_size(stdtab) == 1,
527  CPL_ERROR_UNSUPPORTED_MODE);
528  cpl_ensure_code(irplib_framelist_get_size(objtab) > 0,
529  CPL_ERROR_UNSUPPORTED_MODE);
530 
531  frm = irplib_framelist_get_const(stdtab, 0);
532  skip_if(frm == NULL);
533  {
534  const char * fn = cpl_frame_get_filename(frm);
535  cpl_bivector * model = visir_bivector_load_fits(fn, "WLEN",
536  "STD_STAR_MODEL", 1);
537  std = visir_bivector_load_fits(fn, "WLEN", "SPC_EXTRACTED", 1);
538  stde = visir_bivector_load_fits(fn, "WLEN", "SPC_ERROR", 1);
539 
540  /* calibrate spectrum, FIXME: do in spc_obs? */
541  cpl_vector_divide(cpl_bivector_get_y(std), cpl_bivector_get_y(model));
542  cpl_vector_divide(cpl_bivector_get_y(stde), cpl_bivector_get_y(model));
543  cpl_bivector_delete(model);
544  }
545  skip_if(0);
546 
547  for (int i = 0; i < irplib_framelist_get_size(objtab); i++) {
548  char buffer[300];
549  cpl_frame * ofrm =
550  cpl_frame_duplicate(irplib_framelist_get_const(objtab, i));
551  cpl_frame * sfrm = cpl_frame_duplicate(frm);
552  cpl_frameset * usedframes = cpl_frameset_new();
553  cpl_frame_set_group(sfrm, CPL_FRAME_GROUP_CALIB);
554  cpl_frame_set_group(ofrm, CPL_FRAME_GROUP_RAW);
555  cpl_frameset_insert(usedframes, sfrm);
556  cpl_frameset_insert(usedframes, ofrm);
557 
558  cpl_table * obj = calibrate_frame(ofrm, std, stde);
559  sprintf(buffer, "visir_calibrated_%03d.fits", i + 1);
560  irplib_dfs_save_table(framelist, parlist, usedframes, obj,
561  NULL, RECIPE_STRING, procatg, NULL,/* todo*/
562  NULL, visir_pipe_id, buffer);
563 
564  /* add the image and extraction weight too (see visir_spc_obs_save) */
565  if (cpl_frame_get_nextensions(ofrm) == 3) {
566  cpl_propertylist * plist =
567  cpl_propertylist_load(cpl_frame_get_filename(ofrm), 2);
568  cpl_image * img = cpl_image_load(cpl_frame_get_filename(ofrm),
569  CPL_TYPE_UNSPECIFIED, 0, 2);
570  cpl_image_save(img, buffer, CPL_TYPE_UNSPECIFIED, plist, CPL_IO_EXTEND);
571  cpl_image_delete(img);
572  cpl_propertylist_delete(plist);
573  plist = cpl_propertylist_load(cpl_frame_get_filename(ofrm), 2);
574  img = cpl_image_load(cpl_frame_get_filename(ofrm),
575  CPL_TYPE_UNSPECIFIED, 0, 2);
576  cpl_image_save(img, buffer, CPL_TYPE_UNSPECIFIED, plist, CPL_IO_EXTEND);
577  cpl_image_delete(img);
578  cpl_propertylist_delete(plist);
579  }
580 
581  cpl_frameset_delete(usedframes);
582  cpl_table_delete(obj);
583  skip_if(0);
584  }
585 
586  end_skip;
587 
588  cpl_bivector_delete(std);
589  cpl_bivector_delete(stde);
590 
591  return cpl_error_get_code();
592 }
593 
594 
595 /*----------------------------------------------------------------------------*/
602 /*----------------------------------------------------------------------------*/
603 static int visir_util_apply_calib(cpl_frameset * framelist,
604  const cpl_parameterlist * parlist)
605 {
606  irplib_framelist * allframes = irplib_framelist_cast(framelist);
607  cpl_errorstate cleanstate = cpl_errorstate_get();
608 
609  irplib_framelist * others = NULL;
610  irplib_framelist * objects =
611  irplib_framelist_extract_regexp(allframes, ".*OBJ.*", CPL_FALSE);
612  irplib_framelist * specobs =
613  irplib_framelist_extract_regexp(allframes, ".*SPC_OBS.*", CPL_FALSE);
614 
615  if (irplib_framelist_get_size(allframes) > 0)
616  cpl_errorstate_set(cleanstate);
617 
618  /* no objects or only objects -> nothing to apply */
619  if (objects && irplib_framelist_get_size(objects) <
620  irplib_framelist_get_size(allframes)) {
621  double conv = 1., error = 0.;
622  cpl_msg_info(cpl_func, "Applying conversion factor");
623  skip_if(get_img_conv(&conv, &error, allframes));
624  skip_if(apply_img_calib(framelist, parlist, objects, conv, error));
625  others = irplib_framelist_extract_regexp(allframes, ".*OBJ.*", CPL_TRUE);
626  skip_if(propagate_all(framelist, parlist, others));
627  }
628  else if (specobs && irplib_framelist_get_size(specobs) <
629  irplib_framelist_get_size(allframes)) {
630  irplib_framelist * stdtab =
631  irplib_framelist_extract_regexp(allframes, ".*PHOT.*TAB", CPL_FALSE);
632  irplib_framelist * objtab =
633  irplib_framelist_extract_regexp(allframes, ".*OBS.*TAB", CPL_FALSE);
634  cpl_msg_info(cpl_func, "Removing telluric lines");
635  skip_if(get_spec_std(framelist, stdtab, objtab,
636  parlist, "SPC_OBS_LMR_TAB"));
637  others = irplib_framelist_extract_regexp(allframes, ".*OBS.*TAB", CPL_TRUE);
638  propagate_all(framelist, parlist, others);
639  irplib_framelist_delete(objtab);
640  irplib_framelist_delete(stdtab);
641  skip_if(0);
642  }
643  else {
644  cpl_msg_info(cpl_func, "No calibration data to apply, doing nothing");
645  skip_if(propagate_all(framelist, parlist, allframes));
646  }
647 
648  end_skip;
649  irplib_framelist_delete(allframes);
650  irplib_framelist_delete(objects);
651  irplib_framelist_delete(specobs);
652  irplib_framelist_delete(others);
653 
654  return cpl_error_get_code();
655 }
cpl_error_code irplib_dfs_save_table(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_table *table, const cpl_propertylist *tablelist, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)
Save a table as a DFS-compliant pipeline product.
Definition: irplib_utils.c:335
cpl_error_code irplib_dfs_save_propertylist(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)
Save a propertylist as a DFS-compliant pipeline product.
Definition: irplib_utils.c:240
irplib_framelist * irplib_framelist_extract_regexp(const irplib_framelist *self, const char *regexp, cpl_boolean invert)
Extract the frames with the given tag from a framelist.
const cpl_propertylist * irplib_framelist_get_propertylist_const(const irplib_framelist *self, int pos)
Get the propertylist of the specified frame in the framelist.
cpl_error_code irplib_dfs_save_image(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_image *image, cpl_type_bpp bpp, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)
Save an image as a DFS-compliant pipeline product.
Definition: irplib_utils.c:192
cpl_error_code irplib_framelist_load_propertylist_all(irplib_framelist *self, int ind, const char *regexp, cpl_boolean invert)
Load the propertylists of all frames in the framelist.
cpl_frame * irplib_framelist_get(irplib_framelist *self, int pos)
Get the specified frame from the framelist.
irplib_framelist * irplib_framelist_extract(const irplib_framelist *self, const char *tag)
Extract the frames with the given tag from a framelist.
const cpl_frame * irplib_framelist_get_const(const irplib_framelist *self, int pos)
Get the specified frame from the framelist.
void irplib_framelist_delete(irplib_framelist *self)
Deallocate an irplib_framelist with its frames and properties.
cpl_error_code irplib_framelist_contains(const irplib_framelist *self, const char *key, cpl_type type, cpl_boolean is_equal, double fp_tol)
Verify that a property is present for all frames.
cpl_propertylist * irplib_framelist_get_propertylist(irplib_framelist *self, int pos)
Get the propertylist of the specified frame in the framelist.
irplib_framelist * irplib_framelist_cast(const cpl_frameset *frameset)
Create an irplib_framelist from a cpl_framelist.
int irplib_framelist_get_size(const irplib_framelist *self)
Get the size of a framelist.