X-shooter Pipeline Reference Manual 3.8.15
Macros
xsh_utils_image.c File Reference
#include <xsh_utils_wrappers.h>
#include <xsh_utils_image.h>
#include <xsh_error.h>
#include <xsh_utils.h>
#include <xsh_pfits_qc.h>
#include <xsh_pfits.h>
#include <xsh_dfs.h>
#include <xsh_data_pre.h>
#include <xsh_data_instrument.h>
#include <math.h>
#include <string.h>
#include <float.h>

Go to the source code of this file.

Macros

#define FLAG   -1.e+9
 

Functions

xsh_show_interpolation_kernel

@memo Print out an interpolation kernel values on stdout.

Parameters
kernel_nameName of the kernel to print out.
Returns
void @doc

Takes in input a kernel name, generates the corresponding kernel and prints it out on stdout, then discards the generated kernel.

For debugging purposes mostly.

static cpl_image * xsh_image_crop (const cpl_image *image, int xlo, int ylo, int xhi, int yhi)
 Crop image.
 
void xsh_show_interpolation_kernel (char *kernel_name)
 
double xsh_image_get_stdev_robust (const cpl_image *image, double cut, double *dstdev)
 Get robust empirical stdev of data.
 
double xsh_image_get_stdev_clean (const cpl_image *image, double *dstdev)
 Get clean (3*sigma clip) empirical stdev of data.
 
double xsh_fixed_pattern_noise (const cpl_image *master, double convert_ADU, double master_noise)
 Compute fixed pattern noise in flat field.
 
double xsh_fixed_pattern_noise_bias (const cpl_image *first_raw, const cpl_image *second_raw, double ron)
 Compute fixed pattern noise in bias.
 
cpl_error_code xsh_image_warp_polynomial_scale (cpl_image *out, const cpl_polynomial *poly_x, const cpl_polynomial *poly_y)
 Compute area change ratio for a 2D polynomial transformation.
 
cpl_image * xsh_scharr_x (cpl_image *in)
 Compute X Scharr filter transformation.
 
cpl_image * xsh_scharr_y (cpl_image *in)
 Compute Y Scharr filter transformation.
 
cpl_image * xsh_sobel_lx (cpl_image *in)
 Compute X Sobel filter transformation.
 
cpl_image * xsh_sobel_ly (cpl_image *in)
 Compute Y Sobel filter transformation.
 
cpl_error_code xsh_compute_ron (cpl_frameset *frames, int llx, int lly, int urx, int ury, int nsampl, int hsize, const int reg_id, double *ron, double *ron_err)
 compute ron taking random windows of given size in a given region on 2 frames difference
 
cpl_image * xsh_image_search_bad_pixels_via_noise (cpl_imagelist *darks, float thresh_sigma_factor, float low_threshold, float high_threshold, int llx, int lly, int urx, int ury)
 search bad pixels
 
xsh_clean_mean()

his routine computes the clean mean of a given data

Parameters
arraydata array to average
n_elementsnumber of elements of the data array
throwaway_lowpercentage of low value elements to be thrown away before averaging
throwaway_highpercentage of high value elements to be thrown away before averaging
Returns
the clean mean of a data array FLT_MAX in case of error @doc this routine computes the clean mean of a given data array that means the array is first sorted and a given percentage of the lowest and the highest values is not considered for averaging
static float xsh_clean_mean (float *array, int n_elements, float throwaway_low, float throwaway_high)
 
static cpl_error_code xsh_compute_geom_corr (const double dxdu, const double dydv, const double dxdv, const double dydu, const double du, const double dv, double *dA)
 Pixel area geometric trasformation computation.
 
cpl_image * xsh_image_compute_geom_corr (cpl_image *in)
 Pixel area geometric trasformation computation.
 
xsh_sinc

@memo Cardinal sine.

Parameters
xdouble value.
Returns
1 double. @doc

Compute the value of the function xsh_sinc(x)=sin(pi*x)/(pi*x) at the requested x.

static double xsh_sinc (double x)
 
reverse_tanh_kernel

@memo Bring a hyperbolic tangent kernel from Fourier to normal space.

Parameters
dataKernel samples in Fourier space.
nnNumber of samples in the input kernel.
Returns
void @doc

Bring back a hyperbolic tangent kernel from Fourier to normal space. Do not try to understand the implementation and DO NOT MODIFY THIS FUNCTION.

static void reverse_tanh_kernel (double *data, int nn)
 
xsh_image_smooth_fft

@memo Smooth an image using a FFT.

Parameters
inpImage to filter
fxfilter radii
fyfilter radii
Returns
1 newly allocated image. @doc This function applies a lowpass spatial filter of frequency fy along Y.
Note
works only with square size images The returned image is a newly allocated object, it must be deallocated using xsh_free_image().
static cpl_image * xsh_gen_lowpass (const int xs, const int ys, const double sigma_x, const double sigma_y)
 Generate a low pass filter for FFT convolution .
 
cpl_image * xsh_image_smooth_fft (cpl_image *inp, const int fx, const int fy)
 
xsh_generate_interpolation_kernel

@memo Generate an interpolation kernel to use in this module.

Parameters
kernel_typeType of interpolation kernel.
Returns
1 newly allocated array of doubles. @doc

Provide the name of the kernel you want to generate. Supported kernel types are:

\begin{tabular}{ll} NULL & default kernel, currently "tanh" \ "default" & default kernel, currently "tanh" \ "tanh" & Hyperbolic tangent \ "sinc2" & Square xsh_sinc \ "lanczos" & Lanczos2 kernel \ "hamming" & Hamming kernel \ "hann" & Hann kernel \end{tabular}

The returned array of doubles is ready of use in the various re-sampling functions in this module. It must be deallocated using cpl_free().

double * xsh_generate_interpolation_kernel (const char *kernel_type)
 
xsh_pixel_qsort

@memo Sort an array of pixels by increasing pixelvalue.

Parameters
pix_arrArray to sort.
npixNumber of pixels in the array.
Returns
void @doc

Optimized implementation of a fast pixel sort. The input array is modified.

void xsh_pixel_qsort (pixelvalue *pix_arr, int npix)
 
xsh_image_smooth_mean_y

@memo Smooth an image using a simple mean.

Parameters
inpImage to shift.
rsmoothing radii.
Returns
1 newly allocated image. @doc

This function applies a running mean or radius r along y.

The returned image is a newly allocated object, it must be deallocated using xsh_free_image().

cpl_image * xsh_image_smooth_mean_y (cpl_image *inp, const int r)
 
xsh_image_smooth_median_y

@memo Smooth an image using a simple mean.

Parameters
inpImage to shift.
rsmoothing radius
Returns
1 newly allocated image. @doc

This function applies a running median or radius r along y.

The returned image is a newly allocated object, it must be deallocated using xsh_free_image().

cpl_image * xsh_image_smooth_median_y (cpl_image *inp, const int r)
 
xsh_image_smooth_mean_x

@memo Smooth an image using a simple mean.

Parameters
inpImage to shift.
rsmoothing radii.
Returns
1 newly allocated image. @doc

This function applies a running mean or radius r along x.

The returned image is a newly allocated object, it must be deallocated using xsh_free_image().

cpl_image * xsh_image_smooth_mean_x (cpl_image *inp, const int r)
 
xsh_image_smooth_median_x

@memo Smooth an image using a simple mean.

Parameters
inpImage to shift.
rsmoothing radius
Returns
1 newly allocated image. @doc

This function applies a running median or radius r along x.

The returned image is a newly allocated object, it must be deallocated using xsh_free_image().

cpl_image * xsh_image_smooth_median_x (cpl_image *inp, const int r)
 
xsh_image_smooth_median_xy

@memo Smooth an image using a simple mean.

Parameters
inpImage to shift.
rsmoothing radius
Returns
1 newly allocated image. @doc

This function applies a running median or radius r along x.

The returned image is a newly allocated object, it must be deallocated using xsh_free_image().

cpl_image * xsh_image_smooth_median_xy (cpl_image *inp, const int r)
 
xsh_image_clean_badpixel

@memo Smooth an image using a simple median.

Parameters
inImage to smooth.
Returns
error code @doc

This function applies a running median of radius r along y.

cpl_error_code xsh_image_clean_badpixel (cpl_frame *in)
 
xsh_image_fit_gaussian_max_pos_x_window

@memo Determine image peack position according Gaussian fit

Parameters
imainput image
llxlower left x
urxupper right x
yposY position on image at which the Gaussian fit is performed
Returns
peak position @doc Determine image peack position according Gaussian fit. In case the Gaussian fit fails a centroid determination is performed.
double xsh_image_fit_gaussian_max_pos_x_window (const cpl_image *ima, const int llx, const int urx, const int ypos)
 
xsh_image_fit_gaussian_max_pos_y_window

@memo Determine image peack position according Gaussian fit

Parameters
imainput image
llylower left y
uryupper right y
xposX position on image at which the Gaussian fit is performed
Returns
peak position @doc Determine image peack position according Gaussian fit. In case the Gaussian fit fails a centroid determination is performed.
static double xsh_image_fit_gaussian_max_pos_y_window (const cpl_image *ima, const int lly, const int ury, const int xpos)
 
static cpl_table * xsh_image_qc_trace_window (cpl_image *data_ima, cpl_propertylist *head, const int hsize, const int method)
 Trace object position in an image.
 
cpl_frame * xsh_frame_image_qc_trace_window (cpl_frame *frm_ima, xsh_instrument *instrument, const char *suffix, const int hsize, const int method)
 Trace object position in an image.
 
cpl_frame * xsh_frame_image_ext_qc_trace_window (cpl_frame *frm_ima, xsh_instrument *instrument, const char *suffix, const int hsize, const int method)
 Trace object position in an image.
 
static cpl_error_code xsh_util_compute_qc_residuals (cpl_table *table, xsh_instrument *instrument, cpl_propertylist *plist)
 Computes residuals statistics on given wave ranges.
 
static cpl_error_code xsh_cube_trace_fit (cpl_table **table, const char *col_wav, const char *col_ref, const char *col_fit, const char *qualifier, cpl_propertylist *plist)
 Fit cube traces and compute fit coeffs differences.
 
static cpl_error_code xsh_cube_trace_diff (const cpl_table *table, const char *col_comp, const char *col_ref, cpl_propertylist *plist)
 Computes differences between cube fit trace coefficients.
 
cpl_frame * xsh_cube_qc_trace_window (cpl_frame *frm_cube, xsh_instrument *instrument, const char *suffix, const char *rec_prefix, const int win_min, const int win_max, const int hsize, const int method, const int compute_qc)
 Trace object position in a cube.
 
cpl_error_code xsh_iml_merge_avg (cpl_imagelist **data, cpl_imagelist **mask, const cpl_image *data_ima, const cpl_image *mask_ima, const int mk)
 merge imagelist via average
 
cpl_error_code xsh_iml_merge_wgt (cpl_imagelist **data, cpl_imagelist **errs, cpl_imagelist **qual, const cpl_image *flux_b, const cpl_image *errs_b, const cpl_image *qual_b, const int mk, const int decode_bp)
 merge imagelist via average
 
cpl_error_code xsh_image_mflat_detect_blemishes (cpl_frame *flat_frame, xsh_instrument *instrument)
 Flag blemishes in a flat image.
 
cpl_error_code xsh_collapse_errs (cpl_image *errs, cpl_imagelist *list, const int mode)
 
cpl_image * xsh_combine_flats (cpl_image *ima1_in, cpl_image *ima2_in, xsh_order_list *qth_list, xsh_order_list *d2_list, const int xrad, const int yrad)
 Combine flat frames line adjusting illumination level to merge them smoothly.
 
cpl_error_code xsh_frame_image_save2ext (cpl_frame *frm, const char *name_o, const int ext_i, const int ext_o)
 
cpl_error_code xsh_frame_image_add_double (cpl_frame *frm, const double value)
 
static cpl_error_code xsh_key_scan_mult_by_fct (cpl_propertylist **plist, const char *kname, const int fct)
 
static cpl_error_code xsh_key_bin_div_by_fct (cpl_propertylist **plist, const char *kname, const int fct)
 
static cpl_error_code xsh_plist_mult_by_fct (cpl_propertylist **plist, const int fctx, const int fcty)
 
static cpl_image * xsh_image_div_by_fct (const cpl_image *ima_dat, const int fctx, const int fcty)
 
static cpl_image * xsh_image_mult_by_fct (const cpl_image *ima_dat, const int fctx, const int fcty)
 
cpl_frame * xsh_frame_image_div_by_fct (cpl_frame *frm, const int fctx, const int fcty)
 
cpl_frame * xsh_frame_image_mult_by_fct (cpl_frame *frm, const int fctx, const int fcty)
 
cpl_error_code xsh_image_cut_dichroic_uvb (cpl_frame *frame1d)
 
cpl_image * xsh_compute_scale (cpl_imagelist *iml_data, cpl_mask *bpm, const int mode, const int win_hsz)
 
cpl_image * xsh_compute_scale_tab (cpl_imagelist *iml_data, cpl_mask *bpm, cpl_table *tab_bpm, const int mode, const int win_hsz)
 
cpl_image * xsh_compute_scale_tab2 (cpl_imagelist *iml_data, cpl_imagelist *iml_qual, cpl_mask *bpm, cpl_table *tab_bpm, const int mode, const int win_hsz, const int decode_bp)
 
cpl_image * xsh_compute_scale_tab3 (cpl_imagelist *iml_data, cpl_imagelist *iml_qual, cpl_mask *bpm, cpl_table *tab_bpm, const int mode, const int win_hsz, const int decode_bp)
 
cpl_table * xsh_qual2tab (cpl_image *qual, const int code)
 

xsh_warp_image_generic

@memo Warp an image according to a polynomial transformation.

Parameters
image_inImage to warp.
kernel_typeInterpolation kernel to use.
poly_uPolynomial transform in U.
poly_vPolynomial transform in V.
Returns
1 newly allocated image. @doc

Warp an image according to a polynomial transform. Provide two polynomials (see poly2d.h for polynomials in this library) Pu and Pv such as:

\begin{verbatim} x = xsh_poly2d_compute(Pu, u, v) y = xsh_poly2d_compute(Pv, u, v) \end{verbatim}

Attention! The polynomials define a reverse transform. (u,v) are coordinates in the warped image and (x,y) are coordinates in the original image. The transform you provide is used to compute from the warped image, which pixels contributed in the original image.

The output image will have strictly the same size as in the input image. Beware that for extreme transformations, this might lead to blank images as result.

See the function xsh_generate_interpolation_kernel() for possible kernel types. If you want to use a default kernel, provide NULL for kernel type.

The returned image is a newly allocated objet, use cpl_image_delete() to deallocate it.

#define hk_gen(x, s)   (((tanh(s*(x+0.5))+1)/2)*((tanh(s*(-x+0.5))+1)/2))
 
cpl_image * xsh_warp_image_generic (cpl_image *image_in, char *kernel_type, cpl_polynomial *poly_u, cpl_polynomial *poly_v)
 

xsh_generate_tanh_kernel

@memo Generate a hyperbolic tangent kernel.

Parameters
steepSteepness of the hyperbolic tangent parts.
Returns
1 pointer to a newly allocated array of doubles. @doc

The following function builds up a good approximation of a box filter. It is built from a product of hyperbolic tangents. It has the following properties:

\begin{itemize} \item It converges very quickly towards +/- 1. \item The converging transition is very sharp. \item It is infinitely differentiable everywhere (i.e. smooth). \item The transition sharpness is scalable. \end{itemize}

The returned array must be deallocated using cpl_free().

#define KERNEL_SW(a, b)   tempr=(a);(a)=(b);(b)=tempr
 
double * xsh_generate_tanh_kernel (double steep)
 

xsh_image_stats_on_rectangle()

computes the mean and standard deviation of a given rectangle on an image by leaving the extreme intensity values.

Parameters
imflatfield image to search for bad pix
loRejectpercentage (0...100) of extrem values that should not be considere
hiRejectpercentage (0...100) of extrem values that should not be considered
llxlower left pixel position of rectangle
llylower left pixel position of rectangle
urxupper right pixel position of rectangle
uryupper right pixel position of rectangle
Returns
data structure giving the mean and standard deviation
#define PIX_SWAP(a, b)   { pixelvalue temp=(a);(a)=(b);(b)=temp; }
 
#define PIX_STACK_SIZE   50
 
static Statsxsh_image_stats_on_rectangle (cpl_image *im, float loReject, float hiReject, int llx, int lly, int urx, int ury)
 

Macro Definition Documentation

◆ FLAG

#define FLAG   -1.e+9

Definition at line 39 of file xsh_utils_image.c.

◆ hk_gen

#define hk_gen (   x,
  s 
)    (((tanh(s*(x+0.5))+1)/2)*((tanh(s*(-x+0.5))+1)/2))

Definition at line 485 of file xsh_utils_image.c.

◆ KERNEL_SW

#define KERNEL_SW (   a,
 
)    tempr=(a);(a)=(b);(b)=tempr

Definition at line 559 of file xsh_utils_image.c.

◆ PIX_STACK_SIZE

#define PIX_STACK_SIZE   50

Definition at line 1725 of file xsh_utils_image.c.

◆ PIX_SWAP

#define PIX_SWAP (   a,
 
)    { pixelvalue temp=(a);(a)=(b);(b)=temp; }

Definition at line 1724 of file xsh_utils_image.c.

Function Documentation

◆ reverse_tanh_kernel()

static void reverse_tanh_kernel ( double *  data,
int  nn 
)
static

Definition at line 575 of file xsh_utils_image.c.

References KERNEL_SW, m, M_PI, and n.

Referenced by xsh_generate_tanh_kernel().

◆ xsh_clean_mean()

float xsh_clean_mean ( float *  array,
int  n_elements,
float  throwaway_low,
float  throwaway_high 
)
static

Definition at line 1825 of file xsh_utils_image.c.

References FLAG, n, xsh_msg_error, and xsh_pixel_qsort().

Referenced by xsh_image_stats_on_rectangle().

◆ xsh_collapse_errs()

cpl_error_code xsh_collapse_errs ( cpl_image *  errs,
cpl_imagelist *  list,
const int  mode 
)

Create an error image from an image list and a "valid pixels" mask

Parameters
errs[OUTPUT] The errs image result
listerror images list to collapse
modemode qualifier (median or mean stack combination)
Returns
Pointer to error image

Definition at line 3540 of file xsh_utils_image.c.

References assure, check, M_PI, mode, nx, and ny.

Referenced by xsh_create_master_bias2(), xsh_create_master_dark2(), xsh_find_cosmics(), and xsh_remove_cosmics().

◆ xsh_combine_flats()

cpl_image * xsh_combine_flats ( cpl_image *  ima1_in,
cpl_image *  ima2_in,
xsh_order_list qth_list,
xsh_order_list d2_list,
const int  xrad,
const int  yrad 
)

Combine flat frames line adjusting illumination level to merge them smoothly.

Parameters
frm11st frame
frm22nd frame
otaborder table
oreforder where to merge
xradx-radius size
xrady-radius size
Returns
CPL_ERROR_NONE if everything is ok

@doc

Definition at line 3623 of file xsh_utils_image.c.

References xsh_order_list::absorder_max, xsh_order_list::absorder_min, assure, xsh_order::cenpoly, xsh_order::edglopoly, xsh_order::edguppoly, xsh_order::endy, xsh_order_list::list, llx, lly, xsh_order_list::size, xsh_order::starty, urx, ury, xsh_free_image(), xsh_free_polynomial(), xsh_free_propertylist(), xsh_free_table(), xsh_msg, and xsh_order_list_eval_int().

Referenced by xsh_flat_merge_qth_d2_smooth().

◆ xsh_compute_geom_corr()

static cpl_error_code xsh_compute_geom_corr ( const double  dxdu,
const double  dydv,
const double  dxdv,
const double  dydu,
const double  du,
const double  dv,
double *  dA 
)
static

Pixel area geometric trasformation computation.

Parameters
dxdurelative derivative dx/du
dydvrelative derivative dy/dv
dxdvrelative derivative dx/dv
dydurelative derivative dy/du
duincremental du
dvincremental dv
dAresulting pixel area change
Returns
cpl_error_code @doc http://wwwatnf.atnf.csiro.au/computing/software/midas/Hypertext/doc/95NOV/vol2/node19.html

Definition at line 109 of file xsh_utils_image.c.

Referenced by xsh_image_compute_geom_corr().

◆ xsh_compute_ron()

cpl_error_code xsh_compute_ron ( cpl_frameset *  frames,
int  llx,
int  lly,
int  urx,
int  ury,
int  nsampl,
int  hsize,
const int  reg_id,
double *  ron,
double *  ron_err 
)

compute ron taking random windows of given size in a given region on 2 frames difference

Parameters
framesinput frameset
llximage lower left x
llyimage lower left y
urximage upper left x
uryimage upper left y
nsamplnumber of sampling window
hsizehal size of (square) window
reg_idparameter switch
ronoutput ron value
ron_erroutput error on ron value

Definition at line 1294 of file xsh_utils_image.c.

References check, llx, lly, urx, ury, xsh_error_msg, xsh_free_image(), xsh_free_propertylist(), XSH_PCATG, xsh_pfits_set_qc_ron1(), xsh_pfits_set_qc_ron1_err(), xsh_pfits_set_qc_ron2(), and xsh_pfits_set_qc_ron2_err().

Referenced by xsh_util_ronbias().

◆ xsh_compute_scale()

cpl_image * xsh_compute_scale ( cpl_imagelist *  iml_data,
cpl_mask *  bpm,
const int  mode,
const int  win_hsz 
)

Definition at line 4278 of file xsh_utils_image.c.

References mode, n, x, and y.

◆ xsh_compute_scale_tab()

cpl_image * xsh_compute_scale_tab ( cpl_imagelist *  iml_data,
cpl_mask *  bpm,
cpl_table *  tab_bpm,
const int  mode,
const int  win_hsz 
)

Definition at line 4532 of file xsh_utils_image.c.

References m, mode, n, size, x, xsh_msg, and y.

◆ xsh_compute_scale_tab2()

cpl_image * xsh_compute_scale_tab2 ( cpl_imagelist *  iml_data,
cpl_imagelist *  iml_qual,
cpl_mask *  bpm,
cpl_table *  tab_bpm,
const int  mode,
const int  win_hsz,
const int  decode_bp 
)

Definition at line 4790 of file xsh_utils_image.c.

References m, mode, n, size, x, xsh_msg, and y.

◆ xsh_compute_scale_tab3()

cpl_image * xsh_compute_scale_tab3 ( cpl_imagelist *  iml_data,
cpl_imagelist *  iml_qual,
cpl_mask *  bpm,
cpl_table *  tab_bpm,
const int  mode,
const int  win_hsz,
const int  decode_bp 
)

Definition at line 5079 of file xsh_utils_image.c.

References m, mode, n, size, x, xsh_msg, and y.

◆ xsh_cube_qc_trace_window()

cpl_frame * xsh_cube_qc_trace_window ( cpl_frame *  frm_cube,
xsh_instrument instrument,
const char *  suffix,
const char *  rec_prefix,
const int  win_min,
const int  win_max,
const int  hsize,
const int  method,
const int  compute_qc 
)

Trace object position in a cube.

Parameters
frm_cubeThe frame whose frame need to be updated
instrumentThe instrument setting structure
suffixThe product filename suffix
rec_prefixThe input recipe prefix string value
win_minThe win_min value allowed in the search
win_maxThe win_max value allowed in the search
hsizeThe half window size used in the object peack final search
methodThe peack search method 0: Gaussian, 1: centroid
compute_qcSwitch to activate QC computation
Returns
The error code

Definition at line 3109 of file xsh_utils_image.c.

References check, instrument, llx, method, urx, xsh_cube_trace_diff(), xsh_cube_trace_fit(), xsh_frame_product(), xsh_free_imagelist(), xsh_free_propertylist(), xsh_free_table(), xsh_image_fit_gaussian_max_pos_x_window(), xsh_instrument_arm_tostring(), xsh_pfits_get_cdelt3(), xsh_pfits_get_crval3(), and xsh_util_compute_qc_residuals().

Referenced by xsh_build_ifu_cube(), xsh_geom_ifu(), xsh_scired_ifu_offset(), xsh_scired_ifu_stare(), and xsh_util_ifu_build_cube().

◆ xsh_cube_trace_diff()

static cpl_error_code xsh_cube_trace_diff ( const cpl_table *  table,
const char *  col_comp,
const char *  col_ref,
cpl_propertylist *  plist 
)
static

Computes differences between cube fit trace coefficients.

Parameters
tableThe table object with columns to fit
col_compThe table comparison's column
col_refThe table reference's column
plistThe FITS header to hold results
Returns
The error code

Definition at line 3008 of file xsh_utils_image.c.

References check, XSH_QC_TRACE_FIT_C0, XSH_QC_TRACE_FIT_C1, XSH_QC_TRACE_FIT_C2, XSH_QC_TRACE_FIT_DIFF_C0, XSH_QC_TRACE_FIT_DIFF_C1, and XSH_QC_TRACE_FIT_DIFF_POS.

Referenced by xsh_cube_qc_trace_window().

◆ xsh_cube_trace_fit()

static cpl_error_code xsh_cube_trace_fit ( cpl_table **  table,
const char *  col_wav,
const char *  col_ref,
const char *  col_fit,
const char *  qualifier,
cpl_propertylist *  plist 
)
static

Fit cube traces and compute fit coeffs differences.

Parameters
tableThe table object with columns to fit
col_wavThe column indicating the fit independent variable
col_refThe column indicating the fit dependent variable
col_fitThe column indicating the fit result
qualifierA string indicating which trace the fit refers to
plistThe FITS header to hold results
Returns
The error code

Definition at line 2923 of file xsh_utils_image.c.

References check, order, xsh_free_polynomial(), xsh_polynomial_fit_1d_create(), XSH_QC_TRACE_FIT_C0, XSH_QC_TRACE_FIT_C1, and XSH_QC_TRACE_FIT_C2.

Referenced by xsh_cube_qc_trace_window().

◆ xsh_fixed_pattern_noise()

double xsh_fixed_pattern_noise ( const cpl_image *  master,
double  convert_ADU,
double  master_noise 
)

Compute fixed pattern noise in flat field.

Parameters
mastermaster image
convert_ADUfactor to convert from master units to ADU
master_noisemaster noise (ADU) for a shift of zero
Returns
fixed pattern noise. The master noise is quadratically subtracted

Definition at line 765 of file xsh_utils_image.c.

References assure, xsh_free_image(), and xsh_image_crop().

◆ xsh_fixed_pattern_noise_bias()

double xsh_fixed_pattern_noise_bias ( const cpl_image *  first_raw,
const cpl_image *  second_raw,
double  ron 
)

Compute fixed pattern noise in bias.

Parameters
first_rawFirst raw bias frame
second_rawSecond raw bias frame
ronRead out noise (ADU) for a shift of zero
Returns
fixed pattern noise. The ron is quadratically subtracted

Definition at line 845 of file xsh_utils_image.c.

References assure, nx, ny, xsh_free_image(), xsh_image_crop(), and xsh_image_get_stdev_robust().

◆ xsh_frame_image_add_double()

cpl_error_code xsh_frame_image_add_double ( cpl_frame *  frm,
const double  value 
)

◆ xsh_frame_image_div_by_fct()

cpl_frame * xsh_frame_image_div_by_fct ( cpl_frame *  frm,
const int  fctx,
const int  fcty 
)

◆ xsh_frame_image_ext_qc_trace_window()

cpl_frame * xsh_frame_image_ext_qc_trace_window ( cpl_frame *  frm_ima,
xsh_instrument instrument,
const char *  suffix,
const int  hsize,
const int  method 
)

Trace object position in an image.

Parameters
frm_imaThe image frame where object traces need to be found
instrumentThe instrument setting structure
suffixThe product filename suffix
hsizeThe half window size used in the object peack final search
methodThe peack search method 0: Gaussian, 1: centroid
Returns
The error code

Definition at line 2732 of file xsh_utils_image.c.

References check, instrument, method, xsh_frame_product(), xsh_free_image(), xsh_free_propertylist(), xsh_free_table(), xsh_image_qc_trace_window(), xsh_instrument_arm_tostring(), and xsh_msg.

Referenced by xsh_absorp().

◆ xsh_frame_image_mult_by_fct()

cpl_frame * xsh_frame_image_mult_by_fct ( cpl_frame *  frm,
const int  fctx,
const int  fcty 
)

◆ xsh_frame_image_qc_trace_window()

cpl_frame * xsh_frame_image_qc_trace_window ( cpl_frame *  frm_ima,
xsh_instrument instrument,
const char *  suffix,
const int  hsize,
const int  method 
)

Trace object position in an image.

Parameters
frm_imaThe image frame where object traces need need to be found
instrumentThe instrument setting structure
suffixThe product filename suffix
hsizeThe half window size used in the object peack final search
methodThe peack search method 0: Gaussian, 1: centroid
Returns
The error code

Definition at line 2672 of file xsh_utils_image.c.

References check, instrument, method, xsh_frame_product(), xsh_free_image(), xsh_free_propertylist(), xsh_free_table(), xsh_image_qc_trace_window(), and xsh_instrument_arm_tostring().

Referenced by xsh_absorp().

◆ xsh_frame_image_save2ext()

cpl_error_code xsh_frame_image_save2ext ( cpl_frame *  frm,
const char *  name_o,
const int  ext_i,
const int  ext_o 
)

◆ xsh_gen_lowpass()

static cpl_image * xsh_gen_lowpass ( const int  xs,
const int  ys,
const double  sigma_x,
const double  sigma_y 
)
static

Generate a low pass filter for FFT convolution .

Parameters
xsx size of the generated image.
ysy size of the generated image.
sigma_xSigma for the gaussian distribution.
sigma_ySigma for the gaussian distribution.
Returns
1 newly allocated image.

This function generates an image of a 2d gaussian, modified in such a way that the different quadrants have a quadrants of the gaussian in the corner. This image is suitable for FFT convolution. Copied from eclipse, src/iproc/generate.c

The returned image must be deallocated.

Definition at line 1973 of file xsh_utils_image.c.

References x, xsh_msg_error, and y.

Referenced by xsh_image_smooth_fft().

◆ xsh_generate_interpolation_kernel()

double * xsh_generate_interpolation_kernel ( const char *  kernel_type)

◆ xsh_generate_tanh_kernel()

double * xsh_generate_tanh_kernel ( double  steep)

◆ xsh_image_clean_badpixel()

cpl_error_code xsh_image_clean_badpixel ( cpl_frame *  in)

◆ xsh_image_compute_geom_corr()

cpl_image * xsh_image_compute_geom_corr ( cpl_image *  in)

Pixel area geometric trasformation computation.

Parameters
ininput image
Returns
image containing in each pixel the geometric correction values @doc http://wwwatnf.atnf.csiro.au/computing/software/midas/Hypertext/doc/95NOV/vol2/node19.html

Definition at line 134 of file xsh_utils_image.c.

References assure, check, xsh_compute_geom_corr(), and xsh_free_image().

◆ xsh_image_crop()

static cpl_image * xsh_image_crop ( const cpl_image *  image,
int  xlo,
int  ylo,
int  xhi,
int  yhi 
)
static

Crop image.

Parameters
imageimage
xlolower left x
ylolower left y
xhiupper right x
yhiupper right y
Returns
cropped image This function does a locale image extraction, that is the parts outside the rectangular region (xlo, ylo) - (xhi, yhi) are removed.

Coordinates are inclusive, counting from 1

Definition at line 920 of file xsh_utils_image.c.

References assure, and check.

Referenced by xsh_fixed_pattern_noise(), and xsh_fixed_pattern_noise_bias().

◆ xsh_image_cut_dichroic_uvb()

cpl_error_code xsh_image_cut_dichroic_uvb ( cpl_frame *  frame1d)

◆ xsh_image_div_by_fct()

static cpl_image * xsh_image_div_by_fct ( const cpl_image *  ima_dat,
const int  fctx,
const int  fcty 
)
static

Definition at line 3921 of file xsh_utils_image.c.

References check, m, nx, ny, and xsh_msg.

Referenced by xsh_frame_image_div_by_fct().

◆ xsh_image_fit_gaussian_max_pos_x_window()

double xsh_image_fit_gaussian_max_pos_x_window ( const cpl_image *  ima,
const int  llx,
const int  urx,
const int  ypos 
)

◆ xsh_image_fit_gaussian_max_pos_y_window()

static double xsh_image_fit_gaussian_max_pos_y_window ( const cpl_image *  ima,
const int  lly,
const int  ury,
const int  xpos 
)
static

◆ xsh_image_get_stdev_clean()

double xsh_image_get_stdev_clean ( const cpl_image *  image,
double *  dstdev 
)

Get clean (3*sigma clip) empirical stdev of data.

Parameters
imageimage
dstdev(output) error of estimate
Returns
empirical stdev (scatter around median, not mean)

Definition at line 718 of file xsh_utils_image.c.

References assure, kappa, xsh_free_image(), and xsh_free_mask().

◆ xsh_image_get_stdev_robust()

double xsh_image_get_stdev_robust ( const cpl_image *  image,
double  cut,
double *  dstdev 
)

Get robust empirical stdev of data.

Parameters
imageimage
cutpixels outside median +- cut are ignored
dstdev(output) error of estimate
Returns
empirical stdev (scatter around median, not mean)

Definition at line 678 of file xsh_utils_image.c.

References assure, xsh_free_image(), and xsh_free_mask().

Referenced by xsh_fixed_pattern_noise_bias().

◆ xsh_image_mflat_detect_blemishes()

cpl_error_code xsh_image_mflat_detect_blemishes ( cpl_frame *  flat_frame,
xsh_instrument instrument 
)

Flag blemishes in a flat image.

Parameters
flat_frameinput image
instrumentarm setting
Returns
output frame or NULL;

Definition at line 3429 of file xsh_utils_image.c.

References binx, xsh_pre::binx, biny, xsh_pre::biny, check, xsh_pre::data, xsh_pre::errs, instrument, kappa, xsh_pre::nx, xsh_pre::ny, QFLAG_OTHER_BAD_PIXEL, xsh_pre::qual, XSH_ASSURE_NOT_NULL_MSG, xsh_free_array(), xsh_free_frame(), xsh_free_image(), xsh_free_matrix(), xsh_image_filter_median(), xsh_pre_free(), xsh_pre_load(), and xsh_pre_save().

Referenced by xsh_mflat().

◆ xsh_image_mult_by_fct()

static cpl_image * xsh_image_mult_by_fct ( const cpl_image *  ima_dat,
const int  fctx,
const int  fcty 
)
static

Definition at line 3977 of file xsh_utils_image.c.

References check, m, nx, ny, and xsh_msg.

Referenced by xsh_frame_image_mult_by_fct().

◆ xsh_image_qc_trace_window()

static cpl_table * xsh_image_qc_trace_window ( cpl_image *  data_ima,
cpl_propertylist *  head,
const int  hsize,
const int  method 
)
static

Trace object position in an image.

Parameters
data_imaThe image where object traces need need to be found
headThe FITS header where to write QC
hsizeThe half window size used in the object peack final search
methodThe peack search method 0: Gaussian, 1: centroid
Returns
The error code

Definition at line 2592 of file xsh_utils_image.c.

References check, llx, lly, method, ury, xsh_image_fit_gaussian_max_pos_y_window(), xsh_pfits_get_cdelt1(), and xsh_pfits_get_crval1().

Referenced by xsh_frame_image_ext_qc_trace_window(), and xsh_frame_image_qc_trace_window().

◆ xsh_image_search_bad_pixels_via_noise()

cpl_image * xsh_image_search_bad_pixels_via_noise ( cpl_imagelist *  darks,
float  thresh_sigma_factor,
float  low_threshold,
float  high_threshold,
int  llx,
int  lly,
int  urx,
int  ury 
)

search bad pixels

Parameters
darkssequence of darks (NDIT = 1) stored in a cube, at least 10 to get good statistics
thresh_sigma_factorfactor to determined standard deviation in each pixel to determine the threshold beyond which a pixel is declared as bad.
low_thresholdpercentage (0...100) of extreme pixel values that is \ not considered for image statistics
high_thresholdpercentage (0...100) of extreme pixel values that is \ not considered for image statistics
llxlower left X corner pix
llyupper left Y corner pix
urxlower right X corner pix
uryupper right Y corner pix
Returns
Bad pixel mask image (1: good pixel, 0: bad pixel).

Job this routine searches for static bad pixel positions This is done by building a cube of xsh_dark frames and examine the noise variations in each pixel. If big deviations from a clean mean pixel noise occurr, the pixel is declared as bad.

Definition at line 1429 of file xsh_utils_image.c.

References _STATS_::cleanmean, _STATS_::cleanstdev, llx, lly, n, QFLAG_HOT_PIXEL, urx, ury, xsh_image_stats_on_rectangle(), xsh_msg_error, and xsh_pixel_qsort().

Referenced by xsh_get_master_dark_nir_via_noise().

◆ xsh_image_smooth_fft()

cpl_image * xsh_image_smooth_fft ( cpl_image *  inp,
const int  fx,
const int  fy 
)

Definition at line 1896 of file xsh_utils_image.c.

References check, cknull_msg, filter, xsh_free_image(), and xsh_gen_lowpass().

◆ xsh_image_smooth_mean_x()

cpl_image * xsh_image_smooth_mean_x ( cpl_image *  inp,
const int  r 
)

Definition at line 2183 of file xsh_utils_image.c.

References check, and XSH_ASSURE_NOT_NULL.

◆ xsh_image_smooth_mean_y()

cpl_image * xsh_image_smooth_mean_y ( cpl_image *  inp,
const int  r 
)

Definition at line 2073 of file xsh_utils_image.c.

References check, XSH_ASSURE_NOT_NULL, and xsh_free_image().

◆ xsh_image_smooth_median_x()

cpl_image * xsh_image_smooth_median_x ( cpl_image *  inp,
const int  r 
)

Definition at line 2241 of file xsh_utils_image.c.

References check, and cknull_msg.

◆ xsh_image_smooth_median_xy()

cpl_image * xsh_image_smooth_median_xy ( cpl_image *  inp,
const int  r 
)

Definition at line 2304 of file xsh_utils_image.c.

References check, and cknull_msg.

◆ xsh_image_smooth_median_y()

cpl_image * xsh_image_smooth_median_y ( cpl_image *  inp,
const int  r 
)

Definition at line 2128 of file xsh_utils_image.c.

References check, and cknull_msg.

◆ xsh_image_stats_on_rectangle()

Stats * xsh_image_stats_on_rectangle ( cpl_image *  im,
float  loReject,
float  hiReject,
int  llx,
int  lly,
int  urx,
int  ury 
)
static

◆ xsh_image_warp_polynomial_scale()

cpl_error_code xsh_image_warp_polynomial_scale ( cpl_image *  out,
const cpl_polynomial *  poly_x,
const cpl_polynomial *  poly_y 
)

Compute area change ratio for a 2D polynomial transformation.

Parameters
outPre-allocated image to hold the result
poly_xDefines source x-pos corresponding to destination (u,v).
poly_yDefines source y-pos corresponding to destination (u,v).
Returns
CPL_ERROR_NONE or the relevant #_cpl_error_code_ on error
See also
cpl_image_warp_polynomial()

Given a polynomial transformation from (x, y) to (u, v) coordinate systems, such as the one used in cpl_image_warp_polynomial() to "warp" (or "map") an image onto another, this function creates an image reporting for each pixel the scaling ratio between the unitary area in the system (u, v) and the same area before mapping, in the system (x, y).

This is trivially obtained by computing the absolute value of the determinant of the Jacobian of the transformation for each pixel of the image out.

Typically this function would be used to determine a flux-conservation correction map for the target image specified in function cpl_image_warp_polynomial(). For example,

* cpl_image_warp_polynomial(out, in, poly_x, poly_y, xprof, xrad, yprof, yrad);
* correction_map = cpl_image_new(cpl_image_get_size_x(out),
*                                cpl_image_get_size_y(out),
*                                cpl_image_get_type(out));
* cpl_image_warp_polynomial_scale(correction_map, poly_x, poly_y);
* out_flux_corrected = cpl_image_multiply_create(out, correction_map);
* 

where out_flux_corrected is the resampled image out after correction for flux conservation.

Note
The scale map produced by this function is not applicable for flux conservation in case the transformation implies severe undersampling of the original signal.

Possible #_cpl_error_code_ set in this function:

  • CPL_ERROR_NULL_INPUT if (one of) the input pointer(s) is NULL
  • CPL_ERROR_ILLEGAL_INPUT if the polynomial dimensions are not 2
  • CPL_ERROR_INVALID_TYPE if the passed image type is not supported

Definition at line 1012 of file xsh_utils_image.c.

References nx, and ny.

◆ xsh_iml_merge_avg()

cpl_error_code xsh_iml_merge_avg ( cpl_imagelist **  data,
cpl_imagelist **  mask,
const cpl_image *  data_ima,
const cpl_image *  mask_ima,
const int  mk 
)

merge imagelist via average

Parameters
[in]dataimagelist
[in]maskcorresponding mask
[out]data_imaaverage image
[out]mask_imacorresponding mask
[in]mkindex

Definition at line 3285 of file xsh_utils_image.c.

References check, and size.

Referenced by xsh_util_ifu_build_cube().

◆ xsh_iml_merge_wgt()

cpl_error_code xsh_iml_merge_wgt ( cpl_imagelist **  data,
cpl_imagelist **  errs,
cpl_imagelist **  qual,
const cpl_image *  flux_b,
const cpl_image *  errs_b,
const cpl_image *  qual_b,
const int  mk,
const int  decode_bp 
)

merge imagelist via average

Parameters
[in]dataimagelist
[in]maskcorresponding mask
[out]data_imaaverage image
[out]mask_imacorresponding mask
[in]mkindex

Definition at line 3333 of file xsh_utils_image.c.

References check, size, xsh_badpixelmap_image_coadd(), and xsh_free_image().

Referenced by xsh_build_ifu_cube().

◆ xsh_key_bin_div_by_fct()

static cpl_error_code xsh_key_bin_div_by_fct ( cpl_propertylist **  plist,
const char *  kname,
const int  fct 
)
static

Definition at line 3880 of file xsh_utils_image.c.

References check, and xsh_get_property_value().

Referenced by xsh_plist_mult_by_fct().

◆ xsh_key_scan_mult_by_fct()

static cpl_error_code xsh_key_scan_mult_by_fct ( cpl_propertylist **  plist,
const char *  kname,
const int  fct 
)
static

Definition at line 3860 of file xsh_utils_image.c.

References check, and xsh_get_property_value().

Referenced by xsh_plist_mult_by_fct().

◆ xsh_pixel_qsort()

void xsh_pixel_qsort ( pixelvalue pix_arr,
int  npix 
)

Definition at line 1739 of file xsh_utils_image.c.

References PIX_STACK_SIZE, PIX_SWAP, and xsh_msg_error.

Referenced by xsh_clean_mean(), and xsh_image_search_bad_pixels_via_noise().

◆ xsh_plist_mult_by_fct()

static cpl_error_code xsh_plist_mult_by_fct ( cpl_propertylist **  plist,
const int  fctx,
const int  fcty 
)
static

◆ xsh_qual2tab()

cpl_table * xsh_qual2tab ( cpl_image *  qual,
const int  code 
)

Definition at line 5370 of file xsh_utils_image.c.

References size.

Referenced by xsh_correct_scale(), xsh_correct_scale_w(), and xsh_rec_list_add().

◆ xsh_scharr_x()

cpl_image * xsh_scharr_x ( cpl_image *  in)

Compute X Scharr filter transformation.

Parameters
ininput image
Returns
X scarr filter image
http://en.wikipedia.org/wiki/Sobel_operator

Definition at line 1131 of file xsh_utils_image.c.

References check.

Referenced by xsh_compute_flat_edges().

◆ xsh_scharr_y()

cpl_image * xsh_scharr_y ( cpl_image *  in)

Compute Y Scharr filter transformation.

Parameters
ininput image
Returns
Y scharr filter image
http://en.wikipedia.org/wiki/Sobel_operator

Definition at line 1170 of file xsh_utils_image.c.

References check.

◆ xsh_show_interpolation_kernel()

void xsh_show_interpolation_kernel ( char *  kernel_name)

Definition at line 649 of file xsh_utils_image.c.

References KERNEL_SAMPLES, TABSPERPIX, x, and xsh_generate_interpolation_kernel().

◆ xsh_sinc()

static double xsh_sinc ( double  x)
static

Definition at line 295 of file xsh_utils_image.c.

References M_PI, and x.

Referenced by xsh_generate_interpolation_kernel().

◆ xsh_sobel_lx()

cpl_image * xsh_sobel_lx ( cpl_image *  in)

Compute X Sobel filter transformation.

Parameters
ininput image
Returns
X scharr filter image
http://en.wikipedia.org/wiki/Sobel_operator

Definition at line 1208 of file xsh_utils_image.c.

References check.

Referenced by xsh_compute_flat_edges().

◆ xsh_sobel_ly()

cpl_image * xsh_sobel_ly ( cpl_image *  in)

Compute Y Sobel filter transformation.

Parameters
ininput image
Returns
Y scharr filter image
http://en.wikipedia.org/wiki/Sobel_operator

Definition at line 1248 of file xsh_utils_image.c.

References check.

◆ xsh_util_compute_qc_residuals()

static cpl_error_code xsh_util_compute_qc_residuals ( cpl_table *  table,
xsh_instrument instrument,
cpl_propertylist *  plist 
)
static

Computes residuals statistics on given wave ranges.

Parameters
tableThe table object to compute residuals on column differences
instrumentThe instrument setting structure
plistThe FITS header to hold results
Returns
The error code

Definition at line 2810 of file xsh_utils_image.c.

References check, instrument, qc_table, XSH_ARM_UVB, XSH_ARM_VIS, xsh_free_table(), xsh_instrument_get_arm(), XSH_QC_TRACE12_AVG, XSH_QC_TRACE12_MAX, XSH_QC_TRACE12_MED, XSH_QC_TRACE12_MIN, XSH_QC_TRACE12_RMS, XSH_QC_TRACE13_AVG, XSH_QC_TRACE13_MAX, XSH_QC_TRACE13_MED, XSH_QC_TRACE13_MIN, XSH_QC_TRACE13_RMS, XSH_QC_TRACE32_AVG, XSH_QC_TRACE32_MAX, XSH_QC_TRACE32_MED, XSH_QC_TRACE32_MIN, and XSH_QC_TRACE32_RMS.

Referenced by xsh_cube_qc_trace_window().

◆ xsh_warp_image_generic()

cpl_image * xsh_warp_image_generic ( cpl_image *  image_in,
char *  kernel_type,
cpl_polynomial *  poly_u,
cpl_polynomial *  poly_v 
)

Definition at line 344 of file xsh_utils_image.c.

References TABSPERPIX, x, xsh_generate_interpolation_kernel(), xsh_msg_error, and y.

Referenced by main().