open_viewmin.nematic.jones ========================== .. py:module:: open_viewmin.nematic.jones .. autoapi-nested-parse:: Jones matrix calculations for transmission of polarized light through the nematic liquid crystal. Adapted from code originally written by Sophie Ettinger and adapted for open-Qmin data by Yvonne Zagzag. Functions --------- .. autoapisummary:: open_viewmin.nematic.jones._add_jones_arrows open_viewmin.nematic.jones._add_jones_lambda_arrow open_viewmin.nematic.jones._double_headed_arrow open_viewmin.nematic.jones.add_jones_to_plotter open_viewmin.nematic.jones.add_jones_toolbar_to_plotter open_viewmin.nematic.jones.get_director_data_from_plotter open_viewmin.nematic.jones.get_quarter_wave_plate_jones open_viewmin.nematic.jones.jones_light_propagation_through_sample open_viewmin.nematic.jones.jones_matrices_multiple_wavelengths open_viewmin.nematic.jones.jones_matrix open_viewmin.nematic.jones.list_to_xyz_mat open_viewmin.nematic.jones.n_and_site_types_from_open_qmin open_viewmin.nematic.jones.permute_axes open_viewmin.nematic.jones.polarizer_matrix_from_angle open_viewmin.nematic.jones.pom_animation_rotate_polarizers open_viewmin.nematic.jones.pom_image_color open_viewmin.nematic.jones.pom_image_one_wavelength open_viewmin.nematic.jones.pom_image_sequence_rotate_polarizers open_viewmin.nematic.jones.rgb_to_texture open_viewmin.nematic.jones.rotation_matrix_2d open_viewmin.nematic.jones.rotation_transform open_viewmin.nematic.jones.save_jones_data open_viewmin.nematic.jones.save_jones_data_gui open_viewmin.nematic.jones.save_jones_images open_viewmin.nematic.jones.save_jones_images_gui Module Contents --------------- .. py:function:: _add_jones_arrows(plotter, coord_index, center, actor_name) Add arrows for polarizer and analyzer directions and, if applicable, quarter-wave plate direction :param plotter: :type plotter: :class:`~open_viewmin.nematic.nematic_plot.nematic_plot_no_qt.NematicPlotNoQt` :param coord_index: :type coord_index: int :param center: :type center: Iterable of [float] :param actor_name: :type actor_name: str .. py:function:: _add_jones_lambda_arrow(plotter, p_dir, a_dir, jones_arrows_scale, arrows_center, lambda_arrow_actor_name) Add arrow indicating orientation of quarter-wave plate :param plotter: :type plotter: :class:`~open_viewmin.nematic.nematic_plot.nematic_plot_no_qt.NematicPlotNoQt` :param p_dir: :type p_dir: Iterable of [float] :param a_dir: :type a_dir: Iterable of [float] :param jones_arrows_scale: :type jones_arrows_scale: float :param arrows_center: :type arrows_center: Iterable of [float] :param lambda_arrow_actor_name: :type lambda_arrow_actor_name: str .. py:function:: _double_headed_arrow(center, direction, **kwargs) :param center: :type center: Iterable of [float] :param direction: :type direction: Iterable of [float] :param kwargs: Keyword arguments to `pyvista.Arrow` :type kwargs: dict, optional :rtype: `(pyvista.Arrow, pyvista.Arrow)` .. py:function:: add_jones_to_plotter(plotter, n=None, site_types=None) Add planes to back of box, colored by RGB Jones matrix transmission and normal to x, y, z. :param plotter: :type plotter: :class:`~open_viewmin.nematic.nematic_plot.NematicPlot` or :class:`~open_viewmin.nematic.nematic_plot.NematicPlotNoQt` :param n: director data; if `None`, director will be taken from plotter :type n: numpy.ndarray or `None`, optional :param site_types: site types data; if `"off"`, all sites are taken to be bulk; if `None`, site types data will be taken from plotter :type site_types: numpy.ndarray, `"off"`, or `None` .. py:function:: add_jones_toolbar_to_plotter(plotter, n=None, site_types=None) Add planes to back of box, colored by RGB Jones matrix transmission and normal to x, y, z, with polarizer/analyzer angles and brightness controlled by sliders. :param plotter: :type plotter: open_viewmin.NematicPlot :param n: director data; if `None`, director will be taken from plotter :type n: numpy.ndarray or None, optional :param site_types: site types data; if `"off"`, all sites are taken to be bulk; if `None`, site types data will be taken from plotter :type site_types: numpy.ndarray, `"off"`, or `None` :returns: callback that refreshes Jones planes by re-applying the control slider widgets :rtype: callable() .. py:function:: get_director_data_from_plotter(plotter, n, site_types) Use plotter's existing nematic director data for Jones matrix calculations :param plotter: :type plotter: open_viewmin.NematicPlot or open_viewmin.NematicPlotNoQt :param n: nematic director field in flattened array; if `None`, data is taken from plotter :type n: numpy.ndarray or `None` :param site_types: site types in flattened array; if `"off"`, all sites are treated as bulk; if `None`, data is taken from plotter :type site_types: numpy.ndarray, `"off"`, or `None` :returns: reshaped arrays of nematic director and site types data :rtype: numpy.ndarray, numpy.ndarray .. py:function:: get_quarter_wave_plate_jones(angle) Apply quarter-wave plate transformation to Jones matrix :param angle: :type angle: float :rtype: numpy.ndarray .. py:function:: jones_light_propagation_through_sample(director, site_types, wavelength=6.6e-07, res=4.5e-08, n_ord=1.55, n_ext=1.7, optical_axis='z', n_bdy=1.333) Calculate Jones matrix product for light propagation through nematic sample. :param director: nematic director field :type director: numpy.ndarray :param site_types: array of site types (bulk, boundary, or surface) for the lattice :type site_types: numpy.ndarray :param wavelength: wavelength of incident light, in meters :type wavelength: float :param res: lattice resolution, in meters :type res: float :param n_ord: ordinary index of refraction :type n_ord: float :param n_ext: extraordinary index of refraction :type n_ext: float :param optical_axis: light propagation direction :type optical_axis: 'x', 'y', or 'z', optional :param n_bdy: isotropic index of refraction inside boundary :type n_bdy: float or sequence of floats :returns: Jones matrix for light propagation through the entire simulation box :rtype: numpy.ndarray .. py:function:: jones_matrices_multiple_wavelengths(n, site_types, wavelengths=(6.38e-07, 5.32e-07, 4.65e-07), **kwargs) Calculate list of Jones matrices for a sequence of wavelengths. :param n: nematic director field :type n: numpy.ndarray :param site_types: array of site types (bulk, boundary, surface) :type site_types: numpy.ndarray :param wavelengths: wavelengths in meters :type wavelengths: sequence of floats :param \*\*kwargs: keyword arguments accepted by `jones_light_propagation_through_sample` :returns: list of Jones matrix arrays :rtype: list(numpy.ndarray) .. py:function:: jones_matrix(n_phi, phi_ext, phi_ord) Calculate Jones matrix array for one slice at constant z. :param n_phi: azimuthal angle of director in plane transverse to light propagation :type n_phi: numpy.ndarray :param phi_ext: array of local-frame complex Jones matrices for effective extraordinary index of refraction :type phi_ext: numpy.ndarray :param phi_ord: local-frame complex Jones matrix for ordinary index of refraction :type phi_ord: numpy.ndarray :returns: array of lab-frame complex Jones matrices :rtype: numpy.ndarray .. py:function:: list_to_xyz_mat(data, dims) Convert a flattened data array to shape `(Lx, Ly, Lz, ...)`. :param data: :type data: numpy.ndarray :param dims: :type dims: (int, int, int) :rtype: numpy.ndarray .. py:function:: n_and_site_types_from_open_qmin(filename) Import Q-tensor data in the open-Qmin data_format :param filename: Filename of open-Qmin-style data. :type filename: str :returns: director, site_types arrays :rtype: numpy.ndarray, numpy.ndarray .. py:function:: permute_axes(arr, axis_name) Permute coordinate axes so that the optical axis corresponds to axis_name :param arr: :type arr: numpy.ndarray :param axis_name: :type axis_name: 'x', 'y', or 'z' :rtype: numpy.ndarray .. py:function:: polarizer_matrix_from_angle(angle) Calculate projection matrix along a polarizer's direction in the xy plane. :param angle: angle of polarizer with respect to x-axis (after permuting axes so that z is the light propagation direction) :type angle: float :returns: polarizer projection matrix :rtype: numpy.ndarray .. py:function:: pom_animation_rotate_polarizers(plotter, n=None, site_types='off', interval=50, filename=None, **kwargs) Create video of simulated polarized optical microscopy images with polarizer and analyzer rotating linearly in time through total angle pi/2. :param plotter: :type plotter: open_viewmin.NematicPlot or open_viewmin.NematicPlotNoQt :param n: nematic director data; if `None`, this data is taken from the plotter :type n: numpy.ndarray or None, optional :param site_types: site types data; if `"off"`, all sites are treated as bulk; if `None`, data is taken from plotter :type site_types: numpy.ndarray, `"off"`, or `None`, optional :param interval: number of milliseconds between frames of animation :type interval: int, optional :param filename: filename for exported video; if `None`, no export occurs and the function returns the full HTML string for the video :type filename: str or `None`, optional :param kwargs: keyword arguments accepted by `pom_image_sequence_rotate_polarizers` :type kwargs: dict, optional :returns: filename of exported video or full HTML string defining the video :rtype: str .. py:function:: pom_image_color(jones_mats, polarizer_angle=0.0, analyzer_angle=None, brightness_factor=1, use_quarter_wave_plate=False) Given Jones matrices for red, green, and blue light propagation, generate rgb array (float values in [0, 1]) for a simulated color polarized optical microscopy image. :param jones_mats: list of three Jones matrix products for propagation of red, green, and blue light (respectively) through the entire sample :type jones_mats: Iterable of [numpy.ndarray] :param polarizer_angle: angle of polarizer :type polarizer_angle: float :param analyzer_angle: angle of analyzer :type analyzer_angle: float :param brightness_factor: multiplier for intensity :type brightness_factor: float :param use_quarter_wave_plate: whether to insert a quarter wave plate, oriented at a 45-degree counterclockwise rotation from the polarizer, between the polarizer and the sample :type use_quarter_wave_plate: bool, optional :returns: 2D array of rgb values for transmitted light :rtype: numpy.ndarray .. py:function:: pom_image_one_wavelength(jones_mat_product, p_angle, a_angle, use_quarter_wave_plate=False) Simulated polarized optical microscopy image using a single wavelength of light. :param jones_mat_product: array of Jones matrix products for light propagation through the entire sample :type jones_mat_product: numpy.ndarray :param p_angle: angle of polarizer with respect to x-axis (after permuting axes so that light propagates along z) :type p_angle: float :param a_angle: angle of analyzer with respect to x-axis (after permuting axes so that light propagates along z) :type a_angle: float :param use_quarter_wave_plate: whether to insert a quarter wave plate, oriented at a 45-degree counterclockwise rotation from the polarizer, between the polarizer and the sample :type use_quarter_wave_plate: bool, optional :returns: 2D array of transmitted intensities :rtype: numpy.ndarray .. py:function:: pom_image_sequence_rotate_polarizers(ax, n, site_types, num_frames=10, brightness_factor=1, **kwargs) Create image sequence of simulated polarized optical microscopy images with polarizer and analyzer rotating linearly in time through total angle pi/2. :param ax: figure axes :type ax: matplotlib.axes :param n: nematic director field in flattened array; if `None`, data is taken from plotter :type n: numpy.ndarray or `None` :param site_types: site types in flattened array; if `"off"`, all sites are treated as bulk; if `None`, data is taken from plotter :type site_types: numpy.ndarray, `"off"`, or `None` :param num_frames: number of subdivisions of the [0, pi/2] interval for the polarizer angle, and thus the number of frames in the animation :type num_frames: int, optional :param brightness_factor: multiplier for intensity :type brightness_factor: float, optional :param kwargs: keyword arguments accepted by `jones_matrices_multiple_wavelengths` :type kwargs: dict, optional :returns: list of transmitted intensity images :rtype: list(matplotlib.axes.Axes.imshow) .. py:function:: rgb_to_texture(rgb_data, sigma=1.0) Transform 2D NumPy float rgb array to PyVista texture :param rgb_data: 2D array of (red, green, blue) intensities, each in the interval [0, 1] :type rgb_data: numpy.ndarray :param sigma: smoothing factor for Gaussian filter; set to 1. for no filter. :type sigma: float, optional :rtype: pyvista.Texture .. py:function:: rotation_matrix_2d(angle) Calculate 2x2 rotation matrix :param angle: rotation angle or array thereof :type angle: float or numpy.ndarray :returns: rotation matrix or array thereof :rtype: numpy.ndarray .. py:function:: rotation_transform(mat, rot_mat) Calculate M' = R M R^T for given matrix M and rotation matrix R. :param mat: Array of matrices *M*. :type mat: numpy.ndarray :param rot_mat: Rotation matrix *R*. :type rot_mat: numpy.ndarray :returns: Array of rotated matrices :rtype: numpy.ndarray .. py:function:: save_jones_data(plotter, filename: str) Saves numerical Jones matrix data to files :param plotter: :type plotter: :class:`~open_viewmin.nematic.nematic_plot.nematic_plot_no_qt.NematicPlotNoQt` :param filename: :type filename: str .. py:function:: save_jones_data_gui(plotter, filename=None) Launch dialog to save numerical Jones matrix data to files :param plotter: :type plotter: :class:`~open_viewmin.nematic.nematic_plot.nematic_plot.NematicPlot` :param filename: :type filename: str | `None` .. py:function:: save_jones_images(plotter, filename: str) Save Jones matrix images to files :param plotter: :type plotter: :class:`~open_viewmin.nematic.nematic_plot.nematic_plot_no_qt.NematicPlotNoQt` :param filename: :type filename: str .. py:function:: save_jones_images_gui(plotter, filename=None) Launch dialog to save Jones matrix images to files :param plotter: :type plotter: :class:`~open_viewmin.nematic.nematic_plot.nematic_plot.NematicPlot` :param filename: :type filename: str | `None`