Sample YAML file reader with schema.

Start with the opticks package import (as the notebook sometimes fails to find it)

[16]:
# If opticks import fails, try to locate the module
import os

try:
    import opticks
except ModuleNotFoundError:
    os.chdir(os.path.join("..", ".."))
    os.getcwd()

Now start with code proper with the imports. Then define the file input locations.

You may need to modify the directory locations. At the final step, initialise the ‘Imager’ object from the files.

[17]:
from pathlib import Path

from opticks import u
from opticks.imager_model.imager import Imager

print(f"current working directory: {Path.cwd()}")

file_directory = Path("docs", "examples", "sample_drone_imager")
optics_file_path = file_directory.joinpath("optics.yaml")
detector_file_path = file_directory.joinpath("detector.yaml")

# check whether input files exist
print(f"optics file exists:  {optics_file_path.is_file()}")
print(f"detector file exists:  {detector_file_path.is_file()}")

imager = Imager.from_yaml_file(optics_file_path, detector_file_path, None)
current working directory: c:\Users\EgemenImre\PycharmProjects\opticks
optics file exists:  True
detector file exists:  True

Let’s get some sample output values for the optics.

[18]:
# shorthand
optics = imager.optics

# basic params
print(f"name : {optics.params.name}")
print(f"focal length : {optics.params.focal_length:~}")
print(f"aperture diameter : {optics.params.aperture_diameter:~}")
print(
    f"image diameter on focal plane : {optics.params.image_diam_on_focal_plane:~}"
)

# derived params
print(f"f-number : {optics.f_number:.4}")
print(f"full optical fov : {optics.full_optical_fov:~P.4}")
print(f"aperture area : {optics.aperture_area:~P.6}")
name : Sample Reflective Optics
focal length : 1270 mm
aperture diameter : 25 in
image diameter on focal plane : 27 mm
f-number : 2.0
full optical fov : 1.218 deg
aperture area : 490.874 in²