Operators¶
Operators
¶
propagate_fraunhofer(fields, params, reconstruction, z=None)
¶
Propagate a field using the Fraunhofer approximation.
Here \(F\) is the unitary 2D Fourier transform, with ordering controlled
by params.fftshiftSwitch.
The propagation is implemented as a centered 2D Fourier transform.
The Fourier-shift convention is controlled by
params.fftshiftSwitch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Electric field to propagate. The Fourier transform is applied along the two spatial dimensions. |
required |
params
|
Params
|
Reconstruction parameters. |
required |
reconstruction
|
Reconstruction
|
Reconstruction object containing the current exit surface wave. |
required |
z
|
float
|
Propagation distance. This argument is ignored for Fraunhofer propagation. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing |
Source code in PtyLab/Operators/Operators.py
propagate_fraunhofer_inv(fields, params, reconstruction, z=None)
¶
Back-propagate a field using the inverse Fraunhofer transform.
The back-propagation is implemented as a centered 2D inverse Fourier
transform. The Fourier-shift convention is controlled by
params.fftshiftSwitch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Electric field to back-propagate. The inverse Fourier transform is applied along the two spatial dimensions. |
required |
params
|
Params
|
Reconstruction parameters. |
required |
reconstruction
|
Reconstruction
|
Reconstruction object containing the current exit surface wave. |
required |
z
|
float
|
Propagation distance. This argument is ignored for inverse Fraunhofer propagation. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing |
Source code in PtyLab/Operators/Operators.py
propagate_fresnel(fields, params, reconstruction, z=None)
¶
Propagate a field using the Fresnel approximation.
Here \(F\) is the unitary 2D Fourier transform with the configured ordering, and \(Q\) is the source-plane quadratic phase.
The input field is multiplied by a quadratic phase factor and then
transformed using a centered 2D Fourier transform. If z is not
provided, reconstruction.zo is used as the propagation distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Complex-valued field to propagate. NumPy and CuPy arrays are supported. The last two dimensions represent the spatial field. |
required |
params
|
Params
|
Reconstruction parameters. |
required |
reconstruction
|
Reconstruction
|
Reconstruction object providing the wavelength, pixel size, and default propagation distance. |
required |
z
|
float
|
Propagation distance in meters. If None,
|
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the unchanged |
Source code in PtyLab/Operators/Operators.py
propagate_fresnel_inv(fields, params, reconstruction, z=None)
¶
Back-propagate a field using the inverse Fresnel approximation.
The input field is transformed using a centered 2D inverse Fourier
transform and multiplied by the complex conjugate of the quadratic
phase factor. If z is not provided, reconstruction.zo is used
as the propagation distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Complex-valued field to back-propagate. NumPy and CuPy arrays are supported. |
required |
params
|
Params
|
Reconstruction parameters. |
required |
reconstruction
|
Reconstruction
|
Reconstruction object providing the wavelength, pixel size, field size, and default propagation distance. |
required |
z
|
float
|
Propagation distance in meters. If None,
|
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the unchanged |
Source code in PtyLab/Operators/Operators.py
propagate_ASP(fields, params, reconstruction, inverse=False, z=None, fftflag=True)
¶
Propagate a field using the angular spectrum method.
Here \(F\) is the unitary 2D Fourier transform and \(H\) is the
band-limited angular-spectrum transfer function in matching ordering.
This equation describes forward propagation (inverse=False).
The field is transformed to the spatial-frequency domain, multiplied
by an angular-spectrum transfer function, and transformed back to the
spatial domain. If z is not provided, reconstruction.zo is
used as the propagation distance.
This propagator supports single-wavelength reconstruction only and
requires params.fftshiftSwitch to be False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Complex-valued field to propagate. NumPy and CuPy arrays are supported. |
required |
params
|
Params
|
Reconstruction parameters. |
required |
reconstruction
|
Reconstruction
|
Reconstruction object providing the wavelength, propagation grid, field size, and default propagation distance. |
required |
inverse
|
bool
|
If True, use the complex conjugate of the transfer function for back-propagation. Defaults to False. |
False
|
z
|
float
|
Propagation distance in meters. If None,
|
None
|
fftflag
|
bool
|
If True, apply centered Fourier transforms internally and shift the transfer function accordingly. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the unchanged |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in PtyLab/Operators/Operators.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
propagate_ASP_inv(*args, **kwargs)
¶
Back-propagate a field using the angular spectrum method.
This function forwards all arguments to propagate_ASP with
inverse=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Positional arguments forwarded to |
()
|
|
**kwargs
|
Keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the unchanged |
Source code in PtyLab/Operators/Operators.py
propagate_twoStepPolychrome(fields, params, reconstruction, inverse=False, z=None)
¶
Propagate a multi-wavelength field using the two-step polychrome method.
Here \(F\) is the centered unitary 2D Fourier transform, \(H_\lambda\)
propagates over \(z(1-\lambda_0/\lambda)\), and \(Q\) is the quadratic
phase for reference wavelength \(\lambda_0\) at distance \(z\).
This equation describes forward propagation (inverse=False).
The propagation combines wavelength-dependent angular-spectrum
propagation with a quadratic phase correction and a final Fourier
transform. The first entry of reconstruction.spectralDensity is
used as the reference wavelength.
If z is not provided, reconstruction.zo is used as the
propagation distance. This propagator requires
params.fftshiftSwitch to be False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Complex-valued field to propagate. NumPy and CuPy arrays are supported. |
required |
params
|
Params
|
Reconstruction parameters. |
required |
reconstruction
|
Reconstruction
|
Reconstruction object providing the spectral density, propagation geometry, sampling parameters, and mode dimensions. |
required |
inverse
|
bool
|
If True, apply the conjugated propagation factors for back-propagation. Defaults to False. |
False
|
z
|
float
|
Propagation distance in meters. If None,
|
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the unchanged |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in PtyLab/Operators/Operators.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
propagate_twoStepPolychrome_inv(fields, params, reconstruction, z=None)
¶
Back-propagate a field using the two-step polychrome method.
Both the input field and the detector-plane field stored in
reconstruction.ESW are back-propagated. The latter is returned as
the first element of the result, while the back-propagated input field
is returned as the second element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Complex-valued detector-plane field to back-propagate. NumPy and CuPy arrays are supported. |
required |
params
|
Params
|
Reconstruction parameters passed to
|
required |
reconstruction
|
Reconstruction
|
Reconstruction object containing the detector-plane field
|
required |
z
|
float
|
Propagation distance in meters. If None,
|
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the back-propagated
|
Source code in PtyLab/Operators/Operators.py
propagate_scaledASP(fields, params, reconstruction, inverse=False, z=None)
¶
Propagate a field using the scaled angular spectrum method.
Here \(F\) is the centered unitary 2D Fourier transform; \(Q_1\) and
\(Q_2\) are the source-plane and frequency-domain scaled Fresnel
factors, including sampling masks. This describes inverse=False.
The propagation uses two phase factors to account for different
sampling intervals in the object and detector planes. If z is not
provided, reconstruction.zo is used as the propagation distance.
This propagator supports single-wavelength reconstruction only and
requires params.fftshiftSwitch to be False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Complex-valued field to propagate. NumPy and CuPy arrays are supported. |
required |
params
|
Params
|
Reconstruction parameters. |
required |
reconstruction
|
Reconstruction
|
Reconstruction object providing the wavelength, propagation distance, mode dimensions, and object- and detector-plane sampling intervals. |
required |
inverse
|
bool
|
If True, use the complex conjugates of the propagation factors for back-propagation. Defaults to False. |
False
|
z
|
float
|
Propagation distance in meters. If None,
|
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the unchanged |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in PtyLab/Operators/Operators.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | |
propagate_scaledASP_inv(fields, params, reconstruction, z=None)
¶
Back-propagate a field using the scaled angular spectrum method.
This function forwards the input arguments to propagate_scaledASP
with inverse=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Complex-valued field to back-propagate. NumPy and CuPy arrays are supported. |
required |
params
|
Params
|
Reconstruction parameters passed to |
required |
reconstruction
|
Reconstruction
|
Reconstruction object providing the propagation geometry and sampling parameters. |
required |
z
|
float
|
Propagation distance in meters. If None,
|
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the unchanged |
Source code in PtyLab/Operators/Operators.py
propagate_scaledPolychromeASP(fields, params, reconstruction, inverse=False, z=None)
¶
Propagate a multi-wavelength field using the scaled angular spectrum method.
Here \(F\) is the centered unitary 2D Fourier transform; \(Q_{1,\lambda}\)
and \(Q_{2,\lambda}\) are wavelength-dependent scaled Fresnel factors,
including sampling masks. This describes inverse=False.
Separate propagation factors are constructed for each wavelength in
reconstruction.spectralDensity to account for wavelength-dependent
propagation and different sampling intervals in the object and detector
planes. If z is not provided, reconstruction.zo is used as the
propagation distance.
This propagator requires params.fftshiftSwitch to be False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Complex-valued field to propagate. NumPy and CuPy arrays are supported. |
required |
params
|
Params
|
Reconstruction parameters. |
required |
reconstruction
|
Reconstruction
|
Reconstruction object providing the spectral density, propagation distance, mode dimensions, and object- and detector-plane sampling intervals. |
required |
inverse
|
bool
|
If True, use the complex conjugates of the propagation factors for back-propagation. Defaults to False. |
False
|
z
|
float
|
Propagation distance in meters. If None,
|
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the unchanged |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in PtyLab/Operators/Operators.py
propagate_scaledPolychromeASP_inv(fields, params, reconstruction, z=None)
¶
Back-propagate a multi-wavelength field using the scaled angular spectrum method.
This function forwards the input arguments to
propagate_scaledPolychromeASP with inverse=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Complex-valued field to back-propagate. NumPy and CuPy arrays are supported. |
required |
params
|
Params
|
Reconstruction parameters passed to
|
required |
reconstruction
|
Reconstruction
|
Reconstruction object providing the spectral density, propagation geometry, and sampling parameters. |
required |
z
|
float
|
Propagation distance in meters. If None,
|
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the unchanged |
Source code in PtyLab/Operators/Operators.py
propagate_polychromeASP(fields, params, reconstruction, inverse=False, z=None)
¶
Propagate a multi-wavelength field using the angular spectrum method.
Here \(F\) is the centered unitary 2D Fourier transform and \(H_\lambda\)
is the band-limited angular-spectrum kernel for each wavelength.
This equation describes forward propagation (inverse=False).
A wavelength-dependent transfer function is constructed for each entry
in reconstruction.spectralDensity. If z is not provided,
reconstruction.zo is used as the propagation distance.
This propagator requires params.fftshiftSwitch to be False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Complex-valued field to propagate. NumPy and CuPy arrays are supported. |
required |
params
|
Params
|
Reconstruction parameters. |
required |
reconstruction
|
Reconstruction
|
Reconstruction object providing the spectral density, propagation geometry, and mode dimensions. |
required |
inverse
|
bool
|
If True, use the complex conjugate of the transfer function for back-propagation. Defaults to False. |
False
|
z
|
float
|
Propagation distance in meters. If None,
|
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the unchanged |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in PtyLab/Operators/Operators.py
propagate_identity(fields, params, reconstruction, inverse=False, z=None)
¶
Return the input field without applying propagation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Complex-valued field to return unchanged. NumPy and CuPy arrays are supported. |
required |
params
|
Params
|
Reconstruction parameters. This argument is accepted for compatibility with the common propagator interface and is not used. |
required |
reconstruction
|
Reconstruction
|
Reconstruction object containing the current exit surface wave. |
required |
inverse
|
bool
|
Accepted for compatibility with the common propagator interface and ignored. Defaults to False. |
False
|
z
|
float
|
Accepted for compatibility with the common propagator interface and ignored. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing |
Source code in PtyLab/Operators/Operators.py
propagate_polychromeASP_inv(fields, params, reconstruction, z=None)
¶
Back-propagate a multi-wavelength field using the angular spectrum method.
This function forwards the input arguments to
propagate_polychromeASP with inverse=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray
|
Complex-valued field to back-propagate. NumPy and CuPy arrays are supported. |
required |
params
|
Params
|
Reconstruction parameters passed to
|
required |
reconstruction
|
Reconstruction
|
Reconstruction object providing the spectral density, propagation geometry, and mode dimensions. |
required |
z
|
float
|
Propagation distance in meters. If None,
|
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the unchanged |
Source code in PtyLab/Operators/Operators.py
detector2object(fields, params, reconstruction)
¶
Propagate a field from the detector plane to the object plane.
The inverse propagation method is selected from
params.propagatorType. If fields is None, the detector-plane
field stored in reconstruction.ESW is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray or None
|
Detector-plane field to back-propagate. If None,
|
required |
params
|
Params
|
Reconstruction parameters. |
required |
reconstruction
|
Reconstruction
|
Reconstruction object providing the propagation parameters and detector-plane field. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Result returned by the selected inverse propagator, typically containing an object-plane exit surface wave and the back-propagated field. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Source code in PtyLab/Operators/Operators.py
object2detector(fields, params, reconstruction)
¶
Propagate a field from the object plane to the detector plane.
The forward propagation method is selected from
params.propagatorType. If fields is None, the exit surface
wave stored in reconstruction.esw is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
ndarray or None
|
Object-plane field to propagate. If None,
|
required |
params
|
Params
|
Reconstruction parameters. |
required |
reconstruction
|
Reconstruction
|
Reconstruction object providing the propagation parameters and current exit surface wave. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Result returned by the selected forward propagator, typically
containing |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Source code in PtyLab/Operators/Operators.py
aspw(u, z, wavelength, L, bandlimit=True, is_FT=False)
¶
Propagate a field using the angular spectrum plane-wave method.
Here \(F\) is the centered unitary 2D Fourier transform and \(H\) is the angular-spectrum transfer function returned by this function.
The propagation uses a band-limited angular-spectrum transfer function to reduce sampling artifacts in numerical free-space propagation.1 The input is assumed to be sampled on a square grid.
-
K. Matsushima and T. Shimobaba, "Band-Limited Angular Spectrum Method for Numerical Simulation of Free-Space Propagation in Far and Near Fields," Opt. Express 17, 19662-19673 (2009). https://doi.org/10.1364/OE.17.019662 ↩
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
Complex-valued field or its Fourier transform. NumPy and CuPy arrays are supported. The last two dimensions are assumed to describe a square spatial grid. |
required |
z
|
float
|
Propagation distance in meters. Negative values correspond to back-propagation. |
required |
wavelength
|
float
|
Wavelength in meters. |
required |
L
|
float
|
Physical side length of the sampled field in meters. |
required |
bandlimit
|
bool
|
If True, apply a band limit to the angular-spectrum transfer function to reduce sampling artifacts. Defaults to True. |
True
|
is_FT
|
bool
|
If True, treat |
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the propagated field and the angular-spectrum transfer function. |
Source code in PtyLab/Operators/Operators.py
complexexp(angle)
¶
Compute the complex exponential of a phase angle elementwise.
Uses Euler's identity,
to construct a complex phase factor. For real-valued input, the result has unit magnitude up to floating-point precision. NumPy and CuPy arrays are supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angle
|
float or ndarray
|
Phase angle in radians. Array inputs may have any shape. |
required |
Returns:
| Type | Description |
|---|---|
complex or ndarray
|
Complex phase factor with the same shape as the input. CuPy inputs produce CuPy outputs; otherwise, NumPy is used. |
Examples:
>>> import numpy as np
>>> phase = complexexp(np.array([0.0, np.pi / 2, np.pi]))
>>> np.allclose(phase, [1.0, 1j, -1.0])
True
Source code in PtyLab/Operators/Operators.py
scaledASP(u, z, wavelength, dx, dq, bandlimit=True, exactSolution=False)
¶
Propagate a field with independently specified input and output pixel sizes.
Uses scaled angular-spectrum propagation within the Fresnel (paraxial)
approximation. The output retains the input grid shape, with pixel size
dq instead of dx. For the scaling ratio \(m = dq / dx\), propagation
is evaluated as
where \(Q_1\) is a source-plane quadratic phase factor and \(Q_2\) is a
spatial-frequency quadratic phase factor. If exactSolution=True,
the result is also multiplied by the output-plane phase factor \(Q_3\).
This restores the output phase within the paraxial model; it does not
switch to nonparaxial propagation. Omitting \(Q_3\) leaves the intensity
unchanged because this factor has unit magnitude for real parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
Complex-valued input field on a square grid of shape |
required |
z
|
float
|
Nonzero propagation distance in meters. |
required |
wavelength
|
float
|
Positive wavelength in meters. |
required |
dx
|
float
|
Positive source-plane pixel size in meters. |
required |
dq
|
float
|
Positive destination-plane pixel size in meters. |
required |
bandlimit
|
bool
|
Apply circular sampling masks to |
True
|
exactSolution
|
bool
|
Include the output-plane quadratic phase factor |
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Examples:
>>> u = np.ones((64, 64), dtype=complex)
>>> u_out, q1, q2 = scaledASP(
... u, z=0.01, wavelength=500e-9, dx=5e-6, dq=4e-6
... )
>>> u_out.shape
(64, 64)
Source code in PtyLab/Operators/Operators.py
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 | |
scaledASPinv(u, z, wavelength, dx, dq)
¶
Back-propagate a field using conjugated scaled Fresnel phase factors.
Reverses the unmasked scaled propagation performed by scaledASP
with exactSolution=False. The backward operation is
where \(Q_1\) and \(Q_2\) are constructed from the original forward propagation geometry.
Pass the same propagation distance and pixel sizes as in the forward
call. Do not negate z or interchange dx and dq.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
Complex-valued destination-plane field sampled at pixel size
|
required |
z
|
float
|
Nonzero propagation distance used in the forward operation, in meters. |
required |
wavelength
|
float
|
Positive wavelength in meters. |
required |
dx
|
float
|
Positive source-plane pixel size from the forward operation, in meters. This is the pixel size of the returned field. |
required |
dq
|
float
|
Positive destination-plane pixel size from the forward
operation, in meters. This is the pixel size of |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Back-propagated complex field with the same shape as |
Notes
This function uses the Fresnel (paraxial) approximation and does not apply band-limit masks. It is the inverse of the unmasked forward operator for even-sized grids, up to numerical precision. Information discarded by forward band limiting is not recovered.
If the forward calculation used exactSolution=True, multiply
its output by Q3.conj() before passing it to this function.
Odd-sized grids currently use coordinates inconsistent with
scaledASP and should be avoided.
Examples:
>>> u = np.ones((32, 32), dtype=complex)
>>> v, _, _ = scaledASP(
... u, 0.01, 500e-9, 5e-6, 4e-6,
... bandlimit=False, exactSolution=False
... )
>>> recovered = scaledASPinv(v, 0.01, 500e-9, 5e-6, 4e-6)
>>> np.allclose(recovered, u)
True
Source code in PtyLab/Operators/Operators.py
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 | |
fresnelPropagator(u, z, wavelength, L)
¶
Propagate a field using a single-FFT Fresnel approximation.
Multiplies the source field by a quadratic phase factor Q1,
applies a centered orthonormal Fourier transform, and multiplies
the result by the destination-plane phase factor Q2 and
1 / (1j * wavelength * z).
The source and destination pixel sizes are related by
Unlike scaledASP, this method does not allow the destination
pixel size to be chosen independently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
Source-plane field on a square grid of shape |
required |
z
|
float
|
Nonzero propagation distance in meters. Positive values give a positive destination pixel spacing. |
required |
wavelength
|
float
|
Positive wavelength in meters. |
required |
L
|
float
|
Positive physical side length of the source grid in meters.
The source pixel size is |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
|
Notes
This standalone helper is currently unused by the reconstruction
workflow. The repository contains an unused import and a skipped
test; reconstruction uses propagate_fresnel and
propagate_fresnel_inv instead. External usage has not been
assessed.
This implementation uses the paraxial approximation and does not apply explicit band limiting or zero-padding.
Absolute physical amplitude normalization is incomplete:
the orthonormal FFT requires an additional factor N * dx**2
to represent the discretized Fresnel integral. The global
propagation phase exp(1j * k * z) is also omitted.
Zero-distance propagation is not supported.
Examples:
>>> u = np.ones((64, 64), dtype=complex)
>>> u_out, dq, q1, q2 = fresnelPropagator(
... u, z=0.01, wavelength=500e-9, L=320e-6
... )
>>> u_out.shape
(64, 64)
Source code in PtyLab/Operators/Operators.py
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 | |
clear_cache(logger=None)
¶
Clear cached propagation kernels and quadratic phase factors.
Clears the seven registered propagation-helper caches, including
the shared quadratic-phase cache imported from
PtyLab.Operators._propagation_kernels. Both CPU and GPU cache
entries are removed, and cache hit/miss statistics are reset.
Subsequent propagation calls recompute the required arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
Logger used to report cache statistics at DEBUG level and cache-clearing messages at INFO level. If None, no messages are emitted by this function. Defaults to None. |
None
|
Notes
This is a manual maintenance utility; no internal calls were found in the current reconstruction workflow.
Clearing the caches removes their references to stored arrays. Arrays referenced elsewhere remain allocated. This function does not explicitly release memory retained by CuPy's memory pool, so reported GPU memory usage may not immediately decrease.
Avoid clearing caches inside reconstruction loops, since this forces repeated computation of propagation factors.
Examples:
Source code in PtyLab/Operators/Operators.py
aspw_cached(u, z, wavelength, L)
¶
Propagate a spatial-domain field using a cached angular-spectrum kernel.
Applies a centered Fourier transform to the input, multiplies it by
the band-limited transfer function from __aspw_transfer_function,
and transforms the result back to the spatial domain. NumPy and CuPy
arrays are supported.
Only the transfer function is cached. The Fourier transforms and
propagated field are computed on every call. aspw also uses the
cached kernel; this helper provides a field-only return value with
band limiting always enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
Spatial-domain input field with square final two dimensions
|
required |
z
|
float
|
Propagation distance in meters. Negative values use the complex conjugate of the positive-distance kernel. |
required |
wavelength
|
float
|
Positive wavelength in meters. |
required |
L
|
float
|
Positive physical side length of the spatial grid in meters.
The input and output pixel sizes are both |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Propagated complex field with the same shape and NumPy or CuPy backend as the input. The transfer function is not returned. |
Notes
For ordinary scalar geometry parameters, this is equivalent to
taking the first return value of
aspw(u, z, wavelength, L, bandlimit=True, is_FT=False).
The input must not already be Fourier-transformed.
Band limiting removes spatial frequencies, so backward propagation does not generally recover the original field. Use even-sized grids because the underlying kernel currently uses frequency coordinates inconsistent with FFT bins for odd N.
Examples:
>>> u = np.ones((64, 64), dtype=complex)
>>> u_out = aspw_cached(u, z=0.01, wavelength=500e-9, L=320e-6)
>>> u_out.shape
(64, 64)
Source code in PtyLab/Operators/Operators.py
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 | |