├── config └── .keep ├── src ├── .pure ├── spc_driz.h ├── spce_pathlength.h ├── aXe_errors.h ├── aper_check.h ├── spce_pgp.h ├── spc_cfg.h ├── spc_CD.h ├── spce_PET.h ├── lm_eval.h ├── dlstubs.c ├── drz2pet_utils.h ├── fringe_utils.h ├── dirimage_model.h ├── spc_wl_calib.h ├── spc_optimum.h ├── spce_is_in.h ├── scaleback_utils.h ├── spc_FITScards.h ├── spce_sect.h ├── nicback_utils.h ├── spc_trace_functions.h ├── spce_fitting.h ├── aXe_errors.c ├── inout_aper.h ├── trace_conf.h ├── crossdisp_utils.h ├── spc_fluxcube.h ├── spce_binning.h ├── inima_utils.h ├── Makefile.am ├── spc_spc.h ├── lmmin.h ├── aper_check.c ├── disp_conf.h ├── drizzle_utils.h ├── aXe_FILET2.c ├── specmodel_utils.h ├── spc_model.h ├── aper_conf.h ├── spc_utils.h ├── spc_flatfield.h ├── trfit_utils.h ├── spce_output.h ├── aXe_FRIGEN.c ├── fringe_model.h ├── spc_resp.h ├── aXe_utils.h ├── spc_driz.c ├── ipixcorr_utils.h ├── spc_CD.c ├── fringe_conf.h ├── spc_back.h ├── lm_eval.c ├── aXe_NICBACK.c ├── aXe_SCALEBCK.c ├── spce_pathlength.c ├── aXe_TEST.c ├── spce_is_in.c ├── spc_cfg.c ├── spc_sex.h ├── spce_sect.c ├── aXe_CHECK.c ├── spce_pgp.c ├── model_utils.h ├── aXe_TFIT.c └── aXe_DIRIMAGE.c ├── Makefile.am ├── README.md ├── .gitignore ├── configure.ac └── README /config/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/.pure: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = src 2 | EXTRA_DIST = autogen.sh 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aXe_c_code 2 | Just the C code contained in the original aXe package 3 | 4 | Updated C code for aXe can be found in the spacetelescope/hstaxe repository 5 | -------------------------------------------------------------------------------- /src/spc_driz.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_driz.h 3 | * @author Nor Pirzkal 4 | * @package spc_driz 5 | * @version $Revision: 1.3 $ 6 | * @date $Date: 2010-06-15 09:48:34 $ 7 | */ 8 | 9 | #ifndef _SPC_DRIZ_H 10 | #define _SPC_DRIZ_H 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | double sgarea(double x1, double y1, double x2, double y2, int is, int js); 19 | double boxer(int is,int js,double *x,double *y); 20 | 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | 34 | # Autotools 35 | *.deps/ 36 | autom4te.cache/ 37 | aclocal.m4 38 | configure 39 | config/ 40 | config.h 41 | config.h.in 42 | config.log 43 | config.status 44 | config.sub 45 | Makefile 46 | Makefile.in 47 | 48 | 49 | # Backups 50 | *~ 51 | -------------------------------------------------------------------------------- /src/spce_pathlength.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spce_pathlength.h 3 | * Interface of spce_pathlength.h 4 | * 5 | * @author Nor Pirzkal, Markus Demleitner 6 | * @package spce_pathlength 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | 11 | #ifndef _SPCE_PATHLENGTH_H 12 | 13 | #define _SPCE_PATHLENGTH_H 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "spc_trace_functions.h" 20 | 21 | extern int 22 | abscissa_to_pathlength (const trace_func * const func, gsl_vector * const data); 23 | 24 | #endif /* !_SPCE_PATHLENGTH_H */ 25 | -------------------------------------------------------------------------------- /src/aXe_errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * File: aXe_errors.h 4 | * Code to report errors. 5 | * @author Martin Kuemmel, Markus Demleitner, Nor Pirzkal 6 | * @package aXe_error 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | 11 | #ifndef _aXe_ERRORS_H 12 | #define _aXe_ERRORS_H 1 13 | 14 | 15 | /* public */ 16 | 17 | #define aXe_M_FATAL 1 18 | #define aXe_M_ERROR 2 19 | #define aXe_M_WARN1 101 20 | #define aXe_M_WARN2 102 21 | #define aXe_M_WARN3 103 22 | #define aXe_M_WARN4 104 23 | 24 | extern void 25 | aXe_message (const int level, const char *const w_file, const int w_line, 26 | const char *const msg, ...); 27 | 28 | #endif /* !_aXe_ERRORS_H */ 29 | -------------------------------------------------------------------------------- /src/aper_check.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: aper_check.h 3 | * APER_CHECK - create a FITS image showing the locations of 4 | * apertures. 5 | * 6 | * @author Martin Kuemmel, Markus Demleitner, Nor Pirzkal 7 | * @package aper_check 8 | * @version $Revision: 1.3 $ 9 | * @date $Date: 2010-06-15 09:48:34 $ 10 | */ 11 | 12 | #ifndef _APER_CHECK_H 13 | #define _APER_CHECK_H 14 | 15 | 16 | typedef struct 17 | { 18 | gsl_matrix *img; 19 | } 20 | aXe_mask; 21 | 22 | extern aXe_mask * 23 | aXe_mask_init (observation * ob); 24 | 25 | extern void 26 | add_ap_p_to_aXe_mask (ap_pixel * ap_p, aXe_mask * mask); 27 | 28 | extern void 29 | mark_trace_in_aXe_mask(ap_pixel * ap_p, aXe_mask *mask); 30 | #endif 31 | -------------------------------------------------------------------------------- /src/spce_pgp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spce_pgp.h 3 | * Interface to PGplot routines. 4 | * 5 | * @author Nor Pirzkal, Markus Demleitner 6 | * @package spce_pgp 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | 11 | #ifndef _SPCE_PGP_H 12 | 13 | #define _SPCE_PGP_H 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "aXe_grism.h" 24 | #include "aXe_utils.h" 25 | #include "spce_pathlength.h" 26 | #include "spce_output.h" 27 | 28 | extern void 29 | pgp_stamp_image (const ap_pixel * const ap_p, const int n_sub, 30 | const object * ob, int beamnum, char filename[], 31 | const int negative); 32 | #endif /* !_SPCE_PGP_H */ 33 | -------------------------------------------------------------------------------- /src/spc_cfg.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * File: spc_cfg.h 4 | * @author Martin Kuemmel, Nor Pirzkal 5 | * @package spc_cfg 6 | * @version $Revision: 1.3 $ 7 | * @date $Date: 2010-06-15 09:48:34 $ 8 | */ 9 | 10 | 11 | #ifndef _SPC_CFG_H 12 | #define _SPC_CFG_H 13 | 14 | #define LINE_LEN_MAX 1280 /* actual max line length */ 15 | #define BUFFERSIZE LINE_LEN_MAX +2 /* ... including \n and \0 */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "aXe_errors.h" 22 | #include "spc_utils.h" 23 | 24 | 25 | enum RetVal 26 | { 27 | NO_PROBLEMS, 28 | ERR_FOPEN, 29 | ERR_MEM, 30 | }; 31 | 32 | struct CfgStrings 33 | { 34 | char *name; 35 | char *data; 36 | }; 37 | 38 | extern int 39 | CfgRead (char *Filename, struct CfgStrings *CfgInfo); 40 | 41 | extern int 42 | CfgRead_from_array (char **arr, struct CfgStrings *CfgInfo); 43 | #endif 44 | -------------------------------------------------------------------------------- /src/spc_CD.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_CD.h 3 | * @author Martin Kuemmel, Markus Demleitner, Nor Pirzkal 4 | * @package spc_CD 5 | * @version $Revision: 1.3 $ 6 | * @date $Date: 2010-06-15 09:48:34 $ 7 | */ 8 | #ifndef SPC_CD_H 9 | #define SPC_CD_H 10 | 11 | #include 12 | #include 13 | #include "aXe_grism.h" 14 | #include "wcs.h" 15 | #include "aXe_errors.h" 16 | 17 | 18 | /** 19 | A point in world coordinates. 20 | 21 | */ 22 | typedef struct 23 | { 24 | // RA 25 | double ra; 26 | // dec 27 | double dec; 28 | // equinox 29 | char *equinox; 30 | } 31 | sky_coord; 32 | 33 | extern sky_coord * 34 | ij_to_radec (struct WorldCoor *wcs, d_point ij); 35 | 36 | extern d_point * 37 | radec_to_ij (struct WorldCoor *wcs, sky_coord radec); 38 | 39 | extern char * 40 | get_fits_header (char filenamep[], int hdunum); 41 | 42 | extern struct WorldCoor * 43 | get_wcs (char filename[], int hdunum); 44 | #endif 45 | -------------------------------------------------------------------------------- /src/spce_PET.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spce_PET.h 3 | * The interface the the Pixel extraction table input/output routines 4 | * 5 | * @author Martin Kuemmel, Nor Pirzkal 6 | * @package spce_PET 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | 11 | #ifndef _SPCE_PET_H 12 | 13 | #define _SPCE_PET_H 14 | 15 | extern ap_pixel * 16 | alloc_aperture_table (long N); 17 | 18 | extern void 19 | create_PET (char filename[], int overwrite); 20 | 21 | extern fitsfile * 22 | create_PET_opened (char filename[], int overwrite); 23 | 24 | extern long 25 | PET_count_elements (ap_pixel * ap_p); 26 | 27 | extern int 28 | get_PET_colnum (fitsfile * input, char colname[]); 29 | 30 | extern void 31 | add_ALL_to_PET (ap_pixel * ap_p, char ID[], fitsfile *input, int update); 32 | 33 | extern ap_pixel * 34 | get_ALL_from_next_in_PET(fitsfile *input, int *aperID, int *beamID); 35 | 36 | extern void 37 | fprintf_ap_pixel (FILE * output, ap_pixel ap); 38 | 39 | extern void 40 | fprintf_ap_pixel_list (FILE * output, ap_pixel * ap); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/lm_eval.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: lm_eval.h 3 | * 4 | * @author Martin Kuemmel 5 | * @package lm_eval 6 | * @version $Revision: 1.2 $ 7 | * @date $Date: 2010-06-15 09:48:34 $ 8 | */ 9 | typedef struct { 10 | double* user_t; 11 | double* user_y; 12 | double (*user_func)( double user_t_point, double* par ); 13 | } lm_data_type; 14 | 15 | typedef struct { 16 | double* user_t; 17 | double* user_y; 18 | double* fpars; 19 | double (*user_func)( double user_t_point, double* par, double* fpar); 20 | } lm_data_fpar_type; 21 | 22 | void lm_evaluate_default( double* par, int m_dat, double* fvec, 23 | void *data, int *info ); 24 | 25 | void lm_evaluate_fpar( double* par, int m_dat, double* fvec, 26 | void *data, int *info ); 27 | 28 | void lm_print_default( int n_par, double* par, int m_dat, double* fvec, 29 | void *data, int iflag, int iter, int nfev ); 30 | void lm_print_nothing( int n_par, double* par, int m_dat, double* fvec, 31 | void *data, int iflag, int iter, int nfev ); 32 | -------------------------------------------------------------------------------- /src/dlstubs.c: -------------------------------------------------------------------------------- 1 | /** 2 | * File: dlstubs.c 3 | * Some empty functions needed at some time to statically 4 | * link in Solaris. 5 | * @author Martin Kuemmel 6 | * @package dlstubs 7 | * @version $Revision: 1.2 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #include 11 | #include 12 | 13 | /* dl*() stub routines for static compilation. Prepared from 14 | /usr/include/dlfcn.h by Hal Pomeranz */ 15 | 16 | void *dlopen(const char *str, int x) {} 17 | void *dlsym(void *ptr, const char *str) {} 18 | int dlclose(void *ptr) {} 19 | char *dlerror() {} 20 | void *dlmopen(Lmid_t a, const char *str, int x) {} 21 | int dladdr(void *ptr1, Dl_info *ptr2) {} 22 | int dldump(const char *str1, const char *str2, int x) {} 23 | int dlinfo(void *ptr1, int x, void *ptr2) {} 24 | 25 | void *_dlopen(const char *str, int x) {} 26 | void *_dlsym(void *ptr, const char *str) {} 27 | int _dlclose(void *ptr) {} 28 | char *_dlerror() {} 29 | void *_dlmopen(Lmid_t a, const char *str, int x) {} 30 | int _dladdr(void *ptr1, Dl_info *ptr2) {} 31 | int _dldump(const char *str1, const char *str2, int x) {} 32 | int _dlinfo(void *ptr1, int x, void *ptr2) {} 33 | -------------------------------------------------------------------------------- /src/drz2pet_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: drz2pet_utils.h 3 | * Header file for the code in "drz2pet_utils.c" 4 | * 5 | * @author Martin Kuemmel 6 | * @package drz2pet 7 | * @version $Revision: 1.2 $ 8 | * @date $Date: 2009-06-18 09:50:07 $ 9 | */ 10 | #ifndef _DRZ2PET_UTILS_H 11 | #define _DRZ2PET_UTILS_H 12 | 13 | #include 14 | #include 15 | #include "aXe_grism.h" 16 | #include 17 | #include 18 | 19 | ap_pixel * 20 | make_spc_drztable(observation * const obs, observation * const wobs, 21 | const object *ob, const double lambda0, 22 | const double dlambda); 23 | 24 | extern char * 25 | get_ID_num(char *grism_image,char *extname); 26 | 27 | extern void 28 | normalize_weight(observation * wobs, object *ob, 29 | const int opt_extr); 30 | 31 | extern gsl_matrix * 32 | comp_equ_weight(gsl_matrix *exp_map, const object *ob); 33 | 34 | gsl_matrix * 35 | comp_exp_weight(gsl_matrix *exp_map, const object *ob); 36 | 37 | gsl_matrix * 38 | comp_opt_weight(gsl_matrix *mod_map, 39 | gsl_matrix *var_map, const object *ob); 40 | #endif /* !_DRZ2PET_UTILS_H */ 41 | -------------------------------------------------------------------------------- /src/fringe_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: fringe_utils.h 3 | * Header file for fringe_utils.c. 4 | * 5 | * @author Martin Kuemmel 6 | * @package fringe_utils 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef _FRINGE_UTILS_H 11 | #define _FRINGE_UTILS_H 12 | 13 | 14 | typedef struct 15 | { 16 | gsl_vector *lambda_values; // vector with l_min, l_1, l_2, l_max 17 | double tp_max; // the maximum throughput value 18 | } 19 | pixel_tput; 20 | 21 | extern void 22 | fringe_correct_PET(const fringe_conf *fconf, const beam act_beam, 23 | ap_pixel *obj_pet, ap_pixel *bck_pet); 24 | 25 | extern gsl_vector ** 26 | evaluate_pixel_throughput(const fringe_conf *fconf, 27 | const beam act_beam, const ap_pixel *obj_pix); 28 | 29 | gsl_vector ** 30 | get_gauss_throughput(const fringe_conf *fconf, const ap_pixel *obj_pix, 31 | const double fwhm); 32 | 33 | interpolator * 34 | create_interp_tput(const pixel_tput *p_tput); 35 | 36 | extern void 37 | compute_pixel_tput(const beam act_beam, const ap_pixel *obj_pix, 38 | pixel_tput *p_tput); 39 | 40 | extern d_point 41 | compute_tput_angles(const beam act_beam, const ap_pixel *act_pet); 42 | 43 | extern pixel_tput * 44 | alloc_pixel_tput(); 45 | 46 | void 47 | print_pixel_tput(pixel_tput *p_tput); 48 | 49 | extern void 50 | free_pixel_tput(pixel_tput *p_tput); 51 | #endif 52 | -------------------------------------------------------------------------------- /src/dirimage_model.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: dirimage_model.h 3 | * Header file for dirimage_model.c 4 | * 5 | * @author Martin Kuemmel 6 | * @package dirimage_model 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef _DIRIMAGE_MODEL_H 11 | #define _DIRIMAGE_MODEL_H 12 | 13 | // interpolation type used for the 14 | // total passband curves 15 | #define TPASS_INTERP_TYPE gsl_interp_linear 16 | 17 | extern int 18 | compute_dirimage_model(char dirim_file_path[], char conf_file_path[], char tpass_file_path[], 19 | char specmod_file_path[], char objmod_file_path[], char aper_file_path[], 20 | const double model_scale, const double tel_area, const double lambda_psf, 21 | observation *obs, char map_file_path[]); 22 | 23 | extern interpolator * 24 | get_filter_sensitivity(const char tpass_file[], const double tel_area); 25 | 26 | extern gsl_matrix * 27 | make_dirimage(object **oblist, dirobject **dirlist, const px_point npixels, 28 | const double lambda_psf, interpolator *tpass); 29 | 30 | 31 | extern double 32 | get_cps_for_dirobject(interpolator *tpass, dirobject *actdir); 33 | 34 | extern double 35 | integrate_interpolator(interpolator *combine); 36 | 37 | extern interpolator * 38 | combine_tpass_SED(interpolator *tpass, dirobject *actdir); 39 | 40 | extern interpolator * 41 | get_combined_tpass_SED(gsl_vector *indep_data, interpolator *tpass, dirobject *actdir); 42 | #endif 43 | -------------------------------------------------------------------------------- /src/spc_wl_calib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_wl_calib.h 3 | * Header file for the code in "spc_wl_calib.c" 4 | * 5 | * @author Martin Kuemmel, Nor Pirzkal 6 | * @package spc_wl_calib 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | 11 | #ifndef _SPC_WL_CALIB_H 12 | #define _SPC_WL_CALIB_H 1 13 | 14 | 15 | /** 16 | * A calibration function, mostly containing the coefficients of 17 | * the polynomial. To be filled in with create_calib 18 | */ 19 | typedef struct 20 | { 21 | int order; /* The order of the polynomial */ 22 | gsl_vector *pr_range; /* the valid range for prisms */ 23 | double *coeffs; /* a pointer order+1 doubles, 0th coeff at coeffs[0] */ 24 | double (*func) (const double xi, const int order, 25 | const double *const coeffs); 26 | } 27 | calib_function; 28 | 29 | 30 | extern calib_function * 31 | create_calib_from_gsl_vector (const int for_grism, const gsl_vector * a); 32 | 33 | extern void 34 | free_calib (calib_function * const calib); 35 | 36 | extern void 37 | wl_calib (ap_pixel * ap_p, const calib_function * const calib); 38 | 39 | extern void 40 | pwise_wl_calib(const global_disp *gdisp, const d_point pixel, 41 | const beam actbeam, const int for_grism, ap_pixel *ap_p, const calib_function *old_calib); 42 | 43 | extern ap_pixel * 44 | prange_cut(ap_pixel * ap_p, const gsl_vector * lambda_range, 45 | const calib_function * wl_calibration); 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /src/spc_optimum.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_optimum.h 3 | * The interface to the binning and weight routines 4 | * 5 | * @author Martin Kuemmel 6 | * @package spc_optimum 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef _SPC_OPTIMUM_H 11 | #define _SPC_OPTIMUM_H 1 12 | 13 | #define NSPARE_PIX 5 14 | 15 | extern gsl_matrix * 16 | create_weightimage(ap_pixel *ap_p, const beam actbeam, 17 | const aperture_conf *conf, const double exptime, 18 | const double sky_cps); 19 | 20 | extern drzstamp * 21 | compute_modvar(ap_pixel *ap_p, const beam actbeam, 22 | const drzstamp_dim dimension); 23 | 24 | void 25 | prepare_inv_variance(ap_pixel *ap_p, ap_pixel *bg_p, const int dobck, 26 | const aperture_conf *conf, const double exptime, 27 | const double sky_cps, const double xi_shift); 28 | 29 | extern void 30 | compute_object_ivar(ap_pixel *ap_p, const double rdnoise, 31 | const double exptime, const double sky_cps); 32 | 33 | void 34 | compute_total_ivar(ap_pixel *ap_p, const ap_pixel *bg_p, const double rdnoise, 35 | const double exptime, const double sky_cps); 36 | 37 | extern drzstamp * 38 | alloc_drzstamp(const drzstamp_dim dimension); 39 | 40 | drzstamp_dim 41 | get_all_dims(const ap_pixel *ap_p, const ap_pixel *bg_p, const beam actbeam, 42 | const int dobck); 43 | 44 | extern drzstamp_dim 45 | get_resample_dims(const ap_pixel *ap_p, const beam actbeam); 46 | 47 | extern drzstamp_dim 48 | get_default_dim(); 49 | 50 | extern drzstamp * 51 | get_default_modvar(); 52 | 53 | extern gsl_matrix * 54 | get_default_weight(); 55 | 56 | extern gsl_matrix * 57 | comp_allweight(drzstamp *modvar); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/spce_is_in.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spce_is_in.h 3 | * External definitions for spce_is_in.c 4 | * 5 | * @author Martin Kuemmel, Nor Pirzkal, Markus Demleitner 6 | * @package spce_is_in 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | 11 | #ifndef _SPC_IS_IN_H 12 | 13 | #define _SPC_IS_IN_H 14 | 15 | 16 | /** 17 | A triangle together with some pre-computed properties, consisting of 18 | the coordinates of the root vertex, the coordinates of the ends 19 | of the sides s, t relative to the root and some pre-computed 20 | properties. 21 | */ 22 | typedef struct 23 | { 24 | px_point root; /* pixel coordinate of the angle point */ 25 | px_point s, t; /* the end points of the sides relative to root */ 26 | double sabs, tabs; /* length of s and t */ 27 | double s_t; /* scalar product of s and t */ 28 | } 29 | triangle; 30 | 31 | /** 32 | An opaque structure describing a quadrangle through two triangles 33 | @see fill_is_in_descriptor 34 | */ 35 | typedef struct 36 | { 37 | triangle trig1, trig2; /* The quadrangle is split into two triangles */ 38 | int mini, maxi; /* The mininum and maximum row-span of the 39 | aperture */ 40 | int minj, maxj; /* The mininum and maximum col-span of the 41 | aperture */ 42 | } 43 | is_in_descriptor; 44 | 45 | 46 | /* public */ 47 | 48 | extern int 49 | is_in (const int x, const int y, const is_in_descriptor * const iid); 50 | 51 | extern int 52 | fill_is_in_descriptor (is_in_descriptor * const iid, 53 | const px_point * const corners); 54 | 55 | extern int 56 | tracedist_criteria(const double x, const double y, sectionfun *sf, 57 | const trace_func *tracefun, const double width); 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /src/scaleback_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: scaleback_utils.h 3 | * header files for scaleback_utils.c 4 | * 5 | * @author Martin Kuemmel 6 | * @package scaleback_utils 7 | * @version $Revision: 1.8 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef _SCALEBACK_UTILS_H 11 | #define _SCALEBACK_UTILS_H 12 | 13 | #define N_BCKSCALE_ITER 10 14 | #define N_BCKSCALE_KAPPA 3.0 15 | #define N_BCKSCALE_ACCUR 1.0e-04 16 | #define MASK_VALUE -1.0e+06 17 | 18 | FITScards * 19 | fit_to_FITScards(const gsl_vector* bck_vals, const px_point npixels); 20 | 21 | void 22 | make_scale_back(char grism_image[], const char grism_mask[], char conf_file[], 23 | const char scale_image[], char bck_image[], const char plist_name[], 24 | const int scale_to_master, const int make_plis); 25 | 26 | void 27 | print_plis(const fitbck_data *fbck_data, const char plist_name[]); 28 | 29 | gsl_matrix * 30 | compute_scale_grism(gsl_matrix *gr_img, gsl_matrix *gr_dqval, gsl_matrix *gr_mask, 31 | int dqmask, gsl_vector *bck_vals); 32 | 33 | gsl_matrix * 34 | compute_scale_master(const gsl_matrix *sc_img, const gsl_vector *bck_vals); 35 | 36 | void 37 | fill_mask_data(gsl_matrix *gr_img, gsl_matrix *gr_dqval, gsl_matrix *gr_mask, 38 | gsl_matrix *sc_img, fitbck_data *fbck_data, int dqmask); 39 | 40 | void 41 | fill_cont_data(gsl_matrix *gr_img, gsl_matrix *gr_dqval, gsl_matrix *gr_mask, 42 | gsl_matrix *sc_img, fitbck_data *fbck_data, int dqmask); 43 | 44 | gsl_vector * 45 | make_ksig_scalefit(fitbck_data *fbck_data); 46 | 47 | void 48 | get_bck_scale(const double *xs, double *ys, double *ws, 49 | const int n, gsl_vector *bck_vals); 50 | 51 | int 52 | clipp_scale_data(fitbck_data *fbck_data, const gsl_vector *bck_vals, 53 | const float kappa); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/spc_FITScards.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_FITScards.h 3 | * @author Martin Kuemmel, Nor Pirzkal 4 | * @package spc_FITScards 5 | * @version $Revision: 1.4 $ 6 | * @date $Date: 2010-06-15 09:48:34 $ 7 | */ 8 | 9 | #ifndef SPC_FITSCARDS_H 10 | #define SPC_FITSCARDS_H 11 | 12 | #include 13 | #include "aXe_grism.h" 14 | #include "fitsio.h" 15 | #include "disp_conf.h" 16 | #include "aper_conf.h" 17 | #include 18 | #include 19 | 20 | typedef struct 21 | { 22 | int n; /* Number of cards in the **cards array */ 23 | char **cards; /* A pointer to an array of strings */ 24 | } FITScards; 25 | 26 | extern FITScards * 27 | allocate_FITScards(int n); 28 | 29 | extern void 30 | free_FITScards(FITScards *cards); 31 | 32 | extern FITScards * 33 | get_WCS_FITScards(const double rval1, const double delta1, const double rval2); 34 | 35 | extern FITScards * 36 | beam_to_FITScards(object *ob, int beamnum); 37 | 38 | extern FITScards * 39 | stpmin_to_FITScards(d_point stp_min); 40 | 41 | extern FITScards * 42 | drzinfo_to_FITScards(object *ob, int beamnum, d_point outref, 43 | aperture_conf *conf, gsl_matrix *drizzcoeffs, 44 | int trlength, double relx, double rely, 45 | double objwidth, d_point refwave_pos, 46 | float sky_cps, double drizzle_width, 47 | double cdcorr, double spcorr); 48 | 49 | extern FITScards * 50 | nicbck_info_to_FITScards(const double skypix_frac, const double scale_factor, 51 | const double offset); 52 | 53 | extern FITScards * 54 | dispstruct_to_FITScards(dispstruct *disp); 55 | 56 | extern void 57 | update_contam_model(fitsfile *fptr, char model_name[]); 58 | 59 | extern int 60 | check_quantitative_contamination(fitsfile *fptr); 61 | 62 | extern void 63 | transport_cont_modname(char grism_file_path[], char PET_file_path[]); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/spce_sect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: spce_sect.h 3 | * External definitions for spce_sect.c 4 | * 5 | * 6 | * @author Martin Kuemmel, Nor Pirzkal, Markus Demleitner 7 | * @package spce_sect 8 | * @version $Revision: 1.3 $ 9 | * @date $Date: 2010-06-15 09:48:34 $ 10 | * 11 | */ 12 | 13 | #ifndef spce_sect_H 14 | #define spce_sect_H 15 | 16 | #include 17 | #include 18 | #include "aXe_grism.h" 19 | #include "spc_trace_functions.h" 20 | 21 | 22 | /** 23 | @package spce_sect 24 | */ 25 | 26 | /** 27 | A structure to support old gsl 0.9 gsl_interval 28 | */ 29 | typedef struct 30 | { 31 | double lower; 32 | double upper; 33 | } 34 | gsl_interval; 35 | 36 | /** 37 | A structure describing the function that has a zero at the section point, 38 | including the measuring point and the slope of the line through it, 39 | the function describing the spectrum trace, functions related to 40 | gsl and a flag to initiate special handling of vertically oriented 41 | objects. 42 | 43 | @see fill_in_sectionfun 44 | @see free_sectionfun 45 | */ 46 | typedef struct 47 | { 48 | int vertical; /* Special handling if orientation is close to vertical */ 49 | double m; /* slope of line through x0, y0 that is to */ 50 | double x0, y0; /* intersect the trace */ 51 | trace_func *func; /* Parametrization of the trace */ 52 | 53 | /* the GSL stuff has to be kept in here to avoid excessive re-allocing 54 | of the solver for each pixel */ 55 | gsl_interval *interv; 56 | gsl_function *gslfun; 57 | gsl_root_fsolver *solver; 58 | } 59 | sectionfun; 60 | 61 | /* public */ 62 | 63 | int fill_in_sectionfun (sectionfun * const sf, const double inclination, 64 | const beam * const b); 65 | int find_section_point (sectionfun *sf, const double x, const double y, 66 | double *const res); 67 | void free_sectionfun (sectionfun * const sf); 68 | #endif 69 | -------------------------------------------------------------------------------- /src/nicback_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: nicback_utils.h 3 | * header files for nicback_utils.c 4 | * 5 | * @author Martin Kuemmel 6 | * @package nicback_utils 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef _NICKBACK_UTILS_H 11 | #define _NICKBACK_UTILS_H 12 | 13 | #define N_KSIGBCK_ITER 3 14 | #define N_KSIGBCK_KAPPA 3.0 15 | 16 | #define FRAC_BPIX_MIN 0.1 17 | #define NPIX_DIM1 256.0 18 | #define NPIX_DIM2 256.0 19 | #define AREA_EXTEND_MIN 0.5 20 | #define BCK_SCALE_MIN 0.5 21 | #define BCK_SCALE_MAX 1.5 22 | 23 | 24 | typedef struct 25 | { 26 | int n_data; 27 | 28 | double *x_values; 29 | double *y_values; 30 | double *e_values; 31 | int *x_pos; 32 | int *y_pos; 33 | } 34 | fitbck_data; 35 | 36 | extern void 37 | make_nicmos_back(const observation * const obs, const char *msk_name, 38 | const char *master_bck, char bck_name[], char plist_name[], 39 | const char corr_bck[]); 40 | 41 | extern fitbck_data * 42 | alloc_fitbck_data(const int n_data); 43 | 44 | extern double 45 | get_skypix_frac(const fitbck_data *fbck_data); 46 | 47 | extern gsl_matrix * 48 | compute_nicmos_back(const gsl_matrix *mbck_img, const double factor, 49 | const double offset, const gsl_matrix *corr_img); 50 | 51 | extern gsl_vector * 52 | make_ksig_linfit(fitbck_data *fbck_data); 53 | 54 | extern double 55 | comp_stdev_from_array(const double *data, const int ndata, const double mean); 56 | 57 | extern int 58 | check_fbck_data(fitbck_data *fbck_data); 59 | 60 | extern gsl_vector* 61 | get_fbck_defaults(); 62 | 63 | extern int 64 | clipp_fbck_data(fitbck_data *fbck_data, const gsl_vector *lfit, const float kappa); 65 | 66 | extern void 67 | fill_fbck_data(const observation * const obs, const gsl_matrix *msk_img, 68 | const gsl_matrix *mbck_img, fitbck_data *fbck_data, char plist_name[], 69 | const gsl_matrix *corr_img); 70 | 71 | extern void 72 | free_fitbck_data(fitbck_data *fbck_data); 73 | #endif 74 | -------------------------------------------------------------------------------- /src/spc_trace_functions.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_trace_functions.h 3 | * External definitions to parametrize spectrum traces 4 | * in aXe grism exposures 5 | * 6 | * @author Martin Kuemmel, Nor Pirzkal, Markus Demleitner 7 | * @package spc_trace_functions 8 | * @version $Revision: 1.3 $ 9 | * @date $Date: 2010-06-15 09:48:34 $ 10 | */ 11 | 12 | #ifndef _SPC_TRACE_FUNCTIONS_H 13 | 14 | #define _SPC_TRACE_FUNCTIONS_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "aXe_errors.h" 21 | 22 | /* public */ 23 | 24 | 25 | 26 | /** A function for parametrizing spectrum traces; deriv and/or path_len 27 | (i.e. its derivative or the path length from parameter 0) may be 28 | NULL if they are not known analytically. 29 | func should return the the y offset for a given pixel column x of 30 | the spectrum trace 31 | */ 32 | typedef struct 33 | { 34 | int type; /* A unique type ID for the trace function */ 35 | double (*func) (const double, const void *const pars); 36 | double (*deriv) (const double, const void *const pars); 37 | double (*path_len) (const double, const void *const pars); 38 | void *data; /* private data for trace function, should 39 | be passed as a second parameter */ 40 | } 41 | trace_func; 42 | 43 | 44 | /* The create_xxx functions return a pointer to an allocated trace_func 45 | or NULL if the allocation failed. */ 46 | extern trace_func * 47 | create_poly2 (const double a0, const double a1, const double a2); 48 | 49 | extern trace_func * 50 | create_polyN (gsl_vector *v); 51 | 52 | extern trace_func * 53 | vector_to_trace_poly2 (gsl_vector *v); 54 | 55 | extern trace_func * 56 | vector_to_trace_polyN(gsl_vector *v); 57 | 58 | extern double 59 | polyN_ds(double x, void *pars); 60 | 61 | extern void 62 | free_poly2(trace_func * func); 63 | 64 | extern void 65 | free_polyN(trace_func * func); 66 | 67 | #endif /* ! _SPC_TRACE_FUNCTIONS_H */ 68 | -------------------------------------------------------------------------------- /src/spce_fitting.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * File: spce_fitting.h 4 | * @author Nor Pirzkal 5 | * @package spce_fitting 6 | * @version $Revision: 1.3 $ 7 | * @date $Date: 2010-06-15 09:48:34 $ 8 | */ 9 | 10 | #ifndef _SPC_FITTING_H 11 | #define _SPC_FITTING_H 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | #include "aXe_errors.h" 18 | 19 | 20 | extern void 21 | comp_vector_average (const double *xs, double *ys, 22 | double *ws, double *yi, const int n, const int final); 23 | extern void 24 | comp_vector_median (const double *xs, double *ys, 25 | double *ws, double *yi, const int n, const int final); 26 | 27 | extern void 28 | comp_vector_linear (const double *xs, double *ys, 29 | double *ws, double *yi, const int n, const int final); 30 | 31 | extern void 32 | comp_vector_polyN (const int m, const double *xs, double *ys, 33 | double *ws, double *yi, const int n, const int final); 34 | 35 | extern void 36 | fill_const_value(double *ys, double *ws, double *yi, const int n, 37 | double cval, double stdev, const int final); 38 | 39 | extern void 40 | det_vector_average (const double *xs, double *ys, 41 | double *ws, const int n, double *avg, double *std); 42 | extern void 43 | det_vector_median (const double *xs, double *ys, 44 | double *ws, const int n, double *med, double *std); 45 | 46 | extern gsl_vector * 47 | det_vector_linear(const double *xs, double *ys, double *ws, 48 | const int n, const int weight); 49 | 50 | extern gsl_vector * 51 | det_vector_poly_N (int m, const double *const xs, double *const ys, 52 | double *const ws, const int n, gsl_vector *c, 53 | gsl_matrix *cov); 54 | 55 | extern void 56 | fill_linear_interp(const double *const xs, double *const ys, 57 | double *const ws, double *yi, const int n, 58 | gsl_vector *interp, const int final); 59 | 60 | extern void 61 | fill_polyN_interp(const double *const xs, double *const ys, 62 | double *const ws, double *yi, const int n, 63 | gsl_vector *coeffs, gsl_matrix *cov, gsl_vector *interp, 64 | const int final); 65 | #endif 66 | -------------------------------------------------------------------------------- /src/aXe_errors.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: aXe_errors.c 3 | * Code to report errors. 4 | * @author Martin Kuemmel, Markus Demleitner, Nor Pirzkal 5 | * @package aXe_error 6 | * @version $Revision: 1.3 $ 7 | * @date $Date: 2010-06-15 09:48:34 $ 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include "aXe_errors.h" 14 | 15 | /** 16 | Report an error message or warning and exit if error is fatal. 17 | 18 | @param level severety of the message, one of
  • aXe_M_FATAL (fatal error, 19 | exit),
  • 20 |
  • aXe_M_ERROR (an error that will invalidate the result but doesn't 21 | preclude further processing within the program),
  • 22 |
  • aXe_M_WARN1 (a problem that will most likely invalidate the result), 23 |
  • 24 |
  • aXe_M_WARN2 (a problem that may invalidate the result),
  • 25 |
  • aXe_M_WARN3 (a problem that might be looked into, but probably all is 26 | ok),
  • 27 |
  • aXe_M_WARN4 (informational messages only).
28 | @param w_file the module the error occurred in. 29 | @param w_line the line the error occurred in. 30 | @param message the error message -- this works like printf 31 | */ 32 | void 33 | aXe_message (const int level, const char *const w_file, const int w_line, 34 | const char *const msg, ...) 35 | /* This is based on fvwm's fvwm_msg */ 36 | { 37 | char *typestr; 38 | va_list args; 39 | 40 | switch (level) 41 | { 42 | case aXe_M_FATAL: 43 | typestr = "Fatal:"; 44 | break; 45 | case aXe_M_ERROR: 46 | typestr = "Error:"; 47 | break; 48 | case aXe_M_WARN1: 49 | case aXe_M_WARN2: 50 | case aXe_M_WARN3: 51 | case aXe_M_WARN4: 52 | typestr = "Warning:"; 53 | break; 54 | default: 55 | typestr = "Oops:"; 56 | break; 57 | } 58 | 59 | va_start (args, msg); 60 | 61 | fprintf (stderr, "aXe (%s, %d): %s ", w_file, w_line, typestr); 62 | vfprintf (stderr, msg, args); 63 | //fprintf (stderr, "\n"); 64 | 65 | va_end (args); 66 | 67 | if (level == aXe_M_FATAL) 68 | exit (-1); 69 | } 70 | -------------------------------------------------------------------------------- /src/inout_aper.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: inout_aper.h 3 | * header files for inout_aper.c 4 | * 5 | * @author Martin Kuemmel, Markus Demleitner, Nor Pirzkal 6 | * @package inout_aper 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef _INOUT_APER_H 11 | 12 | #define _INOUT_APER_H 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "aXe_grism.h" 21 | #include "aXe_utils.h" 22 | #include "aXe_errors.h" 23 | #include "spc_cfg.h" 24 | #include "spc_trace_functions.h" 25 | 26 | #define APER_MAXLINE 14 27 | 28 | extern int 29 | nbeams_from_char_array2 (char **apers, int num); 30 | 31 | extern gsl_vector_int * 32 | nbeams_from_char_array (char **apers, int num); 33 | 34 | extern int 35 | object_list_to_file (object * const *oblist, char *filename, 36 | int leaveout_ignored); 37 | 38 | extern int 39 | get_beam_from_aper_file (char *filename, int aperID, int beamID,beam * b); 40 | 41 | extern gsl_vector_int * 42 | aper_file_aperlist (char *filename); 43 | 44 | extern int 45 | aper_file_apernum (char *filename); 46 | 47 | extern object * 48 | get_aperture_from_aper_file (char *filename, int aperID); 49 | 50 | extern object ** 51 | file_to_object_list (char filename[], observation * obs); 52 | 53 | extern char ** 54 | return_next_aperture(FILE *input); 55 | 56 | extern object ** 57 | file_to_object_list_seq (char filename[], observation * obs); 58 | 59 | extern int 60 | find_object_in_object_list(object **oblist, const int ID); 61 | 62 | extern beam 63 | find_beam_in_object_list(object **oblist, const int objID, 64 | const int beamID); 65 | 66 | extern beam * 67 | find_beamptr_in_object_list(object **oblist, const int objID, 68 | const int beamID); 69 | 70 | extern void 71 | refurbish_object_list(object **oblist, const int new_default, 72 | const int old_value, const int new_value); 73 | 74 | extern int 75 | object_list_size(object **oblist); 76 | 77 | extern int 78 | get_beamspec_size(object **oblist); 79 | #endif 80 | -------------------------------------------------------------------------------- /src/trace_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: trace_conf.h 3 | * @author Martin Kuemmel, Nor Pirzkal 4 | * @package trace_conf 5 | * @version $Revision: 1.3 $ 6 | * @date $Date: 2010-06-15 09:48:34 $ 7 | */ 8 | 9 | #ifndef _TRACE_CONF_H 10 | 11 | #define _TRACE_CONF_H 12 | 13 | #include 14 | #include 15 | #include "aXe_grism.h" 16 | #include "aXe_errors.h" 17 | #include 18 | #include "spc_cfg.h" 19 | #include "disp_conf.h" 20 | 21 | 22 | /** 23 | A structure to contain the coefficient of a 2D 24 | polynomial that can be used to compute the given 25 | coefficient of the polynomial dispersion relation 26 | as at a particular i.j location in the image 27 | */ 28 | typedef struct 29 | { 30 | gsl_vector *pol; /* A vector containing the 2D polynomial coefficients */ 31 | d_point offset; /* X and Y offsets to apply to input coordinates */ 32 | d_point cpoint; /* The detector location at which this structure was computed */ 33 | int ID; /* The ID of the beam for which this coefficient is defined */ 34 | char file[MAXCHAR]; 35 | } 36 | tracestruct; 37 | 38 | 39 | extern int 40 | get_beam_trace_norder (char *filename, int beamID); 41 | 42 | extern gsl_vector * 43 | get_beam_trace_order (char *filename, int beamID, int order); 44 | 45 | extern float 46 | get_trace_coeff_at_pos (char *filename, int beamID, int order, d_point p); 47 | 48 | extern gsl_vector * 49 | get_trace_coeffs_at_pos (char *filename, int beamID, d_point p); 50 | 51 | extern gsl_vector * 52 | get_beam_trace_xoff (char *filename, int beamID); 53 | 54 | extern gsl_vector * 55 | get_beam_trace_yoff (char *filename, int beamID); 56 | 57 | extern float 58 | get_trace_xoff_at_pos (char *filename, int beamID, d_point p); 59 | 60 | extern float 61 | get_trace_yoff_at_pos (char *filename, int beamID, d_point p); 62 | 63 | extern float 64 | eval_trace_off_at_pos (gsl_vector *coeffs, d_point p, int beamID); 65 | 66 | extern tracestruct * 67 | get_tracestruct_at_pos (char *filename, int beamID, d_point p); 68 | 69 | extern void 70 | tracestruct_fprintf (FILE * file, tracestruct * trace); 71 | 72 | extern void 73 | free_tracestruct (tracestruct * trace); 74 | #endif 75 | -------------------------------------------------------------------------------- /src/crossdisp_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * File: crossdisp_utils.h 4 | * @author Martin Kuemmel 5 | * @package crossdisp_utils 6 | * @version $Revision: 1.3 $ 7 | * @date $Date: 2010-06-15 09:48:34 $ 8 | */ 9 | #ifndef _CROSSDISP_UTILS_H 10 | #define _CROSSDISP_UTILS_H 11 | 12 | 13 | #include "spc_trace_functions.h" 14 | #include 15 | #include 16 | #include 17 | #include "aXe_grism.h" 18 | #include "aXe_utils.h" 19 | #include 20 | #include "trace_conf.h" 21 | 22 | /** 23 | * Structure: drz_pars 24 | * A description of an ellipse with a,b, theta. 25 | */ 26 | typedef struct 27 | { 28 | gsl_matrix *coeffs; 29 | d_point offset; 30 | px_point npixels; 31 | } 32 | drz_pars; 33 | 34 | int 35 | drizzle_distort(const gsl_vector * x, void *params, gsl_vector * f); 36 | 37 | 38 | d_point 39 | undistort_point(gsl_matrix *coeffs, const px_point pixmax, 40 | d_point xy_image); 41 | 42 | d_point 43 | distort_point(gsl_matrix *coeffs, const px_point pixmax, d_point xy_image); 44 | 45 | extern gsl_matrix * 46 | get_crossdisp_matrix(char * filename, int sci_numext); 47 | 48 | extern d_point 49 | get_axis_scales(beam actbeam, gsl_matrix * drzcoeffs, px_point pixmax); 50 | 51 | extern double 52 | get_crossdisp_scale(trace_func *trace, d_point refpnt, gsl_matrix * drzcoeffs, px_point pixmax); 53 | 54 | extern d_point 55 | get_drz_position(d_point in_point, gsl_matrix * drzcoeffs, px_point pixmax); 56 | 57 | extern d_point 58 | get_drz_position_free(d_point in_point, gsl_matrix * drzcoeffs, px_point pix_in, px_point pix_out); 59 | 60 | extern trace_func * 61 | get_tracefunc_at(char *filename, d_point p); 62 | 63 | extern double 64 | evaln(double x, double y, gsl_matrix * drzcoeffs, int row); 65 | 66 | extern double 67 | devalndx(double x, double y, gsl_matrix * drzcoeffs, int row); 68 | 69 | extern double 70 | devalndy(double x, double y, gsl_matrix * drzcoeffs, int row); 71 | 72 | extern gsl_matrix * 73 | get_jacobian(int i, int j, gsl_matrix * drzcoeffs, int width, int height); 74 | 75 | extern double 76 | get_det_jacobian(int i, int j, gsl_matrix * drzcoeffs, int width, int height); 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/spc_fluxcube.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_fluxcube.h 3 | * Header file for spc_fluxcube.c 4 | * 5 | * @author Martin Kuemmel 6 | * @package spc_fluxcube 7 | * @version 1.0 8 | */ 9 | 10 | #ifndef _SPC_FLUXCUBE_H 11 | #define _SPC_FLUXCUBE_H 12 | 13 | 14 | typedef struct 15 | { 16 | double wavelength; // the wavelength of the flux image 17 | gsl_matrix *flux; // the pixel values in the flux image 18 | } 19 | flux_image; 20 | 21 | typedef struct 22 | { 23 | int xoffs; // x-pixel offset between flt and fluxcube image 24 | int yoffs; // y-pixel offset between flt and fluxcube image 25 | int n_fimage; // the number of flux images 26 | gsl_matrix_int *segmentation; // the segmentation image 27 | flux_image **fluxims; // the flux images 28 | gsl_vector_int *fimage_order; // vector with the indices of the fluximages 29 | } 30 | flux_cube; 31 | 32 | extern flux_cube * 33 | load_fluxcube(const char fcube_file[]); 34 | 35 | extern flux_cube * 36 | alloc_fluxcube(const int nflux); 37 | 38 | extern int 39 | load_offsets(const char fcube_file[], flux_cube *fcube); 40 | 41 | extern gsl_matrix_int * 42 | load_segmentation(const char fcube_file[]); 43 | 44 | extern flux_image * 45 | load_fluximage(const char fcube_file[], int hdunum); 46 | 47 | extern gsl_vector_int * 48 | order_fluxims(flux_cube *fcube); 49 | 50 | extern void 51 | free_fluxcube(flux_cube *fcube); 52 | 53 | extern void 54 | free_fluximage(flux_image *fimage); 55 | 56 | extern d_point 57 | flt_to_fcube_trans(const flux_cube *fcube,const d_point point); 58 | 59 | extern d_point 60 | fcube_to_flt_trans(const flux_cube *fcube,const d_point point); 61 | 62 | extern dirobject ** 63 | fluxcube_to_dirlist(const flux_cube *fcube, object **oblist); 64 | 65 | extern dirobject * 66 | dirobject_from_segpoint(const px_point point, const object *obj); 67 | 68 | extern void 69 | update_dirobject(dirobject *actdir, const px_point fcube_point); 70 | 71 | extern void 72 | fill_xy_offsets(dirobject **dirlist, char CONF_file[]); 73 | 74 | extern void 75 | fill_fluxvalues(const flux_cube *fcube, const px_point point, 76 | dirobject *actdir, const int inter_type); 77 | 78 | extern void 79 | print_fluxcube(const flux_cube *fcube); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/spce_binning.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spce_binning.h 3 | * The interface to the binning and weight routines 4 | * 5 | * @author Martin Kuemmel, Nor Pirzkal, Markus Demleitner 6 | * @package spce_binning 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef _SPCE_BINNING_H 11 | #define _SPCE_BINNING_H 1 12 | 13 | #include 14 | #include 15 | #include "spce_output.h" 16 | #include "spc_trace_functions.h" 17 | #include "aXe_grism.h" 18 | #include "spc_spc.h" 19 | 20 | 21 | /** 22 | defines a pixel for weighting purposes. Here, p0, p1, p2, p3 are 23 | the coordinates of the points where the square first contribute, 24 | where its contribution becomes constant, where it slopes down again, 25 | and where it doesn't contribute any more. For example, a pixel at (0,0) 26 | viewed at from a side has p0=p1=0, p2=p3=1, whereas the same pixel 27 | viewed from a corner has p0=-1, p1=p2=0, p3=1; slope is the 28 | ascent on the non-constant parts, fmax the maximum contribution. 29 | angle is the angle viewing. Its tangent tana or its cotangent 30 | cota may be undefined for certain viewing angles. The function 31 | weight_function is selected such that this is unimportatnt. 32 | x0, y0, and size are the coordinates of the lower left corner and 33 | the size of the square. 34 | */ 35 | typedef struct w_pixel_s 36 | { 37 | double p0, p1, p2, p3; 38 | double angle; 39 | double tana, cota; 40 | double x0, y0, size; 41 | double fmax, slope; 42 | double (*weight_function) (const double x1, const double y1, 43 | const double x2, const double y2, 44 | const struct w_pixel_s * const pix); 45 | } 46 | w_pixel; 47 | 48 | extern spectrum * 49 | bin_naive (const ap_pixel * const ap_p, const double ob_width, 50 | const double ob_orient, const int quant_cont); 51 | 52 | extern spectrum * 53 | bin_weighted (const ap_pixel * const ap_p, const double ob_orient, 54 | const trace_func * const trace, const int n_sub, 55 | const int flags); 56 | 57 | extern spectrum * 58 | bin_optimal (const ap_pixel * const ap_p, const beam curbeam, 59 | const int quant_cont, const gsl_matrix *weights, 60 | const drzstamp_dim dimension, gsl_matrix *coverage); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([aXe], [2.6], [help@stsci.edu]) 6 | AC_CONFIG_AUX_DIR(config) 7 | AC_CONFIG_SRCDIR([config.h.in]) 8 | AC_CONFIG_HEADERS([config.h]) 9 | 10 | AM_INIT_AUTOMAKE([foreign]) 11 | 12 | # Checks for programs. 13 | AC_PROG_CC 14 | AC_PROG_LIBTOOL 15 | 16 | # Checks for libraries. 17 | AC_ARG_WITH(gsl, [AS_HELP_STRING([--with-gsl], [path to gsl])]) 18 | AS_IF([test "x$with_gsl" != "xno"], [ 19 | GSL="$withval" 20 | ]) 21 | 22 | 23 | AC_ARG_WITH(cfitsio, [AS_HELP_STRING([--with-cfitsio], [path to cfitsio])]) 24 | AS_IF([test "x$with_cfitsio" != "xno"], [ 25 | CFITSIO="$withval" 26 | ]) 27 | 28 | AC_ARG_WITH(wcstools, [AS_HELP_STRING([--with-wcstools], [path to wcstools])]) 29 | AS_IF([test "x$with_wcstools" != "xno"], [ 30 | if test ! -d "$withval"; then 31 | AC_MSG_ERROR([--with-wcstools requires a directory prefix]) 32 | fi 33 | 34 | WCSTOOLS="$withval" 35 | ]) 36 | 37 | if test "x$GSL" != "x"; then 38 | GSL_LIBS=`$GSL/bin/gsl-config --libs` 39 | GSL_CFLAGS=`$GSL/bin/gsl-config --cflags` 40 | else 41 | PKG_CHECK_MODULES([GSL], [gsl >= 1]) 42 | fi 43 | 44 | if test "x$CFITSIO" != "x"; then 45 | CFITSIO_LIBS="-L$CFITSIO/lib -lcfitsio -lpthread" 46 | CFITSIO_CFLAGS="-I$CFITSIO/include" 47 | else 48 | PKG_CHECK_MODULES([CFITSIO], [cfitsio >= 3]) 49 | fi 50 | 51 | if test "x$WCSTOOLS" != "x"; then 52 | WCSTOOLS_LIBS="-L$WCSTOOLS/lib -lwcs" 53 | WCSTOOLS_CFLAGS="-I$WCSTOOLS/include" 54 | LDFLAGS="$LDFLAGS $WCSTOOLS_LIBS" 55 | CFLAGS="$CFLAGS $WCSTOOLS_CFLAGS" 56 | else 57 | AC_MSG_ERROR([wcstools does not support pkg-config; use --with-wcstools=/path/to/wcstools]) 58 | fi 59 | 60 | 61 | # Checks for header files. 62 | AC_CHECK_HEADERS([limits.h stddef.h stdlib.h string.h unistd.h]) 63 | 64 | # Checks for typedefs, structures, and compiler characteristics. 65 | AC_TYPE_SIZE_T 66 | AC_CHECK_HEADER_STDBOOL 67 | 68 | # Checks for library functions. 69 | AC_FUNC_MALLOC 70 | AC_FUNC_STRTOD 71 | AC_CHECK_FUNCS([floor pow rint sqrt strchr strdup strstr strtol]) 72 | 73 | AC_CONFIG_FILES([Makefile src/Makefile]) 74 | AC_OUTPUT 75 | -------------------------------------------------------------------------------- /src/inima_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: inima_utils.h 3 | * Header file for inima_utils.c 4 | * 5 | * @author Martin Kuemmel 6 | * @package inima_utils 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef _INIMA_UTILS_H 11 | #define _INIMA_UTILS_H 12 | 13 | #define MAXCHAR 255 14 | //#define LINE_LEN_MAX 1280 15 | 16 | /* 17 | * Struct: basic_input 18 | */ 19 | typedef struct 20 | { 21 | char grism_file[MAXCHAR]; 22 | char config_file[MAXCHAR]; 23 | char dirima_file[MAXCHAR]; 24 | char iol_cat[MAXCHAR]; 25 | double dmag; 26 | } 27 | basic_input; 28 | 29 | /* 30 | * Struct: axe_inputs 31 | */ 32 | typedef struct 33 | { 34 | int nitems; 35 | basic_input *axe_items; 36 | } 37 | axe_inputs; 38 | 39 | 40 | /* 41 | * Struct: char_array 42 | */ 43 | typedef struct 44 | { 45 | int nitems; 46 | char **char_items; 47 | } 48 | char_array; 49 | 50 | extern axe_inputs * 51 | get_axe_inputs(char inima[], char confterm[]); 52 | 53 | extern void 54 | copy_basic_input(char_array *line_array, char_array *iol_array, 55 | char_array *conf_array, int arr_index, int dirim_col, 56 | int dmag_col, basic_input *axe_item); 57 | 58 | extern axe_inputs * 59 | extract_axe_inputs(char inima[], char confterm[], int nrows, int nmult, int dirim_col, 60 | int conf_col, int dmag_col); 61 | 62 | extern void 63 | get_inima_cols(char inima[], int *dirim_col, 64 | int *conf_col, int *dmag_col, int *nmult); 65 | 66 | extern void 67 | get_inlist_basics(char inima[], int *nrows, int *ncols); 68 | 69 | extern char_array * 70 | get_items(char input_line[], char tokens[]); 71 | 72 | extern int 73 | is_valid_inima_line(char input_line[]); 74 | 75 | extern int 76 | get_ntokens(char input_line[], char tokens[]); 77 | 78 | extern char_array * 79 | alloc_char_array(int nitems); 80 | 81 | extern void 82 | free_char_array(char_array *an_array); 83 | 84 | extern void 85 | print_char_array(char_array *an_array); 86 | 87 | extern axe_inputs * 88 | alloc_axe_inputs(int nitems); 89 | 90 | extern void 91 | free_axe_inputs(axe_inputs *in_list); 92 | 93 | extern char * 94 | trim(char inString[], char outString[]); 95 | 96 | extern void 97 | print_axe_inputs(axe_inputs *in_list); 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS = $(GSL_CFLAGS) $(CFITSIO_CFLAGS) $(WCSTOOLS_CFLAGS) 2 | AM_LDFLAGS = $(GSL_LIBS) $(CFITSIO_LIBS) $(WCSTOOLS_LIBS) 3 | 4 | suppl = spc_driz.c spc_spc.c spc_utils.c spc_sex.c \ 5 | spc_CD.c trace_conf.c spc_FITScards.c spc_resp.c \ 6 | disp_conf.c aper_conf.c spc_extract.c spce_is_in.c \ 7 | spce_sect.c spc_trace_functions.c spce_pathlength.c \ 8 | aXe_errors.c aXe_utils.c spce_binning.c \ 9 | spce_output.c spc_wl_calib.c spc_back.c \ 10 | spc_flatfield.c spc_cfg.c inout_aper.c \ 11 | spce_fitting.c spce_PET.c aper_check.c \ 12 | drizzle_utils.c drz2pet_utils.c crossdisp_utils.c \ 13 | spc_model.c model_utils.c spc_fluxcube.c \ 14 | spc_optimum.c fringe_conf.c fringe_model.c \ \ 15 | fringe_utils.c trfit_utils.c lm_eval.c lmmin.c \ 16 | ipixcorr_utils.c inima_utils.c nicback_utils.c \ 17 | specmodel_utils.c dirimage_model.c scaleback_utils.c 18 | 19 | bin_PROGRAMS = aXe_SEX2GOL \ 20 | aXe_GOL2AF \ 21 | aXe_AF2PET \ 22 | aXe_BE \ 23 | aXe_PET2SPC \ 24 | aXe_STAMPS \ 25 | aXe_DRZPREP \ 26 | aXe_PETCONT \ 27 | aXe_PETFF \ 28 | aXe_DRZ2PET \ 29 | aXe_GPS \ 30 | aXe_FILET \ 31 | aXe_FRIGEN \ 32 | aXe_FRINGECORR \ 33 | aXe_TFIT \ 34 | aXe_INTPIXCORR \ 35 | aXe_PETIPC \ 36 | aXe_NICBACK \ 37 | aXe_TEST \ 38 | aXe_DIRIMAGE \ 39 | aXe_SCALEBCK 40 | 41 | aXe_SEX2GOL_SOURCES = aXe_SEX2GOL.c $(suppl) 42 | aXe_GOL2AF_SOURCES = aXe_GOL2AF.c $(suppl) 43 | aXe_AF2PET_SOURCES = aXe_AF2PET.c $(suppl) 44 | aXe_BE_SOURCES = aXe_BE.c $(suppl) 45 | aXe_PET2SPC_SOURCES = aXe_PET2SPC.c $(suppl) 46 | aXe_STAMPS_SOURCES = aXe_STAMPS.c $(suppl) 47 | aXe_DRZPREP_SOURCES = aXe_DRZPREP.c $(suppl) 48 | aXe_PETCONT_SOURCES = aXe_PETCONT.c $(suppl) 49 | aXe_PETFF_SOURCES = aXe_PETFF.c $(suppl) 50 | aXe_DRZ2PET_SOURCES = aXe_DRZ2PET.c $(suppl) 51 | aXe_GPS_SOURCES = aXe_GPS.c $(suppl) 52 | aXe_FILET_SOURCES = aXe_FILET.c $(suppl) 53 | aXe_FRIGEN_SOURCES = aXe_FRIGEN.c $(suppl) 54 | aXe_FRINGECORR_SOURCES = aXe_FRINGECORR.c $(suppl) 55 | aXe_TFIT_SOURCES = aXe_TFIT.c $(suppl) 56 | aXe_INTPIXCORR_SOURCES = aXe_INTPIXCORR.c $(suppl) 57 | aXe_PETIPC_SOURCES = aXe_PETIPC.c $(suppl) 58 | aXe_NICBACK_SOURCES = aXe_NICBACK.c $(suppl) 59 | aXe_TEST_SOURCES = aXe_TEST.c $(suppl) 60 | aXe_DIRIMAGE_SOURCES = aXe_DIRIMAGE.c $(suppl) 61 | aXe_SCALEBCK_SOURCES = aXe_SCALEBCK.c $(suppl) 62 | 63 | -------------------------------------------------------------------------------- /src/spc_spc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_spc.h 3 | * @author Nor Pirzkal 4 | * @package spc_spc 5 | * @version $Revision: 1.3 $ 6 | * @date $Date: 2010-06-15 09:48:34 $ 7 | */ 8 | 9 | #ifndef _SPC_SPC_H 10 | 11 | #define _SPC_SPC_H 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "aXe_grism.h" 19 | #include "aXe_utils.h" 20 | #include 21 | #include 22 | #include 23 | 24 | #define SPCTOL 1.0e-5 25 | 26 | // interpolation type used for the 27 | // response function 28 | #define RESP_FUNC_INTERP_TYPE gsl_interp_linear 29 | 30 | extern spectrum * 31 | allocate_spectrum (const int numbin); 32 | 33 | extern void 34 | free_spectrum (spectrum * const spec); 35 | 36 | extern void 37 | fprintf_spectrum (FILE * output, const spectrum * const sp); 38 | 39 | extern spectrum * 40 | subtract_spectra (spectrum * a, spectrum * b); 41 | 42 | extern int 43 | get_ID_index_to_SPC (char filename[], char ID[]); 44 | 45 | extern void 46 | add_ID_index_to_SPC (char filename[], char ID[], int hdunum); 47 | 48 | extern int 49 | add_ID_to_SPC (char filename[], int N, char ID[]); 50 | 51 | extern int 52 | find_ID_in_SPC (char filename[], char ID[]); 53 | 54 | extern void 55 | create_SPC (char filename[], int overwrite); 56 | 57 | extern int 58 | get_SPC_colnum (fitsfile * input, char colname[]); 59 | 60 | extern void 61 | add_spectra_to_SPC (char filename[], spectrum * obj_spec, 62 | spectrum * bck_spec, spectrum * sobj_spec, 63 | int aperID, int beamID); 64 | 65 | extern void 66 | add_data_to_SPC (spectrum * spec, char countcolname[], 67 | char errorcolname[], char weightcolname[], char ID[], 68 | char filename[], int hdunum, long N); 69 | 70 | extern spectrum * 71 | trim_spectrum (spectrum * spc); 72 | 73 | extern spectrum * 74 | empty_counts_spectrum_copy (spectrum * a); 75 | 76 | extern void 77 | add_ID_to_SPC_opened (fitsfile *output, int N, char ID[]); 78 | 79 | extern void 80 | add_spectra_to_SPC_opened (fitsfile *input, spectrum * obj_spec, 81 | spectrum * bck_spec, spectrum * sobj_spec, 82 | int aperID, int beamID); 83 | 84 | extern void 85 | add_data_to_SPC_opened (spectrum * spec, char countcolname[], 86 | char errorcolname[], char weightcolname[], 87 | char ID[], fitsfile *input, long N); 88 | 89 | extern fitsfile * 90 | create_SPC_opened (char filename[], int overwrite); 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /src/lmmin.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: lmmin.h 3 | * @package lmmin 4 | * @version $Revision: 1.2 $ 5 | * @date $Date: 2010-06-15 09:48:34 $ 6 | * 7 | */ 8 | // parameters for calling the high-level interface lmfit 9 | // ( lmfit.c provides lm_initialize_control which sets default values ): 10 | typedef struct { 11 | double ftol; // relative error desired in the sum of squares. 12 | double xtol; // relative error between last two approximations. 13 | double gtol; // orthogonality desired between fvec and its derivs. 14 | double epsilon; // step used to calculate the jacobian. 15 | double stepbound; // initial bound to steps in the outer loop. 16 | double fnorm; // norm of the residue vector fvec. 17 | int maxcall; // maximum number of iterations. 18 | int nfev; // actual number of iterations. 19 | int info; // status of minimization. 20 | } lm_control_type; 21 | 22 | 23 | // the subroutine that calculates fvec: 24 | typedef void (lm_evaluate_ftype) ( 25 | double* par, int m_dat, double* fvec, void *data, int *info ); 26 | 27 | // default implementation therof, provided by lm_eval.c: 28 | void lm_evaluate_default ( 29 | double* par, int m_dat, double* fvec, void *data, int *info ); 30 | 31 | // the subroutine that informs about fit progress: 32 | typedef void (lm_print_ftype) ( 33 | int n_par, double* par, int m_dat, double* fvec, void *data, 34 | int iflag, int iter, int nfev ); 35 | // default implementation therof, provided by lm_eval.c: 36 | void lm_print_default ( 37 | int n_par, double* par, int m_dat, double* fvec, void *data, 38 | int iflag, int iter, int nfev ); 39 | 40 | // compact high-level interface: 41 | void lm_initialize_control( lm_control_type *control ); 42 | void lm_minimize ( int m_dat, int n_par, double* par, 43 | lm_evaluate_ftype *evaluate, lm_print_ftype *printout, 44 | void *data, lm_control_type *control ); 45 | double lm_enorm( int, double* ); 46 | 47 | // low-level interface for full control: 48 | void lm_lmdif( int m, int n, double* x, double* fvec, double ftol, double xtol, 49 | double gtol, int maxfev, double epsfcn, double* diag, int mode, 50 | double factor, int *info, int *nfev, 51 | double* fjac, int* ipvt, double* qtf, 52 | double* wa1, double* wa2, double* wa3, double* wa4, 53 | lm_evaluate_ftype *evaluate, lm_print_ftype *printout, 54 | void *data ); 55 | 56 | 57 | #ifndef _LMDIF 58 | extern char *lm_infmsg[]; 59 | extern char *lm_shortmsg[]; 60 | #endif 61 | -------------------------------------------------------------------------------- /src/aper_check.c: -------------------------------------------------------------------------------- 1 | /** 2 | * File: aper_check.c 3 | * APER_CHECK - create a FITS image showing the locations of 4 | * apertures. 5 | * 6 | * @author Martin Kuemmel, Markus Demleitner, Nor Pirzkal 7 | * @package aper_check 8 | * @version $Revision: 1.3 $ 9 | * @date $Date: 2010-06-15 09:48:34 $ 10 | */ 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "aXe_grism.h" 18 | #include "aper_check.h" 19 | 20 | 21 | void mark_trace_in_aXe_mask(ap_pixel * ap_p, aXe_mask *mask) 22 | { 23 | gsl_vector_int *trace_inds; 24 | int i, ind; 25 | 26 | trace_inds = (gsl_vector_int *) get_trace_inds (ap_p); 27 | 28 | 29 | for (i = 0; i < trace_inds->size; i++) 30 | { 31 | ind = gsl_vector_int_get (trace_inds, i); 32 | fprintf(stderr,"%d %d\n",ap_p[ind].p_x,ap_p[ind].p_y); 33 | } 34 | 35 | gsl_vector_int_free(trace_inds); 36 | } 37 | 38 | /** 39 | Function to create and return a gsl array of the same size as the grism 40 | part of n observation structure. 41 | 42 | @param ob a pointer to an observation structure 43 | @return a pointer to a newly allocated aXe_mask structure 44 | 45 | */ 46 | aXe_mask * 47 | aXe_mask_init (observation * ob) 48 | { 49 | aXe_mask *mask; 50 | long i,j; 51 | double v; 52 | 53 | /* Allocated space for the mask array */ 54 | mask = (aXe_mask *) malloc (sizeof (aXe_mask)); 55 | if (!mask) 56 | { 57 | aXe_message (aXe_M_FATAL, __FILE__, __LINE__, "Out of memory."); 58 | } 59 | 60 | /* Create the GSL image array */ 61 | mask->img = gsl_matrix_alloc (ob->grism->size1, ob->grism->size2); 62 | // fprintf(stderr,"%ld %ld\n",ob->grism->size1,ob->grism->size2); 63 | 64 | /* Initialise the mask array */ 65 | for (i=0;igrism->size1;i++) { 66 | for (j=0;jgrism->size2;j++) { 67 | v = gsl_matrix_get(ob->grism,i,j); 68 | gsl_matrix_set(mask->img, i,j, v); 69 | 70 | } 71 | } 72 | 73 | //gsl_matrix_set_all (mask->img, 1.0); 74 | 75 | return mask; 76 | } 77 | 78 | /** 79 | * This function sets all the pixels listed in an ap_pixel list 80 | * in an aXe_mask to 0.0 81 | 82 | @param a pointer to a ap_pixel array 83 | @param mask an existing aXe_mask structure 84 | 85 | */ 86 | void 87 | add_ap_p_to_aXe_mask (ap_pixel * ap_p, aXe_mask * mask) 88 | { 89 | ap_pixel *cur_p; 90 | 91 | if (ap_p==NULL) return; 92 | 93 | for (cur_p = ap_p; cur_p->p_x != -1; cur_p++) 94 | { 95 | 96 | /* Loop over pixels which are valid */ 97 | if (!isnan (cur_p->count)) 98 | { 99 | // fprintf(stderr,"%d %d\n",cur_p->p_x, cur_p->p_y); 100 | 101 | gsl_matrix_set (mask->img, cur_p->p_x, cur_p->p_y, 0.0); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/disp_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: disp_conf.h 3 | * Header file for the code in "disp_conf.c" 4 | * 5 | * @author Martin Kuemmel, Markus Demleitner, Nor Pirzkal 6 | * @package disp_conf 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | 11 | #ifndef _DISP_CONF_H 12 | 13 | #define _DISP_CONF_H 14 | 15 | 16 | /** 17 | * A structure to contain the coefficient of a 2D 18 | * polynomial that can be used to compute the given 19 | * coefficient of the polynomial dispersion relation 20 | * as at a particular i.j location in the image 21 | */ 22 | typedef struct 23 | { 24 | gsl_vector *pol; /* A vector containing the 2D polynomial coefficients */ 25 | int for_grism; /* If true, pol is of form sum(a_i x^i, i=0..order) 26 | otherwise, it is of form sum(a_i 1/x^i, i=0..order) */ 27 | d_point cpoint; /* The detector location at which this structure 28 | was computed */ 29 | int ID; /* The ID of the beam for which this coefficient 30 | is defined */ 31 | char file[MAXCHAR]; 32 | } 33 | dispstruct; 34 | 35 | typedef struct 36 | { 37 | char file[MAXCHAR]; 38 | 39 | int ID; 40 | int for_grism; 41 | 42 | int n_order; 43 | gsl_vector **all_coeffs; 44 | } 45 | global_disp; 46 | 47 | extern float 48 | get_beam_mmag_extract (char *filename, int beamID); 49 | 50 | extern float 51 | get_beam_mmag_mark (char *filename, int beamID); 52 | 53 | extern int 54 | get_beam_disp_norder (char *filename, int beamID); 55 | 56 | extern gsl_vector * 57 | get_beam_disp_order (char *filename, const int for_grism, 58 | int beamID, int order); 59 | 60 | extern float 61 | get_disp_coeff_at_pos (char *filename, const int for_grism, int beamID, 62 | int order, d_point p); 63 | 64 | extern gsl_vector * 65 | get_disp_coeffs_at_pos (char *filename, const int for_grism, 66 | int beamID, d_point p); 67 | extern void 68 | free_dispstruct(dispstruct *p); 69 | 70 | extern dispstruct * 71 | get_dispersion_at_pos (char *filename, int beamID, d_point p); 72 | 73 | extern void 74 | dispstruct_fprintf (FILE * file, dispstruct * disp); 75 | 76 | extern dispstruct * 77 | get_dispstruct_at_pos (char *filename, const int for_grism, 78 | int beamID, d_point p); 79 | 80 | extern int 81 | check_for_grism (char *filename, int beamID); 82 | 83 | extern int 84 | check_disp_coeff (char *filename,const int for_grism,int beamID,int order); 85 | 86 | extern gsl_vector * 87 | get_prange (char *filename, int beamID); 88 | 89 | extern global_disp * 90 | get_global_disp(char *filename, const int for_grism, int beamID); 91 | 92 | extern gsl_vector * 93 | get_calvector_from_gdisp(const global_disp *gdisp, const d_point p); 94 | 95 | extern double 96 | get_2Ddep_value(const gsl_vector *coeffs, const d_point p); 97 | 98 | extern void 99 | print_global_disp(const global_disp *gdisp); 100 | 101 | extern int 102 | check_disp_order(const gsl_vector *tmp, const int beamID, const int order); 103 | 104 | extern void 105 | free_global_disp(global_disp *gdisp); 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /src/drizzle_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * File: drizzle_utils.h 4 | * Subroutines to calculate the 5 | * drizzle coefficients. 6 | * 7 | * @author Martin Kuemmel 8 | * @package drizzleutils 9 | * @version $Revision: 1.4 $ 10 | * @date $Date: 2010-06-15 09:48:34 $ 11 | */ 12 | 13 | #ifndef _DRIZZLE_UTILS_H 14 | #define _DRIZZLE_UTILS_H 15 | 16 | 17 | #define NMAXOBS 1100 18 | #define NMAXOBJ 20000 19 | 20 | #define DRZMAX 0 21 | 22 | typedef struct 23 | { 24 | int OBJID; 25 | int nobs; 26 | int max_width; 27 | int max_height; 28 | int pointer; 29 | int max_tlength; 30 | double owidthmax; 31 | double cdrefscale; 32 | double cdmeanscale; 33 | double sprefreso; 34 | double spmeanreso; 35 | d_point mean_refpoint; 36 | int width[NMAXOBS]; 37 | int height[NMAXOBS]; 38 | int tlength[NMAXOBS]; 39 | double objwidth[NMAXOBS]; 40 | double orient[NMAXOBS]; 41 | double cdscale[NMAXOBS]; 42 | double spreso[NMAXOBS]; 43 | d_point refpoint[NMAXOBS]; /* Pixel coordinates of the reference point */ 44 | d_point relrefpt[NMAXOBS]; 45 | } 46 | objectobs; 47 | 48 | gsl_matrix *get_drizzle_coeffs(dispstruct * disp, trace_func * trace, 49 | int boxwidth, int boxheight, int trlength, 50 | double relx, double rely, aperture_conf *conf, 51 | double orient, dispstruct * outdisp, 52 | double cdcorr, double spref,double spmeanreso); 53 | gsl_matrix *get_coeffs_back(trace_func * trace); 54 | double get_rotation_angle(double dxdy); 55 | int add_observation(char * filename, char * conf_file, 56 | objectobs **allobjects, int nobjects, object ** oblist, 57 | int list_size, px_point pixmax, int sci_numext); 58 | void add_obs_to_allobj(objectobs * actobject, object * actobs, px_point pixmax, 59 | double cdscale, double spreso, int tlength); 60 | int add_obj_to_allobj(objectobs **allobjects, int nobjects, object * actobs, 61 | px_point pixmax, double cdscale, double spreso, int tlength); 62 | int make_refpoints(char * conf_file, char * filename, px_point pixmax, 63 | objectobs **allobjects, int nobjects); 64 | d_point get_mean_refpoint(objectobs **allobjects, int nobjects, int ID, 65 | int * boxwidth, int * boxheight, double * relx, 66 | double * rely, double * objwidth, double * orient, 67 | double * cdref, double * cdscale, 68 | double * cdmeanscale, double *sprefreso, 69 | double *spreso, double *spmeanreso, int *tlength); 70 | px_point recalc_bbox(int xmin, int xmax, int ymin, int ymax, px_point pixmax); 71 | px_point recalc_mins(int xmin, int xmax, int ymin, int ymax, px_point pixmax); 72 | d_point get_refwave_position(dispstruct * disp, trace_func * trace, 73 | d_point refpix, aperture_conf *conf); 74 | double get_drizzle_width(object *ob, int beamnum,trace_func * trace); 75 | objectobs **malloc_objectobs(); 76 | void free_objectobs(objectobs **allobjects); 77 | void print_objectobs(objectobs **allobjects, int nobjects); 78 | void print_objectobs2(objectobs allobjects[], int nobjects); 79 | 80 | extern int 81 | get_beam_trace_length(const beam actbeam); 82 | #endif 83 | -------------------------------------------------------------------------------- /src/aXe_FILET2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: aXe_FILET2.c 3 | * $Revision: 1.2 $ $Date: 2010-06-15 09:48:34 $ 4 | * ST-ECF - Space Telescope European Coordinating Facility 5 | * Martin Kuemmel 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | #include 22 | #include "fitsio.h" 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | fitsfile *infptr, *outfptr1, *outfptr2, *outfptr3; /* FITS file pointers defined in fitsio.h */ 27 | int status = 0, ii = 1; /* status must always be initialized = 0 */ 28 | int hdu_start=0; 29 | 30 | hdu_start = atoi(argv[2]); 31 | 32 | /* Open the input file */ 33 | if ( !fits_open_file(&infptr, argv[1], READONLY, &status) ) 34 | { 35 | /* Create the output file */ 36 | fits_create_file(&outfptr1, argv[3], &status); 37 | if (status){ 38 | fits_report_error(stderr, status); 39 | return(status);} 40 | fits_movabs_hdu(infptr, hdu_start, NULL, &status); 41 | if (status){ 42 | fits_report_error(stderr, status); 43 | return(status);} 44 | fits_copy_hdu(infptr, outfptr1, 0, &status); 45 | if (status){ 46 | fits_report_error(stderr, status); 47 | return(status);} 48 | fits_close_file(outfptr1, &status); 49 | if (status){ 50 | fits_report_error(stderr, status); 51 | return(status);} 52 | 53 | fits_create_file(&outfptr2, argv[4], &status); 54 | if (status){ 55 | fits_report_error(stderr, status); 56 | return(status);} 57 | fits_movrel_hdu (infptr, 1, NULL, &status); 58 | if (status){ 59 | fits_report_error(stderr, status); 60 | return(status);} 61 | fits_copy_hdu(infptr, outfptr2, 0, &status); 62 | if (status){ 63 | fits_report_error(stderr, status); 64 | return(status);} 65 | fits_close_file(outfptr2, &status); 66 | if (status){ 67 | fits_report_error(stderr, status); 68 | return(status);} 69 | 70 | fits_create_file(&outfptr3, argv[5], &status); 71 | if (status){ 72 | fits_report_error(stderr, status); 73 | return(status);} 74 | fits_movrel_hdu (infptr, 1, NULL, &status); 75 | if (status){ 76 | fits_report_error(stderr, status); 77 | return(status);} 78 | fits_copy_hdu(infptr, outfptr3, 0, &status); 79 | if (status){ 80 | fits_report_error(stderr, status); 81 | return(status);} 82 | fits_close_file(outfptr3, &status); 83 | if (status){ 84 | fits_report_error(stderr, status); 85 | return(status);} 86 | 87 | fits_close_file(infptr, &status); 88 | } 89 | 90 | /* if error occured, print out error message */ 91 | if (status) fits_report_error(stderr, status); 92 | return(status); 93 | } 94 | -------------------------------------------------------------------------------- /src/specmodel_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: specmodel_utils.h 3 | * Header file for specmodel_utils.c 4 | * 5 | * @author Martin Kuemmel 6 | * @package specmodel_utils 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef _SPECMODEL_UTILS_H 11 | #define _SPECMODEL_UTILS_H 12 | 13 | // interpolation type used for the 14 | // spectral models 15 | #define SMODEL_INTERP_TYPE gsl_interp_linear 16 | 17 | /* 18 | * Struct: energy_distrib 19 | */ 20 | typedef struct 21 | { 22 | int npoints; 23 | double *wavelength; 24 | double *flux; 25 | 26 | gsl_interp *interp; 27 | gsl_interp_accel *accel; 28 | 29 | } 30 | energy_distrib; 31 | 32 | /* 33 | * Struct: spectral_models 34 | */ 35 | typedef struct 36 | { 37 | int n_models; 38 | 39 | energy_distrib **SEDlist; 40 | } 41 | spectral_models; 42 | 43 | typedef struct 44 | { 45 | int dim_x; // the number of pixels in x-direction 46 | int dim_y; // the number of pixels in y-direction 47 | double xmean; // mean x-coordinate of the object 48 | double ymean; // mean y-coordinate of the object 49 | 50 | gsl_matrix *modimage; // matrix with the direct image 51 | } 52 | dirim_emission; 53 | 54 | typedef struct 55 | { 56 | int n_models; // the number of direct image object 57 | 58 | dirim_emission **obj_list; // the list of direct image objects 59 | } 60 | object_models; 61 | 62 | extern object_models * 63 | load_object_models(const char object_models_file[]); 64 | 65 | extern dirim_emission ** 66 | load_diremission_list(const char object_models_file[], const n_models); 67 | 68 | extern dirim_emission * 69 | load_diremission(const char object_models_file[], const int n_extension); 70 | 71 | extern void 72 | free_object_models(object_models *objmodels); 73 | 74 | extern void 75 | free_dirim_emission(dirim_emission *diremission); 76 | 77 | extern void 78 | print_object_models(const object_models *objmodels); 79 | 80 | extern void 81 | print_dirim_emission(const dirim_emission *diremission); 82 | 83 | extern dirim_emission * 84 | get_dirim_emission(const object_models *objmodels, const int objspec); 85 | 86 | extern int 87 | has_aperture_dirim(const object_models *objmodels, const object *actobject); 88 | 89 | extern double 90 | get_diremission_value(const dirim_emission *diremission, 91 | const double xpos, const double ypos); 92 | 93 | extern double 94 | bilin_interp_matrix(const gsl_matrix *modimage, const double x, const double y); 95 | 96 | extern spectral_models * 97 | load_spectral_models(const char spectral_models_file[]); 98 | 99 | extern void 100 | print_spectral_models(const spectral_models *smodels); 101 | 102 | extern energy_distrib ** 103 | load_SED_list(const char spectral_models_file[], const int n_models); 104 | 105 | extern energy_distrib * 106 | load_SED_from_fitsext(const char spectral_models_file[], fitsfile *s_models); 107 | 108 | extern int 109 | get_num_extensions(const char spectral_models_file[]); 110 | 111 | extern void 112 | free_spectral_models(spectral_models *smodels); 113 | 114 | extern void 115 | free_specmodels_SEDs(spectral_models *smodels); 116 | 117 | extern energy_distrib * 118 | get_model_sed(const spectral_models *spec_mod, const int modspec); 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /src/spc_model.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_model.h 3 | * Header file for spc_model.c 4 | * 5 | * @author Martin Kuemmel 6 | * @package spc_model 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | 11 | #ifndef _SPC_MODEL_H 12 | #define _SPC_MODEL_H 13 | 14 | extern int 15 | compute_gauss_cont(char grism_file[], char OAF_file[], char CONF_file[], 16 | const char specmod_file[], const double model_scale, 17 | const int inter_type, const double lambda_psf, observation *obs, 18 | const char PET_file[], char map_file[], const int store); 19 | 20 | extern int 21 | compute_gaussdirim_cont(char grism_file[], char OAF_file[], char CONF_file[], 22 | const char specmod_file[], const char objmod_file[], 23 | const double model_scale, const int inter_type, 24 | const double lambda_psf, observation *obs, 25 | const char PET_file[], char map_file[], const int store); 26 | 27 | extern int 28 | compute_gauss_dirim(char grism_file[], char OAF_file[], char CONF_file[], 29 | const double model_scale, const int inter_type, 30 | const double lambda_psf, observation *obs, 31 | const char PET_file[], char map_file[], const int store); 32 | 33 | extern int 34 | compute_fcube_cont(char grism_file[], char OAF_file[], char fcube_file[], 35 | char CONF_file[], const double model_scale, const int inter_type, 36 | observation *obs, const char PET_file[], char map_file[], 37 | const int store); 38 | 39 | extern int 40 | compute_geometr_cont(char OAF_file[], observation *obs, 41 | const char PET_file[], char map_file[], 42 | const int store); 43 | 44 | extern int 45 | fill_contam_info(const char PET_file[], beamspec **speclist, 46 | const gsl_matrix *all_models, char model_name[]); 47 | 48 | extern gsl_matrix * 49 | make_model_image(const px_point npixels, observation *obs, beamspec **speclist); 50 | 51 | extern beamspec ** 52 | make_fcube_spectra(object **oblist, dirobject **dirlist, 53 | const px_point npixels, char CONF_file[], 54 | const flux_cube *fcube, const int inter_type); 55 | 56 | extern beamspec ** 57 | alloc_beamlist_from_dirlist(object **oblist, dirobject **dirlist, 58 | const px_point npixels, aperture_conf *conf); 59 | 60 | extern gsl_matrix * 61 | make_gauss_dirim(object **oblist, dirobject **dirlist, const double lambda_psf, 62 | const px_point npixels, char CONF_file[], observation *obs); 63 | 64 | extern beamspec ** 65 | make_gauss_spectra(object **oblist, dirobject **dirlist, const double lambda_psf, 66 | const px_point npixels, char CONF_file[]); 67 | 68 | extern beamspec ** 69 | make_gauss_spectra2(object **oblist, dirobject **dirlist, const double lambda_psf, 70 | const px_point npixels, char CONF_file[]); 71 | 72 | extern int 73 | get_index_for_tracepoint(const tracedata *acttrace, const double dx); 74 | 75 | extern int 76 | fill_pixel_in_speed(const dirobject *actdir, const tracedata *acttrace, 77 | const d_point dpixel, const spectrum *resp, 78 | beamspec *actspec, const calib_function *wl_calibration); 79 | 80 | extern int 81 | no_diffuse_spectrum(int ix, int iy, double cps, beamspec *actspec); 82 | 83 | extern int 84 | diffuse_spectrum(double ddx, double ddy, double cps, beamspec *actspec); 85 | 86 | extern int 87 | diffuse_spectrumII(double ddx, double ddy, double cps, beamspec *actspec); 88 | 89 | beamspec * 90 | dimension_beamspec(dirobject *actdir, object *actobject, 91 | const px_point npixels, const aperture_conf * conf, int j); 92 | #endif 93 | -------------------------------------------------------------------------------- /src/aper_conf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * File: aper_conf.h 4 | * @author Martin Kuemmel, Markus Demleitner, Nor Pirzkal 5 | * @package aper_conf 6 | * @version $Revision: 1.3 $ 7 | * @date $Date: 2010-06-15 09:48:34 $ 8 | */ 9 | #ifndef _APER_CONF_H 10 | #define _APER_CONF_H 11 | 12 | #include "aXe_grism.h" 13 | #include "spc_cfg.h" 14 | #include "disp_conf.h" 15 | 16 | #define BCK_BEAM_EXT 1 17 | 18 | 19 | /** 20 | The basic description of a beam span 21 | and its numerical label 22 | */ 23 | typedef struct 24 | { 25 | int ID; 26 | px_offset offset; 27 | float mmag_extract; 28 | float mmag_mark; 29 | float psf_offset; 30 | } 31 | beam_conf; 32 | 33 | /** 34 | The basic description of the dispersed apertures 35 | in coordinates relative to the direct object position. 36 | Contains MAX_BEAMS beam_conf 37 | @see beam_conf 38 | */ 39 | typedef struct 40 | { 41 | char instrument[MAXCHAR]; /* Name of the instrument */ 42 | char camera[MAXCHAR]; /* Name of the camera*/ 43 | int nbeams; /* Number of beams defined */ 44 | char science_ext[MAXCHAR]; /* FITS extension name of the data */ 45 | char errors_ext[MAXCHAR]; /* FITS extension name of the error */ 46 | char dq_ext[MAXCHAR]; /* FITS extension name of the data quality */ 47 | int science_numext; /* Extension number of the data */ 48 | int errors_numext; /* Extension number of the error */ 49 | int dq_numext; /* Extension number of the data quality */ 50 | int dqmask; /* Data Quality Mask */ 51 | char exptimekey[MAXCHAR]; /* Name of EXPTIME FITS keyword */ 52 | char gainkey[MAXCHAR]; /* Name of the GAIN FITS keyword */ 53 | char optkey1[MAXCHAR]; /* optional key */ 54 | char optval1[MAXCHAR]; /* optional key value */ 55 | char FFname[MAXCHAR]; /* The name of the flatfield file */ 56 | char IPIXfunc[MAXCHAR]; /* Name of the intrapixel correction function */ 57 | int refx; /* Optional reference x pixel of the field dependence */ 58 | int refy; /* Optional reference y pixel of the field dependence */ 59 | beam_conf beam[MAX_BEAMS]; 60 | /* aXe-1.4 :*/ 61 | float drz_resol; /* The resolution in the drizzled images in [A/pixel]*/ 62 | float drz_scale; /* The scale in crossdispersion direction in "/pixel */ 63 | float drz_lamb0; /* The starting wavelength for the drizzled spectrum */ 64 | float drz_xstart; /* The x-position the starting wavelength is drizzled to */ 65 | float drz_pfrac; /* The pixfrac for the drizzling */ 66 | char drz_kernel[MAXCHAR]; /* The kernel for the drizzling */ 67 | /* aXe-1.5 :*/ 68 | gsl_vector *psfcoeffs; 69 | gsl_vector *psfrange; 70 | float rdnoise; 71 | 72 | double pobjsize; 73 | double smfactor; 74 | 75 | } 76 | aperture_conf; 77 | 78 | 79 | extern aperture_conf * 80 | get_aperture_descriptor (char *filename); 81 | 82 | extern void 83 | aperture_conf_fprintf (FILE * file, aperture_conf * conf); 84 | 85 | extern void 86 | get_extension_numbers(char filename[], aperture_conf * conf, 87 | char keyword[],char keyval[]); 88 | 89 | extern void 90 | free_aperture_conf(aperture_conf * conf); 91 | 92 | double 93 | get_psf_offset(aperture_conf * conf, const beam actbeam); 94 | 95 | double 96 | get_max_offset(aperture_conf * conf); 97 | 98 | extern void 99 | extend_config_beams(aperture_conf *conf); 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /src/spc_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_utils.h 3 | * Header file for spc_utils.c 4 | * 5 | * @author Martin Kuemmel, Nor Pirzkal 6 | * @package spc_utils 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef SPC_UTILS_H 11 | #define SPC_UTILS_H 12 | 13 | 14 | 15 | void init_search (const char *string); /* Pbmsrch.C */ 16 | char *strsearch (const char *string); /* Pbmsrch.C */ 17 | 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "aXe_errors.h" 31 | #include "aXe_grism.h" 32 | 33 | #define LAMBDACENTRAL 8000.0 34 | #define COLNAMELENGTH 12 35 | #define MAXCOLS 200 36 | 37 | /** 38 | * Structure: sexcol 39 | * Structure for a column header 40 | */ 41 | typedef struct sexcol 42 | { 43 | char name[COLNAMELENGTH]; 44 | int number; 45 | } 46 | sexcol; 47 | 48 | /** 49 | * Structure: colinfo 50 | * Structure for the table header 51 | */ 52 | typedef struct colinfo 53 | { 54 | int numcols; 55 | sexcol columns[MAXCOLS]; 56 | } 57 | colinfo; 58 | 59 | extern int 60 | is_valid_entry(double mag); 61 | 62 | extern int 63 | get_valid_entries(const gsl_vector *magnitudes); 64 | 65 | extern int 66 | check_worldcoo_input(const colinfo * actcatinfo, const int thsky); 67 | 68 | extern int 69 | check_imagecoo_input(const colinfo * actcatinfo); 70 | 71 | extern void 72 | make_GOL_header(FILE *fout, const colinfo * actcatinfo, 73 | const gsl_vector * waves, const gsl_vector * cnums, 74 | const px_point backwin_cols, const px_point modinfo_cols); 75 | 76 | extern colinfo * 77 | get_sex_col_descr (char *filename); 78 | 79 | extern double 80 | get_col_value (const colinfo * actcatinfo, const char key[], 81 | gsl_vector * v, int fatal); 82 | 83 | extern double 84 | get_col_value2 (const colinfo * actcatinfo, const char key[], 85 | gsl_vector * v, int fatal); 86 | 87 | extern int 88 | line_is_valid (const colinfo * actcatinfo, char line[]); 89 | 90 | extern int 91 | get_magauto_col(const gsl_vector *wavelength, const gsl_vector *colnums, 92 | const double lambda_mark); 93 | 94 | extern int 95 | has_magnitudes(const colinfo * actcatinfo); 96 | 97 | extern px_point 98 | has_backwindow(const colinfo * actcatinfo); 99 | 100 | extern px_point 101 | has_modelinfo(const colinfo * actcatinfo); 102 | 103 | extern int 104 | get_magcols(const colinfo * actcatinfo, gsl_vector *wavelength, 105 | gsl_vector *colnums); 106 | 107 | extern int 108 | resolve_colname(const char colname[]); 109 | 110 | extern void 111 | get_columname(const colinfo * actcatinfo, const int colnum, char colname[]); 112 | 113 | extern int 114 | get_columnumber(const char cname[], const colinfo * actcatinfo); 115 | 116 | 117 | extern char * 118 | rmlead (char *str); 119 | 120 | extern char * 121 | stptok (const char *s, char *tok, size_t toklen, char *brk); 122 | 123 | #define strMove(d,s) memmove(d,s,strlen(s)+1) 124 | 125 | extern void 126 | lv1ws (char *str); 127 | 128 | extern int 129 | isnum2(char *string); 130 | 131 | extern gsl_vector * 132 | string_to_gsl_array (char *str); 133 | 134 | extern void 135 | check_libraries (void); 136 | 137 | extern observation * 138 | load_dummy_observation (); 139 | #endif 140 | -------------------------------------------------------------------------------- /src/spc_flatfield.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_flatfield.h 3 | * Interface to flatfielding 4 | * 5 | * @author Martin Kuemmel, Nor Pirzkal, Markus Demleitner 6 | * @package spc_flatfield 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | 11 | #ifndef _SPC_FLATFIELD_H 12 | #define _SPC_FLATFIELD_H 1 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "aXe_grism.h" 21 | #include "aXe_utils.h" 22 | 23 | 24 | /** 25 | 26 | 27 | */ 28 | typedef struct 29 | { 30 | int poly_order; /* order of the polynomial */ 31 | gsl_matrix **coeffs; /* the list of gsl_matrix'es containing */ 32 | /* the polynomial coefficients of the FF */ 33 | double wmin; /* Minumum wavelength value for the coeff. normalization */ 34 | double wmax; /* Maximum wavelength value for the coeff. normalization */ 35 | } 36 | poly_cube_flatfield; 37 | 38 | /** 39 | Descriptor of flatfield with a single flatfield image and a 40 | polynomial flatfield dependence. 41 | */ 42 | typedef struct 43 | { 44 | gsl_matrix *flatfield; /* The flatfield image, giving the relative 45 | efficiency for each pixel in the aperture */ 46 | gsl_matrix *errors; /* relative errors for flatfield */ 47 | int poly_order; /* order of the polynomial */ 48 | double *poly_coeffs; /* coefficients for the polynom */ 49 | } 50 | polynom_flatfield; 51 | 52 | 53 | /** 54 | Descriptor of flatfield with multiple flatfields at different 55 | wave lengths 56 | */ 57 | typedef struct 58 | { 59 | int num_flats; /* number of (lambda,flatfield) pairs */ 60 | gsl_matrix **flatfields; /* flatfield images, giving the relative 61 | efficiency for each pixel in the aperture */ 62 | gsl_matrix **errors; /* relative errors for flatfields */ 63 | double *lambdas; /* wave lengths for entries in flatfields */ 64 | } 65 | multi_flatfield; 66 | 67 | 68 | 69 | 70 | /** 71 | Descriptor of a flatfielding function, including the function 72 | to compute the flat field value of a given pixel, the bounding box 73 | we handle, and auxillary data (usually a flatfield image) 74 | */ 75 | typedef struct s_flatfield 76 | { 77 | void (*func) (const double lambda, const int x, const int y, 78 | PIXEL_T * const val, PIXEL_T * const err, 79 | const struct s_flatfield * const self); 80 | int ll_x, ll_y, w, h; /* bounding box we handle */ 81 | union 82 | { 83 | polynom_flatfield *poly; 84 | multi_flatfield *multi; 85 | } 86 | data; 87 | } 88 | flatfield_d; 89 | 90 | 91 | poly_cube_flatfield * load_flat_poly_cube(char *fname); 92 | void free_flat_poly_cube(poly_cube_flatfield *poly_cube); 93 | 94 | flatfield_d *make_poly_flatfield (const beam * const curbeam, 95 | const char *const flat_name, 96 | const int order, 97 | const double *const coeffs); 98 | void free_poly_flatfield (flatfield_d * const flat); 99 | flatfield_d *make_multi_flatfield (const beam * const curbeam, 100 | const int num_flats, const double lambda, 101 | const char *const flat_name, ...); 102 | void free_multi_flatfield (flatfield_d * const flat); 103 | 104 | void apply_flatfield (ap_pixel * const ap_p, const flatfield_d * const flat); 105 | double poly_cube_flatfield_lambda (const double lambda, const int x, const int y, 106 | poly_cube_flatfield *poly_cube); 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /src/trfit_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: trfit_utils.h 3 | * 4 | * @author Martin Kuemmel 5 | * @package trfit_utils 6 | * @version $Revision: 1.3 $ 7 | * @date $Date: 2010-06-15 09:48:34 $ 8 | */ 9 | #ifndef _TRFIT_UTILS_H 10 | #define _TRFIT_UTILS_H 11 | 12 | #define N_COLUMNS_FIT 6 13 | 14 | #define N_KAPPASIG_ITER 3 15 | #define N_KAPPASIG_SIG 3.0 16 | #define N_ITER_IPC 5 17 | #define KAPPA_IPC 3.0 18 | 19 | // the ipc fit to the 20 | // data must be lower than this number 21 | // to initialize a correction of the spectrum 22 | #define MIN_IPC_LENGTH 60.0 23 | 24 | typedef struct 25 | { 26 | int n_data; 27 | 28 | double *x_values; 29 | double *y_values; 30 | double *e_values; 31 | } 32 | fit_data; 33 | 34 | struct function_data { 35 | int n; 36 | double * x; 37 | double * y; 38 | double * sig; 39 | }; 40 | 41 | 42 | extern gsl_vector * 43 | fit_beamtrace(const aperture_conf *conf, observation *obs, 44 | const int beamID, beam act_beam); 45 | 46 | extern double 47 | gagauss(const double x, const double *params); 48 | 49 | extern gsl_vector * 50 | fit_wuttke(const fit_data *f_data); 51 | 52 | extern gsl_vector * 53 | fit_wuttke_talk(const fit_data *f_data); 54 | 55 | extern d_point 56 | find_grav_center(const fit_data *f_data); 57 | 58 | extern px_point 59 | get_fit_xrange(const aperture_conf *conf, const observation *obs, 60 | beam act_beam); 61 | 62 | extern gsl_vector * 63 | fit_function(const fit_data *f_data); 64 | 65 | extern fit_data * 66 | get_fitdata(observation *obs, int np, px_point tr_point); 67 | 68 | extern fit_data * 69 | alloc_fit_data(const int n_data); 70 | 71 | void 72 | print_fit_data(fit_data *f_data); 73 | 74 | extern void 75 | free_fit_data(fit_data *f_data); 76 | 77 | int 78 | gauss_f(const gsl_vector *x, void *params, gsl_vector *f); 79 | 80 | int 81 | gauss_df(const gsl_vector *x, void *params, gsl_matrix *J); 82 | 83 | int 84 | gauss_fdf (const gsl_vector *x, void *params, gsl_vector *f, gsl_matrix *J); 85 | 86 | extern void 87 | print_fit_state (size_t iter, gsl_multifit_fdfsolver * s); 88 | 89 | extern double 90 | comp_intrel_max(const fit_data *f_data); 91 | 92 | extern gsl_matrix * 93 | bcksub_observation(observation *obs, observation *bck); 94 | 95 | extern double * 96 | evaluate_ipc_fit(fit_data *f_data, double *gpars, double *fpars); 97 | 98 | extern void 99 | write_ipc_fit(fit_data *f_data, double *y_values, const char *ipc_file, const double qual, double *yfract); 100 | 101 | extern double 102 | fit_ipc_data(fit_data *fdata, double *gpars, int n_gpars, 103 | double *fpars, int n_fpars); 104 | 105 | extern fit_data * 106 | get_ipc_fdata(const aperture_conf *conf, observation *obs, 107 | gsl_matrix *data_vals, beam act_beam); 108 | 109 | extern double * 110 | get_wf_special(const aperture_conf *conf, observation *obs, 111 | gsl_matrix *data_vals, beam act_beam, double yoffs); 112 | 113 | extern gsl_vector * 114 | get_ipc_coldata(gsl_matrix *img_data, int np, px_point tr_point); 115 | 116 | extern fit_data * 117 | strip_fitdata(fit_data *old_fdata, int i_max); 118 | 119 | extern double * 120 | strip_wf_special(fit_data *old_fdata, double *y_fract, int i_max); 121 | 122 | extern d_point 123 | kappa_sigma_klipp_ipc(const aperture_conf *conf, observation *obs, 124 | gsl_matrix *data_matrix, beam act_beam, 125 | const char *ipc_file); 126 | 127 | extern void 128 | reject_kappasigma(fit_data *f_data, double *y_values, double max_diff); 129 | 130 | extern double 131 | calculate_sigma(fit_data *f_data, double *y_values); 132 | #endif 133 | -------------------------------------------------------------------------------- /src/spce_output.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spce_output.h 3 | * Interface definitions for the postscript output routines 4 | * 5 | * @author Martin Kuemmel, Nor Pirzkal, Markus Demleitner 6 | * @package spce_output 7 | * @version $Revision: 1.4 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | 11 | #ifndef _SPCE_OUTPUT_H 12 | #define _SPCE_OUTPUT_H 13 | 14 | /* 15 | * Structure to store all information on 16 | * a stamp image which is going to be 17 | * created. This information is steps in x 18 | * start coos in x,y and image dimensions. 19 | */ 20 | typedef struct 21 | { 22 | double resolution; 23 | 24 | double xstart; 25 | double ystart; 26 | 27 | long xsize; 28 | long ysize; 29 | } 30 | drzstamp_dim; 31 | 32 | 33 | /* 34 | * Quadrangle structure to be filled with the 35 | * corners of a pixel in the drizzled coo-system. 36 | * Those corners are then passed to the boxer 37 | * subroutine to determine the overlap for a 38 | * particular pixel 39 | */ 40 | typedef struct 41 | { 42 | double xmax; // the maximum value in x[] 43 | double xmin; // the minimum value in x[] 44 | double ymax; // the maximum value in y[] 45 | double ymin; // the minimum value in y[] 46 | 47 | // (x[0],y[0]), (x[1],y[1]) 48 | double x[4]; // (x[2],y[2]) and (x[3],y[3]) 49 | double y[4]; // are the corner points of a pixel 50 | // in the coo-system of the drizzled image 51 | } 52 | quadrangle; 53 | 54 | typedef struct 55 | { 56 | gsl_matrix *counts; 57 | gsl_matrix *weight; 58 | } 59 | drzstamp; 60 | 61 | 62 | /* 63 | * Structure for all stamp images 64 | * of a beam in 'drzprep' 65 | */ 66 | typedef struct 67 | { 68 | gsl_matrix *counts; 69 | gsl_matrix *error; 70 | gsl_matrix *cont; 71 | gsl_matrix *model; 72 | gsl_matrix *vari; 73 | } 74 | drzprep; 75 | 76 | 77 | extern gsl_vector_int * 78 | get_trace_inds (const ap_pixel * const ap_p); 79 | 80 | extern gsl_matrix * 81 | stamp_img (const ap_pixel * const ap_p, float width, d_point *stp_min); 82 | 83 | extern drzprep * 84 | stamp_img_drzprep (const int opt_extr, const ap_pixel * const ap_p, const ap_pixel * const se_p, 85 | float width, float nullval, int usemode, 86 | drzstamp_dim dimension, gsl_matrix *drzcoeffs, 87 | double exptime, double sky_cps, double rdnoise, 88 | const int bckmode); 89 | 90 | extern void 91 | free_drzprep(drzprep *drzprep_stamps); 92 | 93 | extern gsl_matrix * 94 | rectified_stamp_img (const ap_pixel * const ap_p, float width, d_point *stp_min); 95 | 96 | extern d_point 97 | get_minxy_from_PET(const ap_pixel * const ap_p); 98 | 99 | extern d_point 100 | get_maxxy_from_PET(const ap_pixel * const ap_p); 101 | 102 | extern drzstamp * 103 | drizzled_stamp_img (const ap_pixel * const ap_p, double width, 104 | const double orient, const drzstamp_dim dimension); 105 | 106 | extern drzstamp_dim 107 | get_drzprep_dim(const ap_pixel *const ap_p, float width, 108 | int boxwidth, int boxheight); 109 | 110 | extern drzstamp_dim 111 | get_stamp_dim(const ap_pixel * const ap_p, float width, 112 | aperture_conf *conf, const int beamID, d_point *stp_min); 113 | 114 | extern quadrangle 115 | get_quad_from_pixel(const ap_pixel *cur_p, const double orient, const drzstamp_dim dimension); 116 | 117 | extern gsl_matrix * 118 | drizzled_stamp_img_orig (const ap_pixel * const ap_p, float width, 119 | aperture_conf *conf); 120 | 121 | extern void 122 | interpolate_over_NaN (gsl_matrix *data); 123 | 124 | extern void 125 | free_stamp_img(gsl_matrix *stamp); 126 | 127 | extern void 128 | free_drzstamp(drzstamp *stamp); 129 | #endif 130 | -------------------------------------------------------------------------------- /src/aXe_FRIGEN.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: aXe_FRIGEN.c 3 | * $Revision: 1.4 $ $Date: 2010-06-15 09:48:34 $ 4 | * ST-ECF - Space Telescope European Coordinating Facility 5 | * Martin Kuemmel 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | #include 22 | #include 23 | #include 24 | #include "aXe_grism.h" 25 | #include "aXe_utils.h" 26 | #include "aXe_errors.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include "fringe_conf.h" 32 | #include "fringe_model.h" 33 | 34 | 35 | #define AXE_IMAGE_PATH "AXE_IMAGE_PATH" 36 | #define AXE_OUTPUT_PATH "AXE_OUTPUT_PATH" 37 | #define AXE_CONFIG_PATH "AXE_CONFIG_PATH" 38 | 39 | int 40 | main(int argc, char *argv[]) 41 | { 42 | char *opt; 43 | 44 | char fconf_file[MAXCHAR]; 45 | char fconf_file_path[MAXCHAR]; 46 | 47 | char fimage_file[MAXCHAR]; 48 | char fimage_file_path[MAXCHAR]; 49 | 50 | fringe_conf *fconf; 51 | interpolator *filter_through; 52 | gsl_matrix *fringe_image; 53 | 54 | if ((argc < 3) || (opt = get_online_option("help", argc, argv))) { 55 | fprintf(stdout, 56 | "aXe_FRIGEN Version %s:\n" 57 | "\n", RELEASE); 58 | exit(1); 59 | } 60 | fprintf(stdout, "aXe_FRIGEN: Starting...\n"); 61 | 62 | /* Get the name of the fringe configuration file*/ 63 | strcpy(fconf_file, argv[1]); 64 | build_path(AXE_CONFIG_PATH, fconf_file, fconf_file_path); 65 | 66 | /* Get the configuration file name */ 67 | strcpy(fimage_file, argv[2]); 68 | build_path(AXE_OUTPUT_PATH, fimage_file, fimage_file_path); 69 | 70 | /* report on the input and output that will be used */ 71 | fprintf(stdout, 72 | "aXe_FRIGEN: Input fringe configuration file: %s\n", 73 | fconf_file_path); 74 | fprintf(stdout, 75 | "aXe_FRIGEN: Output fringe image name: %s\n", 76 | fimage_file_path); 77 | 78 | // load the fringe configuration file 79 | fconf = load_fringe_conf(fconf_file_path); 80 | 81 | // check whether all necessary information 82 | // is in place, provide defaults 83 | check_fringe_conf(fconf); 84 | 85 | // check whether a filter throughput file is set 86 | if (!fconf->filter_through) 87 | aXe_message (aXe_M_FATAL, __FILE__, __LINE__, 88 | "aXe_FRIGEN: No filter throughput table\n" 89 | "is set in the fringe configuration file!\n"); 90 | 91 | 92 | // comute the fringe amplitude 93 | fringe_image = compute_fringe_amplitude(fconf); 94 | 95 | // save the matrix to a fits-image 96 | gsl_to_FITSimage (fringe_image, fimage_file_path, 1, NULL); 97 | 98 | // release the space in the fringe image 99 | gsl_matrix_free(fringe_image); 100 | 101 | // release the allocated memory 102 | free_fringe_conf(fconf); 103 | 104 | // exit the program 105 | fprintf(stdout, "aXe_FRIGEN: Done...\n"); 106 | exit(0); 107 | } 108 | -------------------------------------------------------------------------------- /src/fringe_model.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: fringe_model.h 3 | * Header file for fringe_model.c 4 | * 5 | * @author Martin Kuemmel 6 | * @package fringe_model 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef _FRINGE_MODEL_H 11 | #define _FRINGE_MODEL_H 12 | 13 | 14 | /* 15 | * Struct: optical_property 16 | */ 17 | typedef struct 18 | { 19 | double trans_upper; // the transmission coefficient 20 | // to the next upper layer 21 | double reflect_upper; // the reflection coefficient 22 | // to the next upper layer 23 | double sign_upper; // sign for the reflection coefficient 24 | // to the next upper layer 25 | double thickness; // thickness of the layer 26 | double double_attenuation; // the amplitude attenuation when light of a 27 | // certain wavelength traverses the layer twice 28 | gsl_complex double_phshift; // the phase shift when light of a 29 | // certain wavelength traverses the layer twice 30 | double trans_lower; // the transmission coefficient 31 | // to the next lower layer 32 | double reflect_lower; // the reflection coefficient 33 | // to the next lower layer 34 | double sign_lower; // sign for the reflection coefficient 35 | // to the next lower layer 36 | } 37 | optical_property; 38 | 39 | 40 | extern gsl_matrix * 41 | compute_fringe_amplitude(fringe_conf *fconf); 42 | 43 | extern gsl_vector ** 44 | evaluate_wavelength_steps(fringe_conf *fconf); 45 | 46 | extern interpolator * 47 | redefine_filter_throughput(const int lower, const int upper, 48 | fringe_conf *fconf); 49 | 50 | extern gsl_matrix * 51 | alloc_fringe_image(const ccd_layers *opt_layers); 52 | 53 | extern gsl_vector ** 54 | get_calibration_data(); 55 | 56 | gsl_vector ** 57 | get_PET_calibration_data(); 58 | 59 | extern double 60 | eval_linear_interp(linear_interp *lin_int, const double xval); 61 | 62 | extern double 63 | get_layer_thickness(const ccd_layer *opt_layer, const int ii, const int jj); 64 | 65 | extern gsl_complex 66 | get_complex_refindex(const ccd_layer *opt_layer, const double lambda); 67 | 68 | extern double 69 | compute_reflection(const gsl_complex refract_l1, const gsl_complex refract_l2); 70 | 71 | extern double 72 | compute_transmission(const gsl_complex refract_l1, 73 | const gsl_complex refract_l2); 74 | 75 | extern double 76 | compute_attenuation(const gsl_complex refract, const double thickness, 77 | const double phase_number); 78 | 79 | extern gsl_complex 80 | compute_pshift(const gsl_complex refract, const double thickness, 81 | const double phase_number); 82 | 83 | extern optical_property * 84 | alloc_optprops_list(const fringe_conf *fconf); 85 | 86 | extern void 87 | print_optprops_list(const optical_property *optprops, const int num_entries); 88 | 89 | extern void 90 | free_optprops_list(optical_property *optprops); 91 | 92 | extern void 93 | init_optprops_list(const fringe_conf *fconf, const double lambda_mean, 94 | optical_property *optprops); 95 | 96 | extern void 97 | fill_optprops_thickness(const ccd_layers *opt_layers, const int ii, 98 | const int jj, optical_property *optprops); 99 | 100 | extern void 101 | fill_optprops_all(const ccd_layers *opt_layers, const double lambda, 102 | optical_property *optprops); 103 | 104 | extern double 105 | fringe_contrib_single(const optical_property *optprops, 106 | const fringe_conf *fconf); 107 | #endif 108 | -------------------------------------------------------------------------------- /src/spc_resp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * File: spc_resp.h 4 | * @author Martin Kuemmel, Nor Pirzkal 5 | * @package spc_resp 6 | * @version $Revision: 1.3 $ 7 | * @date $Date: 2010-06-15 09:48:34 $ 8 | */ 9 | #ifndef _SPC_RESP_H 10 | 11 | #define _SPC_RESP_H 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "aXe_grism.h" 22 | #include "spc_cfg.h" 23 | #include "spc_spc.h" 24 | 25 | #define RESPBUFFERSIZE 1024 26 | 27 | // number of points used 28 | // for smoothing 29 | #define RESP_SMOOTH_LENGTH 50 30 | 31 | // the number of sigmas 32 | // to smooth over 33 | #define RESP_SMOOTH_NSIG 3.0 34 | 35 | #define MAX_ITER_TL 1000 36 | 37 | /* 38 | * Struct: interpolator 39 | */ 40 | typedef struct 41 | { 42 | double xmin; 43 | double xmax; 44 | interpolator *resp_values; 45 | interpolator *resp_errors; 46 | } 47 | response_function; 48 | 49 | typedef struct 50 | { 51 | double wavelength; 52 | const calib_function *wl_calibration; 53 | } 54 | trlength_search; 55 | 56 | extern spectrum * 57 | get_response_function_from_FITS(char filename[], int hdunum); 58 | 59 | extern void 60 | apply_response_function(spectrum *spec, spectrum *resp, const int quant_cont); 61 | 62 | extern void 63 | apply_response_functionII(spectrum *spec, response_function *resp_func, const int quant_cont); 64 | 65 | extern d_point 66 | get_smooth_pars_for_beam(const aperture_conf *conf, const int smooth_conv, beam actbeam); 67 | 68 | extern int 69 | check_conf_for_smoothing(const aperture_conf *conf, const int smooth_conv); 70 | 71 | extern void 72 | apply_smoothed_response(const calib_function *wl_calibration, const int for_grism, 73 | const int quant_cont, response_function *resp_func, 74 | const d_point smooth_pars, spectrum *spec); 75 | 76 | extern double 77 | find_wavelength(double x, void *params); 78 | 79 | extern double 80 | get_tlength_prismwav(const double wavelength, const calib_function *wl_calibration); 81 | 82 | extern double 83 | get_central_tracelength(const double wavelength, const calib_function *wl_calibration, 84 | const int for_grism); 85 | 86 | extern void 87 | get_smoothed_response(const double wavelength, const d_point smooth_pars, 88 | const calib_function *wl_calibration, const int for_grism, 89 | const gsl_vector *weights, response_function *resp_func, 90 | double *resp_vals); 91 | //extern void 92 | //get_smoothed_response(const double wavelength, const double sigma_wav, const gsl_vector *weights, 93 | // response_function *resp_func, double *resp_vals); 94 | 95 | extern void 96 | get_weighted_sensitivity(const gsl_vector *pixvalues, const gsl_vector *errvalues, const gsl_vector *weights, 97 | const gsl_vector *pmask, double *resp_vals); 98 | 99 | extern void 100 | fill_weight(gsl_vector *weights); 101 | 102 | extern void 103 | get_troughput_table_name(char *filename, int beamID, char *table_name); 104 | 105 | extern double 106 | get_response_value_plus(const spectrum *resp, const double wavelength, 107 | int *nguess); 108 | 109 | extern void 110 | get_response_values(response_function *resp_func, double wavelength, double* resp_vals); 111 | 112 | extern response_function * 113 | create_response_function(char *filename); 114 | 115 | extern void 116 | free_response_function(response_function *resp_func); 117 | 118 | extern calib_function * 119 | get_calfunc_for_beam(const beam actbeam, const int for_grism, char CONF_file[], const aperture_conf * conf); 120 | 121 | #endif 122 | 123 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | The source distribution for the aXe spectral extracion software 2 | =============================================================== 3 | 4 | 1. The aXe software 5 | ------------------- 6 | The aXe software was designed to extract spectra in a consistent 7 | manner from all slitless spectroscopy modes provided by the 8 | Advanced Camera for Surveys (ACS) and the Wide Field Camera 3 9 | which are installed on the Hubble Space Telescope. aXe was designed 10 | to be quite general and can also be used for extraction of slitless 11 | spectra from other instruments. 12 | 13 | A full description of aXe and its capabilities can also be found 14 | at: http://axe-info.stsci.edu/ 15 | 16 | The purpose of the current document is restricted to providing 17 | an explanation on how to compile and install the C-code of aXe 18 | (see also Chapter 2 of the aXe manual). 19 | 20 | 21 | 2. Requirements 22 | --------------- 23 | The following are required to compile and install aXe: 24 | 25 | - GNU CC 2.95 or later compiler 26 | - GNU Scientific Libraries 1.9 or later (http://www.gnu.org/software/gsl/) 27 | - WCStools libraries 3.5 or later (http://tdc-www.harvard.edu/wcstools/) 28 | - CFITSIO 3.x libraries (https://heasarc.gsfc.nasa.gov/lheasoft/fitsio/fitsio.html) 29 | 30 | Install the libraries according to the instructions given with the 31 | respective source or binary distributions. 32 | 33 | In case that you do not have the privileges to install the libraries 34 | at their default location (e.g. "/usr/local/lib" or similar) it 35 | may be wise to install them at a common location, e.g. under 36 | "/yourpath/axelibs/", where "yourpath" is the location of a directory 37 | accessible to you. In this case do not forget to: 38 | a) set the location of the libraries on the library path LD_LIBRARY_PATH 39 | (e.g. by inserting the line 40 | "setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/yourpath/axelibs/lib" 41 | into your .cshrc); 42 | b) make the GSL-script "gsl-config" accessible by either putting its 43 | location ("/yourpath/axelibs/bin") on your PATH-variable 44 | or defining the variable GSL_CONFIG by inserting the 45 | line "setenv GSL_CONFIG /yourpath/axelibs/bin/gsl-config" 46 | into your .cshrc. 47 | 48 | 49 | 3. Configuring aXe 50 | ------------------ 51 | The configure script generates a Makefile which can be used to compile 52 | the aXe tasks. After all the above preparation it should be 53 | straightforward to configure aXe. In the case that the libraries are 54 | at the usual locations this is done by typing 55 | 56 | ./configure 57 | 58 | in the directory where the aXe-source was extracted. 59 | 60 | In the event that the libraries listed above are not installed in the 61 | usual places, online parameters should be used to tell the configure 62 | script where to find them. If you installed the libraries at the 63 | locations recommended above, typing 64 | 65 | >./configure --with-cfitsio-prefix=/yourpath/axelibs 66 | --with-wcstools-prefix=/yourpath/axelibs/wcstools-3.x.x 67 | 68 | should do the job. In case things do not go smoothly, follow the 69 | instructions which go along with the error messages to fix problems. 70 | Also the file "config.log" records continually the status information 71 | of the configuration process. A detailed description of the errors 72 | and possible solutions can be found there, too. 73 | 74 | The configure script should create a proper Makefile on Linux, Solaris 75 | and MacOSX platforms. Note that under MacOSX the option "-build=powerpc" 76 | must be added to the configure command for Power PC machines, and 77 | the option "-build=i386-pc-macosx" for Intel Macs . 78 | 79 | 4. Compiling and installing aXe 80 | ------------------------------- 81 | The next step consists of actually building the aXe library 82 | and aXe tasks: 83 | 84 | >make 85 | 86 | to execute the Makefile and create the c-tasks. The tasks must be 87 | installed in the bin directory within the iraf-directory. Simply execute 88 | 89 | >make install 90 | 91 | to move the binaries to their proper location. 92 | 93 | 5. Validating the aXe installation 94 | ---------------------------------- 95 | Test data with grism and prism images can can be obtained from the aXe 96 | web site (http://axe-info.stsci.edu/). 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/aXe_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: aXe_utils.h 3 | * Interface for aXe_utils.c 4 | * 5 | * @author Martin Kuemmel, Markus Demleitner, Nor Pirzkal 6 | * @package aXe_utils 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | 11 | #ifndef aXe_UTILS_H 12 | #define aXe_UTILS_H 13 | 14 | #include 15 | #include "aXe_grism.h" 16 | #include "spc_FITScards.h" 17 | 18 | #define MAXNCONF 10 19 | 20 | struct Col_Descr 21 | { 22 | char *ttype; 23 | char *tform; 24 | char *tunit; 25 | }; 26 | 27 | 28 | extern gsl_matrix * 29 | simulate_errors(gsl_matrix * img, float exptime, float gain); 30 | 31 | extern gsl_matrix * 32 | simulate_errors_t(gsl_matrix * img, const double exptime, 33 | const double rdnoise); 34 | 35 | extern void 36 | apply_DQ(observation * obs, int dqmask); 37 | 38 | extern observation * 39 | load_image(const char *const fname, int hdunum_data, 40 | int hdunum_err, int hdunum_dq, int dqmask, 41 | float exptime, float gain); 42 | 43 | extern observation * 44 | load_image_t(const char *const fname, int hdunum_data, 45 | int hdunum_err, int hdunum_dq, int dqmask, 46 | const double exptime, const double rdnoise); 47 | 48 | extern observation * 49 | load_sci_image(const char *const fname, int hdunum_data); 50 | 51 | extern int 52 | FITSextnum(const char *const fname); 53 | 54 | extern gsl_matrix * 55 | FITSnaxes_to_gsl (const char *const fname, int hdunum); 56 | 57 | extern gsl_matrix * 58 | FITSimage_to_gsl (const char *const fname, int hdunum, int fatal); 59 | 60 | extern px_point 61 | get_npixels (const char *const fname, int hdunum); 62 | 63 | extern int 64 | gsl_to_FITSimage (gsl_matrix * data, char filename[], 65 | int overwrite, char ID[]); 66 | 67 | extern int 68 | gsl_to_FITSimageHDU (gsl_matrix * data, char filename[], int overwrite, 69 | char ID[], int hdu_num); 70 | 71 | extern void 72 | quad_to_bbox (const px_point * const corners, px_point * const ll, 73 | px_point * const ur); 74 | 75 | extern int 76 | gsl_matrix_to_pgm (const char *const fname, const gsl_matrix * const m); 77 | 78 | extern void 79 | build_path (char envpathname[], const char file[], char *filename); 80 | 81 | extern char ** 82 | alloc_char_arr(int nrows, int ncols); 83 | 84 | extern void 85 | free_char_arr(char **char_arr, int nrows); 86 | 87 | extern int 88 | build_config_files(char list_file[], char **list_files, int maxnrows); 89 | 90 | extern void 91 | replace_file_extension (char infile[], char outfile[], char from_ext[], 92 | char to_ext[], int hdu); 93 | 94 | extern void 95 | free_oblist (object ** oblist); 96 | 97 | extern void 98 | fprintf_object (FILE * output, object * o); 99 | 100 | extern char * 101 | get_online_option (char option_name[], int argc, char *argv[]); 102 | 103 | extern int 104 | get_online_option2 (char option_name[], char option_value[], 105 | int argc, char *argv[]); 106 | 107 | extern void 108 | free_observation (observation * obs); 109 | 110 | extern int 111 | get_hdunum_from_hduname(char filename[], char extname[], 112 | char keyword[], char keyval[], int extver); 113 | 114 | extern FITScards * 115 | get_FITS_cards (char filename[], int hdu); 116 | 117 | extern FITScards * 118 | get_FITS_cards_opened (fitsfile *input); 119 | 120 | extern void 121 | put_FITS_cards (char filename[], int hdu, FITScards *cards); 122 | 123 | extern void 124 | put_FITS_cards_opened (fitsfile *output, FITScards *cards); 125 | 126 | extern void 127 | gsl_to_FITSimage_opened (gsl_matrix * data, fitsfile *ouput, 128 | int overwrite, char ID[]); 129 | 130 | extern fitsfile * 131 | create_FITSimage_opened (char filename[], int overwrite); 132 | 133 | extern float 134 | get_float_from_keyword(char *filename, int hdunum, char *keyword); 135 | 136 | extern void 137 | create_FITSimage(char *filename,int overwrite); 138 | 139 | extern int 140 | drzprep_fitstrans(char filename[], int hdunum, fitsfile *PET_ptr); 141 | 142 | extern px_point 143 | get_npixel(const observation *obs); 144 | #endif 145 | -------------------------------------------------------------------------------- /src/spc_driz.c: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_driz.c 3 | * @author Nor Pirzkal 4 | * @package spc_driz 5 | * @version $Revision: 1.3 $ 6 | * @date $Date: 2010-06-15 09:48:34 $ 7 | */ 8 | 9 | #include "spc_driz.h" 10 | 11 | #define MIN(x,y) (((x)<(y))?(x):(y)) 12 | #define MAX(x,y) (((x)>(y))?(x):(y)) 13 | 14 | 15 | /** 16 | Calculate the area common to input clockwise polygon x(n), y(n) with 17 | square (is, js) to (is+1, js+1). 18 | This version is for a quadrilateral. 19 | W.B. Sparks STScI 2-June-1990. 20 | Phil Hodge 20-Nov-1990 Change calling sequence; single precision. 21 | Richard Hook ECF 24-Apr-1996 Change coordinate origin 22 | so that centre of pixel has integer position 23 | 03-Jan-2001 Removed accuracy check 24 | Nor Pirzkal 27-Jan-2003 C version 25 | **/ 26 | double boxer(int is,int js,double *xx,double *yy) 27 | { 28 | double px[4],py[4], sum; 29 | int i; 30 | 31 | /* 32 | Set up coords relative to unit square at origin 33 | Note that the +0.5s were added when this code was 34 | included in DRIZZLE 35 | */ 36 | for(i=0;i<4;i++) { 37 | px[i] = xx[i] - is + 0.5; 38 | py[i] = yy[i] - js + 0.5; 39 | // fprintf(stderr,"%d %d %f %f\n",is,js,px[i],py[i]); 40 | } 41 | 42 | /* 43 | For each line in the polygon (or at this stage, input quadrilateral) 44 | calculate the area common to the unit square (allow negative area for 45 | subsequent `vector' addition of subareas). 46 | */ 47 | sum = 0.; 48 | for (i=0;i<3;i++) { 49 | sum += sgarea(px[i],py[i],px[i+1],py[i+1],is,js); 50 | } 51 | sum += sgarea(px[3],py[3],px[0],py[0],is,js); 52 | 53 | return sum; 54 | 55 | } 56 | 57 | double sgarea(double x1, double y1, double x2, double y2, int is, int js) 58 | { 59 | double m,c,dx; 60 | double xlo,xhi,ylo,yhi,xtop; 61 | int negdx=0; 62 | double res; 63 | 64 | dx = x2-x1; 65 | 66 | /* 67 | Trap vertical line 68 | */ 69 | if (dx==0.0) { 70 | res = 0.0; 71 | return res; 72 | } 73 | 74 | /* 75 | Order the two input points in x 76 | */ 77 | if (x1=1.0) { 89 | res = 0.0; 90 | return res; 91 | } 92 | 93 | if (xhi<=0.0) { 94 | res = 0.0; 95 | return res; 96 | } 97 | 98 | xlo = MAX(xlo,0.0); 99 | xhi = MIN(xhi,1.0); 100 | 101 | /* 102 | Now look at y basic info about the line y = mx+c 103 | */ 104 | negdx = (dx<0.0); 105 | m = (y2-y1)/dx; 106 | c = y1-m*x1; 107 | ylo = m*xlo+c; 108 | yhi = m*xhi+c; 109 | 110 | /* 111 | Trap segment entirely below axis 112 | */ 113 | if ( (ylo<=0.0)&&(yhi<=0.0) ) { 114 | res = 0.0; 115 | return res; 116 | } 117 | 118 | /* 119 | Adjust bounds if segment crosses axis (to exclude anything below axis) 120 | */ 121 | if (ylo<0.0) { 122 | ylo = 0.0; 123 | xlo = -c/m; 124 | } 125 | if (yhi<0.0) { 126 | yhi = 0.0; 127 | xhi = -c/m; 128 | } 129 | 130 | /* 131 | There are four possibilities: 132 | both y below 1 133 | both y above 1 134 | and one of each 135 | */ 136 | 137 | 138 | if ( (ylo>=1.0) && (yhi>=1.0) ) { 139 | /* Line segment is entirrely above square */ 140 | if (negdx) { 141 | res = xlo-xhi; 142 | } else { 143 | res = xhi-xlo; 144 | } 145 | return res; 146 | } 147 | 148 | if ( (ylo<=1.0) && (yhi<=1.0) ) { 149 | /* segment is entirely within square */ 150 | if (negdx) { 151 | res = 0.5*(xlo-xhi)*(yhi+ylo); 152 | } else { 153 | res = 0.5*(xhi-xlo)*(yhi+ylo); 154 | } 155 | return res; 156 | } 157 | 158 | 159 | /* Otherwise it must cross the top square */ 160 | xtop = (1.0 -c)/m; 161 | 162 | if (ylo<1.) { 163 | if (negdx) { 164 | res = -(0.5*(xtop-xlo)*(1.0+ylo)+xhi-xtop); 165 | } else { 166 | res = 0.5*(xtop-xlo)*(1.0+ylo)+xhi-xtop; 167 | } 168 | return res; 169 | } 170 | 171 | if (negdx) { 172 | res = -(0.5*(xhi-xtop)*(1.0+yhi)+xtop-xlo); 173 | } else { 174 | res = 0.5*(xhi-xtop)*(1.0+yhi)+xtop-xlo; 175 | } 176 | 177 | return res; 178 | } 179 | -------------------------------------------------------------------------------- /src/ipixcorr_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: ipixcorr_utils.h 3 | * Header files for ipixcorr_utils.c 4 | * 5 | * @author Martin Kuemmel 6 | * @package ipixcorr_utils 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef _IPIXCORR_UTILS_H 11 | 12 | #define _IPIXCORR_UTILS_H 13 | 14 | // interpolation type used for the 15 | // complex refractive indices 16 | #define IPCORR_INTERP_TYPE gsl_interp_linear 17 | 18 | // interpolation type used for the 19 | // complex refractive indices 20 | #define NLINCORR_INTERP_TYPE gsl_interp_linear 21 | 22 | // maximum beamID to be corrected 23 | #define CORRMAX 0 24 | 25 | // maximum number of iterations 26 | // for the zero point search 27 | #define MAX_ITER 1000 28 | 29 | // extension for the interval in the zero 30 | // point search to include the zero 31 | #define INTERVEXT 10 32 | 33 | // stepsize in x to compute the 34 | // correction factor and the wavelength 35 | // on the object trace 36 | #define XSTEPSIZE 0.5 37 | 38 | // the ipc fit to the 39 | // data must be lower than this number 40 | // to initialize a correction of the spectrum 41 | #define MAXQUALITY 1.5 42 | 43 | 44 | 45 | typedef struct 46 | { 47 | int aperID; // the aperture ID 48 | int beamID; // the beam ID 49 | int nelems; // the number of spectral elements 50 | spectrum *fgr_spec; // the spectrum structure for the foreground 51 | spectrum *bck_spec; // the spectrum structure for the background 52 | spectrum *obj_spec; // the spectrum structure for the object 53 | } 54 | full_spectr; 55 | 56 | 57 | 58 | /** 59 | * Structure: tlength_pars 60 | */ 61 | typedef struct 62 | { 63 | beam *actbeam; 64 | double tlength; 65 | } 66 | tlength_pars; 67 | 68 | 69 | extern double 70 | get_intpix_corr(beam *actbeam, gsl_vector *cdisp, interpolator *ipcorr, 71 | float lambda); 72 | 73 | extern double 74 | get_yfract_for_xvalue(const beam *actbeam, double xvalue); 75 | 76 | extern double 77 | get_xvalue_from_tlength(beam *actbeam, double tlength); 78 | 79 | extern d_point 80 | get_xinterv_from_beam(const beam *actbeam); 81 | 82 | extern double 83 | zero_tlength (double x, void *params); 84 | 85 | extern double 86 | get_tlength_from_dispersion(gsl_vector *cdisp, float lambda); 87 | 88 | extern gsl_vector * 89 | condense_dispersion(gsl_vector *disp_input); 90 | 91 | extern int 92 | fitting_ipc_corr(beam act_beam, char conf_file_path[], interpolator *ipcorr, 93 | full_spectr *SPC, observation *obs, gsl_matrix *data_matrix, 94 | char ipc_file_path[], beam *beam_ptr); 95 | 96 | extern void 97 | intpix_corr_beam(beam actbeam, char conf_file_path[], interpolator *ipcorr, 98 | full_spectr *SPC); 99 | 100 | extern gsl_vector * 101 | get_ipc_lambdas(const beam actbeam, char conf_file_path[], gsl_vector *xvalues); 102 | 103 | extern gsl_vector * 104 | get_ipc_cvalues(const beam actbeam, interpolator *ipcorr, gsl_vector *xvalues); 105 | 106 | extern gsl_vector * 107 | get_ipc_xvalues(const beam actbeam); 108 | 109 | extern interpolator * 110 | get_ipclambda(beam actbeam, char conf_file_path[], interpolator *ipcorr); 111 | 112 | extern void 113 | apply_corr_pet(interpolator *ipclambda, ap_pixel *PET); 114 | 115 | extern void 116 | intpix_corr_pet(beam actbeam, char conf_file_path[], 117 | interpolator *ipcorr, ap_pixel *PET); 118 | 119 | extern int 120 | is_pointlike(beam actbeam, int spec_OAF, double max_ext); 121 | 122 | extern fitsfile * 123 | get_SPC_opened(char SPCname[], int mode); 124 | 125 | extern full_spectr * 126 | get_ALL_from_next_in_SPC(fitsfile *SPC_ptr, int *aperID, int *beamID); 127 | 128 | extern void 129 | free_full_spectr(full_spectr *act_spectr); 130 | 131 | extern spectrum * 132 | get_spectrum_from_SPC(fitsfile *SPC_ptr, char count_col[], char error_col[], 133 | int nelems); 134 | 135 | extern double * 136 | get_dcolumn_from_SPC_opened(fitsfile *SPC_ptr, char colname[], int nelems); 137 | 138 | extern long * 139 | get_lcolumn_from_SPC_opened(fitsfile *SPC_ptr, char colname[], int nelems); 140 | 141 | extern interpolator * 142 | create_nlincor(); 143 | 144 | extern void 145 | nlin_corr_beam(interpolator *nlincorr, double adcgain, full_spectr *SPC); 146 | 147 | extern double 148 | get_nlin_corr(interpolator *nlincorr, const double lambda, const double cps); 149 | #endif 150 | -------------------------------------------------------------------------------- /src/spc_CD.c: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_CD.c 3 | * WCS related routines 4 | * 5 | * @author Martin Kuemmel, Markus Demleitner, Nor Pirzkal 6 | * @package spc_CD 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #include "spc_CD.h" 11 | 12 | 13 | /** 14 | * Function: get_fits_header 15 | * Returns the header of extension hdunum from a fits file filename 16 | * 17 | * Parameters: 18 | * @param filename The name of the FITS file 19 | * @param hdunum the number of the HDU to access 20 | * 21 | * Returns: 22 | * @return a pointer to a newly allocated string containing the entire header 23 | */ 24 | char * 25 | get_fits_header (char filename[], int hdunum) 26 | { 27 | 28 | fitsfile *input; 29 | int f_status = 0, hdutype; 30 | int nkeys, i; 31 | char card[FLEN_CARD]; 32 | 33 | char *header, *p; 34 | 35 | // Open the file for creating/appending 36 | fits_open_file (&input, filename, READONLY, &f_status); 37 | if (f_status) 38 | { 39 | ffrprt (stderr, f_status); 40 | aXe_message (aXe_M_FATAL, __FILE__, __LINE__, 41 | "get_fits_header: Could not open" " file:", filename); 42 | } 43 | fits_movabs_hdu (input, hdunum, &hdutype, &f_status); 44 | if (f_status) 45 | { 46 | ffrprt (stderr, f_status); 47 | aXe_message (aXe_M_FATAL, __FILE__, __LINE__, 48 | "get_fits_header: " 49 | "Could not read extention %d from file: %s", hdunum, 50 | filename); 51 | } 52 | 53 | 54 | 55 | fits_get_hdrspace (input, &nkeys, NULL, &f_status); /* get # of keywords */ 56 | 57 | header = (char *) malloc ((nkeys + 1) * FLEN_CARD * sizeof (char)); 58 | p = header; 59 | for (i = 0; i < nkeys; i++) 60 | { /* Read and print each keywords */ 61 | 62 | if (fits_read_record (input, i + 1, card, &f_status)) 63 | break; 64 | 65 | sprintf(p,"%-80s", card); 66 | p = p + 80; 67 | } 68 | /* Add END keyword */ 69 | 70 | sprintf (card, "END"); 71 | sprintf(p,"%-80s", card); 72 | 73 | return header; 74 | } 75 | 76 | /** 77 | * Function: get_wcs 78 | * Returns a pointer to a WoldCoor structure filled using the extension 79 | * hdunum of file filename. 80 | * Sets things to use linear WCS and J2000 equinox. 81 | * 82 | * Parameters: 83 | * @param filename The name of the FITS file 84 | * @param hdunum the number of the HDU to access 85 | * 86 | * Return: 87 | * @return a pointer to a WoldCoor structure. NULL if no WCS was found 88 | */ 89 | struct WorldCoor * 90 | get_wcs (char filename[], int hdunum) 91 | { 92 | char *header; 93 | struct WorldCoor *wcs; 94 | 95 | // Read the FITS or IRAF image file header 96 | header = get_fits_header (filename, hdunum); 97 | 98 | // extract the WCS from the header 99 | wcs = wcsinit (header); 100 | 101 | // release memory 102 | free (header); 103 | 104 | // return the result 105 | return wcs; 106 | } 107 | 108 | 109 | 110 | /** 111 | * Function: ij_to_radec 112 | * Returns the world coordinates corresponding to the 113 | * point ij in an image which as a WCS wcs. 114 | * 115 | * Parameter: 116 | * @param wcs, a pointer to a WorldCoor WCS structure 117 | * @param ij, a point inthe image 118 | * 119 | * Return: 120 | * @return a pointer to a d_point structure containing the world 121 | * coordinates at point ij in degrees. 122 | */ 123 | sky_coord * 124 | ij_to_radec (struct WorldCoor * wcs, d_point ij) 125 | { 126 | sky_coord *pos; 127 | 128 | pos = malloc (sizeof (d_point)); 129 | pix2wcs (wcs, ij.x, ij.y, &pos->ra, &pos->dec); 130 | 131 | return pos; 132 | } 133 | 134 | 135 | /** 136 | * Function: radec_to_ij 137 | * Returns the detector pixel coordinates corresponding to the 138 | * point radec in the sky sgiven the WCS wcs. 139 | * 140 | * Parameter: 141 | * @param wcs a pointer to a WorldCoor WCS structure 142 | * @param radec a point with celestial coordinates 143 | * 144 | * Return: 145 | * @return a pointer to a d_point structure containing the image 146 | * pixel coordinates. 147 | */ 148 | d_point * 149 | radec_to_ij (struct WorldCoor * wcs, sky_coord radec) 150 | { 151 | d_point *pos; 152 | int offscl; 153 | 154 | pos = malloc (sizeof (d_point)); 155 | wcs2pix (wcs, radec.ra, radec.dec, &pos->x, &pos->y, &offscl); 156 | 157 | return pos; 158 | } 159 | -------------------------------------------------------------------------------- /src/fringe_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: fringe_conf.h 3 | * Header file for fringe_conf.c 4 | * 5 | * @author Martin Kuemmel 6 | * @package fringe_conf 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef _FRINGE_CONF_H 11 | #define _FRINGE_CONF_H 12 | 13 | // switch to let the debugging 14 | // information print to the screen 15 | //#define DEBUGFCONF 1 16 | 17 | // the minimum number of layers 18 | #define NLAYERS_MIN 1 19 | 20 | // the default fringe step in AA 21 | #define DEFAULT_FRINGE_STEP 1.0 22 | 23 | // the default number of steps 24 | // to resolve the pixel throughput 25 | #define DEFAULT_NUM_STEPS 100 26 | 27 | // the default maximal resolution 28 | #define DEFAULT_MAX_DISPERSION 1.0e+4 29 | 30 | // the default maximal resolution 31 | #define DEFAULT_MIN_LAMBDA 0.0 32 | 33 | // the default maximal resolution 34 | #define DEFAULT_MAX_LAMBDA 2.0e+4 35 | 36 | // threshold for filter values 37 | // to be considered relevant 38 | #define FILTER_THRESHOLD 1.0e-05 39 | 40 | // interpolation type used for the filter 41 | // throughput values 42 | #define FILTER_INTERP_TYPE gsl_interp_linear 43 | 44 | // interpolation type used for the 45 | // complex refractive indices 46 | #define REFRAC_INTERP_TYPE gsl_interp_linear 47 | 48 | /* 49 | * Struct: interpolator 50 | */ 51 | typedef struct 52 | { 53 | double xmin; // minimum in the independent variable 54 | double xmax; // maximum in the independent variable 55 | int nvals; // the naumber of data values 56 | double *xvals; // array for the independent values 57 | double *yvals; // array for the dependent values 58 | gsl_interp_accel *acc; // spline accelerator 59 | gsl_interp *interp; // interpolation structure 60 | } 61 | interpolator; 62 | 63 | /* 64 | * Struct: linear_interp 65 | */ 66 | typedef struct 67 | { 68 | double xmin; // minimum in the independent variable 69 | double xmax; // maximum in the independent variable 70 | int num_elem ; // the number of elements in the arrays 71 | int act_index; // the actual position in the interpolator 72 | gsl_vector *xvals; // the array of independent values 73 | gsl_vector *yvals; // the array of dependent value 74 | } 75 | linear_interp; 76 | 77 | 78 | /* 79 | * Struct: ccd_layer 80 | */ 81 | typedef struct 82 | { 83 | double thickness; // thicknes of the CCD in $[\mu m]$ 84 | gsl_matrix *thickness2D; // the layer thickness at every pixel in [mum] 85 | interpolator *re_refraction; // real part of refractive index 86 | interpolator *im_refraction; // imaginary part of refractive index 87 | } 88 | ccd_layer; 89 | 90 | 91 | /* 92 | * Struct: ccd_layers 93 | */ 94 | typedef struct 95 | { 96 | int num_layers; // the number of CCD layers 97 | ccd_layer **opt_layer; // array with optical layers in a CCD 98 | interpolator *substrate; // to represent the CCD substrate 99 | } 100 | ccd_layers; 101 | 102 | 103 | /* 104 | * Struct: fringe_conf 105 | */ 106 | typedef struct 107 | { 108 | double fringe_amp; // the fringe amplitude 109 | double fringe_phase; // phase at the first layer 110 | double fringe_step; // step interval to examine 111 | int num_steps; // number of steps for filter function 112 | gsl_vector *fringe_range; // minimum and maximum wavelength for fringing 113 | double max_dispersion; // maximal dispersion considered in fringing 114 | interpolator *filter_through; // structure for the filter throughput 115 | ccd_layers *opt_layers; // the different optical layers in a CCD 116 | } 117 | fringe_conf; 118 | 119 | extern ccd_layer * 120 | load_CCD_layer(const char refr_table[], const char thickness[]); 121 | 122 | extern void 123 | free_CCD_layer(ccd_layer *opt_layer); 124 | 125 | extern ccd_layers * 126 | load_CCD_layers(char fring_conf_path[]); 127 | 128 | extern void 129 | free_CCD_layers(ccd_layers *opt_layers); 130 | 131 | extern fringe_conf * 132 | load_fringe_conf(char fring_conf_path[]); 133 | 134 | extern void 135 | check_fringe_conf(fringe_conf *fconf); 136 | 137 | extern void 138 | free_fringe_conf(fringe_conf *fconf); 139 | 140 | extern interpolator * 141 | create_interp_ftable(const char table_name[], const int fdunum, 142 | char xcol[], char ycol[], 143 | const gsl_interp_type *T); 144 | 145 | extern interpolator * 146 | create_interp(const int nvals, const gsl_interp_type *interp_type, 147 | double *xvals, double *yvals); 148 | 149 | extern void 150 | print_interp(interpolator *interp); 151 | 152 | extern double 153 | eval_interp(interpolator *interp, const double xval); 154 | 155 | extern void 156 | free_interp(interpolator *interp); 157 | 158 | extern linear_interp * 159 | create_linint_ftable(const char table_name[], const int fdunum, 160 | char xcol[], char ycol[]); 161 | 162 | extern void 163 | free_linint(linear_interp *lin_int); 164 | 165 | #endif 166 | -------------------------------------------------------------------------------- /src/spc_back.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_back.h 3 | * Header file for the subroutines in spc_back.c 4 | * 5 | * @author Martin Kuemmel, Nor Pirzkal 6 | * @package spc_back 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef _SPC_BACK_H 11 | #define _SPC_BACK_H 12 | 13 | #include "spce_is_in.h" 14 | 15 | #define DQ_KAPPA_SIGMA -1.0 16 | 17 | /** 18 | A descriptor of a background, consisting of a function to 19 | compute the background at absolute position x,y and a 20 | parameter block (e.g., matrices containing the background) 21 | */ 22 | typedef struct s_background 23 | { 24 | void (*bck_func) (const int x, const int y, PIXEL_T * const val, 25 | PIXEL_T * const err, const struct s_background * pars); 26 | void *pars; 27 | } 28 | background; 29 | 30 | /** 31 | An aggregation of the background and the error for each background pixel, 32 | used for the fullimg family of background functions. 33 | */ 34 | typedef struct 35 | { 36 | gsl_matrix *bck; 37 | gsl_matrix *err; 38 | } 39 | fullimg_background; 40 | 41 | extern int 42 | is_pt_in_a_beam (const px_point * const apoint, 43 | const is_in_descriptor * const iids, const int tnbeams); 44 | 45 | extern void 46 | compute_background2(object **oblist, const int obj_index, 47 | const int beamorder, gsl_matrix *bck_mask, 48 | const int tnbeams, fullimg_background * fib, int npoints, 49 | int interporder); 50 | 51 | //gsl_vector_int * 52 | //get_window_points(observation *obs, gsl_matrix *bck_mask, beam actbeam, 53 | // px_point tr_point); 54 | 55 | extern gsl_vector_int * 56 | get_interp_points(observation *obs, gsl_matrix *bck_mask, 57 | int np, px_point tr_point); 58 | 59 | extern void 60 | compute_background (observation *obs, beam actbeam, gsl_matrix *bck_mask, 61 | fullimg_background *fib, int npoints, 62 | int interporder, const int niter_med, 63 | const int niter_fit, const double kappa); 64 | 65 | extern void 66 | compute_global_background (object **oblist, const int obj_index, 67 | gsl_matrix *bck_mask, fullimg_background * fib, 68 | int interporder); 69 | extern void 70 | fullimg_background_function (const int x, const int y, PIXEL_T * const val, 71 | PIXEL_T * const err, 72 | const background * const back); 73 | 74 | extern background * 75 | compute_fullimg_background2(observation *obs, object **oblist, 76 | int npoints, int interporder); 77 | 78 | extern background * 79 | compute_fullimg_background(observation *obs, object **oblist, 80 | int npoints, int interporder, const int niter_med, 81 | const int niter_fit, const double kappa, 82 | int nor_flag, const int sm_length, const double fwhm); 83 | 84 | extern background * 85 | compute_backsub_mask (observation *obs, object **oblist); 86 | 87 | extern background * 88 | compute_fullimg_global_background (observation *obs, object **oblist, 89 | int interporder, const int sm_length, const double fwhm); 90 | 91 | extern void 92 | free_fullimg_background (background * const fib); 93 | 94 | extern void 95 | background_to_FITSimage (char filename[], background * bck, observation *obs); 96 | 97 | extern gsl_matrix * 98 | aperture_mask (observation * const obs, object **oblist); 99 | 100 | extern void 101 | comp_vector_interp(const double *const xs, double *const ys, 102 | double *const ws, double *const yi, const int n, 103 | const int interp, const int final); 104 | 105 | extern void 106 | comp_kappasigma_interp(const double *const xs, double *const ys, 107 | double *const ws, const int n, 108 | const int interp, const int niter, const double kappa, 109 | observation *obs, int colnum); 110 | void 111 | kappa_sigma_clipp(const double *const xs, double *const ys, double *const ws, const int n, const double kappa, 112 | observation *obs, int colnum); 113 | 114 | extern px_point 115 | get_xrange(observation *obs, beam actbeam); 116 | 117 | extern void 118 | gsmooth_background (const gsl_matrix *bck_mask, const int smooth_length, 119 | const double fwhm, fullimg_background *fib); 120 | 121 | extern double 122 | get_weighted_mean(const gsl_vector *pixvalues, const gsl_vector *weights, 123 | const gsl_vector *pmask); 124 | 125 | extern void 126 | fill_pixvalues(const gsl_matrix *bck_mask, const int smooth_length, 127 | const fullimg_background *fib, const int ix, const int iy, 128 | gsl_vector *pixvalues, gsl_vector *pmask); 129 | 130 | extern double 131 | compute_gvalue(const double xdiff, const double efactor); 132 | 133 | extern double 134 | compute_efactor(const double fwhm); 135 | 136 | #endif 137 | -------------------------------------------------------------------------------- /src/lm_eval.c: -------------------------------------------------------------------------------- 1 | /** 2 | * File: lm_eval.c 3 | * Subroutines for the Levenberg Marqwart Minimization 4 | * 5 | * @author Martin Kuemmel 6 | * @package lm_eval 7 | * @version $Revision: 1.2 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #include "lmmin.h" 11 | #include "lm_eval.h" 12 | #include 13 | 14 | /* 15 | * This file contains default implementation of the evaluate and printout 16 | * routines. In most cases, customization of lmfit can be done by modifying 17 | * these two routines. Either modify them here, or copy and rename them. 18 | */ 19 | 20 | void lm_evaluate_default( double* par, int m_dat, double* fvec, 21 | void *data, int *info ) 22 | /* 23 | * par is an input array. At the end of the minimization, it contains 24 | * the approximate solution vector. 25 | * 26 | * m_dat is a positive integer input variable set to the number 27 | * of functions. 28 | * 29 | * fvec is an output array of length m_dat which contains the function 30 | * values the square sum of which ought to be minimized. 31 | * 32 | * data is a read-only pointer to lm_data_type, as specified by lmuse.h. 33 | * 34 | * info is an integer output variable. If set to a negative value, the 35 | * minimization procedure will stop. 36 | */ 37 | { 38 | int i; 39 | lm_data_type *mydata; 40 | mydata = (lm_data_type*)data; 41 | 42 | for (i=0; iuser_y[i] 44 | - mydata->user_func( mydata->user_t[i], par); 45 | 46 | *info = *info; /* to prevent a 'unused variable' warning */ 47 | /* if { *info = -1; } */ 48 | } 49 | 50 | void lm_evaluate_fpar( double* par, int m_dat, double* fvec, 51 | void *data, int *info ) 52 | /* 53 | * par is an input array. At the end of the minimization, it contains 54 | * the approximate solution vector. 55 | * 56 | * m_dat is a positive integer input variable set to the number 57 | * of functions. 58 | * 59 | * fvec is an output array of length m_dat which contains the function 60 | * values the square sum of which ought to be minimized. 61 | * 62 | * data is a read-only pointer to lm_data_type, as specified by lmuse.h. 63 | * for this version of the evaluate function, data contains some fixed 64 | * parameters which are passed to the evaluation function 65 | * 66 | * info is an integer output variable. If set to a negative value, the 67 | * minimization procedure will stop. 68 | */ 69 | { 70 | int i; 71 | lm_data_fpar_type *mydata; 72 | mydata = (lm_data_fpar_type*)data; 73 | 74 | //fprintf(stderr, "%i 1.: %e, %e, %e: %e\n", m_dat, mydata->fpars[0], mydata->fpars[1], mydata->fpars[2], par[0]); 75 | for (i=0; iuser_t[i]); 79 | //fprintf(stderr, "value: %e, ", mydata->user_y[i]); 80 | //fprintf(stderr, "func_value: %e \n", mydata->user_func( mydata->user_t[i], par, mydata->fpars)); 81 | 82 | 83 | fvec[i] = mydata->user_y[i] 84 | - mydata->user_func( mydata->user_t[i], par, mydata->fpars); 85 | 86 | } 87 | //fprintf(stderr, "2.: %e, %e, %e: %e\n", mydata->fpars[0], mydata->fpars[1], mydata->fpars[2], par[0]); 88 | *info = *info; /* to prevent a 'unused variable' warning */ 89 | /* if { *info = -1; } */ 90 | } 91 | 92 | void lm_print_default( int n_par, double* par, int m_dat, double* fvec, 93 | void *data, int iflag, int iter, int nfev ) 94 | /* 95 | * data : for soft control of printout behaviour, add control 96 | * variables to the data struct 97 | * iflag : 0 (init) 1 (outer loop) 2(inner loop) -1(terminated) 98 | * iter : outer loop counter 99 | * nfev : number of calls to *evaluate 100 | */ 101 | { 102 | double f, y, t; 103 | int i; 104 | lm_data_type *mydata; 105 | mydata = (lm_data_type*)data; 106 | 107 | if (iflag==2) { 108 | printf ("trying step in gradient direction\n"); 109 | } else if (iflag==1) { 110 | printf ("determining gradient (iteration %d)\n", iter); 111 | } else if (iflag==0) { 112 | printf ("starting minimization\n"); 113 | } else if (iflag==-1) { 114 | printf ("terminated after %d evaluations\n", nfev); 115 | } 116 | 117 | printf( " par: " ); 118 | for( i=0; i norm: %12g\n", lm_enorm( m_dat, fvec ) ); 121 | 122 | if ( iflag == -1 ) { 123 | printf( " fitting data as follows:\n" ); 124 | for( i=0; iuser_t)[i]; 126 | y = (mydata->user_y)[i]; 127 | f = mydata->user_func( t, par ); 128 | printf( " t[%2d]=%12g y=%12g fit=%12g residue=%12g\n", 129 | i, t, y, f, y-f ); 130 | } 131 | } 132 | } 133 | 134 | void lm_print_nothing( int n_par, double* par, int m_dat, double* fvec, 135 | void *data, int iflag, int iter, int nfev ) 136 | /* 137 | * data : for soft control of printout behaviour, add control 138 | * variables to the data struct 139 | * iflag : 0 (init) 1 (outer loop) 2(inner loop) -1(terminated) 140 | * iter : outer loop counter 141 | * nfev : number of calls to *evaluate 142 | */ 143 | { 144 | double f, y, t; 145 | int i; 146 | lm_data_type *mydata; 147 | mydata = (lm_data_type*)data; 148 | 149 | } 150 | -------------------------------------------------------------------------------- /src/aXe_NICBACK.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: aXe_NICBACK.c 3 | * $Revision: 1.4 $ $Date: 2010-06-15 09:48:34 $ 4 | * ST-ECF - Space Telescope European Coordinating Facility 5 | * Martin Kuemmel 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include "aXe_grism.h" 26 | #include "aXe_utils.h" 27 | #include "spce_sect.h" 28 | #include "inout_aper.h" 29 | #include "aper_conf.h" 30 | #include "spc_back.h" 31 | #include "nicback_utils.h" 32 | 33 | #define AXE_IMAGE_PATH "AXE_IMAGE_PATH" 34 | #define AXE_OUTPUT_PATH "AXE_OUTPUT_PATH" 35 | #define AXE_CONFIG_PATH "AXE_CONFIG_PATH" 36 | 37 | int 38 | main(int argc, char *argv[]) 39 | { 40 | char *opt; 41 | char grism_image[MAXCHAR]; 42 | char grism_image_path[MAXCHAR]; 43 | 44 | char conf_file[MAXCHAR]; 45 | char conf_file_path[MAXCHAR]; 46 | 47 | char master_bck[MAXCHAR]; 48 | char master_bck_path[MAXCHAR]; 49 | 50 | char corr_bck[MAXCHAR]; 51 | char corr_bck_path[MAXCHAR]; 52 | 53 | char msk_name[MAXCHAR]; 54 | char msk_name_path[MAXCHAR]; 55 | 56 | char plist_name[MAXCHAR]; 57 | char plist_name_path[MAXCHAR]; 58 | 59 | char bck_name[MAXCHAR]; 60 | char bck_name_path[MAXCHAR]; 61 | 62 | // int np; 63 | // int interp; 64 | 65 | // int makemask=0; 66 | // int nor_flag=0; 67 | 68 | // object **oblist; 69 | observation *obs; 70 | aperture_conf *conf; 71 | // background *backg; 72 | 73 | // int niter_med; 74 | // int niter_fit; 75 | 76 | // double kappa; 77 | double exptime; 78 | 79 | if ((argc <= 3) || (opt = get_online_option("help", argc, argv))) { 80 | fprintf(stdout, 81 | "aXe_NICBACK Version %s:\n" 82 | "\n" 83 | "Example: aXe_BE slim_grismb.fits -np=10 -interp=3 \n" 84 | "\n", RELEASE); 85 | exit(1); 86 | } 87 | fprintf(stdout, "aXe_NICKBACK: Starting...\n"); 88 | 89 | // Getting the grism/prism image name 90 | strcpy(grism_image, argv[1]); 91 | build_path(AXE_IMAGE_PATH, grism_image, grism_image_path); 92 | 93 | // Get the name of the configuration file 94 | strcpy(conf_file, argv[2]); 95 | build_path(AXE_CONFIG_PATH, conf_file, conf_file_path); 96 | 97 | // Getting the master background name 98 | strcpy(master_bck, argv[3]); 99 | build_path(AXE_CONFIG_PATH, master_bck, master_bck_path); 100 | 101 | // check whether a pedestal file was given 102 | if (argc > 4) 103 | { 104 | // transfer file name 105 | strcpy(corr_bck, argv[4]); 106 | build_path(AXE_CONFIG_PATH, corr_bck, corr_bck_path); 107 | } 108 | else 109 | { 110 | // give a default 111 | strcpy(corr_bck, ""); 112 | strcpy(corr_bck_path, ""); 113 | } 114 | 115 | // read the configuration file 116 | conf = get_aperture_descriptor(conf_file_path); 117 | /* Determine where the various extensions are in the FITS file */ 118 | get_extension_numbers(grism_image_path, conf, conf->optkey1, conf->optval1); 119 | 120 | // fix the mask file name 121 | replace_file_extension(grism_image, msk_name, ".fits", 122 | ".MSK.fits", conf->science_numext); 123 | build_path(AXE_OUTPUT_PATH, msk_name, msk_name_path); 124 | 125 | // fix the name of the pixel list 126 | replace_file_extension(grism_image, plist_name, ".fits", 127 | ".plis", conf->science_numext); 128 | build_path(AXE_OUTPUT_PATH, plist_name, plist_name_path); 129 | 130 | // fix the mask file name 131 | replace_file_extension(grism_image, bck_name, ".fits", 132 | ".NBCK.fits", conf->science_numext); 133 | build_path(AXE_OUTPUT_PATH, bck_name, bck_name_path); 134 | 135 | 136 | fprintf(stdout, 137 | "aXe_NICBACK: Input data file name: %s\n", 138 | grism_image_path); 139 | fprintf(stdout, 140 | "aXe_NICBACK: Main configuration file name: %s\n", 141 | conf_file_path); 142 | fprintf(stdout, 143 | "aXe_NICBACK: Master background file name: %s\n", 144 | master_bck_path); 145 | if (strlen(corr_bck_path) > 0) 146 | fprintf(stdout, 147 | "aXe_NICBACK: Correction background file name: %s\n", 148 | corr_bck_path); 149 | fprintf(stdout, 150 | "aXe_NICBACK: Grism mask file name: %s\n", 151 | msk_name_path); 152 | fprintf(stdout, 153 | "aXe_NICBACK: Background image file name: %s\n", 154 | bck_name_path); 155 | fprintf(stdout, "\n\n"); 156 | 157 | fprintf(stdout, "aXe_NICBACK: "); 158 | 159 | // try to get the descriptor 'exptime' from the 'sci'-extension 160 | exptime = (double)get_float_from_keyword(grism_image_path, 161 | conf->science_numext, conf->exptimekey); 162 | if (isnan(exptime)) 163 | exptime = (double)get_float_from_keyword(grism_image_path, 1, conf->exptimekey); 164 | if (isnan(exptime)) 165 | exptime = 1.0; 166 | 167 | // load the grism image in an obs structure 168 | obs = load_image_t(grism_image_path, conf->science_numext, 169 | conf->errors_numext, conf->dq_numext, 170 | conf->dqmask, exptime, conf->rdnoise); 171 | 172 | // run the subroutine which does everything 173 | make_nicmos_back(obs, msk_name_path, master_bck_path, bck_name_path, 174 | plist_name_path, corr_bck_path); 175 | 176 | // free the memory in the ob structure 177 | free_observation(obs); 178 | fprintf(stdout, "aXe_NICBACK: Done...\n"); 179 | exit(0); 180 | } 181 | -------------------------------------------------------------------------------- /src/aXe_SCALEBCK.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: aXe_SCALEBCK.c 3 | * $Revision: 1.6 $ $Date: 2010-06-15 09:48:34 $ 4 | * ST-ECF European Coordinating Facility 5 | * Martin Kuemmel 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include "aXe_grism.h" 26 | #include "aXe_utils.h" 27 | #include "spce_sect.h" 28 | #include "inout_aper.h" 29 | #include "aper_conf.h" 30 | #include "spc_back.h" 31 | #include "nicback_utils.h" 32 | #include "scaleback_utils.h" 33 | 34 | #define AXE_IMAGE_PATH "AXE_IMAGE_PATH" 35 | #define AXE_OUTPUT_PATH "AXE_OUTPUT_PATH" 36 | #define AXE_CONFIG_PATH "AXE_CONFIG_PATH" 37 | 38 | int 39 | main(int argc, char *argv[]) 40 | { 41 | char *opt; 42 | 43 | char scale_image[MAXCHAR]; 44 | char scale_image_path[MAXCHAR]; 45 | 46 | char conf_file[MAXCHAR]; 47 | char conf_file_path[MAXCHAR]; 48 | 49 | char grism_image[MAXCHAR]; 50 | char grism_image_path[MAXCHAR]; 51 | 52 | char grism_mask[MAXCHAR]; 53 | char grism_mask_path[MAXCHAR]; 54 | 55 | char bck_image[MAXCHAR]; 56 | char bck_image_path[MAXCHAR]; 57 | 58 | char plist_name[MAXCHAR]; 59 | char plist_name_path[MAXCHAR]; 60 | 61 | int scale_to_master=0; 62 | int make_plis=0; 63 | 64 | 65 | if ((argc <= 3) || (opt = get_online_option("help", argc, argv))) { 66 | fprintf(stdout, 67 | "aXe_SCALEBCK Version %s:\n" 68 | " Task for finding the scaling value between the pixels of\n" 69 | " two images. pixels marked in the dq-extension or in a mask\n" 70 | " image are excluded. From the extracted list of pixels, the\n" 71 | " scale is determined via several kappa-sigma clipping\n" 72 | " iterations around the median.\n" 73 | " A scaled version of either the input image or the grism\n" 74 | " image is written to the disk.\n" 75 | "\n" 76 | "Usage:\n" 77 | " aXe_SCALEBCK [g/prism image] [g/prism mask] [config file] [master sky] [options]\n" 78 | "\n" 79 | "Options:\n" 80 | " -toMaster - scale the g/prism image to the master sky\n" 81 | " -make_plis - create an ASCII pixel list as output\n" 82 | "\n" 83 | "\n", RELEASE); 84 | exit(1); 85 | } 86 | fprintf(stdout, "aXe_SCALEBCK: Starting...\n"); 87 | 88 | // getting the grism/prism image name 89 | // get the name mask file for the scale image 90 | strcpy(grism_image, argv[1]); 91 | build_path(AXE_IMAGE_PATH, grism_image, grism_image_path); 92 | 93 | // get the name mask file for the scale image 94 | strcpy(grism_mask, argv[2]); 95 | build_path(AXE_OUTPUT_PATH, grism_mask, grism_mask_path); 96 | 97 | // get the configuration file name 98 | strcpy(conf_file, argv[3]); 99 | build_path(AXE_CONFIG_PATH, conf_file, conf_file_path); 100 | 101 | // get the master sky file name 102 | strcpy(scale_image, argv[4]); 103 | build_path(AXE_CONFIG_PATH, scale_image, scale_image_path); 104 | 105 | // fix the scaled image path 106 | replace_file_extension(grism_image, bck_image, ".fits", 107 | ".SGRISM.fits", 2); 108 | build_path(AXE_OUTPUT_PATH, bck_image, bck_image_path); 109 | 110 | // fix the name of the pixel list 111 | replace_file_extension(grism_image, plist_name, ".fits", 112 | ".plis", 2); 113 | build_path(AXE_OUTPUT_PATH, plist_name, plist_name_path); 114 | 115 | // check option for scaling target 116 | if ((opt = get_online_option ("toMaster", argc, argv))) 117 | scale_to_master = 1; 118 | else 119 | scale_to_master = 0; 120 | 121 | // check option to make pixel list 122 | if ((opt = get_online_option ("make_plis", argc, argv))) 123 | make_plis = 1; 124 | else 125 | make_plis = 0; 126 | 127 | fprintf(stdout, 128 | "aXe_SCALEBCK: Input grism image: %s\n", 129 | grism_image_path); 130 | fprintf(stdout, 131 | "aXe_SCALEBCK: Input grism mask: %s\n", 132 | grism_mask_path); 133 | fprintf(stdout, 134 | "aXe_SCALEBCK: aXe configuration file: %s\n", 135 | conf_file_path); 136 | fprintf(stdout, 137 | "aXe_SCALEBCK: Master sky image: %s\n", 138 | scale_image_path); 139 | fprintf(stdout, 140 | "aXe_SCALEBCK: Scaled grism image: %s\n", 141 | bck_image_path); 142 | if (make_plis) 143 | fprintf(stdout, 144 | "aXe_SCALEBCK: Pixel list name: %s\n", 145 | plist_name_path); 146 | if (scale_to_master) 147 | fprintf(stdout, "aXe_SCALEBCK: Grism is scaled to master sky!\n"); 148 | else 149 | fprintf(stdout, "aXe_SCALEBCK: Master sky is scaled to grism!\n"); 150 | 151 | // do some line feed 152 | fprintf(stdout, "\n\n"); 153 | 154 | // read the configuration file 155 | // determine all extensions 156 | //conf = get_aperture_descriptor(conf_file_path); 157 | //get_extension_numbers(grism_image_path, conf, conf->optkey1, conf->optval1); 158 | 159 | // run the subroutine which does everything 160 | make_scale_back(grism_image_path, grism_mask_path, conf_file_path, 161 | scale_image_path, bck_image_path, plist_name_path, 162 | scale_to_master, make_plis); 163 | 164 | // give feedback and out 165 | fprintf(stdout, "aXe_SCALEBCK: Done...\n"); 166 | exit(0); 167 | } 168 | -------------------------------------------------------------------------------- /src/spce_pathlength.c: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spce_pathlength.c 3 | * Functions to replace an x coordinate with the path length of a given 4 | * function of that x coordinate. 5 | * 6 | * Sample usage: 7 | * trace_func *f; 8 | * gsl_vector *data; 9 | * 10 | * abscissa_to_pathlength(f, data); 11 | * 12 | * So, this is a little trivial... 13 | * 14 | * @author Nor Pirzkal, Markus Demleitner 15 | * @package spce_pathlength 16 | * @version $Revision: 1.3 $ 17 | * @date $Date: 2010-06-15 09:48:34 $ 18 | */ 19 | 20 | #include "spce_pathlength.h" 21 | 22 | 23 | /** 24 | transforms a list of abscissas to a list of path lengths if the path length 25 | is known analytically. 26 | 27 | @param func the spectrum trace function to use in the transformation 28 | @param data the table of abscissas relative to the reference point 29 | */ 30 | static int 31 | absc_to_pathl_path_len (const trace_func * const func, 32 | gsl_vector * const data) 33 | { 34 | int i; 35 | 36 | for (i = 0; i < data->size; i++) 37 | { 38 | gsl_vector_set (data, i, 39 | func->path_len (gsl_vector_get (data, i), 40 | func->data)); 41 | 42 | } 43 | return 0; 44 | } 45 | 46 | /* computes sqrt(1+f'(x)^2), i.e. the function to integrate to obtain 47 | * the path length. 48 | * 49 | * @param x the abscissa to compute the function for 50 | * @pars a pointer to the trace_func struct, declared void to please gsl 51 | */ 52 | static double 53 | pathlength_fun (double x, void *pars) 54 | { 55 | const trace_func *const func = pars; 56 | double y = func->deriv (x, func->data); 57 | 58 | return sqrt (1 + y * y); 59 | } 60 | 61 | 62 | /* Compute the path length of (x,func->func(x)) from x0 to x1 (helper 63 | * function for absc_to_pathl_deriv) 64 | * 65 | * @param func the spectrum trace 66 | * @param x0 start of parameter range 67 | * @param x1 end of parameter range 68 | * 69 | */ 70 | static double 71 | pathlength_integral (const trace_func * const func, const double x0, 72 | const double x1) 73 | { 74 | double res, abserr; 75 | size_t neval; 76 | gsl_function f; 77 | 78 | f.function = &pathlength_fun; 79 | f.params = (void *) func; 80 | 81 | gsl_integration_qng (&f, x0, x1, 1e-6, 1e-7, &res, &abserr, &neval); 82 | return res; 83 | } 84 | 85 | 86 | #define NUM_INTERPOINTS 50 /* number of interpolation points */ 87 | /** 88 | * transforms a list of abscissas to a list of path lengths if the derivative 89 | * but not the path length is known analytically. The strategy is to compute 90 | * NUM_INTERPOINTS actual path lengths and the interpolate between them. 91 | * This should work with sufficient accuracy if the trace function is 92 | * reasonably smooth. 93 | * 94 | * @param func the spectrum trace function to use in the transformation 95 | * @param data the table of abscissas relative to the reference point 96 | */ 97 | static int 98 | absc_to_pathl_deriv (const trace_func * const func, gsl_vector * const data) 99 | { 100 | int i; 101 | double min_absc = gsl_vector_min (data), max_absc = 102 | gsl_vector_max (data); 103 | double step; 104 | double xvals[NUM_INTERPOINTS], yvals[NUM_INTERPOINTS]; 105 | double res; 106 | gsl_spline *spline; 107 | gsl_interp_accel *acc; 108 | 109 | //gsl_interp_factory factory = gsl_interp_factory_cspline_natural; 110 | //gsl_interp_obj *interpolator; 111 | //gsl_interp_accel *accelerator; 112 | 113 | 114 | 115 | /* thresh in a little space left and right to avoid interpolation 116 | disasters at the edges of the interval */ 117 | min_absc = min_absc - (max_absc - min_absc) / NUM_INTERPOINTS * 2; 118 | max_absc = max_absc + (max_absc - min_absc) / NUM_INTERPOINTS * 2; 119 | step = (max_absc - min_absc) / NUM_INTERPOINTS; 120 | xvals[0] = min_absc; 121 | yvals[0] = pathlength_integral (func, 0, xvals[0]); 122 | for (i = 1; i < NUM_INTERPOINTS; i++) 123 | { 124 | xvals[i] = min_absc + i * step; 125 | yvals[i] = 126 | yvals[i - 1] + pathlength_integral (func, xvals[i - 1], 127 | xvals[i]); 128 | } 129 | 130 | //interpolator = factory.create(xvals, yvals, NUM_INTERPOINTS); 131 | //accelerator = gsl_interp_accel_new(); 132 | 133 | acc = gsl_interp_accel_alloc (); 134 | spline = gsl_spline_alloc (gsl_interp_cspline, NUM_INTERPOINTS); 135 | gsl_spline_init (spline, xvals, yvals, NUM_INTERPOINTS); 136 | 137 | for (i = 0; i < data->size; i++) 138 | { 139 | //gsl_interp_eval_impl(interpolator, xvals, yvals, 140 | // gsl_vector_get(data, i), accelerator, &res); 141 | res = gsl_spline_eval (spline, gsl_vector_get (data, i), acc); 142 | gsl_vector_set (data, i, res); 143 | } 144 | 145 | gsl_spline_free (spline); 146 | gsl_interp_accel_free (acc); 147 | 148 | return 0; 149 | } 150 | 151 | 152 | /** 153 | * transforms a list of abscissas to a list of path lengths if not even 154 | * the derivative is known. 155 | * 156 | * @param func the spectrum trace function to use in the transformation 157 | * @param data the table of abscissas relative to the reference point 158 | * @todo pathlength for traces without derivatibes is not implemented 159 | */ 160 | static int 161 | absc_to_pathl_val_only (const trace_func * const func, 162 | gsl_vector * const data) 163 | { 164 | fprintf (stderr, "Not implemented yet\n"); 165 | abort (); 166 | return 0; 167 | } 168 | 169 | 170 | /** 171 | * transforms a list of abscissas to a list of path lengths. This function 172 | * decides what of the absc_to_pathl_len, absc_to_pathl_deriv, or 173 | * absc_to_pathl_val_only to use. 174 | * 175 | * @param func the spectrum trace function to use in the transformation 176 | * @param data the table of abscissas relative to the reference point 177 | */ 178 | int 179 | abscissa_to_pathlength (const trace_func * const func, 180 | gsl_vector * const data) 181 | { 182 | if (func->path_len) 183 | { 184 | return absc_to_pathl_path_len (func, data); 185 | } 186 | if (func->deriv) 187 | { 188 | return absc_to_pathl_deriv (func, data); 189 | } 190 | return absc_to_pathl_val_only (func, data); 191 | } 192 | -------------------------------------------------------------------------------- /src/aXe_TEST.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: aXe_TEST.c 3 | * $Revision: 1.4 $ $Date: 2010-06-15 09:48:34 $ 4 | * ST-ECF - Space Telescope European Coordinating Facility 5 | * Martin Kuemmel 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "wcs.h" 26 | 27 | struct WorldCoor *get_wcs_l(char filename[], int hdunum); 28 | char *get_fits_header_l(char filename[], int hdunum); 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | char *opt; 33 | char direct_image[30]; 34 | char direct_image_path[30]; 35 | int direct_hdunum; 36 | 37 | char grism_image[30]; 38 | char grism_image_path[30]; 39 | int grism_hdunum; 40 | 41 | struct WorldCoor *dirim_wcs; 42 | struct WorldCoor *grisi_wcs; 43 | 44 | double x_in = 1000.0; 45 | double y_in = 1000.0; 46 | double x_out = 0.0; 47 | double y_out = 0.0; 48 | double ra_in = 0.0; 49 | double dec_in = 0.0; 50 | 51 | int offscl=0; 52 | 53 | if (argc<3) 54 | { 55 | fprintf (stdout, "ST-ECF European Coordinating Facility\nCopyright (C) 2002 Sofisof\naXe_TEST Version 0.01: \n\nUsage:\n" 56 | "aXe_TEST direct_image.fits grism_image.fits\n\n"); 57 | exit (1); 58 | } 59 | fprintf (stdout, "aXe_TEST: Starting...\n"); 60 | 61 | // copy the input over 62 | strcpy (direct_image, argv[1]); 63 | strcpy (grism_image, argv[2]); 64 | 65 | // give feedback on the input 66 | fprintf (stdout, "aXe_TEST: direct image: %s\n", direct_image); 67 | fprintf (stdout, "aXe_TEST: grism image: %s\n", grism_image); 68 | 69 | // load the wcs of both images 70 | dirim_wcs = get_wcs_l (direct_image, 2); 71 | grisi_wcs = get_wcs_l (grism_image, 2); 72 | 73 | // convert a point onto the sky 74 | pix2wcs (dirim_wcs, x_in, y_in, &ra_in, &dec_in); 75 | 76 | fprintf (stdout, "aXe_TEST: (%.1f,%.1f) --> (%e,%e)\n", x_in, y_in, ra_in, dec_in); 77 | 78 | wcs2pix (grisi_wcs, ra_in, dec_in, &x_out, &y_out, &offscl); 79 | fprintf (stdout, "aXe_TEST: (%e,%e) --> (%.1f,%.1f)\n", ra_in, dec_in, x_out, y_out); 80 | 81 | /* 82 | // load the wcs of both images 83 | dirim_wcs = get_wcs (direct_image, 3); 84 | grisi_wcs = get_wcs (grism_image, 3); 85 | 86 | fprintf(stdout, "\n\n"); 87 | 88 | // convert a point onto the sky 89 | pix2wcs (dirim_wcs, x_in, y_in, &ra_in, &dec_in); 90 | 91 | fprintf (stdout, "aXe_TEST: (%.1f,%.1f) --> (%e,%e)\n", x_in, y_in, ra_in, dec_in); 92 | 93 | wcs2pix (grisi_wcs, ra_in, dec_in, &x_out, &y_out, &offscl); 94 | fprintf (stdout, "aXe_TEST: (%e,%e) --> (%.1f,%.1f)\n", ra_in, dec_in, x_out, y_out); 95 | */ 96 | 97 | // print a last status message and exit 98 | fprintf(stdout, "aXe_TEST: Done.\n"); 99 | exit(0); 100 | } 101 | 102 | 103 | /** 104 | * Function: get_fits_header 105 | * Returns the header of extension hdunum from a fits file filename 106 | * 107 | * Parameters: 108 | * @param filename The name of the FITS file 109 | * @param hdunum the number of the HDU to access 110 | * 111 | * Returns: 112 | * @return a pointer to a newly allocated string containing the entire header 113 | */ 114 | char * 115 | get_fits_header_l (char filename[], int hdunum) 116 | { 117 | 118 | fitsfile *input; 119 | int f_status = 0, hdutype; 120 | int nkeys, i; 121 | char card[FLEN_CARD]; 122 | 123 | char *header, *p; 124 | 125 | // Open the file for creating/appending 126 | fits_open_file (&input, filename, READONLY, &f_status); 127 | if (f_status) 128 | { 129 | ffrprt (stderr, f_status); 130 | fprintf (stdout, "ERROR: get_fits_header: Could not open file: %s", filename); 131 | } 132 | fits_movabs_hdu (input, hdunum, &hdutype, &f_status); 133 | if (f_status) 134 | { 135 | ffrprt (stderr, f_status); 136 | fprintf (stdout, "ERROR: get_fits_header: Could not read extention %d from file: %s", hdunum, filename); 137 | } 138 | 139 | 140 | 141 | fits_get_hdrspace (input, &nkeys, NULL, &f_status); /* get # of keywords */ 142 | 143 | header = (char *) malloc ((nkeys + 1) * FLEN_CARD * sizeof (char)); 144 | p = header; 145 | for (i = 0; i < nkeys; i++) 146 | { /* Read and print each keywords */ 147 | 148 | if (fits_read_record (input, i + 1, card, &f_status)) 149 | break; 150 | 151 | sprintf(p,"%-80s", card); 152 | p = p + 80; 153 | } 154 | /* Add END keyword */ 155 | 156 | sprintf (card, "END"); 157 | sprintf(p,"%-80s", card); 158 | 159 | return header; 160 | } 161 | 162 | /** 163 | * Function: get_wcs 164 | * Returns a pointer to a WoldCoor structure filled using the extension 165 | * hdunum of file filename. 166 | * Sets things to use linear WCS and J2000 equinox. 167 | * 168 | * Parameters: 169 | * @param filename The name of the FITS file 170 | * @param hdunum the number of the HDU to access 171 | * 172 | * Return: 173 | * @return a pointer to a WoldCoor structure. NULL if no WCS was found 174 | */ 175 | struct WorldCoor * get_wcs_l (char filename[], int hdunum) 176 | { 177 | char *header; 178 | struct WorldCoor *wcs; 179 | 180 | // Read the FITS or IRAF image file header 181 | header = get_fits_header_l (filename, hdunum); 182 | 183 | // extract the WCS from the header 184 | wcs = wcsinit (header); 185 | 186 | // release memory 187 | free (header); 188 | 189 | // return the result 190 | return wcs; 191 | } 192 | 193 | -------------------------------------------------------------------------------- /src/spce_is_in.c: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spce_is_in.c 3 | * A function to decide whether a point is in a given quadrangle 4 | * (and its helpers) 5 | * 6 | * Usage: 7 | * is_in_descriptor iid; 8 | * fill_is_in_descriptor(&iid, corners); 9 | * for (i=0; i<30; i++) if (is_in(i,i,&iid)) printf("Yes"); 10 | * 11 | * @author Martin Kuemmel, Nor Pirzkal, Markus Demleitner 12 | * @package spce_is_in 13 | * @version $Revision: 1.3 $ 14 | * @date $Date: 2010-06-15 09:48:34 $ 15 | */ 16 | 17 | #include 18 | #include "aXe_grism.h" 19 | #include "aXe_utils.h" 20 | #include "spce_sect.h" 21 | #include "spce_is_in.h" 22 | 23 | 24 | #define SQR(x) ((x)*(x)) 25 | #define MIN(x,y) (((x)<(y))?(x):(y)) 26 | #define MAX(x,y) (((x)>(y))?(x):(y)) 27 | 28 | 29 | /** 30 | * Fills a triangle structure and makes sure the angle at points[0] 31 | * is <=90 deg. 32 | * 33 | * @param trig the struct to fill. 34 | * @param points the three point at the corners of the triangle. 35 | */ 36 | void 37 | fill_triag_struct (triangle * const trig, px_point points[3]) 38 | { 39 | trig->root = points[0]; 40 | trig->s.x = points[1].x - points[0].x; 41 | trig->s.y = points[1].y - points[0].y; 42 | trig->t.x = points[2].x - points[0].x; 43 | trig->t.y = points[2].y - points[0].y; 44 | trig->sabs = sqrt (SQR (trig->s.x) + SQR (trig->s.y)); 45 | trig->tabs = sqrt (SQR (trig->t.x) + SQR (trig->t.y)); 46 | trig->s_t = trig->s.x * trig->t.x + trig->s.y * trig->t.y; 47 | 48 | if (trig->s_t / trig->sabs / trig->tabs < 0) 49 | { 50 | px_point tmp; 51 | tmp = points[0]; 52 | points[0] = points[1]; 53 | points[1] = tmp; 54 | fill_triag_struct (trig, points); 55 | } 56 | } 57 | 58 | 59 | /** 60 | * pre-computes some constant items for deciding whether a point is in 61 | * a given convex quadrangle. 62 | * 63 | * @param iid the descriptor to fill 64 | * @param corners the corners of the quadrangle 65 | * @return 0 for success, -1 for error 66 | */ 67 | int 68 | fill_is_in_descriptor (is_in_descriptor * const iid, 69 | const px_point * const corners) 70 | { 71 | px_point points[3]; 72 | 73 | points[0] = corners[0]; 74 | points[1] = corners[1]; 75 | points[2] = corners[3]; 76 | iid->mini = 77 | MIN (MIN (MIN (corners[0].x, corners[1].x), corners[2].x), 78 | corners[3].x); 79 | iid->maxi = 80 | MAX (MAX (MAX (corners[0].x, corners[1].x), corners[2].x), 81 | corners[3].x); 82 | iid->minj = 83 | MIN (MIN (MIN (corners[0].y, corners[1].y), corners[2].y), 84 | corners[3].y); 85 | iid->maxj = 86 | MAX (MAX (MAX (corners[0].y, corners[1].y), corners[2].y), 87 | corners[3].y); 88 | 89 | fill_triag_struct (&(iid->trig1), points); 90 | points[0] = corners[2]; 91 | points[1] = corners[1]; 92 | points[2] = corners[3]; 93 | fill_triag_struct (&(iid->trig2), points); 94 | return 0; 95 | } 96 | 97 | 98 | /** 99 | * decides if a point is within a triangle. 100 | * 101 | * @param pix_x x-coordinate of the point to check. 102 | * @param pix_y y-coordinate of the point to check. 103 | * @param trig a pointer to the triangle structure. 104 | * @return 1 if point is in triangle, 0 otherwise. 105 | */ 106 | /* This works by computing normalized covariant coordinates */ 107 | static int 108 | is_in_triag (const int pix_x, const int pix_y, const triangle * const trig) 109 | { 110 | int x, y; 111 | double p_s, p_t, pabs, xsqrtarg, ysqrtarg, xp, yp; 112 | 113 | x = pix_x - trig->root.x; 114 | y = pix_y - trig->root.y; 115 | p_s = trig->s.x * x + trig->s.y * y; 116 | p_t = trig->t.x * x + trig->t.y * y; 117 | pabs = sqrt (SQR (x) + SQR (y)); 118 | xsqrtarg = 119 | (1 - SQR (p_s) / SQR (pabs) / SQR (trig->sabs)) / (1 - SQR (trig->s_t) / SQR (trig->sabs) / SQR (trig->tabs)); 120 | ysqrtarg = 121 | (1 - SQR (p_t) / SQR (pabs) / SQR (trig->tabs)) / (1 - SQR (trig->s_t) / SQR (trig->sabs) / SQR (trig->tabs)); 122 | 123 | if (xsqrtarg < 0) 124 | { 125 | if (xsqrtarg > -1e-8) 126 | { 127 | xsqrtarg = 0; 128 | } 129 | else 130 | { 131 | printf ("is_in_triag: %d %d x%g\n", x, y, xsqrtarg); 132 | xsqrtarg = 0; 133 | 134 | //abort (); 135 | } 136 | } 137 | if (ysqrtarg < 0) 138 | { 139 | if (ysqrtarg > -1e-8) 140 | { 141 | ysqrtarg = 0; 142 | } 143 | else 144 | { 145 | printf ("is_in_triag: y%g\n", ysqrtarg); 146 | ysqrtarg = 0; 147 | 148 | //abort (); 149 | } 150 | } 151 | 152 | xp = 1. / SQR (trig->sabs) * (p_s - 153 | trig->s_t * pabs / trig->tabs * 154 | sqrt (xsqrtarg)); 155 | yp = 1. / SQR (trig->tabs) * (p_t - 156 | trig->s_t * pabs / trig->sabs * 157 | sqrt (ysqrtarg)); 158 | 159 | 160 | /* The 1.0xx1 should be harmless for 161 | quadrangles that are not too extended since these points are at 162 | the point where the triangles are stitched together. */ 163 | if ((-1e-10 <= xp) && (-1e-10 <= yp) && ((xp + yp) < (1.0 + 1e-10))) 164 | return 1; 165 | 166 | return 0; 167 | } 168 | 169 | 170 | /** 171 | Decides if a point is within a quadrangle. 172 | 173 | @param x The x-coordinate of the point. 174 | @param y The y-coordinate of the point. 175 | @param iid The descriptor of the quadrangle. 176 | @return 1 if point is in quadrangle, 0 otherwise. 177 | @see fill_is_in_descriptor 178 | */ 179 | int 180 | is_in (const int x, const int y, const is_in_descriptor * const iid) 181 | { 182 | if ((x < iid->mini) || (x > iid->maxi) || (y < iid->minj) 183 | || (y > iid->maxj)) 184 | return 0; 185 | 186 | if (is_in_triag (x, y, &(iid->trig1))) 187 | return 1; 188 | if (is_in_triag (x, y, &(iid->trig2))) 189 | return 1; 190 | return 0; 191 | } 192 | 193 | int 194 | tracedist_criteria(const double x, const double y, sectionfun *sf, 195 | const trace_func *tracefun, const double width) 196 | { 197 | double x_sect, y_sect; 198 | double dist, max_dist; 199 | 200 | int ireturn=0; 201 | 202 | 203 | find_section_point (sf, x, y, &x_sect); 204 | y_sect = tracefun->func (x_sect, tracefun->data); 205 | 206 | dist = sqrt((y_sect-y)*(y_sect-y)+(x_sect-x)*(x_sect-x)); 207 | 208 | if (dist < width) 209 | ireturn=1; 210 | 211 | return ireturn; 212 | } 213 | -------------------------------------------------------------------------------- /src/spc_cfg.c: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_cfg.c 3 | * @author Martin Kuemmel, Nor Pirzkal 4 | * @package spc_cfg 5 | * @version $Revision: 1.3 $ 6 | * @date $Date: 2010-06-15 09:48:34 $ 7 | */ 8 | 9 | #include "inima_utils.h" 10 | #include "spc_cfg.h" 11 | 12 | 13 | 14 | /** 15 | Utility function to parse a filename and populate a CfgStrings structure 16 | 17 | @param Filename a pointer to a string containing the name of a configuration file 18 | @param CfgInfo a pointer to an existing CfgStrings structure 19 | @return 20 | 21 | @see CfgStrings 22 | 23 | */ 24 | int 25 | CfgRead (char *Filename, struct CfgStrings *CfgInfo) 26 | { 27 | static char Buffer[BUFFERSIZE]; 28 | char *WorkPtr; 29 | char *CfgName; 30 | char *CfgData; 31 | struct CfgStrings *Cfg; 32 | FILE *CfgFile; 33 | 34 | CfgFile = fopen (Filename, "r"); 35 | if (NULL == CfgFile) 36 | { 37 | aXe_message (aXe_M_FATAL, __FILE__, __LINE__, "Could not open %s!\n", 38 | Filename); 39 | } 40 | 41 | // fprintf(stderr, "%s: %s\n", Filename, CfgInfo->name); 42 | 43 | while (NULL != fgets (Buffer, BUFFERSIZE, CfgFile)) 44 | { 45 | // check whether it is a valid 46 | // line, or whether it can be discarded 47 | if (!is_valid_inima_line(Buffer)) 48 | continue; 49 | /* clip off optional comment tail indicated by a semi-colon 50 | */ 51 | if (NULL != (WorkPtr = strchr (Buffer, ';'))) 52 | *WorkPtr = '\0'; 53 | else 54 | WorkPtr = Buffer + strlen (Buffer); 55 | 56 | /* clip off trailing and leading white space 57 | */ 58 | WorkPtr--; 59 | while (isspace ((int) *WorkPtr) && WorkPtr >= Buffer) 60 | *WorkPtr-- = '\0'; 61 | WorkPtr = NULL; 62 | 63 | WorkPtr = Buffer; 64 | while (isspace ((int) *WorkPtr)) 65 | WorkPtr++; 66 | if (0 == strlen (WorkPtr)) 67 | continue; 68 | 69 | CfgName = strtok (WorkPtr, " ="); 70 | 71 | if (NULL != CfgName) 72 | { 73 | /* Condition the name (lower case required), 74 | and strip leading white and a 'late' = from data part. 75 | */ 76 | //strlwr( CfgName ); 77 | CfgData = strtok (NULL, ""); 78 | if (CfgData != NULL) 79 | { 80 | while (isspace ((int) *CfgData)) 81 | CfgData++; 82 | if ('=' == *CfgData) 83 | CfgData++; 84 | while (isspace ((int) *CfgData)) 85 | CfgData++; 86 | } 87 | 88 | /* look for matching 'name' 89 | */ 90 | Cfg = CfgInfo; 91 | while (NULL != Cfg->name 92 | && 0 != strcmp (Cfg->name, CfgName)) 93 | Cfg++; 94 | 95 | /* duplicate the data if the name is found. 96 | */ 97 | // fprintf(stderr, "%s: %s: %s %i\n", Filename, CfgInfo->name, Buffer, strlen(Buffer)); 98 | // fprintf(stderr, "%s: %s:\n", Cfg->name, CfgData); 99 | if (NULL != Cfg->name) 100 | { 101 | if (NULL == CfgData) 102 | { 103 | fclose (CfgFile); 104 | aXe_message (aXe_M_FATAL, __FILE__, __LINE__, 105 | "Error. No data read for %s. Check format of configuration file.\n", 106 | Cfg->name); 107 | } 108 | Cfg->data = strdup (CfgData); /* strdup is not ANSI */ 109 | /* memory leaks if Cfg->data */ 110 | /* is malloc'ed already */ 111 | 112 | } /* undetected error on failure should not be a problem */ 113 | /* as configuration reading should be done early. */ 114 | } /* but test and handle it anyway ... */ 115 | } 116 | fclose (CfgFile); 117 | return NO_PROBLEMS; 118 | } 119 | 120 | 121 | /** 122 | Utility function to parse a NULL terminated array of strings and populate a CfgStrings structure 123 | 124 | @param Filename a pointer to a string containing the name of a confiuration file 125 | @param CfgInfo a pointer to an existing CfgStrings structure 126 | @return 127 | 128 | @see CfgStrings 129 | 130 | */ 131 | int 132 | CfgRead_from_array (char **arr, struct CfgStrings *CfgInfo) 133 | { 134 | char Buffer[BUFFERSIZE]; 135 | char *WorkPtr; 136 | char *CfgName; 137 | char *CfgData; 138 | struct CfgStrings *Cfg; 139 | int i=0; 140 | 141 | while (NULL != arr[i] && strcmp(arr[i],"NULL\0") != 0) 142 | { 143 | sprintf(Buffer,"%s",arr[i]); 144 | /* clip off optional comment tail indicated by a semi-colon 145 | */ 146 | if (NULL != (WorkPtr = strchr (Buffer, ';'))) 147 | *WorkPtr = '\0'; 148 | else 149 | WorkPtr = Buffer + strlen (Buffer); 150 | 151 | /* clip off trailing and leading white space 152 | */ 153 | WorkPtr--; 154 | while (isspace ((int) *WorkPtr) && WorkPtr >= Buffer) 155 | *WorkPtr-- = '\0'; 156 | WorkPtr = Buffer; 157 | while (isspace ((int) *WorkPtr)) 158 | WorkPtr++; 159 | if (0 == strlen (WorkPtr)) 160 | continue; 161 | 162 | CfgName = strtok (WorkPtr, " ="); 163 | 164 | if (NULL != CfgName) 165 | { 166 | /* Condition the name (lower case required), 167 | and strip leading white and a 'late' = from data part. 168 | */ 169 | //strlwr( CfgName ); 170 | CfgData = strtok (NULL, ""); 171 | if (CfgData != NULL) 172 | { 173 | while (isspace ((int) *CfgData)) 174 | CfgData++; 175 | if ('=' == *CfgData) 176 | CfgData++; 177 | while (isspace ((int) *CfgData)) 178 | CfgData++; 179 | } 180 | 181 | /* look for matching 'name' 182 | */ 183 | Cfg = CfgInfo; 184 | while (NULL != Cfg->name 185 | && 0 != strcmp (Cfg->name, CfgName)) 186 | Cfg++; 187 | 188 | /* duplicate the data if the name is found. 189 | */ 190 | if (NULL != Cfg->name) 191 | { 192 | Cfg->data = strdup (CfgData); /* strdup is not ANSI */ 193 | // strcpy(Cfg->data,CfgData); /* strdup is not ANSI */ 194 | /* memory leaks if Cfg->data */ 195 | /* is malloc'ed already */ 196 | if (NULL == Cfg->data) 197 | { 198 | aXe_message (aXe_M_FATAL, __FILE__, __LINE__, 199 | "Memory error. No data read"); 200 | } 201 | } /* undetected error on failure should not be a problem */ 202 | /* as configuration reading should be done early. */ 203 | } /* but test and handle it anyway ... */ 204 | i++; 205 | } 206 | return NO_PROBLEMS; 207 | } 208 | -------------------------------------------------------------------------------- /src/spc_sex.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spc_sex.h 3 | * Header files for the routines in spc_sex.c 4 | * 5 | * @author Martin Kuemmel, Nor Pirzkal 6 | * @package spc_sex 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | #ifndef SPC_DEF_H 11 | #define SPC_DEF_H 12 | 13 | #include "spc_CD.h" 14 | 15 | 16 | 17 | #define CATBUFFERSIZE 10240 18 | 19 | #define MAX(x,y) (((x)>(y))?(x):(y)) 20 | 21 | #define MIN_DIFFANGLE 3.0 22 | 23 | /** 24 | * Structure: ellipse 25 | * A description of an ellipse with a,b, theta. 26 | */ 27 | typedef struct 28 | { 29 | double a; 30 | double b; 31 | double theta; 32 | } 33 | ellipse; 34 | 35 | 36 | 37 | /** 38 | * Structure: SexObject 39 | * A SeXtractor 2.0 object type which contains 40 | * various information about the object 41 | */ 42 | typedef struct 43 | { 44 | int number; /* Sextractor ID of the object */ 45 | d_point xy_image; /* i,j coordinates of the barycenter of the object in image X_IMAGE, Y_IMAGE */ 46 | sky_coord xy_world; /* Celestial coordinates of the barycenter of the object X_WORLD, Y_WORLD */ 47 | ellipse el_image; /* Ellipsoidal description of object in image A_IMAGE, B_IMAGE, THETA_IMAGE */ 48 | ellipse el_world; /* Ellipsoidal description of object in world coordinates A_WORLD */ 49 | /* B_WORLD, THETA_WORLD */ 50 | double mag_auto; /* Object magnitude MAG_AUTO */ 51 | d_point backwindow; 52 | int modspec; 53 | int modimage; 54 | gsl_vector * lambdas; 55 | gsl_vector * magnitudes; 56 | } 57 | SexObject; 58 | 59 | 60 | extern SexObject * 61 | create_SexObject(const colinfo *actinfo, char *line, const gsl_vector * waves, 62 | const gsl_vector * cnums, const px_point backwin_cols, const 63 | px_point modinfo_cols, const int magcol, const int fullinfo); 64 | 65 | extern void 66 | SexObject_fprintf (FILE * output, SexObject * o); 67 | 68 | extern void 69 | SexMags_to_beamFlux(SexObject * sobj, beam *actbeam); 70 | 71 | extern void 72 | SexObject_to_slitgeom(const aperture_conf *conf, const SexObject * sobj, 73 | const double trace_angle, beam *actbeam); 74 | 75 | extern void 76 | fill_corner_ignore(SexObject * sobj, observation * const obs, aperture_conf *conf, 77 | int beamID, float dmag, beam *actbeam); 78 | 79 | extern d_point 80 | check_object_size(const aperture_conf *conf, const SexObject *sobj, const int beamID); 81 | 82 | extern void 83 | SexObject_to_beam(SexObject * sobj, observation * const obs, aperture_conf *conf, char conffile[], 84 | float mfwhm, float dmag, int auto_reorient, int bck_mode, 85 | int beamID, beam *actbeam); 86 | 87 | extern object * 88 | SexObject_to_objectII(SexObject * sobj, observation * const obs, 89 | aperture_conf *conf, char conffile[], float mfwhm, 90 | float dmag, int auto_reorient, int bck_mode); 91 | 92 | extern object * 93 | SexObject_to_object (SexObject * sobj, observation * const obs, 94 | aperture_conf *conf, char conffile[], float mfwhm, 95 | float dmag, int auto_reorient, int bck_mode); 96 | 97 | extern object ** 98 | SexObjects_to_oblist (SexObject ** sobjs, observation * const obs, 99 | aperture_conf *conf, char conffile[], float mfwhm, 100 | float dmag, int auto_reorient, int back_mode); 101 | 102 | extern object ** 103 | SexObjects_to_oblistII (SexObject ** sobjs, observation * const obs, 104 | aperture_conf *conf, char conffile[], float mfwhm, 105 | float dmag, int auto_reorient, int bck_mode); 106 | 107 | extern int 108 | check_conf_for_slitlessgeom(const aperture_conf *conf, const int auto_reorient); 109 | //check_conf_for_slitlessgeom(const aperture_conf *conf, const int slitless_geom); 110 | 111 | extern int 112 | fill_object_bbox (observation * const obs, beam * b, const float m_width, 113 | const int dxmin, const int dxmax); 114 | 115 | extern int 116 | size_of_sextractor_catalog (char filename[]); 117 | 118 | extern SexObject ** 119 | get_SexObject_from_catalog (char filename[], const double lambda_mark); 120 | 121 | extern void 122 | ABC_image_to_el (d_point *a, d_point *b, d_point *c, ellipse *el); 123 | 124 | extern void 125 | ABC_image_to_el2 (d_point *a, d_point *b, d_point *c, ellipse *el); 126 | 127 | extern void 128 | el_to_ABC_world (ellipse *el, sky_coord *a, sky_coord *b, sky_coord *c); 129 | 130 | extern void 131 | el_to_ABC_world2 (ellipse *el, sky_coord *a, sky_coord *b, sky_coord *c); 132 | 133 | extern void 134 | fill_missing_image_coordinates (SexObject * o, 135 | struct WorldCoor *from_wcs,int overwrite); 136 | 137 | extern void 138 | fill_all_missing_image_coordinates (SexObject ** sobjs, 139 | struct WorldCoor *from_wcs, 140 | int overwrite); 141 | 142 | extern void 143 | fill_missing_WCS_coordinates (SexObject * o, struct WorldCoor *from_wcs, 144 | int overwrite); 145 | 146 | extern void 147 | fill_all_missing_WCS_coordinates (SexObject ** sobjs, 148 | struct WorldCoor *from_wcs, 149 | int overwrite); 150 | 151 | extern void 152 | compute_new_image_coordinates (SexObject * o, struct WorldCoor *to_wcs); 153 | 154 | extern void 155 | compute_new_image_sexobject (SexObject * o, struct WorldCoor *to_wcs, int th_sky); 156 | 157 | extern void 158 | compute_all_new_image_coordinates (SexObject ** sobjs, 159 | struct WorldCoor *to_wcs); 160 | 161 | extern void 162 | catalog_to_wcs (char grismfile[], int hdunum, char infile[], char outfile[], 163 | struct WorldCoor *from_wcs, struct WorldCoor *to_wcs, 164 | int distortion, int overwrite_wcs, int overwrite_img); 165 | 166 | extern void 167 | catalog_to_wcs_nodim (char infile[], char outfile[], 168 | struct WorldCoor *to_wcs,int overwrite_wcs, 169 | int overwrite_img); 170 | 171 | extern gsl_vector * 172 | sobs_to_vout(const SexObject *sobs); 173 | 174 | extern void 175 | free_SexObjects (SexObject ** sobjs); 176 | #endif 177 | -------------------------------------------------------------------------------- /src/spce_sect.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: scpe_sect.c 3 | * A function find the abscissa of the section between a curve and 4 | * a line of given inclination through a number of points 5 | * (and its helpers) 6 | * 7 | * Usage: 8 | * sectionfun sf; 9 | * double res; 10 | * if (fill_in_sectionfun(&sf, init_lo, init_hi, inclination, 11 | * curve_func, curve_data)) 12 | * # init_hi and init_lo are the starting values for the bracketing 13 | * Error 14 | * for (i=0; i<20; i++) 15 | * if (!find_section_point(&sf,i,i,&res)) 16 | * printf("%f\n",res); 17 | * free_sectionfun(&sf); 18 | * 19 | * The coordinates passed to find_section_point should be relative 20 | * to the reference point within the framework of spc_extract 21 | * 22 | * @author Martin Kuemmel, Nor Pirzkal, Markus Demleitner 23 | * @package spce_sect 24 | * @version $Revision: 1.3 $ 25 | * @date $Date: 2010-06-15 09:48:34 $ 26 | * 27 | */ 28 | 29 | 30 | 31 | #include "spce_sect.h" 32 | 33 | /** 34 | computes the value of the section function. 35 | 36 | @param x abscissa at which to evaluate (should be relative to the beam's 37 | refpoint). 38 | @param data a sectionfun struct (declared void to please gsl). 39 | @return the value of the section function. 40 | */ 41 | static double 42 | compute_sectionfun (double x, void *data) 43 | { 44 | const sectionfun *const sf = data; 45 | double trace_y, sect_y; 46 | 47 | trace_y = sf->func->func (x, sf->func->data); 48 | sect_y = sf->m * (x - sf->x0) + sf->y0; 49 | return sect_y - trace_y; 50 | } 51 | 52 | 53 | /** 54 | finds the section point between a line of given slope through a given 55 | point and a not too unreasonable function. 56 | 57 | @param sf the section function descriptor, created by fill_in_sectionfun. 58 | @param x abscissa of the given point. 59 | @param x ordinate of the given point. 60 | @param res abscissa of section point. 61 | @returns 0 if section point could be found, -1 if not. 62 | */ 63 | int 64 | find_section_point (sectionfun *sf, const double x, const double y, 65 | double *const res) 66 | { 67 | int iter_count = 0; 68 | double x_lower, x_upper; 69 | 70 | if (sf->vertical) 71 | { 72 | *res = x; 73 | return 0; 74 | } 75 | 76 | sf->x0 = x; 77 | sf->y0 = y; 78 | 79 | if (compute_sectionfun (sf->interv->lower, sf) * 80 | compute_sectionfun (sf->interv->upper, sf) >= 0) 81 | { 82 | return -1; 83 | } 84 | gsl_root_fsolver_set (sf->solver, sf->gslfun, sf->interv->lower, 85 | sf->interv->upper); 86 | 87 | while (1) 88 | { 89 | gsl_root_fsolver_iterate (sf->solver); 90 | x_lower = gsl_root_fsolver_x_lower (sf->solver); 91 | x_upper = gsl_root_fsolver_x_upper (sf->solver); 92 | if (gsl_root_test_interval (x_lower, x_upper, 0.0001, 0.000001) == 93 | GSL_SUCCESS) 94 | break; 95 | 96 | if (iter_count++ > 100) 97 | { 98 | return -1; 99 | } 100 | } 101 | 102 | *res = gsl_root_fsolver_root (sf->solver); 103 | return 0; 104 | } 105 | 106 | 107 | /** 108 | prepares a sectionfun structure 109 | 110 | @param sf a pointer to the structure to fill 111 | @param inclination the slope of the line (orientation of the object) 112 | @param b the current beam 113 | @return 0 if successful, -1 otherwise 114 | */ 115 | int 116 | fill_in_sectionfun (sectionfun * const sf, const double inclination, 117 | const beam * const b) 118 | { 119 | gsl_function *gf; 120 | gsl_interval *interv; 121 | int i; 122 | double delta_x, delta_y, slope, x0, y0, x, xr, yr; 123 | 124 | if (fabs (inclination) < 0.001) 125 | { 126 | sf->vertical = 1; 127 | return 0; 128 | } 129 | else 130 | { 131 | sf->vertical = 0; 132 | } 133 | 134 | sf->m = tan (inclination); 135 | sf->func = b->spec_trace; 136 | 137 | if (!(gf = malloc (sizeof (gsl_function)))) 138 | { 139 | return -1; 140 | } 141 | gf->function = &compute_sectionfun; 142 | gf->params = sf; 143 | 144 | if (!(interv = malloc (sizeof (gsl_interval)))) 145 | { 146 | free (gf); 147 | gf = NULL; 148 | return -1; 149 | } 150 | 151 | interv->lower = b->bbox[0].x - b->refpoint.x; 152 | interv->upper = b->bbox[1].x - b->refpoint.x; 153 | 154 | /* find out slope of object w.r.t. the spectrum trace */ 155 | xr = b->refpoint.x; 156 | yr = sf->func->func (0, sf->func->data) + b->refpoint.y; 157 | delta_y = 158 | b->spec_trace->func (interv->lower, 159 | b->spec_trace->data) - 160 | b->spec_trace->func (interv->upper, b->spec_trace->data); 161 | delta_x = interv->lower - interv->upper; 162 | if (fabs (delta_x) < 1e-7) 163 | { 164 | aXe_message (aXe_M_FATAL, __FILE__, __LINE__, 165 | "Vanishing bounding box"); 166 | } 167 | slope = delta_y / delta_x; 168 | if (fabs (sf->m - slope) < 1e-7) 169 | { 170 | aXe_message (aXe_M_FATAL, __FILE__, __LINE__, 171 | "Spectrum trace and object" 172 | " orientation are almost parallel"); 173 | } 174 | 175 | /* extend interval such that the section point should be found at 176 | least when everything is linear */ 177 | for (i = 0; i < 4; i++) 178 | { 179 | x0 = b->corners[i].x - xr; 180 | y0 = b->corners[i].y - yr; 181 | x = (y0 - x0 * sf->m) / (slope - sf->m); 182 | if (x < interv->lower) 183 | interv->lower = x; 184 | if (x > interv->upper) 185 | interv->upper = x; 186 | } 187 | 188 | /* choose something harmless to initialize the solver */ 189 | sf->x0 = 1; 190 | sf->y0 = 1; 191 | if (compute_sectionfun (interv->lower, sf) * 192 | compute_sectionfun (interv->upper, sf) >= 0) 193 | { 194 | //aXe_message(aXe_M_FATAL, __FILE__, __LINE__, "Invalid spectrum trace " 195 | // "function"); 196 | } 197 | sf->gslfun = gf; 198 | sf->interv = interv; 199 | sf->solver = gsl_root_fsolver_alloc (gsl_root_fsolver_brent); 200 | return 0; 201 | } 202 | 203 | 204 | /** 205 | releases the memory allocated in the fields of a sectionfun structure 206 | (but not the structure itself) 207 | 208 | @param sf the struct the children of which should be freed 209 | */ 210 | 211 | void 212 | free_sectionfun (sectionfun * const sf) 213 | { 214 | if (sf->vertical) 215 | { 216 | return; 217 | } 218 | gsl_root_fsolver_free (sf->solver); 219 | free (sf->interv); 220 | sf->interv = NULL; 221 | free (sf->gslfun); 222 | sf->gslfun = NULL; 223 | } 224 | -------------------------------------------------------------------------------- /src/aXe_CHECK.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: aXe_CHECK.c 3 | * $Revision: 1.5 $ $Date: 2010-06-15 09:48:34 $ 4 | * ST-ECF European Coordinating Facility 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "aXe_grism.h" 25 | #include "aXe_utils.h" 26 | #include "spce_PET.h" 27 | #include "inout_aper.h" 28 | #include "trace_conf.h" 29 | #include "aper_conf.h" 30 | #include "spc_sex.h" 31 | #include "disp_conf.h" 32 | #include "spc_wl_calib.h" 33 | #include "spce_binning.h" 34 | #include "spc_spc.h" 35 | #include "spce_pgp.h" 36 | #include "spce_output.h" 37 | #include "spc_FITScards.h" 38 | #include "aper_check.h" 39 | 40 | #define AXE_IMAGE_PATH "AXE_IMAGE_PATH" 41 | #define AXE_OUTPUT_PATH "AXE_OUTPUT_PATH" 42 | #define AXE_CONFIG_PATH "AXE_CONFIG_PATH" 43 | 44 | 45 | 46 | 47 | 48 | int 49 | main(int argc, char *argv[]) 50 | { 51 | char *opt; 52 | 53 | char grism_image[MAXCHAR]; 54 | char grism_image_path[MAXCHAR]; 55 | 56 | char aper_file[MAXCHAR]; 57 | char aper_file_path[MAXCHAR]; 58 | 59 | char PET_file[MAXCHAR]; 60 | char PET_file_path[MAXCHAR]; 61 | 62 | char outputroot[MAXCHAR]; 63 | char outputroot_path[MAXCHAR]; 64 | 65 | char output_path[MAXCHAR]; 66 | 67 | object **oblist; 68 | observation *obs; 69 | ap_pixel *PET; 70 | fitsfile *PET_ptr; 71 | 72 | int index, i; 73 | char label[MAXCHAR]; 74 | 75 | int f_status = 0; 76 | 77 | aXe_mask *mask; 78 | 79 | 80 | int aperID, beamID, objindex; 81 | FITScards *cards; 82 | 83 | if ((argc < 3) || (opt = get_online_option("help", argc, argv))) { 84 | fprintf(stdout, 85 | "ST-ECF European Coordinating Facility\n" 86 | "Copyright (C) 2002 Nor Pirzkal\n" 87 | "aXe_CHECK Version %s:\n" 88 | " Task that generates some Postscript stamp images from the\n" 89 | " content of a Pixel Extraction Table (PET)\n" 90 | " The trace is overplotted and is generated from the group\n" 91 | " of pixels in the PET which have the smallest projected distance\n" 92 | " to the trace in the PET. No analytical a-priori trace function \n" 93 | " is used.\n" 94 | "\n" 95 | "Usage:\n" 96 | " aXe_CHECK grism_image Pixel_extraction_table config_filename [options]\n" 97 | "\n" 98 | "Options:\n" 99 | " -outputroot=[string] - overwrite the automatically generated path\n" 100 | " and rootname of the output postscript stamp\n" 101 | " images\n" 102 | "\n", RELEASE); 103 | exit(1); 104 | } 105 | fprintf(stdout, "aXe_CHECK: Starting...\n"); 106 | 107 | index = 0; 108 | 109 | strcpy(grism_image, argv[++index]); 110 | build_path(AXE_IMAGE_PATH, grism_image, grism_image_path); 111 | 112 | strcpy(PET_file, argv[++index]); 113 | build_path(AXE_OUTPUT_PATH, PET_file, PET_file_path); 114 | 115 | strcpy(aper_file, argv[++index]); 116 | build_path(AXE_OUTPUT_PATH, aper_file, aper_file_path); 117 | 118 | if ((opt = get_online_option("outputroot", argc, argv))) { 119 | strcpy(outputroot, opt); 120 | } else { 121 | replace_file_extension(PET_file, outputroot, ".PET.fits", "", 122 | -1); 123 | } 124 | 125 | build_path(AXE_OUTPUT_PATH, outputroot, outputroot_path); 126 | sprintf(output_path, "%s.CHECK.fits", outputroot_path); 127 | 128 | fprintf(stdout, "aXe_CHECK: Input file name: %s\n", 129 | grism_image_path); 130 | fprintf(stdout, "aXe_CHECK: Input Aperture file name: %s\n", 131 | aper_file_path); 132 | fprintf(stdout, "aXe_CHECK: Input PET file name: %s\n", 133 | PET_file_path); 134 | fprintf(stdout, "aXe_CHECK: Name of CHECK file : %s\n", 135 | output_path); 136 | 137 | obs = load_dummy_observation(); 138 | obs = load_image_t(grism_image_path, 1, -1, -1, 0); 139 | 140 | /* Loading the object list */ 141 | //fprintf(stdout, "aXe_CHECK: Loading object aperture list..."); 142 | //oblist = file_to_object_list_seq(aper_file_path, obs); 143 | //fprintf(stdout, "Done.\n"); 144 | 145 | //Open the OPET file for reading 146 | fits_open_file(&PET_ptr, PET_file_path, READONLY, &f_status); 147 | if (f_status) { 148 | ffrprt(stdout, f_status); 149 | aXe_message(aXe_M_FATAL, __FILE__, __LINE__, 150 | "aXe_CHECK: Could not open file: %s", 151 | PET_file_path); 152 | } 153 | mask = aXe_mask_init(obs); 154 | 155 | while (1) { 156 | 157 | /* Get the PET for this object */ 158 | PET = get_ALL_from_next_in_PET(PET_ptr, &aperID, &beamID); 159 | if ((aperID == -1) && (beamID == -1)) 160 | break; 161 | fprintf(stdout, "aXe_CHECK: object %d%c", aperID, BEAM(beamID)); 162 | fflush(stdout); 163 | //objindex = find_object_in_object_list(oblist, aperID); 164 | 165 | { 166 | //add_ap_p_to_aXe_mask(PET, mask); 167 | //mark_trace_in_aXe_mask(PET, mask); 168 | } 169 | 170 | if (PET != NULL) 171 | free(PET); 172 | 173 | fprintf(stdout, ".Done\n"); 174 | fflush(stdout); 175 | } 176 | //free_oblist(oblist); 177 | 178 | fits_close_file(&PET_ptr, &f_status); 179 | 180 | gsl_to_FITSimage(mask->img, "tmp.fits", 1, NULL); 181 | 182 | fprintf(stdout, "aXe_CHECK: Done...\n"); 183 | 184 | 185 | /* Copy the header info from the grism image */ 186 | { 187 | FITScards *cards; 188 | cards = get_FITS_cards(PET_file_path, 1); 189 | put_FITS_cards("tmp.fits", 1, cards); 190 | free_FITScards(cards); 191 | } 192 | 193 | exit(0); 194 | } 195 | -------------------------------------------------------------------------------- /src/spce_pgp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * File: spce_pgp.c 3 | * Various PGplot routines amd helper functions. 4 | * 5 | * @author Nor Pirzkal, Markus Demleitner 6 | * @package spce_pgp 7 | * @version $Revision: 1.3 $ 8 | * @date $Date: 2010-06-15 09:48:34 $ 9 | */ 10 | 11 | #include "spce_pgp.h" 12 | 13 | #define MAX(x,y) (((x)>(y))?(x):(y)) 14 | #define MIN(x,y) (((x)<(y))?(x):(y)) 15 | #define NCOL 64 16 | 17 | #ifdef HAVE_PGPLOT 18 | 19 | #include 20 | 21 | 22 | /** 23 | A helper function to convert a gsl_matrix into a linear 24 | integer array suitble to plot with pgplot's routines 25 | 26 | @param ar 2D gal_matrix 27 | @param r a pointer to an already allocated amount of memeory 28 | */ 29 | void 30 | gsl_to_pgarr (gsl_matrix * ar, int *r) 31 | { 32 | int i, j, k; 33 | 34 | for (i = 0; i < ar->size1; i++) 35 | { 36 | for (j = 0; j < ar->size2; j++) 37 | { 38 | k = j * ar->size1 + i; 39 | r[k] = (int) gsl_matrix_float_get (ar, i, j); 40 | } 41 | } 42 | } 43 | 44 | 45 | /** 46 | Outputs a stamp image using pgplot and using the information for an 47 | ap_pixel structure. 48 | 49 | @param ap_p an existing ap_pixel structure 50 | @param n_sub subsampling used (usualy 1.) 51 | @param ob a pointer to the object correspoding to ap_p 52 | @param beamnum the numeric ID of the beam corresponding to ap_p 53 | @param filename a pointer to a char array containing the name of the file to output the 54 | postscript stamp image to 55 | 56 | */ 57 | void 58 | pgp_stamp_image (const ap_pixel * const ap_p, const int n_sub, 59 | const object * ob, int beamnum, char filename[], 60 | const int negative) 61 | { 62 | int ncol = NCOL; 63 | double r, g, b; 64 | beam *curbeam = ob->beams + beamnum; 65 | gsl_matrix *fpix; 66 | const ap_pixel *cur_p; 67 | double pxmin = ap_p->count, pxmax = ap_p->count; 68 | int i; 69 | int n; 70 | int m; 71 | float *x, *y; 72 | int p_x, p_y; 73 | double minx = ap_p->x, miny = ap_p->y; 74 | //gsl_vector_int * trace_inds = get_trace_inds(ap_p); 75 | gsl_vector_int *trace_inds; 76 | int *k; 77 | int ind; 78 | int icilo, icihi; 79 | char label[255]; 80 | 81 | 82 | quad_to_bbox (curbeam->corners, curbeam->bbox, curbeam->bbox + 1); 83 | n = (curbeam->bbox[1].x - curbeam->bbox[0].x + 1) * n_sub; 84 | m = (curbeam->bbox[1].y - curbeam->bbox[0].y + 1) * n_sub; 85 | 86 | fpix = 87 | gsl_matrix_alloc ((curbeam->bbox[1].x - curbeam->bbox[0].x + 88 | 1) * n_sub, 89 | (curbeam->bbox[1].y - curbeam->bbox[0].y + 90 | 1) * n_sub); 91 | 92 | trace_inds = (gsl_vector_int *) get_trace_inds (ap_p); 93 | 94 | x = malloc (trace_inds->size * sizeof (float)); 95 | y = malloc (trace_inds->size * sizeof (float)); 96 | if ((x == NULL) || (y == NULL)) 97 | { 98 | aXe_message (aXe_M_FATAL, __FILE__, __LINE__, 99 | "pgp_stamp_image: Could not allocate temporary memory space"); 100 | return; 101 | } 102 | if (!fpix) 103 | { 104 | aXe_message (aXe_M_FATAL, __FILE__, __LINE__, 105 | "Could not allocate GSL array"); 106 | return; 107 | } 108 | sprintf (label, "Object %d Beam %c at (%4.2f,%4.2f)", ob->ID, 109 | BEAM (beamnum), curbeam->refpoint.x, curbeam->refpoint.y); 110 | 111 | for (i = 0; i < trace_inds->size; i++) 112 | { 113 | if (gsl_vector_int_get (trace_inds, i) != -1) 114 | { 115 | break; 116 | } 117 | } 118 | if (i == trace_inds->size) 119 | { 120 | aXe_message (aXe_M_ERROR, __FILE__, __LINE__, 121 | "No valid trace found"); 122 | return; 123 | } 124 | 125 | for (cur_p = ap_p; cur_p->p_x != -1; cur_p++) 126 | { 127 | if (!isnan (cur_p->count)) 128 | { 129 | pxmin = MIN (pxmin, cur_p->count); 130 | pxmax = MAX (pxmax, cur_p->count); 131 | } 132 | minx = MIN (minx, cur_p->x); 133 | miny = MIN (miny, cur_p->y); 134 | } 135 | //cpgopen("plot.ps/CPS"); 136 | cpgopen (filename); 137 | 138 | cpgpage (); 139 | cpgscr (0, 0, 0.3, 0.2); 140 | cpgsvp (0.05, 0.95, 0.05, 0.95); 141 | cpgwnad (0., n, 0., m); 142 | cpgqcir (&icilo, &icihi); 143 | 144 | for (i = 0; i < trace_inds->size; i++) 145 | { 146 | ind = gsl_vector_int_get (trace_inds, i); 147 | x[i] = floor (ap_p[ind].x - minx) + .5; 148 | y[i] = floor (ap_p[ind].y - miny) + .5; 149 | } 150 | 151 | ncol = icihi - icilo; 152 | /* Create a vector fot pgplot to plot */ 153 | k = malloc (n * m * sizeof (int)); 154 | if (k == NULL) 155 | { 156 | aXe_message (aXe_M_FATAL, __FILE__, __LINE__, "Out of memory."); 157 | } 158 | gsl_matrix_set_all (fpix, negative ? 0 : pxmax); 159 | 160 | for (cur_p = ap_p; cur_p->p_x != -1; cur_p++) 161 | { 162 | p_x = (int) floor ((cur_p->x - minx) * n_sub); 163 | p_y = (int) floor ((cur_p->y - miny) * n_sub); 164 | gsl_matrix_set (fpix, p_x, p_y, 165 | (cur_p->count - pxmin) * ncol / (pxmax - pxmin) + 166 | icilo + 1); 167 | } 168 | 169 | gsl_to_pgarr (fpix, k); 170 | 171 | /* Set up a uniform BW color table */ 172 | for (i = 0; i < ncol; i++) 173 | { 174 | r = (i - 1.) / (ncol - 1.) * 0.8 + 0.2; 175 | g = MAX (0.0, 2. * (i - 1. - ncol / 2.0) / (ncol - 1.)); 176 | b = 0.2 + 0.4 * (ncol - i) / ncol; 177 | cpgscr (i + 15, r, g, b); 178 | //cpgscr(i + 15, 1 - i * 1. / ncol, 1 - i * 1. / ncol, 1 - i * 1. / ncol); 179 | //cpgscr(i + 15, i * 1. / ncol, i * 1. / ncol, i * 1. / ncol); 180 | } 181 | //cpgpixl(k, 10, 10, 1, 10, 1, 10, 0.0, 10, 0., 10); 182 | 183 | cpgpixl (k, n, m, 1, n, 1, m, 0.0, n, 0., m); 184 | cpgline (trace_inds->size, x, y); 185 | 186 | cpgsci (1); 187 | cpgmtxt ("t", 1., 0.0, 0., label); 188 | cpgbox ("bcnts", 0., 0, "bcnts", 0., 0); 189 | cpgend (); 190 | 191 | free (k); 192 | k = NULL; 193 | free (x); 194 | x = NULL; 195 | free (y); 196 | y = NULL; 197 | } 198 | #endif 199 | #ifndef HAVE_PGPLOT 200 | void 201 | pgp_stamp_image (const ap_pixel * const ap_p, const int n_sub, 202 | const object * ob, int beamnum, char filename[], 203 | const int negative) 204 | { 205 | aXe_message (aXe_M_WARN4, __FILE__, __LINE__, 206 | "pgp_stamp_image: PGplot support was not compiled in at compile time. "); 207 | return; 208 | 209 | } 210 | #endif 211 | -------------------------------------------------------------------------------- /src/model_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * File: model_utils.h 3 | * Header file for model_utils.c 4 | * 5 | * @author Martin Kuemmel 6 | * @package modelutils 7 | * @version $Revision: 1.2 $ 8 | * @date $Date: 2009-06-18 09:50:07 $ 9 | */ 10 | #ifndef _MODEL_UTILS_H 11 | #define _MODEL_UTILS_H 12 | 13 | 14 | #define AXE_CONFIG_PATH "AXE_CONFIG_PATH" 15 | 16 | #define LIGHTVEL 2.99792458 // light velocity/1.0E+08 17 | 18 | #define NSUB 1.0 // half the number of subsampling steps 19 | // done in the gaussian (take only integers!!) 20 | #define NDIFF 3.0 // half the number of subsampling steps when 21 | // diffusing the spectrum 22 | 23 | #define MINPSF 0.1 24 | 25 | 26 | /* 27 | * Struct: dirobject 28 | */ 29 | typedef struct dirobject 30 | { 31 | int ID; // the ID of the object 32 | 33 | d_point refpoint; // the refpoint of the object 34 | 35 | d_point xy_off[MAX_BEAMS]; // possible offsets appy to the beams of the direct object 36 | 37 | d_point drzscale; // the relative scale along the major and minor axis respectively 38 | 39 | int ix_min; // smallest x-value where the direct object is defined 40 | int ix_max; // largest x-value where the direct object is defined 41 | int iy_min; // smallest y-value where the direct object is defined 42 | int iy_max; // largest y-value where the direct object is defined 43 | 44 | int bb_sed; 45 | 46 | energy_distrib *SED; 47 | dirim_emission *dirim; 48 | // double (*dpsf) (const double, const double); 49 | } 50 | dirobject; 51 | 52 | /* 53 | * Struct: beamspec 54 | */ 55 | typedef struct 56 | { 57 | int objectID; // the object ID of the modelled beam 58 | int beamID; // the beam ID of the modelled beam 59 | 60 | d_point model_ref; // the start coo's of the beam model in the image 61 | 62 | gsl_matrix * model; // the model data 63 | } 64 | beamspec; 65 | 66 | 67 | 68 | /* 69 | * Struct: tracedata 70 | */ 71 | typedef struct 72 | { 73 | int npoints; 74 | double dx_start; 75 | 76 | gsl_vector *dx; 77 | gsl_vector *dy; 78 | gsl_vector *xi; 79 | gsl_vector *lambda; 80 | gsl_vector *dlambda; 81 | gsl_vector *flux; 82 | gsl_vector *gvalue; 83 | } 84 | tracedata; 85 | 86 | extern dirim_emission * 87 | model_gauss_dirim(dirobject *actdir, beam actbeam, aperture_conf *conf, double psf_offset); 88 | 89 | extern calib_function * 90 | get_calib_function(beamspec *actspec, dirobject *actdir, char CONF_file[], const aperture_conf * conf); 91 | 92 | extern spectrum * 93 | get_throughput_spec(beamspec *actspec, char CONF_file[]); 94 | 95 | extern tracedata * 96 | compute_tracedata(const beam actbeam, const dirobject *actdir, 97 | const calib_function *wl_calibration, const beamspec *actspec); 98 | 99 | extern tracedata * 100 | compute_short_tracedata(const aperture_conf *conf, const beam actbeam, 101 | const dirobject *actdir, const calib_function *wl_calibration, 102 | const beamspec *actspec); 103 | 104 | extern double 105 | get_valid_tracedata(tracedata *acttrace, const calib_function *wl_calibration); 106 | 107 | extern void 108 | select_tracedata(tracedata *acttrace, const calib_function *wl_calibration, const int nentries); 109 | 110 | extern void 111 | fill_fluxfrom_SED(const dirobject *actdir, tracedata *acttrace); 112 | 113 | extern energy_distrib * 114 | make_sed_from_beam(const beam onebeam, const int int_type, const int objID); 115 | 116 | extern void 117 | print_tracedata(tracedata *acttrace); 118 | 119 | extern dirobject ** 120 | oblist_to_dirlist(char grism_file[], char CONF_file[], const px_point npixels, 121 | object **oblist, spectral_models *spec_mod, 122 | const double model_scale, const int int_type); 123 | 124 | extern dirobject ** 125 | oblist_to_dirlist2(char grism_file[], char CONF_file[], const px_point npixels, 126 | object **oblist, spectral_models *spec_mod, object_models *obj_mod, 127 | const double model_scale, const int int_type); 128 | 129 | extern dirobject * 130 | fill_dirobject(const object *actobject, const px_point npixels, 131 | gsl_matrix *drzcoeffs, const double model_scale, const int max_offset); 132 | 133 | extern dirobject * 134 | fill_dirobj_fromdirim(const object *actobject, object_models *objmodels); 135 | 136 | extern gsl_vector * 137 | get_refpoint_ranges(const object *actobject); 138 | 139 | extern void 140 | fill_spectrum(const object *actobject, dirobject *actdir, 141 | spectral_models *spec_mod, const int int_type); 142 | 143 | extern dirobject * 144 | get_dirobject_from_list(dirobject ** dirlist, const int ID); 145 | 146 | extern d_point 147 | get_dirobject_meanpos(dirobject *actdir); 148 | 149 | extern beam 150 | get_beam_for_beamspec(object **oblist, const int nobjects, const beamspec *actspec); 151 | 152 | extern beamspec * 153 | get_beamspec_from_list(beamspec **speclist, const int aperID, const int beamID); 154 | 155 | extern void 156 | print_dirobject(const dirobject * actdir); 157 | 158 | extern int 159 | check_interp_type(const int inter_type, const int n_flux, const int ID); 160 | 161 | extern void 162 | free_dirlist (dirobject ** dirlist); 163 | 164 | extern void 165 | free_dirlist_specmodels(dirobject ** dirlist, spectral_models *spec_mod); 166 | 167 | extern void 168 | free_enerdist (energy_distrib *sed); 169 | 170 | extern void 171 | free_speclist(beamspec **speclist); 172 | 173 | extern void 174 | free_tracedata(tracedata *acttrace); 175 | 176 | //extern double 177 | //get_flux_from_dirobject(const dirobject *actdir, double in_wave); 178 | 179 | extern double 180 | get_flux_from_SED(const energy_distrib *sed, double in_wave); 181 | 182 | extern double 183 | get_flambda_from_magab(double mag, double lambda); 184 | 185 | extern double 186 | get_aveflux_from_SED(const energy_distrib *sed, double in_wave, double int_wave); 187 | 188 | extern void 189 | fill_gaussvalues(const d_point dpixel, const beam actbeam, 190 | const dirobject *actdir, const double lambda_ref, 191 | const aperture_conf * conf, const double psf_offset, 192 | tracedata *acttrace); 193 | 194 | extern beam 195 | get_newbeam(const beam actbeam, const double dpsf); 196 | 197 | extern double 198 | get_dpsf(const double lambda_ref, const double lambda, 199 | const aperture_conf *conf, const beam actbeam); 200 | 201 | extern double 202 | get_sub_emodel_value(const d_point dpixel, const beam actbeam, 203 | const d_point drzscale); 204 | extern double 205 | get_emodel_value(const d_point dpixel, const beam actbeam, 206 | const d_point drzscale); 207 | 208 | extern double 209 | get_dpsf_WFC(const double lambda_ref, const double lambda); 210 | 211 | extern double 212 | get_dpsf_HRC(const double lambda_ref, const double lambda); 213 | 214 | extern double 215 | get_dpsf_SBC(const double lambda_ref, const double lambda); 216 | 217 | extern double 218 | get_polyN_gsl (const double x, const gsl_vector *params); 219 | #endif 220 | -------------------------------------------------------------------------------- /src/aXe_TFIT.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: aXe_TFIT.c 3 | * $Revision: 1.4 $ $Date: 2010-06-15 09:48:34 $ 4 | * ST-ECF - Space Telescope European Coordinating Facility 5 | * Martin Kuemmel 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | #include 22 | #include 23 | #include 24 | #include "aXe_grism.h" 25 | #include "aXe_utils.h" 26 | #include "inout_aper.h" 27 | #include "aper_conf.h" 28 | #include 29 | #include "trfit_utils.h" 30 | 31 | 32 | #define AXE_IMAGE_PATH "AXE_IMAGE_PATH" 33 | #define AXE_OUTPUT_PATH "AXE_OUTPUT_PATH" 34 | #define AXE_CONFIG_PATH "AXE_CONFIG_PATH" 35 | 36 | 37 | int 38 | main(int argc, char *argv[]) 39 | { 40 | 41 | char *opt; 42 | 43 | char grism_image[MAXCHAR]; 44 | char grism_image_path[MAXCHAR]; 45 | 46 | char conf_file[MAXCHAR]; 47 | char conf_file_path[MAXCHAR]; 48 | 49 | char aper_file[MAXCHAR]; 50 | char aper_file_path[MAXCHAR]; 51 | 52 | 53 | int i, j; 54 | int num; 55 | 56 | object **oblist; 57 | observation *obs; 58 | 59 | aperture_conf *conf; 60 | 61 | 62 | int err_num=0, dq_num=0, extver=0; 63 | 64 | double exptime; 65 | 66 | gsl_vector *fit_result; 67 | 68 | if ((argc < 1) || (opt = get_online_option("help", argc, argv))) { 69 | fprintf(stdout, 70 | "aXe_TFIT Version %s:\n" 71 | "\n", RELEASE); 72 | exit(1); 73 | } 74 | fprintf(stdout, "aXe_TFIT: Starting...\n"); 75 | 76 | // Get the data file name 77 | strcpy(grism_image, argv[1]); 78 | 79 | // Get the configuration file name 80 | strcpy(conf_file, argv[2]); 81 | build_path(AXE_CONFIG_PATH, conf_file, conf_file_path); 82 | 83 | // Read the configuration file 84 | conf = get_aperture_descriptor(conf_file_path); 85 | 86 | // Determine where the various extensions are in the FITS file 87 | build_path(AXE_IMAGE_PATH, grism_image, grism_image_path); 88 | get_extension_numbers(grism_image_path, conf, conf->optkey1, conf->optval1); 89 | 90 | // Get or set up the name of the output Aperture File 91 | if ((opt = get_online_option ("in_AF", argc, argv))) 92 | { 93 | /* get it */ 94 | strcpy (aper_file, opt); 95 | strcpy (aper_file_path, opt); 96 | } 97 | else { 98 | // Build aperture file name 99 | replace_file_extension (grism_image, aper_file, ".fits", 100 | ".OAF", conf->science_numext); 101 | build_path (AXE_OUTPUT_PATH, aper_file, aper_file_path); 102 | } 103 | 104 | fprintf(stdout, 105 | "aXe_TFIT: Input configuration file name: %s\n", 106 | conf_file_path); 107 | fprintf(stdout, 108 | "aXe_TFIT: Input data file name: %s\n", 109 | grism_image_path); 110 | fprintf(stdout, 111 | "aXe_TFIT: SCI extension number: %d\n", 112 | conf->science_numext); 113 | fprintf(stdout, 114 | "aXe_TFIT: ERR extension number: %d\n", 115 | conf->errors_numext); 116 | fprintf(stdout, 117 | "aXe_TFIT: DQ extension number: %d\n", 118 | conf->dq_numext); 119 | fprintf(stdout, 120 | "aXe_TFIT: DQ mask: %d\n", 121 | conf->dqmask); 122 | fprintf(stdout, 123 | "aXe_TFIT: Input aperture file name: %s\n", 124 | aper_file_path); 125 | fprintf(stdout, "\n\n"); 126 | 127 | /* Loading the observation data */ 128 | fprintf(stdout, "aXe_TFIT: "); 129 | 130 | // 131 | // try to get the descriptor 'exptime' from the 'sci'-extension 132 | // 133 | exptime = (double)get_float_from_keyword(grism_image_path, 134 | conf->science_numext, 135 | conf->exptimekey); 136 | if (isnan(exptime)) 137 | exptime = (double)get_float_from_keyword(grism_image_path, 1, 138 | conf->exptimekey); 139 | if (isnan(exptime)) 140 | exptime = 1.0; 141 | 142 | // Load an image from AXE_DATA_PATH 143 | obs = load_image_t(grism_image_path, conf->science_numext, 144 | conf->errors_numext, conf->dq_numext, 145 | conf->dqmask, exptime, conf->rdnoise); 146 | 147 | // Loading the object list 148 | fprintf(stdout, "aXe_TFIT: Loading object list..."); 149 | oblist = file_to_object_list_seq(aper_file_path, obs); 150 | fprintf(stdout, "%d objects loaded.\n", object_list_size(oblist)); 151 | 152 | // initialize the counter 153 | i = 0; 154 | 155 | // check whether there are apertures 156 | if (oblist != NULL) { 157 | 158 | // go over all apertures 159 | while (oblist[i] != NULL) { 160 | 161 | // print the current aperture ID 162 | fprintf(stdout, "aXe_TFIT: Fitting object ID:%d", oblist[i]->ID); 163 | 164 | // go over all beams 165 | for (j = 0; j < oblist[i]->nbeams; j++) { 166 | 167 | // skip beam if ignore flag for thisbeam is set 168 | if (oblist[i]->beams[j].ignore !=0 || oblist[i]->beams[j].ID != 0) 169 | { 170 | fprintf(stdout,", %c ( Ignored )", 171 | BEAM(oblist[i]->beams[j].ID)); 172 | continue; 173 | } 174 | 175 | // print the current beam ID 176 | fprintf(stdout, ", %c (Fitted)", BEAM(oblist[i]->beams[j].ID)); 177 | 178 | 179 | // fit the trace of the beam, modify the 180 | // beam definition with the new values 181 | // oblist[i]->beams[j].refpoint.y = fit_beamtrace(conf, obs, j, oblist[i]->beams[j]); 182 | fit_result = fit_beamtrace(conf, obs, j, oblist[i]->beams[j]); 183 | oblist[i]->beams[j].refpoint.x = gsl_vector_get(fit_result,0); 184 | oblist[i]->beams[j].refpoint.y = gsl_vector_get(fit_result,1); 185 | oblist[i]->beams[j].width = gsl_vector_get(fit_result,4); 186 | 187 | gsl_vector_free(fit_result); 188 | } 189 | 190 | // give feedback on the progress, 191 | // enhance the counter 192 | fprintf(stdout, " Done.\n"); 193 | i++; 194 | } 195 | } 196 | 197 | // write the modified beam definitions 198 | // to an OAF file 199 | fprintf (stdout, "aXe_TFIT: Writing new aperture file...");fflush(stdout); 200 | num = object_list_to_file (oblist, aper_file_path, 1); 201 | fprintf (stdout, "%d beams written.\n", num); 202 | 203 | // release the memory 204 | free_observation(obs); 205 | if (oblist != NULL){ 206 | free_oblist(oblist);} 207 | 208 | // print a last status message and exit 209 | fprintf(stdout, "aXe_TFIT: Done...\n"); 210 | exit(0); 211 | } 212 | -------------------------------------------------------------------------------- /src/aXe_DIRIMAGE.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: aXe_DIRIMAGE.c 3 | * $Revision: 1.5 $ $Date: 2010-06-15 09:48:34 $ 4 | * ST-ECF European Coordinating Facility 5 | * Martin Kuemmel 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "aXe_grism.h" 26 | #include "aXe_utils.h" 27 | #include "aper_conf.h" 28 | #include "spce_output.h" 29 | 30 | #define AXE_IMAGE_PATH "AXE_IMAGE_PATH" 31 | #define AXE_OUTPUT_PATH "AXE_OUTPUT_PATH" 32 | #define AXE_CONFIG_PATH "AXE_CONFIG_PATH" 33 | #define AXE_SIMDATA_PATH "AXE_SIMDATA_PATH" 34 | 35 | int 36 | main (int argc, char *argv[]) 37 | { 38 | char dirim_file[MAXCHAR]; 39 | char dirim_file_path[MAXCHAR]; 40 | 41 | char conf_file[MAXCHAR]; 42 | char conf_file_path[MAXCHAR]; 43 | 44 | char tpass_file[MAXCHAR]; 45 | char tpass_file_path[MAXCHAR]; 46 | 47 | char aper_file[MAXCHAR]; 48 | char aper_file_path[MAXCHAR]; 49 | 50 | char specmod_file[MAXCHAR]; 51 | char specmod_file_path[MAXCHAR]; 52 | 53 | char objmod_file[MAXCHAR]; 54 | char objmod_file_path[MAXCHAR]; 55 | 56 | char map_file[MAXCHAR]; 57 | char map_file_path[MAXCHAR]; 58 | 59 | char *opt; 60 | aperture_conf *conf; 61 | observation *obs; 62 | 63 | int index; 64 | double model_scale=0.0; 65 | double lambda_psf=0.0; 66 | double tel_area=0.0; 67 | 68 | FITScards *cards; 69 | 70 | if ((argc < 3) || (opt = get_online_option ("help", argc, argv))) 71 | { 72 | fprintf (stdout, 73 | "ST-ECF European Coordinating Facility\n" 74 | "aXe_DIRIMAGE Version %s:\n" 75 | "\n",RELEASE); 76 | exit (1); 77 | } 78 | 79 | fprintf (stdout, "aXe_DIRIMAGE: Starting...\n"); 80 | 81 | // initialize an index for the command arguments 82 | index = 0; 83 | 84 | // save the first argument as direct image name 85 | strcpy (dirim_file, argv[++index]); 86 | build_path (AXE_IMAGE_PATH, dirim_file, dirim_file_path); 87 | 88 | // save the second argument as aXe config file name 89 | strcpy (conf_file, argv[++index]); 90 | build_path (AXE_CONFIG_PATH, conf_file, conf_file_path); 91 | 92 | // save the third argument as total throughput file 93 | strcpy (tpass_file, argv[++index]); 94 | build_path (AXE_SIMDATA_PATH, tpass_file, tpass_file_path); 95 | 96 | // load the aXe configuration file 97 | conf = get_aperture_descriptor (conf_file_path); 98 | 99 | /* Determine where the various extensions are in the FITS file */ 100 | get_extension_numbers(dirim_file_path, conf,conf->optkey1,conf->optval1); 101 | 102 | /* Get or set up the name of the output Aperture File */ 103 | if ((opt = get_online_option ("in_AF", argc, argv))) 104 | { 105 | /* get it */ 106 | strcpy (aper_file, opt); 107 | strcpy (aper_file_path, opt); 108 | } 109 | else { 110 | /* Build aperture file name */ 111 | replace_file_extension (dirim_file, aper_file, ".fits", 112 | ".OAF", conf->science_numext); 113 | build_path (AXE_OUTPUT_PATH, aper_file, aper_file_path); 114 | } 115 | 116 | // check whether a name for the spectral 117 | // models file is given 118 | if ((opt = get_online_option ("model_spectra", argc, argv))) 119 | { 120 | // get and set up the filename 121 | strcpy (specmod_file, opt); 122 | build_path (AXE_IMAGE_PATH, specmod_file, specmod_file_path); 123 | } 124 | else 125 | { 126 | // set the filenames to NULL, 127 | // indicating that they are NOT used 128 | strcpy (specmod_file, ""); 129 | strcpy (specmod_file_path, ""); 130 | } 131 | 132 | if (opt = get_online_option ("model_images", argc, argv)) 133 | { 134 | // get and set up the name for the image templates 135 | strcpy (objmod_file, opt); 136 | build_path (AXE_IMAGE_PATH, objmod_file, objmod_file_path); 137 | } 138 | else 139 | { 140 | // set the filenames to NULL, 141 | // indicating that they are NOT used 142 | strcpy (objmod_file, ""); 143 | strcpy (objmod_file_path, ""); 144 | } 145 | 146 | 147 | /* Build object CONT file name */ 148 | replace_file_extension (dirim_file, map_file, ".fits", 149 | ".CONT.fits", conf->science_numext); 150 | build_path (AXE_OUTPUT_PATH, map_file, map_file_path); 151 | 152 | // determine the extend of the gaussian emission model 153 | if ((opt = get_online_option ("model_scale", argc, argv))) 154 | model_scale = atof(opt); 155 | else 156 | model_scale = 3.0; 157 | 158 | // determine the telescope area 159 | if ((opt = get_online_option ("tel_area", argc, argv))) 160 | tel_area = atof(opt); 161 | else 162 | // set the default HST collecting area 163 | tel_area = 45238.93; 164 | 165 | // give feedback onto the screen: 166 | // report on input and output 167 | // and also on specific parameter 168 | fprintf (stdout, "aXe_DIRIMAGE: Input Aperture file name: %s\n", 169 | aper_file_path); 170 | fprintf (stdout, "aXe_DIRIMAGE: Output CONT file name: %s\n", 171 | map_file_path); 172 | fprintf (stdout, "aXe_DIRIMAGE: Computing gaussian contamination\n"); 173 | fprintf (stdout, "aXe_DIRIMAGE: Scale factor for the direct image model %f\n", model_scale); 174 | if (strlen(specmod_file_path) > 0) 175 | fprintf (stdout, "aXe_DIRIMAGE: Using spectral models in table: %s\n", specmod_file_path); 176 | if (strlen(objmod_file_path) > 0) 177 | fprintf (stdout, "aXe_DIRIMAGE: Using direct emission objects in image:: %s\n", specmod_file_path); 178 | 179 | 180 | fprintf (stdout, "aXe_DIRIMAGE: "); 181 | obs = load_sci_image (dirim_file_path, conf->science_numext); 182 | 183 | 184 | compute_dirimage_model(dirim_file_path, conf_file_path, tpass_file_path, specmod_file_path, 185 | objmod_file_path, aper_file_path, model_scale, tel_area, 186 | lambda_psf, obs, map_file_path); 187 | 188 | // copy the header from the grism image 189 | // to the contamination image 190 | cards = get_FITS_cards(dirim_file_path, conf->science_numext); 191 | put_FITS_cards(map_file_path, 2, cards); 192 | free_FITScards(cards); 193 | 194 | // de-allocate memory 195 | //free_observation(obs); 196 | free_aperture_conf(conf); 197 | 198 | // free the observation structure 199 | free_observation(obs); 200 | 201 | // report on the program end 202 | fprintf (stdout, "aXe_DIRIMAGE: Done...\n"); 203 | 204 | exit (0); 205 | } 206 | --------------------------------------------------------------------------------