CR2RE Pipeline Reference Manual 1.6.8
Functions
Trace Functions

Functions

cpl_table * cr2res_trace (cpl_image *ima, int smooth_x, int smooth_y, double threshold, int opening, int degree, int min_cluster)
 Main function for running all parts of the trace algorithm.
 
cpl_mask * cr2res_trace_clean (cpl_mask *mask, int opening, int min_cluster)
 Clean small blobs.
 
cpl_image * cr2res_trace_gen_image (cpl_table *trace, int nx, int ny)
 Make an image out of the trace solution.
 
int * cr2res_trace_get_order_idx_values (const cpl_table *trace, int *nb_order_idx_values)
 Count and return the different order_idx values from a TW table.
 
cpl_size cr2res_get_nb_traces (const cpl_table *trace_wave, int order_idx)
 Get the number of traces for a specified order_idx.
 
int * cr2res_get_trace_numbers (const cpl_table *trace_wave, int order_idx, int *nb_traces)
 Get the trace numbers for a specified order_idx.
 
cpl_table * cr2res_trace_merge (const cpl_table *trace_wave1, const cpl_table *trace_wave2)
 Merge 2 trace_wave tables.
 
cpl_size cr2res_get_trace_table_index (const cpl_table *trace_wave, int order_idx, int trace_nb)
 Get the index in a TRACE_WAVE table.
 
cpl_polynomial * cr2res_get_trace_wave_poly (const cpl_table *trace_wave, const char *poly_column, int order_idx, int trace_nb)
 Get a polynomial from a TRACE_WAVE table.
 
cpl_vector * cr2res_trace_get_wl (const cpl_table *trace_wave, int order_idx, int trace_nb, int size)
 Get the Wavelength vector from a TRACE_WAVE table.
 
cpl_vector * cr2res_trace_get_ycen (const cpl_table *trace, int order_idx, int trace_nb, int size)
 Retrieves the middle (All) polynomial from trace table and evaluates.
 
int cr2res_trace_get_height (const cpl_table *trace, cpl_size order_idx, cpl_size trace_nb)
 Computes the average height (pix) of an order, from trace polys.
 
cpl_vector * cr2res_trace_compute_middle (cpl_polynomial *trace1, cpl_polynomial *trace2, int vector_size)
 Computes the positions between 2 trace polynomials.
 
int cr2res_trace_compute_height (cpl_polynomial *trace1, cpl_polynomial *trace2, int vector_size)
 Computes extraction height between 2 trace polynomials.
 
double cr2res_trace_get_trace_ypos (const cpl_table *traces, int idx)
 Compute the y position of the trace.
 
int cr2res_trace_add_extra_columns (cpl_table *traces, const char *infile, int det_nr)
 Add extra columns to the plain trace table.
 
cpl_table * cr2res_trace_new_slit_fraction (const cpl_table *traces, const cpl_array *new_slit_fraction)
 Recompute the traces at a newly specified slit fraction.
 
cr2res_decker cr2res_trace_slit_fraction_info (const cpl_array *slit_frac, int *up_or_down)
 Get a standard slit fraction information.
 
cpl_array * cr2res_trace_slit_fraction_create (cr2res_decker decker_position, int up_or_down)
 Get a standard slit fraction.
 
cpl_table * cr2res_trace_split (cpl_table *trace_wave, int order_idx, int nb_subtraces)
 Splits full slit traces into several sub traces.
 
cpl_table * cr2res_trace_filter (const cpl_table *tw, const char *setting, int zp_order)
 Only keep the predefined orders of the setting.
 

Detailed Description

Function Documentation

◆ cr2res_get_nb_traces()

cpl_size cr2res_get_nb_traces ( const cpl_table *  trace_wave,
int  order_idx 
)

Get the number of traces for a specified order_idx.

Parameters
tabA TRACE_WAVE table
order_idxthe order_idx
Returns
the number or traces in this order or -1 in error case

Definition at line 486 of file cr2res_trace.c.

Referenced by cr2res_get_trace_numbers().

◆ cr2res_get_trace_numbers()

int * cr2res_get_trace_numbers ( const cpl_table *  trace_wave,
int  order_idx,
int *  nb_traces 
)

Get the trace numbers for a specified order_idx.

Parameters
tabA TRACE_WAVE table
order_idxthe order_idx
nb_traces[out] number of traces
Returns
the trace numbers, or NULL in error cases return value must be freed with cpl_free

Definition at line 517 of file cr2res_trace.c.

References cr2res_get_nb_traces().

Referenced by cr2res_qc_flat_trace_center_y(), cr2res_slit_pos(), cr2res_trace_new_slit_fraction(), and cr2res_trace_split().

◆ cr2res_get_trace_table_index()

cpl_size cr2res_get_trace_table_index ( const cpl_table *  trace_wave,
int  order_idx,
int  trace_nb 
)

Get the index in a TRACE_WAVE table.

Parameters
tabA TRACE_WAVE table
order_idxthe order_idx
trace_nbthe trace number
Returns
the row index or -1 in error case

Definition at line 652 of file cr2res_trace.c.

Referenced by cr2res_extract2d_trace(), cr2res_get_trace_wave_poly(), cr2res_slit_pos(), cr2res_trace_new_slit_fraction(), cr2res_trace_split(), and cr2res_wave_apply().

◆ cr2res_get_trace_wave_poly()

cpl_polynomial * cr2res_get_trace_wave_poly ( const cpl_table *  trace_wave,
const char *  poly_column,
int  order_idx,
int  trace_nb 
)

Get a polynomial from a TRACE_WAVE table.

Parameters
tabA TRACE_WAVE table
poly_columnCR2RES_COL_WAVELENGTH, CR2RES_COL_UPPER,
order_idxthe order_idx
trace_nbthe trace number
Returns
The newly created polynomial or NULL in error case The returned object must be de allocated with cpl_polynomial_delete()

Definition at line 685 of file cr2res_trace.c.

References cr2res_convert_array_to_poly(), and cr2res_get_trace_table_index().

Referenced by cr2res_extract_slitdec_curved(), cr2res_extract_sum_tilt(), cr2res_pol_get_beam_trace(), cr2res_slit_pos(), cr2res_trace_get_height(), cr2res_trace_get_wl(), cr2res_trace_get_ycen(), and cr2res_wave_apply().

◆ cr2res_trace()

cpl_table * cr2res_trace ( cpl_image *  ima,
int  smooth_x,
int  smooth_y,
double  threshold,
int  opening,
int  degree,
int  min_cluster 
)

Main function for running all parts of the trace algorithm.

Parameters
imainput image
smooth_xLow pass filter kernel size in x
smooth_yLow pass filter kernel size in y
thresholdThe threshold used for detection
openingUsed for cleaning the mask
degreeFitted polynomial degree
min_clusterA trace must be bigger - discarded otherwise
Returns
The newly allocated trace table or NULL in error case

A detection is applied to create a mask. This one is labelised. The function converts the label image in the proper cluster table in trace to call the traces fitting function. The cluster table contains the label image information in the form of a table. One column per pixel. The columns are xs (pixel x position), ys (pixel y position) and cluster (label number). The returned table contains 1 line per trace. Each line has 3 polynomials (All, Upper and Lower). For example with degree 1 : All| Upper| Lower| 24.3593, 0.0161583| 34.6822, 0.0164165| 14.0261, 0.0159084| 225.479, 0.0167469| 236.604, 0.0168986| 214.342, 0.0166058| 436.94, 0.0173438| 448.436, 0.017493| 425.423, 0.017203|

Definition at line 163 of file cr2res_trace.c.

References cr2res_trace_clean().

◆ cr2res_trace_add_extra_columns()

int cr2res_trace_add_extra_columns ( cpl_table *  traces,
const char *  infile,
int  det_nr 
)

Add extra columns to the plain trace table.

Parameters
tracesThe plain traces table
infileFile used for WL infos and Decker position
det_nrDetector
Returns
0 if ok

infile is the input file from which we use the header to get the Wavelength and the Decker position.

The added columns are: CR2RES_COL_ORDER CR2RES_COL_TRACENB CR2RES_COL_WAVELENGTH CR2RES_COL_WAVELENGTH_ERROR CR2RES_COL_SLIT_CURV_A CR2RES_COL_SLIT_CURV_B CR2RES_COL_SLIT_CURV_C CR2RES_COL_SLIT_FRACTION The values are set as defaults The resulting table is a proper TRACE_WAVE table

Definition at line 972 of file cr2res_trace.c.

References cr2res_io_get_ext_idx(), cr2res_pfits_get_decker_position(), cr2res_pfits_get_order_idx(), cr2res_trace_get_order_idx_values(), cr2res_trace_get_trace_ypos(), and cr2res_wave_get_estimate().

◆ cr2res_trace_clean()

cpl_mask * cr2res_trace_clean ( cpl_mask *  mask,
int  opening,
int  min_cluster 
)

Clean small blobs.

Parameters
maskinput mask with small blobs
openingFlag to apply opening filtering to the traces
min_clusterRemove all clusters smaller than this
Returns
A newly allocated mask or NULL in error case

Definition at line 292 of file cr2res_trace.c.

Referenced by cr2res_trace().

◆ cr2res_trace_compute_height()

int cr2res_trace_compute_height ( cpl_polynomial *  trace1,
cpl_polynomial *  trace2,
int  vector_size 
)

Computes extraction height between 2 trace polynomials.

Parameters
trace1First trace
trace2Second trace
vector_sizedetector x size
Returns
The average height between 2 polynomials or -1 in error case

The returned int is the rounded-up mean difference between the two input polynomials, evaluated on a vector from 1 to vector_size.

Definition at line 886 of file cr2res_trace.c.

Referenced by cr2res_trace_get_height().

◆ cr2res_trace_compute_middle()

cpl_vector * cr2res_trace_compute_middle ( cpl_polynomial *  trace1,
cpl_polynomial *  trace2,
int  vector_size 
)

Computes the positions between 2 trace polynomials.

Parameters
poly1First trace
poly2Second trace
sizeOutput vector size
Returns
The returned vector contains the pixel positions of the middle of the 2 traces. The nth vector value is trace1(n) + trace2(n) / 2 n=1 for the first value

Definition at line 851 of file cr2res_trace.c.

◆ cr2res_trace_filter()

cpl_table * cr2res_trace_filter ( const cpl_table *  tw,
const char *  setting,
int  zp_order 
)

Only keep the predefined orders of the setting.

Parameters
twtrace wave table
settingThe setting ID
zp_orderThe order ZP
Returns
the filtered table

Definition at line 1965 of file cr2res_trace.c.

References cr2res_order_idx_to_real().

◆ cr2res_trace_gen_image()

cpl_image * cr2res_trace_gen_image ( cpl_table *  trace,
int  nx,
int  ny 
)

Make an image out of the trace solution.

Parameters
traceThe trace table
nxX size of the produced image
nyY size of the produced image
Returns
A newly allocated image or NULL in error case The returned INT image is of size nx x ny, is filled with -1. The polynomials of the different trace edges are used to fill the traces with the value of the order_idx.

Definition at line 362 of file cr2res_trace.c.

References cr2res_convert_array_to_poly().

Referenced by cr2res_qc_overexposed().

◆ cr2res_trace_get_height()

int cr2res_trace_get_height ( const cpl_table *  trace,
cpl_size  order_idx,
cpl_size  trace_nb 
)

Computes the average height (pix) of an order, from trace polys.

Parameters
traceTRACE table
order_idxthe order_idx
trace_nbthe trace number
Returns
height in pixels

Definition at line 805 of file cr2res_trace.c.

References cr2res_get_trace_wave_poly(), and cr2res_trace_compute_height().

Referenced by cr2res_extract_median(), cr2res_extract_slitdec_curved(), cr2res_extract_sum_tilt(), and cr2res_extract_sum_vert().

◆ cr2res_trace_get_order_idx_values()

int * cr2res_trace_get_order_idx_values ( const cpl_table *  trace,
int *  nb_order_idx_values 
)

Count and return the different order_idx values from a TW table.

Parameters
traceTW table
nb_order_idx_values[output] number of different order_idx values
Returns
newly allocated int array

The int array will need to be freed by the caller. Its size is nb_orders. It contains the list of different order_idx values found in the TW table.

Definition at line 431 of file cr2res_trace.c.

Referenced by cr2res_fit_interorder(), cr2res_qc_der_snr(), cr2res_qc_flat_order_positions(), cr2res_qc_flat_trace_center_y(), cr2res_qc_snr(), cr2res_slit_pos(), cr2res_trace_add_extra_columns(), cr2res_trace_merge(), cr2res_trace_new_slit_fraction(), and cr2res_trace_split().

◆ cr2res_trace_get_trace_ypos()

double cr2res_trace_get_trace_ypos ( const cpl_table *  traces,
int  idx 
)

Compute the y position of the trace.

Parameters
tracesThe traces table
idxThe index of the trace row
Returns
The y position of the center of the trace

Definition at line 923 of file cr2res_trace.c.

References cr2res_convert_array_to_poly().

Referenced by cr2res_qc_flat_order_positions(), and cr2res_trace_add_extra_columns().

◆ cr2res_trace_get_wl()

cpl_vector * cr2res_trace_get_wl ( const cpl_table *  trace_wave,
int  order_idx,
int  trace_nb,
int  size 
)

Get the Wavelength vector from a TRACE_WAVE table.

Parameters
trace_waveA TRACE_WAVE table
order_idxthe order_idx
trace_nbthe trace number
sizeOutput vector size
Returns
The newly created vector or NULL in error case The returned object must be de allocated with cpl_vector_delete()

Definition at line 730 of file cr2res_trace.c.

References cr2res_get_trace_wave_poly().

Referenced by cr2res_extract_EXTRACT1D_create(), cr2res_qc_wave_central(), and cr2res_qc_wave_disp().

◆ cr2res_trace_get_ycen()

cpl_vector * cr2res_trace_get_ycen ( const cpl_table *  trace,
int  order_idx,
int  trace_nb,
int  size 
)

Retrieves the middle (All) polynomial from trace table and evaluates.

Parameters
traceTRACE table
order_idxthe order_idx
trace_nbthe trace number
sizeOutput vector size
Returns
The returned vector contains the poly evaluation result on i vector from 1 to size. It needs to be destroyed by the caller.

Definition at line 769 of file cr2res_trace.c.

References cr2res_get_trace_wave_poly().

Referenced by cr2res_extract_median(), cr2res_extract_slitdec_curved(), cr2res_extract_sum_tilt(), cr2res_extract_sum_vert(), cr2res_qc_flat_trace_center_y(), and cr2res_slit_curv_compute_order_trace().

◆ cr2res_trace_merge()

cpl_table * cr2res_trace_merge ( const cpl_table *  trace_wave1,
const cpl_table *  trace_wave2 
)

Merge 2 trace_wave tables.

Parameters
trace_wave1Table to merge
trace_wave2Table to merge
Returns
a newly allocated trace_wave table or NULL in error case

Definition at line 592 of file cr2res_trace.c.

References cr2res_trace_get_order_idx_values().

◆ cr2res_trace_new_slit_fraction()

cpl_table * cr2res_trace_new_slit_fraction ( const cpl_table *  traces,
const cpl_array *  new_slit_fraction 
)

Recompute the traces at a newly specified slit fraction.

Parameters
tracesThe input traces
new_slit_fractionThe newly wished slit fraction
Returns
The newly computed trace
See also
cr2res_trace_new_trace()

For each order in the input tracewave, the function will produce a new row in the output trace table corresponding to the passed slit fraction, based on all available traces (rows).

  • CR2RES_COL_SLIT_FRACTION is filled with the input fraction
  • CR2RES_COL_ORDER and CR2RES_COL_TRACENB are copied from input trace file
  • CR2RES_COL_UPPER CR2RES_COL_LOWER CR2RES_COL_ALL are computed by cr2res_trace_new_trace()
  • CR2RES_COL_WAVELENGTH and CR2RES_COL_WAVELENGTH_ERROR are computed like this: TODO
  • CR2RES_COL_SLIT_CURV_A CR2RES_COL_SLIT_CURV_B CR2RES_COL_SLIT_CURV_C are computed like this: TODO

Definition at line 1152 of file cr2res_trace.c.

References cr2res_convert_array_to_poly(), cr2res_convert_poly_to_array(), cr2res_dfs_check_traces_table(), cr2res_get_trace_numbers(), cr2res_get_trace_table_index(), and cr2res_trace_get_order_idx_values().

Referenced by cr2res_pol_get_beam_trace().

◆ cr2res_trace_slit_fraction_create()

cpl_array * cr2res_trace_slit_fraction_create ( cr2res_decker  decker_position,
int  up_or_down 
)

Get a standard slit fraction.

Parameters
decker_positionCR2RES_DECKER_NONE, _1_3 or _2_4
up_or_down0 (if CR2RES_DECKER_NONE), 1 for up, 2 for down
Returns
A newly allocated mask or NULL in error case.

Definition at line 1760 of file cr2res_trace.c.

◆ cr2res_trace_slit_fraction_info()

cr2res_decker cr2res_trace_slit_fraction_info ( const cpl_array *  slit_frac,
int *  up_or_down 
)

Get a standard slit fraction information.

Parameters
slit_fracSlit Fraction array
up_or_down[out] 0 (if CR2RES_DECKER_NONE), 1 for up, 2 for down
Returns
CR2RES_DECKER_NONE, _1_3 or _2_4 or CR2RES_DECKER_INVALID

Definition at line 1710 of file cr2res_trace.c.

Referenced by cr2res_qc_flat_order_positions().

◆ cr2res_trace_split()

cpl_table * cr2res_trace_split ( cpl_table *  trace_wave,
int  order_idx,
int  nb_subtraces 
)

Splits full slit traces into several sub traces.

Parameters
trace_wavetrace wave table
order_idxorder to split (-100 for all)
nb_subtracesnumber of subtraces to create
Returns
the new trace_wave table or NULL in error case

All input traces that have a full slit_fraction are split.

The returned trace wave table only contains the newly created traces.

Sub traces are created by evenly splitting the existing trace, so that no subtraces overlap.

Definition at line 1834 of file cr2res_trace.c.

References cr2res_get_trace_numbers(), cr2res_get_trace_table_index(), cr2res_trace_get_order_idx_values(), and fraction().