35#include <sys/resource.h>
43#define M_PI 3.1415926535897932384626433832795
49#define XSH_MALLOC( POINTER, TYPE, SIZE) \
50 assure(POINTER == NULL, CPL_ERROR_ILLEGAL_OUTPUT,\
51 "Try to allocate non NULL pointer");\
52 POINTER = (TYPE*)(cpl_malloc(SIZE*sizeof(TYPE)));\
53 assure (POINTER != NULL, CPL_ERROR_ILLEGAL_OUTPUT,\
54 "Memory allocation failed!")
56#define XSH_CALLOC( POINTER, TYPE, SIZE) \
57 assure(POINTER == NULL, CPL_ERROR_ILLEGAL_OUTPUT,\
58 "Try to allocate non NULL pointer");\
59 POINTER = (TYPE*)(cpl_calloc(SIZE,sizeof(TYPE)));\
60 assure (POINTER != NULL, CPL_ERROR_ILLEGAL_OUTPUT,\
61 "Memory allocation failed!")
63#define XSH_REALLOC( POINTER, TYPE, SIZE ) \
64 assure(POINTER != NULL, CPL_ERROR_ILLEGAL_INPUT,\
65 "Try to re-allocate NULL pointer") ;\
66 POINTER = (TYPE *)cpl_realloc(POINTER,SIZE*sizeof(TYPE)));\
67 assure( POINTER != NULL, CPL_ERROR_ILLEGAL_OUTPUT,\
68 "Memory re-allocation failed!")
70#define XSH_NEW_PROPERTYLIST( POINTER) \
71 assure(POINTER == NULL, CPL_ERROR_ILLEGAL_OUTPUT,\
72 "Try to allocate non NULL pointer");\
73 POINTER = cpl_propertylist_new();\
74 assure (POINTER != NULL, CPL_ERROR_ILLEGAL_OUTPUT,\
75 "Memory allocation for propertylist failed!")
77#define XSH_NEW_FRAME( POINTER) \
78 assure(POINTER == NULL, CPL_ERROR_ILLEGAL_OUTPUT,\
79 "Try to allocate non NULL pointer");\
80 POINTER = cpl_frame_new();\
81 assure (POINTER != NULL, CPL_ERROR_ILLEGAL_OUTPUT,\
82 "Memory allocation for frame failed!")
84#define XSH_NEW_FRAMESET( POINTER) \
85 assure(POINTER == NULL, CPL_ERROR_ILLEGAL_OUTPUT,\
86 "Try to allocate non NULL pointer");\
87 POINTER = cpl_frameset_new();\
88 assure (POINTER != NULL, CPL_ERROR_ILLEGAL_OUTPUT,\
89 "Memory allocation for frameset failed!")
92#define XSH_FREE(POINTER)\
93 if(POINTER!=NULL) cpl_free(POINTER);\
96#define XSH_PREFIX(prefix,name,instr) \
98 prefix = xsh_stringcat_any(name,"_",\
99 xsh_instrument_arm_tostring(instr ),\
101 XSH_ASSURE_NOT_NULL(prefix)
103#define XSH_MODE_PREFIX(prefix,name,instr) \
105 prefix = xsh_stringcat_any(name,"_",\
106 xsh_instrument_mode_tostring(instr ),\
108 xsh_instrument_arm_tostring(instr ),\
110 XSH_ASSURE_NOT_NULL(prefix)
113#define XSH_TABLE_NEW_COL(TABLE, NAME, UNIT, TYPE) \
114 check( cpl_table_new_column(TABLE, NAME, TYPE));\
115 check( cpl_table_set_column_unit( TABLE, NAME, UNIT))
117#define BOOLEAN_TO_STRING( boolean) \
118 boolean == 0 ? "false" : "true"
160cpl_frame*
xsh_frame_inv( cpl_frame* in,
const char *filename,
189cpl_error_code
xsh_end(
const char *recipe_id, cpl_frameset *frames,
190 cpl_parameterlist * list );
191cpl_error_code
xsh_begin(cpl_frameset *frames,
192 const cpl_parameterlist *parameters,
194 cpl_frameset ** raws, cpl_frameset ** calib,
195 const char * tag_list[],
197 const char *recipe_id,
198 unsigned int binary_version,
const char *short_descr);
202 const char *keyword, cpl_type keywordtype,
void *result);
212 const char *s4,
const char *s5);
214 const char *s4,
const char *s5,
const char *s6);
220 int (*compar)(
const void *,
const void *));
223 double* mean,
double* stdev);
250 double max,
double* tcheb_pos);
276 const cpl_imagelist * imlist,
291 cpl_table_select_operator
operator,
294 cpl_table_select_operator
operator,
300 const char *X1,
const char *X2,
const char *Y,
302 int degree1,
int degree2,
303 const char *polynomial_fit,
const char *residual_square,
304 const char *variance_fit,
305 double *mse,
double *red_chisq,
313 const cpl_propertylist* pheader);
345 const char *column_y,
int *istart );
394 const cpl_image *spectrum_error,
395 const cpl_propertylist *spectrum_header,
399 const double airmass,
401 const cpl_table *atm_extinction,
402 cpl_image **scaled_error);
406 const cpl_frame *atm_ext_frame,
407 cpl_boolean correct_binning,
413 const cpl_frame *atm_ext_frame,
414 cpl_boolean correct_binning,
419 double frac_min,
double *mean,
double *stdev);
422 double frac_min,
double *median,
double *stdev);
425 double kappa,
int niter,
double frac_min,
int deg, cpl_polynomial **poly,
426 double *chisq,
int **flags);
443 double *params,
double *errs,
int *status);
465cpl_error_code
calc_flat_slit_qc(cpl_image* im,
int xa1,
int xa2, cpl_propertylist* qclist);
static xsh_instrument * instrument
polynomial * xsh_polynomial_regression_2d(cpl_table *t, const char *X1, const char *X2, const char *Y, const char *sigmaY, int degree1, int degree2, const char *polynomial_fit, const char *residual_square, const char *variance_fit, double *mse, double *red_chisq, polynomial **variance, double kappa, double min_reject)
Fit a 2d polynomial to three table columns.
cpl_frame * xsh_normalize_spectrum(const cpl_frame *obj_frame, const cpl_frame *atm_ext_frame, cpl_boolean correct_binning, xsh_instrument *instrument, const char *tag)
Normalize a spectrum.
int xsh_max_int(int x, int y)
Maximum of two numbers.
void xsh_unwrap_vector(cpl_vector **v)
Unwrap a vector and set the pointer to NULL.
cpl_frame * xsh_frameset_average(cpl_frameset *set, const char *tag)
Dump propertylist.
void xsh_vector_fit_gaussian(cpl_vector *x, cpl_vector *y, XSH_GAUSSIAN_FIT *result)
set debug level
void xsh_image_fit_spline(cpl_image *img, xsh_grid *grid)
perform spline fit
void xsh_free_polynomial(cpl_polynomial **p)
Deallocate a polynomial and set the pointer to NULL.
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
void xsh_free_parameterlist(cpl_parameterlist **p)
Deallocate a parameter list and set the pointer to NULL.
const char * xsh_set_recipe_sky_file_prefix(char *rec_prefix)
Set recipe sky frames prefix.
cpl_error_code xsh_check_input_is_unbinned(cpl_frame *in)
Check if an input frame is not binned.
cpl_image * xsh_normalize_spectrum_image(const cpl_image *spectrum, const cpl_image *spectrum_error, const cpl_propertylist *spectrum_header, const int binx, const double gain, const double exptime, const double airmass, const int n_traces, const cpl_table *atm_extinction, cpl_image **scaled_error)
Normalize a spectrum.
int xsh_time_stamp_set(int ts)
set timestamp
cpl_error_code get_average_qc_from_raws(cpl_frameset *fset, xsh_instrument *instrument, cpl_propertylist *qclist)
int xsh_fileutils_copy(const char *srcpath, const char *dstpath)
char * xsh_stringcat_4(const char *s1, const char *s2, const char *s3, const char *s4)
String concatenation.
const char * xsh_string_tolower(char *s)
Convert all uppercase characters in a string into lowercase characters.
int xsh_select_table_rows(cpl_table *t, const char *column, cpl_table_select_operator operator, double value)
Select table rows.
char * xsh_stringcat_5(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5)
String concatenation.
void xsh_tools_min_max(int size, double *tab, double *min, double *max)
computes min & max in ab array
cpl_error_code xsh_frameset_dump_nod_info(cpl_frameset *set)
Dump frameset nod info.
const char * xsh_string_toupper(char *s)
Convert all lowercase characters in a string into uppercase characters.
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
int xsh_debug_level_get(void)
get debug level
int xsh_fileutils_move(const char *srcpath, const char *dstpath)
cpl_error_code xsh_update_pheader_in_image_multi(cpl_frame *frame, const cpl_propertylist *pheader)
Update FITS header.
double xsh_spline_hermite(double xp, const double *x, const double *y, int n, int *istart)
Spline interpolation based on Hermite polynomials.
void xsh_unwrap_bivector_vectors(cpl_bivector **b)
Unwrap a bi-vector and set the pointer to NULL.
double convert_data_to_bin(double data, int binning)
cpl_error_code xsh_get_property_value(const cpl_propertylist *plist, const char *keyword, cpl_type keywordtype, void *result)
Read a property value from a property list.
int xsh_min_int(int x, int y)
Minimum of two numbers.
cpl_frame * xsh_spectrum_interpolate_linear(cpl_frame *table_frame, const double wstep, const double wmin, const double wmax)
spectra interpolation
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
double xsh_vector_get_err_median(cpl_vector *vect)
Computes median error on a data set.
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
int xsh_debug_level_set(int level)
set debug level
char * xsh_stringcat_6(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6)
String concatenation.
char * xsh_set_recipe_file_prefix(cpl_frameset *raw, const char *recipe)
Set recipe frames prefix.
char * xsh_stringcat_3(const char *s1, const char *s2, const char *s3)
String concatenation.
void xsh_free_temporary_files(void)
Free temprary files list.
cpl_frame * xsh_normalize_spectrum_ord(const cpl_frame *obj_frame, const cpl_frame *atm_ext_frame, cpl_boolean correct_binning, xsh_instrument *instrument, const char *tag)
Normalize a spectrum.
void xsh_free_array(cpl_array **v)
Deallocate an array and set the pointer to NULL.
double * xsh_function1d_xcorrelate(double *line_i, int width_i, double *line_t, int width_t, int half_search, int normalise, double *xcorr_max, double *delta)
double xsh_tools_tchebitchev_transform(double pos, double min, double max)
computes Tchebitchev transformation
cpl_frame * xsh_util_multiply_by_response_ord(cpl_frame *merged_sci, cpl_frame *response, const char *tag)
Multiply input frame by response frame.
double xsh_vector_get_err_mean(cpl_vector *vect)
Computes mean error on a data set.
const char * xsh_debug_level_tostring(void)
set debug level
void xsh_tools_get_statistics(double *tab, int size, double *median, double *mean, double *stdev)
Compute median, stdev and mean for the tab.
void xsh_mem_dump(const char *prompt)
void xsh_free_stats(cpl_stats **s)
Deallocate a stats object and set the pointer to NULL.
void xsh_reindex_float(float *data, int *idx, int size)
TO BE DESCRIBED.
void xsh_frame_table_save(cpl_frame *frm, const char *name_o)
Save a table frame.
cpl_error_code xsh_monitor_flux(cpl_frame *frm_ima, const cpl_frame *frm_tab, xsh_instrument *instrument, const char *qc_key_prefix)
Monitor Flux level along the orders traces given by an input table
cpl_frame * xsh_frame_mult(cpl_frame *in, xsh_instrument *instr, cpl_frame *sign)
Computes product of two input frames.
void xsh_random_init(void)
cpl_error_code calc_flat_slit_qc(cpl_image *im, int xa1, int xa2, cpl_propertylist *qclist)
cpl_vector * xsh_tools_tchebitchev_poly_eval(int n, double X)
Compute tchebitchev Tn(X) first coefficient for tchebitchev polynomial.
void xsh_plist_dump(cpl_propertylist *plist)
Dump propertylist.
int xsh_get_random_int_window(const int v1, const int v2)
generates random integer values in range [v1,v2]
double xsh_tools_tchebitchev_reverse_transform(double pos, double min, double max)
computes reverse Tchebitchev transformation
void xsh_gsl_init_gaussian_fit(cpl_vector *xpos_vect, cpl_vector *ypos_vect, double *init_par)
cpl_error_code xsh_set_cd_matrix3d(cpl_propertylist *plist)
Set CD matrix.
cpl_frame * xsh_frame_abs(cpl_frame *in, xsh_instrument *instr, cpl_frame **sign)
Computes absolute value of a frame.
void xsh_free_mask(cpl_mask **m)
Deallocate an image mask and set the pointer to NULL.
char * xsh_get_basename(const char *filename)
Return base filename.
int xsh_tools_running_median_1d_get_max(double *tab, int size, int wsize)
get max of a list of doubles after running median
cpl_error_code calc_curve_qc(cpl_image *im, xsh_instrument *instrument, cpl_propertylist *qclist)
void xsh_free_product_files(void)
Free temprary files list.
int raw_mjd_frame_compare(const cpl_frame *f1, const cpl_frame *f2)
const char * xsh_get_license(void)
Get the pipeline copyright and license.
char * xsh_stringcat_any(const char *s,...)
Concatenate an arbitrary number of strings.
void xsh_reindex_int(int *data, int *idx, int size)
TO BE DESCRIBED.
cpl_error_code xsh_tools_sort_double(double *pix_arr, int size)
Sort a double array.
cpl_error_code xsh_frameset_dump(cpl_frameset *set)
Dump frameset.
cpl_error_code xsh_set_cd_matrix2d(cpl_propertylist *plist)
Set CD matrix.
double xsh_hms2deg(const double hms)
Convert a double from hours minute seconds to deg:
int xsh_time_stamp_get(void)
get timestamp
double xsh_get_random_double_window(const double v1, const double v2)
generates random integer values in range [v1,v2]
cpl_frame * xsh_spectrum_resample(cpl_frame *frame_inp, const double wstep, const double wmin, const double wmax, xsh_instrument *instr)
resample a spectrum
void xsh_array_clip_poly1d(cpl_vector *pos_array, cpl_vector *val_array, double kappa, int niter, double frac_min, int deg, cpl_polynomial **poly, double *chisq, int **flags)
clip outliers from a 1D poly fit
char * xsh_stringdup(const char *s1)
String duplication.
int xsh_erase_table_rows(cpl_table *t, const char *column, cpl_table_select_operator operator, double value)
Erase table rows.
cpl_error_code xsh_tools_sort_int(int *pix_arr, int size)
Sort an integer array.
cpl_error_code get_chromatic_eff(cpl_frame *eff, cpl_propertylist *qclist)
void xsh_frame_image_save(cpl_frame *frm, const char *name_o)
save an image frame
cpl_frame * xsh_util_frameset_collapse_mean(cpl_frameset *set, xsh_instrument *instrument)
Compute mean frame from a list of (IMAGE) framesets.
cpl_vector * xsh_image_to_vector(cpl_image *spectrum)
cpl_frame * xsh_frame_inv(cpl_frame *in, const char *filename, xsh_instrument *instr)
Inverse the flux of a PRE frame.
void xsh_free_parameter(cpl_parameter **p)
Deallocate a parameter and set the pointer to NULL.
long xsh_round_double(double x)
Computes round(x)
cpl_error_code xsh_set_cd_matrix(cpl_propertylist *plist)
Set CD matrix.
cpl_frame * xsh_util_multiply_by_response(cpl_frame *merged_sci, cpl_frame *response, const char *tag)
Multiply input frame by response frame.
int * xsh_sort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
Sort an array and give is index table.
void xsh_reindex(double *data, int *idx, int size)
TO BE DESCRIBED.
void xsh_array_clip_median(cpl_array *array, double kappa, int niter, double frac_min, double *median, double *stdev)
median clip of an array
void xsh_init(void)
Reset library state.
double xsh_tools_get_median_double(double *array, int size)
Calculates the median value of an array of double.
cpl_frameset * xsh_order_frameset_by_date(cpl_frameset *frameset)
Order frameset by date.
char * xsh_sdate_utc(time_t *t)
void xsh_unwrap_image(cpl_image **i)
Unwrap an image and set the pointer to NULL.
cpl_image * xsh_imagelist_collapse_sigclip_iter_create(const cpl_imagelist *imlist, double sigma_low, double sigma_upp, const int niter)
Average with sigma-clipping rejection an imagelist to a single image.
void xsh_array_clip_mean(cpl_array *array, double kappa, int niter, double frac_min, double *mean, double *stdev)
mean clip of an array
cpl_error_code xsh_tools_sort_float(float *pix_arr, int size)
Sort a float array.
double xsh_sess2deg(const double sess)
Convert a double from ssessagesimal to deg: 203049.197= 20:30:49.197 = 20.5136658333.
void xsh_free_matrix(cpl_matrix **m)
Deallocate a matrix and set the pointer to NULL.
char * xsh_stringcat(const char *s1, const char *s2)
String concatenation.
void xsh_gsl_fit_gaussian(cpl_vector *xpos_vect, cpl_vector *ypos_vect, int deg, double *params, double *errs, int *status)
cpl_error_code xsh_remove_crh_single_params_set_defaults(cpl_parameterlist *pars, const char *rec_id, xsh_instrument *inst, xsh_remove_crh_single_param *rectify_par)
cpl_error_code xsh_begin(cpl_frameset *frames, const cpl_parameterlist *parameters, xsh_instrument **instr, cpl_frameset **raws, cpl_frameset **calib, const char *tag_list[], int tag_list_size, const char *recipe_id, unsigned int binary_version, const char *short_descr)
Recipe initialization.
cpl_error_code xsh_rectify_params_set_defaults(cpl_parameterlist *pars, const char *rec_id, xsh_instrument *inst, xsh_rectify_param *rectify_par)
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.
cpl_error_code calc_resp_qc(cpl_table *mtab, cpl_table *rtab, xsh_instrument *instrument, int lower, int upper, const char *label, cpl_propertylist *qclist)
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
cpl_error_code xsh_end(const char *recipe_id, cpl_frameset *frames, cpl_parameterlist *list)
Recipe termination.
cpl_image * xsh_vector_to_image(const cpl_vector *vector, cpl_type type)
Convert a vector to a 1d image.
void xsh_add_product_file(const char *name)
Add temporary file to temprary files list.
cpl_frame * xsh_spectrum_interpolate(cpl_frame *table_frame, const double wstep, const double wmin, const double wmax)
spectra interpolation
void xsh_frame_spectrum_save(cpl_frame *frm, const char *name_o)
save an spectrum frame
cpl_frame * xsh_frameset_add(cpl_frameset *set, xsh_instrument *instr, const int decode_bp)
coadd frames in a frameset
double xsh_spline_hermite_table(double xp, const cpl_table *t, const char *column_x, const char *column_y, int *istart)
Spline interpolation based on Hermite polynomials.
void xsh_tools_tchebitchev_transform_tab(int size, double *pos, double min, double max, double *tcheb_pos)
computes Tchebitchev transformation
void xsh_free_imagelist(cpl_imagelist **i)
Deallocate an image list and set the pointer to NULL.
double xsh_pow_int(double x, int y)
Computes x^y.
double xsh_max_double(double x, double y)
Maximum of two numbers.
void xsh_free(const void *mem)
Deallocate memory.
void xsh_unwrap_array(cpl_array **a)
Unwrap an array and set the pointer to NULL.
cpl_parameterlist * xsh_parameterlist_duplicate(const cpl_parameterlist *pin)
Extract frames with given tag from frameset.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
cpl_error_code xsh_set_cd_matrix1d(cpl_propertylist *plist)
Set CD matrix.
void xsh_show_time(const char *comment)
show time
cpl_frame * xsh_spectrum_resample2(cpl_frame *frame_inp, const double wstep, const double wmin, const double wmax, xsh_instrument *instr)