Comments (5)
Dear new2python2020,
The new version of LightPipes for Python (2.05) is pure Python ( so no longer a C++ package). This has many advantages and is as fast as the old C++ version (1.2.0). For this we made use of the numpy package and for that we had to change the type of the field from 'list' to numpy array. We thought that nobody would notice that because we anticipated that people would not use the field array elements in their code.....
Please change your code according to the example below. I hope it will work now.
Fred van Goor
from LightPipes import *
wavelength=5*um
size=20.0*mm
N=5
F0=Begin(size,wavelength,N)
print(F0.field.real[1][2])
print(F0.grid_dimension)
print(F0.lam)
print(F0.siz)
# for y in range(N):
# for x in range(N):
# B[x][y] =123*x + 456*y
# A[y][x] = complex(F0[y][x].real * B[x][y] , F0[y][x].imag * B[x][y])
B = [[1 for i in range(N)] for j in range(N)]
A = [[0 for i in range(N)] for j in range(N)]
for y in range(N):
for x in range(N):
A[y][x] = complex(F0.field[y][x].real * B[x][y] , F0.field[y][x].imag * B[x][y])
print(A)
from lightpipes.
Thanks Fred, that seemed to have worked!
from lightpipes.
Apologies, I have a follow-up question. The variable A from my previous post is a list, but I'd like to propagate it forward as a field to functions such as Fresnel, Intensity, etc. Is this field input supposed to be any type of array? I tried to convert it to an array using numpy.array(A), but continue to get the error that "Field is neither first nor last parameter..."
A2 = numpy.array(A)
F2 = lp.Fresnel(A2,d0); # d0 is type int
from lightpipes.
Try this:
from LightPipes import *
wavelength=5*um
size=20.0*mm
N=5
F0=Begin(size,wavelength,N)
print(F0.field.real[1][2])
print(F0.grid_dimension)
print(F0.lam)
print(F0.siz)
# for y in range(N):
# for x in range(N):
# B[x][y] =123*x + 456*y
# A[y][x] = complex(F0[y][x].real * B[x][y] , F0[y][x].imag * B[x][y])
B = [[1 for i in range(N)] for j in range(N)]
A = [[0 for i in range(N)] for j in range(N)]
for y in range(N):
for x in range(N):
A[y][x] = complex(F0.field.real[y][x] * B[x][y] , F0.field[y][x].imag * B[x][y])
print(A)
#A2 = numpy.array(A)
#F2 = lp.Fresnel(A2,d0); # d0 is type int
F1=F0
for y in range(N):
for x in range(N):
F1.field.real[y][x] = A[y][x].real
F1.field.imag[y][x] = A[y][x].imag
print(F1.field)
d0=100
F2=Fresnel(F1,d0)
print(F2.field)
You can write the second for loop as (the benefit of using numpy!):
F1.field = A
It gives the same result.
from LightPipes import *
wavelength=5*um
size=20.0*mm
N=5
F0=Begin(size,wavelength,N)
print(F0.field.real[1][2])
print(F0.grid_dimension)
print(F0.lam)
print(F0.siz)
# for y in range(N):
# for x in range(N):
# B[x][y] =123*x + 456*y
# A[y][x] = complex(F0[y][x].real * B[x][y] , F0[y][x].imag * B[x][y])
B = [[1 for i in range(N)] for j in range(N)]
A = [[0 for i in range(N)] for j in range(N)]
for y in range(N):
for x in range(N):
A[y][x] = complex(F0.field.real[y][x] * B[x][y] , F0.field[y][x].imag * B[x][y])
print(A)
#A2 = numpy.array(A)
#F2 = lp.Fresnel(A2,d0); # d0 is type int
F1=F0
F1.field = A
print(F1.field)
d0=100
F2=Fresnel(F1,d0)
print(F2.field)
from lightpipes.
Wonderful, thanks!
from lightpipes.
Related Issues (20)
- Propagation of Gaussian Beam through free space and through lens HOT 8
- Inconsistent definitions of waist w and xshift HOT 2
- Support for astigmatic beams HOT 2
- The grid_dimension and grid_size properties should be documented
- Unexpected intensity distribution for Fresnel propagation HOT 5
- Cannot install LightPipes on Windows 7 - please help HOT 2
- Finite difference documentation typo? HOT 1
- installation problems
- Add Interpol option in Fresnel and Forvard HOT 1
- Warning when paraxiality is violated HOT 2
- Shift with direct integration Forward
- Diffraction From Thin Wire HOT 4
- Step by Step Propagation With a Short Focal Length Lens HOT 3
- LightPipes on an iPad
- LPtest() fails on some systems while installation is correct HOT 1
- Intensity plot gets cut up when attempting to propagate finite airy beam HOT 9
- Cite lightpipes in a paper HOT 2
- lens Following Field Produced by Forward Function
- Airy Beam HOT 6
- LG doughnut mode HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lightpipes.