CR2RE Pipeline Reference Manual 1.6.2
Functions
Nodding Utilities

Functions

cr2res_nodding_pos * cr2res_nodding_read_positions (const cpl_frameset *in)
 Get the nodding positions from a frame set.
 
char cr2res_nodding_position_char (cr2res_nodding_pos pos)
 Get the nodding position character for display.
 
int cr2res_combine_nodding_split_frames (const cpl_frameset *in, const cr2res_nodding_pos *positions, cpl_frameset **pos_a, cpl_frameset **pos_b)
 Split A/B positions in 2 framesets.
 
int cr2res_combine_nodding_split (const hdrl_imagelist *in, const cr2res_nodding_pos *positions, hdrl_imagelist **pos_a, hdrl_imagelist **pos_b)
 Split A/B positions in 2 image lists.
 
double cr2res_mjd_obs_now (void)
 Get the current MJD-OBS.
 
int cr2res_order_idx_to_real (int order_idx, int order_zp)
 Convert the order_idx into order_real.
 
int cr2res_order_real_to_idx (int order_real, int order_zp)
 Convert the order_real into order_idx.
 
double cr2res_ra_hms2deg (int hh, int mm, double ss)
 Convert the RA from hh mm ss to degrees.
 
double cr2res_dec_hms2deg (int dd, int mm, double ss)
 Convert the DEC from dd mm ss to degrees.
 
int cr2res_format_setting (char *setting_id)
 Format the setting.
 
int cr2res_is_short_wavelength (const char *setting_id)
 Identify Short Wavelength.
 
int cr2res_format_setting2 (char *setting_id)
 Format the setting.
 
double cr2res_vector_get_mad (cpl_vector *invec, double *mad)
 Get MAD from a vector.
 
int * cr2res_vector_get_int (const cpl_vector *ycen)
 
double * cr2res_vector_get_rest (const cpl_vector *ycen)
 
cpl_table * cr2res_combine_extracted (const cpl_table *extracta, const cpl_table *extractb)
 Combine two extracted spectra by resampling one to the other's WL.
 
cpl_polynomial * cr2res_fit_interorder (cpl_image *img, cpl_table *trace_wave, cpl_size order_x, cpl_size order_y)
 Fit a 2D Polynomial to the interorder regions.
 
int cr2res_slit_pos (const cpl_table *trace_wave, cpl_polynomial ***coef_slit, cpl_polynomial ***coef_wave, int *size)
 Create the polynomials needed to calculate the slit pos and wavelength at any point x, y within an order.
 
int cr2res_slit_pos_image (const cpl_table *trace_wave, cpl_image **slitpos, cpl_image **wavelength)
 get a image of the slitposition (and wavelength) along the slit
 
cpl_image * cr2res_image_cut_rectify (const cpl_image *img_in, const cpl_vector *ycen, int height)
 Cut a bent order into a rectangle, shifting columns.
 
int cr2res_image_insert_rect (const cpl_image *rect_in, const cpl_vector *ycen, cpl_image *img_out)
 Re-insert a rectangular cut-out of an order into the full frame.
 
cpl_vector * cr2res_polynomial_eval_vector (const cpl_polynomial *poly, const cpl_vector *vec)
 Evaluate a polynomial on a vector.
 
cpl_vector * cr2res_threshold_spec (const cpl_vector *invector, int smooth, double thresh)
 Find the regions with over-average values in a vector.
 
char * cr2res_get_base_name (const char *filename)
 Find out the base name of a file (i.e. without prefix path)
 
char * cr2res_get_root_name (const char *filename)
 Find out the root part of a basename (name without extension).
 
cpl_frameset * cr2res_extract_frameset (const cpl_frameset *in, const char *tag)
 Extract the frames with the given tag from a frameset.
 
cpl_frameset * cr2res_extract_frameset_several_tags (const cpl_frameset *in, const char **tags, int ntags)
 Extract the frames whose tag is within a list from a frameset.
 
char * cr2res_decker_print_position (cr2res_decker dpos)
 Get the decker position string for display.
 
cpl_polynomial * cr2res_convert_array_to_poly (const cpl_array *arr)
 Convert an array to polynomial.
 
cpl_array * cr2res_convert_poly_to_array (const cpl_polynomial *poly, int size)
 Convert a polynomial to array.
 
cpl_error_code cr2res_detector_shotnoise_model (const cpl_image *ima_data, const double gain, const double ron, cpl_image **ima_errs)
 compute photon count error in [ADU]
 
int cr2res_plot_wavecal_result (const cpl_bivector *extracted_spec, const cpl_bivector *catalog, const char *title, double wmin, double wmax)
 Plot the spectrum with the catalog.
 
cpl_image * cr2res_util_optimal_filter_2d (const cpl_image *img, const cpl_image *weight, double lam_x, double lam_y)
 Apply the optimal filter in the 2D case.
 
cpl_polynomial * cr2res_polyfit_2d_loc (const cpl_vector *x, const cpl_vector *y, const cpl_vector *z, const cpl_matrix *degree)
 Perform a 2D polynomial fit f(x, y) = z.
 
double cr2res_util_blaze_stat (const cpl_table *blaze, int *ngood, double *blaze_tot)
 Computes the average of the blaze.
 
double cr2res_utils_get_center_mjd (const cpl_frameset *frameset)
 Calculate the middle of the exposures in the frameset.
 
const char * cr2res_get_license (void)
 Get the pipeline copyright and license.
 

Detailed Description

Function Documentation

◆ cr2res_combine_extracted()

cpl_table * cr2res_combine_extracted ( const cpl_table *  extracta,
const cpl_table *  extractb 
)

◆ cr2res_combine_nodding_split()

int cr2res_combine_nodding_split ( const hdrl_imagelist *  in,
const cr2res_nodding_pos *  positions,
hdrl_imagelist **  pos_a,
hdrl_imagelist **  pos_b 
)

Split A/B positions in 2 image lists.

Parameters
inInput image list
positionsnodding positions
pos_a[out] A position images
pos_b[out] B position images
Returns
0 if ok, -1 otherwise

Definition at line 153 of file cr2res_nodding.c.

References hdrl_image_duplicate(), hdrl_imagelist_get(), hdrl_imagelist_get_size(), hdrl_imagelist_new(), and hdrl_imagelist_set().

◆ cr2res_combine_nodding_split_frames()

int cr2res_combine_nodding_split_frames ( const cpl_frameset *  in,
const cr2res_nodding_pos *  positions,
cpl_frameset **  pos_a,
cpl_frameset **  pos_b 
)

Split A/B positions in 2 framesets.

Parameters
inInput frameset
positionsnodding positions
pos_a[out] A position frames
pos_b[out] B position frames
Returns
0 if ok, -1 otherwise

Definition at line 100 of file cr2res_nodding.c.

◆ cr2res_convert_array_to_poly()

cpl_polynomial * cr2res_convert_array_to_poly ( const cpl_array *  arr)

Convert an array to polynomial.

Parameters
arrAn array
Returns
The newly created polynomial or NULL The returned object must be de allocated with cpl_polynomial_delete()

Definition at line 1305 of file cr2res_utils.c.

Referenced by cr2res_extract2d_trace(), cr2res_fit_interorder(), cr2res_get_trace_wave_poly(), cr2res_slit_curv_gen_map(), cr2res_slit_pos(), cr2res_trace_gen_image(), cr2res_trace_get_trace_ypos(), cr2res_trace_new_slit_fraction(), and cr2res_wave_gen_wave_map().

◆ cr2res_convert_poly_to_array()

cpl_array * cr2res_convert_poly_to_array ( const cpl_polynomial *  poly,
int  size 
)

Convert a polynomial to array.

Parameters
polyA polynomial
sizeThe requested array size
Returns
The newly created array or NULL The returned object must be de allocated with cpl_array_delete()

Definition at line 1339 of file cr2res_utils.c.

Referenced by cr2res_trace_new_slit_fraction(), and cr2res_wave_apply().

◆ cr2res_dec_hms2deg()

double cr2res_dec_hms2deg ( int  dd,
int  mm,
double  ss 
)

Convert the DEC from dd mm ss to degrees.

Parameters
dddegrees
mmminutes
ssseconds
Returns
DEC in degrees

60 arc-minutes is one degree and 60 arc-seconds is one arc-minute.

Definition at line 139 of file cr2res_utils.c.

Referenced by cr2res_ra_hms2deg().

◆ cr2res_decker_print_position()

char * cr2res_decker_print_position ( cr2res_decker  dpos)

Get the decker position string for display.

Parameters
dposThe decker position
Returns
the newly allocated string

Definition at line 1276 of file cr2res_utils.c.

◆ cr2res_detector_shotnoise_model()

cpl_error_code cr2res_detector_shotnoise_model ( const cpl_image *  ima_data,
const double  gain,
const double  ron,
cpl_image **  ima_errs 
)

compute photon count error in [ADU]

Parameters
ima_datain [ADU]
gaindetector's gain in [e- / ADU]
rondetector's read out noise in [ADU]
ima_errsoutput error image in [ADU]
Returns
cpl_error_code
Note
ima_errs need to be deallocated ima_data must contain the photon counts with no offsets this usually means the image must be overscan and bias corrected Then the shot noise can be calculated from the poissonian distribution as sqrt(electron-counts). To this (transformed back into ADUs) the readout noise is added in quadrature. @doc error is computed with standard formula

$ err_{ADU} = \sqrt{ \frac{ counts }{ gain } + ron^{ 2 } } $

If an image value is negative the associated error is set to RON

Definition at line 1426 of file cr2res_utils.c.

◆ cr2res_extract_frameset()

cpl_frameset * cr2res_extract_frameset ( const cpl_frameset *  in,
const char *  tag 
)

Extract the frames with the given tag from a frameset.

Parameters
inA non-empty frameset
tagThe tag of the requested frames
Returns
The newly created frameset or NULL on error

The returned frameset must be de allocated with cpl_frameset_delete()

Definition at line 1179 of file cr2res_utils.c.

◆ cr2res_extract_frameset_several_tags()

cpl_frameset * cr2res_extract_frameset_several_tags ( const cpl_frameset *  in,
const char **  tags,
int  ntags 
)

Extract the frames whose tag is within a list from a frameset.

Parameters
inA non-empty frameset
tagsThe list of allowed tags of the requested frames
ntagsThe number of tags
Returns
The newly created frameset or NULL on error

The returned frameset must be de allocated with cpl_frameset_delete()

Definition at line 1224 of file cr2res_utils.c.

Referenced by cr2res_io_find_BPM_all(), cr2res_io_find_EXTRACT_1D_all(), cr2res_io_find_SLIT_MODEL(), and cr2res_io_find_TRACE_WAVE_all().

◆ cr2res_fit_interorder()

cpl_polynomial * cr2res_fit_interorder ( cpl_image *  img,
cpl_table *  trace_wave,
cpl_size  order_x,
cpl_size  order_y 
)

Fit a 2D Polynomial to the interorder regions.

Parameters
imgImage, Image with the noise and traces to fit (e.g. a observation)
trace_waveTrace Wave Table
order_xmaximum order of the polynomial in x direction
order_ymaximum order of the polynomial in y direction
Returns
the fitted polynomial if successful, NULL on error

Definition at line 461 of file cr2res_utils.c.

References cr2res_convert_array_to_poly(), and cr2res_trace_get_order_idx_values().

◆ cr2res_format_setting()

int cr2res_format_setting ( char *  setting_id)

Format the setting.

Parameters
Setting
Returns
0 if ok, -1 in error case replace / by _ in the setting string

Definition at line 152 of file cr2res_utils.c.

Referenced by cr2res_io_find_SLIT_MODEL().

◆ cr2res_format_setting2()

int cr2res_format_setting2 ( char *  setting_id)

Format the setting.

Parameters
Setting
Returns
0 if ok, -1 in error case replace _ by / in the setting string

Definition at line 190 of file cr2res_utils.c.

◆ cr2res_get_base_name()

char * cr2res_get_base_name ( const char *  filename)

Find out the base name of a file (i.e. without prefix path)

Parameters
filenameFull path name to scan.
Returns
Pointer to char within the input string.

Definition at line 1112 of file cr2res_utils.c.

◆ cr2res_get_license()

const char * cr2res_get_license ( void  )

Get the pipeline copyright and license.

Returns
The copyright and license string

The function returns a pointer to the statically allocated license string. This string should not be modified using the returned pointer.

Definition at line 2362 of file cr2res_utils.c.

◆ cr2res_get_root_name()

char * cr2res_get_root_name ( const char *  filename)

Find out the root part of a basename (name without extension).

Parameters
filenameFile name to scan.
Returns
Pointer to statically allocated string.

Definition at line 1128 of file cr2res_utils.c.

◆ cr2res_image_cut_rectify()

cpl_image * cr2res_image_cut_rectify ( const cpl_image *  img_in,
const cpl_vector *  ycen,
int  height 
)

Cut a bent order into a rectangle, shifting columns.

Parameters
img_in
ycen
height
Returns
img_out

Definition at line 907 of file cr2res_utils.c.

References cr2res_vector_get_int().

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

◆ cr2res_image_insert_rect()

int cr2res_image_insert_rect ( const cpl_image *  rect_in,
const cpl_vector *  ycen,
cpl_image *  img_out 
)

Re-insert a rectangular cut-out of an order into the full frame.

Parameters
rect_in
ycen
Returns
img_out

Definition at line 984 of file cr2res_utils.c.

References cr2res_vector_get_int().

Referenced by cr2res_extract_slitdec_curved().

◆ cr2res_is_short_wavelength()

int cr2res_is_short_wavelength ( const char *  setting_id)

Identify Short Wavelength.

Parameters
Setting
Returns
1 if SW, 0 if LW, -1 in error case

Definition at line 171 of file cr2res_utils.c.

◆ cr2res_mjd_obs_now()

double cr2res_mjd_obs_now ( void  )

Get the current MJD-OBS.

Returns
The MJD-OBS

Definition at line 58 of file cr2res_utils.c.

Referenced by cr2res_io_save_EMISSION_LINES(), and cr2res_io_save_PHOTO_FLUX().

◆ cr2res_nodding_position_char()

char cr2res_nodding_position_char ( cr2res_nodding_pos  pos)

Get the nodding position character for display.

Parameters
posthe nodding position
Returns
the character for display

Definition at line 83 of file cr2res_nodding.c.

◆ cr2res_nodding_read_positions()

cr2res_nodding_pos * cr2res_nodding_read_positions ( const cpl_frameset *  in)

Get the nodding positions from a frame set.

Parameters
setInput frame set
Returns
the NODDING positions or NULL in error case

Definition at line 50 of file cr2res_nodding.c.

References cr2res_pfits_get_nodding_pos().

◆ cr2res_order_idx_to_real()

int cr2res_order_idx_to_real ( int  order_idx,
int  order_zp 
)

Convert the order_idx into order_real.

Parameters
order_idxOrder index
order_zpOrder Zero Point
Returns
order_real

Definition at line 89 of file cr2res_utils.c.

Referenced by cr2res_trace_filter().

◆ cr2res_order_real_to_idx()

int cr2res_order_real_to_idx ( int  order_real,
int  order_zp 
)

Convert the order_real into order_idx.

Parameters
order_realOrder Real
order_zpOrder Zero Point
Returns
order_idx

Definition at line 102 of file cr2res_utils.c.

Referenced by cr2res_wave_apply().

◆ cr2res_plot_wavecal_result()

int cr2res_plot_wavecal_result ( const cpl_bivector *  extracted_spec,
const cpl_bivector *  catalog,
const char *  title,
double  wmin,
double  wmax 
)

Plot the spectrum with the catalog.

Parameters
extracted_specThe extracted spectrum
catalogThe lines catalog
titleThe title for the plot
wminMin Wavelength to display or -1
wmaxMax Wavelength to display or -1
Returns
0 if ok

Definition at line 1458 of file cr2res_utils.c.

Referenced by cr2res_wave_1d().

◆ cr2res_polyfit_2d_loc()

cpl_polynomial * cr2res_polyfit_2d_loc ( const cpl_vector *  x,
const cpl_vector *  y,
const cpl_vector *  z,
const cpl_matrix *  degree 
)

Perform a 2D polynomial fit f(x, y) = z.

Parameters
xcoordinates
ycoordinates
zvalues to fit
degreesto fit with shape (ndegrees, 2) with one entry per xy combination, x degrees in the 1st column, and y degrees in the 2nd, Note that you need to include 0, 0 as well for the constant offset
Returns
Fitted polynomial, NULL for error

Perform a 2D polynomial fit, where the fit degrees are explicitly specified.

Definition at line 2063 of file cr2res_utils.c.

◆ cr2res_polynomial_eval_vector()

cpl_vector * cr2res_polynomial_eval_vector ( const cpl_polynomial *  poly,
const cpl_vector *  vec 
)

Evaluate a polynomial on a vector.

Parameters
poly
vec
Returns
Vector with evaluation result. Caller needs to deallocate.

Definition at line 1059 of file cr2res_utils.c.

Referenced by cr2res_extract2d_trace(), and cr2res_wave_etalon().

◆ cr2res_ra_hms2deg()

double cr2res_ra_hms2deg ( int  hh,
int  mm,
double  ss 
)

Convert the RA from hh mm ss to degrees.

Parameters
hhhours
mmminutes
ssseconds
Returns
RA in degrees

An arc-hour is 15 degrees, 60 arc-minutes is one arc-hour and 60 arc-seconds is one arc-minute.

Definition at line 121 of file cr2res_utils.c.

References cr2res_dec_hms2deg().

◆ cr2res_slit_pos()

int cr2res_slit_pos ( const cpl_table *  trace_wave,
cpl_polynomial ***  coef_slit,
cpl_polynomial ***  coef_wave,
int *  size 
)

Create the polynomials needed to calculate the slit pos and wavelength at any point x, y within an order.

Parameters
trace_waveinput trace wave table with wavelength polynomials for all orders
coef_slit[out] slit pos polynomials as a function of the wavelength and the pixel row y
coef_wave[out] wavelength polynomials as a function of the pixel position x, y
size[out] the number of orders (polynomials) in coef_slit and coef_wave
Returns
0 on success, -1 on fail

Definition at line 627 of file cr2res_utils.c.

References cr2res_convert_array_to_poly(), cr2res_get_trace_numbers(), cr2res_get_trace_table_index(), cr2res_get_trace_wave_poly(), and cr2res_trace_get_order_idx_values().

Referenced by cr2res_slit_pos_image().

◆ cr2res_slit_pos_image()

int cr2res_slit_pos_image ( const cpl_table *  trace_wave,
cpl_image **  slitpos,
cpl_image **  wavelength 
)

get a image of the slitposition (and wavelength) along the slit

Parameters
tw_decker_1tracewave table for traces with decker 1
tw_decker_2tracewave_table for traces with decker 2
slitposoutput image of slit positions
wavelengthoutput image of wavelength
Returns
return 0 if successful, -1 otherwise

Uses the polynomials from cr2res_slit_pos to calculate the slit position and wavelength of each pixel

Definition at line 841 of file cr2res_utils.c.

References cr2res_slit_pos().

Referenced by cr2res_extract2d_traces().

◆ cr2res_threshold_spec()

cpl_vector * cr2res_threshold_spec ( const cpl_vector *  invector,
int  smooth,
double  thresh 
)

Find the regions with over-average values in a vector.

Parameters
invectorThe vector to be analyzed
smoothThe size of the boxcar smoothing kernel
Returns
Vector derived as (invector-smoothed_vector - thresh), meaning that positive values are at least thresh larger than the smoothed vector. The returned vector needs to be deallocated by the caller.

Definition at line 1089 of file cr2res_utils.c.

◆ cr2res_util_blaze_stat()

double cr2res_util_blaze_stat ( const cpl_table *  blaze,
int *  ngood,
double *  blaze_tot 
)

Computes the average of the blaze.

Parameters
blazeThe extracted spectrum from the flat ie blaze
Returns
The average Compute for each spectrum of the input EXTRACT_1D table : median(snr) Return the median of the medians

Definition at line 2223 of file cr2res_utils.c.

References cr2res_dfs_SPEC_colname_parse().

◆ cr2res_util_optimal_filter_2d()

cpl_image * cr2res_util_optimal_filter_2d ( const cpl_image *  img,
const cpl_image *  weight,
double  lam_x,
double  lam_y 
)

Apply the optimal filter in the 2D case.

Parameters
imgInput image to filter
weightWeights for each point, should be between 0 and 1
lam_xRegularization factor in x direction
lam_yRegularization factor in y direction
Returns
filtered image if ok, NULL otherwise

The optimal filter applies a restriction on the 1st derivatives in the x and y directions.

Definition at line 1848 of file cr2res_utils.c.

◆ cr2res_utils_get_center_mjd()

double cr2res_utils_get_center_mjd ( const cpl_frameset *  frameset)

Calculate the middle of the exposures in the frameset.

Parameters
frameset- the input frames
Returns
The center of the exposures in MJD

The calculation is a weighted arithmetic mean of the midpoints in mjd, weighted by the exposure times.

Definition at line 2289 of file cr2res_utils.c.

◆ cr2res_vector_get_int()

int * cr2res_vector_get_int ( const cpl_vector *  ycen)

◆ cr2res_vector_get_mad()

double cr2res_vector_get_mad ( cpl_vector *  invec,
double *  mad 
)

Get MAD from a vector.

Parameters
invecinput vector
mad*median absolute deviation (output)
Returns
median

Wrap a vector into an image because the cpl does not have this for vectors

Definition at line 212 of file cr2res_utils.c.

Referenced by cr2res_calib_subtract_interorder_column().

◆ cr2res_vector_get_rest()

double * cr2res_vector_get_rest ( const cpl_vector *  ycen)
Parameters
ycen
Returns

Definition at line 253 of file cr2res_utils.c.

Referenced by cr2res_extract_slitdec_curved().