dtmm.field_viewer¶
Matplotlib-based field visualizer (polarizing miscroscope simulator) and pom image calculation functions
High level functions¶
pom_viewer()for polarizing optical microscope simulation.field_viewer()for raw field_data visualization.bulk_viewer()for raw bulk_data visualization.calculate_pom_field()calculates polarizing optical microscope field.
Classes¶
FieldVieweris the actual field viewer object.BulkVieweris the actual bulk viewer object.POMVieweris the actual microscope viewer object.
Module Contents¶
-
dtmm.field_viewer.calculate_pom_field(field, jvec=None, pmat=None, dmat=None, window=None, input_fft=False, output_fft=False, out=None)¶ Calculates polarizing optical microscope field from the input field.
This function refocuses the field, applies polarizer and analayzers
- Parameters
field (ndarray) – Input array of shape (…,:,4,:,:) describing multiwavelength polarized field array or an array of shape (…,2,:,4,:,:) describing unpolarized (x nad y polarized) multiwavelength field arrays. Works also with jones multiwavelengths fields of shapes (…,:,2,:,:) and (…,2,:,2,:,:).
jvec (jonesvec, optional) – Normalized jones vector describing which polarization state of the input field to choose. Input field must be of unpolarized type if this parameter is specified.
pmat (ndarray, optional) – A 4x4 or 2x2 matrix describing the analyzer and retarder matrix. This matrix is applied in real space only if both input_fft and output_fft are False, otherwise, the matrix is applied in Fourier space.
dmat (ndarray, optional) – A diffraction matrix.
window (array, optional) – If specified, windowing is applied after field is diffracted.
input_fft (bool) – If specified, it idicates that we are working with fft data. pmat must be computed with mode_jonesmat4x4.
output_fft (bool) – If specified, output data is left in FFT space. No inverse Fourier transform is performed if this parameter is set to True.
out (ndarray, optional) – Output array.
- Returns
pom_field – Computed field od
- Return type
ndarray
Examples
>>> polarizer_jvec = dtmm.jones4.jonesvec((1,0)) >>> analyzer_jvec = dtmm.jones4.jonesvec((0,1)) >>> fmat = dtmm.tmm.f_iso() >>> pmat = dtmm.jones4.polarizer4x4(analyzer_jvec,fmat) >>> field_out = calculate_pom_field(field_in, polarizer_jvec, pmat)
-
dtmm.field_viewer.bulk_viewer(field_data, **kwargs)¶ Returns a BulkViewer object for bulk field data visualization. See
field_viewer()for parameters.- Returns
out – A
BulkViewerviewer object- Return type
-
dtmm.field_viewer.field_viewer(field_data, cmf=None, bulk_data=False, n=1.0, mode=None, is_polarized=None, window=None, diffraction=True, polarization_mode='normal', betamax=BETAMAX, beta=None, **parameters)¶ Returns a FieldViewer object for field data visualization.
- Parameters
field_data (tuple[np.ndarray]) – Input field data
cmf (str, ndarray or None, optional) – Color matching function (table). If provided as an array, it must match input field wavelengths. If provided as a string, it must match one of available CMF names or be a valid path to tabulated data. See load_tcmf.
bulk_data (bool) – Specifies whether data is to be treated as bulk data, e.g as returned by the
transfer.transfer_field()function with ret_bulk = True.n (float, optional) – Refractive index of the output material. Set this to the value used in the calculation of the field.
mode ([ 't' | 'r' | None], optional) – Viewer mode ‘t’ for transmission mode, ‘r’ for reflection mode None for as is data (no projection calculation - default).
is_polarized (bool, optional) – If specified, it defines whether the field is polarize or not. For non-polarized fields, the field must be of shape […,2,:,4,:,:]. If not provided, the polarization state is guessed from the shape of the input data. Setting this to False(and having non-polarized field) will allow setting the polarizer and sample rotation.
window (ndarray, optional) – Window function by which the calculated field is multiplied. This can be used for removing artefact from the boundaries.
diffraction (bool, optional) – Specifies whether field is treated as diffractive field or not (if it was calculated by diffraction > 0 algorithm or not). If set to False refocusing is disabled.
polarization_mode (str, optional) – Defines polarization mode. That is, how the polarization of the light is treated after passing the analyzer. By default, polarizer is applied in real space (normal) which is good for normal (or mostly normal) incidence light. You can use mode instead of normal for more accurate, but slower computation. Here polarizers are applied to mode coefficients in fft space.
betamax (float) – Betamax parameter used in the diffraction calculation function. With this you can simulate finite NA of the microscope (NA = betamax).
parameters (kwargs, optional) – Extra parameters passed directly to the
FieldViewer.set_parameters()
- Returns
out – A
FieldViewerorBulkViewerviewer object- Return type
-
class
dtmm.field_viewer.FieldViewer(shape, wavelengths, pixelsize, **kwargs)¶ Bases:
objectField viewer. See
field_viewer()-
property
ffield(self)¶ Fourier transform of the field
-
property
focus(self)¶ Focus position, relative to the calculated field position.
-
property
masked_ffield(self)¶ Fourier transform of the field
-
property
sample(self)¶ Sample rotation angle
-
property
sample_angle(self)¶ Sample rotation angle in degrees in float
-
property
aperture(self)¶ Illumination field aperture
-
property
polarizer(self)¶ Polarizer angle. Can be ‘h’,’v’, ‘lcp’, ‘rcp’, ‘none’, angle float or a jones vector
-
property
analyzer(self)¶ Analyzer angle. Can be ‘h’,’v’, ‘lcp’, ‘rcp’, ‘none’, angle float or a jones vector
-
property
intensity(self)¶ Input light intensity
-
property
input_jones(self)¶ Input field jones vector
-
property
diffraction_matrix(self)¶ Diffraction matrix for diffraction calculation
-
property
output_matrix(self)¶ 4x4 jones output matrix
-
set_parameters(self, **kwargs)¶ Sets viewer parameters. Any of the
VIEWER_PARAMETERS
-
get_parameters(self)¶ Returns viewer parameters as dict
-
plot(self, fig=None, ax=None, sliders=None, show_sliders=None, show_scalebar=None, show_ticks=None, **kwargs)¶ Plots field intensity profile. You can set any of the below listed arguments. Additionaly, you can set any argument that imshow of matplotlib uses (e.g. ‘interpolation = “sinc”’).
- Parameters
show_slider (bool, optional) – Specifies whether to show sliders or not.
show_scalebar (bool, optional) – Specifies whether to show scalebar or not.
show_ticks (bool, optional) – Specifies whether to show ticks in imshow or not.
fmin (float, optional) – Minimimum value for the focus setting.
fmax (float, optional) – Maximum value for the focus setting.
imin (float, optional) – Minimimum value for then intensity setting.
imax (float, optional) – Maximum value for then intensity setting.
pmin (float, optional) – Minimimum value for the polarizer angle.
pmax (float, optional) – Maximum value for the polarizer angle.
smin (float, optional) – Minimimum value for the sample rotation angle.
smax (float, optional) – Maximum value for the sample rotation angle.
amin (float, optional) – Minimimum value for the analyzer angle.
amax (float, optional) – Maximum value for the analyzer angle.
namin (float, optional) – Minimimum value for the numerical aperture.
namax (float, optional) – Maximum value for the numerical aperture.
-
calculate_specter(self, **params)¶ Calculates field specter.
- Parameters
params (kwargs, optional) – Any additional keyword arguments that are passed dirrectly to set_parameters method.
-
calculate_image(self, **params)¶ Calculates RGB image.
- Parameters
params (keyword arguments) – Any additional keyword arguments that are passed dirrectly to set_parameters method.
-
save_image(self, fname, origin='lower', **kwargs)¶ Calculates and saves image to file using matplotlib.image.imsave.
- Parameters
fname (str) – Output filename or file object.
origin ([ 'upper' | 'lower' ]) – Indicates whether the (0, 0) index of the array is in the upper left or lower left corner of the axes. Defaults to ‘lower’
kwargs (optional) – Any extra keyword argument that is supported by matplotlib.image.imsave
-
update_plot(self)¶ Triggers plot redraw
-
show(self)¶ Shows plot
-
property
-
class
dtmm.field_viewer.BulkViewer(shape, wavelengths, pixelsize, **kwargs)¶ Bases:
dtmm.field_viewer.FieldViewerField viewer. See
field_viewer()-
property
focus(self)¶ Focus position
-
property
masked_ffield(self)¶ Fourier transform of the field
-
property