# Name

avgvar_CTF- Calculates average and variance for an image series with CTF correction.

# Usage

Calculate average and variance of image stack with CTF correction, and without applying current alignment parameters:

- avgvar_CTF(data, mode='b')

Calculate average and variance of image stack with CTF correction using current alignment parameters:

- avgvar_CTF(data, mode='a')

Calculate average and variance of only the even numbered images with CTF correction and without using current alignment parameters:

- avgvar_CTF(data, mode='b', use_odd = False)

Calculate average and variance of only the odd numbered images between images 3 and 57, inclusive, without CTF correction and using current alignment parameters:

- avgvar_CTF(data, mode='a', i1 = 3, i2 = 57, use_even=False)

## Input

- data
image stack, must be 2D, and must be in real space. CTF information must be provided in file headers (for details see I_O).

- mode
- whether to apply alignment parameters. Default mode='a' means apply parameters
- ali_params
- name of the attribute alignment parameters are stored under in image headers
- rot_method
- specifies the function by which images are rotated/shifted if alignment parameters are to be applied. This is only relevant for the case where images are 2D, in which case rot_method can be either rot_shift2D or rotshift2dg, with the default being rot_shift2D. If images are 3D, rot_shift3D will be used to rotate/shift the images.
- interp
- interpolation method to use for rot_method when applying alignment parameters.
- i1
- index of first image to be used.
- i2
- index of last image to be used. If i2 = 0, then i2 defaults to one less than number of images in the data
- use_odd
- images with indices between i1 and i2 which are odd are used if and only if use_odd is set to True. Default is True.
- use_even
- images with indices between i1 and i2 which are even are used if and only if use_even is set to True. Default is True.
- snr
- signal to noise ratio, default 1.0

## Output

- tavg
- Inverse fourier transform of the best estimate (Wiener filter) of all the images used in the calculation (as determined by i1, i2, use_even and use_odd).
- var
- Variance, in real space

# Description

The variance is calculated as: ``1/(n-1)]*[sum_j (O_j - F^{-1}(H_j*O))^2 ``, where the sum's index ranges over all images used in the calculations, n is the number of images used in the calculations, O_j is the j-th image in real space, O is the Weiner filter of images used in the calculation, F^{-1} denotes inverse fourier transform operator, and H_j is the CTF of the j-th image

# Author / Maintainer

Jia Fang

# Keywords

- category 1
- UTILITIES

# Files

statistics.py

# See also

mad_scalar, mul_scalar, add_img2, sub_img, mul_img

# Maturity

- Works for author