X-shooter Pipeline Reference Manual 3.8.15
Macros | Functions
Optimal extraction handling

Macros

#define SLIT_USEFUL_WINDOW_FACTOR   0.80
 
#define FIT_FWHM_LIMIT   30
 
#define OPT_EXTRACT_SLIT_SIZE   80
 
#define FLUX_MODE   0
 
#define WAVEMAP_MODE   1
 
#define REGDEBUG_PIXELSIZE   0
 
#define REGDEBUG_INTEGRATE   0
 

Functions

static void xsh_image_gaussian_fit_y (cpl_image *img, int chunk_size, int deg_poly, int oversample, cpl_polynomial **center, cpl_polynomial **height, cpl_polynomial **width, cpl_polynomial **offset)
 Do a gaussian fit of Y columns by chunk and fit the position by polynomials in X.
 
static cpl_image * xsh_image_create_gaussian_image (cpl_image *src, cpl_polynomial *centerp, cpl_polynomial *heightp, cpl_polynomial *widthp, cpl_polynomial *offsetp)
 
static cpl_image * xsh_image_create_model_image (cpl_image *src_img, double *x_data, double *y_data, double kappa, int niter, double frac_min)
 
static cpl_vector * xsh_vector_integrate (int biny, int oversample, int absorder, cpl_vector *ref_pos, double step, cpl_vector *ref_values, cpl_vector *err_values, cpl_vector *qual_values, cpl_vector *new_pos, cpl_vector **spectrum_err, cpl_vector **spectrum_qual)
 Interpolate values following given positions.
 
static void xsh_interpolate_spectrum (int biny, int oversample, int absorder, double lambda_step, cpl_vector *init_pos, cpl_vector *std_flux, cpl_vector *std_err, cpl_vector *std_qual, cpl_vector *opt_flux, cpl_vector *opt_err, cpl_vector *opt_qual, cpl_vector **res_pos, cpl_vector **res_std_flux, cpl_vector **res_std_err, cpl_vector **res_std_qual, cpl_vector **res_opt_flux, cpl_vector **res_opt_err, cpl_vector **res_opt_qual)
 
cpl_image * xsh_optextract_produce_model (cpl_image *s2Dby1D_img, int method, int chunk_ovsamp_size, int deg_poly, int oversample, double *extract_x_data, double *extract_y_data, int abs_order, double kappa, int niter, double frac_min)
 
static void xsh_object_localize (cpl_frame *slitmap_frame, cpl_frame *loc_frame, int oversample, int box_hsize, int nlambdas, int ny_extract, double *extract_x_data, double *extract_y_data, int *ymin, int *ymax)
 
static int xsh_interpolate_linear (float *fluxtab, float *errtab, int *qualtab, int nx, int ny, float pos_x, float pos_y, double *flux, double *err, int *qual, int mode)
 
static void xsh_wavemap_lambda_range (cpl_frame *wavemap_frame, cpl_frame *slitmap_frame, int starty, int endy, int oversample, xsh_order_list *order_list, int iorder, double *xtab, double *ytab, int order, xsh_spectralformat_list *spectralformat, double *lambdastab, double *slitstab, int *sizetab, xsh_instrument *instr)
 Give the value of lambda and x central position for a given y.
 
static void xsh_vector_divide_poly (cpl_vector *vector, double oversample, cpl_polynomial *poly, int shift, xsh_instrument *instr)
 Divide vector values by a polynomial.
 
static cpl_vector * xsh_image_extract_standard (cpl_image *img, cpl_image *err_img, cpl_image *qual_img, cpl_vector **err_v, cpl_vector **qual_v)
 Do a standard extraction on image.
 
static cpl_image * xsh_image_divide_1D (cpl_image *image, cpl_image *err_img, cpl_vector *s1D, cpl_vector *err_s1D, cpl_image **err_2dby1D_img)
 Divide an image by a 1D spectrum (same scale)
 
static cpl_vector * xsh_image_extract_optimal (cpl_image *img, cpl_image *errs_img, cpl_image *qual_img, xsh_opt_extract_param *opt_par, cpl_image *model_img, const int decode_bp, cpl_image **corr_img, cpl_vector **err_v, cpl_vector **qual_v)
 Do an optimal extraction on image.
 
void xsh_opt_extract (cpl_frame *sci_frame, cpl_frame *orderlist_frame, cpl_frame *wavesol_frame, cpl_frame *model_frame, cpl_frame *wavemap_frame, cpl_frame *slitmap_frame, cpl_frame *loc_frame, cpl_frame *spectralformat_frame, cpl_frame *masterflat_frame, xsh_instrument *instrument, xsh_opt_extract_param *opt_extract_par, const char *rec_prefix, cpl_frame **orderext1d_frame, cpl_frame **orderoxt1d_frame, cpl_frame **orderoxt1d_eso_frame, cpl_frame **qc_subextract_frame, cpl_frame **qc_s2ddiv1d_frame, cpl_frame **qc_model_frame, cpl_frame **qc_weight_frame)
 Create a SPECTRUM 1D from a Science frame.
 
void xsh_opt_extract_orders (cpl_frame *sci_frame, cpl_frame *orderlist_frame, cpl_frame *wavesol_frame, cpl_frame *model_frame, cpl_frame *wavemap_frame, cpl_frame *slitmap_frame, cpl_frame *loc_frame, cpl_frame *spectralformat_frame, cpl_frame *masterflat_frame, xsh_instrument *instrument, xsh_opt_extract_param *opt_extract_par, int min_index, int max_index, const char *rec_prefix, cpl_frame **orderext1d_frame, cpl_frame **orderoxt1d_frame, cpl_frame **res_frame_ext, cpl_frame **qc_subextract_frame, cpl_frame **qc_s2ddiv1d_frame, cpl_frame **qc_model_frame, cpl_frame **qc_weight_frame)
 Create a SPECTRUM 1D from a Science frame.
 

Detailed Description

Macro Definition Documentation

◆ FIT_FWHM_LIMIT

#define FIT_FWHM_LIMIT   30

Definition at line 68 of file xsh_opt_extract.c.

◆ FLUX_MODE

#define FLUX_MODE   0

Definition at line 71 of file xsh_opt_extract.c.

◆ OPT_EXTRACT_SLIT_SIZE

#define OPT_EXTRACT_SLIT_SIZE   80

Definition at line 69 of file xsh_opt_extract.c.

◆ REGDEBUG_INTEGRATE

#define REGDEBUG_INTEGRATE   0

Definition at line 75 of file xsh_opt_extract.c.

◆ REGDEBUG_PIXELSIZE

#define REGDEBUG_PIXELSIZE   0

Definition at line 74 of file xsh_opt_extract.c.

◆ SLIT_USEFUL_WINDOW_FACTOR

#define SLIT_USEFUL_WINDOW_FACTOR   0.80

Definition at line 67 of file xsh_opt_extract.c.

◆ WAVEMAP_MODE

#define WAVEMAP_MODE   1

Definition at line 72 of file xsh_opt_extract.c.

Function Documentation

◆ xsh_image_create_gaussian_image()

static cpl_image * xsh_image_create_gaussian_image ( cpl_image *  src,
cpl_polynomial *  centerp,
cpl_polynomial *  heightp,
cpl_polynomial *  widthp,
cpl_polynomial *  offsetp 
)
static

Definition at line 985 of file xsh_opt_extract.c.

References check, nx, ny, width, XSH_ASSURE_NOT_NULL, xsh_free_image(), and XSH_MATH_SQRT_2.

Referenced by xsh_optextract_produce_model().

◆ xsh_image_create_model_image()

static cpl_image * xsh_image_create_model_image ( cpl_image *  src_img,
double *  x_data,
double *  y_data,
double  kappa,
int  niter,
double  frac_min 
)
static

◆ xsh_image_divide_1D()

static cpl_image * xsh_image_divide_1D ( cpl_image *  image,
cpl_image *  err_img,
cpl_vector *  s1D,
cpl_vector *  err_s1D,
cpl_image **  err_2dby1D_img 
)
static

Divide an image by a 1D spectrum (same scale)

Parameters
imageThe data image to divide
err_imgThe error image associate with data
s1DThe 1d spectrum
err_s1DThe 1d error spectrum
[out]err_2dby1D_imgThe pointer on NEW ALLOCATED error associate with result
Returns
The NEW ALLOCATED divided image

Definition at line 1141 of file xsh_opt_extract.c.

References check, nx, ny, size, XSH_ASSURE_NOT_ILLEGAL, XSH_ASSURE_NOT_NULL, and xsh_free_image().

Referenced by xsh_opt_extract_orders().

◆ xsh_image_extract_optimal()

static cpl_vector * xsh_image_extract_optimal ( cpl_image *  img,
cpl_image *  errs_img,
cpl_image *  qual_img,
xsh_opt_extract_param opt_par,
cpl_image *  model_img,
const int  decode_bp,
cpl_image **  corr_img,
cpl_vector **  err_v,
cpl_vector **  qual_v 
)
static

Do an optimal extraction on image.

Parameters
imgThe image
errs_imgThe variance image
qual_imgThe bad pixels image
opt_parThe optimal extraction parameters
model_imgThe reference model image
decode_bpbad pixel code
[out]corr_imgThe corrected image
[out]err_vThe error vector associate with result
[out]qual_vThe bad pixel vector associate with result
Returns
NEW ALLOCATED Extracted positions vector

Definition at line 1230 of file xsh_opt_extract.c.

References check, xsh_opt_extract_param::clip_frac, xsh_opt_extract_param::clip_kappa, xsh_opt_extract_param::clip_niter, n, nx, ny, QFLAG_COSMIC_RAY_REMOVED, sigma, XSH_ASSURE_NOT_NULL, XSH_CALLOC, xsh_debug_level_get(), XSH_DEBUG_LEVEL_MEDIUM, XSH_FREE, xsh_free_vector(), xsh_msg_dbg_medium, and xsh_unwrap_vector().

Referenced by xsh_opt_extract_orders().

◆ xsh_image_extract_standard()

static cpl_vector * xsh_image_extract_standard ( cpl_image *  img,
cpl_image *  err_img,
cpl_image *  qual_img,
cpl_vector **  err_v,
cpl_vector **  qual_v 
)
static

Do a standard extraction on image.

Parameters
[in]imgThe data image
[in]err_imgThe error image
[in]qual_imgThe bad pixel image
[out]err_vThe error vector associate with result
[out]qual_vThe bad pixel vector associate with result
Returns
NEW ALLOCATED Extracted positions vector

Definition at line 1060 of file xsh_opt_extract.c.

References check, nx, ny, XSH_ASSURE_NOT_NULL, and xsh_free_vector().

Referenced by xsh_opt_extract_orders().

◆ xsh_image_gaussian_fit_y()

static void xsh_image_gaussian_fit_y ( cpl_image *  img,
int  chunk_size,
int  deg_poly,
int  oversample,
cpl_polynomial **  center,
cpl_polynomial **  height,
cpl_polynomial **  width,
cpl_polynomial **  offset 
)
static

Do a gaussian fit of Y columns by chunk and fit the position by polynomials in X.

Parameters
[in]imgThe image
[in]chunk_sizeThe size of chunk in pixels along X axis
[in]deg_polyThe degree of polynomial fit
[in]oversampleThe oversample factor
[out]centerThe NEW ALLOCATED polynomial that describes gaussian center position along X axis
[out]heightThe NEW ALLOCATED polynomial that describes gaussian height along X axis
[out]widthThe NEW ALLOCATED polynomial that describes gaussian width along X axis
[out]offsetThe NEW ALLOCATED polynomial that describes gaussian offset along X axis

Definition at line 720 of file xsh_opt_extract.c.

References check, FIT_FWHM_LIMIT, nx, ny, sigma, width, XSH_ASSURE_NOT_ILLEGAL, XSH_ASSURE_NOT_NULL, XSH_CALLOC, xsh_error_reset, XSH_FREE, xsh_free_polynomial(), xsh_free_vector(), XSH_MALLOC, xsh_msg, xsh_msg_dbg_medium, xsh_polynomial_fit_1d_create(), and xsh_unwrap_vector().

Referenced by xsh_optextract_produce_model().

◆ xsh_interpolate_linear()

static int xsh_interpolate_linear ( float *  fluxtab,
float *  errtab,
int *  qualtab,
int  nx,
int  ny,
float  pos_x,
float  pos_y,
double *  flux,
double *  err,
int *  qual,
int  mode 
)
static

◆ xsh_interpolate_spectrum()

static void xsh_interpolate_spectrum ( int  biny,
int  oversample,
int  absorder,
double  lambda_step,
cpl_vector *  init_pos,
cpl_vector *  std_flux,
cpl_vector *  std_err,
cpl_vector *  std_qual,
cpl_vector *  opt_flux,
cpl_vector *  opt_err,
cpl_vector *  opt_qual,
cpl_vector **  res_pos,
cpl_vector **  res_std_flux,
cpl_vector **  res_std_err,
cpl_vector **  res_std_qual,
cpl_vector **  res_opt_flux,
cpl_vector **  res_opt_err,
cpl_vector **  res_opt_qual 
)
static

◆ xsh_object_localize()

static void xsh_object_localize ( cpl_frame *  slitmap_frame,
cpl_frame *  loc_frame,
int  oversample,
int  box_hsize,
int  nlambdas,
int  ny_extract,
double *  extract_x_data,
double *  extract_y_data,
int *  ymin,
int *  ymax 
)
static

◆ xsh_opt_extract()

void xsh_opt_extract ( cpl_frame *  sci_frame,
cpl_frame *  orderlist_frame,
cpl_frame *  wavesol_frame,
cpl_frame *  model_frame,
cpl_frame *  wavemap_frame,
cpl_frame *  slitmap_frame,
cpl_frame *  loc_frame,
cpl_frame *  spectralformat_frame,
cpl_frame *  masterflat_frame,
xsh_instrument instrument,
xsh_opt_extract_param opt_extract_par,
const char *  rec_prefix,
cpl_frame **  orderext1d_frame,
cpl_frame **  orderoxt1d_frame,
cpl_frame **  orderoxt1d_eso_frame,
cpl_frame **  qc_subextract_frame,
cpl_frame **  qc_s2ddiv1d_frame,
cpl_frame **  qc_model_frame,
cpl_frame **  qc_weight_frame 
)

Create a SPECTRUM 1D from a Science frame.

Parameters
sci_frameThe science frame
orderlist_frameThe order table Frame
wavesol_frameThe wave solution frame
model_frameThe model configuration frame
wavemap_frameThe wave map frame
slitmap_frameThe slit map frame
loc_frameThe localization frame
spectralformat_frameThe spectral format frame
masterflat_frameThe master flat frame
instrumentThe instrument structure
opt_extract_parParameters for optimal extraction
rec_prefixThe recipe PREFIX to build output files name or NULL
[out]orderext1d_frameThe orderext1d result
[out]orderoxt1d_frameThe orderoxt1d result
[out]qc_subextract_frameThe QC subextract image
[out]qc_s2ddiv1d_frameThe QC S2ddiv1d image
[out]qc_model_frameThe QC model image
[out]qc_weight_frameThe QC weight image

Definition at line 1832 of file xsh_opt_extract.c.

References check, instrument, and xsh_opt_extract_orders().

Referenced by xsh_absorp(), xsh_respon_slit_stare(), and xsh_scired_slit_stare().

◆ xsh_opt_extract_orders()

void xsh_opt_extract_orders ( cpl_frame *  sci_frame,
cpl_frame *  orderlist_frame,
cpl_frame *  wavesol_frame,
cpl_frame *  model_frame,
cpl_frame *  wavemap_frame,
cpl_frame *  slitmap_frame,
cpl_frame *  loc_frame,
cpl_frame *  spectralformat_frame,
cpl_frame *  masterflat_frame,
xsh_instrument instrument,
xsh_opt_extract_param opt_extract_par,
int  min_index,
int  max_index,
const char *  rec_prefix,
cpl_frame **  orderext1d_frame,
cpl_frame **  orderoxt1d_frame,
cpl_frame **  res_frame_ext,
cpl_frame **  qc_subextract_frame,
cpl_frame **  qc_s2ddiv1d_frame,
cpl_frame **  qc_model_frame,
cpl_frame **  qc_weight_frame 
)

Create a SPECTRUM 1D from a Science frame.

Parameters
sci_frameThe science frame
orderlist_frameThe order table Frame
wavesol_frameThe wave solution frame
model_frameThe model configuration frame
[in]wavemap_frameThe wavemap frame
slitmap_frameThe slit map frame
[in]spectralformat_frameThe spectral format frame
[in]masterflat_frameThe master flat frame
[in]instrumentThe instrument structure
opt_extract_parParameters for optimal extraction
min_indexThe index of first order to extract
max_indexThe index of last order to extract
rec_prefixThe recipe PREFIX to build output files name or NULL
[out]orderext1d_frameThe orderext1d result
[out]orderoxt1d_frameThe orderoxt1d result
[out]qc_subextract_frameThe QC subextract image
[out]qc_s2ddiv1d_frameThe QC S2ddiv1d image
[out]qc_model_frameThe QC model image
[out]qc_weight_frameThe QC weight image

Definition at line 1899 of file xsh_opt_extract.c.

References xsh_order::absorder, binx, xsh_instrument::binx, biny, xsh_instrument::biny, xsh_order::blazepoly, xsh_opt_extract_param::box_hsize, check, xsh_opt_extract_param::chunk_size, xsh_pre::conad, xsh_pre::data, xsh_rec::data1, xsh_pre::data_header, xsh_instrument::decode_bp, xsh_pre::errs, xsh_rec::errs1, FLUX_MODE, xsh_rec_list::header, instrument, kappa, xsh_rec::lambda, lambda_step, xsh_opt_extract_param::lambda_step, xsh_order_list::list, xsh_rec_list::list, xsh_opt_extract_param::method, mode, niter, xsh_opt_extract_param::niter, xsh_pre::nx, nx, xsh_pre::ny, ny, OPT_EXTRACT_SLIT_SIZE, xsh_opt_extract_param::oversample, xsh_pre::qual, xsh_rec::qual1, xsh_rec_list::size, size, SLIT_USEFUL_WINDOW_FACTOR, x, xsh_add_temporary_file(), XSH_ARM_NIR, XSH_ASSURE_NOT_NULL, xsh_create_blaze(), xsh_debug_level_get(), XSH_DEBUG_LEVEL_MEDIUM, XSH_FREE, xsh_free_frame(), xsh_free_image(), xsh_free_propertylist(), xsh_free_vector(), xsh_get_slit_edges(), XSH_GET_TAG_FROM_ARM, xsh_image_divide_1D(), xsh_image_extract_optimal(), xsh_image_extract_standard(), xsh_instrument_get_arm(), xsh_interpolate_linear(), xsh_interpolate_spectrum(), XSH_MALLOC, xsh_model_binxy(), xsh_model_config_load_best(), xsh_model_get_xy(), xsh_msg, xsh_msg_dbg_high, xsh_msg_dbg_low, xsh_msg_warning, XSH_NEW_PROPERTYLIST, xsh_object_localize(), xsh_optextract_produce_model(), XSH_ORDER_EXT1D, xsh_order_list_free(), xsh_order_list_get_endy(), xsh_order_list_get_starty(), xsh_order_list_load(), XSH_ORDER_OXT1D, xsh_pfits_set_extname(), xsh_pfits_set_pcatg(), xsh_pfits_set_rectify_bin_lambda(), xsh_pfits_set_rectify_bin_space(), xsh_pfits_set_rectify_lambda_max(), xsh_pfits_set_rectify_lambda_min(), xsh_pfits_set_rectify_space_max(), xsh_pfits_set_rectify_space_min(), xsh_pre_free(), xsh_pre_load(), xsh_pre_multiply_image(), XSH_PRE_QUAL_BPP, xsh_pre_save(), xsh_rec_list_create(), xsh_rec_list_free(), xsh_rec_list_get_lambda_max(), xsh_rec_list_get_lambda_min(), xsh_rec_list_save(), xsh_rec_list_save2(), xsh_rec_list_set_data_size(), xsh_spectralformat_list_free(), xsh_spectralformat_list_load(), xsh_unwrap_image(), xsh_unwrap_vector(), xsh_vector_divide_poly(), xsh_wavemap_lambda_range(), xsh_wavesol_eval_polx(), xsh_wavesol_eval_poly(), xsh_wavesol_free(), xsh_wavesol_load(), and y.

Referenced by xsh_opt_extract().

◆ xsh_optextract_produce_model()

cpl_image * xsh_optextract_produce_model ( cpl_image *  s2Dby1D_img,
int  method,
int  chunk_ovsamp_size,
int  deg_poly,
int  oversample,
double *  extract_x_data,
double *  extract_y_data,
int  abs_order,
double  kappa,
int  niter,
double  frac_min 
)

◆ xsh_vector_divide_poly()

static void xsh_vector_divide_poly ( cpl_vector *  vector,
double  oversample,
cpl_polynomial *  poly,
int  shift,
xsh_instrument instr 
)
static

Divide vector values by a polynomial.

Parameters
[in,out]vectorThe vector values
[in]oversampleThe oversample factor
[in]polyThe polynomial function that define value to divide
[in]shiftShift between vector and polynomial
(in]instr Instrument structure used to define ARM

Definition at line 665 of file xsh_opt_extract.c.

References check, size, XSH_ARM_NIR, XSH_ASSURE_NOT_NULL, and xsh_instrument_get_arm().

Referenced by xsh_opt_extract_orders().

◆ xsh_vector_integrate()

static cpl_vector * xsh_vector_integrate ( int  biny,
int  oversample,
int  absorder,
cpl_vector *  ref_pos,
double  step,
cpl_vector *  ref_values,
cpl_vector *  err_values,
cpl_vector *  qual_values,
cpl_vector *  new_pos,
cpl_vector **  spectrum_err,
cpl_vector **  spectrum_qual 
)
static

Interpolate values following given positions.

Parameters
oversampleOversample factor
abs_orderAbsolute order
ref_posThe reference position orderby increasing values
stepThe step in wavelength
[in]ref_valuesThe reference values
[in]err_valuesThe error values
[in]qual_valuesThe bad pixel values
[in]new_posThe search positions orderby increasing values
[out]spectrum_errThe error valuea associate with result
[in]spectrum_qualThe bad pixel values associate with result
Returns
NEW ALLOCATED vector containing values for new positions

Definition at line 1535 of file xsh_opt_extract.c.

References biny, check, size, step, x, XSH_ASSURE_NOT_NULL, xsh_debug_level_get(), XSH_DEBUG_LEVEL_MEDIUM, xsh_free_polynomial(), xsh_free_vector(), xsh_msg, xsh_msg_dbg_high, xsh_polynomial_fit_1d_create(), xsh_round_double(), and y.

Referenced by xsh_interpolate_spectrum().

◆ xsh_wavemap_lambda_range()

static void xsh_wavemap_lambda_range ( cpl_frame *  wavemap_frame,
cpl_frame *  slitmap_frame,
int  starty,
int  endy,
int  oversample,
xsh_order_list order_list,
int  iorder,
double *  xtab,
double *  ytab,
int  order,
xsh_spectralformat_list spectralformat,
double *  lambdastab,
double *  slitstab,
int *  sizetab,
xsh_instrument instr 
)
static

Give the value of lambda and x central position for a given y.

Parameters
wavemap_frameThe wave map frame
slitmap_frameThe slit map frame
startyThe first y position
endyThe last y position
oversampleThe oversample factor in y
order_listThe order table list
iorderIndex of order
[out]xtabThe array of x central positions
[out]ytabThe array of y central positions
orderThe absolute order
spectralformatThe spectral format list
[out]lambdatabThe array of wavelength at central positions
[out]slitstabThe array of slit at central positions
(out]sizetab The array size of different tab
[in]instrThe instrument structure

Definition at line 455 of file xsh_opt_extract.c.

References xsh_order::cenpoly, check, endy, xsh_order_list::list, nx, ny, order, size, starty, WAVEMAP_MODE, x, XSH_ARM_NIR, XSH_ASSURE_NOT_NULL, XSH_CALLOC, XSH_FREE, xsh_free_image(), xsh_instrument_get_arm(), xsh_interpolate_linear(), xsh_msg_dbg_high, xsh_msg_dbg_medium, xsh_order_list_eval(), xsh_spectralformat_list_get_lambda_max(), xsh_spectralformat_list_get_lambda_min(), and y.

Referenced by xsh_opt_extract_orders().