28 #include <cxmessages.h>
29 #include <cxstrutils.h>
32 #include <cpl_parameterlist.h>
34 #include "gifiberutils.h"
36 #include "gimessages.h"
54 _giraffe_flat_apply(GiImage *spectra,
const GiTable *fibers,
58 const cxchar *fctid =
"giraffe_flat_apply";
60 const cxchar *idx = NULL;
75 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
85 nfibers = cpl_table_get_nrow(_fibers);
87 if (nfibers > cpl_image_get_size_x(_spectra)) {
88 cpl_error_set(fctid, CPL_ERROR_INCOMPATIBLE_INPUT);
92 nbins = cpl_image_get_size_y(_spectra);
94 if (nbins != cpl_image_get_size_y(_flat)) {
95 cpl_error_set(fctid, CPL_ERROR_INCOMPATIBLE_INPUT);
99 for (nf = 0; nf < nfibers; ++nf) {
102 register cxint ns = cpl_table_get_int(_fibers, idx, nf, NULL) - 1;
104 const cxdouble *f = cpl_image_get_data_const(_flat);
106 cxdouble *s = cpl_image_get_data(_spectra);
109 for (y = 0; y < nbins ; ++y) {
111 cxint ls = y * cpl_image_get_size_x(_spectra) + nf;
112 cxint lf = y * cpl_image_get_size_x(_flat) + ns;
114 if (fabs(f[lf]) < DBL_EPSILON) {
136 _giraffe_flat_apply_errors(GiImage *spectra, GiImage* errors,
137 const GiTable *fibers,
const GiImage* fspectra,
138 const GiImage *ferrors)
141 const cxchar *fctid =
"giraffe_flat_apply";
143 const cxchar *idx = NULL;
161 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
171 nfibers = cpl_table_get_nrow(_fibers);
173 if (nfibers > cpl_image_get_size_x(_spectra)) {
174 cpl_error_set(fctid, CPL_ERROR_INCOMPATIBLE_INPUT);
178 nbins = cpl_image_get_size_y(_spectra);
180 if (nbins != cpl_image_get_size_y(_fspectra)) {
181 cpl_error_set(fctid, CPL_ERROR_INCOMPATIBLE_INPUT);
185 for (nf = 0; nf < nfibers; ++nf) {
188 register cxint ns = cpl_table_get_int(_fibers, idx, nf, NULL) - 1;
190 const cxdouble *fs = cpl_image_get_data_const(_fspectra);
191 const cxdouble *fe = cpl_image_get_data_const(_ferrors);
193 cxdouble *s = cpl_image_get_data(_spectra);
194 cxdouble *e = cpl_image_get_data(_errors);
197 for (y = 0; y < nbins ; ++y) {
199 cxint ls = y * cpl_image_get_size_x(_spectra) + nf;
200 cxint lf = y * cpl_image_get_size_x(_fspectra) + ns;
203 if (fabs(fs[lf]) < DBL_EPSILON) {
209 e[ls] = sqrt(e[ls] * e[ls] +
210 (s[ls] * s[ls]) * (fe[lf] * fe[lf])) / fs[lf];
239 const GiImage *flat,
const GiImage* errors,
240 GiFlatConfig *config)
246 if (extraction == NULL || extraction->spectra == NULL) {
250 if (fibers == NULL) {
258 if (config == NULL) {
263 if (errors == NULL) {
265 status = _giraffe_flat_apply(extraction->spectra, fibers, flat);
267 if ((status == 0) && (extraction->error != NULL)) {
268 status = _giraffe_flat_apply(extraction->error, fibers, flat);
274 status = _giraffe_flat_apply_errors(extraction->spectra,
276 fibers, flat, errors);
307 GiFlatConfig *config = NULL;
314 config = cx_calloc(1,
sizeof *config);
321 config->apply = FALSE;
322 config->transmission = TRUE;
325 p = cpl_parameterlist_find(list,
"giraffe.flat.apply");
326 config->apply = cpl_parameter_get_bool(p);
328 p = cpl_parameterlist_find(list,
"giraffe.flat.transmission");
329 config->transmission = cpl_parameter_get_bool(p);
331 config->load = config->apply || config->transmission;
386 p = cpl_parameter_new_value(
"giraffe.flat.apply",
388 "Controls the flat field correction.",
391 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"flat-apply");
392 cpl_parameterlist_append(list, p);
395 p = cpl_parameter_new_value(
"giraffe.flat.transmission",
397 "Controls the fiber to fiber transmission "
401 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"transmission-apply");
402 cpl_parameterlist_append(list, p);
const cxchar * giraffe_fiberlist_query_index(const cpl_table *fibers)
Query a fiber list for the name of the fiber reference index column.
GiFlatConfig * giraffe_flat_config_create(cpl_parameterlist *list)
Creates a setup structure for the flat field correction.
void giraffe_flat_config_destroy(GiFlatConfig *config)
Destroys a flat field setup structure.
void giraffe_flat_config_add(cpl_parameterlist *list)
Adds parameters for the flat field correction.
cxint giraffe_flat_apply(GiExtraction *extraction, const GiTable *fibers, const GiImage *flat, const GiImage *errors, GiFlatConfig *config)
Apply the flat field correction to the given extracted spectra.
cpl_image * giraffe_image_get(const GiImage *self)
Gets the image data.
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.