72 if ( fname == NULL ) fout = stdout ;
73 else fout = fopen( fname,
"w" ) ;
74 fprintf( fout,
"Found %d orders\n", list->
size ) ;
76 for( i = 0 ; i<list->
size ; i++ ) {
81 fprintf( fout,
"Starty: %d, Endy: %d\n", list->
list[i].
starty,
84 for( j = 0 ; j<=
degree ; j++ )
85 fprintf( fout,
" %lf ",
86 cpl_polynomial_get_coeff( list->
list[i].
cenpoly, &j ) ) ;
87 for( j = 0 ; j<=
degree ; j++ )
88 fprintf( fout,
"%lf ",
90 for( j = 0 ; j<=
degree ; j++ )
91 fprintf( fout,
" %lf ",
93 fprintf( fout,
"\n" ) ;
95 if ( fname != NULL ) fclose( fout ) ;
112 for( i = 0 ; i<list->
size ; i++ )
141 if (cpl_error_get_code() != CPL_ERROR_NONE) {
174 if (cpl_error_get_code() != CPL_ERROR_NONE) {
192 cpl_table* table = NULL;
193 cpl_propertylist* header = NULL;
194 const char* tablename = NULL;
196 int i = 0, pol_degree = 0;
203 check( tablename = cpl_frame_get_filename(frame));
209 check(header = cpl_propertylist_load(tablename,0));
210 check(cpl_propertylist_append(result->
header, header));
216 for(i=0;i<result->
size;i++){
219 CPL_TYPE_INT, i, &(result->
list[i].
order)));
224 CPL_TYPE_INT, i, &pol_degree);
225 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
239 for( k = 0 ; k <= pol_degree ; k++ ) {
260 if ( cpl_table_has_column( table, colname ) == 1 ) {
269 if ( cpl_table_has_column( table, colname ) == 1 ) {
283 CPL_TYPE_INT, i, &result->
list[i].
endy));
330 if (cpl_error_get_code () != CPL_ERROR_NONE) {
331 xsh_error_msg(
"can't load frame %s",cpl_frame_get_filename(frame));
352 double* posx,
double* posy,
int deg_poly)
354 int ordersize, i, nborder, nb_keep_order;
355 cpl_vector *vx = NULL, *vy = NULL;
371 for(i=1; i <=
size; i++) {
376 int absorder =
order[i-1];
379 (absorder <= list->absorder_max) ){
382 check( vx = cpl_vector_wrap( ordersize, &(posx[i-ordersize])));
383 check( vy = cpl_vector_wrap( ordersize, &(posy[i-ordersize])));
385 nborder+1,
order[i-1],ordersize);
387 "You must have more points to fit correctly this order (may be detectarclines-ordertab-deg-y is too large or (for xsh_predict) detectarclines-min-sn is too large)");
390 list->
list[nb_keep_order].
order = nborder;
398 xsh_msg(
"WARNING skipping absorder %d because is not in range",
424 for (i = 0; i < (*list)->size; i++){
433 cpl_free( (*list)->list);
479 cpl_propertylist * res = NULL;
532 for( i = 0 ; i<list->
size ; i++ )
565 for( i=0; i< lista->
size; i++){
570 result->
list[i].
cenpoly = cpl_polynomial_duplicate(
582 for( i=0; i< listb->
size; i++){
588 result->
list[j].
cenpoly = cpl_polynomial_duplicate(
601 if (cpl_error_get_code() != CPL_ERROR_NONE) {
670 check( x_no_bin = cpl_polynomial_eval_1d( poly, y_no_bin, NULL));
702 result = floor( res+0.5);
725 cpl_polynomial *p = NULL;
732 for( i=0; i< list->
size; i++){
734 check( coef = cpl_polynomial_get_coeff( p, &pows));
736 check( cpl_polynomial_set_coeff( p, &pows, coef));
740 check( coef = cpl_polynomial_get_coeff( p, &pows));
742 check( cpl_polynomial_set_coeff( p, &pows, coef));
746 check( coef = cpl_polynomial_get_coeff( p, &pows));
748 check( cpl_polynomial_set_coeff( p, &pows, coef));
752 check( coef = cpl_polynomial_get_coeff( p, &pows));
754 check( cpl_polynomial_set_coeff( p, &pows, coef));
758 check( coef = cpl_polynomial_get_coeff( p, &pows));
760 check( cpl_polynomial_set_coeff( p, &pows, coef));
790 const char* filename,
const char* tag,
const int ny)
792 cpl_table* table = NULL;
793 cpl_table* tabqc = NULL;
794 cpl_frame * result = NULL ;
804 double* pcenterx=NULL;
805 double* pcentery=NULL;
806 double* pedgeupx=NULL;
807 double* pedgelox=NULL;
808 double* pslicupx=NULL;
809 double* psliclox=NULL;
812 cpl_table *tab_ext = NULL;
821 check( pol_degree = cpl_polynomial_get_degree(
826 check(table = cpl_table_new( order_list->
size));
837 for( k = 0 ; k<= pol_degree ; k++ ) {
841 cpl_table_new_column(table, colname, CPL_TYPE_FLOAT));
844 cpl_table_new_column(table, colname, CPL_TYPE_FLOAT));
847 cpl_table_new_column(table, colname, CPL_TYPE_FLOAT));
851 cpl_table_new_column(table, colname, CPL_TYPE_FLOAT));
855 cpl_table_new_column(table, colname, CPL_TYPE_FLOAT));
865 check(cpl_table_set_size(table,order_list->
size));
869 for(i=0;i<order_list->
size;i++){
879 for( k = 0 ; k <= pol_degree ; k++ ) {
885 check(cpl_table_set(table, colname,i,coef));
893 check(cpl_table_set(table, colname,i,coef));
901 check(cpl_table_set(table, colname,i,coef));
909 check(cpl_table_set(table, colname, i, coef));
917 check(cpl_table_set(table, colname, i, coef));
927 check( tabqc = cpl_table_new(nraw));
965 for( iorder=0; iorder< order_list->
size; iorder++){
980 xsh_msg(
"Warning starty equal zero, put starty ==> 1");
984 xsh_msg(
"Warning starty equal zero, put endy ==> %d",
ny);
1029 CPL_GREATER_THAN, -1));
1031 tab_ext = cpl_table_extract_selected( tabqc);
1035 if (strstr(tag,
"EDGE") != NULL) {
1038 "number of detected order edges");
1040 check( cpl_table_save(table, order_list->
header, NULL, filename,
1042 check( cpl_table_save(tab_ext, NULL, NULL, filename,
1047 CPL_FRAME_GROUP_PRODUCT, CPL_FRAME_LEVEL_TEMPORARY));
1058 cpl_frame* spectralformat_frame, cpl_frame** qth_order_tab_frame,
1061 cpl_table *order_tab = NULL;
1062 cpl_table *order_tab_ext = NULL;
1063 const char* order_tab_name = NULL;
1065 cpl_table *order_tab_qth = NULL;
1066 cpl_table *order_tab_d2 = NULL;
1067 cpl_table *order_tab_ext_qth = NULL;
1068 cpl_table *order_tab_ext_d2 = NULL;
1070 cpl_propertylist *header = NULL;
1081 check( order_tab_name = cpl_frame_get_filename( order_tab_frame));
1083 check(order_tab_ext=cpl_table_load(order_tab_name,2,0));
1084 check( header = cpl_propertylist_load( order_tab_name, 0));
1085 check( order_tab_size = cpl_table_get_nrow( order_tab));
1086 for (i=0; i< order_tab_size; i++){
1088 const char* lamp = NULL;
1091 CPL_TYPE_INT, i, &absorder));
1095 if ( strcmp(lamp,
"QTH")==0){
1096 check( cpl_table_select_row( order_tab, i));
1099 check( cpl_table_unselect_row( order_tab, i));
1103 check( order_tab_qth = cpl_table_extract_selected( order_tab));
1104 check( cpl_table_not_selected( order_tab));
1105 check( order_tab_d2 = cpl_table_extract_selected( order_tab));
1108 check( order_tab_ext_d2 = cpl_table_extract_selected( order_tab_ext));
1109 cpl_table_select_all(order_tab_ext);
1112 check( order_tab_ext_qth = cpl_table_extract_selected( order_tab_ext));
1115 check( cpl_table_save( order_tab_qth, header, NULL,
"ORDER_TAB_CENTR_QTH_UVB.fits", CPL_IO_DEFAULT));
1116 check( cpl_table_save( order_tab_ext_qth, header, NULL,
"ORDER_TAB_CENTR_QTH_UVB.fits", CPL_IO_EXTEND));
1117 check( cpl_table_save( order_tab_d2, header, NULL,
"ORDER_TAB_CENTR_D2_UVB.fits", CPL_IO_DEFAULT));
1118 check( cpl_table_save( order_tab_ext_d2, header, NULL,
"ORDER_TAB_CENTR_D2_UVB.fits", CPL_IO_EXTEND));
1121 *qth_order_tab_frame = cpl_frame_new();
1122 cpl_frame_set_filename( *qth_order_tab_frame,
"ORDER_TAB_CENTR_QTH_UVB.fits");
1123 *d2_order_tab_frame = cpl_frame_new();
1124 cpl_frame_set_filename( *d2_order_tab_frame,
"ORDER_TAB_CENTR_D2_UVB.fits");
static xsh_instrument * instrument
xsh_order_list * xsh_order_list_create(xsh_instrument *instr)
create an empty order list
void xsh_order_split_qth_d2(cpl_frame *order_tab_frame, cpl_frame *spectralformat_frame, cpl_frame **qth_order_tab_frame, cpl_frame **d2_order_tab_frame, xsh_instrument *instr)
void xsh_order_list_set_bin_y(xsh_order_list *list, int bin)
Set the bin of image in y.
int xsh_order_list_get_index_by_absorder(xsh_order_list *list, double absorder)
void xsh_order_list_apply_shift(xsh_order_list *list, double xshift, double yshift)
Shift a order list.
cpl_frame * xsh_order_list_save(xsh_order_list *order_list, xsh_instrument *instrument, const char *filename, const char *tag, const int ny)
Save an order list to a frame.
void xsh_order_list_set_bin_x(xsh_order_list *list, int bin)
Set the bin of image in x.
int xsh_order_list_eval_int(xsh_order_list *list, cpl_polynomial *poly, double y)
Evaluate an order list poly but return the central pixel position rounding the polynomial.
xsh_order_list * xsh_order_list_load(cpl_frame *frame, xsh_instrument *instr)
load an order list from a frame
xsh_order_list * xsh_order_list_merge(xsh_order_list *lista, xsh_order_list *listb)
cpl_propertylist * xsh_order_list_get_header(xsh_order_list *list)
get header of the table
int xsh_order_list_get_starty(xsh_order_list *list, int i)
get position on Y axis of first pixel detected on order
void xsh_order_list_dump(xsh_order_list *list, const char *fname)
void xsh_order_list_fit(xsh_order_list *list, int size, double *order, double *posx, double *posy, int deg_poly)
fit the polynomial solution of given points
int xsh_order_list_get_endy(xsh_order_list *list, int i)
get position on Y axis of last pixel detected on order
int xsh_order_list_get_order(xsh_order_list *list, int absorder)
xsh_order_list * xsh_order_list_new(int size)
Create a new order list from size (no check)
void xsh_order_list_free(xsh_order_list **list)
free memory associated to an order_list
void xsh_order_list_verify(xsh_order_list *list, int ny)
double xsh_order_list_eval(xsh_order_list *list, cpl_polynomial *poly, double y)
Evaluate an order list poly.
#define XSH_ASSURE_NOT_ILLEGAL(cond)
#define XSH_ASSURE_NOT_ILLEGAL_MSG(cond, msg)
#define xsh_error_msg(...)
#define XSH_ASSURE_NOT_NULL(pointer)
int xsh_instrument_get_binx(xsh_instrument *instrument)
XSH_INSTRCONFIG * xsh_instrument_get_config(xsh_instrument *i)
Get the instrument default set of keywords.
int xsh_instrument_get_biny(xsh_instrument *instrument)
#define xsh_msg_dbg_medium(...)
#define xsh_msg(...)
Print a message on info level.
#define xsh_msg_dbg_low(...)
#define xsh_msg_dbg_high(...)
void xsh_pfits_set_pcatg(cpl_propertylist *plist, const char *value)
Write the PCATG value.
void xsh_unwrap_vector(cpl_vector **v)
Unwrap a vector and set the pointer to NULL.
void xsh_free_polynomial(cpl_polynomial **p)
Deallocate a polynomial and set the pointer to NULL.
double convert_data_to_bin(double data, int binning)
double convert_bin_to_data(double bin_data, int binning)
void xsh_free_table(cpl_table **t)
Deallocate a table and set the pointer to NULL.
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
cpl_error_code xsh_get_table_value(const cpl_table *table, const char *colname, cpl_type coltype, int i, void *result)
Read a table value from a fits table.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
xsh_instrument * instrument
cpl_propertylist * header
cpl_polynomial * edguppoly
cpl_polynomial * edglopoly
cpl_polynomial * slicuppoly
cpl_polynomial * sliclopoly
#define XSH_ORDER_MIN_UVB_D2
#define XSH_ORDER_MAX_UVB_QTH
#define XSH_ORDER_TABLE_COLNAME_SLICUP
#define XSH_ORDER_TABLE_COLNAME_SLICUPX
#define XSH_ORDER_TABLE_COLNAME_SLICLOX
#define XSH_ORDER_TABLE_COLNAME_EDGLOX
#define XSH_ORDER_TABLE_COLNAME_SLICLO
#define XSH_ORDER_TABLE_COLNAME_ENDY
#define XSH_ORDER_TABLE_COLNAME_EDGUP
#define XSH_ORDER_TABLE_COLNAME_CENTERX
#define XSH_ORDER_TABLE_COLNAME_STARTY
#define XSH_ORDER_TABLE_COLNAME_EDGLO
#define XSH_ORDER_TABLE_COLNAME_CENTERY
#define XSH_ORDER_TABLE_COLNAME_ABSORDER
#define XSH_ORDER_TABLE_COLNAME_CENTER
#define XSH_ORDER_TABLE_COLNAME_EDGUPX
#define XSH_ORDER_TABLE_DEGY
#define XSH_ORDER_TABLE_COLNAME_ORDER
cpl_frame * xsh_frame_product(const char *fname, const char *tag, cpl_frame_type type, cpl_frame_group group, cpl_frame_level level)
Creates a frame with given characteristics.
#define XSH_ORDER_TAB_EDGES
#define XSH_CMP_TAG_LAMP(tag_in, TAG)
#define XSH_QC_ORD_EDGE_NDET
#define XSH_NEW_PROPERTYLIST(POINTER)
#define XSH_CALLOC(POINTER, TYPE, SIZE)
#define XSH_TABLE_LOAD(TABLE, NAME)
#define XSH_TABLE_FREE(TABLE)
cpl_polynomial * xsh_polynomial_fit_1d_create(const cpl_vector *x_pos, const cpl_vector *values, int degree, double *mse)