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_combine_pixtables_z.h"
00031
00032
00041
00042 int
00043 muse_scipost_combine_pixtables_compute(muse_processing *aProcessing,
00044 muse_scipost_combine_pixtables_params_t *aParams)
00045 {
00046
00047 muse_xcombine_types weight = muse_postproc_get_weight_type(aParams->weight_s);
00048
00049
00050 cpl_table *exposures = muse_processing_sort_exposures(aProcessing);
00051 if (!exposures) {
00052 cpl_msg_error(__func__, "no science exposures found in input");
00053 return -1;
00054 }
00055 int nexposures = cpl_table_get_nrow(exposures);
00056
00057 cpl_table *offsets = muse_table_load(aProcessing, MUSE_TAG_OFFSET_LIST, 0);
00058 if (offsets && muse_cpltable_check(offsets, muse_offset_list_def) != CPL_ERROR_NONE) {
00059 cpl_msg_warning(__func__, "Input %s has unexpected format, proceeding "
00060 "without offset and flux scales!", MUSE_TAG_OFFSET_LIST);
00061 cpl_table_delete(offsets);
00062 offsets = NULL;
00063 }
00064
00065
00066
00067 muse_pixtable **pixtables = cpl_calloc(nexposures + 1, sizeof(muse_pixtable *));
00068 int i;
00069 for (i = 0; i < nexposures; i++) {
00070 cpl_table *thisexp = cpl_table_extract(exposures, i, 1);
00071 pixtables[i] = muse_pixtable_load_merge_channels(thisexp,
00072 aParams->lambdamin,
00073 aParams->lambdamax);
00074 cpl_table_delete(thisexp);
00075
00076 cpl_propertylist_erase_regexp(pixtables[i]->header, "ESO QC ", 0);
00077 }
00078 cpl_table_delete(exposures);
00079
00080 do {
00081
00082 muse_pixtable *bigpixtable = NULL;
00083 if (nexposures > 1) {
00084 cpl_error_code rc = muse_xcombine_weights(pixtables, weight);
00085 if (rc != CPL_ERROR_NONE) {
00086 cpl_msg_error(__func__, "weighting the pixel tables didn't work: %s",
00087 cpl_error_get_message());
00088 break;
00089 }
00090
00091 bigpixtable = muse_xcombine_tables(pixtables, offsets);
00092 if (!bigpixtable) {
00093 cpl_msg_error(__func__, "combining the pixel tables didn't work: %s",
00094 cpl_error_get_message());
00095 break;
00096 }
00097 } else {
00098 bigpixtable = pixtables[0];
00099 }
00100 cpl_free(pixtables);
00101
00102 muse_processing_save_table(aProcessing, -1, bigpixtable, NULL,
00103 MUSE_TAG_PIXTABLE_COMBINED,
00104 MUSE_TABLE_TYPE_PIXTABLE);
00105 muse_pixtable_delete(bigpixtable);
00106 cpl_table_delete(offsets);
00107 return 0;
00108 } while (0);
00109 for (i = 0; i < nexposures; i++) {
00110 muse_pixtable_delete(pixtables[i]);
00111 }
00112 cpl_free(pixtables);
00113 cpl_table_delete(offsets);
00114 return -1;
00115 }