bryancole / raypier_optics

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

Problem with "model.ipython_view" #6

Closed Jonas231 closed 2 years ago

Jonas231 commented 2 years ago

Hello Bryan,

I tried your jupyter example:

from raypier.api import RayTraceModel, GeneralLens, ParallelRaySource, SphericalFace, CircleShape, OpticalMaterial

Build a couple of lenses

shape = CircleShape(radius=12.5) f1 = SphericalFace(curvature=-50.0, z_height=0.0) f2 = SphericalFace(curvature=50.0, z_height=5.0) m = OpticalMaterial(glass_name="N-BK7") lens1 = GeneralLens(centre=(0,0,0), direction=(0,0,1), shape=shape, surfaces=[f1,f2], materials=[m]) lens2 = GeneralLens(centre=(0,0,100.0), direction=(0,0,1), shape=shape, surfaces=[f1,f2], materials=[m])

Add a source

src = ParallelRaySource(origin=(0,0,-50.0), direction=(0,0,1), rings=5, show_normals=False, display="wires", opacity=0.1)

model = RayTraceModel(optics=[lens1,lens2], sources=[src])

It produces this output:

new curvature -50.0 new curvature 50.0 Face changed TraitChangeEvent(object=<raypier.general_optic.GeneralLens object at 0x00000157CEF132C0>, name='shape', old=None, new=<raypier.shapes.CircleShape object at 0x0000015741AAF680>) Face changed TraitChangeEvent(object=<raypier.general_optic.GeneralLens object at 0x00000157CEF132C0>, name='surfaces', old=[], new=[, ]) Face changed TraitChangeEvent(object=<raypier.general_optic.GeneralLens object at 0x00000157CEF60720>, name='shape', old=None, new=<raypier.shapes.CircleShape object at 0x0000015741AAF680>) Face changed TraitChangeEvent(object=<raypier.general_optic.GeneralLens object at 0x00000157CEF60720>, name='surfaces', old=[], new=[, ]) trace Trace time: 0.0 secs SET MTIME

However when I execute "model.ipython_view(400,300)", I get this error message:

"

TypeError Traceback (most recent call last) ~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _data_and_metadata(self, always_both) 1299 try: -> 1300 b64_data = b2a_base64(self.data).decode('ascii') 1301 except TypeError:

TypeError: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

FileNotFoundError Traceback (most recent call last) ~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\formatters.py in call(self, obj, include, exclude) 968 969 if method is not None: --> 970 return method(include=include, exclude=exclude) 971 return None 972 else:

~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _reprmimebundle(self, include, exclude) 1288 if self.embed: 1289 mimetype = self._mimetype -> 1290 data, metadata = self._data_and_metadata(always_both=True) 1291 if metadata: 1292 metadata = {mimetype: metadata}

~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _data_and_metadata(self, always_both) 1300 b64_data = b2a_base64(self.data).decode('ascii') 1301 except TypeError: -> 1302 raise FileNotFoundError( 1303 "No such file or directory: '%s'" % (self.data)) 1304 md = {}

FileNotFoundError: No such file or directory: '/dev/shm/temp_vtk_put.png'


TypeError Traceback (most recent call last) ~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _data_and_metadata(self, always_both) 1299 try: -> 1300 b64_data = b2a_base64(self.data).decode('ascii') 1301 except TypeError:

TypeError: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

FileNotFoundError Traceback (most recent call last) ~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\formatters.py in call(self, obj) 343 method = get_real_method(obj, self.print_method) 344 if method is not None: --> 345 return method() 346 return None 347 else:

~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _reprpng(self) 1318 def _reprpng(self): 1319 if self.embed and self.format == self._FMT_PNG: -> 1320 return self._data_and_metadata() 1321 1322 def _reprjpeg(self):

~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _data_and_metadata(self, always_both) 1300 b64_data = b2a_base64(self.data).decode('ascii') 1301 except TypeError: -> 1302 raise FileNotFoundError( 1303 "No such file or directory: '%s'" % (self.data)) 1304 md = {}

FileNotFoundError: No such file or directory: '/dev/shm/temp_vtk_put.png'

HBox(children=(HBox(children=(Button(description='↑', style=ButtonStyle()), Button(description='↓', style=Butt… " Looks like there is some path defined which I do not have. Would be cool to find a way around this error. Best regards, Jonas
bryancole commented 2 years ago

OK, I have committed a fix for this, but for some reason f**king github won't let me push. The fix is in my working Hg repo which you can find at: https://bryancole-enterprises.codebasehq.com/inverse-pig/raytrace-db846a.hg (on the default branch). As soon as I can figure out why github hates me, I'll push it there as well.

bryancole commented 2 years ago

OK, got this pushed to github finally. Was my ISP blocking github SSH. Very annoying. Please let me know if the fix works for you, Jonas, then I can close the issue.

Jonas231 commented 2 years ago

Thank you for the fix. I still get the error with the new version of tracer.py.


TypeError Traceback (most recent call last) ~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _data_and_metadata(self, always_both) 1299 try: -> 1300 b64_data = b2a_base64(self.data).decode('ascii') 1301 except TypeError:

TypeError: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

FileNotFoundError Traceback (most recent call last) ~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\formatters.py in call(self, obj, include, exclude) 968 969 if method is not None: --> 970 return method(include=include, exclude=exclude) 971 return None 972 else:

~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _reprmimebundle(self, include, exclude) 1288 if self.embed: 1289 mimetype = self._mimetype -> 1290 data, metadata = self._data_and_metadata(always_both=True) 1291 if metadata: 1292 metadata = {mimetype: metadata}

~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _data_and_metadata(self, always_both) 1300 b64_data = b2a_base64(self.data).decode('ascii') 1301 except TypeError: -> 1302 raise FileNotFoundError( 1303 "No such file or directory: '%s'" % (self.data)) 1304 md = {}

FileNotFoundError: No such file or directory: '/dev/shm/temp_vtk_put.png'


TypeError Traceback (most recent call last) ~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _data_and_metadata(self, always_both) 1299 try: -> 1300 b64_data = b2a_base64(self.data).decode('ascii') 1301 except TypeError:

TypeError: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

FileNotFoundError Traceback (most recent call last) ~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\formatters.py in call(self, obj) 343 method = get_real_method(obj, self.print_method) 344 if method is not None: --> 345 return method() 346 return None 347 else:

~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _reprpng(self) 1318 def _reprpng(self): 1319 if self.embed and self.format == self._FMT_PNG: -> 1320 return self._data_and_metadata() 1321 1322 def _reprjpeg(self):

~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _data_and_metadata(self, always_both) 1300 b64_data = b2a_base64(self.data).decode('ascii') 1301 except TypeError: -> 1302 raise FileNotFoundError( 1303 "No such file or directory: '%s'" % (self.data)) 1304 md = {}

FileNotFoundError: No such file or directory: '/dev/shm/temp_vtk_put.png'

{'position': (0.0, 0.0, 816.7000917972435), 'view_up': (0.0, 1.0, 0.0), 'focal_point': (0.0, 0.0, 127.5)} ​
bryancole commented 2 years ago

Did you update to the right branch? You need to be on master. The fix I made completely removed the bad path "/dev/shm/temp_vtk_put.png". Since your traceback is still referencing that path, I think you're not running the right version.

Jonas231 commented 2 years ago

Somehow I am not sure why I do not get the right version. I did this: git clone https://github.com/bryancole/raypier_optics.git went to the location of the cloned repository and typed python setup.py install This folder is created and updated: C:\Users\herbst\Anaconda3\envs\myRaypier38\Lib\site-packages\raypier-0.2.3-py3.8-win-amd64.egg\raypier With your new version of tracer.py. I am still getting the error message.

bryancole commented 2 years ago

I think you are importing an older version from somewhere. Try printing the path for tracer.py i.e. "From raypier import tracer: print(tracer.path)" For example I had to change the top line of the Jupiter notebook example to "Import sys; sys.path.insert(0,'..')" This ensures that the repo version is first on the import path. Sys.append('..') puts it last.

Bryan

On Fri, 3 Jun 2022, 08:06 Jonas231, @.***> wrote:

Somehow I am not sure why I do not get the right version. I did this: git clone https://github.com/bryancole/raypier_optics.git went to the location of the cloned repository and typed python setup.py install This folder is created and updated:

C:\Users\herbst\Anaconda3\envs\myRaypier38\Lib\site-packages\raypier-0.2.3-py3.8-win-amd64.egg\raypier With your new version of tracer.py. I am still getting the error message.

— Reply to this email directly, view it on GitHub https://github.com/bryancole/raypier_optics/issues/6#issuecomment-1145655938, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABYLNVJDMYQMB5VCAHZ2Z3VNGVHPANCNFSM5XT4PJNQ . You are receiving this because you commented.Message ID: @.***>

Jonas231 commented 2 years ago

Okay in my case:

from raypier import tracer print(tracer.file)

"C:\Users\herbst\Anaconda3\envs\myRaypier38\lib\raypier\tracer.py"

This is not the most recent version which installed into this folder: C:\Users\herbst\Anaconda3\envs\myRaypier38\Lib\site-packages\raypier-0.2.3-py3.8-win-amd64.egg\raypier

I had to copy and overwrite this folder "raypier" or delete it. Now it works. Thank you.

bryancole commented 2 years ago

Glad this is sorted. Thanks for the report.

bryancole commented 2 years ago

Hi Jonas

Sorry my bad. Line 498 in raypier.tracer.py contains a hardcoded path to a temp file location which would only work on Linux. I don't know why I didn't use the tempfile module. Must have been in a hurry.

The Linux path is in a memory filesystem. If you put a real hdd path instead the performance might be slower. However it looks like the PNGWriter object has a feature for wiring to memory directly and accessing it by pointer. I would probably be better to use this technique on Windows. I'll take a look over the weekend. In the mean time you can just use a temp disk path of your choice and it should work. Maybe with disk caching it won't make much difference.

Bryan

On Thu, 2 Jun 2022, 07:31 Jonas231, @.***> wrote:

Hello Bryan,

I tried your jupyter example:

from raypier.api import RayTraceModel, GeneralLens, ParallelRaySource, SphericalFace, CircleShape, OpticalMaterial Build a couple of lenses

shape = CircleShape(radius=12.5) f1 = SphericalFace(curvature=-50.0, z_height=0.0) f2 = SphericalFace(curvature=50.0, z_height=5.0) m = OpticalMaterial(glass_name="N-BK7") lens1 = GeneralLens(centre=(0,0,0), direction=(0,0,1), shape=shape, surfaces=[f1,f2], materials=[m]) lens2 = GeneralLens(centre=(0,0,100.0), direction=(0,0,1), shape=shape, surfaces=[f1,f2], materials=[m]) Add a source

src = ParallelRaySource(origin=(0,0,-50.0), direction=(0,0,1), rings=5, show_normals=False, display="wires", opacity=0.1)

model = RayTraceModel(optics=[lens1,lens2], sources=[src])

It produces this output:

new curvature -50.0 new curvature 50.0 Face changed TraitChangeEvent(object=<raypier.general_optic.GeneralLens object at 0x00000157CEF132C0>, name='shape', old=None, new=<raypier.shapes.CircleShape object at 0x0000015741AAF680>) Face changed TraitChangeEvent(object=<raypier.general_optic.GeneralLens object at 0x00000157CEF132C0>, name='surfaces', old=[], new=[, ]) Face changed TraitChangeEvent(object=<raypier.general_optic.GeneralLens object at 0x00000157CEF60720>, name='shape', old=None, new=<raypier.shapes.CircleShape object at 0x0000015741AAF680>) Face changed TraitChangeEvent(object=<raypier.general_optic.GeneralLens object at 0x00000157CEF60720>, name='surfaces', old=[], new=[, ]) trace Trace time: 0.0 secs SET MTIME

However when I execute "model.ipython_view(400,300)", I get this error message: "

TypeError Traceback (most recent call last) ~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _data_and_metadata(self, always_both) 1299 try: -> 1300 b64_data = b2a_base64(self.data).decode('ascii') 1301 except TypeError:

TypeError: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

FileNotFoundError Traceback (most recent call last) ~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\formatters.py in call(self, obj, include, exclude) 968 969 if method is not None: --> 970 return method(include=include, exclude=exclude) 971 return None 972 else:

~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in repr_mimebundle(self, include, exclude) 1288 if self.embed: 1289 mimetype = self._mimetype -> 1290 data, metadata = self._data_and_metadata(always_both=True) 1291 if metadata: 1292 metadata = {mimetype: metadata}

~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _data_and_metadata(self, always_both) 1300 b64_data = b2a_base64(self.data).decode('ascii') 1301 except TypeError: -> 1302 raise FileNotFoundError( 1303 "No such file or directory: '%s'" % (self.data)) 1304 md = {}

FileNotFoundError: No such file or directory: '/dev/shm/temp_vtk_put.png'

TypeError Traceback (most recent call last) ~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _data_and_metadata(self, always_both) 1299 try: -> 1300 b64_data = b2a_base64(self.data).decode('ascii') 1301 except TypeError:

TypeError: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

FileNotFoundError Traceback (most recent call last) ~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\formatters.py in call(self, obj) 343 method = get_real_method(obj, self.print_method) 344 if method is not None: --> 345 return method() 346 return None 347 else:

~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in repr_png(self) 1318 def repr_png(self): 1319 if self.embed and self.format == self._FMT_PNG: -> 1320 return self._data_and_metadata() 1321 1322 def repr_jpeg(self):

~\Anaconda3\envs\myRaypier38\lib\site-packages\IPython\core\display.py in _data_and_metadata(self, always_both) 1300 b64_data = b2a_base64(self.data).decode('ascii') 1301 except TypeError: -> 1302 raise FileNotFoundError( 1303 "No such file or directory: '%s'" % (self.data)) 1304 md = {}

FileNotFoundError: No such file or directory: '/dev/shm/temp_vtk_put.png'

HBox(children=(HBox(children=(Button(description='↑', style=ButtonStyle()), Button(description='↓', style=Butt… " Looks like there is some path defined which I do not have. Would be cool to find a way around this error. Best regards, Jonas — Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>