00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025
00026
00027
00028
00029 #include <muse.h>
00030 #include "muse_scipost_subtract_sky_simple_z.h"
00031
00032
00040
00041 int
00042 muse_scipost_subtract_sky_simple_compute(muse_processing *aProcessing,
00043 muse_scipost_subtract_sky_simple_params_t *aParams)
00044 {
00045 cpl_table *spectrum = muse_table_load(aProcessing, MUSE_TAG_SKY_SPECTRUM, 0);
00046 if (!spectrum) {
00047 cpl_msg_warning(__func__, "Could not load %s", MUSE_TAG_SKY_SPECTRUM);
00048 }
00049
00050
00051 cpl_table_name_column(spectrum, "data", "flux");
00052
00053 cpl_errorstate prestate = cpl_errorstate_get();
00054 cpl_frameset *inframes = muse_frameset_find_tags(aProcessing->inframes,
00055 aProcessing->intags, 0,
00056 CPL_FALSE);
00057 cpl_error_code rc = CPL_ERROR_NONE;
00058 cpl_size iframe, nframes = cpl_frameset_get_size(inframes);
00059 for (iframe = 0; iframe < nframes; iframe++) {
00060 cpl_frame *frame = cpl_frameset_get_position(inframes, iframe);
00061 const char *fn = cpl_frame_get_filename(frame);
00062 muse_pixtable *pixtable =
00063 muse_pixtable_load_restricted_wavelength(fn,
00064 aParams->lambdamin,
00065 aParams->lambdamax);
00066 if (pixtable == NULL) {
00067 cpl_msg_error(__func__, "NULL pixel table for \"%s\"", fn);
00068 rc = CPL_ERROR_NULL_INPUT;
00069 break;
00070 }
00071 muse_processing_append_used(aProcessing, frame, CPL_FRAME_GROUP_RAW, 1);
00072
00073
00074 cpl_propertylist_erase_regexp(pixtable->header, "ESO QC ", 0);
00075
00076 if (muse_pixtable_is_skysub(pixtable) == CPL_TRUE) {
00077 cpl_msg_error(__func__, "Pixel table \"%s\" already sky subtracted", fn);
00078 muse_pixtable_delete(pixtable);
00079 rc = CPL_ERROR_ILLEGAL_INPUT;
00080 break;
00081 }
00082
00083 rc = muse_sky_subtract_continuum(pixtable, spectrum);
00084 if (rc != CPL_ERROR_NONE) {
00085 cpl_msg_error(__func__, "while subtracting sky spectrum from \"%s\"", fn);
00086 muse_pixtable_delete(pixtable);
00087 break;
00088 }
00089 muse_processing_save_table(aProcessing, -1, pixtable, NULL,
00090 MUSE_TAG_PIXTABLE_REDUCED,
00091 MUSE_TABLE_TYPE_PIXTABLE);
00092 muse_pixtable_delete(pixtable);
00093 }
00094 cpl_frameset_delete(inframes);
00095 cpl_table_delete(spectrum);
00096
00097 return cpl_errorstate_is_equal(prestate) ? 0 : rc;
00098 }