bryancole / raypier_optics

A raytracing toolkit for optical design
Other
57 stars 8 forks source link

How to insert glass material not in refractiveindex.info? #7

Open Jonas231 opened 2 years ago

Jonas231 commented 2 years ago

Hi Bryan, I want to transfer an optical model from another optical design program for testing. The lens is called "AFL12-15" from asphericon. I have the glass material as .csv and extracted the information:

['!Manufact ', 'Name ', 'EqName ', 'Code ', 'B1 ', 'B2 ', 'B3 ', 'C1 ', 'C2 ', 'C3 ', ' A7 ', ' A8 ', ' A9 ', 'EQ ', ' Lmin', ' Lmax ', 'Lv ', 'D0 ', 'D1 ', 'D2 ', 'E0 ', 'E1 ', 'LTK ', 'DNDT7 ', 'DNDT8 ', 'DNDT9 ', 'DNDT10', 'DNDT11', 'DNDT12', 'DRT ', ' 2500', ' 2325', ' 1970', ' 1530', ' 1060', ' 700', ' 660', ' 620', ' 580', ' 546', ' 500', ' 460', ' 436', ' 420', ' 404', ' 400', ' 390', ' 380', ' 370', ' 365', ' 350', ' 334', ' 320', ' 310', ' 300', ' 290', ' 280', ' 270', ' 260', ' 250', ' 240', ' 230', ' CC', ' al1 ', ' al2 ', ' rho ', 'price']

['SPECIAL ', 'HPFS7980 ', 'SILICA ', ' ', '0.683740494 ', ' 0.420323613 ', ' 0.585027480 ', ' 0.00460352869', ' 0.01339688560', ' 64.4932732 ', ' ', ' ', ' ', ' 1 ', ' 0.18 ', ' 2.30 ', ' ', ' 2.40E-5 ', ' 0.0 ', ' 0.0 ', ' 5.5E-7 ', ' 0.0 ', '0.10 ', ' ', ' ', ' ', ' ', ' ', ' ', '10.0', '0.9897', '0.9964', '0.9997', '0.9998', '0.9999', '0.9999', '0.9999', '0.9999', '0.9999', '0.9999', '0.9999', '0.9998', '0.9998', '0.9999', '0.9999', '0.9999', '0.9999', '0.9999', '0.9999', '0.9999', '0.9999', '0.9999', '0.9999', '0.9999', '0.9999', '0.9997', '0.9996', '0.9992', '0.9962', '0.9846', '0.9747', '0.9831', ' ', ' 0.52', ' ', ' 2.20', '']

How can I define a glass material "OpticalMaterial" in raypier by inserting Sellmeier coefficients "B1 ', 'B2 ', 'B3 ', 'C1 ', 'C2 ', 'C3"?

The equation is like eq. 10 in http://www.schott.com/shop/medias/tie-29-refractive-index-and-dispersion-eng.pdf?context=bWFzdGVyfHJvb3R8MTg4OTQ2NHxhcHBsaWNhdGlvbi9wZGZ8aDQ3L2hjYS84ODE3NDA5NTg5Mjc4LnBkZnxkMTc5MjMyYjI5YmRlZTAzZmFmYzIxZmVlNTMyMmE5NzBiNWI5OGJhODM3YWRjYmM5NmY1ZTczMjY1ZWM3NDdk

I saw you defined some Sellmeier equations here: https://github.com/bryancole/raypier_optics/blob/master/raypier/core/cmaterials.pyx used in "BaseDispersionCurve(object)".

Could you please provide me with an example how to enter the Sellmeier coefficients?

Best regards, Jonas

Jonas231 commented 2 years ago

Ah I found this class here https://github.com/bryancole/raypier_optics/blob/79da3d45312f66bf9bf0833f0cdd76f17ba16610/raypier/dispersion.py:

class FusedSilica(BaseDispersionCurve): """ A Dispersion curve for fused silica. """ def init(self, absorption=0.0): formula_id=1 coefs = numpy.array([0.0, 0.6961663, 0.0684043, 0.4079426, 0.1162414, 0.8974794, 9.896161]) wavelen_min=0.21 wavelen_max=6.7 super(FusedSilica,self).init(formula_id, coefs, absorption, wavelen_min, wavelen_max )

Jonas231 commented 2 years ago

Could it be done by adding a property "from_formula" to https://github.com/bryancole/raypier_optics/blob/79da3d45312f66bf9bf0833f0cdd76f17ba16610/raypier/materials.py :

class OpticalMaterial(HasStrictTraits): name = Str("Part A") from_database = Bool(True) refractive_index = Float(1.0) glass_name=Enum(GlassNames) absorption=Float(0.0)

dispersion_curve = Property(depends_on="glass_name, absorption, refractive_index, from_database")

traits_view = View(VGroup(
        Item("from_database"),
        Item("glass_name", style="simple", enabled_when="from_database"),
        Item("refractive_index", editor=NumEditor, enabled_when="not from_database"),
        Item("absorption", editor=NumEditor),
    ))

def __init__(self, *args, **kwds):
    if "from_database" not in kwds:
        if ("refractive_index" in kwds) and ("glass_name" not in kwds):
            kwds['from_database'] = False
    return super().__init__(*args, **kwds)

@cached_property
def _get_dispersion_curve(self):
    if self.from_database:
        return NamedDispersionCurve(self.glass_name, absorption=self.absorption)
    else:
        return NondispersiveCurve(refractive_index=self.refractive_index,
                              absorption=self.absorption)

?

bryancole commented 2 years ago

Hi Jonas, Looks like you more-or-less found the answer. I've just pushed a changeset which adds a OpticalMaterialFromFormula class. The OpticalMaterial class was a very simple Traits wrapper roundthe BaseDispersiveMaterial object (not a Traits class) which actually evaluates the Sellmeier equation. I didn't want to add another parameter to OpticalMaterial; I think making a new subclass of the (newly added) BaseOpticalMaterial is cleaner. Note, for the Schott glass you mention, you need to use Formula_ID=2. Check against the formula definitions here: https://refractiveindex.info/database/doc/Dispersion%20formulas.pdf There are a couple other changesets I've pushed as well (stuff playing with implicit functions for modelling complex shaped optics) which, on reflection, I should have done on another branch. However, I don't think I've broken anything. Bryan On Fri, 2022-06-10 at 00:42 -0700, Jonas231 wrote:

Could it be done by adding a property "from_formula" to

https://github.com/bryancole/raypier_optics/blob/79da3d45312f66bf9bf0833f0cdd76f17ba16610/raypier/materials.py : class OpticalMaterial(HasStrictTraits):

name = Str("Part A")

from_database = Bool(True)

refractive_index = Float(1.0)

glass_name=Enum(GlassNames)

absorption=Float(0.0) dispersion_curve = Property(depends_on="glass_name, absorption, refractive_index, from_database") traits_view = View(VGroup( Item("from_database"), Item("glass_name", style="simple", enabled_when="from_database"), Item("refractive_index", editor=NumEditor, enabled_when="not from_database"), Item("absorption", editor=NumEditor), )) def init(self, *args, *kwds): if "from_database" not in kwds: if ("refractive_index" in kwds) and ("glass_name" not in kwds): kwds['from_database'] = False return super().init(args, **kwds) @cached_propertydef _get_dispersion_curve(self): if self.from_database: return NamedDispersionCurve(self.glass_name, absorption=self.absorption) else: return NondispersiveCurve(refractive_index=self.refractive_index,
absorption=self.absorption) ?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: < @.***>

Jonas231 commented 2 years ago

Hello Bryan, with your new version I get now this error:

~\Anaconda3\envs\myRaypier38\lib\site-packages\raypier-0.2.3-py3.8-win-amd64.egg\raypier\core\cfaces.pyx in init raypier.core.cfaces()

ModuleNotFoundError: No module named 'distribute_setup'

Regards, Jonas

Jonas231 commented 2 years ago

Okay. I repeated the build of your new version. Now it works.

Jonas231 commented 2 years ago

I used: "m1 = OpticalMaterialFromFormula(formula_id = 2, coefs = coeffs, wavelen_min = Lmin, wavelen_max = Lmax)"

Jonas231 commented 2 years ago

Hi Bryan, I setup a new environment with myRaypier38.yml on another Windows PC and "pip install chaco=3.8.0". I used git clone https://github.com/bryancole/raypier_optics and used "python setup.py install".

Now I am getting the error "~\Anaconda3\envs\myRaypier38\lib\site-packages\raypier-0.2.3-py3.8-win-amd64.egg\raypier\core\cfaces.pyx in init raypier.core.cfaces()

ModuleNotFoundError: No module named 'distribute_setup' " again.

Full error message: " from raypier.api import OpticalMaterialFromFormula

File "C:\Users\Jonas.conda\envs\myRaypier38\lib\site-packages\raypier-0.2.3-py3.8-win-amd64.egg\raypier\api.py", line 5, in from .general_optic import GeneralLens

File "C:\Users\Jonas.conda\envs\myRaypier38\lib\site-packages\raypier-0.2.3-py3.8-win-amd64.egg\raypier\general_optic.py", line 15, in from raypier.lenses import BaseLens

File "C:\Users\Jonas.conda\envs\myRaypier38\lib\site-packages\raypier-0.2.3-py3.8-win-amd64.egg\raypier\lenses.py", line 30, in from raypier.core.cfaces import CircularFace, SphericalFace, ConicRevolutionFace, AsphericFace

File "raypier\core\cfaces.pyx", line 11, in init raypier.core.cfaces

ModuleNotFoundError: No module named 'distribute_setup' "

Do you know why this error occurs?

Best regards, Jonas

Jonas231 commented 2 years ago

This is the content of my .yml file:

name: myRaypier38 channels:

prefix: C:\Users\herbst\Anaconda3\envs\myRaypier38

bryancole commented 2 years ago

Hi Jonas,

Sorry, my bad. Lines 11-13 in raypier\core\cfaces.pyx in the latest commit should not be there. This is my IDE (eclipse) adding random imports at the top of the file (as part of it's auto-fix 'feature') without me noticing. Very annoying. I need to figure out how to turn that off.

I've just pushed a fix.

Bryan