/* $Id: sinfo_dfs.c,v 1.44 2013-09-17 08:11:22 amodigli Exp $ * * This file is part of the SINFONI Pipeline * Copyright (C) 2002,2003 European Southern Observatory * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * $Author: amodigli $ * $Date: 2013-09-17 08:11:22 $ * $Revision: 1.44 $ * $Name: not supported by cvs2svn $ */ #ifdef HAVE_CONFIG_H # include #endif /*---------------------------------------------------------------------------- Macros ----------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------- Private to this module ----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- Includes ----------------------------------------------------------------------------*/ #include "sinfo_dfs.h" #include #include #include "sinfo_error.h" #include "sinfo_utilities.h" #include "sinfo_utils_wrappers.h" #include "sinfo_msg.h" #include "sinfo_globals.h" #include "sinfo_pro_save.h" #include "sinfo_skycor.h" #include "sinfo_file_handling.h" #include #include /**@{*/ /*---------------------------------------------------------------------------*/ /** * @defgroup sinfo_dfs DFS related Utilities * * TBD */ /*---------------------------------------------------------------------------*/ /* defines */ #define FITS_MAGIC_SZ 6 /**@{*/ /*---------------------------------------------------------------------------*/ /** * @brief Extract frames with given tag from frameset * @param frames frame set * @param tag to search for * @return newly allocated, possibly empty, frameset, or NULL on error */ /*---------------------------------------------------------------------------*/ cpl_frameset * sinfo_frameset_extract(const cpl_frameset *frames, const char *tag) { cpl_frameset *subset = NULL; const cpl_frame *f; assure( frames != NULL, CPL_ERROR_ILLEGAL_INPUT, "Null frameset" ); assure( tag != NULL, CPL_ERROR_ILLEGAL_INPUT, "Null tag" ); subset = cpl_frameset_new(); for (f = cpl_frameset_find_const(frames, tag); f != NULL; f = cpl_frameset_find_const(frames, NULL)) { cpl_frameset_insert(subset, cpl_frame_duplicate(f)); } cleanup: return subset; } /** @brief Check if an error has happened and returns error kind and location @param val input value @return 0 if no error is detected,-1 else */ int sinfo_print_rec_status(const int val) { if(cpl_error_get_code() != CPL_ERROR_NONE) { sinfo_msg_error("Recipe status at %d",val); sinfo_msg_error("%s",(const char*) cpl_error_get_message()); sinfo_msg_error("%s",(const char*) cpl_error_get_where()); return -1; } return 0; } /** @brief Kappa-sigma clip of vector values @param vin Input vector @param kappa Value of kappa @param n Number of iterations @param method Possible method: 0: are rejected values ||val-mean|| > kappa*sigma 1: are rejected values ||val-median|| > kappa*sigma @return clipped vector */ cpl_vector* sinfo_vector_clip(const cpl_vector* vinp, const double kappa, const int n, const int method) { cpl_vector* vout=NULL; cpl_vector* vtmp=NULL; int size=0; int j=0; register int i=0; double mean=0; double median=0; double stdev=0; double* pt=NULL; double* po=NULL; cknull(vinp,"Null input vector"); check_nomsg(vout=cpl_vector_duplicate(vinp)); check_nomsg(mean=cpl_vector_get_mean(vout)); check_nomsg(median=cpl_vector_get_median_const(vout)); check_nomsg(stdev=cpl_vector_get_stdev(vout)); check_nomsg(pt=cpl_vector_get_data(vtmp)); if(method == 0) { /* are rejected values ||val-mean|| > kappa*sigma */ for(j=0;j 1) && (fabs(po[size-1]-mean) > kappa*stdev)) { size--; check_nomsg(vtmp=cpl_vector_new(size)); check_nomsg(pt=cpl_vector_get_data(vtmp)); for(i=0;i kappa*sigma */ for(j=0;j 1) && (fabs(po[size-1]-median) > kappa*stdev)) { size--; check_nomsg(vtmp=cpl_vector_new(size)); check_nomsg(pt=cpl_vector_get_data(vtmp)); for(i=0;i eps) return 1; } return 0; } /** @brief Get pixel scale string @param ps input pixel scale @return pixel scale TODO: not used */ const char* sinfo_get_pix_scale(float ps) { const char* key_value; float eps=0.0001; if(fabs(ps - 0.025) < eps) { key_value="0.025"; } else if (fabs(ps - 0.1) < eps) { key_value="0.1"; } else if (fabs(ps - 0.25) < eps) { key_value="0.25"; } else if (fabs(ps - 1.0) < eps) { key_value="pupil"; } else { sinfo_msg_error("ps=%f. Failed to set pixel scale",ps); return NULL; } return key_value; } /** @brief Get clean mean and stdev of an image over a window @param img input image @param llx input lower left x image's window coordinate @param lly input lower left y image's window coordinate @param urx input upper right y image's window coordinate @param ury input upper right y image's window coordinate @param kappa input kappa of kappa-sigma clip @param nclip input max no of kappa-sigma clip iterations @param clean_mean output upper right y image's window coordinate @param clean_stdev output upper right y image's window coordinate @return pixel scale */ int sinfo_get_clean_mean_window(cpl_image* img, int llx, int lly, int urx, int ury, const int kappa, const int nclip, double* local_clean_mean, double* clean_stdev) { double mean=0; double stdev=0; cpl_image* tmp=NULL; cpl_stats* stats=NULL; int i=0; tmp=cpl_image_extract(img,llx,lly,urx,ury); cpl_image_accept_all(tmp); for(i=0;i