30#include "kmclipm_constants.h"
31#include "kmclipm_functions.h"
33#include "kmo_cpl_extensions.h"
38#include "kmo_priv_copy.h"
41static int kmo_copy_create(cpl_plugin *);
42static int kmo_copy_exec(cpl_plugin *);
43static int kmo_copy_destroy(cpl_plugin *);
44static int kmo_copy(cpl_parameterlist *, cpl_frameset *);
46static char kmo_copy_description[] =
47"With this recipe a specified region of an IFU-based cube (F3I), image (F2I) or\n"
48"vector (F1I) can be copied to a new FITS file. One can copy just a plane out\n"
49"of a cube (any orientation) or a vector out of an image etc. By default the\n"
50"operation applies to all IFUs. The input data can contain noise frames which\n"
51"is then copied in the same manner as the input data.\n"
52"It is also possible to extract a specific IFU out of a KMOS FITS structure\n"
53"with 24 IFU extensions or 48 extensions if noise is present.\n"
58"Use this parameter to apply the operation to a specific IFU.\n"
63"These are the start values in each dimension. The first pixel is adressed "
69"These are the extents in each dimension to copy.\n"
72"If set to TRUE all borders containing NaN values are cropped. Vectors will be\n"
73"shortened, images and cubes can get smaller. In This special case following\n"
74"parameters can be omitted: --x, --y, --z, --xsize, --ysize and --zsize.\n"
78"extract a cube-section of a cube: \n"
79"esorex kmo_copy --x=3 --y=2 --z=1 --xsize=2 --ysize=3 --zsize=6 copy.sof\n"
82"esorex kmo_copy --x=3 --y=2 --z=1 --xsize=2 --ysize=3 copy.sof\n"
84"extract vector just of IFU 4:\n"
85"esorex kmo_copy --x=3 --y=2 --z=1 --ysize=3 --ifu=4 copy.sof\n"
87"extract whole IFU 4:\n"
88"esorex kmo_copy --x=1 --y=1 --z=1 --xsize=<NAXIS1> --ysize=<NAXIS2> \n"
89" --zsize=<NAXIS3> --ifu=4 copy.sof\n"
92"esorex kmo_copy --x=3 --y=2 --z=1 copy.sof\n"
97"-------------------------------------------------------------------------------\n"
101" category Type Explanation Required #Frames\n"
102" -------- ----- ----------- -------- -------\n"
103" <none or any> F3I Data cube Y 1 \n"
105" <none or any> F2I Image \n"
107" <none or any> F1I Vector \n"
108" (All inputs with or \n"
109" without noise frame) \n"
114" category Type Explanation\n"
115" -------- ----- -----------\n"
116" COPY F3I or Cropped input data\n"
119"-------------------------------------------------------------------------------\n"
140 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
141 cpl_plugin *plugin = &recipe->interface;
143 cpl_plugin_init(plugin,
146 CPL_PLUGIN_TYPE_RECIPE,
148 "Copy a section of a cube to another cube, "
150 kmo_copy_description,
152 "https://support.eso.org/",
158 cpl_pluginlist_append(list, plugin);
170static int kmo_copy_create(cpl_plugin *plugin)
176 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
177 recipe = (cpl_recipe *)plugin;
182 recipe->parameters = cpl_parameterlist_new();
187 p = cpl_parameter_new_value(
"kmos.kmo_copy.ifu",
189 "Specific IFU to process",
192 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ifu");
193 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
194 cpl_parameterlist_append(recipe->parameters, p);
197 p = cpl_parameter_new_value(
"kmos.kmo_copy.autocrop",
199 "Crop automatically NaN values at borders",
202 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"autocrop");
203 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
204 cpl_parameterlist_append(recipe->parameters, p);
207 p = cpl_parameter_new_value(
"kmos.kmo_copy.x",
209 "Start value in first dimension (pixels).",
212 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"x");
213 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
214 cpl_parameterlist_append(recipe->parameters, p);
216 p = cpl_parameter_new_value(
"kmos.kmo_copy.y",
218 "Start value in second dimension (pixels).",
221 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"y");
222 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
223 cpl_parameterlist_append(recipe->parameters, p);
225 p = cpl_parameter_new_value(
"kmos.kmo_copy.z",
227 "Start value in third dimension (pixels).",
230 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"z");
231 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
232 cpl_parameterlist_append(recipe->parameters, p);
235 p = cpl_parameter_new_value(
"kmos.kmo_copy.xsize",
237 "Length in first dimension (pixels).",
240 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"xsize");
241 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
242 cpl_parameterlist_append(recipe->parameters, p);
244 p = cpl_parameter_new_value(
"kmos.kmo_copy.ysize",
246 "Length in second dimension (pixels).",
249 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ysize");
250 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
251 cpl_parameterlist_append(recipe->parameters, p);
253 p = cpl_parameter_new_value(
"kmos.kmo_copy.zsize",
255 "Length in third dimension (pixels).",
258 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"zsize");
259 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
260 cpl_parameterlist_append(recipe->parameters, p);
270static int kmo_copy_exec(cpl_plugin *plugin)
275 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
276 recipe = (cpl_recipe *)plugin;
279 return kmo_copy(recipe->parameters, recipe->frames);
287static int kmo_copy_destroy(cpl_plugin *plugin)
292 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
293 recipe = (cpl_recipe *)plugin;
296 cpl_parameterlist_delete(recipe->parameters);
314static int kmo_copy(cpl_parameterlist *parlist, cpl_frameset *frameset)
350 cpl_matrix *phys = NULL,
352 cpl_array *status = NULL;
353 cpl_propertylist *sub_header = NULL;
354 cpl_imagelist *imglist = NULL,
356 cpl_image *img = NULL,
358 kmclipm_vector *vec = NULL,
360 cpl_frame *frame = NULL;
365 kmo_init_fits_desc(&desc);
368 KMO_TRY_ASSURE((parlist != NULL) &&
370 CPL_ERROR_NULL_INPUT,
371 "Not all input data is provided!");
373 KMO_TRY_ASSURE(cpl_frameset_get_size(frameset) == 1,
374 CPL_ERROR_NULL_INPUT,
375 "A fits-file must be provided!");
377 KMO_TRY_EXIT_IF_NULL(
378 frame = kmo_dfs_get_frame(frameset,
"0"));
380 desc = kmo_identify_fits_header(
381 cpl_frame_get_filename(frame));
382 KMO_TRY_CHECK_ERROR_STATE_MSG(
"Provided fits file doesn't seem to be "
385 KMO_TRY_ASSURE((desc.fits_type == f1i_fits) ||
386 (desc.fits_type == f2i_fits) ||
387 (desc.fits_type == f3i_fits),
388 CPL_ERROR_ILLEGAL_INPUT,
389 "Input data hasn't correct data type "
390 "(KMOSTYPE must be F1I, F2I or F3I)!");
392 KMO_TRY_ASSURE(kmo_dfs_set_groups(frameset) == 1,
393 CPL_ERROR_ILLEGAL_INPUT,
394 "Cannot identify RAW and CALIB frames!");
397 cpl_msg_info(
"",
"--- Parameter setup for kmo_copy ----------");
399 ifu = kmo_dfs_get_parameter_int(parlist,
"kmos.kmo_copy.ifu");
400 KMO_TRY_ASSURE((ifu == -1) ||
402 CPL_ERROR_ILLEGAL_INPUT,
403 "ifu is out of range!");
406 for (i = 0; i < desc.nr_ext; i++) {
407 if (ifu == desc.sub_desc[i].device_nr) {
411 KMO_TRY_ASSURE(ix == TRUE,
412 CPL_ERROR_ILLEGAL_INPUT,
413 "ifu #%d doesn't exist in this frame!", ifu);
416 KMO_TRY_EXIT_IF_ERROR(
417 kmo_dfs_print_parameter_help(parlist,
"kmos.kmo_copy.ifu"));
419 autocrop = kmo_dfs_get_parameter_bool(parlist,
"kmos.kmo_copy.autocrop");
420 KMO_TRY_ASSURE((autocrop == TRUE) || (autocrop == FALSE),
421 CPL_ERROR_ILLEGAL_INPUT,
422 "autocrop must be TZRUE or FALSE!");
423 KMO_TRY_EXIT_IF_ERROR(
424 kmo_dfs_print_parameter_help(parlist,
"kmos.kmo_copy.autocrop"));
428 x1 = kmo_dfs_get_parameter_int(parlist,
"kmos.kmo_copy.x");
430 KMO_TRY_ASSURE(x1 > 0,
431 CPL_ERROR_ILLEGAL_INPUT,
432 "x is smaller than 1!");
434 KMO_TRY_ASSURE(x1 <= desc.naxis1,
435 CPL_ERROR_ILLEGAL_INPUT,
436 "x is larger than corresponding dimension of "
438 KMO_TRY_EXIT_IF_ERROR(
439 kmo_dfs_print_parameter_help(parlist,
"kmos.kmo_copy.x"));
441 if ((desc.fits_type == f2i_fits) || (desc.fits_type == f3i_fits)) {
442 y1 = kmo_dfs_get_parameter_int(parlist,
"kmos.kmo_copy.y");
444 KMO_TRY_ASSURE(y1 > 0,
445 CPL_ERROR_ILLEGAL_INPUT,
446 "y is smaller than 1!");
448 KMO_TRY_ASSURE(y1 <= desc.naxis2,
449 CPL_ERROR_ILLEGAL_INPUT,
450 "y is larger than corresponding dimension of "
452 KMO_TRY_EXIT_IF_ERROR(
453 kmo_dfs_print_parameter_help(parlist,
"kmos.kmo_copy.y"));
455 if (desc.fits_type == f3i_fits) {
456 z1 = kmo_dfs_get_parameter_int(parlist,
"kmos.kmo_copy.z");
458 KMO_TRY_ASSURE(z1 > 0,
459 CPL_ERROR_ILLEGAL_INPUT,
460 "z is smaller than 1!");
462 KMO_TRY_ASSURE(z1 <= desc.naxis3,
463 CPL_ERROR_ILLEGAL_INPUT,
464 "z is larger than corresponding dimension of "
466 KMO_TRY_EXIT_IF_ERROR(
467 kmo_dfs_print_parameter_help(parlist,
"kmos.kmo_copy.z"));
472 xsize = kmo_dfs_get_parameter_int(parlist,
"kmos.kmo_copy.xsize");
474 KMO_TRY_ASSURE(xsize > 0,
475 CPL_ERROR_ILLEGAL_INPUT,
476 "xsize is smaller than 1!");
477 KMO_TRY_EXIT_IF_ERROR(
478 kmo_dfs_print_parameter_help(parlist,
"kmos.kmo_copy.xsize"));
482 KMO_TRY_ASSURE(x2 > 0,
483 CPL_ERROR_ILLEGAL_INPUT,
484 "End value in 1st dimension smaller than 0!");
486 KMO_TRY_ASSURE(x2 <= desc.naxis1,
487 CPL_ERROR_ILLEGAL_INPUT,
488 "xsize is too large (xsize <= %d)",
489 desc.naxis1 - x1 + 1);
491 if ((desc.fits_type == f2i_fits) || (desc.fits_type == f3i_fits)) {
492 ysize = kmo_dfs_get_parameter_int(parlist,
"kmos.kmo_copy.ysize");
494 KMO_TRY_ASSURE(ysize > 0,
495 CPL_ERROR_ILLEGAL_INPUT,
496 "ysize is smaller than 1!");
497 KMO_TRY_EXIT_IF_ERROR(
498 kmo_dfs_print_parameter_help(parlist,
"kmos.kmo_copy.ysize"));
502 KMO_TRY_ASSURE(y2 > 0,
503 CPL_ERROR_ILLEGAL_INPUT,
504 "End value in 2nd dimension smaller than 0!");
506 KMO_TRY_ASSURE(y2 <= desc.naxis2,
507 CPL_ERROR_ILLEGAL_INPUT,
508 "ysize is too large (ysize <= %d)",
509 desc.naxis2 - y1 + 1);
511 if (desc.fits_type == f3i_fits) {
512 zsize = kmo_dfs_get_parameter_int(parlist,
513 "kmos.kmo_copy.zsize");
515 KMO_TRY_ASSURE(zsize > 0,
516 CPL_ERROR_ILLEGAL_INPUT,
517 "zsize is smaller than 1!");
519 KMO_TRY_EXIT_IF_ERROR(
520 kmo_dfs_print_parameter_help(parlist,
"kmos.kmo_copy.zsize"));
524 KMO_TRY_ASSURE(z2 > 0,
525 CPL_ERROR_ILLEGAL_INPUT,
526 "End value in 3rd dimension smaller than 0!");
528 KMO_TRY_ASSURE(z2 <= desc.naxis3,
529 CPL_ERROR_ILLEGAL_INPUT,
530 "zsize is too large (zsize <= %d)",
531 desc.naxis3 - z1 + 1);
534 KMO_TRY_CHECK_ERROR_STATE();
537 cpl_msg_info(
"",
"-------------------------------------------");
540 KMO_TRY_EXIT_IF_ERROR(
541 kmo_dfs_save_main_header(frameset, COPY,
"", frame, NULL, parlist, cpl_func));
546 for (i = 0; i < desc.nr_ext; i++) {
547 if ((ifu == desc.sub_desc[i].device_nr) ||
550 KMO_TRY_EXIT_IF_NULL(
551 sub_header = kmo_dfs_load_sub_header(frameset,
553 desc.sub_desc[i].device_nr,
554 desc.sub_desc[i].is_noise));
559 if (desc.sub_desc[i].valid_data == TRUE) {
561 switch (desc.fits_type) {
563 KMO_TRY_EXIT_IF_NULL(
564 vec = kmo_dfs_load_vector(frameset,
566 desc.sub_desc[i].device_nr,
567 desc.sub_desc[i].is_noise));
569 if (autocrop && !desc.sub_desc[i].is_noise) {
571 x2 = kmclipm_vector_get_size(vec);
572 while (kmclipm_vector_is_rejected(vec, x1-1)) {
575 while (kmclipm_vector_is_rejected(vec, x2-1)) {
581 KMO_TRY_EXIT_IF_ERROR(
582 kmo_dfs_save_sub_header(COPY,
"",
589 if ((x1 == x2) || (x2 == INT_MIN))
591 KMO_TRY_EXIT_IF_NULL(
592 res_vec = kmclipm_vector_new(1));
594 KMO_TRY_EXIT_IF_ERROR(
595 kmclipm_vector_set(res_vec, 0,
596 kmo_copy_scalar_F1I(vec, x1)));
599 else if ((x2!= INT_MIN) && (x1 != x2))
601 KMO_TRY_EXIT_IF_NULL(
602 res_vec = kmo_copy_vector_F1I(vec, x1, x2));
605 kmclipm_vector_delete(vec); vec = NULL;
609 KMO_TRY_EXIT_IF_NULL(
610 img = kmo_dfs_load_image(frameset,
612 desc.sub_desc[i].device_nr,
613 desc.sub_desc[i].is_noise, FALSE, NULL));
615 if (autocrop && !desc.sub_desc[i].is_noise) {
616 nx = cpl_image_get_size_x(img);
617 ny = cpl_image_get_size_y(img);
623 KMO_TRY_EXIT_IF_NULL(
624 pimg = cpl_image_get_data_float(img));
628 for (iy = 0; iy < ny; iy++) {
629 if(!isnan(pimg[x1-1+iy*nx])) {
641 for (iy = 0; iy < ny; iy++) {
642 if(!isnan(pimg[x2-1+iy*nx])) {
654 for (ix = 0; ix < nx; ix++) {
655 if(!isnan(pimg[ix+(y1-1)*nx])) {
667 for (ix = 0; ix < nx; ix++) {
668 if(!isnan(pimg[ix+(y2-1)*nx])) {
678 if ((x1 > x2) || (y1 > y2)) {
680 KMO_TRY_EXIT_IF_ERROR(
681 kmo_dfs_save_sub_header(COPY,
"",
688 if (((x1 == x2) || (x2 == INT_MIN)) &&
689 ((y1 == y2) || (y2 == INT_MIN)))
691 KMO_TRY_EXIT_IF_NULL(
692 res_vec = kmclipm_vector_new(1));
694 KMO_TRY_EXIT_IF_ERROR(
695 kmclipm_vector_set(res_vec, 0,
696 kmo_copy_scalar_F2I(img, x1, y1)));
699 else if (((y1 == y2) || (y2 == INT_MIN)) &&
703 KMO_TRY_EXIT_IF_NULL(
704 res_vec = kmo_copy_vector_F2I_x(img,
708 else if (((x1 == x2) || (x2 == INT_MIN)) &&
712 KMO_TRY_EXIT_IF_NULL(
713 res_vec = kmo_copy_vector_F2I_y(img,
717 else if ((x2 != INT_MIN) && (x1 != x2) &&
718 (y2 != INT_MIN) && (y1 != y2))
720 KMO_TRY_EXIT_IF_NULL(
721 res_img = kmo_copy_image_F2I(img,
725 cpl_image_delete(img); img = NULL;
729 KMO_TRY_EXIT_IF_NULL(
730 imglist = kmo_dfs_load_cube(frameset,
732 desc.sub_desc[i].device_nr,
733 desc.sub_desc[i].is_noise));
735 if (autocrop && !desc.sub_desc[i].is_noise) {
736 img = cpl_imagelist_get(imglist, 0);
737 nx = cpl_image_get_size_x(img);
738 ny = cpl_image_get_size_y(img);
739 nz = cpl_imagelist_get_size(imglist);
747 while (kmo_image_get_rejected(img) == nx*ny) {
749 img = cpl_imagelist_get(imglist, z1-1);
752 img = cpl_imagelist_get(imglist, z2-1);
753 while (kmo_image_get_rejected(img) == nx*ny) {
755 img = cpl_imagelist_get(imglist, z2-1);
760 for (iz = z1-1; iz < z2; iz++) {
761 img = cpl_imagelist_get(imglist, iz);
762 KMO_TRY_EXIT_IF_NULL(
763 pimg = cpl_image_get_data_float(img));
764 if (allNaN == FALSE) {
767 for (iy = 0; iy < ny; iy++) {
768 if(!isnan(pimg[x1-1+iy*nx])) {
781 for (iz = z1-1; iz < z2; iz++) {
782 img = cpl_imagelist_get(imglist, iz);
783 KMO_TRY_EXIT_IF_NULL(
784 pimg = cpl_image_get_data_float(img));
785 if (allNaN == FALSE) {
788 for (iy = 0; iy < ny; iy++) {
789 if(!isnan(pimg[x2-1+iy*nx])) {
802 for (iz = z1-1; iz < z2; iz++) {
803 img = cpl_imagelist_get(imglist, iz);
804 KMO_TRY_EXIT_IF_NULL(
805 pimg = cpl_image_get_data_float(img));
806 if (allNaN == FALSE) {
809 for (ix = 0; ix < nx; ix++) {
810 if(!isnan(pimg[ix+(y1-1)*nx])) {
823 for (iz = z1-1; iz < z2; iz++) {
824 img = cpl_imagelist_get(imglist, iz);
825 KMO_TRY_EXIT_IF_NULL(
826 pimg = cpl_image_get_data_float(img));
827 if (allNaN == FALSE) {
830 for (ix = 0; ix < nx; ix++) {
831 if(!isnan(pimg[ix+(y2-1)*nx])) {
844 if ((x1 > x2) || (y1 > y2) || (z1 > z2)) {
846 KMO_TRY_EXIT_IF_ERROR(
847 kmo_dfs_save_sub_header(COPY,
"",
854 if (((x1 == x2) || (x2 == INT_MIN)) &&
855 ((y1 == y2) || (y2 == INT_MIN)) &&
856 ((z1 == z2) || (z2 == INT_MIN)))
858 KMO_TRY_EXIT_IF_NULL(
859 res_vec = kmclipm_vector_new(1));
861 KMO_TRY_EXIT_IF_ERROR(
862 kmclipm_vector_set(res_vec, 0,
863 kmo_copy_scalar_F3I(imglist, x1, y1, z1)));
866 else if ((x2 != INT_MIN) && (x1 != x2) &&
867 ((y1 == y2) || (y2 == INT_MIN)) &&
868 ((z1 == z2) || (z2 == INT_MIN)))
870 KMO_TRY_EXIT_IF_NULL(
871 res_vec = kmo_copy_vector_F3I_x(imglist,
875 else if (((x1 == x2) || (x2 == INT_MIN)) &&
876 (y2!= INT_MIN) && (y1 != y2) &&
877 ((z1 == z2) || (z2 == INT_MIN)))
879 KMO_TRY_EXIT_IF_NULL(
880 res_vec = kmo_copy_vector_F3I_y(imglist,
884 else if (((x1 == x2) || (x2 == INT_MIN)) &&
885 ((y1 == y2) || (y2 == INT_MIN)) &&
886 (z2 != INT_MIN) && (z1 != z2))
888 KMO_TRY_EXIT_IF_NULL(
889 res_vec = kmo_copy_vector_F3I_z(imglist,
893 else if (((x1 == x2) || (x2 == INT_MIN)) &&
894 (y2 != INT_MIN) && (y1 != y2) &&
895 (z2 != INT_MIN) && (z1 != z2))
897 KMO_TRY_EXIT_IF_NULL(
898 res_img = kmo_copy_image_F3I_x(imglist,
899 x1, y1, y2, z1, z2));
902 else if ((x2 != INT_MIN) && (x1 != x2) &&
903 ((y1 == y2) || (y2 == INT_MIN)) &&
904 (z2 != INT_MIN) && (z1 != z2))
906 KMO_TRY_EXIT_IF_NULL(
907 res_img = kmo_copy_image_F3I_y(imglist,
908 x1, x2, y1, z1, z2));
911 else if ((x2 != INT_MIN) && (x1 != x2) &&
912 (y2 != INT_MIN) && (y1 != y2) &&
913 ((z1 == z2) || (z2 == INT_MIN)))
915 KMO_TRY_EXIT_IF_NULL(
916 res_img = kmo_copy_image_F3I_z(imglist,
917 x1, x2, y1, y2, z1));
920 else if ((x2!= INT_MIN) && (x1 != x2) &&
921 (y2!= INT_MIN) && (y1 != y2) &&
922 (z2!= INT_MIN) && (z1 != z2))
924 KMO_TRY_EXIT_IF_NULL(
925 res_imglist = kmo_copy_cube_F3I(imglist,
926 x1, x2, y1, y2, z1, z2));
929 cpl_imagelist_delete(imglist); imglist = NULL;
939 if (res_vec != NULL) {
940 KMO_TRY_EXIT_IF_ERROR(
941 kmclipm_update_property_double(sub_header,
944 "[pix] Reference pixel in x"));
945 KMO_TRY_EXIT_IF_ERROR(
946 kmclipm_update_property_double(sub_header,
949 "[um] Wavelength at ref. pixel"));
950 KMO_TRY_EXIT_IF_ERROR(
951 kmclipm_update_property_double(sub_header,
954 "[um] Spectral resolution"));
955 if (cpl_propertylist_has(sub_header, CUNIT1)) {
956 KMO_TRY_EXIT_IF_ERROR(
957 kmclipm_update_property_string(
964 KMO_TRY_EXIT_IF_ERROR(
965 kmclipm_update_property_string(
969 "Coordinate system of x-axis"));
973 if ((desc.fits_type == f3i_fits) &&
974 (cpl_propertylist_has(sub_header, CRPIX3)) &&
975 (cpl_propertylist_has(sub_header, CRVAL3)) &&
976 ((x1 == x2) && (y1 == y2)))
978 crpix3 = cpl_propertylist_get_double(sub_header,
980 crval3 = cpl_propertylist_get_double(sub_header,
982 cdelt3 = cpl_propertylist_get_double(sub_header,
984 KMO_TRY_CHECK_ERROR_STATE();
990 crpix3 = crpix3 - z1 + 1;
993 KMO_TRY_EXIT_IF_ERROR(
994 kmclipm_update_property_double(sub_header,
997 "[pix] Reference pixel in x"));
998 KMO_TRY_EXIT_IF_ERROR(
999 kmclipm_update_property_double(sub_header,
1002 "[um] Wavelength at ref. pixel"));
1003 KMO_TRY_EXIT_IF_ERROR(
1004 kmclipm_update_property_double(sub_header,
1007 "[um] Spectral resolution"));
1008 if (cpl_propertylist_has(sub_header, CUNIT3)) {
1009 KMO_TRY_EXIT_IF_ERROR(
1010 kmclipm_update_property_string(
1013 cpl_propertylist_get_string(sub_header,
1015 cpl_propertylist_get_comment(sub_header,
1019 KMO_TRY_EXIT_IF_ERROR(
1020 kmclipm_update_property_string(
1023 cpl_propertylist_get_string(
1026 "Coordinate system of x-axis"));
1028 if (cpl_propertylist_has(sub_header, CRPIX2))
1029 cpl_propertylist_erase(sub_header, CRPIX2);
1030 if (cpl_propertylist_has(sub_header, CRVAL2))
1031 cpl_propertylist_erase(sub_header, CRVAL2);
1032 if (cpl_propertylist_has(sub_header, CDELT2))
1033 cpl_propertylist_erase(sub_header, CDELT2);
1034 if (cpl_propertylist_has(sub_header, CTYPE2))
1035 cpl_propertylist_erase(sub_header, CTYPE2);
1036 if (cpl_propertylist_has(sub_header, CUNIT2))
1037 cpl_propertylist_erase(sub_header, CUNIT2);
1038 if (cpl_propertylist_has(sub_header, CRPIX3))
1039 cpl_propertylist_erase(sub_header, CRPIX3);
1040 if (cpl_propertylist_has(sub_header, CRVAL3))
1041 cpl_propertylist_erase(sub_header, CRVAL3);
1042 if (cpl_propertylist_has(sub_header, CDELT3))
1043 cpl_propertylist_erase(sub_header, CDELT3);
1044 if (cpl_propertylist_has(sub_header, CTYPE3))
1045 cpl_propertylist_erase(sub_header, CTYPE3);
1046 if (cpl_propertylist_has(sub_header, CUNIT3))
1047 cpl_propertylist_erase(sub_header, CUNIT3);
1048 if (cpl_propertylist_has(sub_header, CD1_1))
1049 cpl_propertylist_erase(sub_header, CD1_1);
1050 if (cpl_propertylist_has(sub_header, CD1_2))
1051 cpl_propertylist_erase(sub_header, CD1_2);
1052 if (cpl_propertylist_has(sub_header, CD1_3))
1053 cpl_propertylist_erase(sub_header, CD1_3);
1054 if (cpl_propertylist_has(sub_header, CD2_1))
1055 cpl_propertylist_erase(sub_header, CD2_1);
1056 if (cpl_propertylist_has(sub_header, CD2_2))
1057 cpl_propertylist_erase(sub_header, CD2_2);
1058 if (cpl_propertylist_has(sub_header, CD2_3))
1059 cpl_propertylist_erase(sub_header, CD2_3);
1060 if (cpl_propertylist_has(sub_header, CD3_1))
1061 cpl_propertylist_erase(sub_header, CD3_1);
1062 if (cpl_propertylist_has(sub_header, CD3_2))
1063 cpl_propertylist_erase(sub_header, CD3_2);
1064 if (cpl_propertylist_has(sub_header, CD3_3))
1065 cpl_propertylist_erase(sub_header, CD3_3);
1066 KMO_TRY_EXIT_IF_ERROR(
1067 kmo_dfs_save_vector(res_vec, COPY,
"",
1068 sub_header, 0./0.));
1070 kmclipm_vector_delete(res_vec); res_vec = NULL;
1071 }
else if (res_img != NULL) {
1074 if ((desc.fits_type == f3i_fits) &&
1075 (cpl_propertylist_has(sub_header, CRPIX3)) &&
1076 (cpl_propertylist_has(sub_header, CRVAL3)) &&
1077 ((x1 == x2) || (y1 == y2)))
1079 crpix3 = cpl_propertylist_get_double(sub_header,
1081 crval3 = cpl_propertylist_get_double(sub_header,
1083 cdelt3 = cpl_propertylist_get_double(sub_header,
1085 KMO_TRY_CHECK_ERROR_STATE();
1091 crpix3 = crpix3 - z1 + 1;
1094 KMO_TRY_EXIT_IF_ERROR(
1095 kmclipm_update_property_double(sub_header,
1098 "[pix] Reference pixel in x"));
1099 KMO_TRY_EXIT_IF_ERROR(
1100 kmclipm_update_property_double(sub_header,
1103 "[pix] Reference pixel in y"));
1104 KMO_TRY_EXIT_IF_ERROR(
1105 kmclipm_update_property_double(sub_header,
1108 "[um] Wavelength at ref. pixel"));
1109 KMO_TRY_EXIT_IF_ERROR(
1110 kmclipm_update_property_double(sub_header,
1114 KMO_TRY_EXIT_IF_ERROR(
1115 kmclipm_update_property_double(sub_header,
1118 "[um] Spectral resolution"));
1119 KMO_TRY_EXIT_IF_ERROR(
1120 kmclipm_update_property_double(sub_header,
1124 if (cpl_propertylist_has(sub_header, CUNIT3)) {
1125 KMO_TRY_EXIT_IF_ERROR(
1126 kmclipm_update_property_string(
1129 cpl_propertylist_get_string(sub_header,
1131 cpl_propertylist_get_comment(sub_header,
1135 KMO_TRY_EXIT_IF_ERROR(
1136 kmclipm_update_property_string(
1139 cpl_propertylist_get_string(
1142 "Coordinate system of x-axis"));
1144 KMO_TRY_EXIT_IF_ERROR(
1145 kmclipm_update_property_string(
1149 "Coordinate system of y-axis"));
1150 if (cpl_propertylist_has(sub_header, CD1_1))
1151 cpl_propertylist_erase(sub_header, CD1_1);
1152 if (cpl_propertylist_has(sub_header, CD1_2))
1153 cpl_propertylist_erase(sub_header, CD1_2);
1154 if (cpl_propertylist_has(sub_header, CD2_1))
1155 cpl_propertylist_erase(sub_header, CD2_1);
1156 if (cpl_propertylist_has(sub_header, CD2_2))
1157 cpl_propertylist_erase(sub_header, CD2_2);
1161 if (cpl_propertylist_has(sub_header, CRPIX3))
1162 cpl_propertylist_erase(sub_header, CRPIX3);
1163 if (cpl_propertylist_has(sub_header, CRVAL3))
1164 cpl_propertylist_erase(sub_header, CRVAL3);
1165 if (cpl_propertylist_has(sub_header, CDELT3))
1166 cpl_propertylist_erase(sub_header, CDELT3);
1167 if (cpl_propertylist_has(sub_header, CTYPE3))
1168 cpl_propertylist_erase(sub_header, CTYPE3);
1169 if (cpl_propertylist_has(sub_header, CUNIT3))
1170 cpl_propertylist_erase(sub_header, CUNIT3);
1171 if (cpl_propertylist_has(sub_header, CD1_3))
1172 cpl_propertylist_erase(sub_header, CD1_3);
1173 if (cpl_propertylist_has(sub_header, CD2_3))
1174 cpl_propertylist_erase(sub_header, CD2_3);
1175 if (cpl_propertylist_has(sub_header, CD3_1))
1176 cpl_propertylist_erase(sub_header, CD3_1);
1177 if (cpl_propertylist_has(sub_header, CD3_2))
1178 cpl_propertylist_erase(sub_header, CD3_2);
1179 if (cpl_propertylist_has(sub_header, CD3_3))
1180 cpl_propertylist_erase(sub_header, CD3_3);
1184 if ((desc.fits_type == f3i_fits) &&
1185 (desc.fits_type == f2i_fits) &&
1186 (cpl_propertylist_has(sub_header, CRPIX1)) &&
1187 (cpl_propertylist_has(sub_header, CRPIX2)) &&
1188 ((x1 != 1) || (y1 != 1)))
1190 KMO_TRY_EXIT_IF_ERROR(
1191 kmclipm_update_property_int(sub_header,
1195 cpl_propertylist_erase(sub_header, NAXIS3);
1197 crpix1 = cpl_propertylist_get_double(sub_header,
1199 crpix2 = cpl_propertylist_get_double(sub_header,
1201 KMO_TRY_CHECK_ERROR_STATE();
1203 KMO_TRY_CHECK_ERROR_STATE();
1208 crpix1_new = crpix1 - xshift;
1209 crpix2_new = crpix2 - yshift;
1211 phys = cpl_matrix_new (2, 2);
1212 cpl_matrix_set(phys, 0, 0, crpix1);
1213 cpl_matrix_set(phys, 0, 1, crpix2);
1214 cpl_matrix_set(phys, 1, 0, crpix1_new);
1215 cpl_matrix_set(phys, 1, 1, crpix2_new);
1217 KMO_TRY_EXIT_IF_NULL(
1218 wcs = cpl_wcs_new_from_propertylist(sub_header));
1220 KMO_TRY_EXIT_IF_ERROR(
1221 cpl_wcs_convert(wcs, phys, &world, &status,
1222 CPL_WCS_PHYS2WORLD));
1224 crval1_new = cpl_matrix_get(world, 1, 0);
1225 crval2_new = cpl_matrix_get(world, 1, 1);
1226 crpix1_new = crpix1-2*xshift;
1227 crpix2_new = crpix2-2*yshift;
1230 KMO_TRY_EXIT_IF_ERROR(
1231 kmclipm_update_property_double(sub_header,
1234 "[pix] Reference pixel in x"));
1235 KMO_TRY_EXIT_IF_ERROR(
1236 kmclipm_update_property_double(sub_header,
1239 "[pix] Reference pixel in y"));
1240 KMO_TRY_EXIT_IF_ERROR(
1241 kmclipm_update_property_double(sub_header,
1244 "[deg] RA at ref. pixel"));
1245 KMO_TRY_EXIT_IF_ERROR(
1246 kmclipm_update_property_double(sub_header,
1249 "[deg] DEC at ref. pixel"));
1251 cpl_matrix_delete(phys); phys = NULL;
1252 cpl_matrix_delete(world); world = NULL;
1253 cpl_array_delete(status); status = NULL;
1254 cpl_wcs_delete(wcs); wcs = NULL;
1257 KMO_TRY_EXIT_IF_ERROR(
1258 kmo_dfs_save_image(res_img, COPY,
"", sub_header, 0./0.));
1259 cpl_image_delete(res_img); res_img = NULL;
1260 }
else if (res_imglist != NULL) {
1262 if ((desc.fits_type == f3i_fits) &&
1263 (cpl_propertylist_has(sub_header, CRPIX1)) &&
1264 (cpl_propertylist_has(sub_header, CRPIX2)) &&
1265 ((x1 != 1) || (y1 != 1)))
1267 crpix1 = cpl_propertylist_get_double(sub_header,
1269 crpix2 = cpl_propertylist_get_double(sub_header,
1271 crpix3 = cpl_propertylist_get_double(sub_header,
1273 KMO_TRY_CHECK_ERROR_STATE();
1278 crpix1_new = crpix1 - xshift;
1279 crpix2_new = crpix2 - yshift;
1281 phys = cpl_matrix_new (2, 3);
1282 cpl_matrix_set(phys, 0, 0, crpix1);
1283 cpl_matrix_set(phys, 0, 1, crpix2);
1284 cpl_matrix_set(phys, 0, 2, crpix3);
1285 cpl_matrix_set(phys, 1, 0, crpix1_new);
1286 cpl_matrix_set(phys, 1, 1, crpix2_new);
1287 cpl_matrix_set(phys, 1, 2, crpix3);
1289 KMO_TRY_EXIT_IF_NULL(
1290 wcs = cpl_wcs_new_from_propertylist(sub_header));
1292 KMO_TRY_EXIT_IF_ERROR(
1293 cpl_wcs_convert(wcs, phys, &world, &status,
1294 CPL_WCS_PHYS2WORLD));
1296 crval1_new = cpl_matrix_get(world, 1, 0);
1297 crval2_new = cpl_matrix_get(world, 1, 1);
1298 crpix1_new = crpix1-2*xshift;
1299 crpix2_new = crpix2-2*yshift;
1302 KMO_TRY_EXIT_IF_ERROR(
1303 kmclipm_update_property_double(sub_header,
1306 "[pix] Reference pixel in x"));
1307 KMO_TRY_EXIT_IF_ERROR(
1308 kmclipm_update_property_double(sub_header,
1311 "[pix] Reference pixel in y"));
1312 KMO_TRY_EXIT_IF_ERROR(
1313 kmclipm_update_property_double(sub_header,
1316 "[deg] RA at ref. pixel"));
1317 KMO_TRY_EXIT_IF_ERROR(
1318 kmclipm_update_property_double(sub_header,
1321 "[deg] DEC at ref. pixel"));
1323 cpl_matrix_delete(phys); phys = NULL;
1324 cpl_matrix_delete(world); world = NULL;
1325 cpl_array_delete(status); status = NULL;
1326 cpl_wcs_delete(wcs); wcs = NULL;
1331 if ((cpl_propertylist_has(sub_header, CRPIX3)) &&
1334 crpix3 = cpl_propertylist_get_double(sub_header,
1336 KMO_TRY_CHECK_ERROR_STATE();
1338 crpix3_new = crpix3 - z1 + 1;
1339 KMO_TRY_EXIT_IF_ERROR(
1340 kmclipm_update_property_double(sub_header,
1343 "[pix] Reference pixel in z"));
1345 KMO_TRY_EXIT_IF_ERROR(
1346 kmo_dfs_save_cube(res_imglist, COPY,
"",
1347 sub_header, 0./0.));
1349 cpl_imagelist_delete(res_imglist); res_imglist = NULL;
1354 KMO_TRY_EXIT_IF_ERROR(
1355 kmo_dfs_save_sub_header(COPY,
"", sub_header));
1358 cpl_propertylist_delete(sub_header); sub_header = NULL;
1369 cpl_propertylist_delete(sub_header); sub_header = NULL;
1370 kmo_free_fits_desc(&desc);
1371 kmclipm_vector_delete(vec); vec = NULL;
1372 kmclipm_vector_delete(res_vec); res_vec = NULL;
1373 cpl_image_delete(img); img = NULL;
1374 cpl_image_delete(res_img); res_img = NULL;
1375 cpl_imagelist_delete(imglist); imglist = NULL;
1376 cpl_imagelist_delete(res_imglist); res_imglist = NULL;
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.