rayopt
rayopt copied to clipboard
Library.get_all: material None/None/sk16 not found
Hi I like the rayopt library and the integration with the scipy.optimize
for lens curvature optimization. However, when I run the tutorial Triplet.ipynb
in the rayopt-notebook
repo, it fails to retrieve the material Schott/SK4
. What is missing in the installation?
Reference: https://github.com/quartiq/rayopt-notebooks/blob/master/triplet.ipynb
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-2-ab0625f0217a> in <module>
55 """
56
---> 57 s = system_from_text(text, columns.split(),
58 description=description)
59 s.object.angle = np.deg2rad(20)
~/Projects/raytracing/venv/lib/python3.8/site-packages/rayopt/formats.py in system_from_text(text, *args, **kwargs)
83 n = max(len(l) for l in array)
84 array = [l for l in array if len(l) == n]
---> 85 return system_from_array(array, *args, **kwargs)
86
87
~/Projects/raytracing/venv/lib/python3.8/site-packages/rayopt/formats.py in system_from_array(data, columns, shifts, material_map, **kwargs)
74 mat = try_get(line, columns, "material")
75 mat = material_map.get(mat, mat)
---> 76 m = Material.make(mat)
77 el.material = m
78 return s
~/Projects/raytracing/venv/lib/python3.8/site-packages/rayopt/material.py in make(cls, name)
116 from .library import Library
117 lib = Library.one()
--> 118 return lib.get("material", name, catalog, source)
119
120 def __str__(self):
~/Projects/raytracing/venv/lib/python3.8/site-packages/rayopt/library.py in get(self, *args, **kwargs)
118
119 def get(self, *args, **kwargs):
--> 120 for k in self.get_all(*args, **kwargs):
121 return k
122
~/Projects/raytracing/venv/lib/python3.8/site-packages/rayopt/library.py in get_all(self, typ, name, catalog, source, **kwargs)
132 res = res.order_by(Typ.name)
133 if not res.count():
--> 134 raise KeyError("{} {}/{}/{} not found".format(
135 typ, source, catalog, name))
136 for item in res:
KeyError: 'material None/None/sk16 not found'
Looks like it's not in the library. Either it was deleted or it never was in the default library. I'd either inspect the library and see whether it's in there or use another material, e.g. N-SK4
etc.
Hmm... I got the same "material not found error for N-SK4
.
I tracked down the library.sqlite
database file to search for the material SK4
. It seems like the exact name is SCHOTT-SK|N-SK4
. Is such a naming style intentional?
$ cd path/to/rayopt/
$ sqlite3 library.sqlite
sqlite> select name from material where name like '%SK4%';
SCHOTT-SK|N-SK4
HIKARI-SK|E-SK4
SUMITA-SK|K-SK4
SUMITA-SSK|K-SSK4
sqlite> .q
$
Have you solved the problem?
@ffgg11 @jordens No I haven't solved the problem, only found the root cause.
Here, if we relabel the material from SK4
to SCHOTT-SK|N-SK4
, the Triplet example Jupyter script can proceed without error.
text = """
O 0 0 .364 AIR
S 21.25 5 6.5 SCHOTT-SK|N-SK4
S -158.65 2 6.5 AIR
...
"""
I call it an adhoc solution because the exact material identifier cannot be known in advance. We need a feature to query materials by the keyword, but I don't know RayOpt's internal architecture (SQLAlchemy) to submit a PR.
I mean, query features like what other authors did at https://github.com/HugoGuillen/refractiveindex.info-sqlite .
@ffgg11 @jordens No I haven't solved the problem, only found the root cause.
Here, if we relabel the material from
SK4
toSCHOTT-SK|N-SK4
, the Triplet example Jupyter script can proceed without error.text = """ O 0 0 .364 AIR S 21.25 5 6.5 SCHOTT-SK|N-SK4 S -158.65 2 6.5 AIR ... """
I call it an adhoc solution because the exact material identifier cannot be known in advance. We need a feature to query materials by the keyword, but I don't know RayOpt's internal architecture (SQLAlchemy) to submit a PR.
I mean, query features like what other authors did at https://github.com/HugoGuillen/refractiveindex.info-sqlite .
Thank you for reply. Two days ago, I found another nice open source implementation, named Pyrate. The link of Pyrate is
@ffgg11 @jordens No I haven't solved the problem, only found the root cause.
Here, if we relabel the material from
SK4
toSCHOTT-SK|N-SK4
, the Triplet example Jupyter script can proceed without error.text = """ O 0 0 .364 AIR S 21.25 5 6.5 SCHOTT-SK|N-SK4 S -158.65 2 6.5 AIR ... """
I call it an adhoc solution because the exact material identifier cannot be known in advance. We need a feature to query materials by the keyword, but I don't know RayOpt's internal architecture (SQLAlchemy) to submit a PR.
I mean, query features like what other authors did at https://github.com/HugoGuillen/refractiveindex.info-sqlite .
Thanks for your reply. two days ago, I found another nice open source implementation, named Pyrate. The link of it is “https://salsa.debian.org/mess42/pyrate”. Pyrate includes many optimization method, such as “CG, Powell” and so on.