Giter VIP home page Giter VIP logo

Comments (5)

FredvanGoor avatar FredvanGoor commented on June 6, 2024

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.

new2python2020 avatar new2python2020 commented on June 6, 2024

Thanks Fred, that seemed to have worked!

from lightpipes.

new2python2020 avatar new2python2020 commented on June 6, 2024

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.

FredvanGoor avatar FredvanGoor commented on June 6, 2024

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.

new2python2020 avatar new2python2020 commented on June 6, 2024

Wonderful, thanks!

from lightpipes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.