prysm.mtf_utils¶
Utilities for working with MTF data.
-
class
prysm.mtf_utils.
MTFvFvF
(data, focus, field, freq, azimuth)¶ Bases:
object
Abstract object representing a cube of MTF vs Field vs Focus data.
-
azimuth
¶ Azimuth associated with the data
- Type
str
-
data
¶ 3D array of data in shape (focus, field, freq)
- Type
numpy.ndarray
-
field
¶ array of fields associated with the field axis of data
- Type
numpy.ndarray
-
focus
¶ array of focus associated with the focus axis of data
- Type
numpy.ndarray
-
freq
¶ array of frequencies associated with the frequency axis of data
- Type
numpy.ndarray
-
plot2d
(freq, symmetric=False, contours=True, interp_method='lanczos', fig=None, ax=None)¶ Create a 2D plot of the cube, an “MTF vs Field vs Focus” plot.
- Parameters
freq (float) – frequency to plot, will be rounded to the closest value present in the self.freq iterable
symmetric (bool) – make the plot symmetric by mirroring it about the x-axis origin
contours (bool) – plot contours
interp_method (string) – interpolation method used for the plot
fig (matplotlib.figure.Figure, optional:) – Figure to plot inside
ax (matplotlib.axes.Axis, optional:) – Axis to plot inside
- Returns
fig (matplotlib.figure.Figure) – figure containing the plot
axis (matplotlib.axes.Axis) – axis containing the plot
-
plot_thrufocus_singlefield
(field, freqs=(10, 20, 30, 40, 50), _range=100, fig=None, ax=None)¶ Create a plot of Thru-Focus MTF for a single field point.
- Parameters
field (float) – which field point to plot, in same units as self.field
freqs (iterable) – frequencies to plot, will be rounded to the closest values present in the self.freq iterable
_range (float) – +/- focus range to plot, symmetric
fig (matplotlib.figure.Figure, optional) – Figure to plot inside
ax (matplotlib.axes.Axis) – Axis to plot inside
- Returns
fig (matplotlib.figure.Figure, optional) – figure containing the plot
axis (matplotlib.axes.Axis) – axis containing the plot
-
trace_focus
(algorithm='avg')¶ Find the focus position in each field.
This is, in effect, the “field curvature” for this azimuth.
- Parameters
algorithm (str) – algorithm to use to trace focus, currently only supports ‘0.5’, see notes for a description of this technique
- Returns
field (numpy.ndarray) – array of field values, mm
focus (numpy.ndarray) – array of focus values, microns
Notes
Algorithm ‘0.5’ uses the frequency that has its peak closest to 0.5 on-axis to estimate the focus coresponding to the minimum RMS WFE condition. This is based on the following assumptions:
- Any combination of third, fifth, and seventh order spherical
aberration will produce a focus shift that depends on frequency, and this dependence can be well fit by an equation of the form y(x) = ax^2 + bx + c. If this is true, then the frequency which peaks at 0.5 will be near the vertex of the quadratic, which converges to the min RMS WFE condition.
- Coma, while it enhances depth of field, does not shift the
focus peak.
- Astigmatism and field curvature are the dominant cause of any
shift in best focus with field.
- Chromatic aberrations do not influence the thru-focus MTF peak
in a way that varies with field.
- Raises
ValueError – if an unsupported algorithm is entered
-
static
from_dataframe
(df)¶ Return a pair of MTFvFvF objects for the tangential and one for the sagittal MTF.
- Parameters
df (pandas.DataFrame) – a dataframe with columns Focus, Field, Freq, Azimuth, MTF
- Returns
t_cube (MTFvFvF) – tangential MTFvFvF
s_cube (MTFvFvF) – sagittal MTFvFvF
-
static
from_trioptics_file
(file_path)¶ Create a new MTFvFvF object from a trioptics file.
- Parameters
file_path (path_like) – path to a file
- Returns
new MTFvFvF object
- Return type
MTFvFvF
-
-
prysm.mtf_utils.
mtf_ts_extractor
(mtf, freqs)¶ Extract the T and S MTF from a PSF object.
- Parameters
mtf (MTF) – MTF object
freqs (iterable) – set of frequencies to extract
- Returns
tan (numpy.ndarray) – array of tangential MTF values
sag (numpy.ndarray) – array of sagittal MTF values
-
prysm.mtf_utils.
mtf_ts_to_dataframe
(tan, sag, freqs, field=0, focus=0)¶ Create a Pandas dataframe from tangential and sagittal MTF data.
- Parameters
tan (numpy.ndarray) – vector of tangential MTF data
sag (numpy.ndarray) – vector of sagittal MTF data
freqs (iterable) – vector of spatial frequencies for the data
field (float) – relative field associated with the data
focus (float) – focus offset (um) associated with the data
- Returns
- Return type
pandas dataframe.
-
class
prysm.mtf_utils.
MTFFFD
(data, field_x, field_y, freq)¶ Bases:
object
An MTF Full-Field Display; stores MTF vs Field vs Frequency and supports plotting.
-
plot2d
(freq, show_contours=True, cmap='inferno', clim=(0, 1), show_cb=True, fig=None, ax=None)¶ Plot the MTF FFD.
- Parameters
freq (float) – frequency to plot at
show_contours (bool) – whether to plot contours
cmap (str) – colormap to pass to imshow
clim (iterable) – length 2 iterable with lower, upper bounds of colors
show_cb (bool) – whether to show the colorbar or not
fig (matplotlib.figure.Figure, optional) – figure containing the plot
ax (matplotlib.axes.Axis) – axis containing the plot
- Returns
fig (matplotlib.figure.Figure, optional) – figure containing the plot
axis (matplotlib.axes.Axis) – axis containing the plot
-
static
from_trioptics_files
(paths, azimuths, upsample=10, ret=('tan', 'sag'))¶ Convert a set of trioptics files to MTF FFD object(s).
- Parameters
paths (path_like) – paths to trioptics files
azimuths (iterable of strs) – azimuths, one per path
ret (tuple, optional) – strings representing outputs, {‘tan’, ‘sag’} are the only currently implemented options
- Returns
MTF FFD object
- Return type
MTFFFD
- Raises
NotImplemented – return option is not available
-
-
prysm.mtf_utils.
radial_mtf_to_mtfffd_data
(tan, sag, imagehts, azimuths, upsample)¶ Take radial MTF data and map it to inputs to the MTFFFD constructor.
Performs upsampling/interpolation in cartesian coordinates
- Parameters
tan (np.ndarray) – tangential data
sag (np.ndarray) – sagittal data
imagehts (np.ndarray) – array of image heights
azimuths (iterable) – azimuths corresponding to the first dimension of the tan/sag arrays
upsample (float) – upsampling factor
- Returns
out_x (np.ndarray) – x coordinates of the output data
out_y (np.ndarray) – y coordinates of the output data
tan (np.ndarray) – tangential data
sag (np.ndarray) – sagittal data
-
prysm.mtf_utils.
plot_mtf_vs_field
(data_dict, fig=None, ax=None)¶ Plot MTF vs Field.
- Parameters
data_dict (dict) – dictionary with keys tan, sag, fields, frequencies
fig (matplotlib.figure.Figure, optional) – figure containing the plot
axis (matplotlib.axes.Axis) – axis containing the plot
- Returns
fig (matplotlib.figure.Figure, optional) – figure containing the plot
axis (matplotlib.axes.Axis) – axis containing the plot