In the bottom code, cut_resample only works for the scalar field, not for the vector field since shape mismatch for RectBivariateSpline ("ValueError: x dimension of z must have same number of elements as x"). It can be fixed by transposing Ex, Ey, Ez first.
I though this stems from the xy indexing in the meshgrid when creating a Scalar_Field_XY object but was surprised cut_resample works for the scalar field. So I don't understand the different behavior since the source codes of the cut_sample methods look the same. Therefore I'm not sure where a correct fix would go
import numpy as np
from diffractio.scalar_sources_XY import Scalar_source_XY
from diffractio.vector_sources_XY import Vector_source_XY
from diffractio import nm, um, mm, degrees
wavelength = 1 * um
field_size = (12000 * um, 5000 * um)
field_resolution = (4 * 2048, 1 * 1024)
xy0 = tuple(
np.linspace(-0.5 * s, 0.5 * s, r) for s, r in zip(field_size, field_resolution)
)
u0 = Scalar_source_XY(*xy0, wavelength)
u0.gauss_beam(
r0=(0.0, 0.0),
w0=(1000 * um, 1000 * um),
z0=(
-1 * um,
-1 * um,
),
alpha=0.0,
beta=0.0,
A=1,
theta=0.0,
phi=0.0,
)
print(f"{u0.x.shape, u0.y.shape, u0.u.shape, u0.X.shape, u0.Y.shape}")
EM0 = Vector_source_XY(*xy0, wavelength, info="initial EM field from Gaussian beam")
EM0.constant_polarization(
u=u0, v=(1.0, 0.0), has_normalization=True
)
u0.cut_resample(
x_limits=(-2000 * um, 2000 * um),
num_points=field_resolution,
new_field=False,
)
print(f"{EM0.x.shape, EM0.y.shape, EM0.Ex.shape, EM0.X.shape, EM0.Y.shape}")
EM0.Ex = EM0.Ex.T # inserted fix for RectBivariateSpline
EM0.Ey = EM0.Ey.T # inserted fix for RectBivariateSpline
EM0.Ez = EM0.Ez.T # inserted fix for RectBivariateSpline
EM0.cut_resample(
x_limits=(-2000 * um, 2000 * um),
num_points=field_resolution,
new_field=False,
)
In the bottom code, cut_resample only works for the scalar field, not for the vector field since shape mismatch for RectBivariateSpline ("ValueError: x dimension of z must have same number of elements as x"). It can be fixed by transposing Ex, Ey, Ez first.
I though this stems from the xy indexing in the meshgrid when creating a Scalar_Field_XY object but was surprised cut_resample works for the scalar field. So I don't understand the different behavior since the source codes of the cut_sample methods look the same. Therefore I'm not sure where a correct fix would go