### Quality assessment and data flagging

Validation of the solution
  One of the difficulties of self-calibration is to evaluate whether it has improved the image or not. The self-calibration solution is biased towards the assumed model. If used with insufficient signal to noise, it will tend to produce a point source at the initial peak position, and the bias will be of order of the noise. This may be inappropriate. Currently, the validity of the self-calibration solution is based on the estimated signal to noise ratio for the gains at each time step. If that SNR is below a user-controlled threshold (by default, SELF_SNR=6), the corresponding data is flagged (default value: SELF_FLAG=YES) or kept WITHOUT self calibration (if SELF_FLAG=NO).
Flagging or not flagging ?
  The decision to flag or not results from a trade-off:
  - SELF_FLAG Yes : will result in no contamination by bad data, but may lead to lower angular resolution since long baselines may be flagged.
  - SELF_FLAG No: will avoid loosing all long baselines (where the SNR is lower)
  Both options may be explored, and it is recommended to check afterwards the final angular resolution with and without flagging.

The following scheme is proposed to check the validity of the self-calibration solution:

- read the status using SELFCAL SUMMARY
- use SELFCAL SHOW to verify if the solution is converged
- if it looks good, but noise is still far from theoretical, try again to self-calibrate with a shorter integration time ( SELF_TIMES).
- if it is not good, try to increase SELF_TIMES and find an optimum value. For ALMA data, typical values may be in the range s, and for NOEMA in the range s. Alternatively, you can also try to decrease SELF_SNR to lower values, but never less than 3.

From our experience, the number of loops SELF_NLOOP does not impact much the quality of the solution, and 2 to 3 iterations are usually sufficient.

Warning: the comparison with theoretical noise relies on a proper scaling of the weights of the UV data. This is fine for the IRAM array, but data exported from CASA is not always correct in this respect. UV_PREVIEW can warn you about potential issues in this respect. UV_REWEIGHT can also evaluate the scaling factor that should be applied to the weights to recover the apparent noise level. UV_PREVIEW requires a sufficient number of spectral channels for this purpose. By default, UV_REWEIGHT suffers from a similar restriction, and both commands may fail if the bandwidth is clobbered with spectral lines or has strong continuum. However, UV_REWEIGHT as a TIME mode where the noise is estimated from consecutive visibilities, and thus is not affected by this limitation.

The appropriate scaling factor can be specified in SELFCAL by variable SELF_SNOISE.