File: detected_slits.cpp

package info (click to toggle)
cpl-plugin-vimos 3.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 23,188 kB
  • sloc: ansic: 169,153; cpp: 14,555; sh: 4,250; python: 1,423; makefile: 899; perl: 10
file content (102 lines) | stat: -rw-r--r-- 4,280 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* $Id: detected_slits.cpp,v 1.5 2013-07-24 14:58:34 cgarcia Exp $
 *
 * This file is part of the MOSCA library
 * Copyright (C) 2013 European Southern Observatory
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/*
 * $Author: cgarcia $
 * $Date: 2013-07-24 14:58:34 $
 * $Revision: 1.5 $
 * $Name: not supported by cvs2svn $
 */


#include <iostream>
#include <stdexcept>
#include <sstream>
#include <cpl_table.h>
#include "detected_slits.h"

std::vector<mosca::detected_slit>  
mosca::detected_slits_load_fits(const std::string& fitsfile_slit_loc,
                                const std::string& fitsfile_curv_coeff,
                                int image_disp_size)
{
    std::vector<detected_slit> slits;
    
    /* We read from extension 1 of slit location table */
    cpl_table* slit_table = cpl_table_load(fitsfile_slit_loc.c_str(), 1, 0);
    
    /* We read from extension 1 of curvature coefficients table */
    cpl_table* curv_coeff = cpl_table_load(fitsfile_curv_coeff.c_str(), 1, 0);

    if(2*cpl_table_get_nrow(slit_table) != cpl_table_get_nrow(curv_coeff))
        throw std::invalid_argument("FITS Tables do not match");
    
    for(cpl_size irow = 0 ; irow < cpl_table_get_nrow(slit_table); irow++)
    {
        int null;
        int slit_id = cpl_table_get_int(slit_table, 
                                        "slit_id", irow, &null); 
        double disp_bottom = cpl_table_get_double(slit_table,
                                               "xbottom", irow, &null); 
        disp_bottom = 1;
        double disp_top    = cpl_table_get_double(slit_table,
                                               "xtop", irow, &null);
        disp_top = image_disp_size;
        double spa_bottom  = cpl_table_get_double(slit_table, 
                                               "ybottom", irow, &null); 
        double spa_top     = cpl_table_get_double(slit_table, 
                                               "ytop", irow, &null);
        
        int slit_id_check = cpl_table_get_int(curv_coeff, 
                                              "slit_id", 2*irow, &null);
        
        int position_spatial_corrected  = cpl_table_get_int(slit_table, 
                                               "position", irow, &null); 
        int length_spatial_corrected     = cpl_table_get_int(slit_table, 
                                               "length", irow, &null);
        
        if(slit_id != slit_id_check)
            throw std::runtime_error("Slit identification doesn't match");

        cpl_size ndegree = cpl_table_get_ncol(curv_coeff) - 1;

        std::vector<double> bottom_trace_coeff;
        std::vector<double> top_trace_coeff;
        for(cpl_size idx_coeff = 0; idx_coeff < ndegree; idx_coeff++)
        {
            std::ostringstream colname;
            colname<<std::left<<"c"<<idx_coeff;
            top_trace_coeff.push_back(cpl_table_get_double
                    (curv_coeff, colname.str().c_str(), 2*irow, NULL));
            bottom_trace_coeff.push_back(cpl_table_get_double
                    (curv_coeff, colname.str().c_str(), 2*irow + 1, NULL));
        }
        
        
        slits.push_back(mosca::detected_slit(slit_id, disp_bottom, spa_bottom,
                                              disp_top, spa_top,
                                              position_spatial_corrected,
                                              length_spatial_corrected,
                                              bottom_trace_coeff, 
                                              top_trace_coeff));
    }
    
    return slits;
}