Sample YAML File Reader with Schema
We start by defining the file input locations. Note that your file locations will likely be different. At the final step, initialise the ‘Imager’ object from the files.
[4]:
# If opticks import fails, try to locate the module
# This can happen building the docs
import os
try:
import importlib.util
if importlib.util.find_spec("opticks") is None:
raise ModuleNotFoundError
except ModuleNotFoundError:
os.chdir(os.path.join("..", ".."))
os.getcwd()
[5]:
from pathlib import Path
from opticks.imaging_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)
optics file exists: True
detector file exists: True
Let’s get some sample output values for the optics.
[6]:
# shorthand
optics = imager.optics
# basic params
print(f"name : {optics.name}")
print(f"focal length : {optics.focal_length}")
print(f"aperture diameter : {optics.aperture_diameter}")
print(f"image diameter on focal plane : {optics.image_diam_on_focal_plane}")
# derived params
print(f"f-number : {optics.f_number:.4}")
print(f"full optical fov : {optics.full_optical_fov:.4}")
print(f"aperture area : {optics.aperture_area:.6}")
name : Sample Reflective Optics
focal length : 300.0 mm
aperture diameter : 130.0 mm
image diameter on focal plane : 12.3 mm
f-number : 2.308
full optical fov : 2.349 deg
aperture area : 13273.2 mm2