MOONS Pipeline Reference Manual 0.13.2
Functions
Miscellaneous Utilities

Functions

const char * moo_get_license (void)
 Get the pipeline copyright and license.
 
cpl_image * moo_compute_sigma_map (cpl_imagelist *list, cpl_imagelist *qlist, cpl_image *img)
 Compute image of sigma variation.
 
cpl_mask * moo_kappa_sigma_clipping (cpl_image *sigma_img, int niter, double kappa, double cdiff, double maxfrac)
 Compute mask of rejected pixels using kappa sigma algorithm.
 
cpl_error_code moo_barycenter_fit (cpl_bivector *points, double *center, double *width)
 Fit positions using weighted fluxes.
 
cpl_error_code moo_gaussian_fit (cpl_bivector *points, cpl_fit_mode fit_pars, double *center, double *width, double *background, double *area)
 Fit the data with a gaussian.
 
double moo_gaussian_eval (double x, double x0, double sigma, double offset, double area)
 Evaluate the gaussian at the given x position.
 
cpl_error_code moo_gaussian_eval_inv (double y, double x0, double sigma, double offset, double area, double *x1, double *x2)
 Find the x positions of the gaussian at the given y position.
 
cpl_error_code moo_find_threshold_limits (cpl_bivector *points, double threshold, double *xmin, double *xmax)
 Find threshold limits of a 1D signal.
 
moo_tcheby_polynomial * moo_tcheby_polynomial_fit (cpl_bivector *data, int degree, double xmin, double xmax)
 Computes Tchebitchev transformation of data.
 
moo_tcheby2d_polynomial * moo_tcheby2d_polynomial_fit (cpl_vector *in_x, int xdegree, double xmin, double xmax, cpl_vector *in_y, int ydegree, double ymin, double ymax, cpl_vector *in_l, double lmin, double lmax)
 Computes Tchebitchev transformation of data.
 
cpl_error_code moo_tchebychev_fit (cpl_bivector *data, int *flag, int degree, double xmin, double xmax, double ymin, double ymax)
 Computes Tchebitchev transformation of data.
 
double moo_vector_get_min (const cpl_vector *v, int *flags)
 Find minimum values in a vector using flags.
 
double moo_vector_get_max (const cpl_vector *v, int *flags)
 Find maximum values in a vector using flags.
 
cpl_error_code moo_interpolate_linear (cpl_bivector *fout, cpl_vector *fout_errs, int *fout_qual, const cpl_bivector *fref, const cpl_vector *fref_errs, const int *fref_qual)
 Linear interpolation of a 1d-function.
 
double moo_vector_get_percentile (cpl_vector *v, double f)
 Get percentile of input vector.
 
cpl_vector * moo_vector_filter_nan (cpl_vector *v)
 Create new vector with nan values filter.
 
cpl_bivector * moo_bivector_filter_nan (cpl_bivector *v)
 Create new bi vector with nan values filter.
 
hdrl_image * moo_image_collapse_median_create (hdrl_image *image)
 Collapse row of an image using a median and compute associate error.
 
double moo_sky_distance (double alpha1, double delta1, double alpha2, double delta2)
 Compute sky distance (in rad)
 
cpl_error_code moo_fit_mul (const cpl_vector *vx, const cpl_vector *vw, const cpl_vector *vy, const cpl_vector *vy_err, double *c, double *sig_c)
 This function computes the best-fit linear regression coefficient c1 of the model Y = c_1 X for the weighted datasets (x, y)
 
cpl_vector * moo_savgol_filter (cpl_vector *v, int window_length, int polyorder)
 Apply a Savitzky-Golay filter to a vector.
 
cpl_vector * moo_median_filter (cpl_vector *v, int winhsize)
 Apply a median filter to a vector.
 
cpl_image * moo_imagelist_collapse_bitwiseor (cpl_imagelist *list, hdrl_imagelist *datalist)
 get the QUAL resulting in a bitwise OR operation on the QUAL list
 
double moo_image_get_ron (cpl_image *diff, int llx, int lly, int urx, int ury, int nb_boxes, int box_hsize, double max_error_frac, int max_niter)
 compute ron in a diff image using boxes
 
cpl_error_code moo_image_get_quartile (cpl_image *image, double *qmin, double *qmax)
 compute first and last quartile from an image
 
double moo_vector_get_dersnr (const cpl_vector *ve)
 This function computes the signal to noise ratio DER_SNR following the definition set forth by the Spectral Container Working Group of ST-ECF, MAST and CADC.
 
int moo_string_is_strictly_equal (const char *a, const char *b)
 This function compares to string to see if the two string are stricly equal.
 
cpl_size moo_table_or_selected_sequal_string (cpl_table *table, const char *name, const char *string)
 Select from unselected table rows, by comparing column values with a constant.
 
cpl_size moo_table_and_selected_sequal_string (cpl_table *table, const char *name, const char *string)
 Select from unselected table rows, by comparing column values with a constant.
 

Detailed Description

Function Documentation

◆ moo_barycenter_fit()

cpl_error_code moo_barycenter_fit ( cpl_bivector *  points,
double *  center,
double *  width 
)

Fit positions using weighted fluxes.

Parameters
pointsto fit (ordered ASC)
centerthe fitted center
widththe width
Returns
the error code or CPL_ERROR_NONE

Possible cpl_error_code set in this function:

  • CPL_ERROR_NULL_INPUT if an input pointer is NULL
  • CPL_ERROR_ILLEGAL_INPUT if the size is equal to zero

Definition at line 254 of file moo_utils.c.

◆ moo_bivector_filter_nan()

cpl_bivector * moo_bivector_filter_nan ( cpl_bivector *  v)

Create new bi vector with nan values filter.

Parameters
vinput bivector
Returns
new vector with no nan values

Definition at line 1343 of file moo_utils.c.

◆ moo_compute_sigma_map()

cpl_image * moo_compute_sigma_map ( cpl_imagelist *  list,
cpl_imagelist *  qlist,
cpl_image *  img 
)

Compute image of sigma variation.

Parameters
listlist of images to compare to reference image
qlistlist of QUAL images to ignore badpixel in computation og sigma
imgreference image
Returns
the sigma map or NULL

Possible cpl_error_code set in this function:

  • CPL_ERROR_NULL_INPUT if an input pointer is NULL
  • CPL_ERROR_ILLEGAL_INPUT if the size is equal to zero

Definition at line 100 of file moo_utils.c.

References MOO_BADPIX_GOOD.

Referenced by moo_single_compute_noise_map().

◆ moo_find_threshold_limits()

cpl_error_code moo_find_threshold_limits ( cpl_bivector *  points,
double  threshold,
double *  xmin,
double *  xmax 
)

Find threshold limits of a 1D signal.

Parameters
pointsdata to analyse
thresholdthe threshold
xmin[OUT] minimum X position of the threshold
xmax[OUT] maximum X position of the threshold
Returns
CPL_ERROR_NONE or the relevant cpl_error_code on error

Definition at line 423 of file moo_utils.c.

◆ moo_fit_mul()

cpl_error_code moo_fit_mul ( const cpl_vector *  vx,
const cpl_vector *  vw,
const cpl_vector *  vy,
const cpl_vector *  vy_err,
double *  c,
double *  sig_c 
)

This function computes the best-fit linear regression coefficient c1 of the model Y = c_1 X for the weighted datasets (x, y)

Parameters
vx
vw
vy
vy_err
cfit result
sig_cerror on fit
Returns
cpl_error_code

Definition at line 1567 of file moo_utils.c.

◆ moo_gaussian_eval()

double moo_gaussian_eval ( double  x,
double  x0,
double  sigma,
double  offset,
double  area 
)

Evaluate the gaussian at the given x position.

Parameters
xx position
x0center of gaussian.
sigmawidth of gaussian
offsetbackground level of gaussian
areaarea of gaussian
Returns
Y gaussian result for x

Definition at line 348 of file moo_utils.c.

◆ moo_gaussian_eval_inv()

cpl_error_code moo_gaussian_eval_inv ( double  y,
double  x0,
double  sigma,
double  offset,
double  area,
double *  x1,
double *  x2 
)

Find the x positions of the gaussian at the given y position.

Parameters
yy position
x0center of gaussian.
sigmawidth of gaussian
offsetbackground level of gaussian
areaarea of gaussian
x1[OUT] first x solution (minimum)
x2[OUT] second x solution (maximum)
Returns
CPL_ERROR_NONE

Definition at line 373 of file moo_utils.c.

◆ moo_gaussian_fit()

cpl_error_code moo_gaussian_fit ( cpl_bivector *  points,
cpl_fit_mode  fit_pars,
double *  center,
double *  width,
double *  background,
double *  area 
)

Fit the data with a gaussian.

Parameters
pointsthe data to fit
fit_parsspecifies which parameters participate in the fit (any other parameters will be held constant). Possible values are CPL_FIT_CENTROID, CPL_FIT_STDEV, CPL_FIT_AREA, CPL_FIT_OFFSET and any bitwise combination of these. As a shorthand for including all four parameters in the fit, use CPL_FIT_ALL.
center[OUT] center of the fitted gaussian
width[OUT] width of the fitted gaussian
background[OUT] background of the fitted gaussian
area[OUT] area of the fitted gaussian
Returns
CPL_ERROR_NONE or the relevant cpl_error_code on error

Definition at line 309 of file moo_utils.c.

◆ moo_get_license()

const char * moo_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 81 of file moo_utils.c.

◆ moo_image_collapse_median_create()

hdrl_image * moo_image_collapse_median_create ( hdrl_image *  image)

Collapse row of an image using a median and compute associate error.

Parameters
imageinput image
Returns
image of median

Definition at line 1386 of file moo_utils.c.

◆ moo_image_get_quartile()

cpl_error_code moo_image_get_quartile ( cpl_image *  image,
double *  qmin,
double *  qmax 
)

compute first and last quartile from an image

Parameters
imageinput image
qminthe first quartile
qmaxthe last quartile

Possible error code :

  • CPL_ERROR_NULL_INPUT if an input pointer is NULL or list size == 0

Definition at line 1906 of file moo_utils.c.

◆ moo_image_get_ron()

double moo_image_get_ron ( cpl_image *  diff,
int  llx,
int  lly,
int  urx,
int  ury,
int  nb_boxes,
int  box_hsize,
double  max_error_frac,
int  max_niter 
)

compute ron in a diff image using boxes

Parameters
diffinput diff image
llxlower left x coord
llylower left y coord
urxupper right x coord
uryupper right y coord
nb_boxesnumber of boxes
box_hsizehalf size of a box
max_error_fracmax error fraction on ron
max_nitermax number of iteration to find ron
Returns
the ron value

Possible error code :

  • CPL_ERROR_NULL_INPUT if an input pointer is NULL or list size == 0

Definition at line 1863 of file moo_utils.c.

◆ moo_imagelist_collapse_bitwiseor()

cpl_image * moo_imagelist_collapse_bitwiseor ( cpl_imagelist *  list,
hdrl_imagelist *  datalist 
)

get the QUAL resulting in a bitwise OR operation on the QUAL list

Parameters
listimage list
datalistthe image data list
Returns
the QUAL collapse with bitwise OR

Possible error code :

  • CPL_ERROR_NULL_INPUT if an input pointer is NULL or list size == 0

Definition at line 1791 of file moo_utils.c.

Referenced by moo_coadd().

◆ moo_interpolate_linear()

cpl_error_code moo_interpolate_linear ( cpl_bivector *  fout,
cpl_vector *  fout_errs,
int *  fout_qual,
const cpl_bivector *  fref,
const cpl_vector *  fref_errs,
const int *  fref_qual 
)

Linear interpolation of a 1d-function.

Parameters
foutPreallocated with X-vector set, to hold interpolation in Y
fout_errsPreallocated to hold interpolation in Y errs
fout_qualPreallocated to hold interpolation in Y qual
frefReference 1d-function
fref_errsReference 1d-function errs
fref_qualReference 1d-function qual
Returns
CPL_ERROR_NONE or the relevant cpl_error_code

fref must have both its abscissa and ordinate defined. fout must have its abscissa defined and its ordinate allocated.

The linear interpolation will be done from the values in fref to the abscissa points in fout.

For each abscissa point in fout, fref must either have two neigboring abscissa points such that xref_i < xout_j < xref{i+1}, or a single identical abscissa point, such that xref_i == xout_j.

This is ensured by monotonely growing abscissa points in both fout and fref (and by min(xref) <= min(xout) and max(xout) < max(xref)).

However, for efficiency reasons (since fref can be very long) the monotonicity is only verified to the extent necessary to actually perform the interpolation.

This input requirement implies that extrapolation is not allowed.

Possible cpl_error_code set in this function:

  • CPL_ERROR_NULL_INPUT if an input pointer is NULL
  • CPL_ERROR_DATA_NOT_FOUND if fout has an endpoint which is out of range
  • CPL_ERROR_ILLEGAL_INPUT if the monotonicity requirement on the 2 input abscissa vectors is not met.

Definition at line 1160 of file moo_utils.c.

◆ moo_kappa_sigma_clipping()

cpl_mask * moo_kappa_sigma_clipping ( cpl_image *  sigma_img,
int  niter,
double  kappa,
double  cdiff,
double  maxfrac 
)

Compute mask of rejected pixels using kappa sigma algorithm.

Parameters
sigma_imgimage on which we used kappa sigma
nitermaximum number of iteration
kappamultiple of sigma
cdiffminimum relative change in sigma
maxfracmaximum fraction of bad pixels allowed
Returns
mask of bad pixels

Possible cpl_error_code set in this function:

  • CPL_ERROR_NULL_INPUT if an input pointer is NULL
  • CPL_ERROR_ILLEGAL_INPUT if the size is equal to zero

Definition at line 163 of file moo_utils.c.

Referenced by moo_single_compute_noise_map().

◆ moo_median_filter()

cpl_vector * moo_median_filter ( cpl_vector *  v,
int  winhsize 
)

Apply a median filter to a vector.

Parameters
vinput vector
winhsizewindow half size
Returns
the filtered vector

Definition at line 1730 of file moo_utils.c.

Referenced by moo_compute_resp().

◆ moo_savgol_filter()

cpl_vector * moo_savgol_filter ( cpl_vector *  v,
int  window_length,
int  polyorder 
)

Apply a Savitzky-Golay filter to a vector.

Parameters
vinput vector
window_lengthThe length of the filter window (i.e. the number of coefficients). window_length must be a positive odd integer.
polyorderThe order of the polynomial used to fit the samples. polyorder must be less than window_length.
Returns
the filtered vector

Definition at line 1656 of file moo_utils.c.

◆ moo_sky_distance()

double moo_sky_distance ( double  alpha1,
double  delta1,
double  alpha2,
double  delta2 
)

Compute sky distance (in rad)

Parameters
alpha1alpha corrdinates of position 1 in degree
delta1delta corrdinates of position 1 in degree
alpha2alpha corrdinates of position 2 in degree
delta2delta corrdinates of position 2 in degree
Returns
result in rad

Definition at line 1417 of file moo_utils.c.

Referenced by moo_select_sky().

◆ moo_string_is_strictly_equal()

int moo_string_is_strictly_equal ( const char *  a,
const char *  b 
)

This function compares to string to see if the two string are stricly equal.

Parameters
afirst string to compare
bsecond string to compare
Returns
1 if a===b else 0 Possible error code :
  • CPL_ERROR_NULL_INPUT if an input pointer is NULL

Definition at line 2233 of file moo_utils.c.

Referenced by moo_table_or_selected_sequal_string().

◆ moo_table_and_selected_sequal_string()

cpl_size moo_table_and_selected_sequal_string ( cpl_table *  table,
const char *  name,
const char *  string 
)

Select from unselected table rows, by comparing column values with a constant.

Parameters
tablePointer to table
nameColumn name
stringReference value
Returns
Current number of selected rows, or a negative number in case of error. Possible error code :
  • CPL_ERROR_NULL_INPUT if an input pointer is NULL

Definition at line 2317 of file moo_utils.c.

Referenced by moo_rebin().

◆ moo_table_or_selected_sequal_string()

cpl_size moo_table_or_selected_sequal_string ( cpl_table *  table,
const char *  name,
const char *  string 
)

Select from unselected table rows, by comparing column values with a constant.

Parameters
tablePointer to table
nameColumn name
stringReference value
Returns
Current number of selected rows, or a negative number in case of error. Possible error code :
  • CPL_ERROR_NULL_INPUT if an input pointer is NULL

Definition at line 2285 of file moo_utils.c.

References moo_string_is_strictly_equal().

Referenced by moo_target_table_find_index(), moo_target_table_find_target(), and moo_target_table_merge().

◆ moo_tcheby2d_polynomial_fit()

moo_tcheby2d_polynomial * moo_tcheby2d_polynomial_fit ( cpl_vector *  in_x,
int  xdegree,
double  xmin,
double  xmax,
cpl_vector *  in_y,
int  ydegree,
double  ymin,
double  ymax,
cpl_vector *  in_l,
double  lmin,
double  lmax 
)

Computes Tchebitchev transformation of data.

Parameters
in_xX data between 1 - 4096
xdegreedegree of 2D polynomial for X
xminthe minimum x value
xmaxthe maximum x value
in_yY data
ydegreedegree of 2D polynomial for Y
yminthe minimum y value
ymaxthe maximum y value
in_lL data
lminthe minimum l value
lmaxthe maximum l value
Returns
tchebitchev polynomial 2D solution

This function fit the input data using tchebitchev transformation.

Definition at line 667 of file moo_utils.c.

◆ moo_tcheby_polynomial_fit()

moo_tcheby_polynomial * moo_tcheby_polynomial_fit ( cpl_bivector *  data,
int  degree,
double  xmin,
double  xmax 
)

Computes Tchebitchev transformation of data.

Parameters
databivector containing data to fit
degreedegree used for polynomial fit
xminMinimum range along X axis
xmaxMaximum range along X axis
Returns
the tchebychev polynomial

This function fit the input data using tchebitchev transformation. The result replace the original values.

Definition at line 573 of file moo_utils.c.

◆ moo_tchebychev_fit()

cpl_error_code moo_tchebychev_fit ( cpl_bivector *  data,
int *  flag,
int  degree,
double  xmin,
double  xmax,
double  ymin,
double  ymax 
)

Computes Tchebitchev transformation of data.

Parameters
databivector containing data to fit
flagarray of flag (same size of data)
degreedegree used for polynomial fit
xminminimum value used in x part of data
xmaxmaximum value used in x part of data
yminminmum value used in y part of data
ymaxmaximum value used in y part of data
Returns
CPL_ERROR_NONE or the relevant cpl_error_code on error

This function fit the input data using tchebitchev transformation. The result replace the original values.

Definition at line 880 of file moo_utils.c.

◆ moo_vector_filter_nan()

cpl_vector * moo_vector_filter_nan ( cpl_vector *  v)

Create new vector with nan values filter.

Parameters
vinput vector
Returns
new vector with no nan values

Definition at line 1309 of file moo_utils.c.

◆ moo_vector_get_dersnr()

double moo_vector_get_dersnr ( const cpl_vector *  ve)

This function computes the signal to noise ratio DER_SNR following the definition set forth by the Spectral Container Working Group of ST-ECF, MAST and CADC.

Parameters
veinput flux
Returns
the estimated signal-to-noise ratio Possible error code :
  • CPL_ERROR_NULL_INPUT if an input pointer is NULL or list size == 0

Definition at line 2189 of file moo_utils.c.

Referenced by moo_ext_single_compute_snr().

◆ moo_vector_get_max()

double moo_vector_get_max ( const cpl_vector *  v,
int *  flags 
)

Find maximum values in a vector using flags.

Parameters
vthe vector to use
flagsarray of flags (same size of v)
Returns
the maximum value of the vector

Definition at line 1003 of file moo_utils.c.

◆ moo_vector_get_min()

double moo_vector_get_min ( const cpl_vector *  v,
int *  flags 
)

Find minimum values in a vector using flags.

Parameters
vthe vector to use
flagsarray of flag (same size of v)
Returns
the minimum value of the vector

Definition at line 979 of file moo_utils.c.

◆ moo_vector_get_percentile()

double moo_vector_get_percentile ( cpl_vector *  v,
double  f 
)

Get percentile of input vector.

Parameters
vinput vector
fFraction between 0 and 1
Returns
the quantile value

Definition at line 1263 of file moo_utils.c.