VIRCAM Pipeline 2.3.12
vircam_dome_flat_combine.c
1/* $Id: vircam_dome_flat_combine.c,v 1.58 2012-01-16 12:32:18 jim Exp $
2 *
3 * This file is part of the VIRCAM Pipeline
4 * Copyright (C) 2015 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: jim $
23 * $Date: 2012-01-16 12:32:18 $
24 * $Revision: 1.58 $
25 * $Name: not supported by cvs2svn $
26 */
27
28/* Includes */
29
30#ifdef HAVE_CONFIG_H
31#include <config.h>
32#endif
33
34#include <stdio.h>
35#include <cpl.h>
36#include <math.h>
37
38#include <casu_utils.h>
39#include <casu_mask.h>
40#include <casu_mods.h>
41#include <casu_stats.h>
42#include <casu_wcsutils.h>
43
44#include "vircam_utils.h"
45#include "vircam_pfits.h"
46#include "vircam_dfs.h"
47#include "vircam_mods.h"
48#include "vircam_channel.h"
49#include "vircam_paf.h"
50
51/* Define values for bit mask that flags dummy results */
52
53#define MEANDOME 1
54#define RATIMG 2
55#define STATS_TAB 4
56
57/* Function prototypes */
58
59static int vircam_dome_flat_combine_create(cpl_plugin *) ;
60static int vircam_dome_flat_combine_exec(cpl_plugin *) ;
61static int vircam_dome_flat_combine_destroy(cpl_plugin *) ;
62static int vircam_dome_flat_combine(cpl_parameterlist *, cpl_frameset *) ;
63static int vircam_dome_flat_combine_save(cpl_frameset *framelist,
64 cpl_parameterlist *parlist);
65static void vircam_dome_flat_combine_dummy_products(void);
66static void vircam_dome_flat_combine_normal(int jext);
67static int vircam_dome_flat_combine_lastbit(int jext, cpl_frameset *framelist,
68 cpl_parameterlist *parlist);
69static void vircam_dome_flat_combine_init(void);
70static void vircam_dome_flat_combine_tidy(int level);
71
72/* Static global variables */
73
74static struct {
75
76 /* Input */
77
78 float lthr;
79 float hthr;
80 int combtype;
81 int scaletype;
82 int xrej;
83 float thresh;
84 int ncells;
85 int extenum;
86
87 /* Output */
88
89 float flatrms;
90 float flatratio_med;
91 float flatratio_rms;
92 float minv;
93 float maxv;
94 float avev;
95
96} vircam_dome_flat_combine_config;
97
98
99static struct {
100 cpl_size *labels;
101 cpl_frameset *domelist;
102 cpl_frame *master_dark;
103 cpl_frame *master_dome_flat;
104 cpl_frame *chantab;
105 casu_fits **good;
106 int ngood;
107 casu_mask *master_mask;
108 cpl_image *outimage;
109 casu_fits **domes;
110 int ndomes;
111 cpl_propertylist *drs;
112 unsigned char *rejmask;
113 unsigned char *rejplus;
114 casu_tfits *ctable;
115 casu_fits *mfimage;
116 casu_fits *mdark;
117 cpl_image *ratioimg;
118 cpl_table *ratioimstats;
119 cpl_propertylist *phupaf;
120} ps;
121
122static int isfirst;
123static cpl_frame *product_frame_mean_dome = NULL;
124static cpl_frame *product_frame_ratioimg = NULL;
125static cpl_frame *product_frame_ratioimg_stats = NULL;
126static int we_expect;
127static int we_get;
128
129static char vircam_dome_flat_combine_description[] =
130"vircam_dome_flat_combine -- VIRCAM dome flat combine recipe.\n\n"
131"Combine a list of dome flat frames into a mean frame. Optionally compare \n"
132"the output frame to a master dome flat frame\n\n"
133"The program accepts the following files in the SOF:\n\n"
134" Tag Description\n"
135" -----------------------------------------------------------------------\n"
136" %-21s A list of raw dome flat images\n"
137" %-21s A master dark frame\n"
138" %-21s Optional reference dome flat frame\n"
139" %-21s Optional channel table or\n"
140" %-21s Optional initial channel table\n"
141" %-21s Optional master bad pixel map or\n"
142" %-21s Optional master confidence map\n"
143"If no master dome flat is made available, then no comparison will be done\n"
144"This means there will be no output ratio image. If a master dome is\n"
145"available, but no channel table is, then a ratio image will be formed\n"
146"but no stats will be written."
147"\n";
148
282/* Function code */
283
284/*---------------------------------------------------------------------------*/
292/*---------------------------------------------------------------------------*/
293
294int cpl_plugin_get_info(cpl_pluginlist *list) {
295 cpl_recipe *recipe = cpl_calloc(1,sizeof(*recipe));
296 cpl_plugin *plugin = &recipe->interface;
297 char alldesc[SZ_ALLDESC];
298 (void)snprintf(alldesc,SZ_ALLDESC,vircam_dome_flat_combine_description,
299 VIRCAM_DOME_RAW,VIRCAM_CAL_DARK,VIRCAM_REF_DOME_FLAT,
300 VIRCAM_CAL_CHANTAB,VIRCAM_CAL_CHANTAB_INIT,VIRCAM_CAL_BPM,
301 VIRCAM_CAL_CONF);
302
303 cpl_plugin_init(plugin,
304 CPL_PLUGIN_API,
305 VIRCAM_BINARY_VERSION,
306 CPL_PLUGIN_TYPE_RECIPE,
307 "vircam_dome_flat_combine",
308 "VIRCAM dome flat combination recipe",
309 alldesc,
310 "Jim Lewis",
311 "jrl@ast.cam.ac.uk",
313 vircam_dome_flat_combine_create,
314 vircam_dome_flat_combine_exec,
315 vircam_dome_flat_combine_destroy);
316
317 cpl_pluginlist_append(list,plugin);
318
319 return(0);
320}
321
322/*---------------------------------------------------------------------------*/
331/*---------------------------------------------------------------------------*/
332
333static int vircam_dome_flat_combine_create(cpl_plugin *plugin) {
334 cpl_recipe *recipe;
335 cpl_parameter *p;
336
337 /* Get the recipe out of the plugin */
338
339 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
340 recipe = (cpl_recipe *)plugin;
341 else
342 return(-1);
343
344 /* Create the parameters list in the cpl_recipe object */
345
346 recipe->parameters = cpl_parameterlist_new();
347
348 /* Lower threshold for rejecting underexposed images */
349
350 p = cpl_parameter_new_value("vircam.vircam_dome_flat_combine.lthr",
351 CPL_TYPE_DOUBLE,
352 "Low rejection threshold for underexpsed images",
353 "vircam.vircam_dome_flat_combine",
354 0.0);
355 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"lthr");
356 cpl_parameterlist_append(recipe->parameters,p);
357
358 /* Upper threshold for rejecting overexposed images */
359
360 p = cpl_parameter_new_value("vircam.vircam_dome_flat_combine.hthr",
361 CPL_TYPE_DOUBLE,
362 "High rejection threshold for overexposed images",
363 "vircam.vircam_dome_flat_combine",
364 65535.0);
365 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"hthr");
366 cpl_parameterlist_append(recipe->parameters,p);
367
368 /* Fill in the parameters. First the combination type */
369
370 p = cpl_parameter_new_range("vircam.vircam_dome_flat_combine.combtype",
371 CPL_TYPE_INT,
372 "1 == Median,\n 2 == Mean",
373 "vircam.vircam_dome_flat_combine",
374 1,1,2);
375 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"combtype");
376 cpl_parameterlist_append(recipe->parameters,p);
377
378 /* The requested scaling */
379
380 p = cpl_parameter_new_range("vircam.vircam_dome_flat_combine.scaletype",
381 CPL_TYPE_INT,
382 "0 == none,\n 1 == additive offset,\n 2 == multiplicative offset,\n 3 == exposure time scaling + additive offset",
383 "vircam.vircam_dome_flat_combine",
384 1,0,3);
385 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"scaletype");
386 cpl_parameterlist_append(recipe->parameters,p);
387
388 /* Extra rejection cycle */
389
390 p = cpl_parameter_new_value("vircam.vircam_dome_flat_combine.xrej",
391 CPL_TYPE_BOOL,
392 "True if using extra rejection cycle",
393 "vircam.vircam_dome_flat_combine",
394 TRUE);
395 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"xrej");
396 cpl_parameterlist_append(recipe->parameters,p);
397
398 /* Rejection threshold */
399
400 p = cpl_parameter_new_value("vircam.vircam_dome_flat_combine.thresh",
401 CPL_TYPE_DOUBLE,
402 "Rejection threshold in sigma above background",
403 "vircam.vircam_dome_flat_combine",5.0);
404 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"thresh");
405 cpl_parameterlist_append(recipe->parameters,p);
406
407 /* How many cells to divide each data channel */
408
409 p = cpl_parameter_new_enum("vircam.vircam_dome_flat_combine.ncells",
410 CPL_TYPE_INT,
411 "Number of cells for data channel stats",
412 "vircam.vircam_dome_flat_combine",8,7,1,2,4,8,
413 16,32,64);
414 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"ncells");
415 cpl_parameterlist_append(recipe->parameters,p);
416
417 /* Extension number of input frames to use */
418
419 p = cpl_parameter_new_range("vircam.vircam_dome_flat_combine.extenum",
420 CPL_TYPE_INT,
421 "Extension number to be done, 0 == all",
422 "vircam.vircam_dome_flat_combine",
423 0,0,16);
424 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"ext");
425 cpl_parameterlist_append(recipe->parameters,p);
426
427 /* Get out of here */
428
429 return(0);
430}
431
432
433/*---------------------------------------------------------------------------*/
439/*---------------------------------------------------------------------------*/
440
441static int vircam_dome_flat_combine_exec(cpl_plugin *plugin) {
442 cpl_recipe *recipe;
443
444 /* Get the recipe out of the plugin */
445
446 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
447 recipe = (cpl_recipe *)plugin;
448 else
449 return(-1);
450
451 return(vircam_dome_flat_combine(recipe->parameters,recipe->frames));
452}
453
454/*---------------------------------------------------------------------------*/
460/*---------------------------------------------------------------------------*/
461
462static int vircam_dome_flat_combine_destroy(cpl_plugin *plugin) {
463 cpl_recipe *recipe ;
464
465 /* Get the recipe out of the plugin */
466
467 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
468 recipe = (cpl_recipe *)plugin;
469 else
470 return(-1);
471
472 cpl_parameterlist_delete(recipe->parameters);
473 return(0);
474}
475
476/*---------------------------------------------------------------------------*/
483/*---------------------------------------------------------------------------*/
484
485static int vircam_dome_flat_combine(cpl_parameterlist *parlist,
486 cpl_frameset *framelist) {
487 const char *fctid="vircam_dome_flat_combine";
488 int j,jst,jfn,retval,status,live,nx,ny,ndit;
489 cpl_size nlab;
490 long i;
491 cpl_parameter *p;
492 cpl_propertylist *pp;
493 casu_fits *ff;
494
495 /* Check validity of input frameset */
496
497 if (framelist == NULL || cpl_frameset_get_size(framelist) <= 0) {
498 cpl_msg_error(fctid,"Input framelist NULL or has no input data");
499 return(-1);
500 }
501
502 /* Initialise some things */
503
504 vircam_dome_flat_combine_init();
505 we_expect = MEANDOME;
506
507 /* Get the parameters */
508
509 p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.lthr");
510 vircam_dome_flat_combine_config.lthr = (float)cpl_parameter_get_double(p);
511 p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.hthr");
512 vircam_dome_flat_combine_config.hthr = (float)cpl_parameter_get_double(p);
513 p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.combtype");
514 vircam_dome_flat_combine_config.combtype = cpl_parameter_get_int(p);
515 p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.scaletype");
516 vircam_dome_flat_combine_config.scaletype = cpl_parameter_get_int(p);
517 p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.xrej");
518 vircam_dome_flat_combine_config.xrej = cpl_parameter_get_bool(p);
519 p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.thresh");
520 vircam_dome_flat_combine_config.thresh = (float)cpl_parameter_get_double(p);
521 p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.ncells");
522 vircam_dome_flat_combine_config.ncells = cpl_parameter_get_int(p);
523 p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.extenum");
524 vircam_dome_flat_combine_config.extenum = cpl_parameter_get_int(p);
525
526 /* Sort out raw from calib frames */
527
528 if (vircam_dfs_set_groups(framelist) != CASU_OK) {
529 cpl_msg_error(fctid,"Cannot identify RAW and CALIB frames");
530 vircam_dome_flat_combine_tidy(2);
531 return(-1);
532 }
533
534 /* Get the dome frames */
535
536 if ((ps.labels = cpl_frameset_labelise(framelist,casu_compare_tags,
537 &nlab)) == NULL) {
538 cpl_msg_error(fctid,"Cannot labelise the input frames");
539 vircam_dome_flat_combine_tidy(2);
540 return(-1);
541 }
542 if ((ps.domelist = casu_frameset_subgroup(framelist,ps.labels,nlab,
543 VIRCAM_DOME_RAW)) == NULL) {
544 cpl_msg_error(fctid,"Cannot find dome frames in input frameset");
545 vircam_dome_flat_combine_tidy(2);
546 return(-1);
547 }
548 ps.ndomes = cpl_frameset_get_size(ps.domelist);
549
550 /* Check to see if there is a master dark frame */
551
552 if ((ps.master_dark = casu_frameset_subgroup_1(framelist,ps.labels,nlab,
553 VIRCAM_CAL_DARK)) == NULL) {
554 cpl_msg_error(fctid,"No master dark found");
555 vircam_dome_flat_combine_tidy(2);
556 return(-1);
557 }
558
559 /* Check to see if there is a master dome flat frame */
560
561 if ((ps.master_dome_flat = casu_frameset_subgroup_1(framelist,ps.labels,
562 nlab,VIRCAM_REF_DOME_FLAT)) == NULL)
563 cpl_msg_info(fctid,"No master dome flat found -- no ratio image will be formed");
564 else
565 we_expect |= RATIMG;
566
567 /* Check to see if there is a master bad pixel map. If there isn't one
568 then look for a confidence map */
569
570 ps.master_mask = casu_mask_define(framelist,ps.labels,nlab,VIRCAM_CAL_CONF,
571 VIRCAM_CAL_BPM);
572
573 /* Check to see if there is a channel table */
574
575 if ((ps.chantab = casu_frameset_subgroup_1(framelist,ps.labels,nlab,
576 VIRCAM_CAL_CHANTAB)) == NULL) {
577 if ((ps.chantab = casu_frameset_subgroup_1(framelist,ps.labels,nlab,
578 VIRCAM_CAL_CHANTAB_INIT)) == NULL) {
579 cpl_msg_info(fctid,"No channel table found -- no ratio image stats and no linearisation will be done");
580 } else {
581 cpl_msg_info(fctid,"Channel table is labelled INIT -- no linearisation will be done");
582 if (we_expect & RATIMG)
583 we_expect |= STATS_TAB;
584 }
585 } else if (we_expect & RATIMG) {
586 we_expect |= STATS_TAB;
587 }
588
589 /* Now, how many image extensions do we want to do? If the extension
590 number is zero, then we loop for all possible extensions. If it
591 isn't then we just do the extension specified */
592
593 vircam_exten_range(vircam_dome_flat_combine_config.extenum,
594 (const cpl_frame *)cpl_frameset_get_position(ps.domelist,0),
595 &jst,&jfn);
596 if (jst == -1 || jfn == -1) {
597 cpl_msg_error(fctid,"Unable to continue");
598 vircam_dome_flat_combine_tidy(2);
599 return(-1);
600 }
601
602 /* Get the number of DITs */
603
604 pp = cpl_propertylist_load(cpl_frame_get_filename(cpl_frameset_get_position(ps.domelist,0)),0);
605 if (vircam_pfits_get_ndit(pp,&ndit) != CASU_OK) {
606 cpl_msg_error(fctid,"No value for NDIT available");
607 freepropertylist(pp);
608 vircam_dome_flat_combine_tidy(2);
609 return(-1);
610 }
611 cpl_propertylist_delete(pp);
612
613 /* Get some space for the good frames */
614
615 ps.good = cpl_malloc(ps.ndomes*sizeof(casu_fits *));
616
617 /* Now loop for all the extension... */
618
619 for (j = jst; j <= jfn; j++) {
620 status = CASU_OK;
621 we_get = 0;
622 isfirst = (j == jst);
623
624 /* Load the images and the master dark. */
625
626 ps.domes = casu_fits_load_list(ps.domelist,CPL_TYPE_FLOAT,j);
627 if (ps.domes == NULL) {
628 cpl_msg_info(fctid,
629 "Extension %" CPL_SIZE_FORMAT " domes wouldn't load",
630 (cpl_size)j);
631 retval = vircam_dome_flat_combine_lastbit(j,framelist,parlist);
632 if (retval != 0)
633 return(-1);
634 continue;
635 }
636
637 /* Are any of these dome flats any good? */
638
639 ps.ngood = 0;
640 for (i = 0; i < ps.ndomes; i++) {
641 ff = ps.domes[i];
643 if (! live) {
644 cpl_msg_info(fctid,"Detector flagged dead %s",
646 casu_fits_set_error(ff,CASU_FATAL);
647 } else {
648 ps.good[ps.ngood] = ff;
649 ps.ngood += 1;
650 }
651 }
652
653 /* If there are no good images, then signal that we need to create
654 dummy products and move on */
655
656 if (ps.ngood == 0) {
657 cpl_msg_info(fctid,"All images flagged bad for this extension");
658 retval = vircam_dome_flat_combine_lastbit(j,framelist,parlist);
659 if (retval != 0)
660 return(-1);
661 continue;
662 }
663
664 /* Load the mask */
665
666 nx = (int)cpl_image_get_size_x(casu_fits_get_image(ps.good[0]));
667 ny = (int)cpl_image_get_size_y(casu_fits_get_image(ps.good[0]));
668 if (casu_mask_load(ps.master_mask,j,nx,ny) == CASU_FATAL) {
669 cpl_msg_info(fctid,
670 "Unable to load mask image %s[%" CPL_SIZE_FORMAT "]",
671 casu_mask_get_filename(ps.master_mask),(cpl_size)j);
672 cpl_msg_info(fctid,"Forcing all pixels to be good from now on");
673 casu_mask_force(ps.master_mask,nx,ny);
674 }
675
676 /* Sort out the images that are either over or under exposed */
677
678 casu_overexp(ps.good,&(ps.ngood),ndit,
679 vircam_dome_flat_combine_config.lthr,
680 vircam_dome_flat_combine_config.hthr,0,
681 &(vircam_dome_flat_combine_config.minv),
682 &(vircam_dome_flat_combine_config.maxv),
683 &(vircam_dome_flat_combine_config.avev));
684
685 /* Check to see how many are left. If there aren't any, then
686 signal a major error */
687
688 if (ps.ngood == 0) {
689 cpl_msg_info(fctid,"All images either under or overexposed");
690 retval = vircam_dome_flat_combine_lastbit(j,framelist,parlist);
691 if (retval != 0)
692 return(-1);
693 continue;
694 }
695
696 /* Right, we want to dark correct, so we need to load the mean
697 dark and make sure it isn't a dummy */
698
699 ps.mdark = casu_fits_load(ps.master_dark,CPL_TYPE_FLOAT,j);
700 if (ps.mdark == NULL) {
701 cpl_msg_info(fctid,
702 "Can't load master dark for extension %" CPL_SIZE_FORMAT,
703 (cpl_size)j);
704 retval = vircam_dome_flat_combine_lastbit(j,framelist,parlist);
705 if (retval != 0)
706 return(-1);
707 continue;
708 } else if (vircam_is_dummy(casu_fits_get_ehu(ps.mdark))) {
709 cpl_msg_info(fctid,
710 "Can't master dark extension %" CPL_SIZE_FORMAT " is a dummy",
711 (cpl_size)j);
712 retval = vircam_dome_flat_combine_lastbit(j,framelist,parlist);
713 if (retval != 0)
714 return(-1);
715 continue;
716 }
717
718 /* Loop for each image and dark correct */
719
720 cpl_msg_info(fctid,"Dark correcting extension %" CPL_SIZE_FORMAT,
721 (cpl_size)j);
722 for (i = 0; i < ps.ngood; i++)
723 casu_darkcor((ps.good)[i],ps.mdark,1.0,&status);
724
725 /* We need to load the channel table (if it exists) for linearisation
726 and for the ratio image stats table */
727
728 if (ps.chantab != NULL) {
729 ps.ctable = casu_tfits_load(ps.chantab,j);
730 if (ps.ctable == NULL) {
731 cpl_msg_info(fctid,
732 "Channel table extension %" CPL_SIZE_FORMAT " won't load",
733 (cpl_size)j);
734 } else if (vircam_chantab_verify(casu_tfits_get_table(ps.ctable)) != CASU_OK) {
735 cpl_msg_info(fctid,
736 "Channel table extension %" CPL_SIZE_FORMAT " has errors",
737 (cpl_size)j);
738 freetfits(ps.ctable);
739 } else {
740 pp = cpl_propertylist_load(cpl_frame_get_filename(ps.chantab),
741 (cpl_size)j);
742 if (vircam_is_dummy(pp)) {
743 cpl_msg_info(fctid,
744 "Channel table extensions %" CPL_SIZE_FORMAT " is a dummy",
745 (cpl_size)j);
746 freetfits(ps.ctable);
747 }
748 freepropertylist(pp);
749 }
750 } else
751 ps.ctable = NULL;
752
753 /* Loop for each of the input images and linearise it if there
754 is a channel table */
755
756 if (ps.ctable != NULL) {
757 cpl_msg_info(fctid,"Linearising extension %" CPL_SIZE_FORMAT,
758 (cpl_size)j);
759 for (i = 0; i < ps.ngood; i++)
760 (void)vircam_lincor((ps.good)[i],ps.ctable,1,ndit,&status);
761 }
762
763 /* Correct for ndit */
764
765 for (i = 0; i < ps.ngood; i++)
766 (void)casu_nditcor((ps.good)[i],ndit,"EXPTIME",&status);
767
768 /* Call the combine module */
769
770 cpl_msg_info(fctid,"Doing combination for extension %" CPL_SIZE_FORMAT,
771 (cpl_size)j);
772 (void)casu_imcombine(ps.good,NULL,ps.ngood,
773 vircam_dome_flat_combine_config.combtype,
774 vircam_dome_flat_combine_config.scaletype,
775 vircam_dome_flat_combine_config.xrej,
776 vircam_dome_flat_combine_config.thresh,"EXPTIME",
777 &(ps.outimage),NULL,&(ps.rejmask),&(ps.rejplus),
778 &(ps.drs),&status);
779
780 /* If these correction and combination routines failed at any stage
781 then get out of here */
782
783 if (status == CASU_OK) {
784 we_get |= MEANDOME;
785 vircam_dome_flat_combine_normal(j);
786 } else {
787 cpl_msg_info(fctid,"A processing step failed");
788 }
789
790 /* Create any dummies and save the products */
791
792 retval = vircam_dome_flat_combine_lastbit(j,framelist,parlist);
793 if (retval != 0)
794 return(-1);
795
796 }
797 vircam_dome_flat_combine_tidy(2);
798 return(0);
799}
800
801
802/*---------------------------------------------------------------------------*/
809/*---------------------------------------------------------------------------*/
810
811static int vircam_dome_flat_combine_save(cpl_frameset *framelist,
812 cpl_parameterlist *parlist) {
813 cpl_propertylist *plist,*elist,*p,*paf;
814 float val;
815 const char *fctid = "vircam_dome_flat_combine_save";
816 const char *outfile = "domecomb.fits";
817 const char *outdiff = "domeratio.fits";
818 const char *outdimst = "domeratiotab.fits";
819 const char *outpaf = "domecomb";
820 const char *outdpaf = "domeratio";
821 const char *recipeid = "vircam_dome_flat_combine";
822
823 /* If we need to make a PHU then do that now based on the first frame
824 in the input frame list */
825
826 if (isfirst) {
827
828 /* Create a new product frame object and define some tags */
829
830 product_frame_mean_dome = cpl_frame_new();
831 cpl_frame_set_filename(product_frame_mean_dome,outfile);
832 cpl_frame_set_tag(product_frame_mean_dome,VIRCAM_PRO_DOME_FLAT);
833 cpl_frame_set_type(product_frame_mean_dome,CPL_FRAME_TYPE_IMAGE);
834 cpl_frame_set_group(product_frame_mean_dome,CPL_FRAME_GROUP_PRODUCT);
835 cpl_frame_set_level(product_frame_mean_dome,CPL_FRAME_LEVEL_FINAL);
836
837 /* Set up the PHU header */
838
839 plist = casu_fits_get_phu(ps.domes[0]);
840 ps.phupaf = vircam_paf_phu_items(plist);
841 if (ps.master_dome_flat != NULL) {
842 cpl_propertylist_update_string(ps.phupaf,"REF_DOME",
843 cpl_frame_get_filename(ps.master_dome_flat));
844 cpl_propertylist_set_comment(ps.phupaf,"REF_DOME",
845 "Reference dome flat used");
846 }
847 vircam_dfs_set_product_primary_header(plist,product_frame_mean_dome,
848 framelist,parlist,
849 (char *)recipeid,
850 "PRO-1.15",NULL,0);
851
852 /* 'Save' the PHU image */
853
854 if (cpl_image_save(NULL,outfile,CPL_TYPE_UCHAR,plist,
855 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
856 cpl_msg_error(fctid,"Cannot save product PHU");
857 cpl_frame_delete(product_frame_mean_dome);
858 return(-1);
859 }
860 cpl_frameset_insert(framelist,product_frame_mean_dome);
861
862 /* Create a new product frame object for the ratio image */
863
864 if (we_expect & RATIMG) {
865 product_frame_ratioimg = cpl_frame_new();
866 cpl_frame_set_filename(product_frame_ratioimg,outdiff);
867 cpl_frame_set_tag(product_frame_ratioimg,
868 VIRCAM_PRO_RATIOIMG_DOME_FLAT);
869 cpl_frame_set_type(product_frame_ratioimg,CPL_FRAME_TYPE_IMAGE);
870 cpl_frame_set_group(product_frame_ratioimg,
871 CPL_FRAME_GROUP_PRODUCT);
872 cpl_frame_set_level(product_frame_ratioimg,CPL_FRAME_LEVEL_FINAL);
873
874 /* Set up the PHU header */
875
876 plist = casu_fits_get_phu(ps.domes[0]);
877 vircam_dfs_set_product_primary_header(plist,product_frame_ratioimg,
878 framelist,parlist,
879 (char *)recipeid,
880 "PRO-1.15",NULL,0);
881
882 /* 'Save' the PHU image */
883
884 if (cpl_image_save(NULL,outdiff,CPL_TYPE_UCHAR,plist,
885 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
886 cpl_msg_error(fctid,"Cannot save product PHU");
887 cpl_frame_delete(product_frame_ratioimg);
888 return(-1);
889 }
890 cpl_frameset_insert(framelist,product_frame_ratioimg);
891 }
892
893 /* Create a new product frame object for the difference image stats
894 table */
895
896 if (we_expect & STATS_TAB) {
897 product_frame_ratioimg_stats = cpl_frame_new();
898 cpl_frame_set_filename(product_frame_ratioimg_stats,outdimst);
899 cpl_frame_set_tag(product_frame_ratioimg_stats,
900 VIRCAM_PRO_RATIOIMG_DOME_FLAT_STATS);
901 cpl_frame_set_type(product_frame_ratioimg_stats,
902 CPL_FRAME_TYPE_TABLE);
903 cpl_frame_set_group(product_frame_ratioimg_stats,
904 CPL_FRAME_GROUP_PRODUCT);
905 cpl_frame_set_level(product_frame_ratioimg_stats,
906 CPL_FRAME_LEVEL_FINAL);
907
908 /* Set up the PHU header */
909
910 plist = casu_fits_get_phu(ps.domes[0]);
912 product_frame_ratioimg_stats,
913 framelist,parlist,
914 (char *)recipeid,
915 "PRO-1.15",NULL,0);
916
917 /* Fiddle with the extension header now */
918
919 elist = casu_fits_get_ehu(ps.domes[0]);
920 p = cpl_propertylist_duplicate(elist);
921 casu_merge_propertylists(p,ps.drs);
922 vircam_paf_append(p,casu_fits_get_phu(ps.domes[0]),
923 "ESO INS FILT1 NAME");
924 if (! (we_get & STATS_TAB))
926 casu_removewcs(p, &(int){CASU_OK});
927 vircam_dfs_set_product_exten_header(p,product_frame_ratioimg_stats,
928 framelist,parlist,
929 (char *)recipeid,
930 "PRO-1.15",NULL);
931
932 /* And finally the difference image stats table */
933
934 if (cpl_table_save(ps.ratioimstats,plist,p,outdimst,
935 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
936 cpl_msg_error(fctid,"Cannot save product table extension");
937 cpl_propertylist_delete(p);
938 return(-1);
939 }
940 cpl_propertylist_delete(p);
941 cpl_frameset_insert(framelist,product_frame_ratioimg_stats);
942 }
943 }
944
945 /* Get the extension property list */
946
947 plist = casu_fits_get_ehu(ps.domes[0]);
948 cpl_propertylist_update_int(plist,"ESO PRO DATANCOM",ps.ngood);
949
950 /* Fiddle with the header now. */
951
952 casu_merge_propertylists(plist,ps.drs);
953 p = cpl_propertylist_duplicate(plist);
954 if (! (we_get & MEANDOME))
956 vircam_dfs_set_product_exten_header(p,product_frame_mean_dome,
957 framelist,parlist,
958 (char *)recipeid,
959 "PRO-1.15",NULL);
960
961 /* Now save the mean dome flat image extension */
962
963 cpl_propertylist_update_float(p,"ESO QC FLATRMS",
964 vircam_dome_flat_combine_config.flatrms);
965 cpl_propertylist_set_comment(p,"ESO QC FLATRMS","RMS of output flat");
966 cpl_propertylist_update_float(p,"ESO QC FLATMIN",
967 vircam_dome_flat_combine_config.minv);
968 cpl_propertylist_set_comment(p,"ESO QC FLATMIN","Ensemble minimum");
969 cpl_propertylist_update_float(p,"ESO QC FLATMAX",
970 vircam_dome_flat_combine_config.maxv);
971 cpl_propertylist_set_comment(p,"ESO QC FLATMAX","Ensemble maximum");
972 cpl_propertylist_update_float(p,"ESO QC FLATAVG",
973 vircam_dome_flat_combine_config.avev);
974 cpl_propertylist_set_comment(p,"ESO QC FLATAVG","Ensemble average");
975 val = vircam_dome_flat_combine_config.maxv -
976 vircam_dome_flat_combine_config.minv;
977 cpl_propertylist_update_float(p,"ESO QC FLATRNG",val);
978 cpl_propertylist_set_comment(p,"ESO QC FLATRNG","Ensemble range");
979 if (cpl_image_save(ps.outimage,outfile,CPL_TYPE_FLOAT,p,
980 CPL_IO_EXTEND) != CPL_ERROR_NONE) {
981 cpl_propertylist_delete(p);
982 cpl_msg_error(fctid,"Cannot save product image extension");
983 return(-1);
984 }
985
986 /* Write the PAF */
987
988 paf = vircam_paf_req_items(p);
989 casu_merge_propertylists(paf,ps.phupaf);
990 vircam_paf_append(paf,casu_fits_get_phu(ps.domes[0]),
991 "ESO INS FILT1 NAME");
992 vircam_paf_append(paf,p,"ESO PRO CATG");
993 vircam_paf_append(paf,p,"ESO PRO DATANCOM");
994 if (vircam_paf_print((char *)outpaf,"VIRCAM/vircam_dome_flat_combine",
995 "QC file",paf) != CASU_OK)
996 cpl_msg_warning(fctid,"Unable to save PAF for mean dome");
997 cpl_propertylist_delete(paf);
998 cpl_propertylist_delete(p);
999
1000 /* Now save the dome ratio image extension */
1001
1002 if (we_expect & RATIMG) {
1003 p = cpl_propertylist_duplicate(plist);
1004 if (! (we_get & RATIMG))
1006 cpl_propertylist_update_float(p,"ESO QC FLATRATIO_MED",
1007 vircam_dome_flat_combine_config.flatratio_med);
1008 cpl_propertylist_set_comment(p,"ESO QC FLATRATIO_MED",
1009 "Median of ratio map");
1010 cpl_propertylist_update_float(p,"ESO QC FLATRATIO_RMS",
1011 vircam_dome_flat_combine_config.flatratio_rms);
1012 cpl_propertylist_set_comment(p,"ESO QC FLATRATIO_RMS",
1013 "RMS of ratio map");
1014 vircam_dfs_set_product_exten_header(p,product_frame_ratioimg,
1015 framelist,parlist,
1016 (char *)recipeid,
1017 "PRO-1.15",NULL);
1018 if (cpl_image_save(ps.ratioimg,outdiff,CPL_TYPE_FLOAT,p,
1019 CPL_IO_EXTEND) != CPL_ERROR_NONE) {
1020 cpl_propertylist_delete(p);
1021 cpl_msg_error(fctid,"Cannot save product image extension");
1022 return(-1);
1023 }
1024
1025 /* Write the PAF */
1026
1027 paf = vircam_paf_req_items(p);
1028 casu_merge_propertylists(paf,ps.phupaf);
1029 vircam_paf_append(paf,casu_fits_get_phu(ps.domes[0]),
1030 "ESO INS FILT1 NAME");
1031 vircam_paf_append(paf,p,"ESO PRO CATG");
1032 if (vircam_paf_print((char *)outdpaf,"VIRCAM/vircam_dome_flat_combine",
1033 "QC file",paf) != CASU_OK)
1034 cpl_msg_warning(fctid,"Unable to save PAF for ratio image");
1035 cpl_propertylist_delete(paf);
1036 cpl_propertylist_delete(p);
1037 }
1038
1039 /* Now any further ratio image stats tables */
1040
1041 if (! isfirst && (we_expect & STATS_TAB)) {
1042 p = cpl_propertylist_duplicate(plist);
1043 if (! (we_get & STATS_TAB))
1045 casu_removewcs(p, &(int){CASU_OK});
1046 vircam_dfs_set_product_exten_header(p,product_frame_ratioimg_stats,
1047 framelist,parlist,
1048 (char *)recipeid,
1049 "PRO-1.15",NULL);
1050 if (cpl_table_save(ps.ratioimstats,NULL,p,outdimst,CPL_IO_EXTEND)
1051 != CPL_ERROR_NONE) {
1052 cpl_propertylist_delete(p);
1053 cpl_msg_error(fctid,"Cannot save product table extension");
1054 return(-1);
1055 }
1056 cpl_propertylist_delete(p);
1057 }
1058
1059 /* Get out of here */
1060
1061 return(0);
1062}
1063
1064/*---------------------------------------------------------------------------*/
1068/*---------------------------------------------------------------------------*/
1069
1070static void vircam_dome_flat_combine_dummy_products(void) {
1071
1072 /* See if you even need to be here */
1073
1074 if (we_get == we_expect)
1075 return;
1076
1077 /* First an output combined dome frame */
1078
1079 if (! (we_get & MEANDOME)) {
1080 ps.outimage = casu_dummy_image(ps.domes[0]);
1081 vircam_dome_flat_combine_config.flatrms = 0.0;
1082 }
1083
1084 /* Do a ratio image */
1085
1086 if ((we_expect & RATIMG) && ! (we_get & RATIMG)) {
1087 vircam_dome_flat_combine_config.flatratio_med = 0.0;
1088 vircam_dome_flat_combine_config.flatratio_rms = 0.0;
1089 ps.ratioimg = casu_dummy_image(ps.domes[0]);
1090 }
1091
1092 /* If a ratio image stats table is required, then do that now */
1093
1094 if ((we_expect & STATS_TAB) && ! (we_get & STATS_TAB))
1095 ps.ratioimstats = vircam_create_diffimg_stats(0);
1096
1097 return;
1098}
1099
1100/*---------------------------------------------------------------------------*/
1105/*---------------------------------------------------------------------------*/
1106
1107static void vircam_dome_flat_combine_normal(int jext) {
1108 int nx,ny,ncells;
1109 long npi;
1110 unsigned char *bpm;
1111 float *idata,med,sig,gdiff,grms;
1112 const char *fctid="vircam_dome_flat_combine_normal";
1113
1114 /* Load up a bad pixel mask */
1115
1116 nx = (int)cpl_image_get_size_x(ps.outimage);
1117 ny = (int)cpl_image_get_size_y(ps.outimage);
1118 npi = nx*ny;
1119 bpm = casu_mask_get_data(ps.master_mask);
1120
1121 /* Work out the RMS of the mean dome frame */
1122
1123 idata = cpl_image_get_data(ps.outimage);
1124 casu_medsig(idata,bpm,npi,&med,&sig);
1125
1126 /* Divide through by the median */
1127
1128 cpl_image_divide_scalar(ps.outimage,med);
1129 casu_medmad(idata,bpm,npi,&med,&sig);
1130 sig *= 1.48;
1131 vircam_dome_flat_combine_config.flatrms = sig;
1132
1133 /* Load up the master dome flat */
1134
1135 if (ps.master_dome_flat != NULL) {
1136 ps.mfimage = casu_fits_load(ps.master_dome_flat,CPL_TYPE_FLOAT,jext);
1137 if (ps.mfimage == NULL) {
1138 cpl_msg_error(fctid,
1139 "Master dome extension %" CPL_SIZE_FORMAT " won't load",
1140 (cpl_size)jext);
1141 } else if (vircam_is_dummy(casu_fits_get_ehu(ps.mfimage))) {
1142 cpl_msg_error(fctid,
1143 "Master dome extension %" CPL_SIZE_FORMAT " is a dummy",
1144 (cpl_size)jext);
1145 freefits(ps.mfimage);
1146 }
1147 } else
1148 ps.mfimage = NULL;
1149
1150
1151 /* Create a ratio image. NB: the difference image routine copes if the
1152 input mean image or the channel tables are null. Thus if either or
1153 both are null because of a failure to load, then the routine will do
1154 as much as it can and return, allowing you to fill in the rest with
1155 dummy products */
1156
1157 vircam_dome_flat_combine_config.flatratio_med = 0.0;
1158 vircam_dome_flat_combine_config.flatratio_rms = 0.0;
1159 ncells = vircam_dome_flat_combine_config.ncells;
1160 vircam_difference_image(casu_fits_get_image(ps.mfimage),ps.outimage,bpm,
1161 casu_tfits_get_table(ps.ctable),ncells,2,
1162 &gdiff,&grms,&(ps.ratioimg),
1163 &(ps.ratioimstats));
1164 casu_mask_clear(ps.master_mask);
1165 vircam_dome_flat_combine_config.flatratio_med = gdiff;
1166 vircam_dome_flat_combine_config.flatratio_rms = grms;
1167 if (ps.ratioimg != NULL)
1168 we_get |= RATIMG;
1169 if (ps.ratioimstats != NULL)
1170 we_get |= STATS_TAB;
1171 return;
1172}
1173
1174/*---------------------------------------------------------------------------*/
1182/*---------------------------------------------------------------------------*/
1183
1184static int vircam_dome_flat_combine_lastbit(int jext, cpl_frameset *framelist,
1185 cpl_parameterlist *parlist) {
1186 int retval;
1187 const char *fctid="vircam_dome_flat_combine_lastbit";
1188
1189 /* Make whatever dummy products you need */
1190
1191 vircam_dome_flat_combine_dummy_products();
1192
1193 /* Save everything */
1194
1195 cpl_msg_info(fctid,"Saving products for extension %" CPL_SIZE_FORMAT,
1196 (cpl_size)jext);
1197 retval = vircam_dome_flat_combine_save(framelist,parlist);
1198 if (retval != 0) {
1199 vircam_dome_flat_combine_tidy(2);
1200 return(-1);
1201 }
1202
1203 /* Free some stuff up */
1204
1205 vircam_dome_flat_combine_tidy(1);
1206 return(0);
1207}
1208
1209/*---------------------------------------------------------------------------*/
1213/*---------------------------------------------------------------------------*/
1214
1215static void vircam_dome_flat_combine_init(void) {
1216 ps.labels = NULL;
1217 ps.domelist = NULL;
1218 ps.domes = NULL;
1219 ps.good = NULL;
1220 ps.master_dark = NULL;
1221 ps.master_dome_flat = NULL;
1222 ps.master_mask = NULL;
1223 ps.chantab = NULL;
1224 ps.ctable = NULL;
1225 ps.outimage = NULL;
1226 ps.drs = NULL;
1227 ps.rejmask = NULL;
1228 ps.rejplus = NULL;
1229 ps.mfimage = NULL;
1230 ps.ratioimg = NULL;
1231 ps.ratioimstats = NULL;
1232 ps.phupaf = NULL;
1233}
1234
1235/*---------------------------------------------------------------------------*/
1239/*---------------------------------------------------------------------------*/
1240
1241static void vircam_dome_flat_combine_tidy(int level) {
1242 freeimage(ps.outimage);
1243 freefitslist(ps.domes,ps.ndomes);
1244 freepropertylist(ps.drs);
1245 freespace(ps.rejmask);
1246 freespace(ps.rejplus);
1247 freetfits(ps.ctable);
1248 freefits(ps.mfimage);
1249 freefits(ps.mdark);
1250 freeimage(ps.ratioimg);
1251 freetable(ps.ratioimstats);
1252 if (level == 1)
1253 return;
1254
1255 freespace(ps.labels);
1256 freeframeset(ps.domelist);
1257 freeframe(ps.master_dark);
1258 freeframe(ps.master_dome_flat);
1259 freeframe(ps.chantab);
1260 freespace(ps.good);
1261 freemask(ps.master_mask);
1262 freepropertylist(ps.phupaf);
1263
1264}
1265
1268/*
1269
1270$Log: not supported by cvs2svn $
1271Revision 1.57 2012/01/15 17:40:09 jim
1272Minor modifications to take into accout the changes in cpl API for v6
1273
1274Revision 1.56 2010/09/09 12:15:01 jim
1275Added QC parameters to give ensemble min, max, ave and range flats
1276
1277Revision 1.55 2010/03/21 06:48:21 jim
1278Fixed bug where DATANCOM wasn't being updated in all products
1279
1280Revision 1.54 2010/03/09 14:27:40 jim
1281Now updates ESO PRO DATANCOM to reflect the number of images used
1282
1283Revision 1.53 2010/02/05 09:42:22 jim
1284Fixed call to non-existent cpl routine
1285
1286Revision 1.52 2010/01/31 18:53:41 jim
1287Reference flat included in paf
1288
1289Revision 1.51 2009/09/21 11:59:06 jim
1290modified to use new version of vircam_overexp
1291
1292Revision 1.50 2009/09/09 09:50:21 jim
1293Modified to try and get headers right
1294
1295Revision 1.49 2008/12/05 13:28:32 jim
1296Fixed save routine so that the correct version of PRO CATG is written to the
1297paf file
1298
1299Revision 1.48 2008/10/01 04:59:13 jim
1300Added call to vircam_frameset_fexists to check input frameset
1301
1302Revision 1.47 2008/09/30 11:33:23 jim
1303Added PRO CATG to pafs
1304
1305Revision 1.46 2008/09/29 11:23:47 jim
1306Defaults to form median flat now. Also fixed header writing bug
1307
1308Revision 1.45 2007/11/26 09:59:06 jim
1309Recipe now takes ndit into account when doing linearity correction
1310
1311Revision 1.44 2007/10/19 09:25:09 jim
1312Fixed problems with missing includes
1313
1314Revision 1.43 2007/10/15 12:53:26 jim
1315Modified for compatibiliity with cpl_4.0
1316
1317Revision 1.42 2007/07/18 15:35:42 jim
1318Added better error handling for missing or corrupt mask extensions
1319
1320Revision 1.41 2007/07/09 13:21:55 jim
1321Modified to use new version of vircam_exten_range
1322
1323Revision 1.40 2007/04/30 09:40:17 jim
1324Added more stuff to paf files
1325
1326Revision 1.39 2007/04/04 10:36:18 jim
1327Modified to use new dfs tags
1328
1329Revision 1.38 2007/03/29 12:19:38 jim
1330Little changes to improve documentation
1331
1332Revision 1.37 2007/03/02 12:37:16 jim
1333Removed WCS stuff from table headers
1334
1335Revision 1.36 2007/03/01 12:41:49 jim
1336Modified slightly after code checking
1337
1338Revision 1.35 2007/02/25 06:27:41 jim
1339plugged a few memory leaks
1340
1341Revision 1.34 2007/02/15 11:54:09 jim
1342Modified to make a distinction between initial channel table and one that
1343has the proper linearity information
1344
1345Revision 1.33 2007/02/15 06:59:37 jim
1346Added ability to write QC paf files
1347
1348Revision 1.32 2007/02/07 10:12:39 jim
1349Removed calls to vircam_ndit_correct as this is now no longer necessary
1350
1351Revision 1.31 2007/02/06 13:11:12 jim
1352Fixed entry for PRO dictionary in cpl_dfs_set_product_header
1353
1354Revision 1.30 2007/02/05 14:14:05 jim
1355Input master frame is now tagged as REFERENCE. QC removed from stats table
1356headers
1357
1358Revision 1.29 2007/01/08 19:09:11 jim
1359Fixed memory leak
1360
1361Revision 1.28 2006/12/13 13:26:09 jim
1362Fxied bad sigma estimate
1363
1364Revision 1.27 2006/11/27 12:13:21 jim
1365Swapped calls to cpl_propertylist_append to cpl_propertylist_update
1366
1367Revision 1.26 2006/11/10 09:21:48 jim
1368Fixed bug in save routine to get the correct propertylist written to product
1369header. Also fixed memory deallocation error in tidy routine
1370
1371Revision 1.25 2006/09/29 11:19:31 jim
1372changed aliases on parameter names
1373
1374Revision 1.24 2006/09/09 16:49:39 jim
1375Header comment update
1376
1377Revision 1.23 2006/08/27 20:30:02 jim
1378Major mods to structure of the main processing routine to deal with missing
1379and dummy frames. Deals better with lower level failures too
1380
1381Revision 1.22 2006/07/11 14:55:12 jim
1382Now checks for zeros in the output flat and replaces them
1383
1384Revision 1.21 2006/06/20 19:07:01 jim
1385Corrects for ndit != 1
1386
1387Revision 1.20 2006/06/15 09:58:58 jim
1388Minor changes to docs
1389
1390Revision 1.19 2006/06/09 11:26:25 jim
1391Small changes to keep lint happy
1392
1393Revision 1.18 2006/06/06 13:01:39 jim
1394Fixed so that the QC parameters go into the correct headers
1395
1396Revision 1.17 2006/05/26 19:38:20 jim
1397Fixed recipe so that the output flat is normalised as it should be
1398
1399Revision 1.16 2006/05/17 14:43:58 jim
1400Fixed problem in save routine which messed up the PRO CATG keywords
1401
1402Revision 1.15 2006/05/16 13:58:47 jim
1403Fixed memory leaks that occur from not closing images at the end of
1404the image extension loop
1405
1406Revision 1.14 2006/05/10 14:30:13 jim
1407deleted ps.domes twice
1408
1409Revision 1.13 2006/05/04 11:53:15 jim
1410Fixed the way the _save routine works to be more consistent with the
1411standard CPL way of doing things
1412
1413Revision 1.12 2006/04/27 09:34:48 jim
1414Fixed data type bug in parameter lthr and hthr. Modified headers to change the
1415dfs keywords to the latest values. Removed confidence map part.
1416
1417Revision 1.11 2006/04/25 14:01:37 jim
1418fixed bug in docs
1419
1420Revision 1.10 2006/04/25 13:45:56 jim
1421Fixed to adhere to new calling sequence for vircam_dfs routines
1422
1423Revision 1.9 2006/04/20 11:32:10 jim
1424Added new parameters to cull out over or under exposed images
1425
1426Revision 1.8 2006/03/23 21:18:45 jim
1427Minor changes mainly to comment headers
1428
1429Revision 1.7 2006/03/22 14:02:51 jim
1430cosmetic changes to keep lint happy
1431
1432Revision 1.6 2006/03/22 13:19:59 jim
1433Added confidence map generation
1434
1435Revision 1.5 2006/03/22 12:13:51 jim
1436Modified to use new vircam_mask capability
1437
1438Revision 1.4 2006/03/15 10:43:40 jim
1439Fixed a few things
1440
1441Revision 1.3 2006/03/08 14:32:35 jim
1442Lots of little mods
1443
1444Revision 1.2 2006/03/03 14:29:06 jim
1445Now calls routines with vir_fits.
1446
1447Revision 1.1 2006/02/27 13:51:17 jim
1448new routine
1449
1450
1451*/
1452
cpl_image * casu_fits_get_image(casu_fits *p)
Definition: casu_fits.c:436
casu_fits ** casu_fits_load_list(cpl_frameset *f, cpl_type type, int exten)
Definition: casu_fits.c:318
int casu_fits_set_error(casu_fits *p, int status)
Definition: casu_fits.c:747
char * casu_fits_get_fullname(casu_fits *p)
Definition: casu_fits.c:680
cpl_propertylist * casu_fits_get_phu(casu_fits *p)
Definition: casu_fits.c:531
cpl_propertylist * casu_fits_get_ehu(casu_fits *p)
Definition: casu_fits.c:576
casu_fits * casu_fits_load(cpl_frame *frame, cpl_type type, int nexten)
Definition: casu_fits.c:80
void casu_mask_force(casu_mask *m, int nx, int ny)
Definition: casu_mask.c:394
unsigned char * casu_mask_get_data(casu_mask *m)
Definition: casu_mask.c:544
int casu_mask_load(casu_mask *m, int nexten, int nx, int ny)
Definition: casu_mask.c:214
void casu_mask_clear(casu_mask *m)
Definition: casu_mask.c:357
casu_mask * casu_mask_define(cpl_frameset *framelist, cpl_size *labels, cpl_size nlab, const char *conftag, const char *bpmtag)
Definition: casu_mask.c:89
const char * casu_mask_get_filename(casu_mask *m)
Definition: casu_mask.c:447
int casu_imcombine(casu_fits **fset, casu_fits **fsetv, int nfits, int combtype, int scaletype, int xrej, float thresh, const char *expkey, cpl_image **outimage, cpl_image **outvimage, unsigned char **rejmask, unsigned char **rejplus, cpl_propertylist **drs, int *status)
Stack images into a mean or median image with rejection.
int casu_nditcor(casu_fits *infile, int ndit, const char *expkey, int *status)
Correct input data for number of dits.
Definition: casu_nditcor.c:85
int casu_darkcor(casu_fits *infile, casu_fits *darksrc, float darkscl, int *status)
Correct input data for dark current.
Definition: casu_darkcor.c:86
void casu_medmad(float *data, unsigned char *bpm, long np, float *med, float *mad)
Definition: casu_stats.c:347
void casu_medsig(float *data, unsigned char *bpm, long np, float *med, float *sig)
Definition: casu_stats.c:672
casu_tfits * casu_tfits_load(cpl_frame *table, int nexten)
Definition: casu_tfits.c:78
cpl_table * casu_tfits_get_table(casu_tfits *p)
Definition: casu_tfits.c:364
int casu_compare_tags(const cpl_frame *frame1, const cpl_frame *frame2)
Compare input tags.
Definition: casu_utils.c:96
void casu_merge_propertylists(cpl_propertylist *p1, cpl_propertylist *p2)
Merge two propertylists.
Definition: casu_utils.c:399
void casu_overexp(casu_fits **fitslist, int *n, int ndit, float lthr, float hthr, int ditch, float *minv, float *maxv, float *avev)
Remove over- or under-exposed images from a list.
Definition: casu_utils.c:652
void casu_dummy_property(cpl_propertylist *p)
Set dummy property keyword.
Definition: casu_utils.c:445
cpl_frame * casu_frameset_subgroup_1(cpl_frameset *frameset, cpl_size *labels, cpl_size nlab, const char *tag)
Extract a frame of a given label from a frameset.
Definition: casu_utils.c:206
cpl_image * casu_dummy_image(casu_fits *model)
Create a dummy image of zeros based on a model.
Definition: casu_utils.c:533
cpl_frameset * casu_frameset_subgroup(cpl_frameset *frameset, cpl_size *labels, cpl_size nlab, const char *tag)
Extract a frameset from another frameset.
Definition: casu_utils.c:149
int casu_removewcs(cpl_propertylist *p, int *status)
int vircam_lincor(casu_fits *infile, casu_tfits *lchantab, int kconst, int ndit, int *status)
Apply linearity curves to data.
int vircam_chantab_verify(cpl_table *intab)
int vircam_dfs_set_groups(cpl_frameset *set)
Definition: vircam_dfs.c:115
void vircam_dfs_set_product_primary_header(cpl_propertylist *plist, cpl_frame *frame, cpl_frameset *frameset, cpl_parameterlist *parlist, char *recipeid, const char *dict, cpl_frame *inherit, int synch)
Definition: vircam_dfs.c:227
void vircam_dfs_set_product_exten_header(cpl_propertylist *plist, cpl_frame *frame, cpl_frameset *frameset, cpl_parameterlist *parlist, char *recipeid, const char *dict, cpl_frame *inherit)
Definition: vircam_dfs.c:299
int vircam_pfits_get_ndit(const cpl_propertylist *plist, int *ndit)
Get the value of NDIT.
Definition: vircam_pfits.c:583
int vircam_pfits_get_detlive(const cpl_propertylist *plist, int *detlive)
Get the value of DET_LIVE.
Definition: vircam_pfits.c:624
const char * vircam_get_license(void)
Definition: vircam_utils.c:116
cpl_table * vircam_create_diffimg_stats(int nrows)
Definition: vircam_utils.c:960
void vircam_difference_image(cpl_image *master, cpl_image *prog, unsigned char *bpm, cpl_table *chantab, int ncells, int oper, float *global_diff, float *global_rms, cpl_image **diffim, cpl_table **diffimstats)
Definition: vircam_utils.c:762
int vircam_is_dummy(cpl_propertylist *p)
void vircam_exten_range(int inexten, const cpl_frame *fr, int *out1, int *out2)
Definition: vircam_utils.c:165