-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathaberrations.py
998 lines (810 loc) · 33.2 KB
/
aberrations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
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
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
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
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
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
"""Features that aberrate and modify pupil functions.
This module provides tools to simulate optical aberrations in microscopy
by modifying the pupil function of an image. These aberrations can be used
to study and model the effects of real-world optical imperfections.
Key Features
------------
The module allows simulation of both amplitude and phase aberrations,
including specific common aberrations, through a set of modular classes:
- **Amplitude Aberrations**
Modulate the intensity profile of the pupil function:
- `GaussianApodization`: Introduces Gaussian pupil apodization to
reduce the amplitude at higher spatial frequencies.
- **Phase Aberrations**
Introduce phase shifts in the pupil function using Zernike polynomials:
- `Zernike`: Adds phase aberrations based on user-defined Zernike
coefficients.
- **Common Aberrations**
Implements commonly encountered Zernike phase aberrations for convenience:
- `Piston`: Uniform phase shift (n=0, m=0).
- `VerticalTilt`: Linear tilt along the y-axis (n=1, m=-1).
- `HorizontalTilt`: Linear tilt along the x-axis (n=1, m=1).
- `ObliqueAstigmatism`: Oblique astigmatism (n=2, m=-2).
- `Defocus`: Defocus (n=2, m=0).
- `Astigmatism`: Regular astigmatism (n=2, m=2).
- `ObliqueTrefoil`: Oblique trefoil (n=3, m=-3).
- `VerticalComa`: Vertical coma (n=3, m=-1).
- `HorizontalComa`: Horizontal coma (n=3, m=1).
- `Trefoil`: Trefoil aberration (n=3, m=3).
- `SphericalAberration`: Spherical aberration (n=4, m=0).
Module Structure
----------------
Classes:
- `Aberration`: Base class for all aberrations.
- `GaussianApodization`: Implements pupil apodization.
- `Zernike`: Adds phase aberrations using Zernike polynomials.
- Specific Zernike-based aberration subclasses, e.g., `Defocus`,
`Astigmatism`, etc.
Examples
--------
Applying Gaussian Apodization
>>> import deeptrack as dt
>>> particle = dt.PointParticle(position=(32, 32))
>>> aberrated_optics = dt.Fluorescence(
>>> NA=0.6,
>>> resolution=1e-7,
>>> magnification=1,
>>> wavelength=530e-9,
>>> output_region=(0, 0, 64, 48),
>>> padding=(64, 64, 64, 64),
>>> aberration=aberrations.GaussianApodization(sigma=0.9),
>>> z = -1.0 * dt.units.micrometer,
>>> )
>>> aberrated_particle = aberrated_optics(particle)
>>> aberrated_particle.plot(cmap="gray")
"""
from __future__ import annotations
from typing import Any
import numpy as np
import math
from deeptrack.features import Feature
from deeptrack.types import PropertyLike
from deeptrack.utils import as_list
class Aberration(Feature):
"""Base class for optical aberrations.
This class represents a generic optical aberration. It computes the
radial (rho) and angular (theta) pupil coordinates for each input image,
normalizes rho by the maximum value within the non-zero region of the
image, and passes these coordinates for further processing.
Parameters
----------
Some common parameters inherited from Feature, such as `sigma`, `offset`,
etc., depending on the specific subclass.
Attributes
----------
__distributed__: bool
Indicates that the feature can be distributed across multiple
processing units.
Methods
-------
`_process_and_get(image_list: list[np.ndarray], **kwargs: dict) -> list[np.ndarray]`
Processes a list of input images to compute pupil coordinates (rho and
theta) and passes them, along with the original images, to the
superclass method for further processing.
"""
__distributed__: bool = True
def _process_and_get(
self: Feature,
image_list: list[np.ndarray],
**kwargs: dict[str, np.ndarray]
) -> list[np.ndarray]:
"""Computes pupil coordinates.
Computes pupil coordinates (rho and theta) for each input image and
processes the images along with these coordinates.
Parameters
----------
image_list: list[np.ndarray]
A list of 2D input images to be processed.
**kwargs: dict[str, np.ndarray]
Additional parameters to be passed to the superclass's
`_process_and_get` method.
Returns
-------
list: list[np.ndarray]
A list of processed images with added pupil coordinates.
"""
new_list = []
for image in image_list:
x = np.arange(image.shape[0]) - image.shape[0] / 2
y = np.arange(image.shape[1]) - image.shape[1] / 2
X, Y = np.meshgrid(y, x)
rho = np.sqrt(X ** 2 + Y ** 2)
rho /= np.max(rho[image != 0])
theta = np.arctan2(Y, X)
new_list += super()._process_and_get(
[image], rho=rho, theta=theta, **kwargs
)
return new_list
class GaussianApodization(Aberration):
"""Introduces pupil apodization.
This class modifies the amplitude of the pupil function to decrease
progressively at higher spatial frequencies, following a Gaussian
distribution. The apodization helps simulate the effects of optical
attenuation at the edges of the pupil.
Parameters
----------
sigma: float, optional
The standard deviation of the Gaussian apodization. Defines how
quickly the amplitude decreases towards the pupil edges. A smaller
value leads to a more rapid decay. The default is 1.
offset: tuple of float, optional
Specifies the (x, y) offset of the Gaussian center relative to the
pupil's geometric center. The default is (0, 0).
Methods
-------
`get(pupil: np.ndarray, offset: tuple[float, float], sigma: float, rho: np.ndarray, **kwargs: dict[str, Any]) -> np.ndarray`
Applies Gaussian apodization to the input pupil function.
Examples
--------
Apply Gaussian apodization to a simulated fluorescence image:
>>> import deeptrack as dt
>>> particle = dt.PointParticle(z = 2 * dt.units.micrometer)
>>> aberrated_optics = dt.Fluorescence(
>>> pupil = dt.GaussianApodization(sigma=0.5),
>>> )
>>> aberrated_particle = aberrated_optics(particle)
>>> aberrated_particle.plot(cmap="gray")
"""
def __init__(
self: GaussianApodization,
sigma: PropertyLike[float] = 1,
offset: PropertyLike[tuple[int, int]] = (0, 0),
**kwargs: dict[str, Any]
) -> None:
"""Initializes the GaussianApodization class.
Initializes the GaussianApodization class with parameters that control
the Gaussian distribution applied to the pupil function.
Parameters
----------
sigma: float, optional
The standard deviation of the Gaussian apodization. A smaller
value results in more rapid attenuation at the edges. Default is 1.
offset: tuple of float, optional
The (x, y) coordinates of the Gaussian center's offset relative
to the geometric center of the pupil. Default is (0, 0).
**kwargs: dict, optional
Additional parameters passed to the parent class `Aberration`.
"""
super().__init__(sigma=sigma, offset=offset, **kwargs)
def get(
self: GaussianApodization,
pupil: np.ndarray,
offset: tuple[float, float],
sigma: float,
rho: np.ndarray,
**kwargs: dict[str, Any]
) -> np.ndarray:
"""Applies Gaussian apodization to the input pupil function.
This method attenuates the amplitude of the pupil function based
on a Gaussian distribution, where the amplitude decreases as the
distance from the Gaussian center increases.
Parameters
----------
pupil: np.ndarray
A 2D array representing the input pupil function.
offset: tuple of float
Specifies the (x, y) offset of the Gaussian center relative
to the pupil's center.
sigma: float
The standard deviation of the Gaussian apodization.
rho: np.ndarray
A 2D array of radial coordinates normalized to the pupil
aperture.
**kwargs: dict, optional
Additional parameters for compatibility with other features
or inherited methods. These are typically passed by the
parent class and may include:
- `z` (float): The depth or axial position of the image,
used in certain contexts.
Returns
-------
np.ndarray
The modified pupil function after applying Gaussian apodization.
Examples
--------
>>> import deeptrack as dt
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> pupil = np.ones((128, 128))
>>> rho = np.linspace(0, 1, 128).reshape(-1, 1) @ np.ones((1, 128))
>>> x = np.linspace(-1, 1, 128)
>>> y = np.linspace(-1, 1, 128)
>>> X, Y = np.meshgrid(x, y)
>>> rho = np.sqrt(X**2 + Y**2)
>>> pupil[rho > 1] = 0
>>> apodizer = dt.GaussianApodization(sigma=0.5, offset=(25, -3))
>>> modified_pupil = apodizer.get(
>>> pupil,
>>> offset=(5, -3),
>>> sigma=0.5,
>>> rho=rho
>>> )
>>> fig, axes = plt.subplots(1, 2, figsize=(12, 6))
>>> axes[0].imshow(np.abs(modified_pupil), cmap="gray")
>>> axes[0].set_title("Modified Pupil Magnitude")
>>> axes[1].imshow(np.angle(modified_pupil), cmap="hsv")
>>> axes[1].set_title("Modified Pupil Phase")
>>> plt.show()
>>> modified_pupil.shape
(128, 128)
"""
if offset != (0, 0):
x = np.arange(pupil.shape[0]) - pupil.shape[0] / 2 - offset[0]
y = np.arange(pupil.shape[1]) - pupil.shape[1] / 2 - offset[1]
X, Y = np.meshgrid(x, y)
rho = np.sqrt(X ** 2 + Y ** 2)
rho /= np.max(rho[pupil != 0])
rho[rho > 1] = np.inf
pupil = pupil * np.exp(-((rho / sigma) ** 2))
return pupil
class Zernike(Aberration):
"""Introduces a Zernike phase aberration.
This class applies Zernike polynomial-based phase aberrations to an input
pupil function. The Zernike polynomials are used to model various optical
aberrations such as defocus, astigmatism, and coma.
The Zernike polynomial is defined by the radial index `n` and the azimuthal
index `m`. The phase contribution is weighted by a specified `coefficient`.
When multiple values are provided for `n`, `m`, and `coefficient`, the
corresponding Zernike polynomials are summed and applied to the pupil
phase.
Parameters
----------
n: PropertyLike[int or list of ints]
The radial index or indices of the Zernike polynomials.
m: PropertyLike[int or list of ints]
The azimuthal index or indices of the Zernike polynomials.
coefficient: PropertyLike[float or list of floats]
The scaling coefficient(s) for the Zernike polynomials.
Attributes
----------
n: PropertyLike[int or list of ints]
The radial index or indices of the Zernike polynomials.
m: PropertyLike[int or list of ints]
The azimuthal index or indices of the Zernike polynomials.
coefficient: PropertyLike[float or list of floats]
The scaling coefficient(s) for the Zernike polynomials.
Methods
-------
`get(pupil: np.ndarray, rho: np.ndarray, theta: np.ndarray, n: int | list[int], m: int | list[int], coefficient: float | list[float], **kwargs: dict[str, Any]) -> np.ndarray`
Applies the Zernike phase aberration to the input pupil function.
Notes
-----
The Zernike polynomials are normalized to ensure orthogonality. The phase
aberration is added in the form of a complex exponential.
Examples
--------
Apply Zernike polynomial-based phase aberrations to a simulated
fluorescence image:
>>> import deeptrack as dt
>>> particle = dt.PointParticle(z = 1 * dt.units.micrometer)
>>> aberrated_optics = dt.Fluorescence(
>>> pupil=dt.Zernike(
>>> n=[0, 1],
>>> m = [1, 2],
>>> coefficient=[1, 1]
>>> )
>>> )
>>> aberrated_particle = aberrated_optics(particle)
>>> aberrated_particle.plot(cmap="gray")
"""
def __init__(
self: "Zernike",
n: PropertyLike[int | list[int]],
m: PropertyLike[int | list[int]],
coefficient: PropertyLike[float | list[float]] = 1,
**kwargs: dict[str, Any]
) -> None:
""" Initializes the Zernike class.
Initializes the Zernike class with the specified indices and coefficients
for the Zernike polynomials.
Parameters
----------
n: int or list of ints
The radial indices of the Zernike polynomials.
m: int or list of ints
The azimuthal indices of the Zernike polynomials.
coefficient: float or list of floats, optional
The coefficients for the Zernike polynomials. These determine the
relative contribution of each polynomial. Default is 1.
**kwargs: dict, optional
Additional parameters passed to the parent class `Aberration`.
Notes
-----
The `n`, `m`, and `coefficient` parameters must have the same length if
provided as lists.
"""
super().__init__(n=n, m=m, coefficient=coefficient, **kwargs)
def get(
self: Zernike,
pupil: np.ndarray,
rho: np.ndarray,
theta: np.ndarray,
n: int | list[int],
m: int | list[int],
coefficient: float | list[float],
**kwargs: dict[str, Any],
) -> np.ndarray:
"""Applies the Zernike phase aberration to the input pupil function.
The method calculates Zernike polynomials for the specified indices `n`
and `m`, scales them by `coefficient`, and adds the resulting phase to
the input pupil function. Multiple polynomials are summed if `n`, `m`,
and `coefficient` are provided as lists.
Parameters
----------
pupil: np.ndarray
A 2D array representing the input pupil function. The values should
represent the amplitude and phase across the aperture.
rho: np.ndarray
A 2D array of radial coordinates normalized to the pupil aperture.
The values should range from 0 to 1 within the aperture.
theta: np.ndarray
A 2D array of angular coordinates in radians. These define the
azimuthal positions for the pupil.
n: int or list of ints
The radial indices of the Zernike polynomials.
m: int or list of ints
The azimuthal indices of the Zernike polynomials.
coefficient: float or list of floats
The coefficients for the Zernike polynomials, controlling their
relative contributions to the phase.
**kwargs: dict, optional
Additional parameters for compatibility with other features or
inherited methods.
Returns
-------
np.ndarray
The modified pupil function with the applied Zernike phase
aberration.
Raises
------
AssertionError
If the lengths of `n`, `m`, and `coefficient` lists do not match.
Notes
-----
- The method first calculates the Zernike polynomials for each
combination of `n` and `m` and scales them by the corresponding
`coefficient`.
- The resulting polynomials are summed and converted into a phase
factor, which is applied to the pupil.
Examples
--------
>>> import deeptrack as dt
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> pupil = np.ones((128, 128), dtype=complex)
>>> x = np.linspace(-1, 1, 128)
>>> y = np.linspace(-1, 1, 128)
>>> X, Y = np.meshgrid(x, y)
>>> rho = np.sqrt(X**2 + Y**2)
>>> theta = np.arctan2(Y, X)
>>> pupil[rho > 1] = 0
>>> n = [2, 3]
>>> m = [0, 1]
>>> coefficient = [0.5, 0.3]
>>> zernike = dt.Zernike(n=n, m=m, coefficient=coefficient)
>>> modified_pupil = zernike.get(pupil, rho, theta, n, m, coefficient)
>>> fig, axes = plt.subplots(1, 2, figsize=(12, 6))
>>> axes[0].imshow(np.abs(modified_pupil), cmap="gray")
>>> axes[0].set_title("Modified Pupil Magnitude")
>>> axes[1].imshow(np.angle(modified_pupil), cmap="hsv")
>>> axes[1].set_title("Modified Pupil Phase")
>>> plt.show()
"""
m_list = as_list(m)
n_list = as_list(n)
coefficients = as_list(coefficient)
assert len(m_list) == len(n_list), "The number of indices need to match"
assert len(m_list) == len(
coefficients
), "The number of indices need to match the number of coefficients"
pupil_bool = pupil != 0
rho = rho[pupil_bool]
theta = theta[pupil_bool]
Z = 0
for n, m, coefficient in zip(n_list, m_list, coefficients):
if (n - m) % 2 or coefficient == 0:
continue
R = 0
for k in range((n - np.abs(m)) // 2 + 1):
R += (
(-1) ** k
* math.factorial(n - k)
/ (
math.factorial(k)
* math.factorial((n - m) // 2 - k)
* math.factorial((n + m) // 2 - k)
)
* rho ** (n - 2 * k)
)
if m > 0:
R = R * np.cos(m * theta) * (np.sqrt(2 * n + 2) * coefficient)
elif m < 0:
R = R * np.sin(-m * theta) * (np.sqrt(2 * n + 2) * coefficient)
else:
R = R * (np.sqrt(n + 1) * coefficient)
Z += R
phase = np.exp(1j * Z)
pupil[pupil_bool] *= phase
return pupil
class Piston(Zernike):
"""Zernike polynomial with n=0, m=0.
This class represents the simplest Zernike polynomial, often referred to as the piston term,
which has no radial or azimuthal variations (n=0, m=0). It adds a uniform phase contribution
to the pupil function.
Parameters
----------
coefficient: PropertyLike[float or list of floats], optional
The coefficient of the polynomial. Default is 1.
Attributes
----------
n: int
The radial index of the Zernike polynomial (always 0 for Piston).
m: int
The azimuthal index of the Zernike polynomial (always 0 for Piston).
coefficient: PropertyLike[float or list of floats]
The coefficient of the polynomial.
Examples
--------
Apply a Piston Zernike phase aberration (n=0, m=0) to a simulated
fluorescence image:
>>> import deeptrack as dt
>>> particle = dt.PointParticle(z=1 * dt.units.micrometer)
>>> piston_aberration = dt.Piston(coefficient=0.9)
>>> aberrated_optics = dt.Fluorescence(
>>> pupil=piston_aberration,
>>> )
>>> aberrated_particle = aberrated_optics(particle)
>>> aberrated_particle.plot(cmap="gray")
"""
def __init__(
self: "Piston",
*args: tuple[Any, ...],
coefficient: PropertyLike[float | list[float]] = 1,
**kwargs: dict[str, Any],
) -> None:
"""Initializes the Piston class.
Parameters
----------
coefficient: float or list of floats, optional
The coefficient for the piston term. Default is 1.
*args: tuple, optional
Additional arguments passed to the parent Zernike class.
**kwargs: dict, optional
Additional parameters passed to the parent Zernike class.
"""
super().__init__(*args, n=0, m=0, coefficient=coefficient, **kwargs)
class VerticalTilt(Zernike):
"""Zernike polynomial with n=1, m=-1.
This class represents a Zernike polynomial corresponding to a vertical tilt
aberration. It introduces a linear phase variation across the aperture
aligned with the vertical axis.
Parameters
----------
coefficient: PropertyLike[float or list of floats], optional
The coefficient of the polynomial. Default is 1.
Attributes
----------
n: int
The radial index of the Zernike polynomial (always 1 for VerticalTilt).
m: int
The azimuthal index of the Zernike polynomial (always -1 for VerticalTilt).
coefficient: PropertyLike[float or list of floats]
The coefficient of the polynomial.
Examples
--------
Apply a VerticalTilt Zernike phase aberration (n=1, m=-1) to a simulated
fluorescence image:
>>> import deeptrack as dt
>>> particle = dt.PointParticle(z=1 * dt.units.micrometer)
>>> vertical_tilt_aberration = dt.VerticalTilt(coefficient=-10)
>>> aberrated_optics = dt.Fluorescence(
>>> pupil=vertical_tilt_aberration,
>>> )
>>> aberrated_particle = aberrated_optics(particle)
>>> aberrated_particle.plot(cmap="gray")
"""
def __init__(
self: VerticalTilt,
*args: tuple[Any, ...],
coefficient: PropertyLike[float | list[float]] = 1,
**kwargs: dict[str, Any],
) -> None:
"""Initializes the VerticalTilt class.
Parameters
----------
coefficient: float or list of floats, optional
The coefficient for the vertical tilt term. Default is 1.
*args: tuple, optional
Additional arguments passed to the parent Zernike class.
**kwargs: dict, optional
Additional parameters passed to the parent Zernike class.
"""
super().__init__(*args, n=1, m=-1, coefficient=coefficient, **kwargs)
class HorizontalTilt(Zernike):
"""Zernike polynomial with n=1, m=1.
This class represents a Zernike polynomial corresponding to a horizontal
tilt aberration. It introduces a linear phase variation across the aperture
aligned with the horizontal axis.
Parameters
----------
coefficient: PropertyLike[float or list of floats], optional
The coefficient of the polynomial. Default is 1.
Attributes
----------
n: int
The radial index of the Zernike polynomial (always 1 for
HorizontalTilt).
m: int
The azimuthal index of the Zernike polynomial (always 1 for
HorizontalTilt).
coefficient: PropertyLike[float or list of floats]
The coefficient of the polynomial.
Examples
--------
Apply a HorizontalTilt Zernike phase aberration (n=1, m=1) to a simulated
fluorescence image:
>>> import deeptrack as dt
>>> particle = dt.PointParticle(z=1 * dt.units.micrometer)
>>> horizontal_tilt_aberration = dt.HorizontalTilt(coefficient=6)
>>> aberrated_optics = dt.Fluorescence(
>>> pupil=horizontal_tilt_aberration,
>>> )
>>> aberrated_particle = aberrated_optics(particle)
>>> aberrated_particle.plot(cmap="gray")
"""
def __init__(
self: HorizontalTilt,
*args: tuple[Any, ...],
coefficient: PropertyLike[float | list[float]] = 1,
**kwargs: dict[str, Any],
) -> None:
"""Initializes the HorizontalTilt class.
Parameters
----------
coefficient: float or list of floats, optional
The coefficient for the horizontal tilt term. Default is 1.
*args: tuple, optional
Additional arguments passed to the parent Zernike class.
**kwargs: dict, optional
Additional parameters passed to the parent Zernike class.
"""
super().__init__(*args, n=1, m=1, coefficient=coefficient, **kwargs)
class ObliqueAstigmatism(Zernike):
"""Zernike polynomial with n=2, m=-2.
This class represents a Zernike polynomial corresponding to oblique
astigmatism, characterized by a phase aberration with a radial index of n=2
and an azimuthal index of m=-2. It describes astigmatism with axes oriented
obliquely to the horizontal and vertical.
Parameters
----------
coefficient: PropertyLike[float or list of floats], optional
The coefficient of the polynomial. Default is 1.
Attributes
----------
n: int
The radial index of the Zernike polynomial (always 2 for
ObliqueAstigmatism).
m: int
The azimuthal index of the Zernike polynomial (always -2 for
ObliqueAstigmatism).
coefficient: PropertyLike[float or list of floats]
The coefficient of the polynomial.
Examples
--------
Apply an ObliqueAstigmatism Zernike phase aberration (n=2, m=-2) to a
simulated fluorescence image:
>>> import deeptrack as dt
>>> particle = dt.PointParticle(z=4 * dt.units.micrometer)
>>> oblique_astigmatism_aberration = dt.ObliqueAstigmatism(coefficient=0.2)
>>> aberrated_optics = dt.Fluorescence(
>>> pupil=oblique_astigmatism_aberration,
>>> )
>>> aberrated_particle = aberrated_optics(particle)
>>> aberrated_particle.plot(cmap="gray")
"""
def __init__(
self: ObliqueAstigmatism,
*args: tuple[Any, ...],
coefficient: PropertyLike[float | list[float]] = 1,
**kwargs: dict[str, Any],
) -> None:
"""Initializes the ObliqueAstigmatism class.
Parameters
----------
coefficient: float or list of floats, optional
The coefficient for the oblique astigmatism term. Default is 1.
*args: tuple, optional
Additional arguments passed to the parent Zernike class.
**kwargs: dict, optional
Additional parameters passed to the parent Zernike class.
"""
super().__init__(*args, n=2, m=-2, coefficient=coefficient, **kwargs)
class Defocus(Zernike):
"""Zernike polynomial with n=2, m=0.
This class represents the Zernike polynomial for defocus aberration,
characterized by a radial index of n=2 and an azimuthal index of m=0.
It describes phase aberrations that result in a uniform spherical defocus
across the optical system.
Parameters
----------
coefficient: PropertyLike[float or list of floats], optional
The coefficient of the polynomial. Default is 1.
Attributes
----------
n: int
The radial index of the Zernike polynomial (always 2 for Defocus).
m: int
The azimuthal index of the Zernike polynomial (always 0 for Defocus).
coefficient: PropertyLike[float or list of floats]
The coefficient of the polynomial.
Examples
--------
Apply a Defocus Zernike phase aberration (n=2, m=0) to a simulated
fluorescence image:
>>> import deeptrack as dt
>>> particle = dt.PointParticle(z=0 * dt.units.micrometer)
>>> defocus_aberration = dt.Defocus(coefficient= 1.5)
>>> aberrated_optics = dt.Fluorescence(
>>> pupil=defocus_aberration,
>>> )
>>> aberrated_particle = aberrated_optics(particle)
>>> aberrated_particle.plot(cmap="gray")
"""
def __init__(
self: Defocus,
*args: tuple[Any, ...],
coefficient: PropertyLike[float | list[float]] = 1,
**kwargs: dict[str, Any],
) -> None:
"""Initializes the Defocus class.
Parameters
----------
coefficient: float or list of floats, optional
The coefficient for the defocus term. Default is 1.
*args: tuple, optional
Additional arguments passed to the parent Zernike class.
**kwargs: dict, optional
Additional parameters passed to the parent Zernike class.
"""
super().__init__(*args, n=2, m=0, coefficient=coefficient, **kwargs)
class Astigmatism(Zernike):
"""Zernike polynomial with n=2, m=2.
This class represents the Zernike polynomial for astigmatism aberration,
characterized by a radial index of n=2 and an azimuthal index of m=2.
It describes phase aberrations that result in elliptical distortions
in the optical system.
Parameters
----------
coefficient: PropertyLike[float or list of floats], optional
The coefficient of the polynomial. Default is 1.
Attributes
----------
n: int
The radial index of the Zernike polynomial (always 2 for Astigmatism).
m: int
The azimuthal index of the Zernike polynomial (always 2 for Astigmatism).
coefficient: PropertyLike[float or list of floats]
The coefficient of the polynomial.
Examples
--------
Apply an Astigmatism Zernike phase aberration (n=2, m=2) to a simulated
fluorescence image:
>>> import deeptrack as dt
>>> particle = dt.PointParticle(z=1 * dt.units.micrometer)
>>> astigmatism_aberration = dt.Astigmatism(coefficient=0.75)
>>> aberrated_optics = dt.Fluorescence(
>>> pupil=astigmatism_aberration,
>>> )
>>> aberrated_particle = aberrated_optics(particle)
>>> aberrated_particle.plot(cmap="gray")
"""
def __init__(
self: Astigmatism,
*args: tuple[Any, ...],
coefficient: PropertyLike[float | list[float]] = 1,
**kwargs: dict[str, Any],
) -> None:
"""Initializes the Astigmatism class.
Parameters
----------
coefficient: float or list of floats, optional
The coefficient for the astigmatism term. Default is 1.
*args: tuple, optional
Additional arguments passed to the parent Zernike class.
**kwargs: dict, optional
Additional parameters passed to the parent Zernike class.
"""
super().__init__(*args, n=2, m=2, coefficient=coefficient, **kwargs)
class ObliqueTrefoil(Zernike):
"""Zernike polynomial with n=3, m=-3.
This class represents the Zernike polynomial for oblique trefoil
aberration, characterized by a radial index of n=3 and an azimuthal index
of m=-3. It describes phase aberrations with triangular symmetry.
Parameters
----------
coefficient: PropertyLike[float or list of floats], optional
The coefficient of the polynomial. Default is 1.
Examples
--------
Apply an Oblique Trefoil Zernike phase aberration (n=3, m=-3) to a
simulated fluorescence image:
>>> import deeptrack as dt
>>> particle = dt.PointParticle(z=0 * dt.units.micrometer)
>>> oblique_trefoil = dt.ObliqueTrefoil(coefficient=1.1)
>>> aberrated_optics = dt.Fluorescence(
>>> pupil=oblique_trefoil,
>>> )
>>> aberrated_particle = aberrated_optics(particle)
>>> aberrated_particle.plot(cmap="gray")
"""
def __init__(
self: ObliqueTrefoil,
*args: tuple[Any, ...],
coefficient: PropertyLike[float | list[float]] = 1,
**kwargs: dict[str, Any],
) -> None:
super().__init__(*args, n=3, m=-3, coefficient=coefficient, **kwargs)
class VerticalComa(Zernike):
"""Zernike polynomial with n=3, m=-1.
This class represents the Zernike polynomial for vertical coma aberration,
characterized by a radial index of n=3 and an azimuthal index of m=-1.
Parameters
----------
coefficient: PropertyLike[float or list of floats], optional
The coefficient of the polynomial. Default is 1.
"""
def __init__(
self: VerticalComa,
*args: tuple[Any, ...],
coefficient: PropertyLike[float | list[float]] = 1,
**kwargs: dict[str, Any],
) -> None:
super().__init__(*args, n=3, m=-1, coefficient=coefficient, **kwargs)
class HorizontalComa(Zernike):
"""Zernike polynomial with n=3, m=1.
This class represents the Zernike polynomial for horizontal coma aberration,
characterized by a radial index of n=3 and an azimuthal index of m=1.
Parameters
----------
coefficient: PropertyLike[float or list of floats], optional
The coefficient of the polynomial. Default is 1.
"""
def __init__(
self: HorizontalComa,
*args: tuple[Any, ...],
coefficient: PropertyLike[float | list[float]] = 1,
**kwargs: dict[str, Any],
) -> None:
super().__init__(*args, n=3, m=1, coefficient=coefficient, **kwargs)
class Trefoil(Zernike):
"""Zernike polynomial with n=3, m=3.
This class represents the Zernike polynomial for trefoil aberration,
characterized by a radial index of n=3 and an azimuthal index of m=3.
Parameters
----------
coefficient: PropertyLike[float or list of floats], optional
The coefficient of the polynomial. Default is 1.
"""
def __init__(
self: Trefoil,
*args: tuple[Any, ...],
coefficient: PropertyLike[float | list[float]] = 1,
**kwargs: dict[str, Any],
) -> None:
super().__init__(*args, n=3, m=3, coefficient=coefficient, **kwargs)
class SphericalAberration(Zernike):
"""Zernike polynomial with n=4, m=0.
This class represents the Zernike polynomial for spherical aberration,
characterized by a radial index of n=4 and an azimuthal index of m=0.
Parameters
----------
coefficient: PropertyLike[float or list of floats], optional
The coefficient of the polynomial. Default is 1.
"""
def __init__(
self: SphericalAberration,
*args: tuple[Any, ...],
coefficient: PropertyLike[float | list[float]] = 1,
**kwargs: dict[str, Any],
) -> None:
super().__init__(*args, n=4, m=0, coefficient=coefficient, **kwargs)