Simple example#
The example below shows how to create a custom eye model from clinical parameters, build it in OpticStudio, and interact with the model.
Import visisipy and other dependencies#
import matplotlib.pyplot as plt
import seaborn as sns
import visisipy
# Use the open-source Optiland backend for calculations; to use OpticStudio, replace
# "optiland" with "opticstudio"
visisipy.set_backend("optiland")
Define and build the eye model#
Yes, it’s only two lines of code!
# Initialize the default Navarro model
model = visisipy.EyeModel()
# Build the model in OpticStudio
model.build()
Perform a raytrace analysis#
# List of (x, y) coordinates
coordinates = [(0, 0), (0, 10), (0, 20), (0, 30), (0, 40)]
raytrace = visisipy.analysis.raytrace(coordinates=coordinates)
# Alternatively, the model can be built and analyzed in one go:
# raytrace = visisipy.analysis.raytrace(model, coordinates=zip([0] * 5, range(0, 60, 10)))
/home/docs/checkouts/readthedocs.org/user_builds/visisipy/checkouts/latest/visisipy/optiland/analysis/raytrace.py:111: UserWarning: Field coordinate (0, 10) not found. Adding it to the system.
normalized_field = set_field(backend, field, field_type)
/home/docs/checkouts/readthedocs.org/user_builds/visisipy/checkouts/latest/visisipy/optiland/analysis/raytrace.py:111: UserWarning: Field coordinate (0, 20) not found. Adding it to the system.
normalized_field = set_field(backend, field, field_type)
/home/docs/checkouts/readthedocs.org/user_builds/visisipy/checkouts/latest/visisipy/optiland/analysis/raytrace.py:111: UserWarning: Field coordinate (0, 30) not found. Adding it to the system.
normalized_field = set_field(backend, field, field_type)
/home/docs/checkouts/readthedocs.org/user_builds/visisipy/checkouts/latest/visisipy/optiland/analysis/raytrace.py:111: UserWarning: Field coordinate (0, 40) not found. Adding it to the system.
normalized_field = set_field(backend, field, field_type)
Visualize the eye model and the raytrace results#
fig, ax = plt.subplots()
visisipy.plots.plot_eye(ax, model.geometry, lens_edge_thickness=0.5)
sns.lineplot(raytrace, x="z", y="y", hue="field", ax=ax)
sns.move_legend(ax, loc="lower right", title="Field")