diff --git a/doc/conf.py b/doc/conf.py index bb7dcfbc..8634766c 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -226,3 +226,11 @@ # If false, no module index is generated. # latex_use_modindex = True + +nbsphinx_prolog = """ +.. warning:: + There is an issue with the generation of documentation from notebooks, + such as this page, that causes interactive plots generated using the + Plot3D function to appear incorrect. The examples should produce correct + 3D plots when executed directly in Jupyter Lab. +""" diff --git a/doc/install.rst b/doc/install.rst index d52499c2..1e1286ee 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -38,27 +38,21 @@ After a Python3 virtualenv is created and activated, pyOpTools can be installed Visualizing pyOpTools simulations in a JupyterLab notebook ---------------------------------------------------------- -The easiest way to use pyOpTools together with -`jupyterlab `_, is to install pyOpTools -inside a python virtualenv, and then install jupyterlab on it also:: +Before being able to visualize pyOpTools simulations in a +`jupyterlab `_ Notebook, pythreejs must be enabled:: - pip install jupyterlab - -After that the jupyter plugin pythreejs must be installed and enabled:: - - pip3 install pythreejs jupyter labextension install jupyter-threejs -after this is done, you will be able to visualize the simulations using the -:func:`~pyoptools.gui.ipywidgets.Plot3D` command. +after this is done, you will be able to visualize the simulations using +the :func:`~pyoptools.gui.ipywidgets.Plot3D` command. JupyterLab and pythreejs +are listed in the requirements.txt file so there is no need to install them +separetelly. + The plot window is interactive. Using the mouse, it is possible to rotate the image by click and drag with the left button, zoom by using the scroll wheel and translate by click and drag with the right button. .. note :: - When installing pyoptools and jupyterlab in a debian 11 machine inside a - virtualenv, it was necesary to install also importlib-resources:: - - pip install importlib-resources - + Please do not run jupyter lab from the pyOpTools source code directory. + pyOptools modules will not import correctly. diff --git a/doc/notebooks/basic/00-Intro.ipynb b/doc/notebooks/basic/00-Intro.ipynb index fc080ebe..e5401bd1 100644 --- a/doc/notebooks/basic/00-Intro.ipynb +++ b/doc/notebooks/basic/00-Intro.ipynb @@ -54,9 +54,7 @@ }, { "cell_type": "markdown", - "metadata": { - "collapsed": true - }, + "metadata": {}, "source": [ "## A basic introduction \n", "\n", @@ -145,6 +143,7 @@ }, "source": [ "## More Information\n", + "\n", "[Surfaces in pyOpTools](Surfaces.ipynb)\n", "[Creating components with pyOpTools](SimpleComponents.ipynb)\n", "[pyOpTools predefined components](PredefinedComponents.ipynb)\n", @@ -157,11 +156,18 @@ "[[Simple EOD calculations](SimpleEODs.ipynb)\n", "-->\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -175,9 +181,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.10.6" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 } diff --git a/doc/notebooks/basic/PredefinedComponents.ipynb b/doc/notebooks/basic/PredefinedComponents.ipynb index 0283cfdb..f713bf44 100644 --- a/doc/notebooks/basic/PredefinedComponents.ipynb +++ b/doc/notebooks/basic/PredefinedComponents.ipynb @@ -31,7 +31,7 @@ "\n", "Using this lens a [System](../../pyoptools.raytrace.system.system.rst#pyoptools.raytrace.system.system.System) is created. The position of the lens (the mid-point between the vertices) is the (0,0,100) coordinate. No rotation of the lens is made.\n", "\n", - "After the system is ready, a list of rays that will be propagated must be defined. In this example a list **R**, containing 5 rays is created. The origin of such [Rays](../pyoptools.raytrace.ray.ray.rst#pyoptools.raytrace.ray.ray.Ray) is defined as the coordinate (0,0,0). Each one has a different direction vector to create something similar to a point source located at the origin and aiming to the lens. The wavelength for all rays is defined as 650nm.\n", + "After the system is ready, a list of rays that will be propagated must be defined. In this example a list **R**, containing 5 rays is created. The origin of such [Rays](../../pyoptools.raytrace.ray.ray.rst#pyoptools.raytrace.ray.ray.Ray) is defined as the coordinate (0,0,0). Each one has a different direction vector to create something similar to a point source located at the origin and aiming to the lens. The wavelength for all rays is defined as 650nm.\n", "\n", "
\n", " \n", @@ -41,7 +41,7 @@ "\n", "After the system and the ray beam are created, the later is added to the former, and the propagation calculation is performed.\n", "\n", - "The last [Plot3d](pyoptools.gui.ipywidgets.rst#pyoptools.gui.ipywidgets.Plot3D) command creates an interactive 3D plot of the system and the propagated rays." + "The last [Plot3d](../../pyoptools.gui.ipywidgets.rst#pyoptools.gui.ipywidgets.Plot3D) command creates an interactive 3D plot of the system and the propagated rays." ] }, { @@ -304,7 +304,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -318,9 +318,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.6" + "version": "3.10.6" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 } diff --git a/doc/notebooks/basic/Simple RayTraces.ipynb b/doc/notebooks/basic/SimpleRayTraces.ipynb similarity index 90% rename from doc/notebooks/basic/Simple RayTraces.ipynb rename to doc/notebooks/basic/SimpleRayTraces.ipynb index 28f9aada..df9a07dc 100644 --- a/doc/notebooks/basic/Simple RayTraces.ipynb +++ b/doc/notebooks/basic/SimpleRayTraces.ipynb @@ -1,26 +1,39 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Random raytracing examples" + ] + }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "from pyoptools.all import *\n", - "from numpy import pi,sqrt" + "from math import pi" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "tags": [] + }, "source": [ - "## Crear un sistema sencillo con una lente" + "## Creation of a simple one-lens system." ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "L1=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=material.schott[\"N-BK7\"])\n", @@ -39,29 +52,33 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Mirar algunos parametros de la lente" + "### Some geometrical parameters of the constructed lens." ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "L1.paraxial_constants() #Distancia focal efectiva, punto focal anterior, punto focal posterior" + "L1.paraxial_constants() # Effective focal lenght, position of the anterior focal point, position of the posterior focal point" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Armar un sistema con 2 lentes" + "## Different examples of raytracing of a 2 lens system" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "L2=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=material.schott[\"N-BK7\"])\n", @@ -81,7 +98,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "L2=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=material.schott[\"N-BK7\"])\n", @@ -101,7 +120,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "L2=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=material.schott[\"N-BK7\"])\n", @@ -123,7 +144,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "%pylab inline\n", @@ -134,12 +157,16 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Un espectroscopio con prisma" + "## Prism spectroscope ray tracing" ] }, { - "cell_type": "markdown", - "metadata": {}, + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], "source": [ "L=60\n", "h=L/2.*cos(pi/3.)\n", @@ -181,15 +208,23 @@ ] }, { - "cell_type": "markdown", - "metadata": {}, + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], "source": [ "spot_diagram_c(C)" ] }, { - "cell_type": "markdown", - "metadata": {}, + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], "source": [ "Plot3D(S,center=(0,.35*PCCD,PCCD),size=(50,30),scale=10,rot=[(0,pi/2+.1,0)])" ] @@ -198,12 +233,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Otro espectroscopio con prisma" + "## Another prism spectroscope " ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "L=60\n", "h=L/2.*cos(pi/3.)\n", @@ -253,15 +290,19 @@ ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "spot_diagram_c(C)" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "Plot3D(S,center=(0,.35*PCCD,PCCD),size=(50,30),scale=10,rot=[(0,pi/2+.1,0)])" ] @@ -270,12 +311,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Colocando aperturas" + "## Placing diaphragms" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "L2=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=material.schott[\"BK7\"])\n", "L3=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=material.schott[\"BK7\"])\n", @@ -306,12 +349,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Reflección total interna" + "## Example with total internal reflection" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "P0=RightAnglePrism(width=50,height=50,material=material.schott[\"BK7\"],reflectivity=0)\n", "P1=RightAnglePrism(width=50,height=50,material=material.schott[\"BK7\"],reflectivity=0)\n", @@ -336,12 +381,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Multiples fuentes y distintos tipos de fuentes" + "## Multiple ray sources" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "r_b=point_source_r(origin=(0.,0.,0.),direction=(0.,0.,0),span=pi/256\n", " ,num_rays=10,wavelength=0.470, label=\"blue\")\n", @@ -422,12 +469,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Par de dobletes" + "## System made with a couple catalog doubletes" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "L1=library.Edmund.get(\"45408\") ##f20,D5\n", "L2=library.Edmund.get(\"45407\")\n", @@ -458,12 +507,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Lente Asférica" + "## Aspheric lens" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "r_b= parallel_beam_c(size=(2,2),num_rays=(5,5), wavelength=.650)\n", "\n", @@ -533,15 +584,17 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Lentes desalineadas" + "## Mis-aligned lenses" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "N_BK7=material.schott[\"BK7\"]\n", - "N_BAK4=material.schott[\"BAK4\"]\n", + "N_BAK4=material.hikari[\"BAK4\"]\n", "N_SF10=material.schott[\"SF10\"]\n", "\n", "\n", @@ -580,7 +633,7 @@ "ccd=CCD()\n", "\n", "\n", - "# Place de tetectors at the focal planes of the lenses\n", + "# Place the detectors at the focal planes of the lenses\n", "\n", "os=System(complist=[(oc,(0,0,500),(.50,0,0)),\n", " (ccd,(0,0,float(990)),(0,0,0)),\n", @@ -603,12 +656,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Sistema con divisores de haz" + "## System with multiple beam splitters" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "N_BK7=material.schott['BK7']\n", "\n", @@ -640,31 +695,11 @@ "S.propagate()\n", "Plot3D(S,center=(-15,0,7), size=(50,50),scale=16,rot=[(0,-pi/2,0),(-pi/2+.1,-pi/4,0)])" ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#Ejercicio:\n", - "\n", - "Simular un expansor de haz fabricado con 2 lentes esfericas de las siguientes caracteristicas:\n", - "\n", - "1. Lente convergente fabricada en BK7 de 50 mm de diametro con radios de curvatura 100 y -100 mm\n", - "1. Lente convergente fabricada en BK7 de 50 mm de diametro con radios de curvatura 100 y -100 mm\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -678,9 +713,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.6" + "version": "3.10.6" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 } diff --git a/doc/requirements.txt b/doc/requirements.txt index 021e72c2..fce365bc 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -2,7 +2,7 @@ Pillow jupyter ipython six -numpy==1.22.0 +numpy scipy Cython matplotlib @@ -17,3 +17,4 @@ sphinx nbsphinx imageio PyYAML +importlib_resources diff --git a/pyoptools/wavefront/field/field.pyx b/pyoptools/wavefront/field/field.pyx index 6a840400..7182ebc3 100644 --- a/pyoptools/wavefront/field/field.pyx +++ b/pyoptools/wavefront/field/field.pyx @@ -18,8 +18,8 @@ from warnings import warn from numpy import dot, zeros, abs, meshgrid, pi, exp, where, angle, sqrt as npsqrt, indices,\ - empty, complex, complex64, newaxis, column_stack, max, array, linspace, dot, zeros_like, \ - round, float, arange, isnan, angle, mgrid, rint, float32, uint32, exp + empty, complex128, complex64, newaxis, column_stack, max, array, linspace, dot, zeros_like, \ + round, float64, arange, isnan, angle, mgrid, rint, float32, uint32, exp from numpy.fft import fft2, ifft2, fftshift, ifftshift @@ -69,8 +69,8 @@ def s(u, n): def s2d(kx, ky, nx, ny): - ux=kx - (arange(nx).astype(float)) # -int(nx/2)) - uy=ky - (arange(ny).astype(float)) # -int(ny/2)) + ux=kx - (arange(nx).astype(float64)) # -int(nx/2)) + uy=ky - (arange(ny).astype(float64)) # -int(ny/2)) ux= ux.reshape(1, nx) uy=uy.reshape(1, ny) # print ux.shape, uy.shapefield.py @@ -322,7 +322,7 @@ cdef class Field: nx=self.shape[0] ny=self.shape[1] - pd=zeros((kx*nx, ky*ny), dtype=complex) + pd=zeros((kx*nx, ky*ny), dtype=complex128) for i in range(kx): for j in range(ky): diff --git a/requirements.txt b/requirements.txt index d9b401b4..dd2b5ac9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ Pillow==9.0.1 -jupyter +jupyterlab ipython -numpy==1.22.0 -scipy==1.5.2 +numpy==1.21.5 +scipy==1.8.0 Cython==0.29.32 -matplotlib==3.3.0 +matplotlib==3.5.1 pythreejs pytest==4.6.11 pep8==1.7.1 @@ -17,4 +17,4 @@ nbsphinx imageio==2.4.1 PyYAML pythreejs - +importlib-resources