MUSE Pipeline Reference Manual  1.0.2
muse_badpix2image.c
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set sw=2 sts=2 et cin: */
3 /*
4  * This file is part of the MUSE Instrument Pipeline
5  * Copyright (C) 2007-2011 European Southern Observatory
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 #include <muse.h>
23 #include <string.h>
24 
25 #define PRINT_USAGE(rc) \
26  fprintf(stderr, "Usage: %s INFILE OUTFILE\n", argv[0]); \
27  cpl_end(); return (rc);
28 
29 /*----------------------------------------------------------------------------*/
33 /*----------------------------------------------------------------------------*/
34 int main(int argc, char **argv)
35 {
36  cpl_init(CPL_INIT_DEFAULT);
37 
38  if (argc <= 2) {
39  /* two filenames are needed */
40  PRINT_USAGE(1);
41  }
42 
43  cpl_table *table = cpl_table_load(argv[1], 3, 0);
44  if (!table) {
45  PRINT_USAGE(10);
46  }
47  int nrow = cpl_table_get_nrow(table);
48  cpl_msg_info(__func__, "read %d columns from \"%s\"", nrow, argv[1]);
49 
50  /* offset all table coordinates by +1 to get normal FITS coordinates */
51  cpl_table_add_scalar(table, "xdet", 1);
52  cpl_table_add_scalar(table, "ydet", 1);
53  /* convert type column to Euro3D flag */
54  cpl_table_new_column(table, "euro3d", CPL_TYPE_INT);
55  int n, nhot = 0, ndark = 0, ntrap = 0;
56  for (n = 0; n < nrow; n++) {
57  /* get first character of type string in this row */
58  char type = cpl_table_get_string(table, "type", n)[0];
59  switch (type) {
60  case 'H':
61  cpl_table_set(table, "euro3d", n, EURO3D_HOTPIXEL);
62  nhot++;
63  break;
64  case 'D':
65  cpl_table_set(table, "euro3d", n, EURO3D_DARKPIXEL);
66  ndark++;
67  break;
68  case 'T':
69  cpl_table_set(table, "euro3d", n, EURO3D_MUSE_TRAP);
70  ntrap++;
71  break;
72  } /* switch */
73  } /* for n (table rows) */
74 #if 0
75  cpl_table_dump(table, 0, 100000, stdout);
76  fflush(stdout);
77 #endif
78  cpl_msg_info(__func__, "%d hot, %d dark, and %d trap pixel%s",
79  nhot, ndark, ntrap, nhot+ndark+ntrap != 1 ? "s" : "");
80 
81  /* use image part to create output image */
82  muse_image *image = muse_image_new();
83  image->data = cpl_image_load(argv[1], CPL_TYPE_INT, 0, 1);
84  int nx = cpl_image_get_size_x(image->data),
85  ny = cpl_image_get_size_y(image->data);
86  /* want an empty image to start with */
87  image->dq = cpl_image_new(nx, ny, CPL_TYPE_INT);
88 
89  for (n = 0; n < nrow; n++) {
90  int i = cpl_table_get_int(table, "xdet", n, NULL),
91  j = cpl_table_get_int(table, "ydet", n, NULL),
92  dq = cpl_table_get_int(table, "euro3d", n, NULL),
93  err, val = cpl_image_get(image->dq, i, j, &err);
94  cpl_image_set(image->dq, i, j, dq | val);
95  } /* for n (table rows) */
96 
97  /* now trim the image to be able to compare it to the MASTER file */
98  image->header = cpl_propertylist_load(argv[1], 1);
99  muse_image *trimmed = muse_quadrants_trim_image(image);
100  cpl_image_save(trimmed->dq, argv[2], CPL_TYPE_INT, NULL, CPL_IO_CREATE);
101  cpl_msg_info(__func__, "saved to \"%s\"", argv[2]);
102 
103  muse_image_delete(trimmed);
104  cpl_table_delete(table);
105  muse_image_delete(image);
106  cpl_end();
107  return 0;
108 }
void muse_image_delete(muse_image *aImage)
Deallocate memory associated to a muse_image object.
Definition: muse_image.c:85
cpl_image * data
the data extension
Definition: muse_image.h:46
Structure definition of MUSE three extension FITS file.
Definition: muse_image.h:40
cpl_propertylist * header
the FITS header
Definition: muse_image.h:72
cpl_image * dq
the data quality extension
Definition: muse_image.h:56
muse_image * muse_image_new(void)
Allocate memory for a new muse_image object.
Definition: muse_image.c:66
muse_image * muse_quadrants_trim_image(muse_image *aImage)
Trim the input image of pre- and over-scan regions of all quadrants.