def getLensFromUI(self): """ Get lens parameters from UI """ # lens name lens = Lens() lens.name = self.ui.listWidget_Lens.currentItem().text() # both surface lens.left = self.getSurfaceFromUI('left') lens.right = self.getSurfaceFromUI('right') # material lens.material = self.ui.lineEdit_Material.text() # thickness try: lens.thickness = float(self.ui.lineEdit_Thickness.text()) except ValueError: lens.thickness = 0.0 # description lens.description = self.ui.textEdit_Description.toPlainText() return lens
def addNewLens(self, lens=None): """ Adds a new lens to the list """ if lens is None: new_lens = Lens() new_lens.name = "New Lens" else: new_lens = lens self.ui.listWidget_Lens.addItem(new_lens.name) item = self.ui.listWidget_Lens.item(self.ui.listWidget_Lens.count() - 1) item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable) self.lens_list.append(new_lens)
def loadFile(self, filepath=""): self.disconnectAll() self.lens_list.clear() self.ui.listWidget_Lens.clear() with open(filepath) as f: dataset = json.load(f) lens_count = int(dataset['lens_count']) for i in range(lens_count): lens_dict = dataset[str(i)] lens = Lens() lens.from_dict(lens_dict) self.addNewLens(lens) self.connectAll() self.currentFile = filepath QtWidgets.QMessageBox.information(self, "Info", "JSON file has bben loaded")
class TestLens(unittest.TestCase): def setUp(self): self.lens1 = Lens(123456789,30.0,60.0,100.0,100.0,2009.0) self.lens2 = Lens(11111111,31.0,61.0,101.0,102.0,2009.1) def test_id_init(self): self.assertEqual(self.lens1._id,123456789) self.assertEqual(self.lens2._id,11111111) def test_ra_init(self): self.assertEqual(self.lens1._ra_0,30.0) self.assertEqual(self.lens2._ra_0,31.0) def test_dec_init(self): self.assertEqual(self.lens1._dec_0,60.0) self.assertEqual(self.lens2._dec_0,61.0) def test_pmra_init(self): self.assertEqual(self.lens1._pmra,100.0) self.assertEqual(self.lens2._pmra,101.0) def test_pmdec_init(self): self.assertEqual(self.lens1._pmdec,100.0) self.assertEqual(self.lens2._pmdec,102.0) def test_epoch_init(self): self.assertEqual(self.lens1._epoch_0,2009.0) self.assertEqual(self.lens2._epoch_0,2009.1) def test_get_eq_coord_epoch(self): self.assertAlmostEqual(self.lens1.get_eq_coords_at_epoch(2025.0)[0],15.000444444) self.assertAlmostEqual(self.lens1.get_eq_coords_at_epoch(2025.0)[1],60.000444444) self.assertAlmostEqual(self.lens1.get_eq_coords_at_epoch(1956.0)[0],14.99852778) self.assertAlmostEqual(self.lens1.get_eq_coords_at_epoch(1956.0)[1],59.99852779) self.assertAlmostEqual(self.lens1.get_eq_coords_at_epoch(2017.0)[0],15.00022222) self.assertAlmostEqual(self.lens1.get_eq_coords_at_epoch(2017.0)[1],60.00022222) def test_get_seprations_at_epoch(self): self.assertAlmostEqual(self.lens1.get_angular_separation_at_epoch(2017.0,30.00069760,60.00024),90.4,places=1)
def update(self): # Do calculations before clearing the diagram objLens = Lens(float(self.fObj.get()), float(self.objHeight.get())) eyeLens = Lens(float(self.fEye.get()), float(self.eyeHeight.get())) # Clear the current diagram just before displaying all the newly calculated items. self.diagram.cla() # Plot the rays using the create_rays method dom, rays = self.create_rays(objLens, eyeLens) objLens.draw(0, self.diagram) eyeLens.draw(objLens.fL + eyeLens.fL, self.diagram) for i in range(3): self.diagram.plot(dom[0], rays[0][i], color="red") self.diagram.plot(dom[1], rays[1][i], color="blue") self.diagram.plot(dom[2], rays[2][i], color="green") # Set the title of the ray diagram, show a grid, and finally, display the ray diagram. self.diagram.set_title("Focusing with a Single Lens") self.diagram.grid() self.diagram.legend() self.canvas.draw()
try: import maya.cmds as cmds except ImportError: print 'WARNING (%s): failed to load maya.cmds module.' % __file__ from lens import Lens, ImpureLens # PURE _x_get = lambda (x, _, __): x _x_set = lambda v: lambda (x, y, z): (v, y, z) _x = Lens(_x_get, _x_set) _y_get = lambda (_, y, __): y _y_set = lambda v: lambda (x, y, z): (x, v, z) _y = Lens(_y_get, _y_set) _z_get = lambda (_, __, z): z _z_set = lambda v: lambda (x, y, z): (x, y, v) _z = Lens(_z_get, _z_set) # IMPURE wsGet = lambda tf: tuple(cmds.xform(tf, query=True, worldSpace=True, translation=True)) wsSet = lambda xyz: lambda tf: cmds.xform(tf, worldSpace=True, translation=xyz) lsGet = lambda tf: tuple(cmds.xform(tf, query=True, translation=True)) lsSet = lambda xyz: lambda tf: cmds.xform(tf, translation=xyz)
fig = plt.figure(figsize=(10, 5)) ax = fig.add_subplot(111) def draw_surf(r, d, x0): surf_spot = [] y = np.linspace(0, d / 2, 20) for y_ in y: if r > 0: x = r - np.sqrt(r**2 - y_**2) else: x = r + np.sqrt(r**2 - y_**2) surf_spot.append(x + x0) ax.plot(surf_spot, y, color='000000') ax.plot(surf_spot, -y, color='000000') if __name__ == "__main__": test_lens = Lens() test_lens.Fno = 1.4 test_lens.wavelength_list = 587.562 test_lens.add_surface(number=1, radius=100, thickness=1, glass='BK7') test_lens.add_surface(number=2, radius=-100, thickness=1, glass='1') draw_surf(test_lens.surface_list[0].radius, 10, 0) draw_surf(test_lens.surface_list[1].radius, 10, test_lens.surface_list[0].thickness) plt.show()
m.polygons = mp m.poly2mask() m.smooth() m.maskfft() """nominal ILT setting""" s = Source() s.na = 1.35 s.maskxpitch = 600.0 s.maskypitch = 800.0 s.type = 'annular' s.sigma_in = 0.6 s.sigma_out = 0.8 s.update() s.ifft() o = Lens() o.na = s.na o.maskxpitch = s.maskxpitch o.maskypitch = s.maskypitch o.update() o.calPupil() o.calPSF() t = TCC(s, o) t.calMutualIntensity() t.calSpatTCC() t.svd() i = ImageHopkins(m, t) i.calAI() """robust ILT setting"""
m.poly2mask() m.smooth() m.maskfft() """nominal ILT setting""" s = Source() s.na = 1.35 s.maskxpitch = 600.0 s.maskypitch = 800.0 s.type = 'annular' s.sigma_in = 0.6 s.sigma_out = 0.8 s.update() s.ifft() o = Lens() o.na = s.na o.maskxpitch = s.maskxpitch o.maskypitch = s.maskypitch o.update() o.calPupil() o.calPSF() t = TCC(s,o) t.calMutualIntensity() t.calSpatTCC() t.svd() i = ImageHopkins(m,t) i.calAI()
def setUp(self): self.lens1 = Lens(123456789,30.0,60.0,100.0,100.0,2009.0) self.lens2 = Lens(11111111,31.0,61.0,101.0,102.0,2009.1)