GRAVI Pipeline Reference Manual  1.2.3
Functions
Averaging the individual DITs into a final OIFITS

Functions

double gravi_randn (void)
 Normal distribution pseudo-random generator.
 
cpl_error_code gravi_array_online_variance_res (cpl_array **data, int n, int rephase)
 On-line variance of arrays. More...
 
cpl_error_code gravi_flux_average_bootstrap (cpl_table *oi_flux_avg, cpl_table *oi_flux, int nboot)
 Average the flux of all DITs into a final, averaged value. More...
 
cpl_error_code gravi_t3_average_bootstrap (cpl_table *oi_t3_avg, cpl_table *oi_vis, cpl_table *oi_flux, int nboot, int use_vFactor, int use_pFactor)
 Average the closure-phase of all DITs into a final, averaged value. More...
 
cpl_error_code gravi_vis_average_bootstrap (cpl_table *oi_vis_avg, cpl_table *oi_vis2_avg, cpl_table *oi_vis, int nboot, const char *phase_ref, int use_vFactor, int use_pFactor, int use_debiasing)
 Average the visibility of all DITs into a final, averaged value. More...
 
cpl_error_code gravi_vis_flag_nan (cpl_table *oi_table)
 Flag samples of OIFITS table which are NAN or NULL. More...
 
cpl_error_code gravi_vis_average_amp (cpl_table *oi_table, const char *name, const char *err, int nbase)
 Average amplitudes column of a multi-observation OIFITS table The averaged quantities are stored in the first nbase rows. More...
 
cpl_error_code gravi_vis_average_phi (cpl_table *oi_table, const char *name, const char *err, int nbase)
 Average phases column of a multi-observation OIFITS table Phases are averaged with arg{<exp(i.phi)>} The averaged quantities are stored in the first nbase rows. More...
 
cpl_error_code gravi_vis_average_value (cpl_table *oi_table, const char *name, const char *err, int nbase)
 Average scalar column of a multi-observation OIFITS table. The averaged quantities are stored in the first nbase rows. More...
 
cpl_error_code gravi_vis_resamp_amp (cpl_table *oi_table, const char *name, const char *err, cpl_size nsamp, cpl_size nwave_new)
 Rebin amplitude column of OIFITS table. More...
 
cpl_error_code gravi_vis_resamp_phi (cpl_table *oi_table, const char *name, const char *err, cpl_size nsamp, cpl_size nwave_new)
 Rebin phase column of OIFITS table (arg{<exp(i.phi)>}) More...
 
cpl_error_code gravi_vis_smooth_amp (cpl_table *oi_table, const char *name, const char *err, cpl_size nsamp)
 Smooth amplitude column of OIFITS table. More...
 
cpl_error_code gravi_vis_smooth_phi (cpl_table *oi_table, const char *name, const char *err, cpl_size nsamp)
 Smooth phase column of OIFITS table. More...
 
cpl_error_code gravi_vis_fit_amp (cpl_table *oi_table, const char *name, const char *err, cpl_size maxdeg)
 Smooth amp column of OIFITS table. More...
 
cpl_error_code gravi_vis_compute_column_mean (cpl_table *out_table, cpl_table *in_table, const char *name, int ntel)
 Compute the mean of a column in OIFITS table, and save the result in the specified output table. More...
 
cpl_error_code gravi_vis_flag_median (cpl_table *oi_table, const char *data, const char *flag, double value)
 Flag samples of OIFITS table based on runnning median. More...
 
double gdAbacusErrPhi (double x)
 
cpl_error_code gravi_average_self_visphi (cpl_table *oi_vis_avg, cpl_table *oi_vis, cpl_array *wavenumber, const char *phase_ref, int *cmin, int *cmax, int nrange)
 Compute Averaged VISPHI in the manner described, e.g., in F. Millour's thesis. More...
 
gravi_data * gravi_compute_vis (gravi_data *p2vmred_data, const cpl_parameterlist *parlist, cpl_size *current_frame)
 The function average the individual frames of a P2VMREDUCED file into a final, single observation per base and per tel. More...
 
cpl_error_code gravi_compute_vis_qc (gravi_data *vis_data)
 The function compute the QC parameters for a VIS (averaged) data. More...
 
cpl_error_code gravi_normalize_sc_to_ft (gravi_data *vis_data)
 Align the SC visibilities on the FT visibilities. More...
 
cpl_error_code gravi_vis_mjd_to_time (gravi_data *vis_data)
 Recompute the TIME column of all OIFITS extension from the MJD column, following the OIFITS standard (number of second since the DATE-OBS at 00:00). More...
 
cpl_error_code gravi_flat_flux (gravi_data *vis_data, gravi_data *p2vm_map)
 Divide the OI_FLUX by OI_FLUX from the P2VM (no checks, no time distance...) More...
 
cpl_error_code gravi_force_uncertainties (gravi_data *oi_data, const cpl_parameterlist *parlist)
 Force uncertainties. More...
 
cpl_error_code gravi_average_vis (gravi_data *oi_data)
 Coadd the observations together. More...
 
cpl_error_code gravi_vis_smooth (gravi_data *oi_data, cpl_size nsamp_vis, cpl_size nsamp_flx, cpl_size maxdeg)
 Smooth the SC table by nsamp consecutive spectral bins. More...
 
cpl_error_code gravi_vis_resamp (gravi_data *oi_data, cpl_size nsamp)
 Re-bin the SC table by nsamp consecutive spectral bins. More...
 
cpl_error_code gravi_vis_flag_threshold (cpl_table *oi_table, const char *data, const char *flag, double value)
 Flag samples of OIFITS table based on absolute threshold. More...
 
cpl_error_code gravi_vis_flag_relative_threshold (cpl_table *oi_table, const char *err, const char *data, const char *flag, double value)
 Flag samples of OIFITS table based on relative threshold. More...
 
cpl_error_code gravi_vis_erase_obs (cpl_table *oi_table, cpl_array *flag_array, cpl_size ntel)
 Erase observation from an OIFITS table. More...
 
cpl_error_code gravi_vis_force_time (gravi_data *oi_data)
 Force all data in OI_TABLE to have the same TIME and MJD. More...
 

Detailed Description

This module processes the p2vmreduced file to produce the final product of the gravity_vis recipe. The functions gravi_compute_vis() computes the averaged quantities, main steps are :

Function Documentation

double gdAbacusErrPhi ( double  x)

Estimate true phase rms from the cross-spectrum variance. see Petrov, Roddier and Aime, JOSAA vol 3, N.5, may 1986 p 634. and Petrov's Thesis, p. 50 ff. I replace the piecewise interpolation usually used by a polynomial approximation of the function: if z=log10(y), then z=(C[1]*X^7+C[2]*X^6+C[3]*X^5+C[4]*X^4+C[5]*X^3+C[6]*X^2+C[7]*X+C[8]) and y=10^z. where C[01]= 2.71918080109099 C[02]=-17.1901043936273 C[03]= 45.0654103760899 C[04]=-63.4441678243197 C[05]= 52.3098941426378 C[06]=-25.8090699917488 C[07]= 7.84352873962491 C[08]=-1.57308595820081 This interpolation is valid in the range x=[0.1,1.74413]. Error is 1% everywhere except above x=1.73 where it is 10% Below x=0.1: y=x Above x=M_PI/sqrt(3.0), y = blanking (impossible value) Above x=1.74413, we take: y=0.691/(pi/sqrt(3.0)-x)

Definition at line 1148 of file gravi_vis.c.

Referenced by gravi_average_self_visphi().

cpl_error_code gravi_array_online_variance_res ( cpl_array **  data,
int  n,
int  rephase 
)

On-line variance of arrays.

Parameters
datalist of 4 arrays, all initialized: 0: current_sample, 1: running_mean, 2: first_boot (to keep track if necessary), 3: running_variance
nthe sample number
rephaseif 1, the value are consired being phases

Compute the online-variance of a sample of 'data' with increasing number of sample (n), in-place. Mean and variance should be init to zero at n=0 See https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance

Definition at line 209 of file gravi_vis.c.

Referenced by gravi_flux_average_bootstrap(), gravi_t3_average_bootstrap(), and gravi_vis_average_bootstrap().

cpl_error_code gravi_average_self_visphi ( cpl_table *  oi_vis_avg,
cpl_table *  oi_vis,
cpl_array *  wavenumber,
const char *  phase_ref,
int *  cmin,
int *  cmax,
int  nrange 
)

Compute Averaged VISPHI in the manner described, e.g., in F. Millour's thesis.

Parameters
oi_vis_avgalready allocated OI_VIS table to be filled
oi_visinput OI_VIS with all individual DITs
basebase to consider (0..5)
phase_refphase used to rephase the DITs

Definition at line 1217 of file gravi_vis.c.

References gdAbacusErrPhi(), gravi_array_get_group_delay_loop(), gravi_array_multiply_phasor(), and gravi_array_new_list().

Referenced by gravi_compute_vis().

cpl_error_code gravi_average_vis ( gravi_data *  oi_data)

Coadd the observations together.

Parameters
oi_datathe OIFITS map to co-add in-place

All observation are averaged together. No checks of consistency ! The result always contains 6 VIS, 6 VIS2, 4 T3, and 4 FLUX, whatever the initial content of the OIFITS. The MJD, UCOORD, VCOORD... are averaged with equal weight (no weighting by the SNR).

Definition at line 2750 of file gravi_vis.c.

References gravi_data_has_type(), gravi_vis_average_amp(), gravi_vis_average_phi(), and gravi_vis_average_value().

gravi_data* gravi_compute_vis ( gravi_data *  p2vmred_data,
const cpl_parameterlist *  parlist,
cpl_size *  current_frame 
)

The function average the individual frames of a P2VMREDUCED file into a final, single observation per base and per tel.

Parameters
p2vmred_dataP2VMREDUCED data containing OI_FLUX and OI_VIS tables coming from the gravi_compute_p2vmred
parlistParameters of the recipe

Definition at line 1509 of file gravi_vis.c.

References gravi_array_get_group_delay_loop(), gravi_array_multiply_phasor(), gravi_average_self_visphi(), gravi_data_add_table(), gravi_data_copy_ext(), gravi_data_get_table(), gravi_data_has_type(), gravi_data_new(), gravi_flux_average_bootstrap(), gravi_t3_average_bootstrap(), gravi_table_extract_time_interval(), gravi_table_oi_create(), gravi_vis_average_bootstrap(), and gravi_vis_compute_column_mean().

cpl_error_code gravi_compute_vis_qc ( gravi_data *  vis_data)

The function compute the QC parameters for a VIS (averaged) data.

Parameters
vis_dataVIS data containing OI_FLUX and OI_VIS tables comming from the gravi_compute_vis

Definition at line 2048 of file gravi_vis.c.

References gravi_data_has_type().

cpl_error_code gravi_flat_flux ( gravi_data *  vis_data,
gravi_data *  p2vm_map 
)

Divide the OI_FLUX by OI_FLUX from the P2VM (no checks, no time distance...)

Parameters
vis_datathe VIS data whose OI_FLUX tables will be updated in-place
p2vm_mapthe input P2VM calibration map to load the reference OI_FLUX

Definition at line 2457 of file gravi_vis.c.

References gravi_apply_tf_amp().

cpl_error_code gravi_flux_average_bootstrap ( cpl_table *  oi_flux_avg,
cpl_table *  oi_flux,
int  nboot 
)

Average the flux of all DITs into a final, averaged value.

Parameters
oi_flux_avgalready allocated OI_FLUX table to be filled
oi_fluxinput OI_FLUX with all individual DITs
nsegnumber of segment for the boostrap
nbootnumber of boostrap
telbeam to consider (0..3)

Average the flux and compute the final flux. The errors are computed with the boostraping method.

Definition at line 262 of file gravi_vis.c.

References gravi_array_new_list(), gravi_array_online_variance_res(), gravi_randn(), and gravi_vis_flag_relative_threshold().

Referenced by gravi_compute_vis().

cpl_error_code gravi_force_uncertainties ( gravi_data *  oi_data,
const cpl_parameterlist *  parlist 
)

Force uncertainties.

Parameters
oi_datathe OIFITS map to co-add in-place

Read the parameter of the recipe and update the uncertainties on the corresponding quantities.

Definition at line 2660 of file gravi_vis.c.

References gravi_param_get_double_default().

cpl_error_code gravi_normalize_sc_to_ft ( gravi_data *  vis_data)

Align the SC visibilities on the FT visibilities.

Parameters
vis_datathe VIS data to update in-place

Force the mean value of the VIS2DATA of the SC to match the mean value of the VIS2DATA of the FT. Same for VISAMP.

Definition at line 2317 of file gravi_vis.c.

cpl_error_code gravi_t3_average_bootstrap ( cpl_table *  oi_t3_avg,
cpl_table *  oi_vis,
cpl_table *  oi_flux,
int  nboot,
int  use_vFactor,
int  use_pFactor 
)

Average the closure-phase of all DITs into a final, averaged value.

Parameters
oi_t3_avgalready allocated OI_T3 table to be filled
oi_visinput OI_VIS with all individual DITs
oi_fluxinput OI_FLUX with all individual DITs
nsegnumber of segment for the boostrap
nbootnumber of boostrap
closuretriplet to consider (0..3)

Average the bispectrum and compute the final closure-phase, considering the rejection flags. The errors are computed with the boostraping method.

Definition at line 473 of file gravi_vis.c.

References gravi_array_new_list(), gravi_array_online_variance_res(), gravi_randn(), gravi_vis_flag_median(), and gravi_vis_flag_threshold().

Referenced by gravi_compute_vis().

cpl_error_code gravi_vis_average_amp ( cpl_table *  oi_table,
const char *  name,
const char *  err,
int  nbase 
)

Average amplitudes column of a multi-observation OIFITS table The averaged quantities are stored in the first nbase rows.

Parameters
oi_tablethe table to update (number of row will be reduced)
namename of column to average
errcorresponding error column
nbasenumber of row per obs (ex: 6 for VIS and 4 for FLUX)

Definition at line 2507 of file gravi_vis.c.

Referenced by gravi_average_vis().

cpl_error_code gravi_vis_average_bootstrap ( cpl_table *  oi_vis_avg,
cpl_table *  oi_vis2_avg,
cpl_table *  oi_vis,
int  nboot,
const char *  phase_ref,
int  use_vFactor,
int  use_pFactor,
int  use_debiasing 
)

Average the visibility of all DITs into a final, averaged value.

Parameters
oi_vis_avgalready allocated OI_VIS table to be filled
oi_vis2_avgalready allocated OI_VIS2 table to be filled
oi_visinput OI_VIS with all individual DITs
oi_fluxinput OI_FLUX with all individual DITs
nsegnumber of segment for the boostrap
nbootnumber of boostrap
basebase to consider (0..5)
phase_refphase used to rephase the DITs
use_vFactoruse the VFACTOR to compensate for vis. losses

Average the coherent flux and photometric fluex, then normalize and compute the final visibilities, considering the rejection flags. The errors are computed with the boostraping method.

Definition at line 797 of file gravi_vis.c.

References gravi_array_new_list(), gravi_array_online_variance_res(), gravi_randn(), gravi_vis_flag_median(), and gravi_vis_flag_threshold().

Referenced by gravi_compute_vis().

cpl_error_code gravi_vis_average_phi ( cpl_table *  oi_table,
const char *  name,
const char *  err,
int  nbase 
)

Average phases column of a multi-observation OIFITS table Phases are averaged with arg{<exp(i.phi)>} The averaged quantities are stored in the first nbase rows.

Parameters
oi_tablethe table to update (number of row will be reduced)
namename of column to average
errcorresponding error column
nbasenumber of row per obs (ex: 6 for VIS and 4 for FLUX)

Definition at line 2567 of file gravi_vis.c.

Referenced by gravi_average_vis().

cpl_error_code gravi_vis_average_value ( cpl_table *  oi_table,
const char *  name,
const char *  err,
int  nbase 
)

Average scalar column of a multi-observation OIFITS table. The averaged quantities are stored in the first nbase rows.

Parameters
oi_tablethe table to update (number of row will be reduced)
namename of column to average
errcorresponding error column
nbasenumber of row per obs (ex: 6 for VIS and 4 for FLUX)

Definition at line 2623 of file gravi_vis.c.

Referenced by gravi_average_vis().

cpl_error_code gravi_vis_compute_column_mean ( cpl_table *  out_table,
cpl_table *  in_table,
const char *  name,
int  ntel 
)

Compute the mean of a column in OIFITS table, and save the result in the specified output table.

Parameters
out_tableOutput table
in_tableInput table
nameColumn name
ntelNumber of tel (or base, or triplet)

The routine create a column in the output table with the same name and units as the one in the input table. It is filled with an average of the signal over all DITs, considering the column REJECTION_FLAG if present (non-zero means frame is rejected). This averaging is performed independently for the ntel tel (or base or triplet). The output table shall thus contain ntel rows while the input table shall contain ntel*NDIT rows.

Note that this routine is not optimized for performance and thus shall not be used on the FT tables.

Definition at line 3641 of file gravi_vis.c.

Referenced by gravi_compute_vis().

cpl_error_code gravi_vis_erase_obs ( cpl_table *  oi_table,
cpl_array *  flag_array,
cpl_size  ntel 
)

Erase observation from an OIFITS table.

Parameters
oi_tableThe oitable, modified in-place
flag_arrayArray with nobs value
ntelNumber of row in oitable for each obs

The recipe first select all obs in oitable corresponding to flagged observations (flag_array != 0). Then they are erased in-place.

Definition at line 3593 of file gravi_vis.c.

Referenced by gravi_disp_cleanup().

cpl_error_code gravi_vis_fit_amp ( cpl_table *  oi_table,
const char *  name,
const char *  err,
cpl_size  maxdeg 
)

Smooth amp column of OIFITS table.

Parameters
oi_tablethe table to update (column depth will be modified)
namename of column to rebin
errcorresponding error column
nsampnumber of consecutive samples to bin into single bin

Definition at line 3018 of file gravi_vis.c.

Referenced by gravi_vis_smooth().

cpl_error_code gravi_vis_flag_median ( cpl_table *  oi_table,
const char *  data,
const char *  flag,
double  value 
)

Flag samples of OIFITS table based on runnning median.

Parameters
oi_tablethe cpl_table to update, in-place
namethe column name to verify
flagthe corresponding flag column (to update in-place)
valuethe threshold to compare

For each sample in the column, if sample>value*median then the corresponding element in the flag column is set to 'T'.

Definition at line 3483 of file gravi_vis.c.

Referenced by gravi_t3_average_bootstrap(), gravi_vis_average_bootstrap(), and gravi_vis_smooth().

cpl_error_code gravi_vis_flag_nan ( cpl_table *  oi_table)

Flag samples of OIFITS table which are NAN or NULL.

Parameters
oi_tablethe cpl_table to update, in-place

Definition at line 3368 of file gravi_vis.c.

Referenced by gravi_vis_smooth().

cpl_error_code gravi_vis_flag_relative_threshold ( cpl_table *  oi_table,
const char *  err,
const char *  data,
const char *  flag,
double  value 
)

Flag samples of OIFITS table based on relative threshold.

Parameters
oi_tablethe cpl_table to update, in-place
namethe column name to verify
namethe corresponding error column
flagthe corresponding flag column (to update in-place)
valuethe threshold to compare

For each sample in the column, if err/sample>value then the corresponding element in the flag column is set to 'T'.

Definition at line 3543 of file gravi_vis.c.

Referenced by gravi_flux_average_bootstrap(), gravi_vis_resamp(), and gravi_vis_smooth().

cpl_error_code gravi_vis_flag_threshold ( cpl_table *  oi_table,
const char *  data,
const char *  flag,
double  value 
)

Flag samples of OIFITS table based on absolute threshold.

Parameters
oi_tablethe cpl_table to update, in-place
namethe column name to verify
flagthe corresponding flag column (to update in-place)
valuethe threshold to compare

For each sample in the column, if sample>value then the corresponding element in the flag column is set to 'T'.

Definition at line 3437 of file gravi_vis.c.

Referenced by gravi_t3_average_bootstrap(), gravi_vis_average_bootstrap(), gravi_vis_resamp(), and gravi_vis_smooth().

cpl_error_code gravi_vis_force_time ( gravi_data *  oi_data)

Force all data in OI_TABLE to have the same TIME and MJD.

Parameters
oi_dataVIS data to process, in-place

The TIME and MJD columns of all OI_VIS, OI_VIS2, OI_FLUX and OI_T3 are averaged and replaced by these averages. Note that: SC and FT are averaged into the same time/mjd, all observations are averaged into the same time/mjd, all observables are averaged into the same time/mjd.

Definition at line 3761 of file gravi_vis.c.

References gravi_data_get_size(), and gravi_data_get_table_x().

cpl_error_code gravi_vis_mjd_to_time ( gravi_data *  vis_data)

Recompute the TIME column of all OIFITS extension from the MJD column, following the OIFITS standard (number of second since the DATE-OBS at 00:00).

Parameters
vis_datathe gravi_data to update in-place

Definition at line 2403 of file gravi_vis.c.

References gravi_data_get_plist_x(), gravi_data_get_size(), and gravi_data_get_table_x().

cpl_error_code gravi_vis_resamp ( gravi_data *  oi_data,
cpl_size  nsamp 
)

Re-bin the SC table by nsamp consecutive spectral bins.

Parameters
oi_dataVIS data to process, in-place
nsampinteger, the number of consecutive bin to sum

The OI_VIS, OI_VIS2, OI_FLUX, OI_T3 and OI_WAVELENGTHs tables are updated accordingly. Note that this operation is not flux conservative (FIXME: understand how to better averaged flux).

Definition at line 3273 of file gravi_vis.c.

References gravi_vis_flag_relative_threshold(), gravi_vis_flag_threshold(), and gravi_vis_resamp_amp().

cpl_error_code gravi_vis_resamp_amp ( cpl_table *  oi_table,
const char *  name,
const char *  err,
cpl_size  nsamp,
cpl_size  nwave_new 
)

Rebin amplitude column of OIFITS table.

Parameters
oi_tablethe table to update (column depth will be modified)
namename of column to rebin
errcorresponding error column
nsampnumber of consecutive samples to bin into single bin
nwave_newnumber of final bins to reach (FIXME: why needed ??)

Definition at line 3180 of file gravi_vis.c.

Referenced by gravi_vis_resamp().

cpl_error_code gravi_vis_resamp_phi ( cpl_table *  oi_table,
const char *  name,
const char *  err,
cpl_size  nsamp,
cpl_size  nwave_new 
)

Rebin phase column of OIFITS table (arg{<exp(i.phi)>})

Parameters
oi_tablethe table to update (column depth will be modified)
namename of column to rebin
errcorresponding error column
nsampnumber of consecutive samples to bin into single bin
nwave_newnumber of final bins to reach (FIXME: why needed ??)

Definition at line 3226 of file gravi_vis.c.

cpl_error_code gravi_vis_smooth ( gravi_data *  oi_data,
cpl_size  nsamp_vis,
cpl_size  nsamp_flx,
cpl_size  maxdeg 
)

Smooth the SC table by nsamp consecutive spectral bins.

Parameters
oi_dataVIS data to process, in-place
nsamp_visinteger, the number of consecutive bin to smooth
nsamp_flxinteger, the number of consecutive bin to smooth
maxdeginteger, fit order
mindeginteger, fit order

The OI_VIS, OI_VIS2, OI_FLUX, OI_T3 tables are updated accordingly. Note that this operation is not flux conservative (FIXME: understand how to better averaged flux).

Definition at line 3102 of file gravi_vis.c.

References gravi_vis_fit_amp(), gravi_vis_flag_median(), gravi_vis_flag_nan(), gravi_vis_flag_relative_threshold(), gravi_vis_flag_threshold(), gravi_vis_smooth_amp(), and gravi_vis_smooth_phi().

cpl_error_code gravi_vis_smooth_amp ( cpl_table *  oi_table,
const char *  name,
const char *  err,
cpl_size  nsamp 
)

Smooth amplitude column of OIFITS table.

Parameters
oi_tablethe table to update (column depth will be modified)
namename of column to rebin
errcorresponding error column
nsampnumber of consecutive samples to bin into single bin

Definition at line 2855 of file gravi_vis.c.

Referenced by gravi_vis_smooth().

cpl_error_code gravi_vis_smooth_phi ( cpl_table *  oi_table,
const char *  name,
const char *  err,
cpl_size  nsamp 
)

Smooth phase column of OIFITS table.

Parameters
oi_tablethe table to update (column depth will be modified)
namename of column to rebin
errcorresponding error column
nsampnumber of consecutive samples to bin into single bin

Definition at line 2936 of file gravi_vis.c.

Referenced by gravi_vis_smooth().