UVES Pipeline Reference Manual  5.4.6
Functions
Recipe: Order Position

Functions

static cpl_table * trace_order (const cpl_table *ordertable, int order, const cpl_image *inputimage, const cpl_image *noise, const cpl_binary *image_bad, int TRACESTEP, double MAXGAP)
 
static int count_orders (const cpl_table *tracetable)
 
static double fit_order_linear (cpl_table *singletrace, int order, double KAPPA, double *slope)
 
static int get_xcenter (int nx, int ny, cpl_table *ordertab, int row)
 
static int get_ycenter (int nx, int ny, cpl_table *ordertab, int row)
 
static int get_orderlength (int nx, int ny, cpl_table *ordertab, int row)
 
static double estimate_threshold (const cpl_image *inputimage, const cpl_image *nosie, cpl_table *ordertable, int row, double relative_threshold)
 
static bool find_centroid (const cpl_image *inputimage, const cpl_image *noise, const cpl_binary *image_bad, double threshold, int spacing, int x, double *yguess, double *dY)
 
cpl_table * uves_locate_orders (const cpl_image *inputimage, const cpl_image *noise, cpl_table *ordertable, int TRACESTEP, double MINTHRESH, double MAXGAP, double MAXRMS, int *DEFPOL1, int *DEFPOL2, double KAPPA, polynomial **bivariate_fit, int *orders_traced)
 Trace all orders. More...
 
static cpl_table * detect_lines (cpl_image *htrans, int minintersept, const cpl_image *inputimage, int NORDERS, bool norders_is_guess, int SAMPLEWIDTH, double PTHRES, double MINSLOPE, double MAXSLOPE, int SLOPERES, bool consecutive)
 Detect order lines from the Hough image. More...
 
static cpl_error_code delete_peak (cpl_image *htrans, int minintersept, int hxmax, int hymax, int SPACING, int imagewidth, int SAMPLEWIDTH, double MINSLOPE, double MAXSLOPE, int SLOPERES)
 Delete peak in Hough image. More...
 
static int firsttrace (int nx, int SAMPLEWIDTH)
 Get the first trace column. More...
 
static int calculate_spacing (const cpl_image *image, int x)
 Estimate spacing of order lines. More...
 
static double autocorr (const cpl_image *image, const int x, const int shift)
 Calculate auto-correlation function of image column. More...
 
static cpl_error_code update_max (const cpl_image *htrans, int *xmax, int *ymax, int SPACING, int imagewidth, int SAMPLEWIDTH, double MINSLOPE, double MAXSLOPE, int SLOPERES)
 Improve position of a peak in the Hough image. More...
 
cpl_table * uves_hough (const cpl_image *image, int ymin, int ymax, int NORDERS, bool norders_is_guess, int SAMPLEWIDTH, double PTHRES, double MINSLOPE, double MAXSLOPE, int SLOPERES, bool consecutive, cpl_image **htrans, cpl_image **htrans_original)
 Compute Hough transform and detect lines. More...
 
cpl_error_code uves_draw_orders (const cpl_table *ordertable, cpl_image *image)
 Draw detected order lines. More...
 

Detailed Description

This recipe determines the echelle order locations. See man-page for details.

Function Documentation

cpl_table* uves_locate_orders ( const cpl_image *  inputimage,
const cpl_image *  noise,
cpl_table *  ordertable,
int  TRACESTEP,
double  MINTHRESH,
double  MAXGAP,
double  MAXRMS,
int *  DEFPOL1,
int *  DEFPOL2,
double  KAPPA,
polynomial **  bivariate_fit,
int *  orders_traced 
)

Trace all orders.

Parameters
inputimageThe input echelle image
noiseNoise of input image
ordertableThe basic order table (one row pr. order)
TRACESTEPSee trace_order()
MINTHRESHSee trace_order()
MAXGAPSee trace_order()
MAXRMSIndividual orders are rejected if RMS of a linear fit of the order is larger than MAXRMS * mRMS, where mRMS is the median of all order's RMSs.
DEFPOL1Degree of global fit (as function of x) If negative, will be set to actual degree used
DEFPOL2Degree of global fit (as function of order number) If negative, will be set to actual degree used
KAPPAKappa used for kappa-sigma clipping of linear fits and final global fit
bivariate_fit(output) The global fit of order positions
orders_traced(output) Number of orders detected
Returns
The order trace table, or NULL on error

This function creates the order trace table starting from the basic ordertable which contains the (guess) order line slopes and intersepts.

  • First, all orders are traced in both directions starting from the center which is inferred from the 'Slope' and 'Intersept' columns of the ordertable . The detection threshold used for a certain order is min + MINTHRESH * (max - min), where min and max are the minimum and maximum pixel values at the center column of that order. See also trace_order() and estimate_threshold() .
  • Then each order is fitted with a straight line, and the entire order is rejected if the RMS is too large.
  • A global polynomial of degree (DEFPOL1, DEFPOL2) is fitted to all orders, and individual points are rejected using kappa-sigma clipping.

Definition at line 250 of file uves_orderpos_follow.c.

References assure_nomsg, check, check_nomsg, passure, uves_error_reset, uves_msg, uves_msg_debug, uves_msg_low, uves_msg_warning, uves_polynomial_delete(), and uves_polynomial_regression_2d().

static cpl_table * detect_lines ( cpl_image *  htrans,
int  minintersept,
const cpl_image *  inputimage,
int  NORDERS,
bool  norders_is_guess,
int  SAMPLEWIDTH,
double  PTHRES,
double  MINSLOPE,
double  MAXSLOPE,
int  SLOPERES,
bool  consecutive 
)
static

Detect order lines from the Hough image.

Parameters
htransThe Hough transform image (detected features will be deleted)
mininterseptMinimum intersept represented in Hough image
inputimageThe raw image
NORDERSThe number of orders to detect
norders_is_guessFlag indicating if we are allowed detect fewer orders than specified by NORDERS.
SAMPLEWIDTHThe seperation of sample traces in the raw image
PTHRESIf NORDERS is zero, or if norders_is_guess is true, this is the threshold used for peak detection (detection stops when intensity drops to below PTHRES * (previous intensity))
MINSLOPEMinimum line slope to search for
MAXSLOPEMaximum line slope to search for
SLOPERESWidth of Hough image
consecutiveIf true, orders are not assumed to be consecutive
Returns
CPL_ERROR_NONE A table describing the detected lines

This function locates the peaks in the input Hough image. After detecting a peak, the peak itself and the area around it are deleted to avoid several detections of the same feature (see delete_peak() ).

The peak locations are initially defined as the local maximum points but are refined by calculating the centroid of the local area around the maximum (see update_max() ).

The number of order lines to detect is specified by the parameter NORDERS. If this parameter is set to zero, the function will detect lines until the intensity of the next candidate drops to below PTHRES times the dimmest line (PTHRES must be between 0 and 1; if norders_is_guess is false, the parameter PTHRES is ignored).

An important parameter for the peak removal to work is the (approximate) interorder spacing. This parameter is estimated as the raw image height divided by the predicted number of orders (NORDERS). In automatic mode it is estimated as the first minimum of the auto-correlation function along the column in the Hough image containing the global maximum. Note that these methods assume that the inter order spacing does not vary too much as function of order number.

The results of the detection are written to the returned table in the columns 'Slope' (slope of order), 'Intersept' (y-intersept of order) and 'Spacing' (appropriate interorder distance at this order). The table is sorted according to 'Intersept'. The column 'Order' is a label of the order number starting from 1.

Definition at line 398 of file uves_orderpos_hough.c.

References calculate_spacing(), check, check_nomsg, delete_peak(), passure, update_max(), uves_msg, uves_msg_debug, and uves_msg_warning.

Referenced by uves_hough().

static cpl_error_code delete_peak ( cpl_image *  htrans,
int  minintersept,
int  hxmax,
int  hymax,
int  SPACING,
int  imagewidth,
int  SAMPLEWIDTH,
double  MINSLOPE,
double  MAXSLOPE,
int  SLOPERES 
)
static

Delete peak in Hough image.

Parameters
htransThe Hough transform
mininterseptThe minimum intersept represented in Hough space
hxmaxX-position of peak in Hough space
hymaxY-position of peak in Hough space
SPACINGSpacing of order lines
imagewidthWidth of raw image
SAMPLEWIDTHWidth between traces on raw image
MINSLOPEMinimum line slope to search for
MAXSLOPEMaximum line slope to search for
SLOPERESWidth of Hough image
Returns
CPL_ERROR_NONE iff okay

This function deletes a (previously detected) peak in Hough space, and the butterfly shaped area around the peak.

The peak location (in Hough space) is mapped to a line in the input image (using the inverse Hough transformation). The Hough transform of this (one-dimensional) line is a (two-dimensional) butterfly-shaped area, which is then removed. See code for details.

Definition at line 966 of file uves_orderpos_hough.c.

References check, and firsttrace().

Referenced by detect_lines().

static int firsttrace ( int  nx,
int  SAMPLEWIDTH 
)
static

Get the first trace column.

Parameters
nxWidth of raw image
SAMPLEWIDTHSeparation between traces in raw image
Returns
The x-position of the first trace column

The function returns the location of the first trace column of the raw image. The location is defined smallest value greater than 0 of (nx / 2 - N * SAMPLEWIDTH), where N is an integer. This ensures that there is always a sample column at nx/2.

Definition at line 930 of file uves_orderpos_hough.c.

Referenced by delete_peak(), and uves_hough().

static int calculate_spacing ( const cpl_image *  image,
int  x 
)
static

Estimate spacing of order lines.

Parameters
imageThe Hough transform
xThe column to look at
Returns
The estimated order spacing

The function estimates the interorder spacing as two times the first minimum point of the auto-correlation function along the column at x in the Hough image.

Definition at line 837 of file uves_orderpos_hough.c.

References autocorr(), check, and uves_msg_debug.

Referenced by detect_lines().

static double autocorr ( const cpl_image *  image,
const int  x,
const int  shift 
)
static

Calculate auto-correlation function of image column.

Parameters
imageThe image
xThe column to look at
shiftWhere to evaluate the auto-correlation function
Returns
The auto-correlation function

The function returns image(x, y) * image(x, y + shift)) The average is over y-values ranging from 1 to ny - shift (both inclusive).

Definition at line 875 of file uves_orderpos_hough.c.

Referenced by calculate_spacing().

static cpl_error_code update_max ( const cpl_image *  htrans,
int *  xmax,
int *  ymax,
int  SPACING,
int  imagewidth,
int  SAMPLEWIDTH,
double  MINSLOPE,
double  MAXSLOPE,
int  SLOPERES 
)
static

Improve position of a peak in the Hough image.

Parameters
htransThe Hough transform
xmaxPeak x-position which will be updated
ymaxPeak Y-position which will be updated
SPACINGSpacing of order lines
imagewidthWidth of raw image
SAMPLEWIDTHSeparation between traces in raw image
MINSLOPEMinimum line slope to search for
MAXSLOPEMaximum line slope to search for
SLOPERESWidth of Hough image
Returns
CPL_ERROR_NONE iff okay

This function improves a peak position (from the max. pixel value) to the center of mass of a line passing through the middle of the 'butterfly wings' in hough space. The slope of this line in Hough space is ( -(width of input image) / 2 ).

Only pixels with values above ( (1 - 0.5 / NOT) * peak_value ) contribute to the calculation of the centroid. (Here NOT is the number of sample traces in the input image, and peak_value is the pixel value of the detected maximum.)

Definition at line 756 of file uves_orderpos_hough.c.

References uves_msg_debug.

Referenced by detect_lines().

cpl_table* uves_hough ( const cpl_image *  image,
int  ymin,
int  ymax,
int  NORDERS,
bool  norders_is_guess,
int  SAMPLEWIDTH,
double  PTHRES,
double  MINSLOPE,
double  MAXSLOPE,
int  SLOPERES,
bool  consecutive,
cpl_image **  htrans,
cpl_image **  htrans_original 
)

Compute Hough transform and detect lines.

Parameters
imageInput image
yminFirst image row to consider (inclusive, FITS convention)
ymaxLast image row to consider (inclusive, FITS convention)
NORDERSThe number of orders to detect, or zero
norders_is_guessFlag indicating if we are allowed detect fewer orders than specified by NORDERS.
SAMPLEWIDTHThe seperation of sample traces in input image
PTHRESIn automatic mode, the ratio between the dimmest and next-dimmest line
MINSLOPEMinimum line slope
MAXSLOPEMaximum line slope
SLOPERESWidth of Hough image (number of slopes represented)
consecutiveIf true, orders are assumed to be consecutive
htrans(output) computed Hough transform with peaks deleted
htrans_original(output) computed Hough transform (returned)
Returns
Table describing the detected lines (see detect_lines() for details )

This function computes the Hough transform of the image image. The input image is traced along vertical lines seperated by SAMPLEWIDTH.

See also detect_lines().

Possible order line slopes range from MINSLOPE to MAXSLOPE . The function assumes that all slopes are positive and small. To detect lines with slopes larger than 0.3 - 0.5 or so, the algorithm should be changed to use polar (i.e. rotation invariant) coordinates in Hough space.

Definition at line 194 of file uves_orderpos_hough.c.

References assure_nomsg, check, check_nomsg, detect_lines(), firsttrace(), passure, uves_msg, uves_msg_debug, and uves_msg_warning.

cpl_error_code uves_draw_orders ( const cpl_table *  ordertable,
cpl_image *  image 
)

Draw detected order lines.

Parameters
ordertableThe order table
imageThe image to draw on
Returns
CPL_ERROR_NONE iff okay

This function draws on the input image the lines listed in the provided order table. The intersept and slope of the lines are read from the order table.

Definition at line 1018 of file uves_orderpos_hough.c.

References check, and passure.