6.11. gui Submodule

6.11.1. gui.command_window

class optrace.gui.command_window.CommandWindow(gui)

Initialize the command window

Parameters:

gui (TraceGUI) – parent TraceGUI

clear_history(event=None)

clear command history :param event: optional trait change event

Parameters:

event (TraitChangeEvent)

Return type:

None

copy_history(event=None)

copy the full history to the clipboard :param event: optional trait change event

Parameters:

event (TraitChangeEvent)

Return type:

None

send_command(event=None)

Execute the entered command in the TraceGUI

Parameters:

event (TraitChangeEvent) – optional trait change event

Return type:

None

automatic_replot: List

Option for automatic replotting/recalculating the geometry after running the command

cmd: Str

command to run

history: List

command history

6.11.2. gui.property_browser

class optrace.gui.property_browser.PropertyBrowser(gui)

Initialize a PropertyBrowser

Parameters:

gui (TraceGUI) – reference to the TraceGUI

update_dict(event=None)

Update the dictionaries in all ValueEditor()

Parameters:

event (TraitChangeEvent) – optional trait change event

Return type:

None

6.11.3. gui.trace_gui

class optrace.gui.trace_gui.TraceGUI(raytracer, initial_camera={}, **kwargs)

Create a new TraceGUI with the assigned Raytracer.

Parameters:
  • RT – raytracer

  • initial_camera (dict) – parameter dictionary for set_camera

  • kwargs – additional arguments, options, traits and parameters

  • raytracer (Raytracer)

add_custom_button(name, function)

Add a custom button with an action to the “custom” GUI tab.

Parameters:
  • name (str) – Name of the button / shown label text

  • function (Callable) – function to call when the button is pressed. Function without parameters.

Return type:

None

add_custom_checkbox(name, val, function=None)

Add a custom checkbox with an action to the “custom” GUI tab.

Parameters:
  • name (str) – Name of the checkbox / shown label

  • val (bool) – if the box is checked in its default state

  • function (Callable) – function to call when box state is changed (optional). Exactly one boolean parameter.

Return type:

None

add_custom_selection(name, list_, val, function=None)

Add a custom selection field with an action to the “custom” GUI tab.

Parameters:
  • name (str) – Name of the checkbox / shown label text

  • list – list of selectable string

  • val (str) – default selection

  • function (Callable) – function to call when selection is changed (optional). Exactly one string parameter.

  • list_ (list[str])

Return type:

None

add_custom_value(name, val, function=None)

Add a custom float value field with an action to the “custom” GUI tab.

Parameters:
  • name (str) – Name of the field / shown label text

  • val (float) – default value

  • function (Callable) – function to call when the value is changed (optional). Exactly one float parameter.

Return type:

None

close(event=None)

Close the whole application.

Parameters:

event (TraitChangeEvent) – optional trait change event

Return type:

None

control(func, args=(), kwargs={})

Interact with the TraceGUI. Function ‘func’ is executed in the main thread after the TraceGUI is loaded.

Parameters:
  • func (Callable) – function to execute

  • args (tuple) – positional arguments for func

  • kwargs (dict) – keyword arguments for func

Return type:

None

custom_button_action_1()
Returns:

function assigned with custom button 1

Return type:

Callable

custom_button_action_2()
Returns:

function assigned with custom button 2

Return type:

Callable

custom_button_action_3()
Returns:

function assigned with custom button 3

Return type:

Callable

debug(func, args=(), kwargs={})

Control the GUI from a separate thread.

Parameters:
  • func (Callable) – thread function to execute while the GUI is active

  • args (tuple) – positional arguments for func

  • kwargs (dict) – keyword arguments for func

Return type:

None

detector_image(event=None, profile=False, extent=None, **kwargs)

Render a detector image at the chosen Detector, uses a separate thread.

Parameters:
  • event – optional trait change event

  • profile (bool) – if a Image profile image is plotted

  • extent (list | ndarray) – image extent, see Raytracer.detector_image()

  • kwargs – additional keyword arguments for r_image_plot

Return type:

None

detector_profile(event=None, extent=None, **kwargs)

Plot a detector image profile.

Parameters:
  • event – optional trait change event

  • extent (list | ndarray) – image extent, see Raytracer.detector_image()

  • kwargs – additional keyword arguments for image_profile_plot

Return type:

None

detector_spectrum(event=None, extent=None, **kwargs)

Render a Detector Spectrum for the chosen Source, uses a separate thread.

Parameters:
  • event (TraitChangeEvent) – optional trait change event

  • extent (list | ndarray) – image extent, see Raytracer.detector_image()

  • kwargs – additional keyword arguments for spectrum_plot

Return type:

None

get_camera()

Get the camera parameters that can be passed down to set_camera()

Returns:

Return the current camera parameters (center, height, direction, roll)

Return type:

tuple[ndarray, float, ndarray, float]

move_to_focus(event=None, **kwargs)

Find a Focus. The chosen Detector defines the search range for focus finding. Searches are always between lenses or the next outline. Search takes place in a separate thread, after that the Detector is moved to the focus

Parameters:
  • event (TraitChangeEvent) – optional trait change event

  • kwargs – additional keyword arguments for focus_search_cost_plot

Return type:

None

open_command_window(event=None)

Open the command window for executing code.

Parameters:

event (TraitChangeEvent) – optional trait change event

Return type:

None

open_documentation(event=None)

Open the online documentation https://drocheam.github.io/optrace in a browser

Parameters:

event (TraitChangeEvent) – optional trait change event

Return type:

None

open_property_browser(event=None)

Open a property browser for the gui, the scene, the raytracer, shown rays and cardinal points.

Parameters:

event (TraitChangeEvent) – optional trait change event

Return type:

None

pick_ray(index)

Pick a ray with index ‘index’. The selected ray is highlighted.

Parameters:

index (int) – is the index of the displayed rays.

Return type:

None

pick_ray_section(index, section, detailed=False)

Pick a ray with index ‘index’ at intersection number ‘section’. A ray highlight plot, crosshair and ray info text are shown.

Parameters:
  • index (int) – is the index of the displayed rays.

  • section (int) – intersection index (starting position is zero)

  • detailed (bool) – If ‘detailed’ is set, a more detailed ray info text is shown

Return type:

None

process()

Force an update to traits and unprocessed events.

Return type:

None

replot(change=None)

replot all or part of the geometry and scene. If the change dictionary is not provided, everything is replotted according to the raytracer geometry

Parameters:

change (dict) – optional change dict from raytracer.compare_property_snapshot

Return type:

None

replot_rays(event=None, mask=None, max_show=None)

choose a subset of all raytracer rays and plot them with :TraceGUI._plot_rays.

By default, a random subset is selected. When mask and max_show (both optional) are provided, a specific subset is displayed. See TraceGUI.select_rays.

Parameters:
  • event (TraitChangeEvent) – optional trait change event

  • mask (ndarray) – boolean array for which rays to display. Shape must equal the number of currently traced rays.

  • max_show (int) – maximum number of rays to display

Return type:

None

reset_picking()

Hide/reset the displayed picker objects. Hides the ray info text, ray highlight and crosshair that have been created with TraceGUI.pick_ray or TraceGUI.pick_ray_section

Return type:

None

retrace(event=None)

raytrace in separate thread, after that call TraceGUI.replot_rays.

Parameters:

event (TraitChangeEvent) – optional trait change event

Return type:

None

run()

Run the TraceGUI

Return type:

None

run_command(cmd)

send/execute a command

Parameters:

cmd (str)

Return type:

None

screenshot(path, **kwargs)

Save a screenshot of the scene. Passes the parameters down to the mlab.savefig function. See https://docs.enthought.com/mayavi/mayavi/auto/mlab_figure.html#savefig for parameters.

Parameters:

path (str)

Return type:

None

select_rays(mask, max_show=None)

Apply a specific selection of rays for display. If the number is too large it is either limited by the ‘max_show’ parameter or a predefined limit.

Parameters:
  • mask (ndarray) – boolean array for which rays to display. Shape must equal the number of currently traced rays.

  • max_show (int) – maximum number of rays to display

Return type:

None

set_camera(center=None, height=None, direction=None, roll=None)

Sets the camera view. Not all parameters must be defined, setting single properties is also allowed.

Parameters:
  • focal_point – 3D position of camera focal point, also defines the center of the view

  • parallel_scale – view scaling. Defines half the size of the view in vertical direction.

  • center (ndarray) – 3D coordinates of center of view

  • height (float) – half of vertical height in mm

  • direction (list) – camera view direction vector (direction of vector perpendicular to your monitor and in your viewing direction)

  • roll (float) – absolute camera roll angle

Return type:

None

smart_replot(automatic_replot=True)

This contextmanager makes a property snapshot of the raytracer before and after a specific action. If changes are detected. the corresponding elements are updated.

Parameters:

automatic_replot (bool) – if automatic replotting should be executed

Return type:

None

source_image(event=None, profile=False, **kwargs)

Render a source image for the chosen Source, uses a separate thread

Parameters:
  • event – optional trait change event

  • profile (bool) – if an Image profile plot is plotted

  • kwargs – additional keyword arguments for image_plot

Return type:

None

source_profile(event=None, **kwargs)

Plot a source image profile.

Parameters:
  • event – optional trait change event

  • kwargs – additional keyword arguments for image_profile_plot

Return type:

None

source_spectrum(event=None, **kwargs)

render a Source Spectrum for the chosen Source, uses a separate thread.

Parameters:
  • event (TraitChangeEvent) – optional trait change event

  • kwargs – additional keyword arguments for spectrum_plot

Return type:

None

activate_filter: List

gaussian blur filter estimating resolution limit

property busy: bool

busy state flag of TraceGUI

coloring_mode: Enum

Ray Coloring Mode

coloring_modes: list = ['Plain', 'Power', 'Wavelength', 'Source', 'Polarization xz', 'Polarization yz', 'Refractive Index']

available ray coloring modes

custom_checkbox_1: List

First assigned checkbox for custom UI elements

custom_checkbox_2: List

Second assigned checkbox for custom UI elements

custom_checkbox_3: List

Third assigned checkbox for custom UI elements

custom_selection_1: Enum

First assigned selection option for custom UI elements

custom_selection_2: Enum

Second assigned selection option for custom UI elements

custom_selection_3: Enum

Third assigned selection option for custom UI elements

custom_value_1: Float

First assigned value field for custom UI elements

custom_value_2: Float

Second assigned value field for custom UI elements

custom_value_3: Float

Third assigned value field for custom UI elements

detector_image_single_source: List

Use only rays from selected source for the detector image

detector_names: List

short names for raytracer detectors

detector_selection: Enum

Detector Selection. Holds the name of one of the Detectors.

detector_spectrum_single_source: List

Use only rays from selected source for the detector spectrum

filter_constant: Range

gaussian filter constant standard deviation

flip_detector_image: List

Boolean value for flipping the image (rotating it by 180°). Packed as Checkbox into a List

focus_search_method: Enum

Focus Finding Mode from raytracer.focus_search_methods

focus_search_single_source: List

Use only rays from selected source for focus finding

hide_labels: List

Shows or hides object labels

high_contrast: List

high contrast mode without object colors and with white background

image_mode: Enum

Image Type

image_pixels: Enum

Image Pixel value for Source/Detector Image. This the number of pixels for the smaller image side.

log_image: List

Boolean value for a logarithmic image visualization. Packed as Checkbox into a List

maximize_scene: List

maximize mode. Menu and toolbar hidden

minimalistic_view: List

More minimalistic scene view. Axes are hidden and labels shortened.

plot_cost_function: List

Show a plot of the optimization cost function for the focus finding

plotting_mode: Enum

Ray Plotting Type

plotting_modes: list = ['Rays', 'Points']

available ray representations

profile_position: Float

numeric profile position value for chosen image profile dimension

profile_position_dimension: Enum

dimension for the image profile position

projection_method: Enum

sphere surface projection method

projection_method_enabled: Bool = False

if method is selectable, only the case for spherical detectors

ray_count: Range

Number of rays for raytracing

ray_opacity: Range

opacity of shown ray

property ray_selection: ndarray
Returns:

boolean array for which of the traced rays in TraceGUI.raytracer.rays are displayed currently

ray_width: Range

Width of rays shown.

rays_visible: Range

Number of rays shown in mayavi scene

raytracer: Raytracer

reference to the raytracer

scene: Instance

the mayavi scene

source_names: List

short names for raytracer ray sources

source_selection: Enum

Source Selection. Holds the name of one of the Sources.

vertical_labels: List

in geometries with tight geometry and long descriptions one could want to display the labels vertically

view

the UI view

z_det: Range

z-Position of Detector. Lies inside z-range of Raytracer.outline