polyTEM.image.ctf.CTF¶
- class polyTEM.image.ctf.CTF(fit_df=Empty DataFrame Columns: [Micrograph Num, Spatial Frequency (1/A), CTF fit, Signal] Index: [], output={'astigmatism': 0, 'cross-corr': 0, 'defocus 1 (A)': 0, 'defocus 2 (A)': 0, 'max fit (A)': 0, 'phase shift (rad)': 0}, params={'Box size': 0, 'Input file': '', 'Pixel size': 0, 'acceleration voltage': 0, 'amplitude contrast': 0, 'max. def.': 0, 'max. res.': 0, 'min. def.': 0, 'min. res.': 0, 'spherical aberration': 0})¶
Bases:
objectClass for handling CTF (Contrast Transfer Function) correction of TEM images.
This class processes the output from CTFFIND4 and provides methods for CTF correction.
- Variables:
df (pd.DataFrame) – Spatial frequency vs ctffit
fit_summary (dict) – defocus, astigmatism, phase shift, cross-correlation, and max fit
fit_pars – ctffind4 input parameters: pixel size, acceleration voltage, spherical aberration, amplitude contrast, min. res., max. res., Box size, min. def., max. def.
envelope_decay (float) – beta parameter for envelope decay
- __init__(fit_df=Empty DataFrame Columns: [Micrograph Num, Spatial Frequency (1/A), CTF fit, Signal] Index: [], output={'astigmatism': 0, 'cross-corr': 0, 'defocus 1 (A)': 0, 'defocus 2 (A)': 0, 'max fit (A)': 0, 'phase shift (rad)': 0}, params={'Box size': 0, 'Input file': '', 'Pixel size': 0, 'acceleration voltage': 0, 'amplitude contrast': 0, 'max. def.': 0, 'max. res.': 0, 'min. def.': 0, 'min. res.': 0, 'spherical aberration': 0})¶
Methods
__init__([fit_df, output, params])build_array(s[, plot])uses the ctf fit output to build np.ndarray of input shape of the ctf function, to allow for correction.
envelope_fit([min_freq])Uses lmfit to fit the envelope parameter to the ctf :returns: lmfit ModelResult self.envelope_decay: Parameter B of envelope function, see _full_ctf_model :rtype: result
load(filename[, tilt_series])Creates CTF instance from ctffind output file
plot_lineout([q])wiener_filter(shape, snr)build wiener filter for CTF, with size (s,s), BUG: RIGHT NOW ASSUME SQUARE! and signal to noise ratio with the same size
Attributes
ctf_fit_dfdefault_parssummary_dict- _ctf_function(i: ndarray, j: ndarray, s, b, center_i, center_j)¶
Reference: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4711343/
To be used in np.fromfunction, in the form lambda i,j: _ctf_function(args) such that the lambda function is called with N parameters, where N is the rank of shape, and each parameter represents the coordinates of the array. i.e. this function needs to work with i is a np.ndarray of row indices and j is a np.ndarray of col indices
- Parameters:
i – row, pixel index
j – col, pixel index
s – size of array (assumes square)
b – envelope decay parameter
note that q=2pi/d (related to GIWAXS) where as u is 1/d
Update 12.13.22 to allow for non-centered i and j.
- _full_ctf_model(max_freq=None)¶
combines CTFFIND ctf fit result with envelope function. envelope fn = exp(-B * u**2) where u is the frequency vector and B is the decay rate :returns: lmfit Model instance to allow for envelope function fitting :rtype: model
- _process_fileline(line, info='summary', linenum=None)¶
Processes ctffind4 output textfiles
Expected info contained in ctffind output (info==’summary’): Line 1: # CTF version, date and time Line 2: # Input file : <filename> ; Line 3: # <Parameter Name>: <Value> <Unit>; Line 4: # <Parameter Name>: <Value> <Unit>; Line 5: # Columns: #1 - micrograph number; #2 - defocus 1 [Angstroms]; #3 - defocus 2; #4 - azimuth of astigmatism; #5 - additional phase shift [radians]; #6 - cross correlation; #7 - spacing (in Angstroms); Line 6+: <Column Values separated by space>
Expected info contained in ctiffind out _avrot: Line 1: # Output from CTFFIND version <version>, run on <date> <time> Line 2: # Input file: <filename> Line 3: # <Parameter Name>: <Value> <Unit>; Line 4: # <Parameter Name>: <Value> <Unit>; Line 5: # 6 lines per micrograph: #1 - spatial frequency (1/Angstroms); #2 - 1D rotational average of spectrum (assuming no astigmatism); #3 - 1D rotational average of spectrum; #4 - CTF fit; #5 - cross-correlation between spectrum and CTF fit; #6 - 2sigma of expected cross correlation of noise Line 6+: Values as described by Line 5.
Assumes Python Version 3.7, where dictionaries are ordered!
- build_array(s, plot=True)¶
uses the ctf fit output to build np.ndarray of input shape of the ctf function, to allow for correction.
- Parameters:
s – size of square array
- Returns:
np.array with shape (s,s) containing CTF, with u=0 centered
- Return type:
shifted_arr
- envelope_fit(min_freq=0.08)¶
Uses lmfit to fit the envelope parameter to the ctf :returns: lmfit ModelResult
self.envelope_decay: Parameter B of envelope function, see _full_ctf_model
- Return type:
result
- classmethod load(filename, tilt_series=False)¶
Creates CTF instance from ctffind output file
- Parameters:
filename (str) – path to ctffind_output.txt
- Returns:
CTF object
- Return type:
ctf
- wiener_filter(shape, snr)¶
build wiener filter for CTF, with size (s,s), BUG: RIGHT NOW ASSUME SQUARE! and signal to noise ratio with the same size