Skip to content

Commit

Permalink
modified for both python3 and python2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
E1iChan committed Aug 15, 2018
1 parent 12531ae commit 74088c5
Show file tree
Hide file tree
Showing 40 changed files with 5,336 additions and 106 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,3 +1,4 @@
*.bak
*.pyc
*.aux
*.bib
Expand Down Expand Up @@ -25,4 +26,4 @@ sdist
develop-eggs
.installed.cfg
lib
lib64
lib64
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -99,7 +99,15 @@ For win64 you also need to take care of additional scipy support:

Please test this workflow. If there is anything incorrect, please fill an issue.

Testing
---
>cd pyrate
>python setup.py --user
>python demos/demo_prism.py

IRC
---


Visit us on freenode (ports 6697, 7000, 7070 for SSL) channel #pyrate for some real time communication.
2 changes: 1 addition & 1 deletion demos/demo_anisotropic_mirrors.py
Expand Up @@ -93,7 +93,7 @@

s.addElement("TMA", elem)

print(s.rootcoordinatesystem.pprint())
print((s.rootcoordinatesystem.pprint()))

sysseq = [("TMA", [
("object", {}),
Expand Down
141 changes: 141 additions & 0 deletions demos/demo_anisotropic_mirrors.py.bak
@@ -0,0 +1,141 @@
#!/usr/bin/env/python
"""
Pyrate - Optical raytracing based on Python
Copyright (C) 2014-2018
by Moritz Esslinger moritz.esslinger@web.de
and Johannes Hartung j.hartung@gmx.net
and Uwe Lippmann uwe.lippmann@web.de
and Thomas Heinze t.heinze@uni-jena.de
and others
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""

import numpy as np
import math
import logging
logging.basicConfig(level=logging.DEBUG)


from pyrateoptics.sampling2d import raster
from pyrateoptics.material.material_anisotropic import AnisotropicMaterial
from pyrateoptics.raytracer import surfShape
from pyrateoptics.raytracer.optical_element import OpticalElement
from pyrateoptics.raytracer.optical_system import OpticalSystem
from pyrateoptics.raytracer.surface import Surface
from pyrateoptics.raytracer.ray import RayBundle

from pyrateoptics.raytracer.aperture import CircularAperture
from pyrateoptics.raytracer.localcoordinates import LocalCoordinates

from pyrateoptics import draw, raytrace
from pyrateoptics.raytracer.globalconstants import degree

from pyrateoptics.analysis.optical_system_analysis import OpticalSystemAnalysis

import pyrateoptics.raytracer.helpers

wavelength = 0.5876e-3

rnd_data1 = np.random.random((3, 3)) #np.eye(3)
rnd_data2 = np.random.random((3, 3))#np.zeros((3, 3))#
lc = LocalCoordinates("1")
myeps = np.eye(3) + 0.1*rnd_data1 + 0.01*complex(0, 1)*rnd_data2 # aggressive complex choice of myeps
#myeps = np.eye(3) + 0.01*np.random.random((3, 3))
crystal = AnisotropicMaterial(lc, myeps)


# definition of optical system
s = OpticalSystem(matbackground=crystal)

lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="object", decz=0.0), refname=s.rootcoordinatesystem.name)
lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="m1", decz=50.0, tiltx=-math.pi/8), refname=lc0.name) # objectDist
lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="m2_stop", decz=-50.0, decy=-20, tiltx=math.pi/16), refname=lc1.name)
lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="m3", decz=50.0, decy=-30, tiltx=3*math.pi/32), refname=lc2.name)
lc4 = s.addLocalCoordinateSystem(LocalCoordinates(name="image1", decz=-50, decy=-15, tiltx=-math.pi/16), refname=lc3.name)
lc5 = s.addLocalCoordinateSystem(LocalCoordinates(name="oapara", decz=-100, decy=-35), refname=lc4.name)
lc5ap = s.addLocalCoordinateSystem(LocalCoordinates(name="oaparaap", decz=0, decy=35), refname=lc5.name)
lc6 = s.addLocalCoordinateSystem(LocalCoordinates(name="image2", decz=55, tiltx=1*math.pi/32), refname=lc5.name)

objectsurf = Surface(lc0)
m1surf = Surface(lc1, shape=surfShape.Conic(lc1, curv=-0.01), apert=CircularAperture(lc1, 20.))
m2surf = Surface(lc2, shape=surfShape.Conic(lc2, curv=0.01), apert=CircularAperture(lc2, 12.7))
m3surf = Surface(lc3, shape=surfShape.Conic(lc3, curv=-0.006), apert=CircularAperture(lc3, 20.7))
image1 = Surface(lc4)
oapara = Surface(lc3, shape=surfShape.Conic(lc5, curv=0.01, cc=-1.), apert=CircularAperture(lc5ap, 30.0))
image2 = Surface(lc6, apert=CircularAperture(lc6, 20.0))


elem = OpticalElement(lc0, name="TMA")

#elem.addMaterial("crystal", crystal)

elem.addSurface("object", objectsurf, (None, None))
elem.addSurface("m1", m1surf, (None, None))
elem.addSurface("m2", m2surf, (None, None))
elem.addSurface("m3", m3surf, (None, None))
elem.addSurface("image1", image1, (None, None))
elem.addSurface("oapara", oapara, (None, None))
elem.addSurface("image2", image2, (None, None))

s.addElement("TMA", elem)

print(s.rootcoordinatesystem.pprint())

sysseq = [("TMA", [
("object", {}),
("m1", {"is_mirror":True}),
("m2", {"is_mirror":True}),
("m3", {"is_mirror":True}),
("image1", {}),
("oapara", {"is_mirror":True}),
("image2", {}) ])]

sysseq_pilot = [("TMA",
[
("object", {}),
("m1", {"is_mirror":True}),
("m2", {"is_mirror":True}),
("m3", {"is_mirror":True}),
("m2", {"is_mirror":True}),
("m1", {"is_mirror":True}),
("m2", {"is_mirror":True}),
("m1", {"is_mirror":True}),
("m2", {"is_mirror":True})
])
]



obj_dx = 0.1
obj_dphi = 1.*degree

osa = OpticalSystemAnalysis(s, sysseq, name="Analysis")

raysdict = {"opticalsystem":s, "startz":-5., "radius":10., "raster":raster.MeridionalFan()}
osa.aim(5, raysdict, bundletype="collimated", wave=wavelength)

r2 = osa.trace()[0]


kw = 5.*degree

pilotbundles = pyrateoptics.raytracer.helpers.build_pilotbundle(objectsurf,\
crystal, (obj_dx, obj_dx), (obj_dphi, obj_dphi),\
kunitvector=np.array([0, math.sin(kw), math.cos(kw)]), num_sampling_points=3)
(pilotray2, r3) = s.para_seqtrace(pilotbundles[-1], osa.initial_bundles[0], sysseq)

draw(s, [(r2, "blue"), (r3, "orange"), (pilotray2, "red")])
6 changes: 3 additions & 3 deletions demos/demo_hud.py
Expand Up @@ -118,7 +118,7 @@

s.addElement("HUD", elem)

print(s.rootcoordinatesystem.pprint())
print((s.rootcoordinatesystem.pprint()))

sysseq = [("HUD",
[
Expand Down Expand Up @@ -172,8 +172,8 @@
print("calculating XYUV")
(m_obj_stop, m_stop_img) = s.extractXYUV(pilotbundles[-1], sysseq)

print(np.array_str(m_obj_stop, precision=5, suppress_small=True))
print(np.array_str(m_stop_img, precision=5, suppress_small=True))
print((np.array_str(m_obj_stop, precision=5, suppress_small=True)))
print((np.array_str(m_stop_img, precision=5, suppress_small=True)))

#print(s.sequence_to_hitlist(sysseq))

Expand Down
185 changes: 185 additions & 0 deletions demos/demo_hud.py.bak
@@ -0,0 +1,185 @@
#!/usr/bin/env/python
"""
Pyrate - Optical raytracing based on Python
Copyright (C) 2014-2018
by Moritz Esslinger moritz.esslinger@web.de
and Johannes Hartung j.hartung@gmx.net
and Uwe Lippmann uwe.lippmann@web.de
and Thomas Heinze t.heinze@uni-jena.de
and others
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""

import numpy as np
import logging


from pyrateoptics.sampling2d import raster
from pyrateoptics.material.material_isotropic import ConstantIndexGlass
from pyrateoptics.raytracer.surfShape import Conic, Biconic
from pyrateoptics.raytracer.optical_element import OpticalElement
from pyrateoptics.raytracer.optical_system import OpticalSystem
from pyrateoptics.raytracer.surface import Surface
from pyrateoptics.raytracer.ray import RayBundle

from pyrateoptics.raytracer.aperture import CircularAperture
from pyrateoptics.raytracer.localcoordinates import LocalCoordinates

from pyrateoptics.raytracer.globalconstants import degree, standard_wavelength

import pyrateoptics.raytracer.helpers

from pyrateoptics import draw

from pyrateoptics.analysis.optical_system_analysis import OpticalSystemAnalysis

# definition of optical system

# Design: US patent no. 5701202 A, inventor: Koichi Takahashi
# and also: Bo Chen, Alois M. Herkommer, Opt. Express 24, 26999 (2016)

logging.basicConfig(level=logging.INFO)

s = OpticalSystem()

lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="object", decz=0.0), refname=s.rootcoordinatesystem.name)

air = ConstantIndexGlass(lc0, 1.0)
glass = ConstantIndexGlass(lc0, 1.492)
s.material_background = air

si = -1.

lcD1 = s.addLocalCoordinateSystem(LocalCoordinates(name="D1", decz=30.002), refname=lc0.name)
lcS1 = s.addLocalCoordinateSystem(LocalCoordinates(name="S1", decy=-24.028, decz=26.360, tiltx=-si*14.7*degree, tiltThenDecenter=False), refname=lc0.name)
lcD1prime = s.addLocalCoordinateSystem(LocalCoordinates(name="D1prime", decy=0., decz=30.002, tiltx=-si*1.066*degree, tiltThenDecenter=False), refname=lc0.name)
lcD2 = s.addLocalCoordinateSystem(LocalCoordinates(name="D2", decy=-0.251, decz=43.485, tiltx=-si*1.066*degree, tiltThenDecenter=False), refname=lc0.name)
lcS2 = s.addLocalCoordinateSystem(LocalCoordinates(name="S2", decy=19.109, decz=33.339, tiltx=si*36.660*degree, tiltThenDecenter=False), refname=lc0.name)
lcD2prime = s.addLocalCoordinateSystem(LocalCoordinates(name="D2prime", decy=-0.251, decz=43.485, tiltx=si*38.376*degree, tiltThenDecenter=False), refname=lc0.name)
lcD3 = s.addLocalCoordinateSystem(LocalCoordinates(name="D3", decy=-11.858, decz=28.827, tiltx=si*38.376*degree, tiltThenDecenter=False), refname=lc0.name)
lcS3 = s.addLocalCoordinateSystem(LocalCoordinates(name="S3", decy=-24.028, decz=26.360, tiltx=-si*14.7*degree, tiltThenDecenter=False), refname=lc0.name)
lcD3prime = s.addLocalCoordinateSystem(LocalCoordinates(name="D3prime", decy=-11.858, decz=28.827, tiltx=-si*55.019*degree, tiltThenDecenter=False), refname=lc0.name)
lcD4 = s.addLocalCoordinateSystem(LocalCoordinates(name="D4", decy=-23.067, decz=36.667, tiltx=-si*55.019*degree, tiltThenDecenter=False), refname=lc0.name)
lcS4 = s.addLocalCoordinateSystem(LocalCoordinates(name="S4", decy=-35.215, decz=18.817, tiltx=-si*47.770*degree, tiltThenDecenter=False), refname=lc0.name)
lcD4prime = s.addLocalCoordinateSystem(LocalCoordinates(name="D4prime", decy=-23.067, decz=36.667, tiltx=-si*50.668*degree, tiltThenDecenter=False), refname=lc0.name)
lcimage = s.addLocalCoordinateSystem(LocalCoordinates(name="image", decy=-30.892, decz=43.083, tiltx=-si*50.668*degree, tiltThenDecenter=False), refname=lc0.name)

objsurf = Surface(lc0)
D1surf = Surface(lcD1)
#S1surf = Surface(lcS1, shape=Conic(lcS1, curv=si*1./108.187, cc=0), apert=CircularAperture(lcS1, 100.0))
S1surf = Surface(lcS1, shape=Biconic(lcS1, curvy=si*1./108.187, curvx=si*1./73.105, coefficients=[(0., 0.), (-si*5.542e-7, -0.08), (-si*8.176e-11, -1.379)]), apert=CircularAperture(lcS1, 40.0))
D1Psurf = Surface(lcD1prime)
D2surf = Surface(lcD2)
#S2surf = Surface(lcS2, shape=Conic(lcS2, curv=si*1./69.871, cc=-0.1368), apert=CircularAperture(lcS2, 60.0))
S2surf = Surface(lcS2, shape=Biconic(lcS2, curvy=si*1./69.871, curvx=si*1./60.374, ccy=-0.1368, ccx=-0.123, coefficients=[(0., 0.), (si*7.233e-11, 29.075), (si*4.529e-12, -2.085)]), apert=CircularAperture(lcS2, 40.0))
D2Psurf = Surface(lcD2prime)
D3surf = Surface(lcD3)
#S3surf = Surface(lcS3, shape=Conic(lcS3, curv=si*1./108.187, cc=0.0001), apert=CircularAperture(lcS3, 100.0))
S3surf = Surface(lcS3, shape=Biconic(lcS3, curvy=si*1./108.187, curvx=si*1./73.105, coefficients=[(0., 0.), (-si*5.542e-7, -0.08), (-si*8.176e-11, -1.379)]), apert=CircularAperture(lcS3, 40.0))
D3Psurf = Surface(lcD3prime)
D4surf = Surface(lcD4)
S4surf = Surface(lcS4, shape=Conic(lcS4, curv=1./77.772), apert=CircularAperture(lcS4, 40.0))
D4Psurf = Surface(lcD4prime)
imgsurf = Surface(lcimage)

elem = OpticalElement(lc0, name="HUD")

elem.addMaterial("air", air)
elem.addMaterial("glass", glass)

elem.addSurface("object", objsurf, (None, None))
elem.addSurface("d1", D1surf, (None, None))
elem.addSurface("s1", S1surf, (None, "glass"))
elem.addSurface("d1p", D1Psurf, ("glass", "glass"))
elem.addSurface("d2", D2surf, ("glass", "glass"))
elem.addSurface("s2", S2surf, ("glass", "glass"))
elem.addSurface("d2p", D2Psurf, ("glass", "glass"))
elem.addSurface("d3", D3surf, ("glass", "glass"))
elem.addSurface("s3", S1surf, ("glass", "glass"))
elem.addSurface("d3p", D3Psurf, ("glass", "glass"))
elem.addSurface("d4", D4surf, ("glass", "glass"))
elem.addSurface("s4", S4surf, ("glass", None))
elem.addSurface("d4p", D4Psurf, (None, None))
elem.addSurface("image", imgsurf, (None, None))

s.addElement("HUD", elem)

print(s.rootcoordinatesystem.pprint())

sysseq = [("HUD",
[
("object", {"is_stop":True}),
("d1", {}),
("s1", {}),
("d1p", {}),
("d2", {}),
("s2", {"is_mirror":True}),
("d2p", {}),
("d3", {}),
("s3", {"is_mirror":True}),
("d3p", {}),
("d4", {}),
("s4", {}),
("d4p", {}),
("image", {})
])
]


osa = OpticalSystemAnalysis(s, sysseq, name="Analysis")

print("collimated bundles")
(o, k1, E1) = osa.collimated_bundle(3, {"radius": 2, "raster": raster.MeridionalFan()}, wave=standard_wavelength)
(o, k2, E2) = osa.collimated_bundle(3, {"radius": 2, "raster": raster.MeridionalFan(), "anglex": 15*degree}, wave=standard_wavelength)
(o, k3, E3) = osa.collimated_bundle(3, {"radius": 2, "raster": raster.MeridionalFan(), "anglex": -15*degree}, wave=standard_wavelength)


initialbundle1 = RayBundle(x0=o, k0=k1, Efield0=E1, wave=standard_wavelength)
initialbundle2 = RayBundle(x0=o, k0=k2, Efield0=E2, wave=standard_wavelength)
initialbundle3 = RayBundle(x0=o, k0=k3, Efield0=E3, wave=standard_wavelength)
print("performing sequential raytrace")
r1 = s.seqtrace(initialbundle1, sysseq)
r2 = s.seqtrace(initialbundle2, sysseq)
r3 = s.seqtrace(initialbundle3, sysseq)

obj_dx = 0.1
obj_dphi = 5*degree

print("calculating pilotbundles")
pilotbundles = pyrateoptics.raytracer.helpers.build_pilotbundle_complex(objsurf, air, (obj_dx, obj_dx), (obj_dphi, obj_dphi), num_sampling_points=3)

#print("seqtrace of rays_pilot")
#rays_pilot = [s.seqtrace(p, sysseq) for p in pilotbundles[2:]]
# only last two bundles hit the next surface

#print("para seqtrace")
#(pilotray, r_pilot) = s.para_seqtrace(pilotbundles[-1], initialbundle1, sysseq)

print("calculating XYUV")
(m_obj_stop, m_stop_img) = s.extractXYUV(pilotbundles[-1], sysseq)

print(np.array_str(m_obj_stop, precision=5, suppress_small=True))
print(np.array_str(m_stop_img, precision=5, suppress_small=True))

#print(s.sequence_to_hitlist(sysseq))


draw(s, [r1, r2, r3])

#pz = np.array([26.36, 33.339, 18.817])
#py = np.array([-24.028, 19.109, -35.215])

2 changes: 1 addition & 1 deletion demos/demo_loadsave.py
Expand Up @@ -34,7 +34,7 @@

s = OpticalSystem()

print "pickle dump"
print("pickle dump")
frozen = jsonpickle.encode(s)

with open('optical_sys.jpkl', 'w') as output:
Expand Down

0 comments on commit 74088c5

Please sign in to comment.