From 40f99c547d9a834657509c961b8becace5458f98 Mon Sep 17 00:00:00 2001 From: CSTEZCAN <33690601+CSTEZCAN@users.noreply.github.com> Date: Sun, 9 Mar 2025 16:01:42 +0000 Subject: [PATCH] Update lens_aberration.py old version threw "AttributeError: np.Inf was removed in the NumPy 2.0 release. Use np.inf instead." error, updated --- examples/lens_aberration.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/lens_aberration.py b/examples/lens_aberration.py index 05c125b..4ee81ed 100644 --- a/examples/lens_aberration.py +++ b/examples/lens_aberration.py @@ -1,23 +1,23 @@ import diffractsim +import numpy as np # Import numpy to use np.inf -diffractsim.set_backend("CPU") #Change the string to "CUDA" to use GPU acceleration -# Note: this example is highly recommendeded to run with CUDA +diffractsim.set_backend("CUDA") # Change the string to "CUDA" to use GPU acceleration +# Note: this example is highly recommended to run with CUDA from diffractsim import MonochromaticField, Lens, nm, mm, cm, GaussianBeam F = MonochromaticField( - wavelength=630 * nm, extent_x=20. * mm, extent_y=20. * mm, Nx=256, Ny=256,intensity = 1 + wavelength=630 * nm, extent_x=20. * mm, extent_y=20. * mm, Nx=256, Ny=256, intensity=1 ) -F.add(GaussianBeam(1*mm)) +F.add(GaussianBeam(1 * mm)) F.add( Lens( - diffractsim.bd.Inf, + np.inf, # Use np.inf instead of diffractsim.bd.Inf # equivalent OPD to a 50cm lens: -1/(2*f) r^2 - aberration=lambda x,y: -1/(2*50*cm) * (x**2+y**2) + aberration=lambda x, y: -1 / (2 * 50 * cm) * (x**2 + y**2) ) ) -longitudinal_profile_rgb, longitudinal_profile_E, extent = F.get_longitudinal_profile( start_distance = 0*cm , end_distance = 100 *cm , steps = 80) -F.plot_longitudinal_profile_colors(longitudinal_profile_rgb = longitudinal_profile_rgb, extent = extent) +longitudinal_profile_rgb, longitudinal_profile_E, extent = F.get_longitudinal_profile(start_distance=0 * cm, end_distance=100 * cm, steps=80) +F.plot_longitudinal_profile_colors(longitudinal_profile_rgb=longitudinal_profile_rgb, extent=extent) print(longitudinal_profile_rgb.shape) -