Functional¶
Sources¶
FieldPupil = Callable[[Field], Field]
module-attribute
¶
__all__ = ['point_source', 'objective_point_source', 'plane_wave', 'gaussian_plane_wave', 'generic_field']
module-attribute
¶
gaussian_plane_wave(shape, dx, spectrum, waist, power=1.0, amplitude=1.0, kykx=(0.0, 0.0), pupil=None, scalar=True)
¶
Generates plane wave of given power with a Gaussian intensity profile
(as opposed to a totally flat plane wave). Can also be given pupil and
kykx vector to control the angle of the plane wave.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, int]
|
The shape (height and width) of the |
required |
dx
|
ScalarLike | Float[Array, wv] | Float[Array, 'wv 2']
|
The spacing (pixel size) of the samples of the |
required |
spectrum
|
Spectrum | ScalarLike | Float[Array, wv] | tuple[Float[Array, wv], Float[Array, wv]]
|
The
|
required |
waist
|
ScalarLike
|
The size of the waist (twice the standard deviation) as a scalar in units of distance. This waist defines the width of the 2D Gaussian amplitude profile of this beam. |
required |
power
|
ScalarLike | None
|
The total power that the result should be normalized to, defaults
to 1.0. If |
1.0
|
amplitude
|
ScalarLike | Float[Array, 3]
|
The amplitude of the electric field. For scalar |
1.0
|
kykx
|
ArrayLike | tuple[int, int]
|
Defines the orientation of the plane wave. Should be a tuple or an
array of shape |
(0.0, 0.0)
|
pupil
|
FieldPupil | None
|
A function that applies a pupil to the field if provided.
Defaults to |
None
|
scalar
|
bool
|
Whether the result should be |
True
|
Source code in src/chromatix/functional/sources.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 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 | |
generic_field(dx, spectrum, amplitude, phase, power=1.0, pupil=None, scalar=True)
¶
Generates field with arbitrary phase and amplitude.
You can likely use the appropriate constructor for the type
of Field you want rather than this function, or just use
Field.build.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dx
|
ScalarLike | Float[Array, wv] | Float[Array, 'wv 2']
|
The spacing (pixel size) of the samples of the |
required |
spectrum
|
Spectrum | ScalarLike | Float[Array, wv] | tuple[Float[Array, wv], Float[Array, wv]]
|
The
|
required |
amplitude
|
ArrayLike
|
The amplitude of the field with shape |
required |
phase
|
ArrayLike
|
The phase of the field with shape |
required |
power
|
ScalarLike | None
|
The total power (a scalar value) that the result should be
normalized to, defaults to 1.0. If |
1.0
|
pupil
|
FieldPupil | None
|
A function that applies a pupil to the field if provided.
Defaults to |
None
|
scalar
|
bool
|
Whether the result should be |
True
|
Source code in src/chromatix/functional/sources.py
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 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | |
objective_point_source(shape, dx, spectrum, z, f, n, NA, power=1.0, amplitude=1.0, offset=(0.0, 0.0), scalar=True)
¶
Generates field due to a point source defocused by an amount z away from
the focal plane, just after passing through a thin lens with focal length
f and numerical aperture NA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, int]
|
The shape (height and width) of the |
required |
dx
|
ScalarLike | Float[Array, wv] | Float[Array, 'wv 2']
|
The spacing (pixel size) of the samples of the |
required |
spectrum
|
Spectrum | ScalarLike | Float[Array, wv] | tuple[Float[Array, wv], Float[Array, wv]]
|
The
|
required |
z
|
ScalarLike | Float[Array, z]
|
How far away the point source is from the focal plane of the lens in units of distance. |
required |
f
|
ScalarLike
|
Focal length of the objective lens in units of distance. |
required |
n
|
ScalarLike
|
Refractive index. |
required |
NA
|
ScalarLike
|
The numerical aperture of the objective lens. |
required |
power
|
ScalarLike | None
|
The total power that the result should be normalized to, defaults
to 1.0. If |
1.0
|
amplitude
|
ScalarLike | Float[Array, 3]
|
The amplitude of the electric field. For scalar |
1.0
|
offset
|
Float[Array, 2] | tuple[float, float]
|
The offset of the point source in the plane in units of
distance. Should be a tuple or an array of shape |
(0.0, 0.0)
|
scalar
|
bool
|
Whether the result should be |
True
|
Source code in src/chromatix/functional/sources.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
plane_wave(shape, dx, spectrum, power=1.0, amplitude=1.0, kykx=(0.0, 0.0), pupil=None, scalar=True)
¶
Generates plane wave of given power, as exp(1j) at each location of
the field. Can also be given pupil and kykx vector to control the
angle of the plane wave. If a kykx wave vector is provided, the plane
wave is constructed as exp(1j * jnp.sum(kykx * field.grid, axis=-1)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, int]
|
The shape (height and width) of the |
required |
dx
|
ScalarLike | Float[Array, wv] | Float[Array, 'wv 2']
|
The spacing (pixel size) of the samples of the |
required |
spectrum
|
Spectrum | ScalarLike | Float[Array, wv] | tuple[Float[Array, wv], Float[Array, wv]]
|
The
|
required |
power
|
ScalarLike | None
|
The total power that the result should be normalized to, defaults
to 1.0. If |
1.0
|
amplitude
|
ScalarLike | Float[Array, 3]
|
The amplitude of the electric field. For scalar |
1.0
|
kykx
|
ArrayLike | tuple[float, float]
|
Defines the orientation of the plane wave. Should be a tuple or an
array of shape |
(0.0, 0.0)
|
pupil
|
FieldPupil | None
|
A function that applies a pupil to the field if provided.
Defaults to |
None
|
scalar
|
bool
|
Whether the result should be |
True
|
Source code in src/chromatix/functional/sources.py
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 | |
point_source(shape, dx, spectrum, z, n, power=1.0, amplitude=1.0, offset=(0.0, 0.0), pupil=None, scalar=True, epsilon=float(np.finfo(np.float32).eps))
¶
Generates field due to point source a distance z away. Can also be given
pupil.
Warning
This function is numerically unstable at z = 0, so an epsilon is applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, int]
|
The shape (height and width) of the |
required |
dx
|
ScalarLike | Float[Array, wv] | Float[Array, 'wv 2']
|
The spacing (pixel size) of the samples of the |
required |
spectrum
|
Spectrum | ScalarLike | Float[Array, wv] | tuple[Float[Array, wv], Float[Array, wv]]
|
The
|
required |
z
|
ScalarLike | Float[Array, z]
|
How far away the point source is in units of distance. |
required |
n
|
ScalarLike
|
Refractive index. |
required |
power
|
ScalarLike | None
|
The total power that the result should be normalized to, defaults
to 1.0. If |
1.0
|
amplitude
|
ScalarLike | Float[Array, 3]
|
The amplitude of the electric field. For scalar |
1.0
|
offset
|
Float[Array, 2] | tuple[float, float]
|
The offset of the point source in the plane in units of
distance. Should be a tuple or an array of shape |
(0.0, 0.0)
|
pupil
|
FieldPupil | None
|
A function that applies a pupil to the field if provided.
Defaults to |
None
|
scalar
|
bool
|
Whether the result should be |
True
|
epsilon
|
float
|
Value added to denominators for numerical stability when z is 0. |
float(eps)
|
Source code in src/chromatix/functional/sources.py
Lenses¶
__all__ = ['thin_lens', 'ff_lens', 'df_lens', 'microlens_array', 'hexagonal_microlens_array', 'rectangular_microlens_array', 'thick_plano_convex_lens', 'thick_plano_convex_ff_lens', 'high_na_ff_lens']
module-attribute
¶
df_lens(field, d, f, n, NA=None, inverse=False)
¶
Applies a thin lens placed a distance d after the incoming Field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The |
required |
d
|
ScalarLike
|
Distance from the incoming |
required |
f
|
ScalarLike
|
Focal length of the lens in units of distance. |
required |
n
|
ScalarLike
|
The refractive index of the surrounding medium (assumed to be the same incoming and exiting). |
required |
NA
|
ScalarLike | None
|
If provided, the NA of the lens. By default, no pupil is applied
to the incoming |
None
|
inverse
|
bool
|
Whether the field is passing forwards or backwards through
the lens. If |
False
|
Returns:
| Type | Description |
|---|---|
Field
|
The |
Source code in src/chromatix/functional/lenses.py
ff_lens(field, f, n, NA=None, inverse=False)
¶
Applies a thin lens placed a distance f after the incoming Field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The |
required |
f
|
ScalarLike
|
Focal length of the lens in units of distance. |
required |
n
|
ScalarLike
|
The refractive index of the surrounding medium (assumed to be the same incoming and exiting). |
required |
NA
|
ScalarLike | None
|
If provided, the NA of the lens. By default, no pupil is applied
to the incoming |
None
|
inverse
|
bool
|
Whether the field is passing forwards or backwards through
the lens. If |
False
|
Returns:
| Type | Description |
|---|---|
Field
|
The |
Source code in src/chromatix/functional/lenses.py
hexagonal_microlens_array(field, f, n, num_lenses_per_side, radius, separation, block_between=False)
¶
Applies a microlens array of hexagonally arranged microlenses placed
immediately in the plane of the incoming Field.
Warning
If you have recently used this function prior to it being documented, note that the arguments have changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The |
required |
f
|
ScalarLike
|
A scalar value defining the focal length of each lens in units of distance. |
required |
n
|
ScalarLike
|
The refractive index of the surrounding medium (assumed to be the same incoming and exiting). |
required |
num_lenses_per_side
|
int
|
The number of lenses on each outer side of the hexagon (e.g. setting this number to 4 will create 37 microlenses). |
required |
radius
|
Array
|
A scalar value defining the radius of each microlens in units of distance. |
required |
separation
|
ScalarLike
|
A scalar value defining how far apart the center of each microlens is from its neighbors in units of distance. |
required |
block_between
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Field
|
The |
Source code in src/chromatix/functional/lenses.py
high_na_ff_lens(field, f, n, NA, output_shape=None, output_dx=None)
¶
Applies a high NA lens placed a distance f after the incoming Field.
Warning
This function assumes that the incoming Field contains only a single
wavelength and has a square shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
ScalarField | VectorField
|
The |
required |
f
|
float
|
Focal length of the lens. |
required |
n
|
float
|
The refractive index of the surrounding medium (assumed to be the same incoming and exiting). |
required |
NA
|
float
|
The NA of the lens. |
required |
output_shape
|
tuple[int, int] | None
|
The shape of the camera (in pixels). If not provided, the output shape will be the same as the shape of the incoming field. |
None
|
output_dx
|
ScalarLike | None
|
The pixel pitch of the camera (in units of distance). If not provided, the output spacing will be the same as the spacing of the incoming field. |
None
|
Returns:
| Type | Description |
|---|---|
ScalarField | VectorField
|
The |
Source code in src/chromatix/functional/lenses.py
microlens_array(field, fs, n, centers, radii, block_between=False)
¶
Applies a microlens array of arbitrary positioned microlenses placed
immediately in the plane of the incoming Field.
Warning
If you have recently used this function prior to it being documented, note that the arguments have changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The |
required |
fs
|
Float[Array, m]
|
A 1D array of shape |
required |
n
|
ScalarLike
|
The refractive index of the surrounding medium (assumed to be the same incoming and exiting). |
required |
centers
|
Float[Array, m]
|
A 2D array of shape |
required |
radii
|
Float[Array, m]
|
A 1D array of shape |
required |
Returns:
| Type | Description |
|---|---|
Field
|
The |
Source code in src/chromatix/functional/lenses.py
rectangular_microlens_array(field, n, f, num_lenses_height, num_lenses_width, radius, separation, block_between=False)
¶
Applies a microlens array of hexagonally arranged microlenses placed
immediately in the plane of the incoming Field.
Warning
If you have recently used this function prior to it being documented, note that the arguments have changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The |
required |
n
|
ScalarLike
|
The refractive index of the surrounding medium (assumed to be the same incoming and exiting). |
required |
f
|
Array
|
A scalar value defining the focal length of each lens in units of distance. |
required |
num_lenses_height
|
int
|
The number of lenses on each vertical side of the rectangle. |
required |
num_lenses_width
|
int
|
The number of lenses on each horizontal side of the rectangle. |
required |
radius
|
Array
|
A scalar value defining the radius of each microlens in units of distance. |
required |
separation
|
ScalarLike
|
A scalar value defining how far apart the center of each microlens is from its neighbors in units of distance. |
required |
block_between
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Field
|
The |
Source code in src/chromatix/functional/lenses.py
thick_plano_convex_ff_lens(field, f, radius, center_thickness, n_lens, n_medium=1.0, NA=None, inverse=False, magnification=1.0)
¶
Applies a thick plano-convex lens placed a distance f after the incoming
Field. This lens includes propagation by a small distance within the
lens (defined by center_thickness).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The |
required |
f
|
ScalarLike
|
The focal length of the lens in units of distance. |
required |
radius
|
ScalarLike
|
The radius of the spherical part of the plano-convex lens in units of distance. |
required |
center_thickness
|
ScalarLike
|
The maximum thickness of the plano-convex lens (i.e. the distance through the center of the lens) in units of distance. |
required |
n_lens
|
ScalarLike
|
The refractive index of the lens material (e.g. glass). |
required |
n_medium
|
ScalarLike
|
The refractive index of the surrounding medium (assumed to be the same incoming and exiting). Defaults to 1.0 for air. |
1.0
|
NA
|
ScalarLike | None
|
If provided, the NA of the lens. By default, no pupil is applied
to the incoming |
None
|
inverse
|
bool
|
Whether the field is passing forwards (plano-convex) or
backwards (convex-plano) through the lens. If |
False
|
magnification
|
ScalarLike
|
The magnification to be applied to the propagation
through the system. A magnification of greater than 1 will zoom
in during the propagation (decrease the spacing of the outgoing
|
1.0
|
Returns:
| Type | Description |
|---|---|
Field
|
The |
Source code in src/chromatix/functional/lenses.py
thick_plano_convex_lens(field, f, radius, center_thickness, n_lens, n_medium=1.0, NA=None, inverse=False, magnification=1.0)
¶
Applies a thick plano-convex lens placed immediately in the plane of the
incoming Field. This lens includes propagation by a small distance
within the lens (defined by center_thickness).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The |
required |
f
|
ScalarLike
|
The focal length of the lens in units of distance. |
required |
radius
|
ScalarLike
|
The radius of the spherical part of the plano-convex lens in units of distance. |
required |
center_thickness
|
ScalarLike
|
The maximum thickness of the plano-convex lens (i.e. the distance through the center of the lens) in units of distance. |
required |
n_lens
|
ScalarLike
|
The refractive index of the lens material (e.g. glass). |
required |
n_medium
|
ScalarLike
|
The refractive index of the surrounding medium (assumed to be the same incoming and exiting). Defaults to 1.0 for air. |
1.0
|
NA
|
ScalarLike | None
|
If provided, the NA of the lens. By default, no pupil is applied
to the incoming |
None
|
inverse
|
bool
|
Whether the field is passing forwards (plano-convex) or
backwards (convex-plano) through the lens. If |
False
|
magnification
|
ScalarLike
|
The magnification to be applied to the propagation
through the system. A magnification of greater than 1 will zoom
in during the propagation (decrease the spacing of the outgoing
|
1.0
|
Returns:
| Type | Description |
|---|---|
Field
|
The |
Source code in src/chromatix/functional/lenses.py
thin_lens(field, f, n, NA=None)
¶
Applies a thin lens placed immediately in the plane of the incoming Field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The |
required |
f
|
ScalarLike
|
Focal length of the lens in units of distance. |
required |
n
|
ScalarLike
|
The refractive index of the surrounding medium (assumed to be the same incoming and exiting). |
required |
NA
|
ScalarLike | None
|
If provided, the NA of the lens. By default, no pupil is applied
to the incoming |
None
|
Returns:
| Type | Description |
|---|---|
Field
|
The |
Source code in src/chromatix/functional/lenses.py
Phase Masks¶
__all__ = ['phase_change', 'interpolated_phase_change', 'wrap_phase', 'spectrally_modulate_phase', 'thin_prism', 'sawtooth_grating', 'sinusoid_grating', 'axicon']
module-attribute
¶
axicon(field, n_axicon, slope_angle, n_medium=1.0)
¶
Applies an axicon placed immediately in the plane of the incoming Field.
The steepness of the axicon can be controlled with slope_angle. To change the
direction of the prism, a rotation can be applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The |
required |
n_axicon
|
ScalarLike
|
The refractive index of the axicon material (e.g. glass). |
required |
slope_angle
|
ScalarLike
|
The angle between the base of the axicon and the base in radians. |
required |
n_medium
|
ScalarLike
|
The refractive index of the surrounding medium. Defaults to 1.0 for air. |
1.0
|
Returns:
| Type | Description |
|---|---|
Field
|
The perturbed |
Source code in src/chromatix/functional/phase_masks.py
interpolated_phase_change(field, phase, phase_range=None, num_bits=None, interpolation_order=0, spectrally_modulate=True)
¶
Perturbs field by phase (in radians), i.e. field * exp(1j
* phase), but with an interpolation of the phase mask to the number of
samples (pixels) in the incoming field. This is useful when the phase mask
itself has a different number of pixels than the field (typically the phase
mask has fewer pixels than the finely-sampled field, e.g. when simulating a
spatial light modulator). Assumes that the phase mask should be interpolated
to the entire extent of the incoming field, i.e. that the extent of the
field is exactly that of the phase mask.
Also scales the phase by the ratio of each wavelength to the central
wavelength of the spectrum (i.e. the first wavelength in the array
of wavelengths) by default. This scaling is necessary to achieve the
proper chromatic dispersion effect after propagating a field that is not
monochromatic through a phase mask (especially if the phase mask is a fine
grating). Returns a new Field with the result of the perturbation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The complex field to be perturbed. |
required |
phase
|
Float[Array, 'h w']
|
The phase mask to apply as a 2D array of phase values (in
radians) of shape |
required |
phase_range
|
tuple[float, float] | None
|
A tuple of two scalar values defining the minimum and
maximum phase range values respectively (in radians) to which the
provided phase values should be wrapped. For example, this could
be |
None
|
num_bits
|
int | None
|
An integer value representing the number of bits to which the
phase mask should be quantized, i.e. only |
None
|
interpolation_order
|
int
|
An integer defining the order of the interpolation
of the phase values to the number of pixels of the field. Set to |
0
|
spectrally_modulate
|
bool
|
Whether to perform the per-wavelength scaling
of the phase based on the given spectrum of the incoming field.
Assumes the phase mask is designed for the central wavelength of the
spectrum (assumed to be the first wavelength in the spectrum). Set
to |
True
|
Returns:
| Type | Description |
|---|---|
Field
|
The perturbed |
Source code in src/chromatix/functional/phase_masks.py
phase_change(field, phase, spectrally_modulate=True)
¶
Perturbs field by phase (in radians), i.e. field * exp(1j * phase).
Also scales the phase by the ratio of each wavelength to the central
wavelength of the spectrum (i.e. the first wavelength in the array
of wavelengths) by default. This scaling is necessary to achieve the
proper chromatic dispersion effect after propagating a field that is not
monochromatic through a phase mask (especially if the phase mask is a fine
grating). Returns a new Field with the result of the perturbation.
Common phase mask generators can be found in chromatix.utils.initializers.
These generators typically assume that the phase mask is placed at the pupil
plane of a system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The complex field to be perturbed. |
required |
phase
|
Float[Array, 'h w']
|
The phase mask to apply as a 2D array of phase values (in
radians) of shape |
required |
spectrally_modulate
|
bool
|
Whether to perform the per-wavelength scaling
of the phase based on the given spectrum of the incoming field.
Assumes the phase mask is designed for the central wavelength of the
spectrum (assumed to be the first wavelength in the spectrum). Set
to |
True
|
Returns:
| Type | Description |
|---|---|
Field
|
The perturbed |
Source code in src/chromatix/functional/phase_masks.py
sawtooth_grating(field, n_grating, period, thickness, rotation=0.0, n_medium=1.0)
¶
Applies a sawtooth grating placed immediately in the plane of the incoming
Field.
The grating can be varied in thickness which changes the overall scale
of the phase values used to calculate the effect of the grating (i.e. the
grating phase is calculated as a thin sample). To change the direction of
the grating, a rotation can be applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The |
required |
n_grating
|
ScalarLike
|
The refractive index of the grating material (e.g. glass). |
required |
period
|
ScalarLike
|
The period of the sawtooth wave defining the grating in units of distance. |
required |
thickness
|
ScalarLike
|
A scalar defining the thickness of the grating in units of distance. |
required |
rotation
|
ScalarLike
|
How much to rotate the grating in-plane (counter-clockwise in radians). |
0.0
|
n_medium
|
ScalarLike
|
The refractive index of the surrounding medium. Defaults to 1.0 for air. |
1.0
|
Returns:
| Type | Description |
|---|---|
Field
|
The perturbed |
Source code in src/chromatix/functional/phase_masks.py
sinusoid_grating(field, n_grating, period, thickness, rotation=0.0, n_medium=1.0)
¶
Applies a sinusoid grating placed immediately in the plane of the incoming
Field.
The grating can be varied in thickness which changes the overall scale
of the phase values used to calculate the effect of the grating (i.e. the
grating phase is calculated as a thin sample). To change the direction of
the grating, a rotation can be applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The |
required |
n_grating
|
ScalarLike
|
The refractive index of the grating material (e.g. glass). |
required |
period
|
ScalarLike
|
The period of the sinusoid wave defining the grating in units of distance. |
required |
thickness
|
ScalarLike
|
A scalar defining the thickness of the grating in units of distance. |
required |
rotation
|
ScalarLike
|
How much to rotate the grating in-plane (counter-clockwise in radians). |
0.0
|
n_medium
|
ScalarLike
|
The refractive index of the surrounding medium. Defaults to 1.0 for air. |
1.0
|
Returns:
| Type | Description |
|---|---|
Field
|
The perturbed |
Source code in src/chromatix/functional/phase_masks.py
spectrally_modulate_phase(phase, spectrum)
¶
Spectrally modulates a given phase for multiple wavelengths.
Scales the phase by the ratio of each wavelength to the central wavelength of the spectrum (i.e. the first wavelength in the array of wavelengths) by default. This scaling is necessary to achieve the proper chromatic dispersion effect after propagating a field that is not monochromatic through a phase mask (especially if the phase mask is a fine grating).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phase
|
Array
|
The phase mask to apply as a 2D array of phase values (in
radians) of shape |
required |
spectrum
|
Spectrum
|
The |
required |
Source code in src/chromatix/functional/phase_masks.py
thin_prism(field, n_prism, max_thickness, rotation=0.0, n_medium=1.0)
¶
Applies a thin prism placed immediately in the plane of the incoming Field.
The prism is applied as a linear phase ramp that starts at 0 and increases
horizontally to the right to a maximum value determined by the specified
max_thickness. To change the direction of the prism, a rotation can
be applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The |
required |
n_prism
|
ScalarLike
|
The refractive index of the prism material (e.g. glass). |
required |
max_thickness
|
ScalarLike
|
A scalar defining the maximum thickness of the prism in units of distance. |
required |
rotation
|
ScalarLike
|
How much to rotate the prism in-plane (counter-clockwise in radians). |
0.0
|
n_medium
|
ScalarLike
|
The refractive index of the surrounding medium. Defaults to 1.0 for air. |
1.0
|
Returns:
| Type | Description |
|---|---|
Field
|
The perturbed |
Source code in src/chromatix/functional/phase_masks.py
wrap_phase(phase, limits=(-jnp.pi, jnp.pi))
¶
Wraps values of phase to the range given by limits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phase
|
Float[Array, 'h w']
|
The phase mask to wrap (in radians) as a 2D array of shape
|
required |
limits
|
ArrayLike | tuple[float, float]
|
A tuple defining the minimum and maximum value that |
(-pi, pi)
|
Source code in src/chromatix/functional/phase_masks.py
Amplitude Masks¶
__all__ = ['amplitude_change', 'interpolated_amplitude_change']
module-attribute
¶
amplitude_change(field, amplitude)
¶
Perturbs field by amplitude, i.e. field * amplitude.
Returns a new Field with the result of the perturbation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The complex field to be perturbed. |
required |
amplitude
|
Float[Array, 'h w']
|
The amplitude mask to apply as a 2D array of amplitude values
of shape |
required |
Source code in src/chromatix/functional/amplitude_masks.py
interpolated_amplitude_change(field, amplitude, binary=False, num_bits=None, interpolation_order=0)
¶
Perturbs field by amplitude, i.e. field * amplitude, but with
an interpolation of the amplitude mask to the number of samples (pixels)
in the incoming field. This is useful when the amplitude mask itself has a
different number of pixels than the field (typically the amplitude mask has
fewer pixels than the finely-sampled field, e.g. when simulating a digital
micromirror device). Assumes that the amplitude mask should be interpolated
to the entire extent of the incoming field, i.e. that the extent of the
field is exactly that of the amplitude mask.
Returns a new Field with the result of the perturbation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The complex field to be perturbed. |
required |
amplitude
|
Float[Array, 'h w']
|
The amplitude mask to apply as a 2D array of amplitude values
of shape |
required |
binary
|
bool
|
Whether the amplitude values should be binarized (0 or 1) or
not. Defaults to |
False
|
num_bits
|
int | None
|
An integer value representing the number of bits to which the
amplitude mask should be quantized, i.e. only |
None
|
interpolation_order
|
int
|
An integer defining the order of the interpolation
of the amplitude values to the number of pixels of the field. Set to
|
0
|
Source code in src/chromatix/functional/amplitude_masks.py
Samples¶
fluorescent_multislice_thick_sample(field, fluorescence_stack, dn_stack, n, thickness_per_slice, pad_width, key, num_samples=1, propagator_forward=None, propagator_backward=None, kykx=(0.0, 0.0), remove_evanescent=False, bandlimit=False)
¶
Perturbs incoming Field as if it went through a thick, transparent,
and fluorescent sample, i.e. a sample consisting of some distribution of
fluorophores emitting within a clear (phase only) scattering volume (with
isotropic refractive index). The thick sample is modeled as being made
of many thin slices each of a given thickness. The fluorescence_stack
contains the fluorescence intensities of each sample slice. The dn_stack
contains the phase delay as change in refractive index from the refractive
index of the medium of each sample slice.
This function simulates the incoherent light from fluorophores using a Monte-Carlo approach in which random phases are applied to the fluorescence and the resulting propagations are averaged.
A propagator_forward and a propagator_backward defining the
propagation kernels for the field going forward and backward through each
slice can be provided. By default, these propagator kernels is calculated
inside the function. After passing through all slices, the field is
propagated backwards slice by slice to compute the scattered fluorescence
intensity.
Returns an Array with the result of the scattered fluorescence intensity
volume.
Warning
The underlying propagation method now defaults to the angular spectrum
method (ASM) with bandlimit=False and `remove_evanescent=False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The complex field to be perturbed. |
required |
fluorescence_stack
|
Float[Array, 'd h w']
|
The sample fluorescence amplitude for each slice
defined as a 3D array of shape |
required |
dn_stack
|
Float[Array, 'd h w']
|
Sample refractive index change as a 3D array of shape |
required |
n
|
ScalarLike
|
Average refractive index of the sample. |
required |
thickness_per_slice
|
ScalarLike
|
How far to propagate for each slice in units of distance. |
required |
pad_width
|
int
|
An integer defining the pad length for the
propagation FFT (NOTE: should not be a |
required |
key
|
PRNGKey
|
A |
required |
num_samples
|
int
|
The number of Monte-Carlo samples (random phases) to simulate. |
1
|
propagator_forward
|
ArrayLike | None
|
The propagator kernel for the forward propagation through the sample. |
None
|
propagator_backward
|
ArrayLike | None
|
The propagator kernel for the backward propagation through the sample. |
None
|
kykx
|
ArrayLike | tuple[float, float]
|
If provided, defines the orientation of the propagation. Should
be an array of shape |
(0.0, 0.0)
|
remove_evanescent
|
bool
|
If |
False
|
bandlimit
|
bool
|
Whether to bandlimit the field before propagation. Defaults
to |
False
|
Returns:
| Type | Description |
|---|---|
Array
|
The scattered fluorescence stack as a 3D array of shape ``(depth height |
Array
|
width)`` after scattering through the provided sample. |
Source code in src/chromatix/functional/samples.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 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 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
jones_sample(field, absorption, dn, thickness)
¶
Perturbs an incoming vectorial Field as if it went through a thin sample
object with a given absorption, anisotropic refractive index change from
the refractive index of the medium dn, and thickness. Ignores the
incoming field in z direction.
The sample is supposed to follow the thin sample approximation, so the
sample perturbation is calculated for each component in the Jones matrix as:
exp(1j * 2 * pi * (dn + 1j * absorption) * thickness / lambda) where dn
and absorption are allowed to vary per component of the Jones matrix, but
thickness is assumed to be the same for each component of the Jones matrix.
Returns a VectorField with the result of the perturbation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
VectorField | ChromaticVectorField
|
The complex field to be perturbed. |
required |
absorption
|
Float[Array, '2 2 h w']
|
The sample absorption defined as a 4D array of shape |
required |
dn
|
Float[Array, '2 2 h w']
|
Sample refractive index change as a 4D array of shape |
required |
thickness
|
ScalarLike
|
Thickness at each sample location as either a scalar or an
array with shape or shape broadcastable to |
required |
Returns:
| Type | Description |
|---|---|
VectorField | ChromaticVectorField
|
|
Source code in src/chromatix/functional/samples.py
multislice_thick_sample(field, absorption_stack, dn_stack, n, thickness_per_slice, pad_width, NA=None, propagator=None, kykx=(0.0, 0.0), reverse_propagate_distance=None, return_stack=False, remove_evanescent=False, bandlimit=False)
¶
Perturbs incoming ScalarField as if it went through a thick sample. The
thick sample is modeled as being made of many thin slices each of a given
thickness. The absorption_stack and dn_stack contain the absorbance
and change in isotropic refractive index from the refractive index of the
medium of each sample slice. Expects that the same sample is being applied
to all elements across the batch of the incoming Field.
A propagator defining the propagation kernel for the field through each
slice can be provided. By default, a propagator is calculated inside
the function. After passing through all slices, the field is propagated
backwards to the center of the stack, or by the distances specified by
reverse_propagate_distance if provided.
Returns a Field with the result of the perturbation.
Warning
The underlying propagation method now defaults to the angular spectrum
method (ASM) with bandlimit=False and remove_evanescent=False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The complex field to be perturbed. |
required |
absorption_stack
|
Float[Array, 'd h w']
|
The sample's absorption per voxel for each slice
defined as a 3D array of shape |
required |
dn_stack
|
Float[Array, 'd h w']
|
The sample's isotropic refractive index change for each slice
as a 3D array of shape |
required |
n
|
ScalarLike
|
Average refractive index of the sample. |
required |
thickness_per_slice
|
ScalarLike
|
How far to propagate for each slice. |
required |
pad_width
|
int
|
An integer defining the pad length for the
propagation FFT (NOTE: should not be a |
required |
NA
|
ScalarLike | None
|
If provided, will be used to define the numerical aperture (limiting the captured frequencies) of the lens that is imaging the center of the volume. If not provided (the default case), this function will return the scattered field directly which may have undesirable high frequencies. |
None
|
propagator
|
ArrayLike | None
|
If provided, will be used as the propagation kernel at each plane of the sample. By default, the propagation kernel is constructed automatically prior to looping through the planes of the sample. |
None
|
kykx
|
ArrayLike | tuple[float, float]
|
If provided, defines the orientation of the propagation. Should
be an array of shape |
(0.0, 0.0)
|
reverse_propagate_distance
|
ScalarLike | None
|
If provided, propagates field at the end backwards by this amount from the top of the stack. By default, field is propagated backwards to the middle of the sample. |
None
|
return_stack
|
bool
|
If |
False
|
remove_evanescent
|
bool
|
If |
False
|
bandlimit
|
bool
|
Whether to bandlimit the field before propagation. Defaults
to |
False
|
Returns:
| Type | Description |
|---|---|
Field
|
If |
Field
|
propagating through sample and being focused to its center (or to any |
Field
|
plane of the sample defined by |
Field
|
optical system with the specified numerical aperture. Otherwise, returns |
Field
|
the intermediate scattered fields at each plane of the sample (where |
Field
|
each plane is contained in the first batch dimension of the resulting |
Field
|
|
Source code in src/chromatix/functional/samples.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 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 | |
polarized_multislice_thick_sample(field, potential_stack, n, thickness_per_slice, NA=1.0)
¶
Implements a thick sample method for samples with anisotroipc refractive index (birefringent samples) per [1].
[1]: Multislice computational model for birefringent scattering, https://doi.org/10.1364/OPTICA.472077.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
VectorField | ChromaticVectorField
|
Incoming vectorial field to propagate through sample. |
required |
potential_stack
|
Float[Array, 'd h w 3 3']
|
Scattering potential as a 5D array of shape |
required |
n
|
ScalarLike
|
Refractive index of medium. |
required |
thickness_per_slice
|
ScalarLike
|
Thickness of each slice of the sample along the optical axis in units of distance. |
required |
NA
|
ScalarLike
|
Numerical aperture of the imaging system. Defaults to 1.0. |
1.0
|
Returns:
| Type | Description |
|---|---|
VectorField | ChromaticVectorField
|
|
VectorField | ChromaticVectorField
|
with the given numerical aperture. |
Source code in src/chromatix/functional/samples.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 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 538 539 540 541 542 543 544 545 546 547 548 549 550 | |
thick_polarized_sample(field, potential_stack, n, thickness_per_slice, NA=1.0)
¶
Alias for polarized_multislice_thick_sample. See
polarized_multislice_thick_sample for documentation.
Warning
This alias is deprecated and will be removed in a future release. Please switch to the updated name.
Source code in src/chromatix/functional/samples.py
thin_sample(field, absorption, dn, thickness)
¶
Perturbs an incoming ScalarField as if it went through a thin sample
object with a given absorption, isotropic refractive index change from
the refractive index of the medium dn, and thickness.
The sample is supposed to follow the thin sample approximation, so the
sample perturbation is calculated as:
exp(1j * 2 * pi * (dn + 1j * absorption) * thickness / lambda).
Returns a ScalarField with the result of the perturbation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The complex field to be perturbed. |
required |
absorption
|
Float[Array, 'h w']
|
The sample's absorption defined as a 2D array of shape
|
required |
dn
|
Float[Array, 'h w']
|
The sample's isotropic refractive index change as a 2D array of
shape |
required |
thickness
|
ScalarLike | Float[Array, 'h w']
|
Thickness in units of distance as a scalar or array
broadcastable to |
required |
Returns:
Field immediately after propagating through sample.
Source code in src/chromatix/functional/samples.py
Sensors¶
__all__ = ['basic_sensor']
module-attribute
¶
basic_sensor(sensor_input, shot_noise_mode=None, resampler=None, reduce_axis=None, reduce_parallel_axis_name=None, input_spacing=None, noise_key=None)
¶
Produces an intensity image from an incoming Field or intensity Array
and simulates shot noise. In most cases, it is better and easier to use
the BasicSensor
element which will handle some of the state/arguments necessary for this
function (especially for resampling to the pixel size of the sensor).
Warning
Assumes that the input has the same spacing at all wavelengths!
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_input
|
Field | Array
|
Either the incoming |
required |
shot_noise_mode
|
Literal['approximate', 'poisson'] | None
|
What type of shot noise simulation to use. Can be
either |
None
|
resampler
|
Resampler | None
|
If provided, will be called to resample the
incoming |
None
|
reduce_axis
|
int | None
|
If provided, the result will be summed along this dimension. Useful for simulating multiple depth planes being summed at the sensor plane. |
None
|
reduce_parallel_axis_name
|
str | None
|
If provided, will do a |
None
|
input_spacing
|
ScalarLike | None
|
Only needs to be provided if |
None
|
noise_key
|
PRNGKey | None
|
If provided, will be used to generate the shot noise. If
|
None
|
Returns:
| Type | Description |
|---|---|
Array
|
The measured intensity of the incoming |
Array
|
across any depth/batch axis of the incoming |
Array
|
plane. |
Source code in src/chromatix/functional/sensors.py
Propagation¶
__all__ = ['transform_propagate', 'compute_sas_precompensation', 'transform_propagate_sas', 'transfer_propagate', 'asm_propagate', 'kernel_propagate', 'compute_transfer_propagator', 'compute_asm_propagator', 'compute_padding_transform', 'compute_padding_transfer', 'compute_padding_exact']
module-attribute
¶
asm_propagate(field, z, n, pad_width, cval=0, absorbing_boundary=None, absorbing_boundary_width=0.65, kykx=(0.0, 0.0), remove_evanescent=False, bandlimit=False, shift_yx=(0.0, 0.0), output_dx=None, output_shape=None, use_czt=True, mode='full')
¶
Propagate field for a distance z using angular spectrum method.
This method does not remove evanescent waves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
|
required |
z
|
ScalarLike | Float[Array, z]
|
How far to propagate as either a scalar value in units of distance
or a 1D array of distances (in which case a batch dimension will be
added to the resulting |
required |
n
|
ScalarLike
|
A float that defines the (isotropic) refractive index of the medium. |
required |
pad_width
|
int
|
A keyword argument integer defining the pad length for
the propagation FFT. Use padding calculator utilities from
Warning The pad value hould not be a Jax array, otherwise a ConcretizationError will arise when traced! |
required |
cval
|
float
|
The background value to use when padding the Field. Defaults to 0 for zero padding. |
0
|
absorbing_boundary
|
Literal['tukey', 'super_gaussian'] | None
|
An optional string that determines which absorbing boundary condition is applied (either "tukey" or "super_gaussian", for the Tukey or super Gaussian pupils respectively). Either choice will taper the propagated field to 0 at the edges to reduce aliasing at the edges due to wrapping. Defaults to None in which case no absorbing boundary is applied. |
None
|
absorbing_boundary
|
Literal['tukey', 'super_gaussian'] | None
|
A float determining the diameter (as a percentage) of the propagated field that will be permitted without being absorbed. The edges of the field beyond this boundary will taper smoothly to 0 using the chosen boundary function. |
None
|
kykx
|
ArrayLike | tuple[float, float]
|
If provided, defines the orientation of the propagation. Should
be an array of shape |
(0.0, 0.0)
|
remove_evanescent
|
bool
|
If |
False
|
bandlimit
|
bool
|
If |
False
|
shift_yx
|
ArrayLike | tuple[float, float]
|
If provided, defines a shift in the destination
plane. Should be an array of shape |
(0.0, 0.0)
|
output_dx
|
ArrayLike | None
|
If provided, defines a different output sampling at the
output plane. Must be of the same shape as that of |
None
|
output_shape
|
tuple[int, int]
|
If provided, defines the output shape of the field. Should be
a tuple of integers. If not provided and |
None
|
use_czt
|
bool
|
Whether or not to use chirp Z-transform for different output
sampling. Defaults to True if |
True
|
mode
|
Literal['full', 'same']
|
Either "full" or "same". If "same", the shape of the output
|
'full'
|
Source code in src/chromatix/functional/propagation.py
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 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 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 | |
compute_asm_propagator(field, z, n, kykx=(0.0, 0.0), bandlimit=False, shift_yx=(0.0, 0.0), remove_evanescent=False)
¶
Compute propagation kernel for propagation with no Fresnel approximation.
This version of the propagation kernel does not remove evanescent waves, as per the definition of the angular spectrum method. Returns an array that can be multiplied with the Fourier transform of the incoming Field, as performed by kernel_propagate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
|
required |
z
|
ScalarLike | Float[Array, z]
|
How far to propagate as either a scalar value in units of distance
or a 1D array of distances (in which case a batch dimension will be
added to the resulting |
required |
n
|
ScalarLike
|
A float that defines the (isotropic) refractive index of the medium. |
required |
kykx
|
ArrayLike | tuple[float, float]
|
If provided, defines the orientation of the propagation. Should
be an array of shape |
(0.0, 0.0)
|
bandlimit
|
bool
|
If |
False
|
shift_yx
|
ArrayLike | tuple[float, float]
|
If provided, defines a shift in the destination
plane. Should be an array of shape |
(0.0, 0.0)
|
remove_evanescent
|
bool
|
If |
False
|
Source code in src/chromatix/functional/propagation.py
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 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
compute_padding_exact(height, wavelength, dx, z)
¶
Automatically estimate the padding required for exact/angular wavelength propagation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
int
|
Height (number of pixels in the y direction) of the field. This assumes that the field is a square (height is the same as width). |
required |
wavelength
|
float
|
The wavelength of the field as a scalar in units of distance (assumed to be a monochromatic field). |
required |
dx
|
float
|
The spacing of the samples of the field as a scalar in units of distance. Assumes square pixels. |
required |
z
|
float
|
A float that defines how far to propagate in units of distance. |
required |
Source code in src/chromatix/functional/propagation.py
compute_padding_transfer(height, wavelength, dx, z)
¶
Automatically estimate the padding required for transfer propagation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
int
|
Height (number of pixels in the y direction) of the field. This assumes that the field is a square (height is the same as width). |
required |
wavelength
|
float
|
The wavelength of the field as a scalar in units of distance (assumed to be a monochromatic field). |
required |
dx
|
float
|
The spacing of the samples of the field as a scalar in units of distance. Assumes square pixels. |
required |
z
|
float
|
A float that defines how far to propagate in units of distance. |
required |
Source code in src/chromatix/functional/propagation.py
compute_padding_transform(height, wavelength, dx, z)
¶
Automatically estimate the padding required for transform propagation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
int
|
Height (number of pixels in the y direction) of the field. This assumes that the field is a square (height is the same as width). |
required |
wavelength
|
float
|
The wavelength of the field as a scalar in units of distance (assumed to be a monochromatic field). |
required |
dx
|
float
|
The spacing of the samples of the field as a scalar in units of distance. Assumes square pixels. |
required |
z
|
float
|
A float that defines how far to propagate in units of distance. |
required |
Source code in src/chromatix/functional/propagation.py
compute_sas_precompensation(field, z, n)
¶
Source code in src/chromatix/functional/propagation.py
compute_transfer_propagator(field, z, n, kykx=(0.0, 0.0))
¶
Compute propagation kernel for Fresnel propagation. Returns an array that can be multiplied with the Fourier transform of the incoming Field, as performed by kernel_propagate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
|
required |
z
|
ScalarLike | Float[Array, z]
|
How far to propagate as either a scalar value in units of distance
or a 1D array of distances (in which case a batch dimension will be
added to the resulting |
required |
n
|
ScalarLike
|
A float that defines the (isotropic) refractive index of the medium. |
required |
kykx
|
ArrayLike | tuple[float, float]
|
If provided, defines the orientation of the propagation. Should
be an array of shape |
(0.0, 0.0)
|
Source code in src/chromatix/functional/propagation.py
kernel_propagate(field, propagator, absorbing_boundary=None, absorbing_boundary_width=0.65, output_dx=None, output_shape=None, shift_yx=(0.0, 0.0), use_czt=False)
¶
Propagate an incoming Field by the given propagation kernel
(propagator). This amounts to performing a Fourier convolution of the
field and the propagator. Can optionally apply an absorbing boundary
(a tapered pupil function) to the field after propagation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
|
required |
propagator
|
ArrayLike
|
The propagation kernel. |
required |
absorbing_boundary
|
Literal['tukey', 'super_gaussian'] | None
|
An optional string that determines which absorbing boundary condition is applied (either "tukey" or "super_gaussian", for the Tukey or super Gaussian pupils respectively). Either choice will taper the propagated field to 0 at the edges to reduce aliasing at the edges due to wrapping. Defaults to None in which case no absorbing boundary is applied. |
None
|
absorbing_boundary
|
Literal['tukey', 'super_gaussian'] | None
|
A float determining the diameter (as a percentage) of the propagated field that will be permitted without being absorbed. The edges of the field beyond this boundary will taper smoothly to 0 using the chosen boundary function. |
None
|
Source code in src/chromatix/functional/propagation.py
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 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
transfer_propagate(field, z, n, pad_width, cval=0, absorbing_boundary=None, absorbing_boundary_width=0.65, kykx=(0.0, 0.0), shift_yx=(0.0, 0.0), output_dx=None, output_shape=None, use_czt=True, mode='full')
¶
Fresnel propagate field for a distance z using transfer method. This
method is also called the convolutional Fresnel propagation (CV-FR) method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
|
required |
z
|
ScalarLike | Float[Array, z]
|
How far to propagate as either a scalar value in units of distance
or a 1D array of distances (in which case a batch dimension will be
added to the resulting |
required |
n
|
ScalarLike
|
A float that defines the (isotropic) refractive index of the medium. |
required |
pad_width
|
int
|
A keyword argument integer defining the pad length for
the propagation FFT. Use padding calculator utilities from
Warning The pad value hould not be a Jax array, otherwise a ConcretizationError will arise when traced! |
required |
cval
|
float
|
The background value to use when padding the Field. Defaults to 0 for zero padding. |
0
|
absorbing_boundary
|
Literal['tukey', 'super_gaussian'] | None
|
An optional string that determines which absorbing boundary condition is applied (either "tukey" or "super_gaussian", for the Tukey or super Gaussian pupils respectively). Either choice will taper the propagated field to 0 at the edges to reduce aliasing at the edges due to wrapping. Defaults to None in which case no absorbing boundary is applied. |
None
|
absorbing_boundary
|
Literal['tukey', 'super_gaussian'] | None
|
A float determining the diameter (as a percentage) of the propagated field that will be permitted without being absorbed. The edges of the field beyond this boundary will taper smoothly to 0 using the chosen boundary function. |
None
|
kykx
|
ArrayLike | tuple[float, float]
|
If provided, defines the orientation of the propagation. Should
be an array of shape |
(0.0, 0.0)
|
shift_yx
|
ArrayLike | tuple[float, float]
|
If provided, defines a shift in the destination
plane. Should be an array of shape |
(0.0, 0.0)
|
output_dx
|
ArrayLike | None
|
If provided, defines a different output sampling at the output plane. |
None
|
output_shape
|
tuple[int, int] | None
|
If provided, defines the output shape of the field. Should be
a tuple of integers. If not provided and |
None
|
use_czt
|
bool
|
Whether or not to use chirp Z-transform for different output
sampling. Defaults to True if |
True
|
mode
|
Literal['full', 'same']
|
Either "full" or "same". If "same", the shape of the output
|
'full'
|
Source code in src/chromatix/functional/propagation.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 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 | |
transform_propagate(field, z, n, pad_width, cval=0, skip_initial_phase=False, skip_final_phase=False)
¶
Fresnel propagate field for a distance z using transform method.
This method is also called the single-FFT (SFT-FR) Fresnel propagation
method. Note that this method changes the sampling of the resulting field.
If the distance is negative, the field is propagated back to the source
inverting essentially performing an inverse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
|
required |
z
|
ScalarLike
|
How far to propagate as a scalar value in units of distance. |
required |
n
|
ScalarLike
|
A float that defines the (isotropic) refractive index of the medium. |
required |
pad_width
|
int | tuple[int, int]
|
A keyword argument integer defining the pad length for
the propagation FFT. Use padding calculator utilities from
Warning The pad value hould not be a Jax array, otherwise a ConcretizationError will arise when traced! |
required |
cval
|
float
|
The background value to use when padding the Field. Defaults to 0 for zero padding. |
0
|
skip_initial_phase
|
bool
|
Whether to skip the input phase change (before Fourier transforming). Defaults to False, in which case the input phase change is not skipped. |
False
|
skip_final_phase
|
bool
|
Whether to skip the output phase change (after Fourier transforming). Defaults to False, in which case the output phase change is not skipped. |
False
|
Source code in src/chromatix/functional/propagation.py
transform_propagate_sas(field, z, n, cval=0, skip_initial_phase=False, skip_final_phase=False)
¶
Propagate field for a distance z using the scalable angular spectrum
(SAS) method. See https://doi.org/10.1364/OPTICA.497809 It changes the
pixelsize like the transform method, but it is more accurate because it
precompensates the phase error. Since it uses three FFTS, it is slower
than the transform method. Note that the field is automatically padded by a
factor of 2, so the pixelsize is halved.
Note also that a negative propagation distance causes the code to apply
the inverse propagation, i.e. propagating by a positive z and then
a negative z would propagate you back to the original field. In
the negative z case the order of single step Fresnel propagation and
precompensation is reversed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
|
required |
z
|
ScalarLike
|
How far to propagate as a scalar value in units of distance. |
required |
n
|
ScalarLike
|
A float that defines the (isotropic) refractive index of the medium. |
required |
cval
|
float
|
The background value to use when padding the Field. Defaults to 0 for zero padding. |
0
|
skip_initial_phase
|
bool
|
Whether to skip the input phase change (before Fourier transforming). Defaults to False, in which case the input phase change is not skipped. |
False
|
skip_final_phase
|
bool
|
Whether to skip the output phase change (after Fourier transforming). Defaults to False, in which case the output phase change is not skipped. |
False
|
Source code in src/chromatix/functional/propagation.py
Polarization¶
ComplexScalarLike = Complex
module-attribute
¶
__all__ = ['jones_vector', 'polarizer', 'phase_retarder', 'linear', 'left_circular', 'right_circular', 'linear_polarizer', 'left_circular_polarizer', 'right_circular_polarizer', 'universal_compensator', 'wave_plate', 'halfwave_plate', 'quarterwave_plate']
module-attribute
¶
halfwave_plate(field, theta)
¶
Applies a halfwave plate with angle theta to the incoming field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
VectorField | ChromaticVectorField
|
incoming field. |
required |
theta
|
float
|
angle w.r.t. horizontal. |
required |
Returns:
| Type | Description |
|---|---|
VectorField | ChromaticVectorField
|
VectorField | ChromaticVectorField: outgoing field. |
Source code in src/chromatix/functional/polarizers.py
jones_vector(theta, beta)
¶
Generates a Jones vector given by [cos(theta), sin(theta)exp(1j*beta)].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
float
|
Polarization angle. |
required |
beta
|
float
|
Relative delay between components. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Jones vector. |
Source code in src/chromatix/functional/polarizers.py
left_circular()
¶
Generates a Jones vector for left circularly polarized light.
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Left circularly polarized Jones vector. |
left_circular_polarizer(field)
¶
Applies a left circular polarizer to the incoming field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
VectorField | ChromaticVectorField
|
incoming field. |
required |
Returns:
| Type | Description |
|---|---|
VectorField | ChromaticVectorField
|
VectorField | ChromaticVectorField: outgoing field. |
Source code in src/chromatix/functional/polarizers.py
linear(theta)
¶
Generates a Jones vector for linearly polarized light with an angle $ heta$ w.r.t. to the horizontal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
float
|
Angle w.r.t horizontal. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Linearly polarized Jones vector. |
Source code in src/chromatix/functional/polarizers.py
linear_polarizer(field, angle)
¶
Applies a linear polarizer with a given angle to the incoming field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
VectorField | ChromaticVectorField
|
incoming field. |
required |
angle
|
float
|
angle w.r.t to the horizontal. |
required |
Returns:
| Type | Description |
|---|---|
VectorField | ChromaticVectorField
|
VectorField | ChromaticVectorField: outgoing field. |
Source code in src/chromatix/functional/polarizers.py
phase_retarder(field, theta, eta, phi)
¶
Applies a general purpose retardation matrix with angle w.r.t horizontal theta, relative phase change eta and circularity phi.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
VectorField | ChromaticVectorField
|
incoming field. |
required |
theta
|
float
|
angle w.r.t horizonal axis. |
required |
eta
|
float
|
relative phase retardation. |
required |
phi
|
float
|
circularity. |
required |
Returns:
| Type | Description |
|---|---|
VectorField | ChromaticVectorField
|
VectorField | ChromaticVectorField: outgoing field. |
Source code in src/chromatix/functional/polarizers.py
polarizer(field, J00, J01, J10, J11)
¶
Applies a Jones matrix with given components to the field. Note that the components here refer to the common choice of coordinate system and are inverted by us - i.e. J00 refers to Jxx.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
VectorField | ChromaticVectorField
|
field to apply polarization to. |
required |
J00
|
Union[float, complex, Array]
|
description |
required |
J01
|
Union[float, complex, Array]
|
description |
required |
J10
|
Union[float, complex, Array]
|
description |
required |
J11
|
Union[float, complex, Array]
|
description |
required |
Returns:
| Type | Description |
|---|---|
VectorField | ChromaticVectorField
|
VectorField | ChromaticVectorField: Field after polarizer. |
Source code in src/chromatix/functional/polarizers.py
quarterwave_plate(field, theta)
¶
Applies a quarterwave plate with angle theta to the incoming field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
VectorField | ChromaticVectorField
|
incoming field. |
required |
theta
|
float
|
angle w.r.t. horizontal. |
required |
Returns:
| Type | Description |
|---|---|
VectorField | ChromaticVectorField
|
VectorField | ChromaticVectorField: outgoing field. |
Source code in src/chromatix/functional/polarizers.py
right_circular()
¶
Generates a Jones vector for right circularly polarized light.
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Right circularly polarized Jones vector. |
right_circular_polarizer(field)
¶
Applies a thin RCP polarizer to the incoming Field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
VectorField | ChromaticVectorField
|
The |
required |
Returns:
| Type | Description |
|---|---|
VectorField | ChromaticVectorField
|
The |
Source code in src/chromatix/functional/polarizers.py
universal_compensator(field, retardance_45, retardance_0)
¶
Applies the Universal Polarizer for the LC-PolScope to the incoming field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
VectorField | ChromaticVectorField
|
Incoming field to polarize. |
required |
retardance_45
|
ScalarLike
|
Retardance induced at a 45 deg angle. |
required |
retardance_0
|
ScalarLike
|
Retardance induced at a 0 deg angle. |
required |
Returns:
| Type | Description |
|---|---|
VectorField | ChromaticVectorField
|
The outgoing field. |
Source code in src/chromatix/functional/polarizers.py
wave_plate(field, theta, eta)
¶
Applies a general waveplate with angle theta and delay eta to the field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
VectorField | ChromaticVectorField
|
incoming field. |
required |
theta
|
float
|
angle w.r.t horizontal. |
required |
eta
|
float
|
relative delay between components. |
required |
Returns:
| Type | Description |
|---|---|
VectorField | ChromaticVectorField
|
VectorField | ChromaticVectorField: outgoing field. |
Source code in src/chromatix/functional/polarizers.py
Convenience¶
optical_fft(field, z, n)
¶
Computes the optical fft or ifft on an incoming Field propagated
by z, assuming that the distance is in the far field. Can also be used
for simulating propagation through a lens from the focal plane to the back
focal plane if z is the focal length of the lens. The direction of the
propagation depends on the sign of z (which is a scalar value that may
be positive or negative). If z is positive an fft```will be performed,
otherwise anifft(due to the1 / (lambda * z)term in the single
Fourier transform Fresnel propagation, which requires this behavior).
Theifftis calculated in terms of the conjugate of thefftwith
appropriate normalization applied so that propagating forwards and then
backwards yields the sameFieldup to numerical precision. This function
also appropriately changes the sampling (dx) of the resultingField``.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The |
required |
z
|
ScalarLike
|
Scalar representing how far the |
required |
n
|
ScalarLike
|
Real-valued scalar representing (isotropic) refractive index of the propagation medium. |
required |
Returns:
The propagated Field, transformed by fft/ifft.