38 #include <cpl_parameter.h>
39 #include <cpl_parameterlist.h>
40 #include <cpl_image.h>
48 #include "gimessages.h"
50 #include "gimath_lm.h"
51 #include "gifiberutils.h"
53 #include "girebinning.h"
64 #define GIFITS_KEYWORD_MISSING_MSG "FITS KEYWORD [%s] not found!! Aborting..."
65 #define GIWAVECAL_GRATING_WAVELENGTH_EPSILON 0.0001
79 cx_string *filter_name;
80 cx_string *setup_name;
97 typedef struct GiGrat GiGrat;
100 struct GiFiberPosition {
105 typedef struct GiFiberPosition GiFiberPosition;
108 struct GiLocPosition {
112 cpl_image *centroids;
116 typedef struct GiLocPosition GiLocPosition;
119 struct GiBinnParams {
124 typedef struct GiBinnParams GiBinnParams;
129 cpl_matrix **subslits;
132 typedef struct GiSlitGeo GiSlitGeo;
134 struct GiWcalSolution {
136 lmrq_model_id opt_mod;
137 cpl_matrix *opt_mod_params;
138 GiSlitGeo *wav_coeffs;
139 GiSlitGeo *wav_limits;
142 typedef struct GiWcalSolution GiWcalSolution;
146 const cxchar* method;
160 typedef struct GiRebinInfo GiRebinInfo;
167 static cxdouble ddb, dde;
171 _giraffe_resample_update_properties(GiImage* spectra, GiRebinInfo* info)
179 giraffe_error_push();
181 cpl_propertylist_update_double(properties, GIALIAS_DATAMIN,
182 cpl_image_get_min(image));
183 cpl_propertylist_update_double(properties, GIALIAS_DATAMAX,
184 cpl_image_get_max(image));
186 cpl_propertylist_update_string(properties, GIALIAS_GIRFTYPE,
189 cpl_propertylist_update_int(properties, GIALIAS_BINWNX,
190 cpl_image_get_size_y(image));
191 cpl_propertylist_update_int(properties, GIALIAS_BINWNS,
192 cpl_image_get_size_x(image));
194 cpl_propertylist_update_string(properties, GIALIAS_BUNIT,
197 cpl_propertylist_update_string(properties, GIALIAS_CTYPE1,
199 cpl_propertylist_update_string(properties, GIALIAS_CUNIT1,
201 cpl_propertylist_update_double(properties, GIALIAS_CRPIX1,
203 cpl_propertylist_update_double(properties, GIALIAS_CRVAL1,
205 cpl_propertylist_update_double(properties, GIALIAS_CDELT1,
208 cpl_propertylist_update_string(properties, GIALIAS_CTYPE2,
210 cpl_propertylist_update_string(properties, GIALIAS_CUNIT2,
212 cpl_propertylist_update_double(properties, GIALIAS_CRPIX2,
214 cpl_propertylist_update_double(properties, GIALIAS_CRVAL2,
216 cpl_propertylist_update_double(properties, GIALIAS_CDELT2,
219 cpl_propertylist_update_double(properties, GIALIAS_BINWLMIN,
221 cpl_propertylist_update_double(properties, GIALIAS_BINWL0,
223 cpl_propertylist_update_double(properties, GIALIAS_BINWLMAX,
225 cpl_propertylist_update_double(properties, GIALIAS_BINSTEP,
227 cpl_propertylist_update_string(properties, GIALIAS_BINMETHOD,
229 cpl_propertylist_update_string(properties, GIALIAS_BINSCALE,
231 cpl_propertylist_update_string(properties, GIALIAS_BINRANGE,
234 if (cpl_error_get_code() != CPL_ERROR_NONE) {
246 _giraffe_grating_new(
void)
249 GiGrat *grating = NULL;
251 grating = (GiGrat*) cx_calloc(1, (cxsize)
sizeof(GiGrat));
253 grating->name = cx_string_create(
"UNKNOWN");
254 grating->filter_name = cx_string_create(
"UNKNOWN");
255 grating->setup_name = cx_string_create(
"UNKNOWN");
256 grating->slit_name = cx_string_create(
"UNKNOWN");
264 _giraffe_grating_delete(GiGrat *grating)
267 if (grating==NULL) {
return; }
269 if (grating->name!=NULL) {
270 cx_string_delete(grating->name);
272 if (grating->filter_name!=NULL) {
273 cx_string_delete(grating->filter_name);
275 if (grating->setup_name!=NULL) {
276 cx_string_delete(grating->setup_name);
278 if (grating->slit_name!=NULL) {
279 cx_string_delete(grating->slit_name);
287 _giraffe_grating_setup(
const GiTable *grating_table,
288 const GiImage *grating_ass_img, GiGrat *grating_setup)
295 const cxchar *fctid =
"_giraffe_grating_setup";
297 cxdouble wlen_match = 0.0,
301 cxint32 row_match = 0,
305 const cxchar *c_name_setup =
"SETUP";
306 const cxchar *c_name_order =
"ORDER";
307 const cxchar *c_name_wl0 =
"WLEN0";
308 const cxchar *c_name_wlmin =
"WLMIN";
309 const cxchar *c_name_wlmax =
"WLMAX";
310 const cxchar *c_name_band =
"BAND";
311 const cxchar *c_name_theta =
"THETA";
312 const cxchar *c_name_fcoll =
"FCOLL";
313 const cxchar *c_name_gcam =
"GCAM";
314 const cxchar *c_name_sdx =
"SDX";
315 const cxchar *c_name_sdy =
"SDY";
316 const cxchar *c_name_sdphi =
"SPHI";
317 const cxchar *c_name_rmed =
"RMED";
318 const cxchar *c_name_rifa =
"RIFA";
320 cpl_propertylist *ref_plimg = NULL;
321 cpl_table *ref_gtable = NULL;
322 cx_string *slit_name = NULL;
324 GiInstrumentMode instrument_mode;
331 if (grating_table ==NULL) {
return 1; }
332 if (grating_ass_img==NULL) {
return 1; }
333 if (grating_setup ==NULL) {
return 1; }
343 slit_name = cx_string_new();
353 if (!cpl_propertylist_has(ref_plimg, GIALIAS_GRATWLEN)) {
354 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_GRATWLEN);
355 cx_string_delete(slit_name);
359 grating_setup->wlen0 = cpl_propertylist_get_double(ref_plimg,
363 if (!cpl_propertylist_has(ref_plimg, GIALIAS_GRATORDER)) {
364 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_GRATORDER);
365 cx_string_delete(slit_name);
369 grating_setup->order = cpl_propertylist_get_int(ref_plimg, GIALIAS_GRATORDER);
372 if (!cpl_propertylist_has(ref_plimg, GIALIAS_SLITNAME)) {
374 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_SLITNAME);
375 cx_string_delete(slit_name);
378 cx_string_set(slit_name,
379 cpl_propertylist_get_string(ref_plimg, GIALIAS_SLITNAME));
382 if (!cpl_propertylist_has(ref_plimg, GIALIAS_GRATGRV)) {
384 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_GRATGRV);
385 cx_string_delete(slit_name);
388 tmp_gratgrv = cpl_propertylist_get_double(ref_plimg, GIALIAS_GRATGRV );
391 if (!cpl_propertylist_has(ref_plimg, GIALIAS_GRATNAME)) {
392 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_GRATNAME);
393 cx_string_delete(slit_name);
396 cx_string_set(grating_setup->name,
397 cpl_propertylist_get_string(ref_plimg, GIALIAS_GRATNAME));
400 if (!cpl_propertylist_has(ref_plimg, GIALIAS_FILTNAME)) {
401 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_FILTNAME);
402 cx_string_delete(slit_name);
406 cx_string_set(grating_setup->filter_name,
407 cpl_propertylist_get_string(ref_plimg, GIALIAS_FILTNAME));
415 for (i = 0; i < cpl_table_get_nrow(ref_gtable); i++) {
417 cxint _order = cpl_table_get_int(ref_gtable, c_name_order, i, NULL);
419 if (_order == grating_setup->order) {
421 wlen = cpl_table_get(ref_gtable, c_name_wl0, i, &row_nulls);
423 if (fabs(wlen - grating_setup->wlen0) <
424 fabs(wlen_match - grating_setup->wlen0)) {
437 if (fabs(wlen_match - grating_setup->wlen0) >
438 GIWAVECAL_GRATING_WAVELENGTH_EPSILON) {
440 cpl_msg_error(fctid,
"Grating setup (wavelength %.2f nm, order %d) "
441 "not found in grating table!", grating_setup->wlen0,
442 grating_setup->order);
443 cx_string_delete(slit_name);
447 cpl_msg_debug(fctid,
"Found wlen0 in grating table at position %d",
456 cx_string_set(grating_setup->setup_name,
457 (cxchar*) cpl_table_get_string(ref_gtable, c_name_setup,
460 cx_string_set(grating_setup->slit_name, cx_string_get(slit_name));
462 grating_setup->wlenmin = cpl_table_get(ref_gtable, c_name_wlmin,
463 row_match, &row_nulls);
465 grating_setup->wlenmax = cpl_table_get(ref_gtable, c_name_wlmax,
466 row_match, &row_nulls);
468 grating_setup->band = cpl_table_get(ref_gtable, c_name_band,
469 row_match, &row_nulls);
471 grating_setup->theta = cpl_table_get(ref_gtable, c_name_theta,
472 row_match, &row_nulls);
474 grating_setup->space = 1.0 / fabs(GI_MM_TO_NM * tmp_gratgrv);
479 switch (instrument_mode) {
481 grating_setup->resol = cpl_table_get(ref_gtable, c_name_rmed,
482 row_match, &row_nulls);
486 grating_setup->resol = cpl_table_get(ref_gtable, c_name_rifa,
487 row_match, &row_nulls);
491 grating_setup->resol = cpl_table_get(ref_gtable, c_name_rifa,
492 row_match, &row_nulls);
496 grating_setup->resol = -1.0;
500 grating_setup->fcoll =
501 cpl_table_get(ref_gtable, c_name_fcoll, row_match, &row_nulls);
503 grating_setup->gcam =
504 cpl_table_get(ref_gtable, c_name_gcam, row_match, &row_nulls);
506 grating_setup->slitdx =
507 cpl_table_get(ref_gtable, c_name_sdx, row_match, &row_nulls);
509 grating_setup->slitdy =
510 cpl_table_get(ref_gtable, c_name_sdy, row_match, &row_nulls);
512 grating_setup->slitphi =
513 cpl_table_get(ref_gtable, c_name_sdphi, row_match, &row_nulls);
515 cx_string_delete(slit_name);
522 static GiFiberPosition*
523 _giraffe_fiberposition_new(
void)
526 GiFiberPosition* tmp = NULL;
528 tmp = (GiFiberPosition*) cx_calloc(1,
sizeof(GiFiberPosition));
538 _giraffe_fiberposition_delete(GiFiberPosition *fp)
544 cpl_matrix_delete(fp->x_fiber);
548 cpl_matrix_delete(fp->y_fiber);
561 _giraffe_slitgeo_new(
void)
564 GiSlitGeo *sgeometry = NULL;
566 sgeometry = cx_malloc(
sizeof(GiSlitGeo));
568 sgeometry->subslits = NULL;
569 sgeometry->nsubslits = 0;
577 _giraffe_slitgeo_delete(GiSlitGeo *sgeometry)
580 if (sgeometry != NULL) {
582 if (sgeometry->subslits != NULL) {
586 for (i = 0; i < sgeometry->nsubslits; i++) {
587 cpl_matrix_delete(sgeometry->subslits[i]);
590 cx_free(sgeometry->subslits);
603 _giraffe_slitgeo_size(GiSlitGeo *sgeometry)
606 if (sgeometry == NULL) {
610 if (sgeometry->subslits != NULL) {
611 return sgeometry->nsubslits;
620 _giraffe_slitgeo_resize(GiSlitGeo *sgeometry, cxint size)
623 if (sgeometry == NULL) {
627 if (size == sgeometry->nsubslits) {
631 if (sgeometry->subslits != NULL) {
635 for (i = 0; i < sgeometry->nsubslits; i++) {
636 cpl_matrix_delete(sgeometry->subslits[i]);
640 cx_free(sgeometry->subslits);
642 sgeometry->nsubslits = size;
643 sgeometry->subslits = cx_calloc(sgeometry->nsubslits,
sizeof(cpl_matrix*));
651 _giraffe_slitgeo_create(GiSlitGeo *sgeometry, cxint idx, cxint nrow,
655 if (sgeometry == NULL) {
659 if (sgeometry->subslits == NULL) {
663 if ((idx < 0) || (idx > sgeometry->nsubslits)) {
667 if (sgeometry->subslits[idx] != NULL) {
668 cpl_matrix_delete(sgeometry->subslits[idx]);
671 sgeometry->subslits[idx] = cpl_matrix_new(nrow, ncol);
679 _giraffe_slitgeo_set(GiSlitGeo *sgeometry, cxint idx, cpl_matrix *nm)
682 if (sgeometry == NULL) {
686 if (sgeometry->subslits == NULL) {
690 if ((idx < 0) || (idx > sgeometry->nsubslits)) {
694 if (sgeometry->subslits[idx] != NULL) {
695 cpl_matrix_delete(sgeometry->subslits[idx]);
699 sgeometry->subslits[idx] = cpl_matrix_duplicate(nm);
702 sgeometry->subslits[idx] = NULL;
709 _giraffe_slitgeo_get(GiSlitGeo *sgeometry, cxint idx)
712 if (sgeometry == NULL) {
716 if (sgeometry->subslits == NULL) {
720 if ((idx < 0)||(idx > sgeometry->nsubslits)) {
724 return (sgeometry->subslits[idx]);
730 _giraffe_slitgeo_setup(
const GiTable *slitgeo,
731 GiFiberPosition *fiber_slit_position,
732 GiSlitGeo *subslits, cxbool fitsubslit)
735 const cxchar *
const fctid =
"_giraffe_slitgeo_setup";
738 const cxchar *c_name_xf =
"XF";
739 const cxchar *c_name_yf =
"YF";
740 const cxchar *c_name_nspec =
"FPS";
741 const cxchar *c_name_ssn =
"SSN";
744 cpl_matrix *nspec = NULL;
745 cpl_matrix *nsubslits = NULL;
747 cxint nr_slitgeo = 0,
760 cpl_table *ref_slitgeo = NULL;
762 cpl_error_code ce_code;
769 if (slitgeo ==NULL) {
return 1; }
770 if (fiber_slit_position==NULL) {
return 1; }
771 if (subslits ==NULL) {
return 1; }
778 nr_slitgeo = cpl_table_get_nrow(ref_slitgeo);
780 fiber_slit_position->x_fiber = cpl_matrix_new(nr_slitgeo, 1);
781 fiber_slit_position->y_fiber = cpl_matrix_new(nr_slitgeo, 1);
783 nspec = cpl_matrix_new(nr_slitgeo, 1);
784 nsubslits = cpl_matrix_new(nr_slitgeo, 1);
792 for (i = 0; i < nr_slitgeo; i++) {
794 tmp_xf = cpl_table_get(ref_slitgeo, c_name_xf, i, &row_null);
795 tmp_yf = cpl_table_get(ref_slitgeo, c_name_yf, i, &row_null);
797 tmp_nspec = cpl_table_get_int(ref_slitgeo, c_name_nspec, i,
800 tmp_nsubslits = cpl_table_get_int(ref_slitgeo, c_name_ssn, i,
803 if (tmp_nsubslits>max_nsubslits) {
804 max_nsubslits = tmp_nsubslits;
807 ce_code = cpl_matrix_set(fiber_slit_position->x_fiber, i, 0, tmp_xf);
808 ce_code = cpl_matrix_set(fiber_slit_position->y_fiber, i, 0, tmp_yf);
810 ce_code = cpl_matrix_set(nspec, i, 0, (cxdouble)tmp_nspec);
811 ce_code = cpl_matrix_set(nsubslits, i, 0, (cxdouble)tmp_nsubslits);
823 _giraffe_slitgeo_resize(subslits, max_nsubslits);
825 for (i = 1; i <= max_nsubslits; i++) {
827 cpl_matrix *ref_matrix = NULL;
831 for (j=0; j<nr_slitgeo; j++) {
832 curr_ssn = (cxint) cpl_matrix_get(nsubslits, j, 0);
838 _giraffe_slitgeo_create(subslits, i-1, count, 1);
840 ref_matrix = _giraffe_slitgeo_get(subslits, i-1);
843 for (j = 0; j < nr_slitgeo; j++) {
845 curr_ssn = (cxint) cpl_matrix_get(nsubslits, j, 0);
848 ce_code = cpl_matrix_set(ref_matrix, column_index, 0,
856 cpl_msg_debug(fctid,
"Using multiple slits for Slit Geometry");
868 cpl_matrix *ref_matrix = NULL;
870 _giraffe_slitgeo_resize(subslits, 1);
871 _giraffe_slitgeo_create(subslits, 0, nr_slitgeo, 1);
873 ref_matrix = _giraffe_slitgeo_get(subslits, 0);
875 for (j = 0; j < nr_slitgeo; j++) {
877 cxint cs = cpl_table_get_int(ref_slitgeo, idx, j, NULL) - 1;
878 ce_code = cpl_matrix_set(ref_matrix, j, 0, cs);
883 cpl_msg_debug(fctid,
"Using single slit for Slit Geometry");
887 cpl_matrix_delete(nspec);
890 cpl_matrix_delete(nsubslits);
898 static GiWcalSolution*
899 _giraffe_wcalsolution_new(
void)
902 GiWcalSolution* tmp = NULL;
904 tmp = (GiWcalSolution*) cx_calloc(1,
sizeof(GiWcalSolution));
906 tmp->subslitfit = FALSE;
907 tmp->opt_mod = LMRQ_UNDEFINED;
908 tmp->opt_mod_params = NULL;
909 tmp->wav_coeffs = NULL;
910 tmp->wav_limits = NULL;
917 _giraffe_wcalsolution_delete(GiWcalSolution *ws)
922 if (ws->opt_mod_params!=NULL) {
923 cpl_matrix_delete(ws->opt_mod_params);
926 if (ws->wav_coeffs!=NULL) {
927 _giraffe_slitgeo_delete(ws->wav_coeffs);
930 if (ws->wav_limits!=NULL) {
931 _giraffe_slitgeo_delete(ws->wav_limits);
943 static GiWcalSolution*
944 _giraffe_wcalsolution_create(
const GiTable *wavesolution)
950 cxint poly_x_deg = 0;
951 cxint poly_y_deg = 0;
952 cxint ncoefficients = 0;
954 cxdouble* pd_coefficients = NULL;
956 cpl_matrix* coefficients = NULL;
957 cpl_matrix* limits = NULL;
959 cpl_propertylist* _properties = NULL;
961 cpl_table* _table = NULL;
963 GiWcalSolution* wavcoeff = NULL;
967 if (wavesolution == NULL) {
971 wavcoeff = _giraffe_wcalsolution_new();
980 if (cpl_propertylist_has(_properties, GIALIAS_OPT_MOD) == TRUE) {
982 const cxchar* optmod = cpl_propertylist_get_string(_properties,
985 if (strncmp(optmod,
"xoptmod2", 8) == 0) {
986 wavcoeff->opt_mod = LMRQ_XOPTMOD2;
988 else if (strncmp(optmod,
"xoptmod", 7) == 0) {
989 wavcoeff->opt_mod = LMRQ_XOPTMOD;
992 wavcoeff->opt_mod = LMRQ_UNDEFINED;
996 if (wavcoeff->opt_mod == LMRQ_XOPTMOD2) {
998 wavcoeff->opt_mod_params = cpl_matrix_new(7,1);
1000 if (cpl_propertylist_has(_properties, GIALIAS_OPTMDIR)) {
1002 wavcoeff->opt_mod_params,
1005 cpl_propertylist_get_int(_properties, GIALIAS_OPTMDIR)
1008 _giraffe_wcalsolution_delete(wavcoeff);
1012 if (cpl_propertylist_has(_properties, GIALIAS_WSOL_OPTMFCOLL)) {
1014 wavcoeff->opt_mod_params,
1017 cpl_propertylist_get_double(_properties, GIALIAS_WSOL_OPTMFCOLL)
1020 _giraffe_wcalsolution_delete(wavcoeff);
1024 if (cpl_propertylist_has(_properties, GIALIAS_WSOL_OPTMGCAM)) {
1026 wavcoeff->opt_mod_params,
1029 cpl_propertylist_get_double(_properties, GIALIAS_WSOL_OPTMGCAM)
1032 _giraffe_wcalsolution_delete(wavcoeff);
1036 if (cpl_propertylist_has(_properties, GIALIAS_WSOL_OPTMTHETA)) {
1038 wavcoeff->opt_mod_params,
1041 cpl_propertylist_get_double(_properties, GIALIAS_WSOL_OPTMTHETA)
1044 _giraffe_wcalsolution_delete(wavcoeff);
1048 if (cpl_propertylist_has(_properties, GIALIAS_WSOL_OPTMSDX)) {
1050 wavcoeff->opt_mod_params,
1053 cpl_propertylist_get_double(_properties, GIALIAS_WSOL_OPTMSDX)
1056 _giraffe_wcalsolution_delete(wavcoeff);
1060 if (cpl_propertylist_has(_properties, GIALIAS_WSOL_OPTMSDY)) {
1065 wavcoeff->opt_mod_params,
1068 cpl_propertylist_get_double(_properties, GIALIAS_WSOL_OPTMSDY)
1072 _giraffe_wcalsolution_delete(wavcoeff);
1076 if (cpl_propertylist_has(_properties, GIALIAS_WSOL_OPTMSPHI)) {
1078 wavcoeff->opt_mod_params,
1081 cpl_propertylist_get_double(_properties, GIALIAS_WSOL_OPTMSPHI)
1085 _giraffe_wcalsolution_delete(wavcoeff);
1089 }
else if (wavcoeff->opt_mod==LMRQ_XOPTMOD) {
1091 wavcoeff->opt_mod_params = cpl_matrix_new(4,1);
1093 if (cpl_propertylist_has(_properties, GIALIAS_OPTMDIR)) {
1095 wavcoeff->opt_mod_params,
1098 cpl_propertylist_get_int(_properties, GIALIAS_OPTMDIR)
1101 _giraffe_wcalsolution_delete(wavcoeff);
1105 if (cpl_propertylist_has(_properties, GIALIAS_WSOL_OPTMFCOLL)) {
1107 wavcoeff->opt_mod_params,
1110 cpl_propertylist_get_double(_properties, GIALIAS_WSOL_OPTMFCOLL)
1113 _giraffe_wcalsolution_delete(wavcoeff);
1117 if (cpl_propertylist_has(_properties, GIALIAS_WSOL_OPTMGCAM)) {
1119 wavcoeff->opt_mod_params,
1122 cpl_propertylist_get_double(_properties, GIALIAS_WSOL_OPTMGCAM)
1125 _giraffe_wcalsolution_delete(wavcoeff);
1129 if (cpl_propertylist_has(_properties, GIALIAS_WSOL_OPTMTHETA)) {
1131 wavcoeff->opt_mod_params,
1134 cpl_propertylist_get_double(_properties, GIALIAS_WSOL_OPTMTHETA)
1137 _giraffe_wcalsolution_delete(wavcoeff);
1144 _giraffe_wcalsolution_delete(wavcoeff);
1156 if (_table != NULL) {
1159 if (cpl_propertylist_has(_properties, GIALIAS_SSF)) {
1161 if (cpl_propertylist_get_bool(_properties, GIALIAS_SSF) == 0) {
1162 wavcoeff->subslitfit = FALSE;
1165 wavcoeff->subslitfit = TRUE;
1171 _giraffe_wcalsolution_delete(wavcoeff);
1176 wavcoeff->wav_limits = _giraffe_slitgeo_new();
1177 _giraffe_slitgeo_resize(wavcoeff->wav_limits, 1);
1179 limits = cpl_matrix_new(1, 4);
1180 cpl_matrix_fill(limits, -1.);
1182 if (cpl_table_has_column(_table,
"XMIN") &&
1183 cpl_table_has_column(_table,
"XMAX")) {
1184 cpl_matrix_set(limits, 0, 0,
1185 cpl_table_get_double(_table,
"XMIN", 0, NULL));
1186 cpl_matrix_set(limits, 0, 1,
1187 cpl_table_get_double(_table,
"XMAX", 0, NULL));
1190 if (cpl_table_has_column(_table,
"YMIN") &&
1191 cpl_table_has_column(_table,
"YMAX")) {
1192 cpl_matrix_set(limits, 0, 2,
1193 cpl_table_get_double(_table,
"YMIN", 0, NULL));
1194 cpl_matrix_set(limits, 0, 3,
1195 cpl_table_get_double(_table,
"YMAX", 0, NULL));
1198 _giraffe_slitgeo_set(wavcoeff->wav_limits, 0, limits);
1200 cpl_matrix_delete(limits);
1203 wavcoeff->wav_coeffs = _giraffe_slitgeo_new();
1204 _giraffe_slitgeo_resize(wavcoeff->wav_coeffs, 1);
1206 if (cpl_propertylist_has(_properties, GIALIAS_XRES_PDEG)) {
1208 cxchar *l, *r, *tmpstr;
1210 tmpstr = (cxchar*) cpl_propertylist_get_string(_properties,
1216 poly_x_deg = atoi(l) + 1;
1217 poly_y_deg = atoi(r) + 1;
1222 _giraffe_wcalsolution_delete(wavcoeff);
1227 ncoefficients = poly_x_deg * poly_y_deg;
1229 coefficients = cpl_matrix_new(poly_x_deg,poly_y_deg);
1230 pd_coefficients = cpl_matrix_get_data(coefficients);
1232 for (i=0; i<ncoefficients; i++) {
1234 snprintf(buffer,
sizeof buffer,
"XC%-d", i);
1236 pd_coefficients[i] =
1237 cpl_table_get_double(_table, buffer, 0, NULL);
1241 _giraffe_slitgeo_set(wavcoeff->wav_coeffs, 0, coefficients);
1243 cpl_matrix_delete(coefficients);
1244 coefficients = NULL;
1254 _giraffe_compute_pixel_abscissa(cpl_matrix* m_wavelengths,
1255 cpl_matrix* m_wloffset,
1256 GiFiberPosition* fiber_slit_position,
1257 cpl_matrix* m_opt_mod_params,
1265 const cxchar *fctid =
"_giraffe_compute_pixel_abscissa";
1268 register cxint line;
1269 register cxint nwlen;
1272 cxint nr_m_opt_mod_params = 0;
1275 cxdouble* pd_xref = NULL;
1276 cxdouble* pd_m_inputs = NULL;
1277 cxdouble* pd_m_yfibre = NULL;
1278 cxdouble* pd_m_xfibre = NULL;
1279 cxdouble* pd_m_wavelengths = NULL;
1280 cxdouble* pd_m_opt_mod_params = NULL;
1282 cpl_image* xref = NULL;
1284 cpl_matrix* m_inputs = NULL;
1291 if (m_wavelengths == NULL) {
1295 if ((fiber_slit_position == NULL) ||
1296 (fiber_slit_position->x_fiber == NULL) ||
1297 (fiber_slit_position->y_fiber == NULL)) {
1301 if (m_opt_mod_params == NULL) {
1306 nwlen = cpl_matrix_get_nrow(m_wavelengths);
1307 ns = cpl_matrix_get_nrow(fiber_slit_position->y_fiber);
1309 if ((m_wloffset != NULL) && (cpl_matrix_get_nrow(m_wloffset) != ns)) {
1318 xref = cpl_image_new(ns, nwlen, CPL_TYPE_DOUBLE);
1319 pd_xref = cpl_image_get_data_double(xref);
1321 m_inputs = cpl_matrix_new(lmrq_opt_mod_x.
ninputs, 1);
1322 pd_m_inputs = cpl_matrix_get_data(m_inputs);
1324 pd_m_yfibre = cpl_matrix_get_data(fiber_slit_position->y_fiber);
1325 pd_m_xfibre = cpl_matrix_get_data(fiber_slit_position->x_fiber);
1326 pd_m_wavelengths = cpl_matrix_get_data(m_wavelengths);
1328 pd_m_opt_mod_params = cpl_matrix_get_data(m_opt_mod_params);
1329 nr_m_opt_mod_params = cpl_matrix_get_nrow(m_opt_mod_params);
1336 if (m_wloffset != NULL) {
1338 cxdouble* pd_m_wloffset = cpl_matrix_get_data(m_wloffset);
1340 for (n = 0; n < ns; n++) {
1342 pd_m_inputs[2] = pd_m_yfibre[n];
1343 pd_m_inputs[1] = pd_m_xfibre[n];
1345 for (line = 0; line < nwlen; line++) {
1347 pd_m_inputs[0] = pd_m_wavelengths[line] + pd_m_wloffset[n];
1349 lmrq_opt_mod_x.
cfunc(pd_m_inputs, pd_m_opt_mod_params,
1350 NULL, &xccd, NULL, nr_m_opt_mod_params);
1352 pd_xref[line * ns + n] = xccd;
1361 for (n = 0; n < ns; n++) {
1363 pd_m_inputs[2] = pd_m_yfibre[n];
1364 pd_m_inputs[1] = pd_m_xfibre[n];
1366 for (line = 0; line < nwlen; line++) {
1368 pd_m_inputs[0] = pd_m_wavelengths[line];
1370 lmrq_opt_mod_x.
cfunc(pd_m_inputs, pd_m_opt_mod_params,
1371 NULL, &xccd, NULL, nr_m_opt_mod_params);
1373 pd_xref[line * ns + n] = xccd;
1381 cpl_matrix_delete(m_inputs);
1383 cpl_msg_debug(fctid,
"Processing completed: Returning image [x,y] ="
1384 " [%" CPL_SIZE_FORMAT
",%" CPL_SIZE_FORMAT
"]",
1385 cpl_image_get_size_x(xref), cpl_image_get_size_y(xref));
1392 inline static cpl_matrix *
1393 _giraffe_rebin_setup_model(GiImage *extspectra, GiWcalSolution *wcal)
1400 cpl_propertylist *properties = NULL;
1402 cpl_matrix *model = NULL;
1405 if (extspectra == NULL) {
1415 if (properties == NULL) {
1424 if (!cpl_propertylist_has(properties, GIALIAS_EXT_NX)) {
1428 npixel = cpl_propertylist_get_int(properties, GIALIAS_EXT_NX);
1435 if (!cpl_propertylist_has(properties, GIALIAS_PIXSIZX)) {
1439 pixelsize = cpl_propertylist_get_double(properties, GIALIAS_PIXSIZX);
1447 switch (wcal->opt_mod) {
1449 if (cpl_matrix_get_nrow(wcal->opt_mod_params) != 4) {
1454 cxdouble direction = cpl_matrix_get(wcal->opt_mod_params, 0, 0);
1455 cxdouble fcoll = cpl_matrix_get(wcal->opt_mod_params, 1, 0);
1456 cxdouble cfact = cpl_matrix_get(wcal->opt_mod_params, 2, 0);
1458 model = cpl_matrix_new(4, 1);
1460 cpl_matrix_set(model, 0, 0, npixel * direction);
1461 cpl_matrix_set(model, 1, 0, pixelsize);
1462 cpl_matrix_set(model, 2, 0, fcoll);
1463 cpl_matrix_set(model, 3, 0, cfact);
1468 if (cpl_matrix_get_nrow(wcal->opt_mod_params) != 7) {
1473 cxdouble direction = cpl_matrix_get(wcal->opt_mod_params, 0, 0);
1474 cxdouble fcoll = cpl_matrix_get(wcal->opt_mod_params, 1, 0);
1475 cxdouble cfact = cpl_matrix_get(wcal->opt_mod_params, 2, 0);
1476 cxdouble sdx = cpl_matrix_get(wcal->opt_mod_params, 4, 0);
1477 cxdouble sdy = cpl_matrix_get(wcal->opt_mod_params, 5, 0);
1478 cxdouble sphi = cpl_matrix_get(wcal->opt_mod_params, 6, 0);
1480 model = cpl_matrix_new(7, 1);
1482 cpl_matrix_set(model, 0, 0, npixel * direction);
1483 cpl_matrix_set(model, 1, 0, pixelsize);
1484 cpl_matrix_set(model, 2, 0, fcoll);
1485 cpl_matrix_set(model, 3, 0, cfact);
1486 cpl_matrix_set(model, 4, 0, sdx);
1487 cpl_matrix_set(model, 5, 0, sdy);
1488 cpl_matrix_set(model, 6, 0, sphi);
1497 cx_assert(model != NULL);
1504 inline static cpl_matrix *
1505 _giraffe_rebin_setup_grating(GiImage *extspectra, GiTable *grating,
1506 GiTable *wlsolution)
1511 cpl_propertylist *properties = NULL;
1513 cpl_matrix *setup = NULL;
1515 GiGrat *grating_data = _giraffe_grating_new();
1518 status = _giraffe_grating_setup(grating, extspectra, grating_data);
1521 _giraffe_grating_delete(grating_data);
1528 if (cpl_propertylist_has(properties, GIALIAS_WSOL_OMFCOLL)) {
1529 grating_data->fcoll = cpl_propertylist_get_double(properties,
1530 GIALIAS_WSOL_OMFCOLL);
1533 if (cpl_propertylist_has(properties, GIALIAS_WSOL_OMGCAM)) {
1534 grating_data->gcam = cpl_propertylist_get_double(properties,
1535 GIALIAS_WSOL_OMGCAM);
1538 if (cpl_propertylist_has(properties, GIALIAS_WSOL_OMGTHETA)) {
1539 grating_data->theta = cpl_propertylist_get_double(properties,
1540 GIALIAS_WSOL_OMGTHETA);
1543 if (cpl_propertylist_has(properties, GIALIAS_WSOL_OMSDX)) {
1544 grating_data->slitdx = cpl_propertylist_get_double(properties,
1545 GIALIAS_WSOL_OMSDX);
1548 if (cpl_propertylist_has(properties, GIALIAS_WSOL_OMSDY)) {
1549 grating_data->slitdy = cpl_propertylist_get_double(properties,
1550 GIALIAS_WSOL_OMSDY);
1553 if (cpl_propertylist_has(properties, GIALIAS_WSOL_OMSPHI)) {
1554 grating_data->slitphi = cpl_propertylist_get_double(properties,
1555 GIALIAS_WSOL_OMSPHI);
1559 setup = cpl_matrix_new(7, 1);
1561 cpl_matrix_set(setup, 0, 0, grating_data->theta);
1562 cpl_matrix_set(setup, 1, 0, grating_data->order);
1563 cpl_matrix_set(setup, 2, 0, grating_data->wlenmin / GI_MM_TO_NM);
1564 cpl_matrix_set(setup, 3, 0, grating_data->wlen0 / GI_MM_TO_NM);
1565 cpl_matrix_set(setup, 4, 0, grating_data->wlenmax / GI_MM_TO_NM);
1566 cpl_matrix_set(setup, 5, 0, grating_data->resol);
1567 cpl_matrix_set(setup, 6, 0, grating_data->space);
1569 _giraffe_grating_delete(grating_data);
1570 grating_data = NULL;
1590 _giraffe_spline_calc_circe(cxdouble x,
register cxdouble* t, cxint n)
1593 register cxint lo = 0;
1594 register cxint hi = n - 1;
1597 if (x >= t[0] && x <= t[n - 1]) {
1599 while (hi - lo > 1) {
1601 register cxint mid = (lo + hi) / 2.;
1643 _giraffe_spline_calc_tridi(
register cxdouble* a,
register cxdouble* b,
1644 register cxdouble* c,
register cxdouble* f,
1645 register cxdouble* x, cxint n)
1648 register cxint i = 0;
1652 for (i = 1; i < n; i++) {
1653 c[i] /= (a[i] - b[i] * c[i - 1]);
1658 for (i = 1; i < n; i++) {
1659 f[i] = (f[i] - b[i] * f[i - 1]) / (a[i] - b[i] * c[i - 1]);
1662 x[n - 1] = f[n - 1];
1664 for (i = n - 2; i >= 0; i--) {
1665 x[i] = f[i] - c[i] * x[i + 1];
1691 _giraffe_spline_calc_interpolate(cxdouble z, cxdouble* val,
1692 register cxdouble* x,
register cxdouble* y,
1693 register cxdouble* k, cxint n)
1706 m = _giraffe_spline_calc_circe(z, x, n);
1713 *val = y[0] + dx * (k[0] + 0.5 * dx * ddb);
1716 *val = y[n - 1] + dx * (k[n - 1] + 0.5 * dx * dde);
1724 h = x[m] - x[m - 1];
1725 d = (y[m] - y[m - 1]) / h;
1727 a = (k[m - 1] - d) * (1 - t);
1729 *val = t * y[m] + (1 - t) * y[m - 1] + h * t * (1 - t) * (a - b);
1756 _giraffe_spline_calc_initalize(cxdouble* x, cxdouble* y, cxdouble* k,
1757 cxint n, cxdouble q2b, cxdouble q2e)
1760 register cxint i = 0;
1761 register cxint ip = 0;
1763 register cxdouble* a;
1764 register cxdouble* b;
1765 register cxdouble* c;
1766 register cxdouble* f;
1778 a = (cxdouble*) cx_malloc(4 * n *
sizeof(cxdouble));
1784 for (i = 0; i < n; i++) {
1786 hip = ((ip = i + 1) < n ? x[ip] - x[i] : 0.0);
1787 dip = (ip < n ? (y[ip] - y[i]) / hip : 0.0);
1788 b[i] = (ip < n ? hip : hio);
1789 a[i] = 2.0 * (hip + hio);
1790 c[i] = (i > 0 ? hio : hip);
1791 f[i] = 3.0 * (hip * dio + hio * dip);
1794 f[0] = 3.0 * hip * dip - hip * hip * q2b * 0.5;
1796 else if (i == n - 1) {
1797 f[n - 1] = 3.0 * hio * dio + hio * hio * q2e * 0.5;
1804 _giraffe_spline_calc_tridi(a, b, c, f, k, n);
1831 _giraffe_rebin_interpolate_spline(cpl_matrix* x_1, cpl_matrix* y_1,
1832 cpl_matrix* x_2, cpl_matrix* y_2)
1841 cxdouble* pd_x1 = NULL;
1842 cxdouble* pd_y1 = NULL;
1843 cxdouble* pd_x2 = NULL;
1844 cxdouble* pd_y2 = NULL;
1848 if (x_1 == NULL || y_1 == NULL || x_2 == NULL || y_2 == NULL) {
1852 nr_x1 = cpl_matrix_get_nrow(x_1);
1853 nr_x2 = cpl_matrix_get_nrow(x_2);
1855 pd_x1 = cpl_matrix_get_data(x_1);
1856 pd_y1 = cpl_matrix_get_data(y_1);
1857 pd_y2 = cpl_matrix_get_data(y_2);
1858 pd_x2 = cpl_matrix_get_data(x_2);
1865 k = (cxdouble*) cx_malloc(nr_x1 *
sizeof(cxdouble));
1872 res = _giraffe_spline_calc_initalize(pd_x1, pd_y1, k, nr_x1, 0.0, 0.0);
1883 for (i = 0; i < nr_x2; i++) {
1884 res = _giraffe_spline_calc_interpolate(pd_x2[i], &(pd_y2[i]), pd_x1,
1916 _giraffe_rebin_interpolate_linear(
1928 register cxdouble a, b ;
1929 register cxint i, j, j_1, found, n1;
1933 cxdouble *pd_x1 = NULL,
1942 if (x_1 == NULL) {
return 1; }
1943 if (y_1 == NULL) {
return 1; }
1944 if (x_2 == NULL) {
return 1; }
1945 if (y_2 == NULL) {
return 1; }
1947 nr_x1 = cpl_matrix_get_nrow(x_1);
1948 nr_x2 = cpl_matrix_get_nrow(x_2);
1949 pd_x1 = cpl_matrix_get_data(x_1);
1950 pd_x2 = cpl_matrix_get_data(x_2);
1951 pd_y1 = cpl_matrix_get_data(y_1);
1952 pd_y2 = cpl_matrix_get_data(y_2);
1960 for (i = 0; i < nr_x2; i++) {
1963 for (j = 0; j < n1; j++) {
1964 if ((pd_x2[i] >= pd_x1[j]) && (pd_x2[i] <= pd_x1[j+1])) {
1974 a = (pd_y1[j_1] - pd_y1[j]) / (pd_x1[j_1] - pd_x1[j]);
1975 b = pd_y1[j] - a * pd_x1[j];
1976 pd_y2[i] = (a * pd_x2[i] + b);
2011 _giraffe_rebin_interpolate_linear_error(
2024 register double a, b ,dx;
2025 register int i, j, j_1, found, n1 ;
2029 cxdouble *pd_x1 = NULL,
2040 if (x_1 == NULL) {
return 1; }
2041 if (y_1 == NULL) {
return 1; }
2042 if (y_1err == NULL) {
return 1; }
2043 if (x_2 == NULL) {
return 1; }
2044 if (y_2 == NULL) {
return 1; }
2045 if (y_2err == NULL) {
return 1; }
2047 nr_x1 = cpl_matrix_get_nrow(x_1);
2048 nr_x2 = cpl_matrix_get_nrow(x_2);
2049 pd_x1 = cpl_matrix_get_data(x_1);
2050 pd_y1 = cpl_matrix_get_data(y_1);
2051 pd_y1err = cpl_matrix_get_data(y_1err);
2052 pd_x2 = cpl_matrix_get_data(x_2);
2053 pd_y2 = cpl_matrix_get_data(y_2);
2054 pd_y2err = cpl_matrix_get_data(y_2err);
2062 for (i = 0; i < nr_x2; i++) {
2065 for (j = 0; j < n1; j++) {
2066 if ((pd_x2[i] >= pd_x1[j]) && (pd_x2[i] <= pd_x1[j+1])) {
2078 dx = (pd_x1[j_1] - pd_x1[j]);
2079 a = (pd_y1[j_1] - pd_y1[j]) / dx;
2080 b = pd_y1[j] - a * pd_x1[j] ;
2081 pd_y2[i] = (a * pd_x2[i] + b) ;
2082 a = (pd_y1err[j_1] - pd_y1err[j]) / dx;
2083 b = pd_y1err[j] - a * pd_x1[j] ;
2084 pd_y2err[i] = (a * pd_x2[i] + b) ;
2113 _giraffe_resample_linear(cpl_image* rbspectra, cpl_image* rberrors,
2114 cpl_image* abscissa, cpl_image* exspectra,
2115 cpl_image* exerrors, cxint opt_direction)
2118 const cxchar*
const fctid =
"_giraffe_resample_linear";
2120 register cxlong n = 0;
2128 cxdouble* _mabscissa = NULL;
2129 cxdouble* _mexspectra = NULL;
2130 cxdouble* _mexerrors = NULL;
2131 cxdouble* _mwavelength = NULL;
2132 cxdouble* _mrbspectra = NULL;
2133 cxdouble* _mrberrors = NULL;
2134 cxdouble* _abscissa = NULL;
2135 cxdouble* _exspectra = NULL;
2136 cxdouble* _exerrors = NULL;
2137 cxdouble* _rbspectra = NULL;
2138 cxdouble* _rberrors = NULL;
2140 cpl_matrix* mabscissa = NULL;
2141 cpl_matrix* mwavelength = NULL;
2142 cpl_matrix* mexspectra = NULL;
2143 cpl_matrix* mexerrors = NULL;
2144 cpl_matrix* mrbspectra = NULL;
2145 cpl_matrix* mrberrors = NULL;
2149 if ((abscissa == NULL) || (exspectra == NULL) || (rbspectra == NULL)) {
2153 if ((exerrors != NULL) && (rberrors == NULL)) {
2158 nx = cpl_image_get_size_y(exspectra);
2159 ns = cpl_image_get_size_x(exspectra);
2160 nwl = cpl_image_get_size_y(abscissa);
2162 if ((exerrors != NULL) &&
2163 ((nx != cpl_image_get_size_y(exerrors)) ||
2164 (ns != cpl_image_get_size_x(exerrors)))) {
2170 mabscissa = cpl_matrix_new(nx, 1);
2171 mexspectra = cpl_matrix_new(nx, 1);
2173 mwavelength = cpl_matrix_new(nwl, 1);
2174 mrbspectra = cpl_matrix_new(nwl, 1);
2176 _mabscissa = cpl_matrix_get_data(mabscissa);
2177 _mexspectra = cpl_matrix_get_data(mexspectra);
2178 _mwavelength = cpl_matrix_get_data(mwavelength);
2179 _mrbspectra = cpl_matrix_get_data(mrbspectra);
2181 _abscissa = cpl_image_get_data_double(abscissa);
2182 _exspectra = cpl_image_get_data_double(exspectra);
2183 _rbspectra = cpl_image_get_data_double(rbspectra);
2185 if (exerrors != NULL) {
2186 mexerrors = cpl_matrix_new(nx, 1);
2187 mrberrors = cpl_matrix_new(nwl, 1);
2189 _mexerrors = cpl_matrix_get_data(mexerrors);
2190 _mrberrors = cpl_matrix_get_data(mrberrors);
2192 _exerrors = cpl_image_get_data_double(exerrors);
2193 _rberrors = cpl_image_get_data_double(rberrors);
2203 cpl_msg_debug(fctid,
"Rebinning %d spectra, using dispersion direction "
2204 "%d and linear interpolation", ns, opt_direction);
2206 for (n = 0; n < ns; n++) {
2208 register cxlong x = 0;
2211 for (x = 0; x < nwl; x++) {
2212 register cxlong j = x * ns + n;
2213 _mwavelength[x] = _abscissa[j];
2216 if (exerrors == NULL) {
2218 if (opt_direction < 0) {
2220 for (x = 0; x < nx; x++) {
2222 register cxlong j = x * ns + n;
2223 register cxlong k = nx - x - 1;
2225 _mabscissa[x] = (cxdouble) x;
2226 _mexspectra[k] = _exspectra[j];
2232 for (x = 0; x < nx; x++) {
2234 register cxlong j = x * ns + n;
2236 _mabscissa[x] = (cxdouble) x;
2237 _mexspectra[x] = _exspectra[j];
2248 status = _giraffe_rebin_interpolate_linear(mabscissa,
2253 for (x = 0; x < nwl; x++) {
2255 register cxlong j = x * ns + n;
2257 if ((-0.5 > _mwavelength[x]) || (_mwavelength[x] > nx1)) {
2261 _rbspectra[j] = _mrbspectra[x];
2269 if (opt_direction < 0) {
2271 for (x = 0; x < nx; x++) {
2273 register cxlong j = x * ns + n;
2274 register cxlong k = nx - x - 1;
2276 _mabscissa[x] = (cxdouble) x;
2277 _mexspectra[k] = _exspectra[j];
2278 _mexerrors[k] = _exerrors[j];
2284 for (x = 0; x < nx; x++) {
2286 register cxlong j = x * ns + n;
2288 _mabscissa[x] = (cxdouble) x;
2289 _mexspectra[x] = _exspectra[j];
2290 _mexerrors[x] = _exerrors[j];
2302 _giraffe_rebin_interpolate_linear_error(mabscissa,
2309 for (x = 0; x < nwl; x++) {
2311 register cxlong j = x * ns + n;
2313 if ((-0.5 > _mwavelength[x]) || (_mwavelength[x] > nx1)) {
2318 _rbspectra[j] = _mrbspectra[x];
2319 _rberrors[j] = _mrberrors[x];
2329 cpl_matrix_delete(mrbspectra);
2332 cpl_matrix_delete(mwavelength);
2335 cpl_matrix_delete(mexspectra);
2338 cpl_matrix_delete(mabscissa);
2341 if (exerrors != NULL) {
2342 cpl_matrix_delete(mrberrors);
2345 cpl_matrix_delete(mexerrors);
2349 cpl_msg_debug(fctid,
"Rebinned %d spectra", ns);
2376 _giraffe_resample_spline(cpl_image* rbspectra, cpl_image* rberrors,
2377 cpl_image* abscissa, cpl_image* exspectra,
2378 cpl_image* exerrors, cxint opt_direction)
2381 const cxchar*
const fctid =
"_giraffe_resample_spline";
2383 register cxlong n = 0;
2391 cxdouble* _mabscissa = NULL;
2392 cxdouble* _mexspectra = NULL;
2393 cxdouble* _mexerrors = NULL;
2394 cxdouble* _mwavelength = NULL;
2395 cxdouble* _mrbspectra = NULL;
2396 cxdouble* _mrberrors = NULL;
2397 cxdouble* _abscissa = NULL;
2398 cxdouble* _exspectra = NULL;
2399 cxdouble* _exerrors = NULL;
2400 cxdouble* _rbspectra = NULL;
2401 cxdouble* _rberrors = NULL;
2403 cpl_matrix* mabscissa = NULL;
2404 cpl_matrix* mwavelength = NULL;
2405 cpl_matrix* mexspectra = NULL;
2406 cpl_matrix* mexerrors = NULL;
2407 cpl_matrix* mrbspectra = NULL;
2408 cpl_matrix* mrberrors = NULL;
2412 if ((abscissa == NULL) || (exspectra == NULL) || (rbspectra == NULL)) {
2416 if ((exerrors != NULL) && (rberrors == NULL)) {
2421 nx = cpl_image_get_size_y(exspectra);
2422 ns = cpl_image_get_size_x(exspectra);
2423 nwl = cpl_image_get_size_y(abscissa);
2425 if ((exerrors != NULL) &&
2426 ((nx != cpl_image_get_size_y(exerrors)) ||
2427 (ns != cpl_image_get_size_x(exerrors)))) {
2433 mabscissa = cpl_matrix_new(nx, 1);
2434 mexspectra = cpl_matrix_new(nx, 1);
2436 mwavelength = cpl_matrix_new(nwl, 1);
2437 mrbspectra = cpl_matrix_new(nwl, 1);
2439 _mabscissa = cpl_matrix_get_data(mabscissa);
2440 _mexspectra = cpl_matrix_get_data(mexspectra);
2441 _mwavelength = cpl_matrix_get_data(mwavelength);
2442 _mrbspectra = cpl_matrix_get_data(mrbspectra);
2444 _abscissa = cpl_image_get_data_double(abscissa);
2445 _exspectra = cpl_image_get_data_double(exspectra);
2446 _rbspectra = cpl_image_get_data_double(rbspectra);
2448 if (exerrors != NULL) {
2449 mexerrors = cpl_matrix_new(nx, 1);
2450 mrberrors = cpl_matrix_new(nwl, 1);
2452 _mexerrors = cpl_matrix_get_data(mexerrors);
2453 _mrberrors = cpl_matrix_get_data(mrberrors);
2455 _exerrors = cpl_image_get_data_double(exerrors);
2456 _rberrors = cpl_image_get_data_double(rberrors);
2466 cpl_msg_debug(fctid,
"Rebinning %d spectra, using dispersion direction "
2467 "%d and linear interpolation", ns, opt_direction);
2469 for (n = 0; n < ns; n++) {
2471 register cxlong x = 0;
2474 for (x = 0; x < nwl; x++) {
2475 register cxlong j = x * ns + n;
2476 _mwavelength[x] = _abscissa[j];
2479 if (exerrors == NULL) {
2481 if (opt_direction < 0) {
2483 for (x = 0; x < nx; x++) {
2485 register cxlong j = x * ns + n;
2486 register cxlong k = nx - x - 1;
2488 _mabscissa[x] = (cxdouble) x;
2489 _mexspectra[k] = _exspectra[j];
2495 for (x = 0; x < nx; x++) {
2497 register cxlong j = x * ns + n;
2499 _mabscissa[x] = (cxdouble) x;
2500 _mexspectra[x] = _exspectra[j];
2511 status = _giraffe_rebin_interpolate_spline(mabscissa,
2516 for (x = 0; x < nwl; x++) {
2518 register cxlong j = x * ns + n;
2520 if ((-0.5 > _mwavelength[x]) || (_mwavelength[x] > nx1)) {
2524 _rbspectra[j] = _mrbspectra[x];
2532 if (opt_direction < 0) {
2534 for (x = 0; x < nx; x++) {
2536 register cxlong j = x * ns + n;
2537 register cxlong k = nx - x - 1;
2539 _mabscissa[x] = (cxdouble) x;
2540 _mexspectra[k] = _exspectra[j];
2541 _mexerrors[k] = _exerrors[j];
2547 for (x = 0; x < nx; x++) {
2549 register cxlong j = x * ns + n;
2551 _mabscissa[x] = (cxdouble) x;
2552 _mexspectra[x] = _exspectra[j];
2553 _mexerrors[x] = _exerrors[j];
2565 status = _giraffe_rebin_interpolate_spline(mabscissa,
2570 status = _giraffe_rebin_interpolate_linear(mabscissa,
2575 for (x = 0; x < nwl; x++) {
2577 register cxlong j = x * ns + n;
2579 if ((-0.5 > _mwavelength[x]) || (_mwavelength[x] > nx1)) {
2584 _rbspectra[j] = _mrbspectra[x];
2585 _rberrors[j] = _mrberrors[x];
2595 cpl_matrix_delete(mrbspectra);
2598 cpl_matrix_delete(mwavelength);
2601 cpl_matrix_delete(mexspectra);
2604 cpl_matrix_delete(mabscissa);
2607 if (exerrors != NULL) {
2608 cpl_matrix_delete(mrberrors);
2611 cpl_matrix_delete(mexerrors);
2615 cpl_msg_debug(fctid,
"Rebinned %d spectra", ns);
2696 giraffe_rebin_compute_opt_mod3(cxdouble xccd, cxdouble xfibre,
2697 cxdouble yfibre, cxdouble nx,
2698 cxdouble pixsize, cxdouble fcoll,
2699 cxdouble cfact, cxdouble gtheta,
2700 cxdouble gorder, cxdouble gspace,
2701 cxdouble slitdx, cxdouble slitdy,
2709 cxdouble xf, yf, d, t1, t12, t13, t18, t19, t2, t23, t28,
2710 t3, t31, t32, t36, t37, t39, t4, t40, t5, t62, t8, t9;
2718 xf = xfibre * (1.0 + slitphi * yfibre) + slitdx;
2719 yf = yfibre * sqrt(1.0 - slitphi * slitphi) + slitdy;
2720 d = sqrt(xf * xf + yf * yf + fcoll * fcoll);
2724 t4 = pixsize*pixsize;
2737 t37 = t19+4.0*t5-4.0*t23+t36;
2740 t62 = sqrt((-t31+t32)*t37*(4.0*t40*t3-4.0*xccd*nx*t40 +
2741 8.0*xccd*t1*cfact*t9*pixsize+t19*t39 -
2742 4.0*cfact*fcoll*t8*nx*t1*pixsize+t36 -
2745 return((4.0*t2*t5 + 4.0*t9*t5 + 4.0*t12*t13*fcoll*t8+t2*t19+t9*t19 -
2746 4.0*t9*t23 - 4.0*t2*t23 + 4.0*t28*t2+t62)*gspace/t37/gorder/d);
2775 giraffe_rebin_compute_log_opt_mod3(cxdouble xccd, cxdouble xfibre,
2776 cxdouble yfibre, cxdouble nx,
2777 cxdouble pixsize, cxdouble fcoll,
2778 cxdouble cfact, cxdouble gtheta,
2779 cxdouble gorder, cxdouble gspace,
2780 cxdouble slitdx, cxdouble slitdy,
2784 return log(giraffe_rebin_compute_opt_mod3(xccd, xfibre, yfibre, nx,
2785 pixsize, fcoll, cfact, gtheta,
2786 gorder, gspace, slitdx, slitdy,
2838 giraffe_rebin_compute_lambda_range(GiFiberPosition *fiber_slit_position,
2839 cpl_matrix *opt_mod_params,
2840 cpl_matrix *grat_params,
2841 cxbool lambda_logarithmic,
2842 cxbool wlen_range_common,
2843 cxdouble *lambda_min, cxdouble *lambda_max)
2850 const cxchar *fctid =
"giraffe_rebin_compute_lambda_range";
2852 register cxlong n, ns;
2853 register cxdouble dx2, dnx, wl1, wl2;
2855 double (*computeWl) (double, double, double, double, double, double,
2856 double, double, double, double, double, double,
2859 cxdouble *pd_opt_mod_params = NULL,
2862 *pd_grat_params = NULL;
2870 if (fiber_slit_position ==NULL) {
return 1; }
2871 if (fiber_slit_position->x_fiber==NULL) {
return 1; }
2872 if (fiber_slit_position->y_fiber==NULL) {
return 1; }
2873 if (opt_mod_params ==NULL) {
return 1; }
2874 if (grat_params ==NULL) {
return 1; }
2875 if (lambda_min ==NULL) {
return 1; }
2876 if (lambda_max ==NULL) {
return 1; }
2878 pd_opt_mod_params = cpl_matrix_get_data(opt_mod_params);
2880 pd_xfiber = cpl_matrix_get_data(fiber_slit_position->x_fiber);
2881 nr_xfiber = cpl_matrix_get_nrow(fiber_slit_position->x_fiber);
2887 if (lambda_logarithmic==TRUE) {
2888 computeWl = giraffe_rebin_compute_log_opt_mod3;
2890 computeWl = giraffe_rebin_compute_opt_mod3;
2893 dnx = abs(pd_opt_mod_params[O_NX]);
2897 if (wlen_range_common==TRUE) {
2899 *lambda_max = CX_MAXDOUBLE;
2901 *lambda_min = CX_MAXDOUBLE;
2905 pd_yfiber = cpl_matrix_get_data(fiber_slit_position->y_fiber);
2906 pd_grat_params = cpl_matrix_get_data(grat_params);
2908 for (n = 0; n < ns; n++) {
2917 pd_opt_mod_params[O_PXSIZ],
2918 pd_opt_mod_params[O_FCOLL],
2919 pd_opt_mod_params[O_CFACT],
2920 pd_grat_params[G_THETA],
2921 pd_grat_params[G_ORDER],
2922 pd_grat_params[G_SPACE],
2923 pd_opt_mod_params[O_SOFFX],
2924 pd_opt_mod_params[O_SOFFY],
2925 pd_opt_mod_params[O_SPHI]
2935 pd_opt_mod_params[O_PXSIZ],
2936 pd_opt_mod_params[O_FCOLL],
2937 pd_opt_mod_params[O_CFACT],
2938 pd_grat_params[G_THETA],
2939 pd_grat_params[G_ORDER],
2940 pd_grat_params[G_SPACE],
2941 pd_opt_mod_params[O_SOFFX],
2942 pd_opt_mod_params[O_SOFFY],
2943 pd_opt_mod_params[O_SPHI]
2946 if (wlen_range_common==TRUE) {
2950 if (pd_opt_mod_params[O_NX] < 0) {
2951 *lambda_max = CX_MIN(*lambda_max, wl1);
2952 *lambda_min = CX_MAX(*lambda_min, wl2);
2954 *lambda_max = CX_MIN(*lambda_max, wl2);
2955 *lambda_min = CX_MAX(*lambda_min, wl1);
2962 if (pd_opt_mod_params[O_NX] < 0) {
2963 *lambda_max = CX_MAX(*lambda_max, wl1);
2964 *lambda_min = CX_MIN(*lambda_min, wl2);
2966 *lambda_max = CX_MAX(*lambda_max, wl2);
2967 *lambda_min = CX_MIN(*lambda_min, wl1);
2974 if (wlen_range_common==TRUE) {
2976 *lambda_max = floor((*lambda_max) * GI_MM_TO_NM) / GI_MM_TO_NM;
2977 *lambda_min = ceil( (*lambda_min) * GI_MM_TO_NM) / GI_MM_TO_NM;
2980 *lambda_max = ceil( (*lambda_max) * GI_MM_TO_NM) / GI_MM_TO_NM;
2981 *lambda_min = floor((*lambda_min) * GI_MM_TO_NM) / GI_MM_TO_NM;
2984 cpl_msg_debug(fctid,
"Rebinning lambda range now: [%12.6f,%12.6f]",
2985 *lambda_min, *lambda_max);
3014 giraffe_rebin_compute_pixel_x_residuals(
3015 GiLocPosition *locPos,
3018 GiSlitGeo *xresiduals_limits,
3019 GiSlitGeo *xresiduals_coeff
3026 const cxchar *fctid =
"giraffe_rebin_compute_pixel_x_residuals";
3028 cxdouble xmin, xmax, ymin, ymax, yup, ylo, yccd, ywid;
3029 cxint n, m, x, xx, x0, i, j, k, l, xxp, x0p;
3045 cpl_matrix *xss = NULL,
3048 *curr_xres_limits = NULL,
3049 *curr_xres_coeff = NULL;
3051 cpl_image *x_residuals_img = NULL;
3053 cpl_matrix *curr_subslit = NULL;
3055 cxdouble *pd_curr_subslit = NULL,
3060 cxdouble *pd_locy = NULL,
3064 *pd_x_residuals_img = NULL;
3071 if (locPos ==NULL) {
return NULL; }
3072 if (locPos->centroids ==NULL) {
return NULL; }
3073 if (locPos->widths ==NULL) {
return NULL; }
3074 if (abcissa ==NULL) {
return NULL; }
3075 if (slitGeo ==NULL) {
return NULL; }
3076 if (xresiduals_limits ==NULL) {
return NULL; }
3077 if (xresiduals_coeff ==NULL) {
return NULL; }
3079 nx = cpl_image_get_size_y(locPos->centroids);
3080 ns = cpl_image_get_size_x(locPos->centroids);
3081 nf = cpl_image_get_size_x(abcissa);
3082 nwl = cpl_image_get_size_y(abcissa);
3086 "Computing pixel x residuals, using nr spec/nr lines/orig abcissa "
3097 x_residuals_img = cpl_image_new(nf, nwl, CPL_TYPE_DOUBLE);
3098 pd_x_residuals_img = cpl_image_get_data_double(x_residuals_img);
3099 pd_abcissa = cpl_image_get_data_double(abcissa);
3103 for (subslit = 0; subslit<_giraffe_slitgeo_size(slitGeo); subslit++) {
3105 curr_subslit = _giraffe_slitgeo_get(slitGeo, subslit);
3106 pd_curr_subslit = cpl_matrix_get_data(curr_subslit);
3111 cpl_matrix_duplicate(
3112 _giraffe_slitgeo_get(xresiduals_limits, subslit)
3116 cpl_matrix_duplicate(
3117 _giraffe_slitgeo_get(xresiduals_coeff, subslit)
3121 nfibers = cpl_matrix_get_nrow(curr_subslit);
3123 nmin = (cxint) pd_curr_subslit[0];
3124 nmax = (cxint) pd_curr_subslit[nfibers - 1];
3125 nlen = nmax - nmin + 1;
3126 ndata = nwl * nfibers;
3129 ymin = CX_MAXDOUBLE;
3131 xss = cpl_matrix_new(ndata, 1);
3132 yss = cpl_matrix_new(ndata, 1);
3134 pd_xss = cpl_matrix_get_data(xss);
3135 pd_yss = cpl_matrix_get_data(yss);
3137 pd_locy = cpl_image_get_data_double(locPos->centroids);
3138 pd_locw = cpl_image_get_data_double(locPos->widths);
3143 for (m = 0, n = 0; n < nfibers; n++, m++) {
3147 for (x = 0; x < nwl; x++) {
3149 j = x * nf + (nstart + n);
3150 x0 = (cxint) floor(pd_abcissa[j]);
3151 xx = (cxint) ceil(pd_abcissa[j]);
3153 x0 = CX_MAX(CX_MIN(x0, nx - 1), 0);
3154 xx = CX_MAX(CX_MIN(xx, nx - 1), 0);
3156 l = i * nfibers + m;
3157 xxp = xx * ns + cpl_matrix_get(curr_subslit, n, 0);
3158 x0p = x0 * ns + cpl_matrix_get(curr_subslit, n, 0);
3160 pd_xss[l] = pd_abcissa[j];
3167 yccd = pd_locy[x0p];
3168 pd_yss[l] = yccd + ((pd_locy[xxp] - yccd) * (pd_xss[l] - x0));
3170 ywid = pd_locw[x0p];
3171 ywid = ywid + ((pd_locw[xxp] - ywid) * (pd_xss[l] - x0));
3193 cpl_matrix_set_size(xss, k, 1);
3194 cpl_matrix_set_size(yss, k, 1);
3195 pd_xss = cpl_matrix_get_data(xss);
3196 pd_yss = cpl_matrix_get_data(yss);
3198 xmin = cpl_matrix_get(curr_xres_limits, 0, 0);
3199 xmax = cpl_matrix_get(curr_xres_limits, 0, 1);
3200 ymin = cpl_matrix_get(curr_xres_limits, 0, 2);
3201 ymax = cpl_matrix_get(curr_xres_limits, 0, 3);
3203 xmin = xmin < 0. ? 0. : xmin;
3204 xmax = xmax < 0. ? (cxdouble)nx : xmax;
3206 ymin = ymin < 0. ? 0. : ymin;
3207 ymax = ymax < 0. ? 2048. : ymax;
3211 giraffe_chebyshev_fit2d(
3214 (ymax - ymin + 1.0),
3220 cpl_matrix_delete(yss);
3221 cpl_matrix_delete(xss);
3222 cpl_matrix_delete(curr_xres_coeff);
3223 cpl_matrix_delete(curr_xres_limits);
3226 buffer = cpl_matrix_get_data(fit);
3227 cpl_matrix_unwrap(fit);
3230 fit = cpl_matrix_wrap(nwl, nfibers, buffer);
3231 pd_fit = cpl_matrix_get_data(fit);
3232 nr_fit = cpl_matrix_get_nrow(fit);
3233 nc_fit = cpl_matrix_get_ncol(fit);
3236 for (x = 0; x < nr_fit; x++) {
3237 for (k = nstart, n = 0; n < nc_fit; n++, k++) {
3238 pd_x_residuals_img[x * nf + k] = pd_fit[x * nc_fit + n];
3242 cpl_matrix_delete(fit);
3251 "Computed pixel x residuals, returning image [%d,%d]",
3256 return x_residuals_img;
3294 giraffe_rebin_compute_rebin_abcissa(GiFiberPosition* fiber_slit_position,
3295 GiLocPosition* locPos,
3297 GiSlitGeo* xresiduals_limits,
3298 GiSlitGeo* xresiduals_coeff,
3299 cpl_matrix* grat_params,
3300 cpl_matrix* opt_mod_params,
3301 cpl_matrix* wloffsets,
3303 GiRebinParams binPrms)
3310 const cxchar*
const fctid =
"giraffe_rebin_compute_rebin_abcissa";
3312 cpl_matrix* wlengths = NULL;
3313 cpl_matrix* temp_params = NULL;
3315 cpl_image* abcissa = NULL;
3316 cpl_image* x_residuals_img = NULL;
3318 cxdouble* pd_wlengths = NULL;
3319 cxdouble* pd_temp_params = NULL;
3320 cxdouble* pd_opt_mod_params = NULL;
3321 cxdouble* pd_grat_params = NULL;
3327 if (fiber_slit_position == NULL) {
3331 if (locPos == NULL) {
3335 if (slitGeo == NULL) {
3339 if (grat_params == NULL) {
3343 if (opt_mod_params == NULL) {
3347 wlengths = cpl_matrix_new(binPrms.size, 1);
3348 pd_wlengths = cpl_matrix_get_data(wlengths);
3350 temp_params = cpl_matrix_new(lmrq_opt_mod_x.
nparams, 1);
3352 pd_temp_params = cpl_matrix_get_data(temp_params);
3353 pd_opt_mod_params = cpl_matrix_get_data(opt_mod_params);
3354 pd_grat_params = cpl_matrix_get_data(grat_params);
3356 pd_temp_params[OG_NX] = pd_opt_mod_params[O_NX];
3357 pd_temp_params[OG_PXSIZ] = pd_opt_mod_params[O_PXSIZ];
3358 pd_temp_params[OG_FCOLL] = pd_opt_mod_params[O_FCOLL];
3359 pd_temp_params[OG_CFACT] = pd_opt_mod_params[O_CFACT];
3360 pd_temp_params[OG_THETA] = pd_grat_params[G_THETA];
3361 pd_temp_params[OG_ORDER] = pd_grat_params[G_ORDER];
3362 pd_temp_params[OG_SPACE] = pd_grat_params[G_SPACE];
3364 if (lmrq_opt_mod_x.
nparams > OG_SOFFX) {
3365 pd_temp_params[OG_SOFFX] = pd_opt_mod_params[O_SOFFX];
3366 pd_temp_params[OG_SOFFY] = pd_opt_mod_params[O_SOFFY];
3367 pd_temp_params[OG_SPHI] = pd_opt_mod_params[O_SPHI];
3378 if (binPrms.log==TRUE) {
3381 for (i = 0; i < binPrms.size; i++) {
3382 pd_wlengths[i] = exp(binPrms.min + (cxdouble) i * binPrms.step);
3386 for (i = 0; i < binPrms.size; i++) {
3387 pd_wlengths[i] = binPrms.min + (cxdouble) i * binPrms.step;
3391 abcissa = _giraffe_compute_pixel_abscissa(wlengths, wloffsets,
3392 fiber_slit_position,
3393 temp_params, lmrq_opt_mod_x);
3401 if ((binPrms.xres==TRUE) && (xresiduals_coeff!=NULL)) {
3404 giraffe_rebin_compute_pixel_x_residuals(
3412 cpl_image_subtract(abcissa, x_residuals_img);
3413 cpl_image_delete(x_residuals_img);
3417 cpl_matrix_delete(wlengths);
3418 cpl_matrix_delete(temp_params);
3420 cpl_msg_debug(fctid,
"Processing complete : returning image "
3421 "[%" CPL_SIZE_FORMAT
", %" CPL_SIZE_FORMAT
"]",
3422 cpl_image_get_size_x(abcissa), cpl_image_get_size_y(abcissa));
3456 _giraffe_resample_spectra(GiRebinning* result,
3457 const GiExtraction* extraction,
3458 const GiLocalization* localization,
3459 GiFiberPosition* fiber_position,
3460 GiSlitGeo* subslits,
3461 GiSlitGeo* xres_limits,
3462 GiSlitGeo* xres_coeff,
3463 GiBinnParams* xres_order,
3464 cpl_matrix* grating_data,
3465 cpl_matrix* optical_model,
3466 cpl_matrix* wlen_offsets,
3468 GiRebinMethod method,
3473 const cxchar*
const fctid =
"_giraffe_resample_spectra";
3476 cxbool log_scale = FALSE;
3484 cxdouble wlmin = 0.;
3485 cxdouble wlmax = 0.;
3486 cxdouble* _optical_model = NULL;
3488 cpl_matrix* wavelengths = NULL;
3490 cpl_image* _exspectra = NULL;
3491 cpl_image* _exerrors = NULL;
3492 cpl_image* _rbspectra = NULL;
3493 cpl_image* _rberrors = NULL;
3494 cpl_image* abscissa = NULL;
3496 cpl_propertylist* properties = NULL;
3498 GiImage* rbspectra = NULL;
3499 GiImage* rberrors = NULL;
3501 GiLocPosition locPos;
3503 GiRebinParams binPrms;
3513 lmrq_model_id opt_mod_id = LMRQ_XOPTMOD2;
3516 if (result == NULL || extraction == NULL || localization == NULL) {
3520 if (result->spectra != NULL || result->errors != NULL) {
3524 if (extraction->spectra == NULL) {
3528 if (localization->locy == NULL || localization->locw == NULL) {
3532 if (fiber_position == NULL) {
3536 if (subslits == NULL) {
3540 if (grating_data == NULL) {
3544 if (optical_model == NULL) {
3549 if (xres_coeff != NULL) {
3550 if (xres_limits == NULL || xres_order == NULL) {
3563 if (extraction->error != NULL) {
3567 _optical_model = cpl_matrix_get_data(optical_model);
3569 nspectra = cpl_image_get_size_x(_exspectra);
3571 om_sign = (_optical_model[O_NX] >= 0) ? 1 : -1;
3573 if (scale == GIREBIN_SCALE_LOG) {
3582 if (range == GIREBIN_RANGE_SETUP) {
3588 wlmin = cpl_matrix_get(grating_data, 2, 0);
3589 wlmax = cpl_matrix_get(grating_data, 4, 0);
3591 if (log_scale == TRUE) {
3603 status = giraffe_rebin_compute_lambda_range(fiber_position,
3605 grating_data, log_scale,
3606 TRUE, &wlmin, &wlmax);
3610 rbsize = 1 + (cxint) ((wlmax - wlmin) / rbstep);
3614 cpl_msg_debug(fctid,
"Invalid dispersion direction [%d], changing "
3615 "optical model orientation", om_sign);
3618 _optical_model[O_NX] = -_optical_model[O_NX];
3620 status = giraffe_rebin_compute_lambda_range(fiber_position,
3622 grating_data, log_scale,
3623 TRUE, &wlmin, &wlmax);
3625 rbsize = 1 + (cxint) ((wlmax - wlmin) / rbstep);
3630 cpl_msg_error(fctid,
"Invalid size %d of rebinned spectra, "
3631 "aborting...", rbsize);
3644 binPrms.min = wlmin;
3645 binPrms.step = rbstep;
3646 binPrms.size = rbsize;
3647 binPrms.log = log_scale;
3649 if (xres_coeff == NULL || (xres_order->xdeg == 0 &&
3650 xres_order->ydeg == 0)) {
3651 binPrms.xres = FALSE;
3654 binPrms.xres = TRUE;
3657 abscissa = giraffe_rebin_compute_rebin_abcissa(fiber_position, &locPos,
3658 subslits, xres_limits,
3659 xres_coeff, grating_data,
3660 optical_model, wlen_offsets,
3661 lmrq_models[opt_mod_id],
3669 wavelengths = cpl_matrix_new(rbsize, 1);
3671 for (i = 0; i < rbsize; i++) {
3672 cpl_matrix_set(wavelengths, i, 0, wlmin + (cxdouble) i * rbstep);
3678 if (_exerrors != NULL) {
3684 case GIREBIN_METHOD_LINEAR:
3685 status = _giraffe_resample_linear(_rbspectra, _rberrors, abscissa,
3686 _exspectra, _exerrors, om_sign);
3689 case GIREBIN_METHOD_SPLINE:
3690 status = _giraffe_resample_spline(_rbspectra, _rberrors, abscissa,
3691 _exspectra, _exerrors, om_sign);
3698 gi_error(
"Invalid rebinning method!");
3702 cpl_image_delete(abscissa);
3706 cpl_msg_error(fctid,
"Error during rebinning, aborting...");
3708 cpl_matrix_delete(wavelengths);
3714 if (rberrors != NULL) {
3729 case GIREBIN_SCALE_LOG:
3731 cxsize nw = cpl_matrix_get_nrow(wavelengths);
3733 cxdouble mm2nm = log(GI_MM_TO_NM);
3735 setup.wmin = mm2nm + cpl_matrix_get(wavelengths, 0, 0);
3736 setup.wcenter = mm2nm + cpl_matrix_get(wavelengths, nw / 2, 0);
3737 setup.wmax = mm2nm + cpl_matrix_get(wavelengths, nw - 1, 0);
3738 setup.wstep = rbstep;
3740 setup.units =
"log(nm)";
3745 case GIREBIN_SCALE_LINEAR:
3747 cxsize nw = cpl_matrix_get_nrow(wavelengths);
3749 setup.wmin = GI_MM_TO_NM * cpl_matrix_get(wavelengths, 0, 0);
3750 setup.wcenter = GI_MM_TO_NM * cpl_matrix_get(wavelengths,
3752 setup.wmax = GI_MM_TO_NM * cpl_matrix_get(wavelengths,
3754 setup.wstep = GI_MM_TO_NM * rbstep;
3765 gi_error(
"Invalid scaling option!");
3769 cpl_matrix_delete(wavelengths);
3774 case GIREBIN_METHOD_LINEAR:
3775 setup.method =
"linear";
3778 case GIREBIN_METHOD_SPLINE:
3779 setup.method =
"spline";
3786 gi_error(
"Invalid rebinning method!");
3792 case GIREBIN_SCALE_LINEAR:
3793 setup.scale =
"linear";
3796 case GIREBIN_SCALE_LOG:
3797 setup.scale =
"logarithmic";
3804 gi_error(
"Invalid scaling option!");
3809 case GIREBIN_RANGE_SETUP:
3810 setup.range =
"setup";
3813 case GIREBIN_RANGE_COMMON:
3814 setup.range =
"common";
3830 giraffe_error_push();
3835 if (cpl_error_get_code() != CPL_ERROR_NONE) {
3839 if (rberrors != NULL) {
3847 giraffe_error_pop();
3849 status = _giraffe_resample_update_properties(rbspectra, &setup);
3855 if (rberrors != NULL) {
3868 if (_rberrors != NULL) {
3870 giraffe_error_push();
3875 if (cpl_error_get_code() != CPL_ERROR_NONE) {
3879 if (rberrors != NULL) {
3887 giraffe_error_pop();
3889 status = _giraffe_resample_update_properties(rberrors, &setup);
3895 if (rberrors != NULL) {
3905 result->spectra = rbspectra;
3906 result->errors = rberrors;
3922 GiTable *grating, GiTable *slitgeometry,
3931 cpl_matrix *optical_model = NULL;
3932 cpl_matrix *grating_data = NULL;
3934 GiFiberPosition *positions = NULL;
3935 GiSlitGeo *subslits = NULL;
3937 GiWcalSolution *wcal = NULL;
3939 GiRange *range = NULL;
3942 if (spectra == NULL) {
3946 if (grating == NULL) {
3950 if (slitgeometry == NULL) {
3955 wcal = _giraffe_wcalsolution_create(wlsolution);
3961 optical_model = _giraffe_rebin_setup_model(spectra, wcal);
3963 if (optical_model == NULL) {
3964 _giraffe_wcalsolution_delete(wcal);
3968 _giraffe_wcalsolution_delete(wcal);
3970 grating_data = _giraffe_rebin_setup_grating(spectra, grating,
3973 if (grating_data == NULL) {
3975 cpl_matrix_delete(grating_data);
3976 cpl_matrix_delete(optical_model);
3982 positions = _giraffe_fiberposition_new();
3983 subslits = _giraffe_slitgeo_new();
3985 status = _giraffe_slitgeo_setup(slitgeometry, positions, subslits,
3990 _giraffe_slitgeo_delete(subslits);
3991 _giraffe_fiberposition_delete(positions);
3993 cpl_matrix_delete(grating_data);
3994 cpl_matrix_delete(optical_model);
4000 status = giraffe_rebin_compute_lambda_range(positions, optical_model,
4002 GIREBIN_SCALE_LINEAR,
4003 common, &min, &max);
4012 _giraffe_slitgeo_delete(subslits);
4013 _giraffe_fiberposition_delete(positions);
4015 cpl_matrix_delete(grating_data);
4016 cpl_matrix_delete(optical_model);
4060 const GiExtraction *extraction,
4061 const GiTable *fibers,
4062 const GiLocalization *localization,
4063 const GiTable *grating,
4064 const GiTable *slitgeo,
4065 const GiTable *solution,
4066 const GiRebinConfig *config)
4069 const cxchar*
const fctid =
"giraffe_rebin_spectra";
4073 cxint ex_sp_extr_pixels = 0;
4074 cxint calc_rebinned_size = 0;
4075 cxint default_rebinned_size = GIREBIN_SIZE_Y_DEFAULT;
4077 cxdouble rbin_multiplier = 0.;
4078 cxdouble ex_sp_pixsize_x = 0.;
4079 cxdouble rbin_stepsize = 0.;
4081 cpl_matrix* grat_params = NULL;
4082 cpl_matrix* opt_mod_params = NULL;
4083 cpl_matrix* wloffsets = NULL;
4085 cpl_table* _fibers = NULL;
4087 cpl_propertylist* _pl_ext_sp = NULL;
4088 cpl_propertylist* _pl_wsol = NULL;
4090 GiImage* ex_sp_frame = NULL;
4091 GiImage* ex_sp_err_frame = NULL;
4092 GiImage* loc_y_frame = NULL;
4093 GiImage* loc_w_frame = NULL;
4095 GiSlitGeo* subslit_fibers = NULL;
4096 GiSlitGeo* wav_coeffs = NULL;
4097 GiSlitGeo* wav_limits = NULL;
4099 GiGrat* grating_data = NULL;
4101 GiFiberPosition* fiber_slit_position = NULL;
4103 GiWcalSolution* wcalib_solution = NULL;
4105 GiBinnParams xres_polynom_deg = {0, 0};
4113 if (extraction == NULL) {
4114 cpl_msg_error(fctid,
"No extracted data, aborting...");
4118 if (extraction->spectra == NULL) {
4119 cpl_msg_error(fctid,
"No extracted spectra, aborting...");
4123 if (fibers == NULL) {
4124 cpl_msg_error(fctid,
"No fiber table, aborting ...");
4128 if (localization == NULL) {
4129 cpl_msg_error(fctid,
"No localization data, aborting...");
4133 if (localization->locy == NULL) {
4134 cpl_msg_error(fctid,
"No localization centroids, aborting...");
4138 if (localization->locw == NULL) {
4139 cpl_msg_error(fctid,
"No localization widths, aborting...");
4143 if (grating == NULL) {
4144 cpl_msg_error(fctid,
"No grating data, aborting...");
4148 if (rebinning == NULL) {
4149 cpl_msg_error(fctid,
"No rebinning results container, aborting...");
4153 if (config == NULL) {
4154 cpl_msg_error(fctid,
"No rebinning configuration data, aborting...");
4158 if (solution == NULL) {
4159 cpl_msg_error(fctid,
"No wavecalibration solution, aborting...");
4163 ex_sp_frame = extraction->spectra;
4164 ex_sp_err_frame = extraction->error;
4165 loc_y_frame = localization->locy;
4166 loc_w_frame = localization->locw;
4173 cx_assert(_fibers != NULL);
4185 if (cpl_propertylist_has(_pl_ext_sp, GIALIAS_PIXSIZX) == TRUE) {
4186 ex_sp_pixsize_x = cpl_propertylist_get_double(_pl_ext_sp,
4191 cpl_msg_error(fctid,
"%s Keyword missing in Extracted Spectra "
4192 "Frame, aborting ...", GIALIAS_PIXSIZX);
4201 if (ex_sp_pixsize_x > 1.) {
4202 ex_sp_pixsize_x /= 1000.;
4210 if (cpl_propertylist_has(_pl_ext_sp, GIALIAS_GRATNAME) == TRUE) {
4212 const cxchar* _string = NULL;
4214 _string = cpl_propertylist_get_string(_pl_ext_sp, GIALIAS_GRATNAME);
4216 if (strncmp(_string,
"LR", 2) == 0) {
4217 rbin_multiplier = 4.;
4219 else if (strncmp(_string,
"HR", 2) == 0) {
4220 rbin_multiplier = 1.;
4223 rbin_multiplier = 1.;
4228 cpl_msg_error(fctid,
"%s Keyword missing in Extracted Spectra Frame, "
4229 "aborting ...", GIALIAS_GRATNAME);
4238 if (cpl_propertylist_has(_pl_ext_sp, GIALIAS_EXT_NX) == TRUE) {
4239 ex_sp_extr_pixels = cpl_propertylist_get_int(_pl_ext_sp,
4244 cpl_msg_error(fctid,
"%s Keyword missing in Extracted Spectra Frame, "
4245 "aborting ...", GIALIAS_EXT_NX);
4254 grating_data = _giraffe_grating_new();
4256 status = _giraffe_grating_setup(grating, ex_sp_frame, grating_data);
4259 cpl_msg_error(fctid,
"Unable to retrieve grating information, "
4261 _giraffe_grating_delete(grating_data);
4269 fiber_slit_position = _giraffe_fiberposition_new();
4270 subslit_fibers = _giraffe_slitgeo_new();
4272 status = _giraffe_slitgeo_setup(slitgeo, fiber_slit_position,
4273 subslit_fibers, FALSE);
4276 cpl_msg_error(fctid,
"Unable to retrieve slit geometry information, "
4278 _giraffe_grating_delete(grating_data);
4279 _giraffe_fiberposition_delete(fiber_slit_position);
4280 _giraffe_slitgeo_delete(subslit_fibers);
4285 wcalib_solution = _giraffe_wcalsolution_create(solution);
4287 if (wcalib_solution == NULL) {
4288 cpl_msg_error(fctid,
"Cannot create wavelength solution, "
4290 _giraffe_grating_delete(grating_data);
4291 _giraffe_fiberposition_delete(fiber_slit_position);
4292 _giraffe_slitgeo_delete(subslit_fibers);
4296 if (cpl_propertylist_has(_pl_wsol, GIALIAS_WSOL_OMFCOLL) == TRUE) {
4297 grating_data->fcoll =
4298 cpl_propertylist_get_double(_pl_wsol, GIALIAS_WSOL_OMFCOLL);
4301 if (cpl_propertylist_has(_pl_wsol, GIALIAS_WSOL_OMGCAM) == TRUE) {
4302 grating_data->gcam =
4303 cpl_propertylist_get_double(_pl_wsol, GIALIAS_WSOL_OMGCAM);
4306 if (cpl_propertylist_has(_pl_wsol, GIALIAS_WSOL_OMGTHETA) == TRUE) {
4307 grating_data->theta =
4308 cpl_propertylist_get_double(_pl_wsol, GIALIAS_WSOL_OMGTHETA);
4311 if (cpl_propertylist_has(_pl_wsol, GIALIAS_WSOL_OMSDX) == TRUE) {
4312 grating_data->slitdx =
4313 cpl_propertylist_get_double(_pl_wsol, GIALIAS_WSOL_OMSDX);
4316 if (cpl_propertylist_has(_pl_wsol, GIALIAS_WSOL_OMSDY) == TRUE) {
4317 grating_data->slitdy =
4318 cpl_propertylist_get_double(_pl_wsol, GIALIAS_WSOL_OMSDY);
4321 if (cpl_propertylist_has(_pl_wsol, GIALIAS_WSOL_OMSPHI) == TRUE) {
4322 grating_data->slitphi =
4323 cpl_propertylist_get_double(_pl_wsol, GIALIAS_WSOL_OMSPHI);
4333 if (cpl_table_has_column(_fibers,
"WLRES") != 0) {
4336 cxint nfibers = cpl_table_get_nrow(_fibers);
4339 wloffsets = cpl_matrix_new(nfibers, 1);
4341 for (fiber = 0; fiber < nfibers; ++fiber) {
4343 cxdouble wloffset = cpl_table_get_double(_fibers,
"WLRES",
4347 wloffset *= -GI_NM_TO_MM;
4348 cpl_matrix_set(wloffsets, fiber, 0, wloffset);
4352 cpl_msg_info(fctid,
"Applying SIMCAL wavelength corrections ...");
4367 if (config->scmethod == GIREBIN_SCALE_LOG) {
4374 rebin_size = default_rebinned_size;
4376 wlenmin = log(grating_data->wlenmin / GI_MM_TO_NM);
4377 wlenmax = log(grating_data->wlenmax / GI_MM_TO_NM);
4379 if ((config->size != rebin_size) && (config->size != 0)) {
4380 rebin_size = config->size;
4383 rbin_stepsize = (wlenmax - wlenmin) / rebin_size;
4385 calc_rebinned_size = 1 + (cxint) ((wlenmax-wlenmin)/ rbin_stepsize);
4395 wlenmin = grating_data->wlenmin / GI_MM_TO_NM;
4396 wlenmax = grating_data->wlenmax / GI_MM_TO_NM;
4398 rbin_stepsize = (config->lstep / GI_MM_TO_NM) * rbin_multiplier;
4399 rebin_size = (wlenmax - wlenmin) / rbin_stepsize;
4401 if ((config->size != rebin_size) && (config->size != 0)) {
4402 rebin_size = config->size;
4403 rbin_stepsize = (wlenmax - wlenmin) / rebin_size;
4406 calc_rebinned_size = 1 + (cxint) ((wlenmax-wlenmin) / rbin_stepsize);
4414 if (wcalib_solution!=NULL) {
4416 if (wcalib_solution->opt_mod==LMRQ_XOPTMOD) {
4419 cxdouble opt_direction, fcoll, cfact;
4421 nrow = cpl_matrix_get_nrow(wcalib_solution->opt_mod_params);
4424 cpl_matrix_get(wcalib_solution->opt_mod_params, 0, 0);
4426 cpl_matrix_get(wcalib_solution->opt_mod_params, 1, 0);
4428 cpl_matrix_get(wcalib_solution->opt_mod_params, 2, 0);
4430 opt_mod_params = cpl_matrix_new(4,1);
4431 cpl_matrix_set(opt_mod_params, 0, 0,
4432 ex_sp_extr_pixels * opt_direction);
4433 cpl_matrix_set(opt_mod_params, 1, 0, ex_sp_pixsize_x);
4434 cpl_matrix_set(opt_mod_params, 2, 0, fcoll);
4435 cpl_matrix_set(opt_mod_params, 3, 0, cfact);
4438 cpl_msg_error(fctid,
"Invalid number of physical optical "
4439 "parameters, aborting...");
4441 if (wloffsets != NULL) {
4442 cpl_matrix_delete(wloffsets);
4445 _giraffe_wcalsolution_delete(wcalib_solution);
4446 _giraffe_grating_delete(grating_data);
4447 _giraffe_fiberposition_delete(fiber_slit_position);
4448 _giraffe_slitgeo_delete(subslit_fibers);
4453 else if (wcalib_solution->opt_mod==LMRQ_XOPTMOD2) {
4456 cxdouble opt_direction, fcoll, cfact, gtheta, slitdx,
4459 nrow = cpl_matrix_get_nrow(wcalib_solution->opt_mod_params);
4462 cpl_matrix_get(wcalib_solution->opt_mod_params, 0, 0);
4464 cpl_matrix_get(wcalib_solution->opt_mod_params, 1, 0);
4466 cpl_matrix_get(wcalib_solution->opt_mod_params, 2, 0);
4468 cpl_matrix_get(wcalib_solution->opt_mod_params, 3, 0);
4470 cpl_matrix_get(wcalib_solution->opt_mod_params, 4, 0);
4472 cpl_matrix_get(wcalib_solution->opt_mod_params, 5, 0);
4474 cpl_matrix_get(wcalib_solution->opt_mod_params, 6, 0);
4476 opt_mod_params = cpl_matrix_new(7,1);
4477 cpl_matrix_set(opt_mod_params, 0, 0,
4478 ex_sp_extr_pixels * opt_direction);
4479 cpl_matrix_set(opt_mod_params, 1, 0, ex_sp_pixsize_x);
4480 cpl_matrix_set(opt_mod_params, 2, 0, fcoll);
4481 cpl_matrix_set(opt_mod_params, 3, 0, cfact);
4482 cpl_matrix_set(opt_mod_params, 4, 0, slitdx);
4483 cpl_matrix_set(opt_mod_params, 5, 0, slitdy);
4484 cpl_matrix_set(opt_mod_params, 6, 0, slitphi);
4488 cpl_msg_error(fctid,
"Invalid number of physical optical "
4489 "parameters, aborting...");
4491 if (wloffsets != NULL) {
4492 cpl_matrix_delete(wloffsets);
4495 _giraffe_wcalsolution_delete(wcalib_solution);
4496 _giraffe_grating_delete(grating_data);
4497 _giraffe_fiberposition_delete(fiber_slit_position);
4498 _giraffe_slitgeo_delete(subslit_fibers);
4504 cpl_msg_error(fctid,
"Invalid optical model, aborting...");
4506 if (wloffsets != NULL) {
4507 cpl_matrix_delete(wloffsets);
4510 _giraffe_wcalsolution_delete(wcalib_solution);
4511 _giraffe_grating_delete(grating_data);
4512 _giraffe_fiberposition_delete(fiber_slit_position);
4513 _giraffe_slitgeo_delete(subslit_fibers);
4518 if (wcalib_solution->wav_coeffs != NULL) {
4520 GiSlitGeo* coeffs = wcalib_solution->wav_coeffs;
4522 xres_polynom_deg.xdeg =
4523 cpl_matrix_get_nrow(_giraffe_slitgeo_get(coeffs, 0));
4524 xres_polynom_deg.ydeg =
4525 cpl_matrix_get_ncol(_giraffe_slitgeo_get(coeffs, 0));
4530 cpl_msg_error(fctid,
"No Wavelength Calibration solution found, "
4533 if (wloffsets != NULL) {
4534 cpl_matrix_delete(wloffsets);
4537 _giraffe_wcalsolution_delete(wcalib_solution);
4538 _giraffe_grating_delete(grating_data);
4539 _giraffe_fiberposition_delete(fiber_slit_position);
4540 _giraffe_slitgeo_delete(subslit_fibers);
4544 if (config->xresiduals==FALSE) {
4545 xres_polynom_deg.xdeg = 0;
4546 xres_polynom_deg.ydeg = 0;
4549 if (wcalib_solution->wav_coeffs!=NULL) {
4550 wav_coeffs = wcalib_solution->wav_coeffs;
4553 if (wcalib_solution->wav_limits!=NULL) {
4554 wav_limits = wcalib_solution->wav_limits;
4562 grat_params = cpl_matrix_new(7,1);
4564 cpl_matrix_set(grat_params, 0, 0, grating_data->theta);
4565 cpl_matrix_set(grat_params, 1, 0, grating_data->order);
4566 cpl_matrix_set(grat_params, 2, 0, grating_data->wlenmin / GI_MM_TO_NM);
4567 cpl_matrix_set(grat_params, 3, 0, grating_data->wlen0 / GI_MM_TO_NM);
4568 cpl_matrix_set(grat_params, 4, 0, grating_data->wlenmax / GI_MM_TO_NM);
4569 cpl_matrix_set(grat_params, 5, 0, grating_data->resol);
4570 cpl_matrix_set(grat_params, 6, 0, grating_data->space );
4577 cpl_msg_info(fctid,
"Performing Rebinning of spectra, stepsize=%.4f "
4578 "[nm], resulting image size=%d, using x residuals : %s",
4579 rbin_stepsize * GI_MM_TO_NM, calc_rebinned_size,
4580 config->xresiduals ?
"Yes" :
"No");
4583 switch (config->rmethod) {
4584 case GIREBIN_METHOD_LINEAR:
4585 cpl_msg_info(fctid,
"Rebinning method : linear");
4588 case GIREBIN_METHOD_SPLINE:
4589 cpl_msg_info(fctid,
"Rebinning method : spline");
4593 cpl_msg_info(fctid,
"Rebinning method : undefined");
4597 switch (config->scmethod) {
4598 case GIREBIN_SCALE_LOG:
4599 cpl_msg_info(fctid,
"Scaling method : logarithmic, "
4600 "log(wavelength [nm]): min,max,range = %.3f, %.3f, %.3f",
4601 log(grating_data->wlenmin),
4602 log(grating_data->wlenmax),
4603 log(grating_data->wlenmax) -
4604 log(grating_data->wlenmin));
4607 case GIREBIN_SCALE_LINEAR:
4608 cpl_msg_info(fctid,
"Scaling method : linear, wavelength [nm]: "
4609 "min,max,range = %.3f, %.3f, %.3f",
4610 grating_data->wlenmin,
4611 grating_data->wlenmax,
4612 grating_data->wlenmax - grating_data->wlenmin);
4616 cpl_msg_info(fctid,
"Scaling method : undefined");
4620 switch (config->range) {
4621 case GIREBIN_RANGE_SETUP:
4622 cpl_msg_info(fctid,
"Wavelength range : Setup");
4625 case GIREBIN_RANGE_COMMON:
4626 cpl_msg_info(fctid,
"Wavelength range : Common");
4630 cpl_msg_info(fctid,
"Wavelength range : undefined");
4639 status = _giraffe_resample_spectra(rebinning, extraction,
4640 localization, fiber_slit_position,
4641 subslit_fibers, wav_limits,
4642 wav_coeffs, &xres_polynom_deg,
4643 grat_params, opt_mod_params,
4644 wloffsets, rbin_stepsize,
4645 config->rmethod, config->range,
4650 if (wloffsets != NULL) {
4651 cpl_matrix_delete(wloffsets);
4654 cpl_matrix_delete(opt_mod_params);
4655 cpl_matrix_delete(grat_params);
4657 _giraffe_wcalsolution_delete(wcalib_solution);
4658 _giraffe_grating_delete(grating_data);
4659 _giraffe_fiberposition_delete(fiber_slit_position);
4660 _giraffe_slitgeo_delete(subslit_fibers);
4671 if (wloffsets != NULL) {
4672 cpl_matrix_delete(wloffsets);
4675 cpl_matrix_delete(opt_mod_params);
4676 cpl_matrix_delete(grat_params);
4678 _giraffe_wcalsolution_delete(wcalib_solution);
4679 _giraffe_grating_delete(grating_data);
4680 _giraffe_fiberposition_delete(fiber_slit_position);
4681 _giraffe_slitgeo_delete(subslit_fibers);
4704 GiRebinning *rebinn = cx_malloc(
sizeof(GiRebinning));
4706 rebinn->spectra = NULL;
4707 rebinn->errors = NULL;
4736 rebin->spectra = spectra;
4740 rebin->errors = errors;
4800 if (rebinning->spectra) {
4802 rebinning->spectra = NULL;
4805 if (rebinning->errors) {
4807 rebinning->errors = NULL;
4836 const cxchar *fctid =
"giraffe_rebin_config_create";
4842 GiRebinConfig *config = NULL;
4849 config = cx_calloc(1,
sizeof *config);
4852 config->rmethod = GIREBIN_METHOD_UNDEFINED;
4853 config->xresiduals = FALSE;
4854 config->lstep = 0.0;
4855 config->scmethod = GIREBIN_SCALE_UNDEFINED;
4857 config->range = GIREBIN_RANGE_UNDEFINED;
4860 p = cpl_parameterlist_find(list,
"giraffe.rebinning.method");
4861 s = cpl_parameter_get_string(p);
4862 if (strcmp(s,
"linear")==0) {
4863 config->rmethod = GIREBIN_METHOD_LINEAR;
4864 }
else if (strcmp(s,
"spline")==0) {
4865 config->rmethod = GIREBIN_METHOD_SPLINE;
4868 p = cpl_parameterlist_find(list,
"giraffe.rebinning.xresiduals");
4869 config->xresiduals = cpl_parameter_get_bool(p);
4871 p = cpl_parameterlist_find(list,
"giraffe.rebinning.lstep");
4872 config->lstep = cpl_parameter_get_double(p);
4874 p = cpl_parameterlist_find(list,
"giraffe.rebinning.scalemethod");
4875 s = cpl_parameter_get_string(p);
4876 if (strcmp(s,
"log")==0) {
4877 config->scmethod = GIREBIN_SCALE_LOG;
4878 }
else if (strcmp(s,
"linear")==0) {
4879 config->scmethod = GIREBIN_SCALE_LINEAR;
4882 p = cpl_parameterlist_find(list,
"giraffe.rebinning.size");
4883 config->size = cpl_parameter_get_int(p);
4885 p = cpl_parameterlist_find(list,
"giraffe.rebinning.range");
4886 s = cpl_parameter_get_string(p);
4887 if (strcmp(s,
"setup")==0) {
4888 config->range = GIREBIN_RANGE_SETUP;
4889 }
else if (strcmp(s,
"common")==0) {
4890 config->range = GIREBIN_RANGE_COMMON;
4895 if (config->rmethod==GIREBIN_METHOD_UNDEFINED) {
4896 cpl_msg_info(fctid,
"Invalid Rebinning method, aborting");
4901 if (config->scmethod==GIREBIN_SCALE_UNDEFINED) {
4902 cpl_msg_info(fctid,
"Invalid Rebinning scaling method, aborting");
4907 if (config->range==GIREBIN_RANGE_UNDEFINED) {
4908 cpl_msg_info(fctid,
"Invalid Rebinning range, aborting");
4966 p = cpl_parameter_new_enum(
"giraffe.rebinning.method",
4968 "Method to use : `linear' or `spline'",
4969 "giraffe.rebinning.method",
4970 "linear", 2,
"linear",
"spline");
4971 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"rbin-method");
4972 cpl_parameterlist_append(list, p);
4974 p = cpl_parameter_new_value(
"giraffe.rebinning.xresiduals",
4976 "Use x residuals during rebinning? `true'/"
4978 "giraffe.rebinning.xresiduals",
4980 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"rbin-xresid");
4981 cpl_parameterlist_append(list, p);
4983 p = cpl_parameter_new_value(
"giraffe.rebinning.lstep",
4985 "Lambda step size, only used if "
4986 "scaling method is 'linear'",
4987 "giraffe.rebinning.lstep",
4989 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"rbin-lstep");
4990 cpl_parameterlist_append(list, p);
4992 p = cpl_parameter_new_enum(
"giraffe.rebinning.scalemethod",
4994 "Scaling method: `log' or `linear'",
4995 "giraffe.rebinning.scalemethod",
4996 "linear", 2,
"linear",
"log");
4997 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"rbin-scmethod");
4998 cpl_parameterlist_append(list, p);
5000 p = cpl_parameter_new_value(
"giraffe.rebinning.size",
5002 "Size of output rebinned spectra, 0 means "
5003 "calculate size based on wavelength range "
5004 "and lambda stepsize",
5005 "giraffe.rebinning.size",
5007 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"rbin-size");
5008 cpl_parameterlist_append(list, p);
5010 p = cpl_parameter_new_enum(
"giraffe.rebinning.range",
5012 "Rebinning range: `setup' or `common'",
5013 "giraffe.rebinning.scalemethod",
5014 "setup", 2,
"setup",
"common");
5015 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"rbin-range");
5016 cpl_parameterlist_append(list, p);