34#include <mf_wrap_config.h>
35#include <telluriccorr.h>
48#define MODEL_RECIPE_ID "xsh_molecfit_model"
49#define MODEL_RECIPE_AUTHOR "N. Fernando, B. Miszalski"
50#define MODEL_RECIPE_CONTACT "nuwanthika.fernando@partner.eso.org"
74"Applies molecfit_model to input spectra";
77"Applies molecfit_model to input spectra";
124 cpl_recipe *recipe = NULL;
125 cpl_plugin *plugin = NULL;
127 recipe = cpl_calloc(1,
sizeof(*recipe));
128 if ( recipe == NULL ){
132 plugin = &recipe->interface ;
134 cpl_plugin_init(plugin,
137 CPL_PLUGIN_TYPE_RECIPE,
148 cpl_pluginlist_append(list, plugin);
150 return (cpl_error_get_code() != CPL_ERROR_NONE);
166 cpl_recipe *recipe = NULL;
181 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin");
184 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
185 CPL_ERROR_TYPE_MISMATCH,
186 "Plugin is not a recipe");
188 recipe = (cpl_recipe *)plugin;
191 recipe->parameters = cpl_parameterlist_new();
192 assure( recipe->parameters != NULL,
193 CPL_ERROR_ILLEGAL_OUTPUT,
194 "Memory allocation failed!");
201 MOLECFIT_PARAMETER_LIST,
"NULL",
207 MOLECFIT_PARAMETER_FIT,
"NULL",
213 MOLECFIT_PARAMETER_RELATIVE_VALUE,
"NULL",
219 MOLECFIT_PARAMETER_WAVE_RANGE_INCLUDE,
"NULL",
225 MOLECFIT_PARAMETER_WAVE_RANGE_EXCLUDE,
"NULL",
231 MOLECFIT_PARAMETER_PIXEL_RANGE_EXCLUDE,
"NULL",
237 MF_PARAMETERS_COLUMN_LAMBDA,
"WAVE",
243 MF_PARAMETERS_COLUMN_FLUX,
"FLUX",
249 MF_PARAMETERS_COLUMN_DFLUX,
"ERR",
255 MF_PARAMETERS_DEFAULT_ERROR,0.01,
261 MF_PARAMETERS_FTOL,0.001,
267 MF_PARAMETERS_XTOL,0.001,
273 MF_PARAMETERS_FIT_CONTINUUM,
"1",
279 MF_PARAMETERS_CONTINUUM_N,
"1",
285 MF_PARAMETERS_FIT_WLC,
"1",
290 MF_PARAMETERS_WLC_N,2,
296 MF_PARAMETERS_WLC_CONST,0.0,
302 MF_PARAMETERS_FIT_RES_BOX,
false,
308 MF_PARAMETERS_RES_BOX,1.0,
314 MF_PARAMETERS_FIT_GAUSS,
true,
320 MF_PARAMETERS_RES_GAUSS,1.0,
326 MF_PARAMETERS_FIT_LORENTZ,
false,
332 MF_PARAMETERS_RES_LORENTZ,2.0,
338 MF_PARAMETERS_KERN_MODE,
false,
344 MF_PARAMETERS_KERN_FAC,3.0,
350 MF_PARAMETERS_VAR_KERN,
true,
356 MOLECFIT_PARAMETER_USE_INPUT_KERNEL,
true,
362 MF_PARAMETERS_FIT_TELESCOPE_BACK,
false,
368 MF_PARAMETERS_TELESCOPE_BACK_CONST,0.1,
374 MF_PARAMETERS_PWV,-1.0,
380 MF_PARAMETERS_SLIT_WIDTH_KEYWORD,
"HEADER",
381 MF_PARAMETERS_SLIT_WIDTH_DESC ));
386 MF_PARAMETERS_SLIT_WIDTH_VALUE,MF_PARAMETERS_SLIT_WIDTH_VALUE_INIT,
387 MF_PARAMETERS_SLIT_WIDTH_VALUE_DESC));
392 MF_LNFL_LINE_DB,MF_LNFL_LINE_DB_AER_VERSION,
397 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
416 cpl_recipe *recipe = NULL;
419 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
422 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
423 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
425 recipe = (cpl_recipe *)plugin;
430 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
449 cpl_recipe *recipe = NULL;
452 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
455 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
456 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
458 recipe = (cpl_recipe *)plugin;
463 if (cpl_error_get_code() != CPL_ERROR_NONE)
487 cpl_frame* f = cpl_frameset_find(frameset,input_name);
488 cpl_frame_set_group(f,CPL_FRAME_GROUP_RAW);
497 tag = cpl_sprintf(
"%s_%s",MOLECFIT_KERNEL_LIBRARY,arm);
498 f = cpl_frameset_find(frameset,tag);
500 cpl_frame_set_group(f, CPL_FRAME_GROUP_CALIB);
503 tag = cpl_sprintf(
"%s_%s",MOLECFIT_GDAS,arm);
505 f = cpl_frameset_find(frameset,tag);
507 cpl_frame_set_group(f, CPL_FRAME_GROUP_CALIB);
510 tag = cpl_sprintf(
"%s_%s",MOLECFIT_WAVE_INCLUDE,arm);
511 f = cpl_frameset_find(frameset,tag);
513 cpl_frame_set_group(f, CPL_FRAME_GROUP_CALIB);
516 tag = cpl_sprintf(
"%s_%s",MOLECFIT_WAVE_EXCLUDE,arm);
517 f = cpl_frameset_find(frameset,tag);
519 cpl_frame_set_group(f, CPL_FRAME_GROUP_CALIB);
522 tag = cpl_sprintf(
"%s_%s",MOLECFIT_PIXEL_EXCLUDE,arm);
523 f = cpl_frameset_find(frameset,tag);
525 cpl_frame_set_group(f, CPL_FRAME_GROUP_CALIB);
528 tag = cpl_sprintf(
"%s_%s",MOLECFIT_MOLECULES,arm);
529 f = cpl_frameset_find(frameset,tag);
531 cpl_frame_set_group(f, CPL_FRAME_GROUP_CALIB);
534 tag = cpl_sprintf(
"%s_%s",MOLECFIT_ATM_PROFILE_STANDARD,arm);
535 f = cpl_frameset_find(frameset,tag);
537 cpl_frame_set_group(f, CPL_FRAME_GROUP_CALIB);
540 tag = cpl_sprintf(
"%s_%s",MOLECFIT_ATM_PROFILE_COMBINED,arm);
541 f = cpl_frameset_find(frameset,tag);
543 cpl_frame_set_group(f, CPL_FRAME_GROUP_CALIB);
545 return CPL_ERROR_NONE;
550 for(cpl_size row=0;row<cpl_table_get_nrow(tab);row++){
551 const char* fld = cpl_sprintf(
"%s",cpl_table_get_string(tab,
"parameter",row));
552 double val = cpl_table_get_double(tab,
"value",row,NULL);
554 if(!strcmp(fld,
"initial_chi2")){
555 cpl_propertylist_update_double(pl,
"ESO QC INITIAL CHI2",val);
557 if(!strcmp(fld,
"best_chi2")){
558 cpl_propertylist_update_double(pl,
"ESO QC BEST CHI2",val);
560 if(!strcmp(fld,
"reduced_chi2")){
561 cpl_propertylist_update_double(pl,
"ESO QC REDUCED CHI2",val);
563 if(!strcmp(fld,
"rms_rel_to_err")){
564 cpl_propertylist_update_double(pl,
"ESO QC RMS TO ERR",val);
566 if(!strcmp(fld,
"rms_rel_to_mean")){
567 cpl_propertylist_update_double(pl,
"ESO QC RMS TO MEAN",val);
569 if(!strcmp(fld,
"chip 1, coef 0")){
570 cpl_propertylist_update_double(pl,
"ESO QC LAMBDA 0",val);
572 if(!strcmp(fld,
"chip 1, coef 1")){
573 cpl_propertylist_update_double(pl,
"ESO QC LAMBDA 1",val);
575 if(!strcmp(fld,
"chip 1, coef 2")){
576 cpl_propertylist_update_double(pl,
"ESO QC LAMBDA 2",val);
578 if(!strcmp(fld,
"h2o_col_mm")){
579 cpl_propertylist_update_double(pl,
"ESO QC H2O COL MM",val);
581 if(strstr(fld,
"rel_mol_col_")){
583 string[0] = strtok(fld,
"_");
585 while(
string[i]!= NULL){
586 if(
string[i] != NULL && strcmp(
string[i],
"rel") && strcmp(
string[i],
"mol") && strcmp(
string[i],
"col")){
588 cpl_propertylist_update_double(pl,kw,val);
591 string[i]= strtok(NULL,
"_");
594 if(strstr(fld,
"ppmv_")){
596 string[0] = strtok(fld,
"_");
598 while(
string[i]!= NULL){
599 if(
string[i]!= NULL && strcmp(
string[i],
"ppmv") && strcmp(
string[i],
"mol") && strcmp(
string[i],
"col")){
601 cpl_propertylist_update_double(pl,kw,val);
604 string[i]= strtok(NULL,
"_");
634 cpl_error_code err= CPL_ERROR_NONE;
635 cpl_errorstate initial_errorstate = cpl_errorstate_get();
644 cpl_parameterlist* ilist = cpl_parameterlist_new();
645 cpl_parameterlist* iframelist = cpl_parameterlist_new();
654 cpl_msg_info(cpl_func,
"completed xsh_molecfit_model_config; %d : %s",err,cpl_error_get_message());
656 const char* input_name = cpl_parameter_get_string(cpl_parameterlist_find(iframelist,
"INPUTNAME"));
657 const char* arm = cpl_parameter_get_string(cpl_parameterlist_find(iframelist,
"ARM"));
659 const char* is_idp = cpl_parameter_get_string(cpl_parameterlist_find(iframelist,
"IDP"));
660 const char* fname = cpl_parameter_get_string(cpl_parameterlist_find(iframelist,
"INPUTFILENAME"));
662 cpl_msg_info(cpl_func,
"iframelist details: INPUTNAME: %s; ARM: %s; IDP: %s; INPUTFILENAME: %s;",input_name,arm,is_idp,fname);
667 const char* suffix = arm;
669 const char* type_suffix =
"STD";
670 if(strstr(input_name,
"SCI")){
680 cpl_parameterlist* mergedlist = cpl_parameterlist_new();
686 err = mf_wrap_merge_parameterlists(ilist, parlist,mergedlist);
698 err = cpl_error_get_code();
725 cpl_msg_info(cpl_func,
"calling mf_wrap_fits_load");
726 data = mf_wrap_fits_load(fname, CPL_FALSE);
735 cpl_msg_info(cpl_func,
"calling mf_wrap_config_model_init");
736 cpl_msg_info(cpl_func,
"property list of header size");
737 cpl_msg_info(cpl_func,
"size: %lld",cpl_propertylist_get_size(
data->v_ext[0].header));
738 mf_wrap_model_parameter* parameters = mf_wrap_config_model_init(mergedlist,
data->v_ext[0].header);
763 err = mf_wrap_data_convert_to_table(
data,
764 parameters->chip_extensions,
765 parameters->use_only_input_pri_ext,
766 parameters->dflux_extension_data,
767 parameters->mask_extension_data,
768 parameters->mf_config->parameters->inputs.column_lambda,
769 parameters->mf_config->parameters->inputs.column_flux,
770 parameters->mf_config->parameters->inputs.column_dflux,
771 parameters->mf_config->parameters->inputs.column_mask);
796 cpl_table* molecules = NULL;
801 molecules = mf_wrap_molecules(frameset,
data, mergedlist, parameters,suffix);
807 cpl_table* inc_wranges = NULL;
808 cpl_table* exc_wranges = NULL;
809 cpl_table* exc_pranges = NULL;
812 err = mf_wrap_wranges(frameset,
data, mergedlist, parameters, &inc_wranges, &exc_wranges, &exc_pranges,suffix);
821 mf_wrap_fits *kernel_data = NULL;
822 cpl_table *mapping_kernel = NULL;
824 err = mf_wrap_kernel(frameset, parameters, kernel_data, mapping_kernel,suffix);
827 cpl_boolean gdas_write = CPL_FALSE;
828 cpl_table *gdas_user = NULL;
831 err = mf_wrap_gdas(frameset, parameters, gdas_user,suffix);
835 cpl_boolean atm_profile_standard_write = CPL_FALSE;
836 cpl_table *atm_profile_standard = NULL;
837 cpl_table *atm_profile_combined = NULL;
839 const char* atm_suffix = cpl_sprintf(
"%s_%s",type_suffix,suffix);
841 err = mf_wrap_atm(frameset, parameters, &atm_profile_standard,atm_suffix);
848 cpl_msg_info(cpl_func,
"Save generic multi-extension output FITS file ('%s','%s') ...", MOLECFIT_ATM_PARAMETERS, MOLECFIT_BEST_FIT_MODEL);
851 const char* combined_suffix = cpl_sprintf(
"%s_%s",type_suffix,suffix);
853 const char* output_fname = mf_wrap_tag_suffix(MOLECFIT_ATM_PARAMETERS,combined_suffix,CPL_TRUE);
854 const char* tag_name = mf_wrap_tag_suffix(MOLECFIT_ATM_PARAMETERS,combined_suffix,CPL_FALSE);
855 err += mf_wrap_save(frameset, frameset, mergedlist,
MODEL_RECIPE_ID, parameters->pl, tag_name, output_fname);
861 output_fname = mf_wrap_tag_suffix(MOLECFIT_BEST_FIT_MODEL,combined_suffix,CPL_TRUE);
862 tag_name = mf_wrap_tag_suffix(MOLECFIT_BEST_FIT_MODEL,combined_suffix,CPL_FALSE);
863 err += mf_wrap_save(frameset, frameset, mergedlist,
MODEL_RECIPE_ID, parameters->pl, tag_name,output_fname);
865 output_fname = mf_wrap_tag_suffix(
"MOLECFIT_DATA",combined_suffix,CPL_TRUE);
866 tag_name = mf_wrap_tag_suffix(
"MOLECFIT_DATA",combined_suffix,CPL_FALSE);
867 err += mf_wrap_save(frameset, frameset, mergedlist,
MODEL_RECIPE_ID, parameters->pl, tag_name,output_fname);
874 output_fname = mf_wrap_tag_suffix(MOLECFIT_MODEL_KERNEL_LIBRARY,suffix,CPL_TRUE);
875 tag_name = mf_wrap_tag_suffix(MOLECFIT_MODEL_KERNEL_LIBRARY,suffix,CPL_FALSE);
876 err += mf_wrap_save(frameset, frameset, mergedlist,
MODEL_RECIPE_ID, parameters->pl, tag_name,output_fname);
893 if ( parameters->use_only_input_pri_ext) n_ext = 1;
894 else if (parameters->chip_extensions ) n_ext =
data->v_ext[0].spectrum_data ? 1 : 2;
895 else n_ext =
data->n_ext;
899 if (!parameters->use_only_input_pri_ext && n_ext == 1){
900 cpl_msg_warning(cpl_func,
"No data extensions found. USE_ONLY_INPUT_PRIMARY_DATA=FALSE and number of extensions == 1");
908 for (cpl_size ext = 0; ext < n_ext && !err; ext++) {
910 mf_model_results *results = NULL;
913 if (
data->v_ext[ext].spectrum_data) {
916 cpl_propertylist *header_kernel = NULL;
917 cpl_matrix *kernel = NULL;
920 if (mapping_kernel) {
922 cpl_size index_kernel_ext = cpl_table_get(mapping_kernel, MOLECFIT_MAPPING_KERNEL_EXT, ext, &null);
923 header_kernel = kernel_data->v_ext[index_kernel_ext].header;
924 kernel = kernel_data->v_ext[index_kernel_ext].matrix;
926 header_kernel = kernel_data->v_ext[ext].header;
927 kernel = kernel_data->v_ext[ext].matrix;
932 cpl_msg_info(cpl_func,
"Load spectrum, ext = %lld ...", ext);
933 cpl_table *molecfit_data = mf_spectrum_create(parameters->mf_config->parameters,
data->v_ext[ext].spectrum_data);
939 if (!parameters->chip_extensions) {
940 double max_wave = cpl_table_get_column_max(molecfit_data,MF_COL_IN_LAMBDA);
941 double min_wave = cpl_table_get_column_min(molecfit_data,MF_COL_IN_LAMBDA);
945 inc_wranges = cpl_table_extract_selected(inc_wranges);
958 results = mf_model( parameters->mf_config,
960 data->v_ext[ext].spectrum_head,
968 atm_profile_standard,
969 atm_profile_combined);
973 cpl_table_delete(molecfit_data);
974 err = cpl_error_get_code();
982 if (results && !gdas_write) {
983 mf_gdas_write(results, mergedlist, gdas_user, frameset, parameters,
data,suffix);
988 if (!err && results && !atm_profile_standard_write) {
989 mf_atm_write(results, mergedlist, frameset, parameters,
data, atm_profile_standard,suffix);
993 if (!err && kernel_data) {
995 cpl_matrix *kernel_matrix = NULL;
997 if (results->kernel) kernel_matrix = results->kernel;
999 const char* output_fname = mf_wrap_tag_suffix(MOLECFIT_MODEL_KERNEL_LIBRARY,suffix,CPL_TRUE);
1000 err += mf_wrap_save_mf_results(header_kernel, output_fname, CPL_FALSE, kernel_matrix, NULL, NULL);
1005 if (!err && (parameters->use_only_input_pri_ext || ext > 0) ) {
1008 cpl_table *atm_profile_fitted = results ? results->atm_profile_fitted : NULL;
1009 cpl_table *best_fit_params = results ? results->res : NULL;
1010 cpl_table *best_fit_model = results ? results->spec : NULL;
1012 const char* combined_suffix = cpl_sprintf(
"%s_%s",type_suffix,suffix);
1013 const char* output_fname = mf_wrap_tag_suffix(MOLECFIT_ATM_PARAMETERS,combined_suffix,CPL_TRUE);
1014 err += mf_wrap_save_mf_results(
data->v_ext[ext].header, output_fname,CPL_FALSE, NULL, atm_profile_fitted, NULL);
1016 if(best_fit_params){
1017 output_fname = mf_wrap_tag_suffix(MOLECFIT_BEST_FIT_PARAMETERS,combined_suffix,CPL_TRUE);
1018 const char* tag_name = mf_wrap_tag_suffix(MOLECFIT_BEST_FIT_PARAMETERS,combined_suffix,CPL_FALSE);
1021 cpl_propertylist* bfp_hdr = cpl_propertylist_duplicate(parameters->pl);
1024 err += mf_wrap_save(frameset, frameset, mergedlist,
MODEL_RECIPE_ID, bfp_hdr, tag_name, output_fname);
1025 err += mf_wrap_save_mf_results(
data->v_ext[ext].header, output_fname, CPL_FALSE, NULL, best_fit_params, NULL);
1026 cpl_propertylist_delete(bfp_hdr);
1028 const char* output_fname = mf_wrap_tag_suffix(MOLECFIT_BEST_FIT_PARAMETERS,combined_suffix,CPL_TRUE);
1029 const char* tag_name = mf_wrap_tag_suffix(MOLECFIT_BEST_FIT_PARAMETERS,combined_suffix,CPL_FALSE);
1030 err += mf_wrap_save(frameset, frameset, mergedlist,
MODEL_RECIPE_ID, parameters->pl, tag_name, output_fname);
1032 output_fname = mf_wrap_tag_suffix(MOLECFIT_BEST_FIT_MODEL,combined_suffix,CPL_TRUE);
1033 err += mf_wrap_save_mf_results(
data->v_ext[ext].header, output_fname,CPL_FALSE, NULL, best_fit_model, NULL);
1035 output_fname = mf_wrap_tag_suffix(
"MOLECFIT_DATA",combined_suffix,CPL_TRUE);
1036 err += mf_wrap_save_mf_results(
data->v_ext[ext].header,output_fname,CPL_FALSE, NULL, results->spec, NULL);
1043 const char* combined_suffix = cpl_sprintf(
"%s_%s",type_suffix,suffix);
1044 const char *output_fname = mf_wrap_tag_suffix(MOLECFIT_BEST_FIT_PARAMETERS,combined_suffix,CPL_TRUE);
1045 const char* tag_name = mf_wrap_tag_suffix(MOLECFIT_BEST_FIT_PARAMETERS,combined_suffix,CPL_FALSE);
1046 err += mf_wrap_save(frameset, frameset, mergedlist,
MODEL_RECIPE_ID, parameters->pl, tag_name, output_fname);
1051 if (results) mf_model_results_delete(results);
1062 if (parameters ) mf_wrap_model_parameter_delete( parameters );
1063 if (
data ) mf_wrap_fits_delete(
data );
1064 if (molecules ) cpl_table_delete( molecules );
1065 if (inc_wranges ) cpl_table_delete( inc_wranges );
1066 if (exc_wranges ) cpl_table_delete( exc_wranges );
1067 if (exc_pranges ) cpl_table_delete( exc_pranges );
1068 if (kernel_data ) mf_wrap_fits_delete( kernel_data );
1069 if (mapping_kernel ) cpl_table_delete( mapping_kernel );
1070 if (gdas_user ) cpl_table_delete( gdas_user );
1071 if (atm_profile_standard) cpl_table_delete( atm_profile_standard );
1072 if (atm_profile_combined) cpl_table_delete( atm_profile_combined );
1076 if (!err && cpl_errorstate_is_equal(initial_errorstate)) {
1077 cpl_msg_info(cpl_func,
"Recipe successfully!");
1080 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
1081 cpl_msg_error(cpl_func,
"Recipe failed!, error(%d)=%s", err, cpl_error_get_message());
1092 cpl_error_code err = CPL_ERROR_NONE;
1093 cpl_boolean USE_ONLY_INPUT_PRIMARY_DATA = CPL_TRUE;
1094 if(!strcmp(is_idp,
"TRUE")){
1095 USE_ONLY_INPUT_PRIMARY_DATA = CPL_FALSE;
1103 if(USE_ONLY_INPUT_PRIMARY_DATA){
1108 cpl_msg_info(cpl_func,
"spec_ext: %d",spec_ext);
1118 cpl_size nrows = cpl_table_get_nrow(
data->v_ext[spec_ext].spectrum_data);
1119 cpl_msg_info(cpl_func,
"nrows: %lld",nrows);
1122 const char* FLUX_COLUMN = cpl_parameter_get_string(cpl_parameterlist_find(ilist,MF_PARAMETERS_COLUMN_FLUX));
1123 cpl_msg_info(cpl_func,
"flux column: %s",FLUX_COLUMN);
1127 double median = cpl_table_get_column_median(
data->v_ext[spec_ext].spectrum_data,FLUX_COLUMN);
1128 cpl_msg_info(cpl_func,
"spectrum median: %.4e",median);
1131 cpl_parameterlist_append(ilist,cpl_parameter_new_value(MF_PARAMETERS_CONTINUUM_CONST,CPL_TYPE_DOUBLE,NULL,NULL,median));
1134 mf_parameters_fitting *fitting = &(parameters->mf_config->parameters->fitting);
1135 fitting->fit_continuum.const_val = median;
1136 cpl_propertylist_update_double(parameters->pl, MF_PARAMETERS_CONTEX_DEFAULT
" "MF_PARAMETERS_CONTINUUM_CONST, fitting->fit_continuum.const_val);
1137 parameters->mf_config->parameters->fitting = *fitting;
1145 cpl_msg_info(cpl_func,
"xsh_molecfit_model_spec_header_calcs");
1147 cpl_msg_info(cpl_func,
"reading in %s",fname);
1153 cpl_propertylist* hdr= cpl_propertylist_load(fname, ext);
1156 if (cpl_parameterlist_find(ilist,
"SLIT_WIDTH_KEYWORD")==NULL){
1157 const char* slit_width_kw =
"NONE";
1158 if(!strcmp(arm,
"UVB")){
1159 slit_width_kw =
"ESO INS OPTI3 NAME";
1160 }
else if(!strcmp(arm,
"VIS")){
1161 slit_width_kw =
"ESO INS OPTI4 NAME";
1162 }
else if(!strcmp(arm,
"NIR")){
1163 slit_width_kw =
"ESO INS OPTI5 NAME";
1165 cpl_msg_info(cpl_func,
"to read in %s value",slit_width_kw);
1166 cpl_property *prop_hval = cpl_propertylist_get_property(hdr, slit_width_kw);
1168 const char* hval = cpl_property_get_string(prop_hval);
1170 cpl_msg_info(cpl_func,
"SLIT_WIDTH_VALUE: %s (read from %s)",strtok(hval,
"x"),slit_width_kw);
1176 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"SLIT_WIDTH_KEYWORD",CPL_TYPE_STRING,NULL,NULL,
"NONE"));
1177 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"SLIT_WIDTH_VALUE",CPL_TYPE_DOUBLE,NULL,NULL,atof(strtok(hval,
"x"))));
1184 const char* WAVELENGTH_FRAME =
"AIR";
1185 const char* OBS_ERF_RV_KEY =
"NONE";
1187 cpl_property *prop_tu = cpl_propertylist_get_property(hdr,
"TUCD1");
1188 cpl_property *prop_ss = cpl_propertylist_get_property(hdr,
"SPECSYS");
1189 cpl_property *prop_hb = cpl_propertylist_get_property(hdr,
"ESO QC VRAD BARYCOR");
1190 cpl_property *prop_hh = cpl_propertylist_get_property(hdr,
"ESO QC VRAD HELICOR");
1196 const char* val = cpl_property_get_string(prop_tu);
1197 cpl_msg_info(cpl_func,
"TUCD1 found: %s",val);
1198 if(!strcmp(val,
"em.wl;obs.atmos")){
1199 WAVELENGTH_FRAME=
"AIR";
1200 }
else if(!strcmp(val,
"em.wl")){
1201 WAVELENGTH_FRAME=
"VAC";
1205 WAVELENGTH_FRAME=
"AIR";
1209 const char* val = cpl_property_get_string(prop_ss);
1210 cpl_msg_info(cpl_func,
"SPECSYS found: %s",val);
1211 if(!strcmp(val,
"TOPOCENT")){
1212 OBS_ERF_RV_KEY =
"NONE";
1213 }
else if(!strcmp(val,
"BARYCENT")){
1214 OBS_ERF_RV_KEY =
"ESO QC VRAD BARYCOR";
1215 WAVELENGTH_FRAME = cpl_sprintf(
"%s_RV",WAVELENGTH_FRAME);
1216 }
else if(!strcmp(val,
"HELIOCENT")){
1217 OBS_ERF_RV_KEY =
"ESO QC VRAD HELICOR";
1218 WAVELENGTH_FRAME = cpl_sprintf(
"%s_RV",WAVELENGTH_FRAME);
1237 if(WAVELENGTH_FRAME){
1239 cpl_msg_info(cpl_func,
"WAVELENGTH_FRAME: %s",WAVELENGTH_FRAME);
1240 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"WAVELENGTH_FRAME",CPL_TYPE_STRING,NULL,NULL,WAVELENGTH_FRAME));
1244 cpl_msg_info(cpl_func,
"OBS_ERF_RV_KEY: %s",OBS_ERF_RV_KEY);
1246 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"OBS_ERF_RV_KEY",CPL_TYPE_STRING,NULL,NULL,OBS_ERF_RV_KEY));
1257 cpl_propertylist_delete(hdr);
1261 return CPL_ERROR_NONE;
1285 cpl_parameterlist* ilist, cpl_parameterlist* iframelist){
1287 cpl_msg_info(cpl_func,
"xsh_molecfit_model_config");
1292 cpl_parameterlist* iframe = cpl_parameterlist_new();
1298 cpl_error_code err= CPL_ERROR_NONE;
1317 const char* input_name = cpl_parameter_get_string(cpl_parameterlist_find(iframe,
"INPUTNAME"));
1318 const char* arm = cpl_parameter_get_string(cpl_parameterlist_find(iframe,
"ARM"));
1319 const char* obsmode = cpl_parameter_get_string(cpl_parameterlist_find(iframe,
"OBSMODE"));
1320 const char* is_idp = cpl_parameter_get_string(cpl_parameterlist_find(iframe,
"IDP"));
1321 const char* fname = cpl_parameter_get_string(cpl_parameterlist_find(iframe,
"INPUTFILENAME"));
1323 cpl_msg_info(cpl_func,
"iframe details; INPUTNAME: %s; ARM: %s; IDP: %s; OBSMODE: %s; INPUTFILENAME: %s",input_name,arm,is_idp,obsmode,fname);
1327 err = cpl_parameterlist_append(iframelist,cpl_parameterlist_find(iframe,
"INPUTNAME"));
1328 err = cpl_parameterlist_append(iframelist,cpl_parameterlist_find(iframe,
"ARM"));
1329 err = cpl_parameterlist_append(iframelist,cpl_parameterlist_find(iframe,
"OBSMODE"));
1330 err = cpl_parameterlist_append(iframelist,cpl_parameterlist_find(iframe,
"IDP"));
1331 err = cpl_parameterlist_append(iframelist,cpl_parameterlist_find(iframe,
"INPUTFILENAME"));
1343 const char* LIST_MOLEC;
1344 const char* FIT_MOLEC;
1345 const char* REL_COL;
1346 const char* WAVE_INCLUDE;
1347 const char* MAP_REGIONS_TO_CHIP;
1352 cpl_boolean USE_ONLY_INPUT_PRIMARY_DATA;
1353 int USE_DATA_EXTENSION_AS_DFLUX;
1354 int USE_DATA_EXTENSION_AS_MASK;
1355 double WLG_TO_MICRON;
1356 cpl_boolean TRANSMISSION;
1366 const char* input_tag;
1367 input_tag = mf_wrap_tag_suffix(MOLECFIT_KERNEL_LIBRARY,arm,CPL_FALSE);
1368 if(!cpl_frameset_find(frameset,input_tag)){
1369 cpl_parameterlist_append(ilist,cpl_parameter_new_value(MOLECFIT_MODEL_MAPPING_KERNEL,CPL_TYPE_STRING,NULL,NULL,
"NULL"));
1370 cpl_parameterlist_append(ilist,cpl_parameter_new_value(MOLECFIT_PARAMETER_USE_INPUT_KERNEL,CPL_TYPE_BOOL,NULL,NULL,
false));
1376 input_tag = mf_wrap_tag_suffix(MOLECFIT_PARAMETER_WAVE_RANGE_EXCLUDE,arm,CPL_FALSE);
1377 if(!cpl_frameset_find(frameset,input_tag)){
1378 cpl_parameterlist_append(ilist,cpl_parameter_new_value(MOLECFIT_PARAMETER_WAVE_RANGE_EXCLUDE,CPL_TYPE_STRING,NULL,NULL,
"NULL"));
1381 input_tag = mf_wrap_tag_suffix(MOLECFIT_PARAMETER_PIXEL_RANGE_EXCLUDE,arm,CPL_FALSE);
1382 if(!cpl_frameset_find(frameset,input_tag)){
1383 cpl_parameterlist_append(ilist,cpl_parameter_new_value(MOLECFIT_PARAMETER_PIXEL_RANGE_EXCLUDE,CPL_TYPE_STRING,NULL,NULL,
"NULL"));
1386 cpl_parameterlist_append(ilist,cpl_parameter_new_value(MOLECFIT_PARAMETER_CHIP_EXTENSIONS,CPL_TYPE_BOOL,NULL,NULL,
false));
1389 input_tag = mf_wrap_tag_suffix(MOLECFIT_GDAS,arm,CPL_FALSE);
1390 if(!cpl_frameset_find(frameset,input_tag)){
1391 cpl_parameterlist_append(ilist,cpl_parameter_new_value(MF_PARAMETERS_GDAS_PROFILE,CPL_TYPE_STRING,NULL,NULL,
"auto"));
1394 cpl_parameterlist_append(ilist,cpl_parameter_new_value(MF_PARAMETERS_EXPERT_MODE,CPL_TYPE_BOOL,NULL,NULL,CPL_FALSE));
1396 TRANSMISSION = CPL_TRUE;
1397 cpl_parameterlist_append(ilist,cpl_parameter_new_value(MF_PARAMETERS_TRANSMISSION,CPL_TYPE_BOOL,NULL,NULL,TRANSMISSION));
1400 if(!strcmp(arm,
"NIR")){
1401 LIST_MOLEC =
"H2O,CO2,CO,CH4,O2";
1402 FIT_MOLEC =
"1,1,0,0,0";
1403 REL_COL =
" 1,1.06,1,1,1";
1404 WAVE_INCLUDE =
"1.16,1.20,1.47,1.48,1.77,1.78,2.06,2.07,2.35,2.36";
1406 MAP_REGIONS_TO_CHIP =
"1";
1413 if(!strcmp(arm,
"VIS")){
1414 LIST_MOLEC =
"H2O,O2";
1417 WAVE_INCLUDE =
"0.686,0.694,0.725,0.730,0.970,0.980";
1419 MAP_REGIONS_TO_CHIP =
"1";
1426 const char* default_list_molec = cpl_parameter_get_string(cpl_parameterlist_find(parlist,
"LIST_MOLEC"));
1427 const char* default_fit_molec = cpl_parameter_get_string(cpl_parameterlist_find(parlist,
"FIT_MOLEC"));
1428 const char* default_rel_col = cpl_parameter_get_string(cpl_parameterlist_find(parlist,
"REL_COL"));
1429 const char* default_wave_include = cpl_parameter_get_string(cpl_parameterlist_find(parlist,
"WAVE_INCLUDE"));
1430 const char* SLIT_WIDTH_KEYWORD = cpl_parameter_get_string(cpl_parameterlist_find(parlist,
"SLIT_WIDTH_KEYWORD"));
1431 double SLIT_WIDTH_VALUE = cpl_parameter_get_double(cpl_parameterlist_find(parlist,
"SLIT_WIDTH_VALUE"));
1434 cpl_msg_info(cpl_func,
"setting arm dependent parameters");
1435 if(!strcmp(arm,
"VIS") || !strcmp(arm,
"NIR")){
1438 input_tag = mf_wrap_tag_suffix(
"MOLECULES",arm,CPL_FALSE);
1439 if(!cpl_frameset_find(frameset,input_tag) && (!strcmp(default_list_molec,
"NULL") && !strcmp(default_fit_molec,
"NULL") && !strcmp(default_rel_col,
"NULL") )){
1440 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"LIST_MOLEC",CPL_TYPE_STRING,NULL,NULL,LIST_MOLEC));
1441 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"FIT_MOLEC",CPL_TYPE_STRING,NULL,NULL,FIT_MOLEC));
1442 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"REL_COL",CPL_TYPE_STRING,NULL,NULL,REL_COL));
1444 input_tag = mf_wrap_tag_suffix(
"WAVE_INCLUDE",arm,CPL_FALSE);
1451 if(!cpl_frameset_find(frameset,input_tag) && !strcmp(default_wave_include,
"NULL")){
1452 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"WAVE_INCLUDE",CPL_TYPE_STRING,NULL,NULL,WAVE_INCLUDE));
1455 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"MAP_REGIONS_TO_CHIP",CPL_TYPE_STRING,NULL,NULL,MAP_REGIONS_TO_CHIP));
1473 const char* PIX_SCALE_KEYWORD =
"NONE";
1474 double PIX_SCALE_VALUE;
1477 if(!strcmp(arm,
"UVB")){
1478 PIX_SCALE_VALUE = 0.161;
1480 if(!strcmp(arm,
"VIS")){
1481 PIX_SCALE_VALUE = 0.158;
1483 if(!strcmp(arm,
"NIR")){
1487 PIX_SCALE_VALUE = 0.248;
1491 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"PIX_SCALE_KEYWORD",CPL_TYPE_STRING,NULL,NULL,PIX_SCALE_KEYWORD));
1492 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"PIX_SCALE_VALUE",CPL_TYPE_DOUBLE,NULL,NULL,PIX_SCALE_VALUE));
1493 if (!strcmp(SLIT_WIDTH_KEYWORD,
"NONE")){
1494 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"SLIT_WIDTH_KEYWORD",CPL_TYPE_STRING,NULL,NULL,SLIT_WIDTH_KEYWORD));
1495 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"SLIT_WIDTH_VALUE",CPL_TYPE_DOUBLE,NULL,NULL, SLIT_WIDTH_VALUE));
1504 USE_ONLY_INPUT_PRIMARY_DATA = CPL_TRUE;
1505 if(!strcmp(is_idp,
"TRUE")){
1506 USE_ONLY_INPUT_PRIMARY_DATA = CPL_FALSE;
1509 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"USE_ONLY_INPUT_PRIMARY_DATA",CPL_TYPE_BOOL,NULL,NULL,USE_ONLY_INPUT_PRIMARY_DATA));
1514 USE_DATA_EXTENSION_AS_DFLUX = 1;
1516 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"USE_DATA_EXTENSION_AS_DFLUX",CPL_TYPE_INT,NULL,NULL,USE_DATA_EXTENSION_AS_DFLUX));
1519 USE_DATA_EXTENSION_AS_MASK = 0;
1520 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"USE_DATA_EXTENSION_AS_MASK",CPL_TYPE_INT,NULL,NULL,USE_DATA_EXTENSION_AS_MASK));
1522 WLG_TO_MICRON = 1e-3;
1524 cpl_parameterlist_append(ilist,cpl_parameter_new_value(
"WLG_TO_MICRON",CPL_TYPE_DOUBLE,NULL,NULL,WLG_TO_MICRON));
1533 cpl_msg_info(cpl_func,
"calling xsh_molecfit_model_spec_header_calcs with fname = %s",fname);
cpl_error_code xsh_molecfit_model_spec_header_calcs(const char *fname, const char *arm, cpl_parameterlist *ilist)
int xsh_molecfit_model(cpl_frameset *frameset, const cpl_parameterlist *parlist)
Interpret the command line options and execute the data processing.
int xsh_molecfit_model_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
int xsh_molecfit_model_create(cpl_plugin *)
Setup the recipe options.
int xsh_molecfit_model_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
cpl_error_code xsh_molecfit_model_spec_data_calcs(mf_wrap_fits *data, const char *is_idp, cpl_parameterlist *ilist, mf_wrap_model_parameter *parameters)
void xsh_molecfit_model_qc(cpl_propertylist *pl, cpl_table *tab)
cpl_error_code xsh_molecfit_setup_frameset(cpl_frameset *frameset, cpl_parameterlist *list, const char *arm, const char *input_name)
cpl_error_code xsh_molecfit_model_config(cpl_frameset *frameset, const cpl_parameterlist *parlist, cpl_parameterlist *ilist, cpl_parameterlist *iframelist)
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
#define assure(CONDITION, ERROR_CODE,...)
#define xsh_error_dump(level)
void xsh_free_parameterlist(cpl_parameterlist **p)
Deallocate a parameter list and set the pointer to NULL.
const char * xsh_string_toupper(char *s)
Convert all lowercase characters in a string into uppercase characters.
const char * xsh_get_license(void)
Get the pipeline copyright and license.
void xsh_init(void)
Reset library state.
#define XSH_MOLECFIT_PARAMETER_USE_INPUT_KERNEL_DESC
char xsh_molecfit_model_description[]
char xsh_molecfit_model_description_short[]
#define MODEL_RECIPE_AUTHOR
#define MODEL_RECIPE_CONTACT
#define XSH_MF_PARAMETERS_RES_BOX_DESC
#define XSH_MF_PARAMETERS_FIT_RES_BOX_DESC
#define XSH_MF_PARAMETERS_COLUMN_LAMBDA_DESC
#define XSH_MF_PARAMETERS_COLUMN_FLUX_DESC
#define XSH_MF_PARAMETERS_CONTINUUM_N_DESC
#define XSH_MF_PARAMETERS_FIT_GAUSS_DESC
#define XSH_MOLECFIT_PARAMETER_RELATIVE_VALUE_DESC
#define XSH_MOLECFIT_PARAMETER_WAVE_RANGE_INCLUDE_DESC
#define XSH_MF_PARAMETERS_TELESCOPE_BACK_CONST_DESC
#define XSH_MF_PARAMETERS_FIT_WLC_DESC
#define XSH_MF_PARAMETERS_COLUMN_DFLUX_DESC
#define XSH_MF_LNFL_LINE_DB_DESC
#define XSH_MF_PARAMETERS_RES_LORENTZ_DESC
#define XSH_MF_PARAMETERS_RES_GAUSS_DESC
#define XSH_MOLECFIT_PARAMETER_LIST_DESC
#define XSH_MOLECFIT_PARAMETER_PIXEL_RANGE_EXCLUDE_DESC
#define XSH_MF_PARAMETERS_KERN_MODE_DESC
#define XSH_MF_PARAMETERS_FIT_CONTINUUM_DESC
#define XSH_MF_PARAMETERS_KERN_FAC_DESC
#define XSH_MF_PARAMETERS_FTOL_DESC
#define XSH_MF_PARAMETERS_WLC_N_DESC
#define XSH_MF_PARAMETERS_DEFAULT_ERROR_DESC
#define XSH_MF_PARAMETERS_VAR_KERN_DESC
#define XSH_MF_PARAMETERS_PWV_DESC
#define XSH_MF_PARAMETERS_FIT_LORENTZ_DESC
#define XSH_MOLECFIT_PARAMETER_WAVE_RANGE_EXCLUDE_DESC
#define XSH_MF_PARAMETERS_WLC_CONST_DESC
#define XSH_MF_PARAMETERS_XTOL_DESC
#define XSH_MOLECFIT_PARAMETER_FIT_DESC
#define XSH_MF_PARAMETERS_FIT_TELESCOPE_BACK_DESC
cpl_error_code xsh_molecfit_utils_find_input_frame(cpl_frameset *frameset, cpl_parameterlist *iframe)
cpl_error_code xsh_molecfit_model_check_extensions_and_ranges(cpl_size extension, double min_wav, double max_wav, cpl_table *range)
void xsh_parameters_new_boolean(cpl_parameterlist *list, const char *recipe_id, const char *name, int value, const char *comment)
void xsh_parameters_new_double(cpl_parameterlist *list, const char *recipe_id, const char *name, double value, const char *comment)
void xsh_parameters_new_string(cpl_parameterlist *list, const char *recipe_id, const char *name, const char *value, const char *comment)
void xsh_parameters_new_int(cpl_parameterlist *list, const char *recipe_id, const char *name, int value, const char *comment)