Elements¶
Sources¶
FieldPupil = Callable[[Field], Field]
module-attribute
¶
__all__ = ['PointSource', 'ObjectivePointSource', 'PlaneWave', 'GenericField']
module-attribute
¶
GenericField
¶
Bases: Module
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.
Attributes:
| Name | Type | Description |
|---|---|---|
dx |
ScalarLike
|
The spacing (pixel size) of the samples of the |
spectrum |
Spectrum | ScalarLike | Float[Array, wv] | tuple[Float[Array, wv], Float[Array, wv]]
|
The
|
amplitude |
ArrayLike
|
The amplitude of the field with shape |
phase |
ArrayLike
|
The phase of the field with shape |
power |
ScalarLike
|
The total power (a scalar value) that the result should be
normalized to, defaults to 1.0. If |
pupil |
FieldPupil | None
|
A function that applies a pupil to the field if provided.
Defaults to |
scalar |
bool
|
Whether the result should be |
Source code in src/chromatix/elements/sources.py
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 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 | |
amplitude
instance-attribute
¶
dx
instance-attribute
¶
phase
instance-attribute
¶
power
instance-attribute
¶
pupil = eqx.field(static=True)
class-attribute
instance-attribute
¶
scalar = eqx.field(static=True)
class-attribute
instance-attribute
¶
spectrum
instance-attribute
¶
__call__()
¶
__init(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
|
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/elements/sources.py
ObjectivePointSource
¶
Bases: Module
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.
Attributes:
| Name | Type | Description |
|---|---|---|
shape |
tuple[int, int]
|
The shape (height and width) of the |
dx |
ScalarLike | Float[Array, 2]
|
The spacing (pixel size) of the samples of the |
spectrum |
Spectrum | ScalarLike | Float[Array, wv] | tuple[Float[Array, wv], Float[Array, wv]]
|
The
|
f |
ScalarLike
|
Focal length of the objective lens in units of distance. |
n |
ScalarLike
|
Refractive index. |
NA |
ScalarLike
|
The numerical aperture of the objective lens. |
power |
ScalarLike | None
|
The total power that the result should be normalized to, defaults
to 1.0. If |
amplitude |
ScalarLike
|
The amplitude of the electric field. For scalar |
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 |
scalar |
bool
|
Whether the result should be |
Source code in src/chromatix/elements/sources.py
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 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 355 356 357 | |
NA = NA
instance-attribute
¶
amplitude = amplitude
instance-attribute
¶
dx = dx
instance-attribute
¶
f = f
instance-attribute
¶
n = n
instance-attribute
¶
offset = offset
instance-attribute
¶
power = power
instance-attribute
¶
scalar = scalar
class-attribute
instance-attribute
¶
shape = shape
class-attribute
instance-attribute
¶
spectrum = spectrum
instance-attribute
¶
__call__(z)
¶
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 |
|---|---|---|---|
z
|
ScalarLike | Float[Array, z]
|
How far away the point source is from the focal plane of the lens in units of distance. |
required |
Source code in src/chromatix/elements/sources.py
__init__(shape, dx, spectrum, 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
|
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 |
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/elements/sources.py
PlaneWave
¶
Bases: Module
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)).
Attributes:
| Name | Type | Description |
|---|---|---|
shape |
tuple[int, int]
|
The shape (height and width) of the |
dx |
ScalarLike
|
The spacing (pixel size) of the samples of the |
spectrum |
Spectrum | ScalarLike | Float[Array, wv] | tuple[Float[Array, wv], Float[Array, wv]]
|
The
|
power |
ScalarLike
|
The total power that the result should be normalized to, defaults
to 1.0. If |
amplitude |
ScalarLike
|
The amplitude of the electric field. For scalar |
kykx |
Float[Array, 2] | tuple[float, float]
|
Defines the orientation of the plane wave. Should be a tuple or an
array of shape |
pupil |
FieldPupil | None
|
A function that applies a pupil to the field if provided.
Defaults to |
scalar |
bool
|
Whether the result should be |
Source code in src/chromatix/elements/sources.py
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 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 | |
amplitude = amplitude
instance-attribute
¶
dx = dx
instance-attribute
¶
kykx = kykx
instance-attribute
¶
power = power
instance-attribute
¶
pupil = pupil
class-attribute
instance-attribute
¶
scalar = scalar
class-attribute
instance-attribute
¶
shape = shape
class-attribute
instance-attribute
¶
spectrum = spectrum
instance-attribute
¶
__call__()
¶
__init__(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
|
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/elements/sources.py
PointSource
¶
Bases: Module
Generates field due to point source a distance z away.
Can also be given pupil.
Attributes:
| Name | Type | Description |
|---|---|---|
shape |
tuple[int, int]
|
The shape (height and width) of the |
dx |
ScalarLike | Float[Array, 2]
|
The spacing (pixel size) of the samples of the |
spectrum |
Spectrum | ScalarLike | Float[Array, wv] | tuple[Float[Array, wv], Float[Array, wv]]
|
The
|
n |
ScalarLike
|
Refractive index. |
power |
ScalarLike | None
|
The total power that the result should be normalized to, defaults
to 1.0. If |
amplitude |
ScalarLike | Float[Array, 3]
|
The amplitude of the electric field. For scalar |
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 |
pupil |
FieldPupil | None
|
A function that applies a pupil to the field if provided.
Defaults to |
scalar |
bool
|
Whether the result should be |
epsilon |
float
|
Value added to denominators for numerical stability when z is 0. |
Source code in src/chromatix/elements/sources.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 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 | |
amplitude = amplitude
instance-attribute
¶
dx = dx
instance-attribute
¶
epsilon = epsilon
class-attribute
instance-attribute
¶
n = n
instance-attribute
¶
offset = offset
instance-attribute
¶
power = power
instance-attribute
¶
pupil = pupil
class-attribute
instance-attribute
¶
scalar = scalar
class-attribute
instance-attribute
¶
shape = shape
class-attribute
instance-attribute
¶
spectrum = (spectrum,)
instance-attribute
¶
__call__(z)
¶
Generates field due to point source a distance z away.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
ScalarLike | Float[Array, z]
|
How far away the point source is in units of distance. |
required |
Source code in src/chromatix/elements/sources.py
__init__(shape, dx, spectrum, 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, int]
|
The shape (height and width) of the |
required |
dx
|
ScalarLike | Float[Array, 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 |
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/elements/sources.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 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 | |
Lenses¶
__all__ = ['ThinLens', 'FFLens', 'DFLens']
module-attribute
¶
DFLens
¶
Bases: Module
Applies a thin lens placed a distance d after the incoming Field.
This element returns the Field a distance f after the lens.
This element can be placed after any element that returns a Field or
before any element that accepts a Field.
Attributes:
| Name | Type | Description |
|---|---|---|
d |
ScalarLike
|
How far away the lens is from the incoming |
f |
ScalarLike
|
Focal length of the lens in units of distance. |
n |
ScalarLike
|
The refractive index of the surrounding medium (assumed to be the same incoming and exiting). |
NA |
ScalarLike | None
|
If provided, the NA of the lens. By default, no pupil is applied
to the incoming |
inverse |
bool
|
Whether the field is passing forwards or backwards through
the lens. If |
Source code in src/chromatix/elements/lenses.py
NA = NA
instance-attribute
¶
d = d
instance-attribute
¶
f = f
instance-attribute
¶
inverse = inverse
class-attribute
instance-attribute
¶
n = n
instance-attribute
¶
__call__(field)
¶
__init__(d, f, n, NA=None, inverse=False)
¶
Applies a thin lens placed a distance d after the incoming Field.
This element returns the Field a distance f after the lens.
This element can be placed after any element that returns a Field or
before any element that accepts a Field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
ScalarLike
|
How far away the lens is 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
|
Source code in src/chromatix/elements/lenses.py
FFLens
¶
Bases: Module
Applies a thin lens placed a distance f after the incoming Field.
This element returns the Field a distance f after the lens.
This element can be placed after any element that returns a Field or
before any element that accepts a Field.
Attributes:
| Name | Type | Description |
|---|---|---|
f |
ScalarLike
|
Focal length of the lens. |
n |
ScalarLike
|
The refractive index of the surrounding medium (assumed to be the same incoming and exiting). |
NA |
ScalarLike | None
|
If provided, the NA of the lens. By default, no pupil is applied
to the incoming |
inverse |
bool
|
Whether the field is passing forwards or backwards through
the lens. If |
Source code in src/chromatix/elements/lenses.py
NA = NA
instance-attribute
¶
f = f
instance-attribute
¶
inverse = inverse
class-attribute
instance-attribute
¶
n = n
instance-attribute
¶
__call__(field)
¶
__init__(f, n, NA=None, inverse=False)
¶
Applies a thin lens placed directly after the incoming Field.
This element returns the Field directly after the lens.
This element can be placed after any element that returns a Field or
before any element that accepts a Field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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
|
Source code in src/chromatix/elements/lenses.py
ThinLens
¶
Bases: Module
Applies a thin lens placed directly after the incoming Field.
This element returns the Field directly after the lens.
This element can be placed after any element that returns a Field or
before any element that accepts a Field.
Attributes:
| Name | Type | Description |
|---|---|---|
f |
ScalarLike
|
Focal length of the lens in units of distance. |
n |
ScalarLike
|
The refractive index of the surrounding medium (assumed to be the same incoming and exiting). |
NA |
ScalarLike | None
|
If provided, the NA of the lens. By default, no pupil is applied
to the incoming |
Source code in src/chromatix/elements/lenses.py
NA = NA
instance-attribute
¶
f = f
instance-attribute
¶
n = n
instance-attribute
¶
__call__(field)
¶
__init__(f, n, NA=None)
¶
Applies a thin lens placed directly after the incoming Field.
This element returns the Field directly after the lens.
This element can be placed after any element that returns a Field or
before any element that accepts a Field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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
|
Source code in src/chromatix/elements/lenses.py
Phase Masks¶
__all__ = ['SeidelAberrations', 'ZernikeAberrations', 'PhaseMask', 'SpatialLightModulator']
module-attribute
¶
PhaseMask
¶
Bases: Module
Perturbs field by phase (in radians), i.e. field * exp(1j * phase).
This element can be placed after any element that returns a Field or
before any element that accepts a Field.
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.
The phase can be optimized (pixel by pixel).
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.
Attributes:
| Name | Type | Description |
|---|---|---|
phase |
Float[Array, 'h w']
|
The phase mask to apply as a 2D array of phase values (in
radians) of shape |
Source code in src/chromatix/elements/phase_masks.py
SeidelAberrations
¶
Bases: Module
Applies Seidel phase polynomial to an incoming Field.
This element can be placed after any element that returns a Field or
before any element that accepts a Field.
This element handles multi-wavelength Fields by assuming that the first
wavelength in the spectrum of the Field is the central wavelength
for which the phase was calculated, and modulates the phase by the
ratio of other wavelengths in the spectrum to the central wavelength
appropriately.
Attributes:
| Name | Type | Description |
|---|---|---|
coefficients |
Float[Array, 5]
|
The Seidel coefficients. Should have shape |
f |
ScalarLike
|
The focal length of the system's objective lens in units of distance. |
n |
ScalarLike
|
The refractive index of the medium. |
NA |
ScalarLike
|
The numerical aperture. The applied phase will be 0 outside NA. |
Source code in src/chromatix/elements/phase_masks.py
NA = NA
instance-attribute
¶
coefficients = coefficients
instance-attribute
¶
f = f
instance-attribute
¶
n = n
instance-attribute
¶
__call__(field, u, v)
¶
Applies phase mask to incoming Field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Field
|
The complex field to be perturbed. |
required |
u
|
ScalarLike
|
The horizontal position of the object field point in normalized coordinates from 0 to +/- 1. A value of 0 represents the center coordinate in the plane while a value of 1 represents the farthest point from the center. Positive values go right and negative values go left. |
required |
v
|
ScalarLike
|
The vertical position of the object field point in normalized coordinates from 0 to +/- 1. A value of 0 represents the center coordinate in the plane while a value of 1 represents the farthest point from the center. Positive values go down and negative values go up. |
required |
Source code in src/chromatix/elements/phase_masks.py
__init__(coefficients, f, n, NA)
¶
SpatialLightModulator
¶
Bases: Module
Simulates a spatial light modulator (SLM) applied to an incoming Field.
This element can be placed after any element that returns a Field or
before any element that accepts a Field.
This means that this element acts as if the SLM is phase only and transmits
a Field, rather than reflecting it.
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.
This element also handles the limited phase modulation range of an SLM,
controlled by phase_range.
This element also approximates the simulation of the surface of the SLM by
interpolating the phase with the given shape (which can be the number of
pixels in the SLM) to the shape of the incoming Field, which is assumed
to have a shape larger than the given SLM shape. The order of the
interpolation performed can be controlled with interpolation_order, but
currently only orders of 0 (nearest neighbor) and 1 (linear interpolation)
are supported.
Attributes:
| Name | Type | Description |
|---|---|---|
phase |
Float[Array, 'h w']
|
The phase mask to apply as a 2D array of phase values (in
radians) of shape |
shape |
tuple[int, int]
|
The shape of the SLM in number of pixels, provided as |
spacing |
ScalarLike
|
The pitch of the SLM pixels in units of distance. |
phase_range |
Float[Array, 2] | tuple[float, float]
|
The phase range in radians that the SLM can simulate,
provided as |
num_bits |
int | None
|
An integer value representing the number of bits to which the
phase mask should be quantized, i.e. only |
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 |
Source code in src/chromatix/elements/phase_masks.py
interpolation_order = 0
class-attribute
instance-attribute
¶
num_bits = num_bits
class-attribute
instance-attribute
¶
phase = phase
instance-attribute
¶
phase_range = phase_range
instance-attribute
¶
shape = shape
instance-attribute
¶
spacing = spacing
instance-attribute
¶
__call__(field)
¶
Applies simulated SLM phase mask to incoming Field.
__init__(phase, shape, spacing, phase_range, num_bits=None, interpolation_order=0)
¶
Source code in src/chromatix/elements/phase_masks.py
ZernikeAberrations
¶
Bases: Module
Applies Zernike aberrations to an incoming Field.
This element can be placed after any element that returns a Field or
before any element that accepts a Field.
This element handles multi-wavelength Fields by assuming that the first
wavelength in the spectrum of the Field is the central wavelength
for which the phase was calculated, and modulates the phase by the
ratio of other wavelengths in the spectrum to the central wavelength
appropriately.
Attributes:
| Name | Type | Description |
|---|---|---|
coefficients |
Float[Array, m]
|
The Zernike coefficients as a 1D array of the same length as the
|
f |
ScalarLike
|
The focal length of the system's objective lens in units of distance. |
n |
ScalarLike
|
The refractive index of the medium. |
NA |
ScalarLike
|
The numerical aperture. The applied phase will be 0 outside NA. |
ansi_indices |
Sequence[int]
|
Linear Zernike indices according to ANSI numbering. |
coefficients |
Float[Array, m]
|
Weight coefficients for the Zernike polynomials. |
normalize |
bool
|
Whether to normalize the Zernike coefficients. Defaults to
|
Source code in src/chromatix/elements/phase_masks.py
NA = NA
instance-attribute
¶
ansi_indices = ansi_indices
instance-attribute
¶
coefficients = coefficients
instance-attribute
¶
f = f
instance-attribute
¶
n = n
instance-attribute
¶
normalize = normalize
instance-attribute
¶
__call__(field)
¶
Applies phase mask to incoming Field.
Source code in src/chromatix/elements/phase_masks.py
__init__(coefficients, f, n, NA, ansi_indices, normalize=True)
¶
Source code in src/chromatix/elements/phase_masks.py
Amplitude Masks¶
__all__ = ['AmplitudeMask']
module-attribute
¶
AmplitudeMask
¶
Bases: Module
Perturbs field by amplitude, i.e. field * amplitude.
This element can be placed after any element that returns a Field or
before any element that accepts a Field.
Attributes:
| Name | Type | Description |
|---|---|---|
amplitude |
Float[Array, 'h w']
|
The amplitude mask to apply as a 2D array of amplitude values
of shape |
is_binary |
bool
|
Binarize (make 0 or 1) the amplitude mask if |
Source code in src/chromatix/elements/amplitude_masks.py
Samples¶
__all__ = ['ThinSample', 'ClearThinSample', 'MultisliceThickSample', 'ClearMultisliceThickSample']
module-attribute
¶
ClearMultisliceThickSample
¶
Bases: Sample, Scattering, Volume
Perturbs incoming ScalarField as if it went through a clear but
scattering thick sample. The thick sample is modeled as being made of many
thin slices each of a given thickness. The dn_stack contains the 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.
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.
Attributes:
| Name | Type | Description |
|---|---|---|
dn |
Float[Array, 'd h w']
|
The sample's isotropic refractive index change per voxel for
each slice as a 3D array of shape |
n |
ScalarLike
|
Average refractive index of the sample. |
dx |
ScalarLike | Float[Array, 2]
|
The spacing of each pixel of the sample as a scalar in units of
distance or as a 1D array of shape |
thickness |
ScalarLike
|
How far to propagate for each slice in units of distance. |
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. |
Source code in src/chromatix/elements/samples.py
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 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 | |
NA = NA
instance-attribute
¶
dn = dn
instance-attribute
¶
dx = _broadcast_dx_to_grid(dx, 1).squeeze()
instance-attribute
¶
grid
property
¶
n = n
instance-attribute
¶
ndim
property
¶
num_planes
property
¶
shape
property
¶
thickness = thickness
instance-attribute
¶
__call__(field, kykx=(0.0, 0.0), pad_width=0, reverse_propagate_distance=None, return_stack=False, remove_evanescent=False, bandlimit=False)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
ScalarField
|
The complex field to be perturbed. |
required |
kykx
|
Float[Array, 2]
|
If provided, defines the orientation of the propagation.
Should be an array of shape |
(0.0, 0.0)
|
pad_width
|
int
|
An integer defining the pad length for the
propagation FFT (NOTE: should not be a |
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
|
Source code in src/chromatix/elements/samples.py
__init__(dn, n, dx, thickness, NA=None)
¶
Source code in src/chromatix/elements/samples.py
ClearThinSample
¶
Bases: Sample, Scattering
Perturbs an incoming ScalarField as if it went through a clear
thin sample object with a given refractive index change dn from the
refractive index of the medium and of a given thickness in the same
units as the spectrum of the incoming ScalarField.
The sample is supposed to follow the thin sample approximation, so the
sample perturbation is calculated as:
exp(1j * 2 * pi * dn * thickness / lambda).
Returns a ScalarField with the result of the perturbation.
Attributes:
| Name | Type | Description |
|---|---|---|
dn |
Float[Array, 'h w']
|
The sample's isotropic refractive index change as a 2D array of
shape |
dx |
ScalarLike | Float[Array, 2]
|
The spacing of each pixel of the sample as a scalar in units of
distance or as a 1D array of shape |
thickness |
ScalarLike | Float[Array, 'h w']
|
Thickness in units of distance as a scalar or array
broadcastable to |
Source code in src/chromatix/elements/samples.py
MultisliceThickSample
¶
Bases: Sample, Absorbing, Scattering, Volume
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.
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.
Attributes:
| Name | Type | Description |
|---|---|---|
absorption |
Float[Array, 'd h w']
|
The sample's absorption per voxel for each slice defined as
a 3D array of shape |
dn |
Float[Array, 'd h w']
|
The sample's isotropic refractive index change for each slice as a
3D array of shape |
n |
ScalarLike
|
Average refractive index of the sample. |
dx |
ScalarLike | Float[Array, 2]
|
The spacing of each pixel of the sample as a scalar in units of
distance or as a 1D array of shape |
thickness |
ScalarLike
|
How far to propagate for each slice in units of distance. |
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. |
Source code in src/chromatix/elements/samples.py
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 | |
NA = NA
instance-attribute
¶
absorption = absorption
instance-attribute
¶
dn = dn
instance-attribute
¶
dx = _broadcast_dx_to_grid(dx, 1).squeeze()
instance-attribute
¶
grid
property
¶
n = n
instance-attribute
¶
ndim
property
¶
num_planes
property
¶
shape
property
¶
thickness = thickness
instance-attribute
¶
__call__(field, kykx=(0.0, 0.0), pad_width=0, reverse_propagate_distance=None, return_stack=False, remove_evanescent=False, bandlimit=False)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
ScalarField
|
The complex field to be perturbed. |
required |
kykx
|
Float[Array, 2]
|
If provided, defines the orientation of the propagation.
Should be an array of shape |
(0.0, 0.0)
|
pad_width
|
int
|
An integer defining the pad length for the
propagation FFT (NOTE: should not be a |
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
|
Source code in src/chromatix/elements/samples.py
__init__(absorption, dn, n, dx, thickness, NA=None)
¶
Source code in src/chromatix/elements/samples.py
ThinSample
¶
Bases: Sample, Absorbing, Scattering
Perturbs an incoming ScalarField as if it went through a thin sample
object with a given absorption, refractive index change dn from
the refractive index of the medium and of a given thickness in the same
units as the spectrum of the incoming ScalarField.
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.
Attributes:
| Name | Type | Description |
|---|---|---|
absorption |
Float[Array, 'h w']
|
The sample's absorption defined as a 2D array of shape
|
dn |
Float[Array, 'h w']
|
The sample's isotropic refractive index change as a 2D array of
shape |
dx |
ScalarLike | Float[Array, 2]
|
The spacing of each pixel of the sample as a scalar in units of
distance or as a 1D array of shape |
thickness |
ScalarLike | Float[Array, 'h w']
|
Thickness in units of distance as a scalar or array
broadcastable to |
Source code in src/chromatix/elements/samples.py
absorption = absorption
instance-attribute
¶
dn = dn
instance-attribute
¶
dx = _broadcast_dx_to_grid(dx, 1).squeeze()
instance-attribute
¶
grid
property
¶
ndim
property
¶
shape
property
¶
thickness = thickness
instance-attribute
¶
__call__(field)
¶
__init__(absorption, dn, dx, thickness)
¶
Source code in src/chromatix/elements/samples.py
Sensors¶
__all__ = ['BasicSensor']
module-attribute
¶
BasicSensor
¶
Bases: Sensor
Produces an intensity image from an incoming Field with shot noise.
Optionally, can also accept an intensity Array if input_spacing is
specified.
Attributes:
| Name | Type | Description |
|---|---|---|
shape |
tuple[int, int]
|
The shape in pixels of the sensor. Should be a tuple of the form
|
spacing |
ScalarLike | Float[Array, 2]
|
The pitch of the sensor pixels. |
shot_noise_mode |
Literal['approximate', 'poisson'] | None
|
What type of shot noise simulation to use. Defaults to
|
resampling_method |
str | None
|
What kind of sampling to use when resampling the
incoming |
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. |
reduce_parallel_axis_name |
str | None
|
If provided, will do a |
Source code in src/chromatix/elements/sensors.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
reduce_axis = reduce_axis
class-attribute
instance-attribute
¶
reduce_parallel_axis_name = reduce_parallel_axis_name
class-attribute
instance-attribute
¶
resampler = eqx.field(static=True)
class-attribute
instance-attribute
¶
resampling_method = resampling_method
class-attribute
instance-attribute
¶
shape = shape
class-attribute
instance-attribute
¶
shot_noise_mode = shot_noise_mode
class-attribute
instance-attribute
¶
spacing = spacing
instance-attribute
¶
__call__(sensor_input, input_spacing=None, resample=True, key=None)
¶
Resample the given sensor_input to the pixels of the sensor and
potentially reduce the result and add shot noise.
Warning
Assumes that the input has the same spacing at all wavelengths!
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_input
|
Field | Float[Array, '... h w']
|
The incoming |
required |
input_spacing
|
ScalarLike | None
|
The spacing of the input, only required if resampling
is desired and the input is an |
None
|
resample
|
bool
|
Whether to perform resampling or not. Only matters if
|
True
|
key
|
PRNGKeyArray | None
|
If provided, will be used to generate the shot noise. If
|
None
|
Source code in src/chromatix/elements/sensors.py
__init__(shape, spacing, shot_noise_mode=None, resampling_method='linear', reduce_axis=None, reduce_parallel_axis_name=None)
¶
Source code in src/chromatix/elements/sensors.py
resample(resample_input, input_spacing)
¶
Resample the given resample_input to the pixels of the sensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resample_input
|
Array
|
The |
required |
input_spacing
|
ScalarLike
|
The spacing of the input pixels as a scalar in units of distance. |
required |
Source code in src/chromatix/elements/sensors.py
Propagation¶
__all__ = ['Propagate', 'KernelPropagate']
module-attribute
¶
KernelPropagate
¶
Bases: Module
Free space propagation with a precomputed propagation kernel.
This element takes a Field as input and outputs a Field that has
been propagated by a distance that is already defined by a propagation
kernel. Propagation is performed via Fourier convolution (two Fourier
transforms).
Attributes:
| Name | Type | Description |
|---|---|---|
propagator |
Array
|
The propagation kernel to use (can be created using e.g.
|
pad_width |
int
|
The padding for propagation (will be used as both height and
width padding). To automatically calculate the padding, use padding
calculation functions from |
cval |
ScalarLike
|
The value to pad with if |
mode |
Literal['full', 'same']
|
Defines the cropping of the output if the method is NOT
"transform". Defaults to "same", which returns a |
Source code in src/chromatix/elements/propagation.py
cval = cval
instance-attribute
¶
mode = mode
class-attribute
instance-attribute
¶
pad_width = pad_width
class-attribute
instance-attribute
¶
propagator = propagator
instance-attribute
¶
__call__(field)
¶
__init__(propagator, pad_width=0, cval=0.0, mode='same')
¶
Source code in src/chromatix/elements/propagation.py
Propagate
¶
Bases: Module
Free space propagation that can be placed after or between other elements.
This element takes a Field as input and outputs a Field that has
been propagated by a distance z. Initialization of this element requires a
Field to construct the propagation kernels.
For example, this element can be constructed as:
from chromatix.elements import Propagate
from chromatix.functional import plane_wave
field = plane_wave(...)
propagation = Propagate(field, z=1e3, n=1.33, method='asm')
Warning
The underlying propagation method now defaults to method=asm,
bandlimit=True and remove_evanescent=False, which corresponds
to bandlimited angular spectrum (BLAS) as proposed in "Band-Limited
Angular Spectrum Method for Numerical Simulation of Free-Space
Propagation in Far and Near Fields" (Matsumina et al., 2009).
Warning
By default this element caches the propagation kernel using the option
cache_propagator. If you would like to have a propagation kernel
with your own initialization, see KernelPropagate which accepts a
custom propagator.
Attributes:
| Name | Type | Description |
|---|---|---|
z |
ScalarLike | Float[Array, z]
|
How far to propagate as a scalar value or a 1D array in units of distance. |
n |
ScalarLike
|
Refractive index. |
pad_width |
int
|
The padding for propagation (will be used as both height and
width padding). To automatically calculate the padding, use padding
calculation functions from |
cval |
ScalarLike
|
The value to pad with if |
kykx |
Float[Array, 2] | tuple[float, float]
|
If provided, defines the orientation of the propagation. Should
be an array of shape |
method |
Literal['transform', 'transfer', 'asm']
|
The propagation method, which can be "transform", "transfer", or "asm". Defaults to "asm", which is propagation as a Fourier convolution (two Fourier transforms) without the Fresnel approximation. |
bandlimit |
bool
|
Whether to bandlimit the field before propagation for "asm". Defaults to True. |
remove_evanescent |
bool
|
Whether to remove evanescent waves when using the "asm" method. Defaults to False. |
mode |
Literal['full', 'same']
|
Defines the cropping of the output if the method is NOT
"transform". Defaults to "same", which returns a |
cache_propagator |
bool
|
Whether to precompute and store the propagation kernel
or not. If |
Source code in src/chromatix/elements/propagation.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 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 | |
bandlimit = bandlimit
class-attribute
instance-attribute
¶
cache_propagator = cache_propagator
class-attribute
instance-attribute
¶
cval = cval
instance-attribute
¶
kykx = kykx
instance-attribute
¶
method = method
class-attribute
instance-attribute
¶
mode = mode
class-attribute
instance-attribute
¶
n = n
instance-attribute
¶
pad_width = pad_width
class-attribute
instance-attribute
¶
propagator
instance-attribute
¶
remove_evanescent = remove_evanescent
class-attribute
instance-attribute
¶
z = z
instance-attribute
¶
__call__(field)
¶
Source code in src/chromatix/elements/propagation.py
__init__(field, z, n, pad_width=0, cval=0, kykx=(0.0, 0.0), method='asm', bandlimit=True, remove_evanescent=False, mode='same', cache_propagator=True)
¶
Source code in src/chromatix/elements/propagation.py
Convenience¶
__all__ = ['Flip', 'ScaleAndBias', 'Binarize', 'Quantize']
module-attribute
¶
Binarize
¶
Bases: Module
This element binarizes the incoming Field.
See chromatix.ops.quantization.binarize for more details.
Source code in src/chromatix/elements/convenience.py
Flip
¶
Bases: Module
This element flips the incoming Field upside down.
This is useful for situations where an upside down image is formed.
Source code in src/chromatix/elements/convenience.py
Quantize
¶
Bases: Module
This element quantizes the incoming Field to the given bit_depth.
See chromatix.ops.quantization.quantize for more details.
Source code in src/chromatix/elements/convenience.py
ScaleAndBias
¶
Bases: Module
This element applies a scale and bias to the incoming Field.
The scale and bias can either be scalars or Arrays
broadcastable to the shape of the incoming Field.