32 #include "muse_xcombine.h"
34 #include "muse_pfits.h"
36 #include "muse_utils.h"
84 cpl_ensure_code(aPixtables, CPL_ERROR_NULL_INPUT);
86 while (aPixtables[npt++]) ;
87 cpl_ensure_code(--npt > 1, CPL_ERROR_ILLEGAL_INPUT);
89 cpl_msg_warning(__func__,
"Unknown exposure weighting scheme (%d)",
91 return cpl_error_set(__func__, CPL_ERROR_UNSUPPORTED_MODE);
94 cpl_msg_info(__func__,
"%d tables to be weighted using %s", npt,
98 if (exptime0 == 0.0) {
99 return cpl_error_set(__func__, CPL_ERROR_INCOMPATIBLE_INPUT);
108 for (i = 0; i < npt; i++) {
110 weight = exptime / exptime0;
111 if (!cpl_table_has_column(aPixtables[i]->table, MUSE_PIXTABLE_WEIGHT)) {
112 cpl_table_new_column(aPixtables[i]->table, MUSE_PIXTABLE_WEIGHT,
117 cpl_errorstate prestate = cpl_errorstate_get();
120 if (fwhm == 0. || !cpl_errorstate_is_equal(prestate)) {
121 cpl_msg_warning(__func__,
"No seeing info in table %d. Weighting it "
122 "equal to first table!", i+1);
125 weight *= fwhm0 / fwhm;
127 cpl_msg_debug(__func__,
"Table %d, weight = %f", i+1, weight);
128 cpl_table_fill_column_window_float(aPixtables[i]->table,
129 MUSE_PIXTABLE_WEIGHT,
136 MUSE_HDR_PT_WEIGHTED_COMMENT);
139 return CPL_ERROR_NONE;
186 cpl_ensure(aPixtables, CPL_ERROR_NULL_INPUT, NULL);
187 unsigned int npt = 0;
188 while (aPixtables[npt++]) ;
189 cpl_ensure(--npt > 1, CPL_ERROR_ILLEGAL_INPUT, NULL);
191 CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
192 cpl_msg_info(__func__,
"%u tables to be combined", npt);
195 cpl_array *dra = NULL,
197 char *raenv = getenv(
"MUSE_XCOMBINE_RA_OFFSETS"),
198 *decenv = getenv(
"MUSE_XCOMBINE_DEC_OFFSETS");
201 unsigned int nra = cpl_array_get_size(dra);
203 cpl_msg_warning(__func__,
"Found %u RA offsets for %u exposures, not "
204 "using them!", nra, npt);
205 cpl_array_delete(dra);
208 cpl_msg_info(__func__,
"Using %u RA offsets", nra);
213 unsigned int ndec = cpl_array_get_size(ddec);
215 cpl_msg_warning(__func__,
"Found %u DEC offsets for %u exposures, not "
216 "using them!", ndec, npt);
217 cpl_array_delete(ddec);
220 cpl_msg_info(__func__,
"Using %u DEC offsets", ndec);
224 double timeinit = cpl_test_get_walltime(),
225 cpuinit = cpl_test_get_cputime();
228 aPixtables[0] = NULL;
232 char keyword[KEYWORD_LENGTH], comment[KEYWORD_LENGTH];
234 cpl_propertylist_append_long_long(pt->
header, keyword, 0);
235 snprintf(comment, KEYWORD_LENGTH, MUSE_HDR_PT_EXP_FST_COMMENT, 1);
236 cpl_propertylist_set_comment(pt->
header, keyword, comment);
238 cpl_propertylist_append_long_long(pt->
header, keyword,
240 snprintf(comment, KEYWORD_LENGTH, MUSE_HDR_PT_EXP_LST_COMMENT, 1);
241 cpl_propertylist_set_comment(pt->
header, keyword, comment);
246 ra0 -= atof(cpl_array_get_string(dra, 0));
249 dec0 -= atof(cpl_array_get_string(ddec, 0));
253 unsigned int i, nskipped = 0;
254 for (i = 1; i < npt; i++) {
256 cpl_msg_warning(__func__,
"Exposure %d was not projected to native "
257 "spherical coordinates, skipping this one!", i + 1);
266 ra -= atof(cpl_array_get_string(dra, i));
267 cpl_msg_debug(__func__,
"positioning not to RA %f but to %f",
268 ra + atof(cpl_array_get_string(dra, i)), ra);
271 dec -= atof(cpl_array_get_string(ddec, i));
272 cpl_msg_debug(__func__,
"positioning not to DEC %f but to %f",
273 dec + atof(cpl_array_get_string(ddec, i)), dec);
278 double raoffset = ra - ra0,
279 decoffset = dec - dec0;
283 float *xpos = cpl_table_get_data_float(aPixtables[i]->table, MUSE_PIXTABLE_XPOS),
284 *ypos = cpl_table_get_data_float(aPixtables[i]->table, MUSE_PIXTABLE_YPOS);
286 #pragma omp parallel for default(none) \
287 shared(decoffset, nrowi, raoffset, xpos, ypos)
288 for (irow = 0; irow < nrowi; irow++) {
289 xpos[irow] += raoffset;
290 ypos[irow] += decoffset;
294 cpl_table_add_scalar(aPixtables[i]->table, MUSE_PIXTABLE_XPOS, raoffset);
295 cpl_table_add_scalar(aPixtables[i]->table, MUSE_PIXTABLE_YPOS, decoffset);
299 double avdec = (dec + dec0) / 2.,
300 raoff = (ra - ra0) * cos(avdec * CPL_MATH_RAD_DEG),
302 cpl_msg_info(__func__,
"Approx. offset of exposure %u: %.3e,%.3e deg", i+1,
307 cpl_table_insert(pt->
table, aPixtables[i]->
table, nrow);
311 aPixtables[i] = NULL;
315 cpl_propertylist_append_long_long(pt->
header, keyword, nrow);
316 snprintf(comment, KEYWORD_LENGTH, MUSE_HDR_PT_EXP_FST_COMMENT, i + 1);
317 cpl_propertylist_set_comment(pt->
header, keyword, comment);
319 cpl_propertylist_append_long_long(pt->
header, keyword,
321 snprintf(comment, KEYWORD_LENGTH, MUSE_HDR_PT_EXP_LST_COMMENT, i + 1);
322 cpl_propertylist_set_comment(pt->
header, keyword, comment);
324 cpl_array_delete(dra);
325 cpl_array_delete(ddec);
330 MUSE_HDR_PT_COMBINED_COMMENT);
332 double timefini = cpl_test_get_walltime(),
333 cpufini = cpl_test_get_cputime();
335 cpl_msg_debug(__func__,
"Combining %u tables took %gs (wall-clock) and %gs "
336 "(CPU)", npt, timefini - timeinit, cpufini - cpuinit);
#define MUSE_HDR_PT_EXP_FST
FITS header keyword defining the first row index for a given exposure.
cpl_size muse_pixtable_get_nrow(muse_pixtable *aPixtable)
get the number of rows within the pixel table
double muse_pfits_get_ra(const cpl_propertylist *aHeaders)
find out the right ascension
#define MUSE_HDR_PT_EXP_LST
FITS header keyword defining the last row index for a given exposure.
void muse_utils_memory_dump(const char *aMarker)
Display the current memory usage of the given program.
#define MUSE_HDR_PT_COMBINED
cpl_table * table
The pixel table.
cpl_error_code muse_xcombine_weights(muse_pixtable **aPixtables, muse_xcombine_types aWeighting)
compute the weights for combination of two or more exposures
cpl_error_code muse_pixtable_origin_copy_offsets(muse_pixtable *aOut, muse_pixtable *aFrom, unsigned int aNum)
Copy MUSE_HDR_PT_IFU_SLICE_OFFSET keywords between pixel tables.
cpl_array * muse_cplarray_new_from_delimited_string(const char *aString, const char *aDelim)
Convert a delimited string into an array of strings.
double muse_pfits_get_fwhm_end(const cpl_propertylist *aHeaders)
find out the ambient seeing at end of exposure (in arcsec)
Structure definition of MUSE pixel table.
#define MUSE_HDR_PT_WEIGHTED
muse_pixtable_wcs muse_pixtable_wcs_check(muse_pixtable *aPixtable)
Check the state of the world coordinate system of a pixel table.
double muse_pfits_get_fwhm_start(const cpl_propertylist *aHeaders)
find out the ambient seeing at start of exposure (in arcsec)
double muse_pfits_get_dec(const cpl_propertylist *aHeaders)
find out the declination
muse_pixtable * muse_xcombine_tables(muse_pixtable **aPixtables)
combine the pixel tables of several exposures into one
double muse_pfits_get_exptime(const cpl_propertylist *aHeaders)
find out the exposure time
cpl_error_code muse_wcs_position_celestial(muse_pixtable *aPixtable, double aRA, double aDEC)
Convert native to celestial spherical coordinates in a pixel table.
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
muse_xcombine_types
Xposure combination types.
cpl_error_code muse_pixtable_compute_limits(muse_pixtable *aPixtable)
(Re-)Compute the limits of the coordinate columns of a pixel table.
cpl_propertylist * header
The FITS header.