-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmat_spy.py
74 lines (57 loc) · 1.6 KB
/
mat_spy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'''Drop in replacement for opticalmaterialspy
Only implements the ior function - .n()
Needs a pre-made database, one should be provided in 'data/mat_spy.db'
The databse can be generated using the make_db.py script
'''
import sqlite3
from functools import lru_cache
class Material:
'''Base class for all materials, implements all logic,
all other classes are placeholders to mimic the opticalmaterialspy api'''
def __init__(self, *args, **kwargs):
self.mat_key=self.__class__.__name__
for arg in args:
self.mat_key+='_'+str(arg)
for arg in kwargs.values():
self.mat_key+='_'+str(arg)
@lru_cache(maxsize=32)
def n(self, wavelength=None):
conn = sqlite3.connect('data/mat_spy.db')
c = conn.cursor()
c.execute('SELECT ior FROM materials WHERE material=? AND wavelength=?', [self.mat_key, wavelength])
value=c.fetchone()
if value:
return value[0]
return 1.0
class CustomIOR:
'''A special material type that has a constant IOR for all wavelengths'''
def __init__(self, ior):
self.ior=float(ior)
def n(self, wavelength=None):
return self.ior
class Ktp(Material):
pass
class Ln(Material):
pass
class Tfln(Material):
pass
class LnMg(Material):
pass
class Bbo(Material):
pass
class Bibo(Material):
pass
class Chalcogenide(Material):
pass
class SiO2(Material):
pass
class Su8(Material):
pass
class Al2O3(Material):
pass
class TiO2(Material):
pass
class Air(Material):
pass
def n(self, wavelength=None):
return 1.0