File: muse_test_processing.c

package info (click to toggle)
cpl-plugin-muse 1.6.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 11,780 kB
  • sloc: ansic: 71,941; sh: 4,276; python: 1,371; makefile: 686
file content (577 lines) | stat: -rw-r--r-- 24,789 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set sw=2 sts=2 et cin: */
/*
 * This file is part of the MUSE Instrument Pipeline
 * Copyright (C) 2007-2014 European Southern Observatory
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

/*----------------------------------------------------------------------------*
 *                              Includes                                      *
 *----------------------------------------------------------------------------*/
#define _BSD_SOURCE /* get mkdtemp() from stdlib.h */
#include <unistd.h> /* access() */
#include <stdlib.h>
#include <stdio.h>
#include <float.h>
#include <math.h>
#include <sys/stat.h>
#include <string.h>
#ifdef HAVE_GETTIMEOFDAY
#include <time.h>
#include <sys/time.h>
#endif

#include <muse.h>
#include "muse_test_processing_z.h"

#ifdef DO_NOT_CPL_TEST
#define cpl_test(A)
#define cpl_test_eq(A, B)
#define cpl_test_eq_string(A, B)
#define cpl_test_nonnull(A)
#define cpl_test_init(A, B) cpl_init(CPL_INIT_DEFAULT)
#define cpl_test_end(A) (A)
#endif

#define DIR_TEMPLATE "/tmp/muse_test_processing_XXXXXX"

/*----------------------------------------------------------------------------*/
/**
  @brief    Prepare the test, mostly by creating a test image with some typical
            MUSE FITS headers.
  @param    aDir   the output directory where to save the image
 */
/*----------------------------------------------------------------------------*/
static void
prepare_test(char *aDir)
{
  cpl_image *raw = cpl_image_fill_test_create(4160, 4164);
  /* offset background, so that not everything is marked as saturated */
  cpl_image_add_scalar(raw, 10.);
  /* extension header */
  cpl_propertylist *hdr = cpl_propertylist_new();
  cpl_propertylist_append_int(hdr, "DUMMY", 1);
  cpl_propertylist_append_int(hdr, "ESO DET BINX", 1);
  cpl_propertylist_append_int(hdr, "ESO DET BINY", 1);
  cpl_propertylist_append_int(hdr, "ESO DET READ CURID", 1);
  cpl_propertylist_append_string(hdr, "ESO DET READ CURNAME", "SCI1.0");
  char *file = cpl_sprintf("%s/raw.fits", aDir);
  cpl_image_save(NULL, file, CPL_TYPE_SHORT, hdr, CPL_IO_CREATE);
  cpl_propertylist_delete(hdr);
  /* extension header */
  hdr = cpl_propertylist_new();
  cpl_propertylist_append_string(hdr, "EXTNAME", "CHAN01");
  cpl_propertylist_append_string(hdr, "ESO DET CHIP NAME", "CHAN01");
  cpl_propertylist_append_string(hdr, "ESO DET CHIP ID", "psyche");
  cpl_propertylist_append_string(hdr, "ESO DET CHIP DATE",
                                 "2014-02-21T12:18:14.207");
  cpl_propertylist_append_int(hdr, "ESO DET OUT1 NX", 2048);
  cpl_propertylist_append_int(hdr, "ESO DET OUT1 NY", 2056);
  cpl_propertylist_append_int(hdr, "ESO DET OUT1 OVSCX", 5);
  cpl_propertylist_append_int(hdr, "ESO DET OUT1 OVSCY", 5);
  cpl_propertylist_append_int(hdr, "ESO DET OUT1 PRSCX", 32);
  cpl_propertylist_append_int(hdr, "ESO DET OUT1 PRSCY", 20);
  cpl_propertylist_append_int(hdr, "ESO DET OUT1 X", 1);
  cpl_propertylist_append_int(hdr, "ESO DET OUT1 Y", 1);
  cpl_propertylist_append_float(hdr, "ESO DET OUT1 GAIN", 0.71);
  cpl_propertylist_append_int(hdr, "ESO DET OUT2 NX", 2048);
  cpl_propertylist_append_int(hdr, "ESO DET OUT2 NY", 2056);
  cpl_propertylist_append_int(hdr, "ESO DET OUT2 OVSCX", 5);
  cpl_propertylist_append_int(hdr, "ESO DET OUT2 OVSCY", 5);
  cpl_propertylist_append_int(hdr, "ESO DET OUT2 PRSCX", 32);
  cpl_propertylist_append_int(hdr, "ESO DET OUT2 PRSCY", 20);
  cpl_propertylist_append_int(hdr, "ESO DET OUT2 X", 4096);
  cpl_propertylist_append_int(hdr, "ESO DET OUT2 Y", 1);
  cpl_propertylist_append_float(hdr, "ESO DET OUT2 GAIN", 0.72);
  cpl_propertylist_append_int(hdr, "ESO DET OUT3 NX", 2048);
  cpl_propertylist_append_int(hdr, "ESO DET OUT3 NY", 2056);
  cpl_propertylist_append_int(hdr, "ESO DET OUT3 OVSCX", 5);
  cpl_propertylist_append_int(hdr, "ESO DET OUT3 OVSCY", 5);
  cpl_propertylist_append_int(hdr, "ESO DET OUT3 PRSCX", 32);
  cpl_propertylist_append_int(hdr, "ESO DET OUT3 PRSCY", 20);
  cpl_propertylist_append_int(hdr, "ESO DET OUT3 X", 4096);
  cpl_propertylist_append_int(hdr, "ESO DET OUT3 Y", 4112);
  cpl_propertylist_append_float(hdr, "ESO DET OUT3 GAIN", 0.73);
  cpl_propertylist_append_int(hdr, "ESO DET OUT4 NX", 2048);
  cpl_propertylist_append_int(hdr, "ESO DET OUT4 NY", 2056);
  cpl_propertylist_append_int(hdr, "ESO DET OUT4 OVSCX", 5);
  cpl_propertylist_append_int(hdr, "ESO DET OUT4 OVSCY", 5);
  cpl_propertylist_append_int(hdr, "ESO DET OUT4 PRSCX", 32);
  cpl_propertylist_append_int(hdr, "ESO DET OUT4 PRSCY", 20);
  cpl_propertylist_append_int(hdr, "ESO DET OUT4 X", 1);
  cpl_propertylist_append_int(hdr, "ESO DET OUT4 Y", 4112);
  cpl_propertylist_append_float(hdr, "ESO DET OUT4 GAIN", 0.74);
  cpl_image_save(raw, file, CPL_TYPE_SHORT, hdr, CPL_IO_EXTEND);
  cpl_free(file);
  cpl_image_delete(raw);
  cpl_propertylist_delete(hdr);
} /* prepare_test() */

static int
frames_sort_valid_ifus_in_exposure(cpl_table *aTable, int aExposure)
{
  /* loop through all IFUs and count the number of valid IFUs found */
  int i, nvalid = 0;
  for (i = 1; i <= 24; i++) {
    char *colname = cpl_sprintf("%02d", i);
    if (cpl_table_is_valid(aTable, colname, aExposure - 1)) {
      nvalid++;
    }
    cpl_free(colname);
  }
  return nvalid;
} /* frames_sort_valid_ifus_in_exposure() */

static void
frames_sort_test(const char *aDir, cpl_recipe *aRecipe)
{
#ifdef HAVE_GETTIMEOFDAY /* fail/skip, if we don't have that function, see below */
  /*
   * create 3 test exposures, with 24 files each (one for each IFU)
   * and add them to 3 different framesets (one with all of them and two
   * where something is wrong (missing IFU and wrong tag)
   */
  cpl_frameset *fall = cpl_frameset_new(), /* all files included */
               *f1 = cpl_frameset_new(), /* missing IFUs */
               *f2 = cpl_frameset_new(); /* wrong tag for some IFUs */
  cpl_propertylist *header = cpl_propertylist_new();
  cpl_table *table = cpl_table_new(0);
  const char *tag = "TEST_FILE_TAG";

  /* loop over all IFUs for 3 exposures and create the test files */
  int n;
  for (n = 1; n <= 3; n++) {
    /* create typical FITS format for DATE-OBS */
    struct timeval tv;
    gettimeofday(&tv, NULL);
    char date[24]; /* full UTC in ISO format plus ms and null byte */
    strftime(date, 20, "%FT%T", gmtime(&tv.tv_sec));
    /* write milliseconds to the same string, starting at the null byte */
    snprintf(date+19, 5, ".%03ld", tv.tv_usec/1000);

    cpl_msg_debug(__func__, "exposure %d: date=\"%s\"", n, date);
    cpl_propertylist_append_string(header, "DATE-OBS", date);

    int i;
    for (i = 1; i <= 24; i++) {
      /* change header to fit */
      char *chan = cpl_sprintf("CHAN%02d", i);
      cpl_propertylist_append_string(header, "EXTNAME", chan);
      cpl_free(chan);

      char *outfile = cpl_sprintf("%s/test_table_%1d_%02d.fits", aDir, n, i);
      cpl_table_save(table, header, NULL, outfile, CPL_IO_CREATE);

      /* create frame for this file and add it to (some of) the framesets */
      cpl_frame *frame = cpl_frame_new();
      cpl_frame_set_filename(frame, outfile);
      cpl_frame_set_tag(frame, tag);
      cpl_frameset_insert(fall, frame); /* always insert into this frameset */
      if (i != 13 && i != 20) { /* exclude these IFUs from the other set */
        cpl_frame *frame1 = cpl_frame_duplicate(frame);
        cpl_frameset_insert(f1, frame1); /* always insert into this frameset */
      }
      cpl_frame *frame2 = cpl_frame_duplicate(frame);
      if (i % n) { /* add wrong tags for some frames for this frameset */
        cpl_frame_set_tag(frame2, "WRONG_TAG");
      }
      cpl_frameset_insert(f2, frame2); /* always insert into this frameset */

      cpl_propertylist_erase(header, "EXTNAME");
      cpl_free(outfile);
    } /* for i */
    cpl_propertylist_erase(header, "DATE-OBS");

    /* the ms of the date strings will be different because of processing *
     * time, but just to be safe, sleep for at least 1s in addition       */
    //sleep(1);
  } /* for n */
  cpl_table_delete(table);
  cpl_propertylist_delete(header);

  /* create new processing structure, adapted for the needs here */
  muse_processing *proc = muse_processing_new("frames_sort", aRecipe);
  cpl_frameset_delete(proc->inframes); /* input frames are set below */
  /* need to replace tag with our tag, for the following tests to work */
  cpl_array_set_string(proc->intags, 0, tag);

  /*
   * now finally run the tests, replacing the empty with
   * a filled input frameset for each run
   */
  proc->inframes = cpl_frameset_duplicate(fall);
  table = muse_processing_sort_exposures(proc);
  cpl_test(cpl_table_get_nrow(table) == 3);
  cpl_test(frames_sort_valid_ifus_in_exposure(table, 1) == 24);
  cpl_test(frames_sort_valid_ifus_in_exposure(table, 2) == 24);
  cpl_test(frames_sort_valid_ifus_in_exposure(table, 3) == 24);
  cpl_table_delete(table);

  cpl_frameset_delete(proc->inframes);
  proc->inframes = cpl_frameset_duplicate(f1);
  table = muse_processing_sort_exposures(proc);
  cpl_test(cpl_table_get_nrow(table) == 3);
  /* 2 IFUs should be missing for all exposures */
  cpl_test(frames_sort_valid_ifus_in_exposure(table, 1) == 22);
  cpl_test(frames_sort_valid_ifus_in_exposure(table, 2) == 22);
  cpl_test(frames_sort_valid_ifus_in_exposure(table, 3) == 22);
  cpl_table_delete(table);

  cpl_frameset_delete(proc->inframes);
  proc->inframes = cpl_frameset_duplicate(f2);
  table = muse_processing_sort_exposures(proc);
  cpl_test(cpl_table_get_nrow(table) == 3);
  cpl_test(frames_sort_valid_ifus_in_exposure(table, 1) == 24);
  cpl_test(frames_sort_valid_ifus_in_exposure(table, 2) == 12); /* every second one missing */
  cpl_test(frames_sort_valid_ifus_in_exposure(table, 3) == 8); /* only every third is there */
  cpl_table_delete(table);

  /* remove all files from the disk, using the frameset that contains all frames */
  cpl_frameset_iterator *fiter = cpl_frameset_iterator_new(fall);
  cpl_frame *frame = cpl_frameset_iterator_get(fiter);
  while (frame) {
    /* using this with cpl_test_zero() might be a good idea, but then *
     * we would test more the test procedure than the function        */
    remove(cpl_frame_get_filename(cpl_frameset_iterator_get_const(fiter)));
    cpl_frameset_iterator_advance(fiter, 1);
    frame = cpl_frameset_iterator_get(fiter);
  } /* while */
  cpl_frameset_iterator_delete(fiter);

  /* cleanup of frames and this processing object */
  cpl_frameset_delete(fall);
  cpl_frameset_delete(f1);
  cpl_frameset_delete(f2);
  muse_processing_delete(proc);
#else /* no gettimeofday() available */
  cpl_msg_error(__func__, "gettimeofday() not available, cannot run this test!");
#endif
} /* frames_sort_test() */

/*----------------------------------------------------------------------------*/
/**
  @brief    Short test program to check the muse processing framework.
 */
/*----------------------------------------------------------------------------*/
int main(int argc, char **argv)
{
  UNUSED_ARGUMENTS(argc, argv);
  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_INFO);

  char dirtemplate[FILENAME_MAX] = DIR_TEMPLATE;
  char *dir = mkdtemp(dirtemplate);
  int retval = chdir(dir);
  // test preparation: build input and test images
  prepare_test(dir);

  // here we just simulate a framework.
  // initialize plugin list
  cpl_pluginlist *list = cpl_pluginlist_new();
  cpl_plugin_get_info(list);
  cpl_test_eq(cpl_pluginlist_get_size(list), 1);
  cpl_plugin *plugin = cpl_pluginlist_get_first(list);
  cpl_test_nonnull(plugin);
  cpl_test_eq(cpl_plugin_get_type(plugin), CPL_PLUGIN_TYPE_RECIPE);
  cpl_recipe *recipe = (cpl_recipe *)plugin;

  // initialize plugin
  cpl_plugin_func init_func = cpl_plugin_get_init(plugin);
  cpl_test(init_func != NULL);
  retval = init_func(plugin);
  cpl_test_eq(retval, CPL_ERROR_NONE);

  // init (input) frames
  recipe->frames = cpl_frameset_new();

  char *file = cpl_sprintf("%s/raw.fits", dir);
  cpl_frame *frame = cpl_frame_new();
  cpl_frame_set_tag(frame, "RAW");
  cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
  cpl_frame_set_filename(frame, file);
  cpl_frameset_insert(recipe->frames, frame);

  // run plugin
  cpl_plugin_func exec_func = cpl_plugin_get_exec(plugin);
  cpl_test(exec_func != NULL);
  retval = exec_func(plugin);
  cpl_test_eq(retval, CPL_ERROR_NONE);

  // run plugin with debug-level output
  cpl_msg_set_level(CPL_MSG_DEBUG);
  retval = exec_func(plugin);
  cpl_test_eq(retval, CPL_ERROR_NONE);
  cpl_msg_set_level(CPL_MSG_INFO);

  // before removing it, use the still existing recipe to do
  // the frames_sort_test that needs a new processing structure
  frames_sort_test(dir, recipe);

  // cleanup
  cpl_plugin_func deinit_func = cpl_plugin_get_deinit(plugin);
  cpl_test(deinit_func != NULL);
  retval = deinit_func(plugin);
  cpl_test_eq(retval, CPL_ERROR_NONE);
  cpl_frameset_delete(recipe->frames);

  cpl_pluginlist_delete(list);
  muse_processinginfo_delete(recipe);
  remove(file);
  cpl_free(file);

  // this removes the dir created for the results, and it also (implicitely)
  // checks that there are no more files.
  retval = chdir(".."); // avoid EBUSY on rmdir
  retval = rmdir(dir);
  cpl_test_eq(retval, 0);

  return cpl_test_end(0);
} /* main() */

/*----------------------------------------------------------------------------*/
/**
  @brief    Dummy compute routine.
  @param    aProcessing   the processing structure
  @param    aParams       the parameters list
  @return   CPL_ERROR_NONE if all tests succeeded, another CPL error otherwise
 */
/*----------------------------------------------------------------------------*/
int
muse_test_processing_compute(muse_processing *aProcessing,
                             muse_test_processing_params_t *aParams)
{
  // test parameters. They're set in muse_test_processing.xml
  cpl_test_eq(aParams->adouble, 3);
  cpl_test_eq(aParams->aboolean, FALSE);
  cpl_test_eq_string(aParams->astring, "DEF");
  cpl_test_eq(aParams->anenum, 1);

  muse_imagelist *images = muse_basicproc_load(aProcessing, aParams->nifu,
                                               NULL);
  cpl_test_nonnull(images);
  cpl_ensure(images, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);

  // just copy the input image
  muse_image *image = muse_image_new();
  image->data = cpl_image_duplicate(muse_imagelist_get(images, 0)->data);
  image->stat = cpl_image_duplicate(muse_imagelist_get(images, 0)->stat);
  image->dq = cpl_image_duplicate(muse_imagelist_get(images, 0)->dq);
  image->header = cpl_propertylist_new();
  cpl_propertylist_append_double(image->header, "ADOUBLE", 1.0);
  cpl_propertylist_append_string(image->header, "BUNIT", "adu");
  int retval;

  // check saving of MUSE images
  retval = muse_processing_save_image(aProcessing, aParams->nifu,
                                      image, "processing_muse_image");
  cpl_test_error(CPL_ERROR_NONE);

  // check saving of CPL images
  retval = muse_processing_save_cimage(aProcessing, aParams->nifu,
                                       image->data, image->header,
                                       "processing_cpl_image");
  cpl_test_error(CPL_ERROR_NONE);

  // check saving of CPL tables
  cpl_table *table = cpl_table_new(0);
  retval = muse_processing_save_table(aProcessing, aParams->nifu,
                                      table, image->header,
                                      "processing_cpl_table",
                                      MUSE_TABLE_TYPE_CPL);
  cpl_test_error(CPL_ERROR_NONE);
  cpl_table_delete(table);

  // check saving of FITS headers
  retval = muse_processing_save_header(aProcessing, aParams->nifu,
                                       image->header, "processing_header");
  cpl_test_error(CPL_ERROR_NONE);
  muse_image_delete(image);
  muse_imagelist_delete(images);

  // check saving of MUSE pixel tables
  muse_pixtable *pt = cpl_malloc(sizeof(muse_pixtable));
  /* give it a positive size to not fail (when saving as image) */
  pt->table = muse_cpltable_new(muse_pixtable_def, 5);
  pt->header = cpl_propertylist_new();
  cpl_propertylist_append_string(pt->header, "PIXEL TABLE TYPE",
                                 "ITS COMPLICATED"); /* for fun */
  retval = muse_processing_save_table(aProcessing, aParams->nifu,
                                      pt, NULL,
                                      "processing_pixel_table",
                                      MUSE_TABLE_TYPE_PIXTABLE);
  cpl_test_error(CPL_ERROR_NONE);
  muse_pixtable_delete(pt);

  // check saving of MUSE datacubes
  muse_datacube *cube = cpl_calloc(1, sizeof(muse_datacube));
  cube->header = cpl_propertylist_new();
  /* set some FITS keywords that saving of a cube requires */
  cpl_propertylist_append_string(cube->header, "OBJECT", "ANOBJECT");
  cpl_propertylist_append_string(cube->header, "BUNIT", "count");
  cube->data = cpl_imagelist_new();
  cpl_image *plane = cpl_image_new(1, 1, CPL_TYPE_FLOAT);
  cpl_imagelist_set(cube->data, plane, 0);
  cube->stat = cpl_imagelist_duplicate(cube->data);
  retval = muse_processing_save_cube(aProcessing, -1, cube,
                                      "processing_data_cube",
                                      MUSE_CUBE_TYPE_FITS);
  cpl_test_error(CPL_ERROR_NONE);
  muse_datacube_delete(cube);

  // check saving of MUSE masks
  muse_mask *mask = muse_mask_new();
  mask->header = cpl_propertylist_new();
  cpl_propertylist_append_string(mask->header, "OBJECT", "A MASK");
  mask->mask = cpl_mask_new(10, 10);
  retval = muse_processing_save_mask(aProcessing, -1, mask,
                                     "processing_mask");
  cpl_test_error(CPL_ERROR_NONE);
  muse_mask_delete(mask);
  mask = NULL;

#if 0
  // check loading the MUSE mask back
  // XXX this doesn't work with the current XML config for this test and
  //     it would need pre-existing data that somehow gets set in the input SOF
  mask = muse_processing_mask_load(aProcessing, "processing_mask");
  cpl_test_error(CPL_ERROR_NONE);
  cpl_test_nonnull(mask);
  cpl_test_nonnull(mask->header);
  cpl_test_nonnull(mask->mask);
  muse_mask_delete(mask);
#endif

  // check the output frameset
  cpl_test_eq(cpl_frameset_get_size(aProcessing->outframes), 7);
  cpl_frame *frame;
  frame = cpl_frameset_find(aProcessing->outframes, "processing_muse_image");
  cpl_test_nonnull(frame);
  if (frame != NULL) {
    cpl_test_eq_string(cpl_frame_get_filename(frame),
                       "processing_muse_image-01.fits");
    cpl_test_eq(cpl_frame_get_group(frame), CPL_FRAME_GROUP_PRODUCT);
    cpl_test_eq(cpl_frame_get_level(frame), CPL_FRAME_LEVEL_FINAL);
    cpl_test_eq(cpl_frame_get_type(frame), CPL_FRAME_TYPE_IMAGE);
    cpl_test_eq(access(cpl_frame_get_filename(frame), F_OK), 0);
  }
  frame = cpl_frameset_find(aProcessing->outframes, "processing_cpl_image");
  cpl_test_nonnull(frame);
  if (frame != NULL) {
    cpl_test_eq_string(cpl_frame_get_filename(frame),
                       "processing_cpl_image_0001-01.fits");
    cpl_test_eq(cpl_frame_get_group(frame), CPL_FRAME_GROUP_PRODUCT);
    cpl_test_eq(cpl_frame_get_level(frame), CPL_FRAME_LEVEL_TEMPORARY);
    cpl_test_eq(cpl_frame_get_type(frame), CPL_FRAME_TYPE_IMAGE);
    cpl_test_eq(access(cpl_frame_get_filename(frame), F_OK), 0);
  }
  frame = cpl_frameset_find(aProcessing->outframes, "processing_cpl_table");
  cpl_test_nonnull(frame);
  if (frame != NULL) {
    cpl_test_eq_string(cpl_frame_get_filename(frame),
                       "processing_cpl_table-01.fits");
    cpl_test_eq(cpl_frame_get_group(frame), CPL_FRAME_GROUP_PRODUCT);
    cpl_test_eq(cpl_frame_get_level(frame), CPL_FRAME_LEVEL_FINAL);
    cpl_test_eq(cpl_frame_get_type(frame), CPL_FRAME_TYPE_TABLE);
    cpl_test_eq(access(cpl_frame_get_filename(frame), F_OK), 0);
  }
  frame = cpl_frameset_find(aProcessing->outframes, "processing_pixel_table");
  cpl_test_nonnull(frame);
  if (frame != NULL) {
    cpl_test_eq_string(cpl_frame_get_filename(frame),
                       "processing_pixel_table-01.fits");
    cpl_test_eq(cpl_frame_get_group(frame), CPL_FRAME_GROUP_PRODUCT);
    cpl_test_eq(cpl_frame_get_level(frame), CPL_FRAME_LEVEL_FINAL);
    cpl_test_eq(cpl_frame_get_type(frame), CPL_FRAME_TYPE_TABLE);
    cpl_test_eq(access(cpl_frame_get_filename(frame), F_OK), 0);
  }
  frame = cpl_frameset_find(aProcessing->outframes, "processing_header");
  cpl_test_nonnull(frame);
  if (frame != NULL) {
    cpl_test_eq_string(cpl_frame_get_filename(frame),
                       "processing_header-01.fits");
    cpl_test_eq(cpl_frame_get_group(frame), CPL_FRAME_GROUP_PRODUCT);
    cpl_test_eq(cpl_frame_get_level(frame), CPL_FRAME_LEVEL_FINAL);
    cpl_test_eq(cpl_frame_get_type(frame), CPL_FRAME_TYPE_IMAGE);
    cpl_test_eq(access(cpl_frame_get_filename(frame), F_OK), 0);
  }
  frame = cpl_frameset_find(aProcessing->outframes, "processing_data_cube");
  cpl_test_nonnull(frame);
  if (frame != NULL) {
    cpl_test_eq_string(cpl_frame_get_filename(frame),
                       "processing_data_cube.fits");
    cpl_test_eq(cpl_frame_get_group(frame), CPL_FRAME_GROUP_PRODUCT);
    cpl_test_eq(cpl_frame_get_level(frame), CPL_FRAME_LEVEL_FINAL);
    cpl_test_eq(cpl_frame_get_type(frame), CPL_FRAME_TYPE_IMAGE);
    cpl_test_eq(access(cpl_frame_get_filename(frame), F_OK), 0);
  }
  frame = cpl_frameset_find(aProcessing->outframes, "processing_mask");
  cpl_test_nonnull(frame);
  if (frame != NULL) {
    cpl_test_eq_string(cpl_frame_get_filename(frame), "processing_mask.fits");
    cpl_test_eq(cpl_frame_get_group(frame), CPL_FRAME_GROUP_PRODUCT);
    cpl_test_eq(cpl_frame_get_level(frame), CPL_FRAME_LEVEL_FINAL);
    cpl_test_eq(cpl_frame_get_type(frame), CPL_FRAME_TYPE_IMAGE);
    cpl_test_eq(access(cpl_frame_get_filename(frame), F_OK), 0);
  }

  /* clean up */
  cpl_frameset_iterator *fiter = cpl_frameset_iterator_new(aProcessing->outframes);
  frame = cpl_frameset_iterator_get(fiter);
  while (frame) {
    cpl_msg_debug(__func__, "deleting \"%s\"", cpl_frame_get_filename(frame));
    cpl_test(remove(cpl_frame_get_filename(frame)) == 0);
    cpl_frameset_iterator_advance(fiter, 1);
    frame = cpl_frameset_iterator_get(fiter);
  } /* while */
  cpl_frameset_iterator_delete(fiter);

  /* Test some failure cases. All these functions just output   *
   * ERROR messages, they don't set error states by themselves. */
  cpl_errorstate state = cpl_errorstate_get();
  muse_processing_delete(NULL);
  cpl_test(cpl_errorstate_is_equal(state));
  /* try to create a frame, but first fail without processing struct */
  cpl_propertylist *hdr = cpl_propertylist_new();
  cpl_propertylist_append_string(hdr, "DATE-OBS", "2013-08-26T15:55:55.555");
  cpl_propertylist_append_string(hdr, "MUSE PRIVATE SOMETHING", "am I here?");
  state = cpl_errorstate_get();
  cpl_frame *testframe = muse_processing_new_frame(NULL, 10, hdr, "BAD_TAG",
                                                   CPL_FRAME_TYPE_ANY);
  cpl_test(!cpl_errorstate_is_equal(state)
           && cpl_error_get_code() == CPL_ERROR_NULL_INPUT);
  cpl_errorstate_set(state);
  cpl_test_null(testframe);
  /* this will issue a WARNING, because BAD_TAG is not in the XML */
  testframe = muse_processing_new_frame(aProcessing, 10, hdr, "BAD_TAG",
                                        CPL_FRAME_TYPE_ANY);
  cpl_test_nonnull(testframe); /* this time it should have succeeded */
  cpl_test(!cpl_propertylist_has(hdr, "MUSE PRIVATE SOMETHING")); /* be removed */
  /* now use this frame to generate a failure when appending used */
  muse_processing_append_used(NULL, testframe, CPL_FRAME_GROUP_RAW, 1);
  cpl_test(cpl_errorstate_is_equal(state));
  cpl_frame_delete(testframe);
  cpl_propertylist_delete(hdr);
  /* one last check, of muse_processing_check_input() */
  state = cpl_errorstate_get();
  cpl_test(muse_processing_check_input(NULL, 10) == CPL_ERROR_NULL_INPUT);
  cpl_test(cpl_errorstate_is_equal(state)); /* no other error can be propagated */

  return retval;
} /* muse_test_processing_compute() */