用Python做一个手机镜头
文章目录
- 设置光学参数
- 添加光学器件
设置光学参数
官方文档:设计手机镜头
rayoptics中提供了OpticalModel类,可用于创建光学模型对象。OpticalModel类中的【optical_spec】成员,是一个OpticalSpecs对象,可用于指定光圈、视野、光谱和焦点位置等信息。
from rayoptics.environment import *opm = OpticalModel()
osp = opm.optical_specosp.title = 'Cell Phone Lens'
osp.dimensions = 'mm'
osp.pupil = PupilSpec(osp, key=['image', 'f/#'], value=3.5)
osp.fov = FieldSpec(osp, key=['image', 'height'], value=3.5, is_relative=True, flds=[0., .7071, 1])
osp.wvls = WvlSpec([('F', 0.5), ('d', 1.0), ('C', 0.5)], ref_wl=1)
上述代码中,
- 【PupilSpec】即孔径,其值为3.5,key表示孔径类型,[‘image’, ‘f/#’]表示以像面F数为主
- 【FieldSpec】即视场,其值为3.5,key表示视场类型,[‘image’, ‘height’]表示像面高度。
- 【WvlSpec】即波长,其输入为波长列表,其中F(氢蓝线)、d(氦黄线)、c(氢红线)的权重分别为0.5,1,0.5。
添加光学器件
opm中提供的seq_model成员,是一个SequentialModel对象,可用于定义接口和间隙,光通过这些接口和间隙传播形成图像,示意如下,其中【Ifc】为接口,【G】表示间隙。
IfcObj Ifc1 Ifc2 Ifc3 ... Ifci-1 IfcImg\ / \ / \ / \ /GObj G1 G2 Gi-1
下面通过成员函数【add_surface】为模型添加光学表面,以设计如下镜头
【add_surface】其输入参数为列表,列表中元素含义为
- curvature,即曲率,若如果 radius_mode 为 True, 则为曲率半径。
- thickness,即厚度,该表面到下一个表面的距离,单位 mm。
- v-number,一般为折射率。
- semi-diameter,半径。
代码如下
sm = opm.seq_model
opm.radius_mode = Truesm.gaps[0].thi=1e10sm.add_surface([0., 0.])
sm.set_stop()sm.add_surface([1.962, 1.19, 1.471, 76.6])
sm.ifcs[sm.cur_surface].profile = RadialPolynomial(r=1.962, ec=2.153,coefs=[0., 0., -1.895e-2, 2.426e-2, -5.123e-2, 8.371e-4, 7.850e-3, 4.091e-3, -7.732e-3, -4.265e-3])sm.add_surface([33.398, .93])
sm.ifcs[sm.cur_surface].profile = RadialPolynomial(r=33.398, ec=40.18,coefs=[0., 0., -4.966e-3, -1.434e-2, -6.139e-3, -9.284e-5, 6.438e-3, -5.72e-3, -2.385e-2, 1.108e-2])sm.add_surface([-2.182, .75, 1.603, 27.5])
sm.ifcs[sm.cur_surface].profile = RadialPolynomial(r=-2.182, ec=2.105,coefs=[0., 0., -4.388e-2, -2.555e-2, 5.16e-2, -4.307e-2, -2.831e-2, 3.162e-2, 4.630e-2, -4.877e-2])sm.add_surface([-6.367, 0.1])
sm.ifcs[sm.cur_surface].profile = RadialPolynomial(r=-6.367, ec=3.382,coefs=[0., 0., -1.131e-1, -7.863e-2, 1.094e-1, 6.228e-3, -2.216e-2, -5.89e-3, 4.123e-3, 1.041e-3])sm.add_surface([5.694, .89, 1.510, 56.2])
sm.ifcs[sm.cur_surface].profile = RadialPolynomial(r=5.694, ec=-221.1,coefs=[0., 0., -7.876e-2, 7.02e-2, 1.575e-3, -9.958e-3, -7.322e-3, 6.914e-4, 2.54e-3, -7.65e-4])sm.add_surface([9.192, .16])
sm.ifcs[sm.cur_surface].profile = RadialPolynomial(r=9.192, ec=0.9331,coefs=[0., 0., 9.694e-3, -2.516e-3, -3.606e-3, -2.497e-4, -6.84e-4, -1.414e-4, 2.932e-4, -7.284e-5])sm.add_surface([1.674, .85, 1.510, 56.2])
sm.ifcs[sm.cur_surface].profile = RadialPolynomial(r=1.674, ec=-7.617,coefs=[0., 0., 7.429e-2, -6.933e-2, -5.811e-3, 2.396e-3, 2.100e-3, -3.119e-4, -5.552e-5, 7.969e-6])sm.add_surface([1.509, .70])
sm.ifcs[sm.cur_surface].profile = RadialPolynomial(r=1.509, ec=-2.707,coefs=[0., 0., 1.767e-3, -4.652e-2, 1.625e-2, -3.522e-3, -7.106e-4, 3.825e-4, 6.271e-5, -2.631e-5])sm.add_surface([0., .40, 1.516, 64.1])
sm.add_surface([0., .64])opm.update_model()
sm.do_apertures = False
sm.list_model()
对模型进行罗列的结果为
r t medium mode zdr sdObj: 0.000000 1.00000e+10 air dummy 1 1.7455e+08Stop: 0.000000 0.00000 air 1 0.793582: 1.962000 1.19000 471.766 1 0.796453: 33.398000 0.930000 air 1 0.672434: -2.182000 0.750000 603.275 1 0.511955: -6.367000 0.100000 air 1 0.510076: 5.694000 0.890000 510.562 1 0.493557: 9.192000 0.160000 air 1 0.419758: 1.674000 0.850000 510.562 1 0.400099: 1.509000 0.700000 air 1 0.2846010: 0.000000 0.400000 516.641 1 0.2035711: 0.000000 0.640000 air 1 0.17198Img: 0.000000 0.00000 dummy 1 0.10146
绘图代码如下
import matplotlib.pyplot as plt
layout_plt0 = plt.figure(FigureClass=InteractiveLayout, opt_model=opm,do_draw_rays=True, do_paraxial_layout=False, is_dark=False).plot()
plt.show()