def create_cemented_doublet(power=0., bending=0., th=None, sd=1., glasses=('N-BK7,Schott', 'N-F2,Schott'), **kwargs): from opticalglass.spectral_lines import get_wavelength from opticalglass import glass wvls = np.array([get_wavelength(w) for w in ['d', 'F', 'C']]) gla_a = gfact.create_glass(glasses[0]) rndx_a = gla_a.calc_rindex(wvls) Va, PcDa = glass.calc_glass_constants(*rndx_a) gla_b = gfact.create_glass(glasses[1]) rndx_b = gla_b.calc_rindex(wvls) Vb, PcDb = glass.calc_glass_constants(*rndx_b) power_a, power_b = achromat(power, Va, Vb) if th is None: th = sd/4 t1 = 3*th/4 t2 = th/4 if power_a < 0: t1, t2 = t2, t1 lens_a = lens_from_power(power=power_a, bending=bending, th=t1, sd=sd, med=gla_a) cv1, cv2, t1, indx_a, sd = lens_a # cv1 = power_a/(rndx_a[0] - 1) # delta_cv = -cv1/2 # cv1 += delta_cv # cv2 = delta_cv # cv3 = power_b/(1 - rndx_b[0]) + delta_cv indx_b = rndx_b[0] cv3 = (power_b/(indx_b-1) - cv2)/((t2*cv2*(indx_b-1)/indx_b) - 1) s1 = Surface(profile=Spherical(c=cv1), max_ap=sd, delta_n=(rndx_a[0] - 1)) s2 = Surface(profile=Spherical(c=cv2), max_ap=sd, delta_n=(rndx_b[0] - rndx_a[0])) s3 = Surface(profile=Spherical(c=cv3), max_ap=sd, delta_n=(1 - rndx_b[0])) g1 = Gap(t=t1, med=gla_a) g2 = Gap(t=t2, med=gla_b) g_tfrm = np.identity(3), np.array([0., 0., 0.]) ifc_list = [] ifc_list.append([0, s1, g1, 1, g_tfrm]) ifc_list.append([1, s2, g2, 1, g_tfrm]) ifc_list.append([2, s3, None, 1, g_tfrm]) ce = CementedElement(ifc_list) tree = ce.tree() return [[s1, g1, None, rndx_a, 1], [s2, g2, None, rndx_b, 1], [s3, None, None, 1, 1]], [ce], tree
def find_glass(self, name, catalog): """ find ``name`` glass or a substitute or, if none found, n=1.5 """ try: if catalog is None or len(catalog) == 0: catalog = gfact._cat_names medium = gfact.create_glass(name, catalog) except glasserror.GlassNotFoundError: pass else: self.track_contents['glass found'] += 1 return medium if self.no_replacements: medium = self.find_substitute_glass(name) if medium is not None: self.track_contents['glass substituted'] += 1 return medium medium = self.handle_glass_not_found(name) if medium is None: self.track_contents['glass not found'] += 1 medium = Medium(1.5, 'not ' + name) return medium
def __call__(self, fig, event): mime = event.mimeData() # comma separated list glass_name, catalog_name = mime.text().split(',') mat = gfact.create_glass(glass_name, catalog_name) self.gap.medium = mat fig.refresh_gui()
def process_glass_data(glass_data): """ process GLA string for fictitious, catalog or private catalog glass """ if isanumber(glass_data): # process as fictitious glass code n, v = fictitious_glass_decode(float(glass_data)) medium = Glass(n, v, '') else: # look for glass name and optional catalog name_cat = glass_data.split('_') if len(name_cat) == 2: name, cat = name_cat elif len(name_cat) == 1: name, cat = glass_data, None if cat is not None: if cat.upper() == 'SCHOTT' and name[:1].upper() == 'N': name = name[:1] + '-' + name[1:] elif cat.upper() == 'OHARA' and name[:1].upper() == 'S': name = name[:1] + '-' + name[1:] if not name[-2:].isdigit() and name[-1].isdigit(): name = name[:-1] + ' ' + name[-1] try: medium = gfact.create_glass(name, cat) except glasserror.GlassNotFoundError as gerr: logging.info('%s glass data type %s not found', gerr.catalog, gerr.name) logging.info('Replacing material with air.') medium = Air() else: # name with no data. default to crown glass global _private_catalog_glasses if name in _private_catalog_glasses: medium = _private_catalog_glasses[name] else: medium = Glass(1.5, 60.0, name) return medium
def test_schott_glass_lf5(self): glass = gf.create_glass('LF5', 'Schott') self.assertIsNotNone(glass.gindex) self.assertEqual(glass.name(), 'LF5') # t_data = glass.transmission_data() # print(glass.gname, glass.gindex, t_data[0][0], t_data[0][1], # t_data[-1][0], t_data[-1][1], len(t_data)) self.compare_transmission(glass, 2325.0, 0.847, 310.0, 0.04, 23)
def test_ohara_glass_slah97(self): glass = gf.create_glass('S-LAH97', 'Ohara') self.assertIsNotNone(glass.gindex) self.assertEqual(glass.name(), 'S-LAH97') # t_data = glass.transmission_data() # print(glass.gname, glass.gindex, t_data[0][0], t_data[0][1], # t_data[-1][0], t_data[-1][1], len(t_data)) self.compare_transmission(glass, 280.0, 0.28, 2400.0, 0.61, 32)
def test_hoya_glass_fd140(self): glass = gf.create_glass('FD140', 'Hoya') self.assertIsNotNone(glass.gindex) self.assertEqual(glass.name(), 'FD140') # t_data = glass.transmission_data() # print(glass.gname, glass.gindex, t_data[0][0], t_data[0][1], # t_data[-1][0], t_data[-1][1], len(t_data)) self.compare_transmission(glass, 1550.0, 0.995, 280.0, 0, 38)
def test_hoya_glass_pcd51(self): glass = gf.create_glass('PCD51', 'Hoya') self.assertIsNotNone(glass.gindex) self.assertEqual(glass.name(), 'PCD51') # t_data = glass.transmission_data() # print(glass.gname, glass.gindex, t_data[0][0], t_data[0][1], # t_data[-1][0], t_data[-1][1], len(t_data)) self.compare_transmission(glass, 2500.0, 0.8, 280.0, 0.145, 44)
def test_hikari_glass_jlasf010(self): glass = gf.create_glass('J-LASF010', 'Hikari') self.assertIsNotNone(glass.gindex) self.assertEqual(glass.name(), 'J-LASF010') # t_data = glass.transmission_data() # print(glass.gname, glass.gindex, t_data[0][0], t_data[0][1], # t_data[-1][0], t_data[-1][1], len(t_data)) self.compare_transmission(glass, 340.0, 0.03, 2400.0, 0.72, 26)
def test_hikari_glass_jlak8(self): glass = gf.create_glass('J-LAK8', 'Hikari') self.assertIsNotNone(glass.gindex) self.assertEqual(glass.name(), 'J-LAK8') # t_data = glass.transmission_data() # print(glass.gname, glass.gindex, t_data[0][0], t_data[0][1], # t_data[-1][0], t_data[-1][1], len(t_data)) self.compare_transmission(glass, 280.0, 0.11, 2400.0, 0.63, 32)
def test_cdgm_glass_hlak51a(self): glass = gf.create_glass('H-LaK51A', 'CDGM') self.assertIsNotNone(glass.gindex) self.assertEqual(glass.name(), 'H-LaK51A') # t_data = glass.transmission_data() # print(glass.gname, glass.gindex, t_data[0][0], t_data[0][1], # t_data[-1][0], t_data[-1][1], len(t_data)) self.compare_transmission(glass, 2400.0, 0.633, 290.0, 0.218, 34)
def test_sumita_glass_kbk7(self): glass = gf.create_glass('K-BK7', 'Sumita') self.assertIsNotNone(glass.gindex) self.assertEqual(glass.name(), 'K-BK7') # t_data = glass.transmission_data() # print(glass.gname, glass.gindex, t_data[0][0], t_data[0][1], # t_data[-1][0], t_data[-1][1], len(t_data)) self.compare_transmission(glass, 270.0, 0.02, 2000.0, 0.959, 27)
def test_sumita_glass_ksk16(self): glass = gf.create_glass('K-SK16', 'Sumita') self.assertIsNotNone(glass.gindex) self.assertEqual(glass.name(), 'K-SK16') # t_data = glass.transmission_data() # print(glass.gname, glass.gindex, t_data[0][0], t_data[0][1], # t_data[-1][0], t_data[-1][1], len(t_data)) self.compare_transmission(glass, 300.0, 0.014, 2000.0, 0.937, 24)
def test_schott_glass_nfk58(self): glass = gf.create_glass('N-FK58', 'Schott') self.assertIsNotNone(glass.gindex) self.assertEqual(glass.name(), 'N-FK58') # t_data = glass.transmission_data() # print(glass.gname, glass.gindex, t_data[0][0], t_data[0][1], # t_data[-1][0], t_data[-1][1], len(t_data)) self.compare_transmission(glass, 2500.0, 0.997, 250.0, 0.09, 30)
def test_schott_glass_nbk7(self): glass = gf.create_glass('N-BK7', 'Schott') self.assertIsNotNone(glass.gindex) self.assertEqual(glass.name(), 'N-BK7') # t_data = glass.transmission_data() # print(glass.gname, glass.gindex, t_data[0][0], t_data[0][1], # t_data[-1][0], t_data[-1][1], len(t_data)) self.compare_transmission(glass, 2500.0, 0.665, 290.0, 0.063, 26)
def create_surface_and_gap(surf_data, radius_mode=False, prev_medium=None, wvl=550.0, **kwargs): """ create a surface and gap where surf_data is a list that contains: [curvature, thickness, refractive_index, v-number] """ s = surface.Surface() if radius_mode: if surf_data[0] != 0.0: s.profile.cv = 1.0 / surf_data[0] else: s.profile.cv = 0.0 else: s.profile.cv = surf_data[0] if len(surf_data) > 2: if isanumber(surf_data[2]): # assume all args are numeric if len(surf_data) < 3: if surf_data[2] == 1.0: mat = m.Air() else: mat = m.Medium(surf_data[2]) else: mat = m.Glass(surf_data[2], surf_data[3], '') else: # string args if surf_data[2].upper() == 'REFL': s.interact_mode = 'reflect' mat = prev_medium else: num_args = len(surf_data[2:]) if num_args == 2: name, cat = surf_data[2], surf_data[3] else: name, cat = surf_data[2].split(',') try: mat = gfact.create_glass(name, cat) except ge.GlassNotFoundError as gerr: logging.info('%s glass data type %s not found', gerr.catalog, gerr.name) logging.info('Replacing material with air.') mat = m.Air() else: # only curvature and thickness entered, set material to air mat = m.Air() thi = surf_data[1] g = gap.Gap(thi, mat) rndx = mat.rindex(wvl) tfrm = np.identity(3), np.array([0., 0., thi]) return s, g, rndx, tfrm
def find_substitute_glass(self, name): """Try to find a similar glass to ``name``.""" # create a list of catalogs # the original lookup didn't find anything so # look in all of our catalogs cat_names = [gc.upper() for gc in self.glass_catalogs] for gc in gfact._cat_names_uc: if gc not in cat_names: cat_names.append(gc) # create a glass list for the given catalogs glist = [] for glass_cat in cat_names: try: glass_cat = gfact.get_glass_catalog(glass_cat) except glasserror.GlassCatalogNotFoundError: pass else: glist += glass_cat.glass_list # Add legacy glasses glist += cat_glass.Robb1983Catalog().glass_list # decode the input name gn_decode = cat_glass.decode_glass_name(name) # build an uppercase version for comparisons gn_decode_uc = gn_decode[0][0].upper() + gn_decode[0][1] subs_glasses = [] for g in glist: gn_decode, gn, gc = g if gn_decode_uc == gn_decode[0][0].upper() + gn_decode[0][1]: subs_glasses.append(g) if len(subs_glasses): possibilities = [gn for gn_decode, gn, gc in subs_glasses] matches = difflib.get_close_matches(name, possibilities) if len(matches) > 0: gn = matches[0] gc = next((g[2] for g in subs_glasses if g[1] == gn), None) else: gn_decode, gn, gc = subs_glasses[0] medium = create_glass(gn, gc) self.glasses_not_found[name] = gn, gc return medium else: return None
def handle_glass_not_found(self, name): """Record missing glasses or create new replacement glass instances.""" if self.no_replacements: # track the number of times self.glasses_not_found[name] += 1 # each missing glass is used return None else: # create a new instance of the replacement glass if name in self.glasses_not_found: val = self.glasses_not_found[name] if len(val) == 2: # call create_glass with name and catalog gn, gc = val return create_glass(gn, gc) else: # eval code to create a new glass instance return eval(self.glasses_not_found[name]) else: return None
def find_substitute_glass(self, name): """Try to find a similar glass to ``name``.""" # create a list of catalogs if len(self.glass_catalogs) > 0: cat_names = self.glass_catalogs else: cat_names = gfact._cat_names # create a glass list for the given catalogs glist = [] for glass_cat in cat_names: try: glass_cat = gfact.get_glass_catalog(glass_cat) except glasserror.GlassCatalogNotFoundError: pass else: glist += glass_cat.glass_list # Add legacy glasses glist += cat_glass.Robb1983Catalog().glass_list # decode the input name gn_decode = cat_glass.decode_glass_name(name) # build an uppercase version for comparisons gn_decode_uc = gn_decode[0][0].upper() + gn_decode[0][1] subs_glasses = [] for g in glist: gn_decode, gn, gc = g if gn_decode_uc == gn_decode[0][0].upper() + gn_decode[0][1]: subs_glasses.append(g) if len(subs_glasses): gn_decode, gn, gc = subs_glasses[0] medium = gfact.create_glass(gn, gc) eval_str = "create_glass('{:s}','{:s}')".format(gn, gc) self.glasses_not_found[name] = eval_str return medium else: return None
def test_schott_glass_sf6ht(self): sf6ht = gf.create_glass('SF6HT', 'Schott') self.assertIsNotNone(sf6ht.gindex) self.assertEqual(sf6ht.name(), 'SF6HT') compare_indices(self, sf6ht, sf6ht.catalog)
""" .. Created on Thu Dec 24 17:17:36 2020 .. codeauthor: Michael J. Hayford """ import warnings from openpyxl import load_workbook from openpyxl import worksheet from opticalglass import ohara import opticalglass.glass as catgl from opticalglass import glassfactory as gfact NBK7 = gfact.create_glass('N-BK7', 'Schott') tdat_nbk7 = NBK7.transmission_data() LaK10 = gfact.create_glass('K-LaK10', 'Sumita') sumita_cat = LaK10.catalog tdat = LaK10.transmission_data() fname = 'OHARA.xlsx' with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=UserWarning) wb = load_workbook(catgl.get_filepath(fname)) ws = wb.active glass_str = 'Glass '
def test_schott_glass_f2(self): f2 = gf.create_glass('F2', 'Schott') self.assertIsNotNone(f2.gindex) self.assertEqual(f2.name(), 'F2') compare_indices(self, f2, f2.catalog)
def test_schott_glass_nbk7(self): nbk7 = gf.create_glass('N-BK7', 'Schott') self.assertIsNotNone(nbk7.gindex) self.assertEqual(nbk7.name(), 'N-BK7') compare_indices(self, nbk7, nbk7.catalog)
def test_ohara_glass_sbsl7(self): sbsl7 = gf.create_glass('S-BSL 7', 'Ohara') self.assertIsNotNone(sbsl7.gindex) self.assertEqual(sbsl7.name(), 'S-BSL 7') compare_indices(self, sbsl7, sbsl7.catalog, tol=6e-6)
def test_ohara_glass_snbh53v(self): glass = gf.create_glass('S-NBH53V', 'Ohara') self.assertIsNotNone(glass.gindex) self.assertEqual(glass.name(), 'S-NBH53V') compare_indices(self, glass, glass.catalog)
def test_ohara_glass_stim2(self): stim2 = gf.create_glass('S-TIM 2', 'Ohara') self.assertIsNotNone(stim2.gindex) self.assertEqual(stim2.name(), 'S-TIM 2') compare_indices(self, stim2, stim2.catalog, tol=6e-6)
def test_hoya_glass_bsc7(self): bsc7 = gf.create_glass('BSC7', 'Hoya') self.assertIsNotNone(bsc7.gindex) self.assertEqual(bsc7.name(), 'BSC7') compare_indices(self, bsc7, bsc7.catalog)
def test_hoya_glass_ef2(self): ef2 = gf.create_glass('E-F2', 'Hoya') self.assertIsNotNone(ef2.gindex) self.assertEqual(ef2.name(), 'E-F2') compare_indices(self, ef2, ef2.catalog)
def test_hoya_glass_fcd1(self): fcd1 = gf.create_glass('FCD1', 'Hoya') self.assertIsNotNone(fcd1.gindex) self.assertEqual(fcd1.name(), 'FCD1') compare_indices(self, fcd1, fcd1.catalog)
def test_cdgm_glass_hk9l(self): glass = gf.create_glass('H-K9L', 'CDGM') self.assertIsNotNone(glass.gindex) self.assertEqual(glass.name(), 'H-K9L') compare_indices(self, glass, glass.catalog, tol=8e-6)