MOONS Pipeline Reference Manual 0.13.2
moo_subtract_nod.c
1/*
2 * This file is part of the MOONS Pipeline
3 * Copyright (C) 2002-2016 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27#include <math.h>
28#include <string.h>
29#include <cpl.h>
30
31#include "moo_subtract_nod.h"
32#include "moo_fits.h"
33#include "moo_pfits.h"
34#include "moo_badpix.h"
35#include "moo_qc.h"
36#include "moo_fibres_table.h"
37#include "moo_utils.h"
38/*----------------------------------------------------------------------------*/
43/*----------------------------------------------------------------------------*/
44
47/*-----------------------------------------------------------------------------
48 Function codes
49 -----------------------------------------------------------------------------*/
50
51/*----------------------------------------------------------------------------*/
68/*----------------------------------------------------------------------------*/
69moo_det *
70moo_subtract_nod(moo_det *object, moo_det *sky, const char *filename)
71{
72 cpl_frame *nod_det_frame = NULL;
73 moo_det *nod_det = NULL;
74 cpl_propertylist *sky_header = NULL;
75 cpl_ensure(object != NULL, CPL_ERROR_NULL_INPUT, NULL);
76 cpl_ensure(sky != NULL, CPL_ERROR_NULL_INPUT, NULL);
77
78 cpl_errorstate prestate = cpl_errorstate_get();
79
80 unsigned int badpix_level = MOO_BADPIX_GOOD;
81
82 moo_try_check(moo_det_save(object, filename), " ");
83 nod_det_frame = cpl_frame_new();
84 cpl_frame_set_filename(nod_det_frame, filename);
85
86 nod_det = moo_det_create(nod_det_frame);
87 moo_try_check(moo_det_load(nod_det, badpix_level), " ");
88 moo_try_check(moo_det_rescale_using_exptime(sky, object), " ");
89
90 moo_try_check(moo_det_subtract(nod_det, sky), " ");
91
92 sky_header = moo_det_get_primary_header(sky);
93 if (cpl_propertylist_has(sky_header, MOONS_QC_FRAME_RAW1)) {
94 const char *sky_filename =
95 cpl_propertylist_get_string(sky_header, MOONS_QC_FRAME_RAW1);
96 moo_qc_set_frame_raw2(nod_det->primary_header, sky_filename);
97 }
98 cpl_table *fibre_table = moo_det_get_fibre_table(nod_det);
99 moo_try_check(moo_fibres_table_add_nod_cols(fibre_table), " ");
100 cpl_table *sky_fibre_table = moo_det_get_fibre_table(sky);
101
102 int sky_nrow = cpl_table_get_nrow(sky_fibre_table);
103 int nrow = cpl_table_get_nrow(fibre_table);
104
105 moo_try_assure(
106 sky_nrow == nrow, CPL_ERROR_ILLEGAL_INPUT,
107 "OBJECT fibre table rows and sky fibre table rows doesnt match");
108 for (int i = 0; i < nrow; i++) {
109 const char *t =
110 cpl_table_get_string(sky_fibre_table, MOO_FIBRES_TABLE_TYPE, i);
111 cpl_table_set_string(fibre_table, MOO_FIBRES_TABLE_TYPE_NOD, i, t);
112 }
113moo_try_cleanup:
114 cpl_frame_delete(nod_det_frame);
115 if (!cpl_errorstate_is_equal(prestate)) {
116 moo_det_delete(nod_det);
117 nod_det = NULL;
118 }
119 return nod_det;
120}
#define MOO_BADPIX_GOOD
Definition: moo_badpix.h:36
cpl_error_code moo_det_rescale_using_exptime(moo_det *self, moo_det *det)
Rescale using exptime factor.
Definition: moo_det.c:721
cpl_propertylist * moo_det_get_primary_header(moo_det *self)
Get the PRIMARY HEADER in DET.
Definition: moo_det.c:453
moo_det * moo_det_create(const cpl_frame *frame)
Create a new moo_det from the given DET frame.
Definition: moo_det.c:91
void moo_det_save(moo_det *self, const char *filename)
Save a moo_det to a FITS file.
Definition: moo_det.c:507
cpl_table * moo_det_get_fibre_table(moo_det *self)
Get the FIBRE TABLE in DET.
Definition: moo_det.c:424
cpl_error_code moo_det_load(moo_det *self, unsigned int level)
Load all parts in DET.
Definition: moo_det.c:135
cpl_error_code moo_det_subtract(moo_det *self, moo_det *det)
Subtract DET structure.
Definition: moo_det.c:643
void moo_det_delete(moo_det *self)
Delete a moo_det.
Definition: moo_det.c:472
cpl_error_code moo_fibres_table_add_nod_cols(cpl_table *table)
add nod additional columns
moo_det * moo_subtract_nod(moo_det *object, moo_det *sky, const char *filename)
Sky from object subtraction.
cpl_error_code moo_qc_set_frame_raw2(cpl_propertylist *plist, const char *val)
Set the QC.FRAME.RAW2 value.
Definition: moo_qc.c:2331