ERIS Pipeline Reference Manual 1.8.14
eris_ifu_sdp.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) 2015 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#ifdef HAVE_CONFIG_H
23#include <config.h>
24#endif
25
26/*----------------------------------------------------------------------------*
27 * Includes *
28 *----------------------------------------------------------------------------*/
29#include <string.h>
30#include <eris_pfits.h>
31#include "eris_ifu_sdp.h"
32#include "eris_ifu_dfs.h"
33#include <math.h>
34#include <cpl.h>
35#include <eris_utils.h>
36#include <eris_ifu_utils.h>
37#include <eris_ifu_wavecal_static.h>
38/*
39#include "muse_dfs.h"
40#include "muse_pfits.h"
41#include "muse_rtcdata.h"
42#include "muse_pixtable.h"
43#include "muse_cplwrappers.h"
44#include "muse_wcs.h"
45#include "muse_flux.h"
46#include "muse_utils.h"
47 */
48
49/*----------------------------------------------------------------------------*
50 * Defines *
51 *----------------------------------------------------------------------------*/
52
53#define KEY_ASSON "ASSON"
54#define KEY_ASSON_COMMENT "Associated file name"
55#define KEY_ASSOC "ASSON"
56#define KEY_ASSOC_COMMENT "Associated file category"
57#define KEY_ASSOM "ASSOM"
58#define KEY_ASSOM_COMMENT "Associated file datamd5"
59
60#define KEY_DEC "DEC"
61#define KEY_DEC_COMMENT "[deg] Image center (J2000)"
62#define KEY_EXPTIME "EXPTIME"
63#define KEY_EXPTIME_COMMENT "[s] Total integration time per pixel"
64#define KEY_FLUXCAL "FLUXCAL"
65#define KEY_FLUXCAL_COMMENT "Type of flux calibration (ABSOLUTE or UNCALIBRATED)"
66#define KEY_FLUXCAL_VALUE_FALSE "UNCALIBRATED"
67#define KEY_FLUXCAL_VALUE_TRUE "ABSOLUTE"
68#define KEY_MJDOBS "MJD-OBS"
69#define KEY_MJDOBS_COMMENT "[d] Start of observations (days)"
70#define KEY_MJDEND "MJD-END"
71#define KEY_MJDEND_COMMENT "[d] End of observations (days)"
72#define KEY_OBID "OBID"
73#define KEY_OBID1 "OBID1"
74#define KEY_OBID_COMMENT "Observation block ID"
75#define KEY_OBSTECH "OBSTECH"
76#define KEY_OBSTECH_COMMENT "Technique for observation"
77#define KEY_PROCSOFT "PROCSOFT"
78#define KEY_PROCSOFT_COMMENT "ESO pipeline version"
79#define KEY_PRODCATG "PRODCATG"
80#define KEY_PRODCATG_COMMENT "Data product category"
81#define KEY_PRODCATG_VALUE_IFS_CUBE "SCIENCE.CUBE.IFS"
82#define KEY_PRODCATG_VALUE_FOV_IMAGE "ANCILLARY.IMAGE"
83#define KEY_PROG_ID "PROG_ID"
84#define KEY_PROG_ID_COMMENT "ESO programme identification"
85#define KEY_PROG_ID_VALUE_MULTIPLE "MULTI"
86#define KEY_PROGID "PROGID"
87#define KEY_PROGID_COMMENT KEY_PROG_ID_COMMENT
88#define KEY_PROV "PROV"
89#define KEY_PROV_COMMENT "Originating raw science file"
90#define KEY_RA "RA"
91#define KEY_RA_COMMENT "[deg] Image center (J2000)"
92#define KEY_REFERENC "REFERENC"
93#define KEY_REFERENC_COMMENT "Reference publication"
94#define KEY_TEXPTIME "TEXPTIME"
95#define KEY_TEXPTIME_COMMENT "[s] Total integration time of all exposures"
96#define KEY_WAVELMIN "WAVELMIN"
97#define KEY_WAVELMIN_COMMENT "[nm] Minimum wavelength"
98#define KEY_WAVELMAX "WAVELMAX"
99#define KEY_WAVELMAX_COMMENT "[nm] Maximum wavelength"
100#define KEY_SKY_RES "SKY_RES"
101#define KEY_SKY_RES_COMMENT "[arcsec] FWHM effective spatial resolution"
102#define KEY_SKY_RERR "SKY_RERR"
103#define KEY_SKY_RERR_COMMENT "[arcsec] Error of SKY_RES"
104#define KEY_SPEC_RES "SPEC_RES"
105#define KEY_SPEC_RES_COMMENT "Spectral resolving power at central wavelength"
106#define KEY_SPEC_ERR "CRDER3"
107#define KEY_SPEC_ERR_COMMENT "[angstrom] Random error in spectral coordinate"
108#define KEY_SPECSYS "SPECSYS"
109#define KEY_SPECSYS_COMMENT "Frame of reference for spectral coordinates."
110#define KEY_PIXNOISE "PIXNOISE"
111#define KEY_PIXNOISE_COMMENT "[erg.s**(-1).cm**(-2).angstrom**(-1)] pixel-to-pixel noise"
112#define KEY_ABMAGLIM "ABMAGLIM"
113#define KEY_ABMAGLIM_COMMENT "5-sigma magnitude limit for point sources"
114#define KEY_NCOMBINE "NCOMBINE"
115#define KEY_NCOMBINE_COMMENT "No. of combined raw science data files"
116
117/* A regular expression matching SDP IFS standard keywords to be cleared. */
118#define CLEAN_KEYS_REGEXP \
119 "^(" KEY_MJDEND "|" \
120 KEY_PROCSOFT "|" \
121 KEY_PRODCATG "|" \
122 KEY_PROG_ID "|" \
123 KEY_PROGID "[0-9]+|" \
124 KEY_OBID "[0-9]+|" \
125 KEY_OBSTECH "|" \
126 KEY_FLUXCAL "|" \
127 KEY_TEXPTIME "|" \
128 KEY_WAVELMIN "|" \
129 KEY_WAVELMAX "|" \
130 KEY_SKY_RES "|" \
131 KEY_SKY_RERR "|" \
132 KEY_SPEC_RES "|" \
133 KEY_PIXNOISE "|" \
134 KEY_ABMAGLIM "|" \
135 KEY_REFERENC "|" \
136 KEY_NCOMBINE "|" \
137 KEY_PROV "[0-9]+|" \
138 KEY_ASSON "[0-9]+" ")$"
139
140/*----------------------------------------------------------------------------*/
144/*----------------------------------------------------------------------------*/
145
148/* Lookup table for spectral resolution vs. wavelength */
149
150typedef struct {
151 /* Wavelength in Angstrom at which the spectral resolution was measured. */
152 double lambda;
153 /* Measured spectral resolution. */
154 double R;
155} eris_ifu_specres_lut_entry;
156
157/* The last entry in the data tables must have a zero wavelength entry! */
158
159//static const eris_ifu_specres_lut_entry
160//eris_ifu_specres_data_wfm[] =
161//{
162// {4650.0000, 1674.77},
163// {4810.3448, 1769.45},
164// {4970.6897, 1864.50},
165// {5131.0345, 1959.52},
166// {5291.3793, 2054.19},
167// {5451.7242, 2148.34},
168// {5612.0690, 2241.81},
169// {5772.4138, 2334.46},
170// {5932.7587, 2426.18},
171// {6093.1035, 2516.84},
172// {6253.4483, 2606.28},
173// {6413.7932, 2694.36},
174// {6574.1380, 2780.89},
175// {6734.4828, 2865.70},
176// {6894.8277, 2948.59},
177// {7055.1725, 3029.32},
178// {7215.5173, 3107.70},
179// {7375.8622, 3183.46},
180// {7536.2070, 3256.36},
181// {7696.5518, 3326.12},
182// {7856.8967, 3392.45},
183// {8017.2415, 3455.01},
184// {8177.5863, 3513.44},
185// {8337.9312, 3567.37},
186// {8498.2760, 3616.34},
187// {8658.6208, 3659.87},
188// {8818.9657, 3697.42},
189// {8979.3105, 3728.38},
190// {9139.6553, 3752.11},
191// {9300.0002, 3767.93},
192// { 0.0000 , 0.00}
193//};
194
195/* XXX: Dummy values from the User Manual for the NFM. Update for production. */
196//static const eris_ifu_specres_lut_entry
197//eris_ifu_specres_data_nfm[] =
198//{
199// {4800.0000, 1740.00},
200// {9300.0000, 3450.00},
201// { 0.0000 , 0.00}
202//};
203
204/* Instrument properties and reference values */
205
206/* Number of detector readout ports */
207//static const unsigned int kErisNumQuadrants = 4;
208
209/* Nominal field size [arcsec] */
210//static const double kErisFovSizeWFM = 60.00;
211//static const double kErisFovSizeNFM = 7.43;
212
213/* Nominal pixel scale wfm, nfm */
214//static const double kErisPixscaleWFM = 0.2;
215//static const double kErisPixscaleNFM = 0.025;
216
217/* Reference wavelength [Angstrom] */
218//static const double kErisLambdaRef = 7000.;
219
220/* Instrument response at reference wavelength */
221//static const double kErisResponseRef = 41.2;
222
223/* Typical error estimated from unresolved sources [arcsec] */
224//static const double kErisExtraErrorIQE = 0.3;
225
226/* Typical values [arcsec] for the effective spatial resolution *
227 * and its uncertainty, given by the median and the standard *
228 * deviation of previous measurements. */
229//static const double kErisSkyResWFM = 0.853823;
230//static const double kErisSkyResErrorWFM = 0.495547;
231//static const double kErisSkyResNFM = 0.15;
232//static const double kErisSkyResErrorNFM = 0.05;
233
234
235/* Unit conversion factors */
236
237static const double day2sec = 86400.0; /* Seconds per day */
238//static const double m2nm = 1.e9; /* meter to nanometer */
239//static const double nm2Angstrom = 10.; /* nanometer to Angstrom */
240//static const double deg2as = 3600.; /* degrees to arcseconds */
241
242
243/*----------------------------------------------------------------------------*
244 * Functions *
245 *----------------------------------------------------------------------------*/
246
247
250// @private
251// @brief Compute spectral resolution for the central wavelength.
252// @param aLambda Wavelength in Angstrom.
253// @param aSpecresLut Spectral resolution look-up table.
254// @return The interpolated spectral resolution
255
256// The function computes the spectral resolution at the wavelength @em aLambda,
257// by interpolating the data points given by the look-up table @em aSpecresLut.
258// For wavelengths outside of the wavelength range of the table, the lower, or
259// the upper boundary value is returned, respectively.
260// */
262//static double
263//eris_ifu_idp_compute_specres(double aLambda, const eris_ifu_specres_lut_entry *aSpecresLut)
264//{
265
266// /* Locate the appropriate wavelength bin in the lut and compute the *
267// * spectral by linear interpolation. */
268
269// cpl_size i = 0;
270// while ((aSpecresLut[i].lambda > 0.) && (aLambda > aSpecresLut[i].lambda)) {
271// ++i;
272// }
273
274// if (i == 0) {
275// return aSpecresLut[0].R;
276// }
277// else if (aSpecresLut[i].lambda == 0.) {
278// return aSpecresLut[i - 1].R;
279// }
280
281// double t = (aLambda - aSpecresLut[i - 1].lambda) /
282// (aSpecresLut[i].lambda - aSpecresLut[i - 1].lambda);
283
284// return (1 - t) * aSpecresLut[i - 1].R + t * aSpecresLut[i].R;
285//}
286
289// @private
290// @brief Estimate image quality at a given wavelength from the seeing
291// and the airmass.
292// @param aLambda Wavelength in Angstrom at which the image quality is
293// computed.
294// @param aSeeing The seeing as seen by the telescope and corrected for
295// airmass.
296// @param aAirmass Airmass at which the observation was carried out.
297// @return The estimate of the image quality at the given wavelength.
298
299// The returned image quality estimate is in units of arcsec.
300// */
302//static double
303//eris_ifu_idp_compute_iqe(double aLambda, double aSeeing, double aAirmass)
304//{
305
306// const double rad2as = 180. / CPL_MATH_PI * 3600.; /* radians to arcsec */
307
308
309// /* Wavefront outer scale at Paranal [meters] */
310// const double L0 = 23.;
311
312// /* UT M1 diameter [meters] from UT M1 vignetted area */
313// const double D = 8.1175365721399437;
314
315// /* Kolb factor (cf. ESO Technical Report 12) */
316// const double Fkolb = 1. / (1. + 300. * D / L0) - 1.;
317
318
319// /* Scaled wavelength: lambda over lambda_ref */
320// double lambda = aLambda / 5000.;
321
322// /* Fried parameter */
323// double r0 = 0.976 * 5.e-7 / aSeeing * rad2as *
324// pow(lambda, 1.2) * pow(aAirmass, -0.6);
325
326// double iqe = aSeeing * pow(lambda, -0.2) * pow(aAirmass, 0.6);
327// iqe *= sqrt(1. + Fkolb * 2.183 * pow(r0 / L0, 0.356));
328
329// return iqe;
330//}
331
334// @private
335// @brief Compute the effective spatial resolution from the Strehl ratio.
336// @param aSkyres Computed effective spatial resolution.
337// @param aSkyresError Error of the computed effective spatial resolution.
338// @param aStrehl Strehl ratio to convert.
339// @param aStrehlError Error of the Strehl ratio.
340// @return Nothing.
341
342// Converts the given input Strehl ratio into an effective spatial resolution
343// valid for a MUSE NFM observation. The conversion uses an empirical model
344// which is only valid for the MUSE NFM mode!
345
346// The computed spatial resolution and its uncertainty are stored at the
347// location referenced by @em aSkyres and @em aSkyresError.
348// */
350//static void
351//eris_ifu_idp_compute_skyres_from_strehl(double *aSkyres, double *aSkyresError,
352// double aStrehl, double aStrehlError)
353//{
354// /* Parameter values of the empirically determined model used to convert *
355// * a Strehl ratio into an effective spatial resolution for the NFM *
356// * instrument mode. */
357// const double rms = 0.01;
358// const double parameter[3] = {-0.71985411, 0.81622807, -0.01941496};
359
360// const double strehl_min = 1.;
361// const double strehl_max = 80.;
362
363// /* The uncertainty of the Strehl ratio is actually not used in the *
364// * following model implementation. Keep it to be prepared. */
365// CPL_UNUSED(aStrehlError);
366
367// /* Keep the input strehl ratio to the model within the limits */
368// double strehl = CPL_MIN(CPL_MAX(aStrehl, strehl_min), strehl_max);
369
370// double skyres = parameter[0] + parameter[1] * pow(strehl, parameter[2]);
371// double skyrerr = parameter[1] * parameter[2] *
372// pow(strehl, (parameter[2] - 1.));
373// skyrerr = sqrt(skyrerr * skyrerr + rms * rms);
374
375// *aSkyres = skyres;
376// *aSkyresError = skyrerr;
377// return;
378//}
379
380/*----------------------------------------------------------------------------*/
390/*----------------------------------------------------------------------------*/
391
392static double
393eris_ifu_sdp_compute_fwhm(cpl_frameset* set)
394{
395 cpl_ensure(set != NULL, CPL_ERROR_NULL_INPUT, 0);
396 // double abmaglimit = 0;
397 cpl_frame* frm = NULL;
398 // cpl_size nexposures = cpl_frameset_count_tags(set, ERIS_IFU_RAW_OBJ);
399 cpl_size kexposure = 0;
400 const char* fname;
401 cpl_propertylist* phead;
402 cpl_size next = 0;
403
404 frm = cpl_frameset_get_position(set, kexposure);
405 next = cpl_frame_get_nextensions(frm);
406 fname = cpl_frame_get_filename(frm);
407 phead = cpl_propertylist_load(fname, 0);
408 cpl_msg_info(cpl_func,"fname: %s next: %lld",fname, next);
409 cpl_table* asm_data;
410 double IA_fwhm_corr = 0;
411 double IA_fwhm_corr_pix = 0;
412 if (next > 0) {
413 double IA_fwhm = 0;
414 double dimm = 0;
415 ifsBand bandId = eris_ifu_get_band(phead);
416 asm_data = cpl_table_load(fname, 1, 0);
417 if(cpl_table_has_column(asm_data,"IA_FWHM")) {
418 IA_fwhm = cpl_table_get_column_mean(asm_data,"IA_FWHM");
419 } else if (cpl_propertylist_has(phead,"ESO TEL IA FWHM")) {
420 IA_fwhm = cpl_propertylist_get_double(phead,"ESO TEL IA FWHM");
421 }
422 if(cpl_table_has_column(asm_data,"DIMM_SEEING")) {
423 dimm = cpl_table_get_column_mean(asm_data,"DIMM_SEEING");
424 } else {
425 double airm_start = 0;
426 double airm_end = 0;
427
428 if (cpl_propertylist_has(phead,"ESO TEL AMBI FWHM START")) {
429 airm_start = eris_pfits_get_fwhm_start(phead);
430 }
431
432 if (cpl_propertylist_has(phead,"ESO TEL AMBI FWHM END")) {
433 airm_end = eris_pfits_get_fwhm_end(phead);
434 }
435
436 if(airm_start > 0 && airm_end > 0) {
437 dimm = 0.5 * (airm_start + airm_end);
438 } else if (airm_start > 0 && airm_end == 0) {
439 dimm = airm_start;
440 } else if (airm_start > 0 && airm_end == 0) {
441 dimm = airm_end;
442 }
443
444 }
445 cpl_table_delete(asm_data);
446 /* compute the wavelength corrected FWHM values from the ASM extension */
447 double lambda_c = 1;
448 eris_ifu_get_central_lambda(bandId, &lambda_c);
449 ifsPreopticsScale scale = eris_ifu_get_preopticsScale(phead);
450 double pix_scale = 1;
451 switch(scale){
452 case S25MAS: pix_scale = 0.025; break;
453 case S100MAS:pix_scale = 0.100; break;
454 case S250MAS:pix_scale = 0.250; break;
455 default:
456 cpl_msg_error(cpl_func,"scale not found");
457 break;
458 }
459
460
461 IA_fwhm_corr = IA_fwhm * pow((0.500/lambda_c), 0.2 );
462 IA_fwhm_corr_pix = IA_fwhm_corr / pix_scale;
463 cpl_msg_info(cpl_func,"IA_fwhm_corr: %g",IA_fwhm_corr);
464 cpl_msg_info(cpl_func,"IA_fwhm_corr_pix: %g",IA_fwhm_corr_pix);
465 double airmass = eris_pfits_get_airmass(phead);
466
467 double dimm_corr = dimm *
468 pow((0.500/lambda_c),0.2) *
469 pow(airmass,(3./5.)) *
470 (1. - 78.08 *
471 (pow( (lambda_c / 1.e6), 0.4) *
472 (pow(airmass, -0.2) / pow(dimm, (1./3.)))
473 ));
474 cpl_msg_info(cpl_func,"dimm_corr: %g",dimm_corr);
475 double dimm_corr_pix = dimm_corr/pix_scale;
476 cpl_msg_info(cpl_func,"dimm_corr_pix: %g",dimm_corr_pix);
477 }
478
479 cpl_propertylist_delete(phead);
480 eris_check_error_code("eris_ifu_sdp_compute_fwhm");
481 return IA_fwhm_corr;
482
483
484 //abmaglimit = -2.5 * log10(2. * sdev / kMuseFluxUnitFactor) + zeropoint;
485}
486
487static double
488eris_ifu_sdp_compute_pixnoise(cpl_frameset* set) {
489
490 cpl_ensure(set != NULL, CPL_ERROR_NULL_INPUT, 0);
491 cpl_frame* frm = NULL;
492 //cpl_frameset_dump(set,stdout);
493 cpl_error_code error_code = cpl_error_get_code();
494 cpl_error_set(cpl_func, error_code);
495
496 if(NULL != cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_CUBE_COADD_FLUXCAL_MEAN)) {
497 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_CUBE_COADD_FLUXCAL_MEAN);
498 } else if(NULL != cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_CUBE_MEAN_FLUXCAL)) {
499 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_CUBE_MEAN_FLUXCAL);
500 } else if(NULL != cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_DAR_CUBE_FLUXCAL_MEAN)) {
501 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_DAR_CUBE_FLUXCAL_MEAN);
502 } else if(NULL != cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_FLUXCAL_MEAN)) {
503 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_FLUXCAL_MEAN);
504 } else if(NULL != cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_FLUX_STD_CUBE_COADD_FLUXCAL_MEAN)) {
505 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_FLUX_STD_CUBE_COADD_FLUXCAL_MEAN);
506 } else if(NULL != cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_TWK_OBJ_CUBE_COADD_FLUXCAL_MEAN)) {
507 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_TWK_OBJ_CUBE_COADD_FLUXCAL_MEAN);
508 }
509
510 const char* fname = cpl_frame_get_filename(frm);
511 cpl_msg_warning(cpl_func,"fname: %s",fname);
512 cpl_image* data = cpl_image_load(fname, CPL_TYPE_DOUBLE, 0, 1);
513 cpl_image* errs = cpl_image_load(fname, CPL_TYPE_DOUBLE, 0, 2);
514 cpl_image* qual = cpl_image_load(fname, CPL_TYPE_INT, 0, 3);
515
516 cpl_mask* bpm = cpl_mask_threshold_image_create(qual, DBL_MIN, 0.9);
517 cpl_image_reject_from_mask(data, bpm);
518 cpl_mask_delete(bpm);
519 //cpl_image_set_bpm(errs, bpm);
520
521 hdrl_image* hima = hdrl_image_create(data, errs);
522
523 cpl_image_delete(data);
524 cpl_image_delete(errs);
525 cpl_image_delete(qual);
526
528 /* TODO: which of the two option should we use to mask the object? */
529 //cpl_mask* obj_mask = eris_ifu_hima_get_obj_mask_percent(hima, 0.5);
530 cpl_mask* obj_mask = eris_ifu_hima_get_obj_mask(hima, 3, 3);
531
532 hdrl_image_reject_from_mask(hima, obj_mask);
533
534 double pixnoise = hdrl_image_get_stdev(hima);
535
536 hdrl_image_delete(hima);
537
538
539 cpl_mask_delete(obj_mask);
540 eris_check_error_code("eris_ifu_sdp_compute_pixnoise");
541 return pixnoise;
542}
543
544static hdrl_image*
545eris_ifu_sdp_get_obj_mean(cpl_frameset* set) {
546
547 cpl_ensure(set != NULL, CPL_ERROR_NULL_INPUT, NULL);
548 cpl_frame* frm = NULL;
549 //cpl_frameset_dump(set,stdout);
550 cpl_error_code error_code = cpl_error_get_code();
551 cpl_error_set(cpl_func, error_code);
552 cpl_msg_warning(cpl_func,"search input frame");
553
554 if(NULL != cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_DAR_CUBE_FLUXCAL_MEAN)) {
555 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_DAR_CUBE_FLUXCAL_MEAN);
556 } else if(NULL != cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_CUBE_COADD_FLUXCAL_MEAN)) {
557 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_CUBE_COADD_FLUXCAL_MEAN);
558 } else if(NULL != cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_STD_CUBE_COADD_FLUXCAL_MEAN)) {
559 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_STD_CUBE_COADD_FLUXCAL_MEAN);
560 } else if(NULL != cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_FLUX_STD_CUBE_COADD_FLUXCAL_MEAN)) {
561 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_FLUX_STD_CUBE_COADD_FLUXCAL_MEAN);
562 } else if(NULL != cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_FLUXCAL_MEAN)) {
563 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_FLUXCAL_MEAN);
564 } else if(NULL != cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_TWK_OBJ_CUBE_COADD_FLUXCAL_MEAN)) {
565 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_TWK_OBJ_CUBE_COADD_FLUXCAL_MEAN);
566 }
567
568 const char* fname = cpl_frame_get_filename(frm);
569
570 cpl_image* data = cpl_image_load(fname, CPL_TYPE_DOUBLE, 0, 1);
571 cpl_image* errs = cpl_image_load(fname, CPL_TYPE_DOUBLE, 0, 2);
572 cpl_image* qual = cpl_image_load(fname, CPL_TYPE_INT, 0, 3);
573 cpl_mask* bpm = cpl_mask_threshold_image_create(qual, DBL_MIN, 0.9);
574
575 cpl_image_set_bpm(data, bpm);
576 //cpl_image_set_bpm(errs, bpm);
577
578 hdrl_image* hima = hdrl_image_create(data, errs);
579
581
582 /* TODO: which of the two option should we use to mask the object? */
583 //cpl_mask* obj_mask = eris_ifu_hima_get_obj_mask_percent(hima, 0.5);
584 cpl_mask* obj_mask = eris_ifu_hima_get_obj_mask(hima, 1, 3);
585 //hdrl_image_reject_from_mask(hima, obj_mask);
586
587 cpl_image_delete(data);
588 cpl_image_delete(errs);
589 cpl_image_delete(qual);
590 cpl_mask_delete(obj_mask);
591
592 eris_check_error_code("eris_ifu_sdp_get_obj_mean");
593 return hima;
594}
595
596static double
597eris_ifu_sdp_compute_zp(ifsBand band)
598{
599 double ZP = 0;
600 switch(band) {
601 /* OLD
602 case J_LOW: ZP = -23.05987; break; // no result??
603 case J_SHORT: ZP = -22.720572007420277; break;
604 case J_MIDDLE: ZP = -23.059874978944993; break;
605 case J_LONG: ZP = -23.40258436053865; break;
606 case H_LOW: ZP = -23.36106526995602; break;
607 case H_SHORT: ZP = -23.539146965; break;
608 case H_MIDDLE: ZP = -23.911951487414118; break;
609 case H_LONG: ZP = -23.9152376244; break;
610 case K_LOW: ZP = -24.516976313167717; break;
611 case K_SHORT: ZP = -24.2690232517; break;
612 case K_MIDDLE: ZP = -24.413665245625793; break;
613 case K_LONG: ZP = -24.644367831; break;
614 default: ZP = 2; break;
615 */
616 /* Using Mark's formula:zp = ab_mag + 2.5 * math.log10(f3_max) - apcor3 */
617 case J_LOW: ZP = -23.564080671; break; //not available take mean of other band values
618 case J_SHORT: ZP = -23.370149709; break; //
619 case J_MIDDLE: ZP = -23.575634864; break; //
620 case J_LONG: ZP = -23.746457445; break; //
621 case H_LOW: ZP = -23.764826331; break; //
622 case H_SHORT: ZP = -23.961968187; break; //
623 case H_MIDDLE: ZP = -24.238252577; break; //
624 case H_LONG: ZP = -24.396966217; break; //
625 case K_LOW: ZP = -24.89135131; break;//
626 case K_SHORT: ZP = -24.730943402; break; //
627 case K_MIDDLE: ZP = -24.8542167693; break;//
628 case K_LONG: ZP = -25.24818993; break;//
629 default: ZP = 2; break;
630
631
632 }
633 return ZP;
634}
635static double
636eris_ifu_sdp_compute_abmaglimit(const double sky_rms, const double fwhm,
637 ifsBand band) {
638
639 double abmaglim = 0;
640 //ABmaglim = -2.5*log10(5. * FWHM * sky_rms * sqrt(pi)/(2. * sqrt(log(4)))) - 2.5 * log10(2.) + ZP
641 double ZP = eris_ifu_sdp_compute_zp(band);
642 abmaglim = -2.5*log10(5. * fwhm * sky_rms * sqrt(CPL_MATH_PI) /
643 (2. * sqrt(log(4)))) - 2.5 * log10(2.) + ZP;
644
645 eris_check_error_code("eris_ifu_sdp_compute_abmaglimit");
646 return abmaglim;
647}
648eris_ifu_sdp_properties *
649eris_ifu_sdp_properties_new(void) {
650 eris_ifu_sdp_properties *properties = cpl_calloc(1, sizeof *properties);
651 return properties;
652}
653
654void
655eris_ifu_sdp_properties_delete(eris_ifu_sdp_properties *aProperties)
656{
657 if (aProperties) {
658 cpl_array_delete(aProperties->obid);
659 cpl_array_delete(aProperties->progid);
660 cpl_propertylist_delete(aProperties->prov);
661 cpl_array_delete(aProperties->asson);
662
663 /* TODO: Remove deallocator call for assoc once it has been *
664 * removed from the interface. */
665 cpl_array_delete(aProperties->assoc);
666 cpl_free((char *)aProperties->prodcatg);
667 //cpl_free((char *)aProperties->procsoft);
668 cpl_free((char *)aProperties->specsys);
669 cpl_free((char *)aProperties->obstech);
670 cpl_free((char *)aProperties->referenc);
671 }
672 cpl_free(aProperties);
673 return;
674}
675
676/*----------------------------------------------------------------------------*/
684/*----------------------------------------------------------------------------*/
685const char *
686eris_ifu_pfits_get_origfile(const cpl_propertylist *aHeaders)
687{
688 const char *value = cpl_propertylist_get_string(aHeaders, "ORIGFILE");
689 cpl_ensure(value, cpl_error_get_code(), NULL);
690 return value;
691}
692
695// @private
696// @brief Estimate image quality at a given wavelength from the seeing
697// and the airmass.
698// @param aLambda Wavelength in Angstrom at which the image quality is
699// computed.
700// @param aSeeing The seeing as seen by the telescope and corrected for
701// airmass.
702// @param aAirmass Airmass at which the observation was carried out.
703// @return The estimate of the image quality at the given wavelength.
704
705// The returned image quality estimate is in units of arcsec.
706// */
708//static double
709//eris_ifu_sdp_compute_iqe(double aLambda, double aSeeing, double aAirmass)
710//{
711
712// const double rad2as = 180. / CPL_MATH_PI * 3600.; /* radians to arcsec */
713
714
715// /* Wavefront outer scale at Paranal [meters] */
716// const double L0 = 23.;
717
718// /* UT M1 diameter [meters] from UT M1 vignetted area */
719// const double D = 8.1175365721399437;
720
721// /* Kolb factor (cf. ESO Technical Report 12) */
722// const double Fkolb = 1. / (1. + 300. * D / L0) - 1.;
723
724
725// /* Scaled wavelength: lambda over lambda_ref */
726// double lambda = aLambda / 5000.;
727
728// /* Fried parameter */
729// double r0 = 0.976 * 5.e-7 / aSeeing * rad2as *
730// pow(lambda, 1.2) * pow(aAirmass, -0.6);
731
732// double iqe = aSeeing * pow(lambda, -0.2) * pow(aAirmass, 0.6);
733// iqe *= sqrt(1. + Fkolb * 2.183 * pow(r0 / L0, 0.356));
734
735// return iqe;
736//}
737
738static cpl_error_code
739eris_ifu_get_sdp_frames(cpl_frameset* set, const cpl_parameterlist* parlist,
740 const char* recipe_name, eris_ifu_sdp_properties *properties,
741 cpl_frameset** raws_obj, cpl_frameset** raws_sky, cpl_frameset** pros_obj)
742{
743
744 cpl_ensure(set != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
745 cpl_ensure(parlist != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
746 cpl_ensure(recipe_name != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
747 cpl_ensure(properties != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
748
749 char* param_name = cpl_sprintf("eris.%s.dar-corr", recipe_name);
750 cpl_boolean is_dar_cor =
751 cpl_parameter_get_bool(cpl_parameterlist_find_const(parlist, param_name));
752 cpl_free(param_name);
753
754
755 param_name = cpl_sprintf("eris.%s.sky_tweak", recipe_name);
756 int is_sky_tweak =
757 cpl_parameter_get_int(cpl_parameterlist_find_const(parlist, param_name));
758 cpl_free(param_name);
759
760 cpl_size nexposures = 0;
761 cpl_frame* frm = NULL;
762 //cpl_frameset_dump(set, stdout);
763 //exit(0);
764 if (strstr(recipe_name, "jitter") != NULL) {
765
766 *raws_obj = eris_dfs_extract_frames_with_tag (set, ERIS_IFU_RAW_OBJ);
767 if(is_dar_cor) {
768 *pros_obj = eris_dfs_extract_frames_with_tag (set, ERIS_IFU_PRO_JITTER_DAR_CUBE);
769 } else {
770 *pros_obj = eris_dfs_extract_frames_with_tag (set, ERIS_IFU_PRO_JITTER_OBJ_CUBE);
771 }
772
773 if(is_sky_tweak > 0) {
774 *pros_obj = eris_dfs_extract_frames_with_tag (set, ERIS_IFU_PRO_JITTER_TWK_CUBE);
775 } else {
776 *pros_obj = eris_dfs_extract_frames_with_tag (set, ERIS_IFU_PRO_JITTER_OBJ_CUBE);
777 }
778 if(*pros_obj != NULL) {
779 // same PRO.CATG independently from DAR correction
780 if(is_dar_cor) {
781 if(NULL == (frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_DAR_CUBE_FLUXCAL_MEAN))) {
782 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_CUBE_COADD_FLUXCAL_MEAN);
783 }
784 } else {
785 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_CUBE_COADD_FLUXCAL_MEAN);
786 }
787 if(frm != NULL) {
788 cpl_frameset_insert(*pros_obj, cpl_frame_duplicate(frm));
789 }
790
791
792 if(is_sky_tweak > 0) {
793 if(NULL == (frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_DAR_CUBE_FLUXCAL_MEAN))) {
794 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_CUBE_COADD_FLUXCAL_MEAN);
795 }
796 } else {
797 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_OBJ_CUBE_COADD_FLUXCAL_MEAN);
798 }
799 if(frm != NULL) {
800 cpl_frameset_insert(*pros_obj, cpl_frame_duplicate(frm));
801 }
802
803
804 }
805
806
807 if(*pros_obj != NULL) {
808 // same PRO.CATG independently from DAR correction
809 if(is_sky_tweak > 0) {
810 if(NULL == (frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_TWK_OBJ_CUBE_COADD_FLUXCAL_MEAN))) {
811 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_TWK_OBJ_CUBE_COADD_FLUXCAL_MEAN);
812 }
813
814 if(frm != NULL) {
815 cpl_frameset_insert(*pros_obj, cpl_frame_duplicate(frm));
816 }
817 }
818 }
819
820 if(*pros_obj == NULL) {
821 *pros_obj = eris_dfs_extract_frames_with_tag (set, ERIS_IFU_PRO_JITTER_TWK_CUBE);
822 }
823
824 nexposures = cpl_frameset_count_tags(*raws_obj, ERIS_IFU_RAW_OBJ);
825 } else if (strstr(recipe_name, "stdstar") != NULL) {
826 *raws_obj = eris_dfs_extract_frames_with_tag (set, ERIS_IFU_RAW_STD_FLUX);
827 /* for STD stars PRO.CATG is independent from dar correction */
828 if(is_dar_cor) {
829 *pros_obj = eris_dfs_extract_frames_with_tag (set, ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE);
830 } else {
831 *pros_obj = eris_dfs_extract_frames_with_tag (set, ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE);
832 }
833
834 if(*pros_obj != NULL) {
835 if(is_dar_cor) {
836 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_FLUXCAL_MEAN);
837 } else {
838 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_FLUXCAL_MEAN);
839 }
840 if(frm != NULL) {
841 cpl_frameset_insert(*pros_obj, cpl_frame_duplicate(frm));
842 }
843 }
844
845 if(pros_obj != NULL) {
846 if(is_dar_cor) {
847 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_FLUX_STD_CUBE_COADD_FLUXCAL_MEAN);
848 } else {
849 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_FLUX_STD_CUBE_COADD_FLUXCAL_MEAN);
850 }
851 if(frm != NULL) {
852 cpl_frameset_insert(*pros_obj, cpl_frame_duplicate(frm));
853 }
854 }
855
856 if(*pros_obj != NULL) {
857 if(is_dar_cor) {
858 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_STD_CUBE_COADD_FLUXCAL_MEAN);
859 } else {
860 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_STD_CUBE_COADD_FLUXCAL_MEAN);
861 }
862 if(frm != NULL) {
863 cpl_frameset_insert(*pros_obj, cpl_frame_duplicate(frm));
864 }
865 }
866 nexposures = cpl_frameset_count_tags(*raws_obj, ERIS_IFU_RAW_STD_FLUX);
867 }
868
869 *raws_sky =
870 eris_dfs_extract_frames_with_tag(set, ERIS_IFU_PRO_JITTER_SKY_CUBE);
871
872 properties->ncombine = nexposures;
873
874
875 //cpl_frameset_dump(set,stdout);
876 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_EXPOSURE_MAP);
877 if(frm != NULL) {
878 cpl_frameset_insert(*pros_obj, cpl_frame_duplicate(frm));
879 }
880
881
882 eris_check_error_code("eris_ifu_get_sdp_frames");
883 return cpl_error_get_code();
884
885}
886eris_ifu_sdp_properties *
887eris_ifu_sdp_properties_collect(hdrl_resample_result *aCube, cpl_frameset* set,
888 const cpl_parameterlist* parlist, const char* recipe_name)
889{
890
891 cpl_ensure(aCube != NULL, CPL_ERROR_NULL_INPUT, NULL);
892 cpl_ensure(set != NULL, CPL_ERROR_NULL_INPUT, NULL);
893 cpl_ensure(parlist != NULL, CPL_ERROR_NULL_INPUT, NULL);
894 cpl_ensure(recipe_name != NULL, CPL_ERROR_NULL_INPUT, NULL);
895
896// cpl_errorstate _status = cpl_errorstate_get();
897 cpl_frameset* raws_obj = NULL;
898 cpl_frameset* raws_sky = NULL;
899 cpl_frameset* pros_obj = NULL;
900 cpl_propertylist* header = aCube->header;
901 cpl_frame* frm;
902 int naxis3 = hdrl_imagelist_get_size(aCube->himlist);
903 eris_ifu_sdp_properties *properties = eris_ifu_sdp_properties_new();
904
905 properties->wlerror = 0.026; /* Fallback random error estimate of wavelength */
906
907 eris_ifu_get_sdp_frames(set, parlist, recipe_name, properties, &raws_obj,
908 &raws_sky, &pros_obj);
909// cpl_size nsky = cpl_frameset_get_size(raws_sky);
910 if(raws_sky != NULL) {
911 cpl_frameset_join(pros_obj, raws_sky);
912 }
913cpl_frameset_delete(raws_sky);
914 cpl_size nexposures = properties->ncombine;
915 /* Collect data from the raw data files */
916 // cpl_errorstate status = cpl_errorstate_get();
917 properties->obid = cpl_array_new(nexposures, CPL_TYPE_LONG);
918 properties->progid = cpl_array_new(nexposures, CPL_TYPE_STRING);
919
920 cpl_msg_info(cpl_func,"obid array size: %lld",
921 cpl_array_get_size(properties->obid));
922
923 cpl_msg_info(cpl_func,"progid array size: %lld",
924 cpl_array_get_size(properties->progid));
925
926 properties->prov = cpl_propertylist_new();
927
928 const char* fname = NULL;
929 cpl_propertylist* phead = NULL;
930 cpl_propertylist* pchead = NULL;
931 double exptime = 0;
932 double dit = 0;
933 int ndit = 0;
934 // int npixel = 64 * 64;
935 properties->texptime = 0;
936 double ia_fwhm_corr = 0;
937 for(cpl_size kexposure = 0; kexposure < properties->ncombine; kexposure++) {
938
939 frm = cpl_frameset_get_position(raws_obj, kexposure);
940 fname = cpl_frame_get_filename(frm);
941 phead = cpl_propertylist_load(fname, 0);
942
943 const char *progid = eris_pfits_get_progid(phead);
944
945 long obid = eris_pfits_get_obsid(phead);
946 cpl_msg_info(cpl_func,"obid: %ld",obid);
947 dit = eris_pfits_get_dit(phead);
948 ndit = eris_pfits_get_ndit(phead);
949 exptime = dit * ndit;
950
951 double mjd = eris_pfits_get_mjdobs(phead);
952
953 double endtime = mjd + exptime / day2sec;
954
955 properties->texptime += exptime;
956 properties->mjd_end = CPL_MAX(endtime, properties->mjd_end);
957
958 /* Get image quality SKY_RES (at the reference wavelength)
959 * and the associated error for this exposure */
960
961
962 cpl_msg_info(cpl_func,"compute FWHM");
963 if (strstr(recipe_name, "jitter") != NULL) {
964 ia_fwhm_corr = eris_ifu_sdp_compute_fwhm(raws_obj);
965 } else {
966 /* in STD stars miss a FITS extension required to determine FWHM */
967 ia_fwhm_corr=7.18;
968 }
969
970 properties->skyres += ia_fwhm_corr;
971 cpl_msg_info(cpl_func, "compute exposure time");
972 frm = cpl_frameset_find(set, ERIS_IFU_PRO_JITTER_EXPOSURE_MAP);
973 cpl_image* expt = cpl_image_load(cpl_frame_get_filename(frm),
974 CPL_TYPE_DOUBLE, 0, 0);
975 cpl_mask* bpm = cpl_image_get_bpm(expt);
976 cpl_mask_threshold_image(bpm, expt, 0, DBL_MAX, CPL_BINARY_0);
977 cpl_image_set_bpm(expt, bpm);
978 properties->exptime = cpl_image_get_median(expt);
979 cpl_image_delete(expt);
980
981 /* Observation ID, program ID, etc. */
982 cpl_array_set_long(properties->obid, kexposure, obid);
983 if (progid) {
984 cpl_array_set_string(properties->progid, kexposure, progid);
985 }
986
987 /* provenance */
988 unsigned int nraw = cpl_propertylist_get_size(properties->prov);
989 const char *prov = eris_pfits_get_ancestor(phead);
990
991 if (!prov) {
992 prov = eris_pfits_get_arcfile(phead);
993 if (!prov) {
994 prov = eris_ifu_pfits_get_origfile(phead);
995 }
996 }
997
998 if (prov) {
999 char *name = cpl_sprintf("PROV%-u", ++nraw);
1000 cpl_propertylist_append_string(properties->prov, name, prov);
1001 cpl_free(name);
1002 } else {
1003 unsigned int iraw = 1;
1004 prov =eris_pfits_get_raw_filename(phead, iraw);
1005 while (prov) {
1006 char *name = cpl_sprintf("PROV%-u", ++nraw);
1007 cpl_propertylist_append_string(properties->prov, name, prov);
1008 prov =eris_pfits_get_raw_filename(phead, ++iraw);
1009 cpl_free(name);
1010 }
1011 }
1012
1013 cpl_propertylist_delete(phead);
1014 }
1015 properties->skyres /= properties->ncombine;
1016
1017 //ASSON WAS HERE
1018
1019 /* ABMAGLIM */
1020 double abmaglim = 0.0;
1021
1022 cpl_msg_info(cpl_func,"compute abmaglim");
1023
1024 double pixnoise = 1;
1025 //cpl_frameset_dump(pros_obj,stdout);
1026 pixnoise = eris_ifu_sdp_compute_pixnoise(pros_obj);
1027
1028 properties->pixnoise = pixnoise;
1029 cpl_size nobj = cpl_frameset_get_size(raws_obj);
1030 cpl_frameset_delete(raws_obj);
1031 cpl_msg_info(cpl_func,"obid array size: %lld",
1032 cpl_array_get_size(properties->obid));
1033
1034 cpl_frame* wave_frm = cpl_frameset_find(set, ERIS_IFU_CALIB_WAVE_MAP);
1035 fname = cpl_frame_get_filename(wave_frm);
1036 phead = cpl_propertylist_load(fname, 0);
1037 //double resol_med = cpl_propertylist_get_double(phead, "ESO QC RESOL MED");
1038 ifsBand bandId = eris_ifu_get_band(phead);
1039 double resol_med = eris_ifu_get_band_resolution(bandId);
1040 cpl_propertylist_delete(phead);
1041
1042 hdrl_image* hima_obj_mean = eris_ifu_sdp_get_obj_mean(pros_obj);
1043
1044 cpl_image* ima_obj_mean = hdrl_image_get_image(hima_obj_mean);
1045
1046 double zp = eris_ifu_sdp_compute_zp(bandId);
1047 //double fwhm = 10;
1048 const cpl_size kernel_size_x = 3;
1049 const cpl_size kernel_size_y = 3;
1050
1051 /*Mode parameters*/
1052 double histo_min = 0.;
1053 double histo_max = 0.;
1054 double bin_size = 0.;
1055 cpl_size error_niter = 0;
1056 hdrl_mode_type mode_method = HDRL_MODE_MEDIAN;
1057 /*
1058 hdrl_mode_parameter_parse_parlist(parlist, "eris_ifu_jitter", &histo_min, &histo_max,
1059 &bin_size, &mode_method, &error_niter);
1060 */
1061
1062 hdrl_parameter * mode_parameter = hdrl_collapse_mode_parameter_create(histo_min,
1063 histo_max, bin_size, mode_method, error_niter);
1064
1065 hdrl_maglim_compute(ima_obj_mean, zp, ia_fwhm_corr, kernel_size_x, kernel_size_y,
1066 HDRL_IMAGE_EXTEND_NEAREST, mode_parameter,&abmaglim);
1067 hdrl_parameter_delete(mode_parameter);
1068 hdrl_image_delete(hima_obj_mean);
1069 cpl_msg_info(cpl_func,"HDRL computed abmaglim: %g", abmaglim);
1070 abmaglim = eris_ifu_sdp_compute_abmaglimit(pixnoise, ia_fwhm_corr, bandId);
1071 properties->abmaglimit = abmaglim;
1072 cpl_msg_info(cpl_func,"LODO computed abmaglim: %g", abmaglim);
1073
1074 /* The following IDP properties are simply hard coded here since *
1075 * not supposed to change. */
1076 properties->prodcatg = cpl_strdup(KEY_PRODCATG_VALUE_IFS_CUBE);
1077 properties->obstech = cpl_strdup("IFU");
1078
1079 char *key = cpl_sprintf("ESO PRO REC1 PIPE ID");
1080 if(cpl_propertylist_has(header, key)) {
1081 properties->procsoft = cpl_propertylist_get_string(header, key);
1082 }
1083 cpl_free(key);
1084 properties->referenc = NULL;
1085 if(cpl_propertylist_has(header, KEY_PROG_ID) ){
1086 cpl_propertylist_get_string(header, KEY_PROG_ID);
1087 }
1088 properties->fluxcal = CPL_TRUE;
1089
1090 /* TODO: ASSON */
1091 cpl_size npros = cpl_frameset_get_size(pros_obj);
1092 //cpl_frameset_dump(pros_obj, stdout);
1093 properties->asson = cpl_array_new(npros, CPL_TYPE_STRING);
1094 cpl_size kstart = 0;
1095 if (nobj == 1) {
1096 /* If nobj == 1 3D cube object (ADU) (1st of list) is not associated */
1097 properties->nobj = 1;
1098 kstart = 1;
1099 }
1100 for(cpl_size kexposure = kstart; kexposure < npros; kexposure++) {
1101 frm = cpl_frameset_get_position(pros_obj, kexposure);
1102 fname = cpl_frame_get_filename(frm);
1103 pchead = cpl_propertylist_load(fname, 0);
1104 cpl_array_set_string(properties->asson, kexposure,
1105 eris_pfits_get_pipefile(pchead));
1106 cpl_propertylist_delete(pchead);
1107 }
1108
1109
1110
1111
1112
1113 properties->specres = resol_med;
1114 properties->specsys = cpl_sprintf("TOPOCENT");
1115 //properties->obid = eris_pfits_get_obsid(header);
1116 // double wstart = 0;
1117 // double wend = 100;
1118 if(cpl_propertylist_has(header,"CRVAL3")) {
1119 properties->wlenrange[0] = cpl_propertylist_get_double(header,"CRVAL3");
1120 }
1121
1122 double cd3_3 = 0;
1123 if(cpl_propertylist_has(header,"CD3_3")) {
1124 cd3_3 = cpl_propertylist_get_double(header,"CD3_3");
1125 }
1126 properties->wlenrange[1] = properties->wlenrange[0] + cd3_3 * (double)(naxis3 -1.);
1127
1128 /* TODO
1129 mandatory keyword PIXNOISE is undefined.
1130 mandatory keyword SKY_RES is undefined.
1131 mandatory keyword ABMAGLIM is undefined.
1132 mandatory keyword ext:HDUCLASS is undefined in HDU0.
1133 mandatory keyword ext:HDUCLASS is undefined in HDU1.
1134 mandatory keyword ext:HDUCLASS is undefined in HDU2.
1135 mandatory keyword ext:HDUDOC is undefined in HDU0.
1136 mandatory keyword ext:HDUDOC is undefined in HDU1.
1137 mandatory keyword ext:HDUDOC is undefined in HDU2.
1138 mandatory keyword ext:HDUVERS is undefined in HDU0.
1139 mandatory keyword ext:HDUVERS is undefined in HDU1.
1140 mandatory keyword ext:HDUVERS is undefined in HDU2.
1141 mandatory keyword ext:HDUCLAS1 is undefined in HDU0.
1142 mandatory keyword ext:HDUCLAS1 is undefined in HDU1.
1143 mandatory keyword ext:HDUCLAS1 is undefined in HDU2.
1144
11453. The keywords CDELT are not supported by the SDP standard. They are in every extension.
1146
11474. ORIGFILE must be recorded in the primary header, and not duplicated in any extension.
1148 */
1149 if (pros_obj) cpl_frameset_delete(pros_obj);
1150
1151 //if (raws_obj) cpl_frameset_delete(raws_obj);
1152 eris_check_error_code("eris_ifu_sdp_properties_collect");
1153 return properties;
1154}
1155/*----------------------------------------------------------------------------*/
1156/* Helper functions for quicksort */
1157/*----------------------------------------------------------------------------*/
1159static int cmp_double_asc(const void *p1, const void *p2) {
1160 double d = (*(const double *)p1 - *(const double *)p2);
1161 return (d < 0)?-1:(d>0)?1:0;
1162}
1164static int cmp_double_desc(const void *p1, const void *p2) {
1165 double d = (*(const double *)p1 - *(const double *)p2);
1166 return (d < 0)?1:(d>0)?-1:0;
1167}
1169static int cmp_float_asc(const void *p1, const void *p2) {
1170 float d = (*(const float *)p1 - *(const float *)p2);
1171 return (d < 0)?-1:(d>0)?1:0;
1172}
1173
1175static int cmp_float_desc(const void *p1, const void *p2) {
1176 float d = (*(const float *)p1 - *(const float *)p2);
1177 return (d < 0)?1:(d>0)?-1:0;
1178}
1179
1180
1182static int cmp_int_asc(const void *p1, const void *p2) {
1183 return (*(const int *)p1 - *(const int *)p2);
1184}
1186static int cmp_int_desc(const void *p1, const void *p2) {
1187 return (*(const int *)p2 - *(const int *)p1);
1188}
1190static int cmp_long_asc(const void *p1, const void *p2) {
1191 return (*(const long *)p1 - *(const long *)p2);
1192}
1194static int cmp_long_desc(const void *p1, const void *p2) {
1195 return (*(const long *)p2 - *(const long *)p1);
1196}
1197
1199static int cmp_string_asc(const void *p1, const void *p2) {
1200 return strcmp(*(const char **)p1, *(const char **)p2);
1201}
1203static int cmp_string_desc(const void *p1, const void *p2) {
1204 return strcmp(*(const char **)p2, *(const char **)p1);
1205}
1206
1207/*----------------------------------------------------------------------------*/
1216/*----------------------------------------------------------------------------*/
1217cpl_error_code
1218eris_ifu_cplarray_sort(cpl_array *aArray, cpl_boolean aOrder)
1219{
1220 cpl_ensure_code(aArray != NULL, CPL_ERROR_NULL_INPUT);
1221 cpl_ensure_code(!cpl_array_has_invalid(aArray), CPL_ERROR_NULL_INPUT);
1222
1223 cpl_size n = cpl_array_get_size(aArray);
1224 if (cpl_array_get_type(aArray) == CPL_TYPE_DOUBLE) {
1225 double *d = cpl_array_get_data_double(aArray);
1226 qsort(d, n, sizeof(double), (aOrder)?cmp_double_asc:cmp_double_desc);
1227 return CPL_ERROR_NONE;
1228 } else if (cpl_array_get_type(aArray) == CPL_TYPE_FLOAT) {
1229 float *d = cpl_array_get_data_float(aArray);
1230 qsort(d, n, sizeof(float), (aOrder)?cmp_float_asc:cmp_float_desc);
1231 return CPL_ERROR_NONE;
1232 } else if (cpl_array_get_type(aArray) == CPL_TYPE_INT) {
1233 int *d = cpl_array_get_data_int(aArray);
1234 qsort(d, n, sizeof(int), (aOrder)?cmp_int_asc:cmp_int_desc);
1235 return CPL_ERROR_NONE;
1236 } else if (cpl_array_get_type(aArray) == CPL_TYPE_LONG) {
1237 long *d = cpl_array_get_data_long(aArray);
1238 qsort(d, n, sizeof(long), (aOrder)?cmp_long_asc:cmp_long_desc);
1239 return CPL_ERROR_NONE;
1240 } else if (cpl_array_get_type(aArray) == CPL_TYPE_STRING) {
1241 char **d = cpl_array_get_data_string(aArray);
1242 qsort(d, n, sizeof(char *), (aOrder)?cmp_string_asc:cmp_string_desc);
1243 return CPL_ERROR_NONE;
1244 } else {
1245 return CPL_ERROR_ILLEGAL_INPUT;
1246 }
1247}
1248
1249cpl_error_code
1250eris_ifu_sdp_properties_update(cpl_propertylist *aHeader,
1251 const eris_ifu_sdp_properties *aProperties)
1252{
1253 cpl_ensure(aHeader && aProperties, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
1254
1255 /* TODO */
1256 cpl_ensure(cpl_array_get_size(aProperties->obid) == aProperties->ncombine,
1257 CPL_ERROR_ILLEGAL_INPUT, CPL_ERROR_ILLEGAL_INPUT);
1258
1259 cpl_ensure(cpl_array_get_size(aProperties->progid) == aProperties->ncombine,
1260 CPL_ERROR_ILLEGAL_INPUT, CPL_ERROR_ILLEGAL_INPUT);
1261 cpl_ensure(cpl_propertylist_get_size(aProperties->prov) >= aProperties->ncombine,
1262 CPL_ERROR_ILLEGAL_INPUT, CPL_ERROR_ILLEGAL_INPUT);
1263
1264
1265 cpl_propertylist_erase_regexp(aHeader, CLEAN_KEYS_REGEXP, 0);
1266
1267 cpl_propertylist_update_double(aHeader, KEY_RA, aProperties->fovcenter[0]);
1268 cpl_propertylist_set_comment(aHeader, KEY_RA, KEY_RA_COMMENT);
1269 cpl_propertylist_update_double(aHeader, KEY_DEC, aProperties->fovcenter[1]);
1270 cpl_propertylist_set_comment(aHeader, KEY_DEC, KEY_DEC_COMMENT);
1271 cpl_propertylist_update_double(aHeader, KEY_EXPTIME, aProperties->exptime);
1272 cpl_propertylist_set_comment(aHeader, KEY_EXPTIME, KEY_EXPTIME_COMMENT);
1273
1274 cpl_propertylist_insert_after_double(aHeader, KEY_EXPTIME,
1275 KEY_TEXPTIME, aProperties->texptime);
1276 cpl_propertylist_set_comment(aHeader, KEY_TEXPTIME, KEY_TEXPTIME_COMMENT);
1277
1278 cpl_propertylist_insert_after_int(aHeader, KEY_TEXPTIME,
1279 KEY_NCOMBINE, aProperties->ncombine);
1280 cpl_propertylist_set_comment(aHeader, KEY_NCOMBINE, KEY_NCOMBINE_COMMENT);
1281
1282 cpl_propertylist_set_comment(aHeader, KEY_MJDOBS, KEY_MJDOBS_COMMENT);
1283 cpl_propertylist_insert_after_double(aHeader, KEY_MJDOBS,
1284 KEY_MJDEND, aProperties->mjd_end);
1285 cpl_propertylist_set_comment(aHeader, KEY_MJDEND, KEY_MJDEND_COMMENT);
1286
1287 /* TODO */
1288 cpl_array *obids = cpl_array_duplicate(aProperties->obid);
1289
1290 eris_ifu_cplarray_sort(obids, CPL_TRUE);
1291
1292 // Add observation block IDs, skipping duplicates
1293 long obid = cpl_array_get_long(obids, 0, NULL);
1294 cpl_msg_warning(cpl_func,"obid: %ld",obid);
1295 cpl_propertylist_update_long(aHeader, KEY_OBID1, obid);
1296 cpl_propertylist_set_comment(aHeader, KEY_OBID1, KEY_OBID_COMMENT);
1297
1298 if (aProperties->ncombine > 1) {
1299 unsigned int ik = 1;
1300 cpl_size idx;
1301 for (idx = 1; idx < aProperties->ncombine; ++idx) {
1302 long _obid = cpl_array_get_long(obids, idx, NULL);
1303 if (_obid != obid) {
1304 char *key = cpl_sprintf(KEY_OBID "%-u", ++ik);
1305 cpl_propertylist_update_long(aHeader, key, _obid);
1306 cpl_propertylist_set_comment(aHeader, key, KEY_OBID_COMMENT);
1307 cpl_free(key);
1308 obid = _obid;
1309 }
1310 }
1311 }
1312 cpl_array_delete(obids);
1313
1314 /* Add the ESO program ID(s). If the product is made from a single program *
1315 * PROG_ID is the ID string, otherwise it set to the special value MULTI, *
1316 * followed by a list of all IDs, skipping duplicate ID values */
1317
1318 /* TODO */
1319 if(aProperties->progid != NULL) {
1320
1321 cpl_array *progids = cpl_array_duplicate(aProperties->progid);
1322
1323 /* TODO */
1324 eris_ifu_cplarray_sort(progids, CPL_TRUE);
1325
1326 const char *progid = cpl_array_get_string(progids, 0);
1327
1328 if (aProperties->ncombine > 1) {
1329 unsigned int nprogid = 1;
1330 cpl_size idx;
1331 for (idx = 1; idx < aProperties->ncombine; ++idx) {
1332 const char *_progid = cpl_array_get_string(progids, idx);
1333 if (strcmp(_progid, progid) != 0) {
1334 progid = _progid;
1335 ++nprogid;
1336 }
1337 }
1338
1339 progid = cpl_array_get_string(progids, 0);
1340 if (nprogid == 1) {
1341 cpl_propertylist_update_string(aHeader, KEY_PROG_ID, progid);
1342 } else {
1343 cpl_propertylist_update_string(aHeader, KEY_PROG_ID,
1344 KEY_PROG_ID_VALUE_MULTIPLE);
1345 cpl_propertylist_update_string(aHeader, KEY_PROGID "1", progid);
1346 cpl_propertylist_set_comment(aHeader, KEY_PROGID "1", KEY_PROGID_COMMENT);
1347
1348 unsigned int ik = 1;
1349 for (idx = 1; idx < aProperties->ncombine; ++idx) {
1350 const char *_progid = cpl_array_get_string(progids, idx);
1351 if (strcmp(_progid, progid) != 0) {
1352 char *key = cpl_sprintf(KEY_PROGID "%-u", ++ik);
1353 cpl_propertylist_update_string(aHeader, key, _progid);
1354 cpl_propertylist_set_comment(aHeader, key, KEY_PROGID_COMMENT);
1355 cpl_free(key);
1356 progid = _progid;
1357 }
1358 }
1359 }
1360 cpl_propertylist_set_comment(aHeader, KEY_PROG_ID, KEY_PROG_ID_COMMENT);
1361
1362 } else {
1363 cpl_propertylist_update_string(aHeader, KEY_PROG_ID, progid);
1364 cpl_propertylist_set_comment(aHeader, KEY_PROG_ID, KEY_PROG_ID_COMMENT);
1365 }
1366 cpl_array_delete(progids);
1367 }
1368
1369
1370 /* Add raw data information */
1371 cpl_propertylist_append(aHeader, aProperties->prov);
1372
1373 /* Add ancillary products file information */
1374 /* TODO */
1375 cpl_size idx_start = 0;
1376 if(aProperties->nobj == 1) {
1377 idx_start = 1;
1378 }
1379
1380 for (cpl_size idx = idx_start; idx < cpl_array_get_size(aProperties->asson); ++idx) {
1381 char *name = cpl_sprintf(KEY_ASSON "%-" CPL_SIZE_FORMAT, idx - idx_start + 1 );
1382 cpl_propertylist_update_string(aHeader, name,
1383 cpl_array_get_string(aProperties->asson, idx));
1384 cpl_free(name);
1385 }
1386
1387
1388 cpl_propertylist_update_string(aHeader, KEY_PRODCATG, aProperties->prodcatg);
1389 cpl_propertylist_set_comment(aHeader, KEY_PRODCATG, KEY_PRODCATG_COMMENT);
1390
1391 cpl_propertylist_update_string(aHeader, KEY_PROCSOFT, aProperties->procsoft);
1392 cpl_propertylist_set_comment(aHeader, KEY_PROCSOFT, KEY_PROCSOFT_COMMENT);
1393
1394 cpl_propertylist_update_string(aHeader, KEY_OBSTECH, aProperties->obstech);
1395 cpl_propertylist_set_comment(aHeader, KEY_OBSTECH, KEY_OBSTECH_COMMENT);
1396
1397 const char *fluxcal = KEY_FLUXCAL_VALUE_TRUE;
1398 if (aProperties->fluxcal == CPL_FALSE) {
1399 fluxcal = KEY_FLUXCAL_VALUE_FALSE;
1400 }
1401
1402 cpl_propertylist_update_string(aHeader, KEY_FLUXCAL, fluxcal);
1403 cpl_propertylist_set_comment(aHeader, KEY_FLUXCAL, KEY_FLUXCAL_COMMENT);
1404 double um2nm = 1000.;
1405 cpl_propertylist_insert_after_double(aHeader, KEY_FLUXCAL, KEY_WAVELMIN,
1406 aProperties->wlenrange[0] * um2nm);
1407 cpl_propertylist_set_comment(aHeader, KEY_WAVELMIN, KEY_WAVELMIN_COMMENT);
1408 cpl_propertylist_insert_after_double(aHeader, KEY_WAVELMIN, KEY_WAVELMAX,
1409 aProperties->wlenrange[1] * um2nm);
1410 cpl_propertylist_set_comment(aHeader, KEY_WAVELMAX, KEY_WAVELMAX_COMMENT);
1411 cpl_propertylist_insert_after_double(aHeader, KEY_WAVELMAX, KEY_SPEC_RES,
1412 aProperties->specres);
1413 cpl_propertylist_set_comment(aHeader, KEY_SPEC_RES, KEY_SPEC_RES_COMMENT);
1414 cpl_propertylist_insert_after_string(aHeader, KEY_SPEC_RES, KEY_SPECSYS,
1415 aProperties->specsys);
1416 cpl_propertylist_set_comment(aHeader, KEY_SPECSYS, KEY_SPECSYS_COMMENT);
1417
1418 /* If any of the properties 'skyres' and 'skyrerr' is negative, the value *
1419 * is a default rather than a measured quantity. Indicate this in the *
1420 * comment. The actual value to be written to the header is the absolute *
1421 * value of the quantity. */
1422
1423 cpl_propertylist_insert_after_double(aHeader, KEY_SPEC_RES, KEY_SKY_RES,
1424 fabs(aProperties->skyres));
1425
1426 const char *method_qualifier = (aProperties->skyres < 0.) ?
1427 "default" : "measured";
1428 char *comment = cpl_sprintf(KEY_SKY_RES_COMMENT " (%s)", method_qualifier);
1429 cpl_propertylist_set_comment(aHeader, KEY_SKY_RES, comment);
1430 cpl_free(comment);
1431 /* TODO
1432 cpl_propertylist_insert_after_double(aHeader, KEY_SKY_RES, KEY_SKY_RERR,
1433 fabs(aProperties->skyrerr));
1434
1435 method_qualifier = (aProperties->skyrerr < 0.) ? "default" : "measured";
1436 comment = cpl_sprintf(KEY_SKY_RERR_COMMENT " (%s)", method_qualifier);
1437 cpl_propertylist_set_comment(aHeader, KEY_SKY_RERR, comment);
1438 cpl_free(comment);
1439 */
1440 cpl_propertylist_insert_after_double(aHeader, KEY_SKY_RES, KEY_PIXNOISE,
1441 aProperties->pixnoise);
1442 cpl_propertylist_set_comment(aHeader, KEY_PIXNOISE, KEY_PIXNOISE_COMMENT);
1443
1444 /* TODO */
1445 cpl_propertylist_insert_after_double(aHeader, KEY_WAVELMAX, KEY_ABMAGLIM,
1446 aProperties->abmaglimit);
1447 cpl_propertylist_set_comment(aHeader, KEY_ABMAGLIM, KEY_ABMAGLIM_COMMENT);
1448
1449 const char *reference = "";
1450 if (aProperties->referenc) {
1451 reference = aProperties->referenc;
1452 }
1453 cpl_propertylist_update_string(aHeader, KEY_REFERENC, reference);
1454 cpl_propertylist_set_comment(aHeader, KEY_REFERENC, KEY_REFERENC_COMMENT);
1455
1456 /* TODO: NEEDED??
1457 cpl_propertylist_insert_after_double(aHeader, KEY_REFERENC, KEY_SPEC_ERR,
1458 aProperties->wlerror);
1459 cpl_propertylist_set_comment(aHeader, KEY_SPEC_ERR, KEY_SPEC_ERR_COMMENT);
1460 */
1461
1462 /* Update data unit values to IDP standards */
1463 /* TODO
1464 if (!strncmp(eris_ifu_pfits_get_cunit(aHeader, 3), "Angstrom", 9)) {
1465 cpl_propertylist_update_string(aHeader, "CUNIT3",
1466 kErisIdpWavelengthUnit);
1467 }
1468 */
1469 /*
1470 if (!strncmp(eris_ifu_pfits_get_bunit(aHeader),
1471 kErisFluxUnitString, strlen(kErisFluxUnitString) + 1)) {
1472 cpl_propertylist_update_string(aHeader, "BUNIT", kErisIdpFluxDataUnit);
1473 }
1474 */
1475
1476 /* Fallback required for IDPs */
1477 /* TODO: not required but would be nice to have them. In such a case we need
1478 * to add correct values
1479
1480 if (!cpl_propertylist_has(aHeader, "CSYER1")) {
1481 cpl_propertylist_update_double(aHeader, "CSYER1", -1.);
1482 cpl_propertylist_set_comment(aHeader, "CSYER1",
1483 "[deg] Systematic error in coordinate");
1484 }
1485 if (!cpl_propertylist_has(aHeader, "CSYER2")) {
1486 cpl_propertylist_update_double(aHeader, "CSYER2", -1.);
1487 cpl_propertylist_set_comment(aHeader, "CSYER2",
1488 "[deg] Systematic error in coordinate");
1489 }
1490 */
1491
1492 eris_check_error_code("eris_ifu_sdp_properties_update");
1493 return CPL_ERROR_NONE;
1494}
1495
1496
ifsPreopticsScale eris_ifu_get_preopticsScale(cpl_propertylist *header)
Return the the pre-optics scaling.
ifsBand eris_ifu_get_band(const cpl_propertylist *header)
Determine preoptic band.
const char * eris_ifu_pfits_get_origfile(const cpl_propertylist *aHeaders)
find out the origfile
Definition: eris_ifu_sdp.c:686
cpl_error_code eris_ifu_cplarray_sort(cpl_array *aArray, cpl_boolean aOrder)
Sort float, int or double array by quicksort.
cpl_error_code eris_ifu_mask_nans_in_hdrlimage(hdrl_image **hima)
Flag NANs in image.
double eris_ifu_get_band_resolution(ifsBand band)
eris_ifu_get_band_resolution
cpl_mask * eris_ifu_hima_get_obj_mask(hdrl_image *hima, const cpl_size niter, const double kappa)
find mask flagging pixels above a threshold set by ks-clip algorithm
double eris_pfits_get_mjdobs(const cpl_propertylist *aHeaders)
find out the Julian Date of the observation
Definition: eris_pfits.c:811
const char * eris_pfits_get_raw_filename(const cpl_propertylist *aHeaders, unsigned int idx)
find out the i-th raw file name.
Definition: eris_pfits.c:609
const char * eris_pfits_get_arcfile(const cpl_propertylist *plist)
find out the arcfile
Definition: eris_pfits.c:82
double eris_pfits_get_fwhm_start(const cpl_propertylist *aHeaders)
find out the ambient seeing at start of exposure (in arcsec)
Definition: eris_pfits.c:649
double eris_pfits_get_fwhm_end(const cpl_propertylist *aHeaders)
find out the ambient seeing at end of exposure (in arcsec)
Definition: eris_pfits.c:669
const char * eris_pfits_get_pipefile(const cpl_propertylist *aHeaders)
find out the PIPEFILE id
Definition: eris_pfits.c:867
int eris_pfits_get_ndit(const cpl_propertylist *plist)
find out the DIT value
Definition: eris_pfits.c:117
const char * eris_pfits_get_ancestor(const cpl_propertylist *aHeaders)
find out the ancestor of a file.
Definition: eris_pfits.c:65
const char * eris_pfits_get_progid(const cpl_propertylist *aHeaders)
find out the ESO program identification
Definition: eris_pfits.c:829
long eris_pfits_get_obsid(const cpl_propertylist *aHeaders)
find out the observation block id
Definition: eris_pfits.c:848
double eris_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
Definition: eris_pfits.c:98
cpl_error_code eris_check_error_code(const char *func_id)
handle CPL errors
Definition: eris_utils.c:56
cpl_frameset * eris_dfs_extract_frames_with_tag(cpl_frameset *input, const char *rtag)
Extract frames of user given tag.
Definition: eris_utils.c:227
hdrl_parameter * hdrl_collapse_mode_parameter_create(double histo_min, double histo_max, double bin_size, hdrl_mode_type mode_method, cpl_size error_niter)
create a parameter object for the mode
cpl_error_code hdrl_image_reject_from_mask(hdrl_image *self, const cpl_mask *map)
set bpm of hdrl_image
Definition: hdrl_image.c:407
double hdrl_image_get_stdev(const hdrl_image *self)
computes the standard deviation of the data of an image
hdrl_image * hdrl_image_create(const cpl_image *image, const cpl_image *error)
create a new hdrl_image from to existing images by copying them
Definition: hdrl_image.c:295
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
Definition: hdrl_image.c:105
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
Definition: hdrl_image.c:379
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
cpl_error_code hdrl_maglim_compute(const cpl_image *image, const double zeropoint, const double fwhm, const cpl_size kernel_size_x, const cpl_size kernel_size_y, const hdrl_image_extend_method image_extend_method, const hdrl_parameter *mode_parameter, double *limiting_magnitude)
Computes the limiting magnitude of an image.
Definition: hdrl_maglim.c:114
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter