25 #include <muse_instrument.h> 26 #include "muse_data_format_z.h" 83 #define PRINT_USAGE(rc) \ 84 fprintf(stderr, "Usage: %s [ -i INTABLE ] [ -r REFIMAGE [ -n extname ] ] " \ 85 "[ -t ] REGION DQVAL IFUNUM OUTTABLE\n", argv[0]); \ 86 cpl_end(); return (rc); 88 int main(
int argc,
char **argv)
90 cpl_init(CPL_INIT_DEFAULT);
96 if (getenv(
"ESOREX_MSG_LEVEL") && !strncmp(getenv(
"ESOREX_MSG_LEVEL"),
98 cpl_msg_set_level(CPL_MSG_DEBUG);
107 unsigned char nifu = 0;
108 cpl_boolean trimmedcoords = CPL_FALSE;
112 for (i = 1; i < argc; i++) {
113 if (strncmp(argv[i],
"-i", 3) == 0) {
121 }
else if (strncmp(argv[i],
"-r", 3) == 0) {
129 }
else if (strncmp(argv[i],
"-n", 3) == 0) {
137 }
else if (strncmp(argv[i],
"-t", 3) == 0) {
139 trimmedcoords = CPL_TRUE;
140 }
else if (strncmp(argv[i],
"-", 1) == 0) {
143 if (region && dqvalue && toname) {
148 }
else if (!dqvalue) {
149 dqvalue = atol(argv[i]);
150 }
else if (nifu == 0) {
151 int ifunum = atoi(argv[i]);
152 if (ifunum < 1 || ifunum > kMuseNumIFUs) {
164 n = sscanf(region,
"[%d:%d,%d:%d]", &x1, &x2, &y1, &y2);
172 printf(
"Converting coordinates from trimmed to raw data dimensions\n");
175 (x2-x1+1) * (y2-y1+1));
177 for (i = x1; i <= x2; i++) {
179 for (j = y1; j <= y2; j++) {
185 if (ix < 1 || ix > (kMuseOutputXRight + 4*kMusePreOverscanSize) ||
186 iy < 1 || iy > (kMuseOutputYTop + 4*kMusePreOverscanSize)) {
187 fprintf(stderr,
"Excluding bad pixel at given %d,%d %s coordinates, as " 188 "it would be outside the MUSE CCD!\n", i, j,
189 trimmedcoords ?
"trimmed" :
"raw");
192 cpl_table_set_int(table, MUSE_BADPIX_X, irow, ix);
193 cpl_table_set_int(table, MUSE_BADPIX_Y, irow, iy);
194 cpl_table_set_int(table, MUSE_BADPIX_DQ, irow++, dqvalue);
197 cpl_table_set_size(table, irow);
198 printf(
"%"CPL_SIZE_FORMAT
" bad pixel%s created from region %s\n", irow,
199 irow != 1 ?
"s" :
"", region);
200 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
201 printf(
"first 10 entries of the new table, as converted from region:\n");
202 cpl_table_dump(table, 0, 10, stdout);
209 cpl_propertylist *htest = cpl_propertylist_load(tiname, 0);
211 cpl_propertylist_delete(htest);
213 printf(
"WARNING: could not open input table \"%s\"!\n", tiname);
219 char *chan = cpl_sprintf(
"CHAN%02hhu", nifu);
220 cpl_table *intable = NULL;
223 cpl_errorstate state = cpl_errorstate_get();
226 cpl_errorstate_set(state);
233 cpl_boolean savedsomething = rc == CPL_ERROR_NONE;
236 inext = cpl_fits_find_extension(toname, chan);
238 cpl_propertylist *pheader = NULL,
241 printf(
"WARNING: no pre-existing data, creating minimal header from " 243 pheader = cpl_propertylist_new();
244 cpl_propertylist_append_string(pheader,
"TELESCOP",
"ESO-VLT-U4");
245 cpl_propertylist_append_string(pheader,
"INSTRUME",
"MUSE");
246 cpl_propertylist_append_string(pheader,
"OBJECT",
247 "Bad pixel table for MUSE (BADPIX_TABLE)");
248 header = cpl_propertylist_new();
249 cpl_propertylist_append_string(header,
"EXTNAME", chan);
250 cpl_propertylist_append_string(header,
"ESO DET CHIP NAME", chan);
252 printf(
"Using primary header from \"%s\" as starting point\n", riname);
253 pheader = cpl_propertylist_load_regexp(riname, 0,
"TELESCOP|INSTRUME|" 257 cpl_propertylist_erase_regexp(pheader,
"ESO DET DEV[0-9] (SHUT |EXP )|" 258 "ESO DET (EXP |[DU]IT|NDIT|DKTM)", 0);
259 cpl_propertylist_erase_regexp(pheader,
"ESO DET (CHIP |OUT[1-4])", 0);
260 cpl_propertylist_update_string(pheader,
"OBJECT",
261 "Bad pixel table for MUSE (BADPIX_TABLE)");
262 int refext = cpl_fits_find_extension(riname, extname);
264 printf(
"Using extension header from \"%s[%s]\" (%d)\n", riname, extname,
266 header = cpl_propertylist_load_regexp(riname, refext,
267 "^EXT|ESO DET (CHIP |OUT[1-4])", 0);
269 printf(
"WARNING: no pre-existing extension found, creating minimal " 270 "extension header from scratch!\n");
271 header = cpl_propertylist_new();
272 cpl_propertylist_append_string(header,
"EXTNAME", chan);
273 cpl_propertylist_append_string(header,
"ESO DET CHIP NAME", chan);
276 if (savedsomething) {
278 rc = cpl_table_save(table, NULL, header, toname, CPL_IO_EXTEND);
281 cpl_propertylist_update_string(pheader,
"PIPEFILE", toname);
282 cpl_propertylist_set_comment(pheader,
"PIPEFILE",
283 "pretend to be a pipeline output file");
284 cpl_propertylist_update_string(pheader,
"ESO PRO CATG", MUSE_TAG_BADPIX_TABLE);
285 cpl_propertylist_set_comment(pheader,
"ESO PRO CATG",
286 "MUSE bad pixel table");
287 rc = cpl_table_save(table, pheader, header, toname, CPL_IO_CREATE);
289 if (rc != CPL_ERROR_NONE) {
290 fprintf(stderr,
"Saving to \"%s\" failed (rc=%d): %s\n", toname, rc,
291 cpl_error_get_message());
293 printf(
"Saved to \"%s\" (%s)\n", toname,
294 savedsomething ?
"new extension" :
"new file");
296 cpl_propertylist_delete(pheader);
297 cpl_propertylist_delete(header);
300 cpl_table_delete(table);
302 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
303 printf(
"Output file \"%s\" has primary header and %"CPL_SIZE_FORMAT
304 " extensions\n", toname, cpl_fits_count_extensions(toname));
305 cpl_errorstate_dump(0, CPL_FALSE, NULL);
cpl_error_code muse_quality_copy_badpix_table(const char *aInFile, const char *aOutFile, int aExtension, const cpl_table *aTable)
Copy bad pixel table on disk, replacing the table in one extension.
cpl_table * muse_quality_merge_badpix_from_file(const cpl_table *aTable, const char *aInFile, const char *aExtname, int *aExt)
Merge bad pixel table in memory with table from file on disk.
cpl_table * muse_cpltable_new(const muse_cpltable_def *aDef, cpl_size aLength)
Create an empty table according to the specified definition.
cpl_error_code muse_quadrants_coords_to_raw(cpl_propertylist *aHeader, int *aX, int *aY)
Convert coordinates of a trimmed image to raw-image coordinates.
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.