-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviper_detector.py
1221 lines (1048 loc) · 54.6 KB
/
viper_detector.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
999
1000
import numpy as np
import sys
from hcipy import *
def emgain_large_poisson(lam, thresh=1e6):
"""
Draw samples from a Poisson distribution while taking into account EM multiplicative noise and taking care of large values of `lam`.
At large values of `lam` the distribution automatically switches to the corresponding normal distribution.
This switch is independently decided for each expectation value in the `lam` array.
Parameters
----------
lam : array_like
Expectation value for the Poisson distribution. Must be >= 0.
thresh : float
The threshold at which the distribution switched from a Poisson to a normal distribution.
Returns
-------
array_like
The drawn samples from the Poisson or normal distribution, depending on the expectation value.
"""
large = lam > thresh
small = ~large
# Use normal approximation if the number of photons is large
n = np.zeros(lam.shape)
n[large] = np.round(lam[large] + np.random.normal(size=np.sum(large)) * np.sqrt(2*lam[large]))
n[small] = np.random.poisson(2*lam[small], size=np.sum(small))-lam[small]
if hasattr(lam, 'grid'):
n = Field(n, lam.grid)
return n
class ProEM512(NoisyDetector):
'''A subclass of NoisyDetector class based on the ProEM®-HS:512BX3.\n
Details can be found at: \n
https://www.princetoninstruments.com/wp-content/uploads/2020/10/ProEM-HS_512BX3_datasheet.pdf \n
The parameters of this detector have been hardcoded into the subclass based on values drawn from
brochures and user manuals. These parameters include:\n
dark current rate - found in documentation \n
read noise - found in documentation (Note that when a range of read noises was given in the documentation,
the MAXIMUM read noise was always choosen. Read Noise generally increases as a function of frame rate
and given the speckle applications of this project, we presumed that the maximum frame rate was desired.
Presuming the maximum frame rate lead to the choice of the maximum read noise.)
flat field - presumed to be zero \n
include photon noise - presumed to be true \n
max fps - The maximum FPS at the size most relevant to the VIPER Project. \n
detector size - The size of the short length of the detector. Many detectors can have their regions of
interest reduced in order to increase frame rate. Some detectors reduce ROI into smaller sqaures
while others reduce ROI into rows with max length but reduced height. In the case of square ROIs
the detector size corresponds to the side length of the square. In the case of rectangular ROIs
the detector size corresponds the the length of the short side, as the long side remains unchanged. \n
shutter type - The electronic shutter that determines the way in which photons are captured and then read out
of the detector. Can be either Rolling or Global. \n
detector type - The classification of the detector. Either EMCCD or some form of CMOS camera. \n
quantum efficiency - The quantum efficiency of the detector calculated based on taking a weighted average
of the QE curves given in documentation with the weights being the transmission ratios of the filters
U, B, V, R, and I. \n
Parameters
----------
detector_grid : Grid
The grid on which the detector samples.
filter : string
A letter indicating the filter from UBVRI. Relevant for computing the quantum efficiency.
EM_gain: Scalar or None
The EM multiplication gain of the EMCCD. Used to determine the read noise and if the full well depth is exceeded.
None means EM Multiplicative noise will not be considered.
EM_saturate: None or np.nan
Choose the behavior of the detector if the full well depth is exceeded. If None, every instance that the full
well depth is exceeded is replaced with the maximum full well depth. If np.nan, it is replaced with np.nan.
subsampling : integer or scalar or ndarray
The number of subpixels per pixel along one axis. For example, a
value of 2 indicates that 2x2=4 subpixels are used per pixel. If
this is a scalar, it will be rounded to the nearest integer. If
this is an array, the subsampling factor will be different for
each dimension. Default: 1.
'''
def __init__(self, detector_grid, filter, EM_gain = None, EM_saturate = None , subsampling=1):
NoisyDetector.__init__(self, detector_grid, subsampling)
# Setting the start charge level.
self.accumulated_charge = 0
# The parameters.
self.dark_current_rate = 0.001
self.read_noise = 125
self.flat_field = 0
self.include_photon_noise = True
self.max_fps = 61
self.detector_size = 512
self.shutter_type = 'Global'
self.detector_type = "EMCCD"
self.EM_gain = EM_gain
self.EM_saturate = EM_saturate
self.full_well_depth = 200000
# Set Quantum Efficiency based on filter
if filter == 'U' or filter == 'u':
self.QE = 0.494
elif filter == 'B' or filter == 'b':
self.QE = 0.795
elif filter == 'V' or filter == 'v':
self.QE = 0.902
elif filter == 'R' or filter == 'r':
self.QE = 0.894
elif filter == 'I' or filter == 'i':
self.QE = 0.499
else:
raise ValueError("Error, invalid filter name.")
# Determine the read noise based on the EM Gain
if EM_gain is not None:
self.read_noise = self.read_noise/EM_gain
def integrate(self, wavefront, dt, weight=1):
'''Integrates the detector.
Identical to the integrate funcion of NoisyDetector except includes loss due to Quantum Efficiency.
Parameters
----------
wavefront : Wavefront or array_like
The wavefront sets the amount of power generated per unit time.
dt : scalar
The integration time in units of time.
weight : scalar
Weight of every unit of integration time.
'''
# The power that the detector detects during the integration.
if hasattr(wavefront, 'power'):
power = wavefront.power
else:
power = wavefront
self.accumulated_charge += self.QE*subsample_field(power, subsampling=self.subsamping, new_grid=self.detector_grid, statistic='sum') * dt * weight
# Adding the generated dark current.
self.accumulated_charge += self.dark_current_rate * dt * weight
def read_out(self):
'''Reads out the detector.
Identical to the read_out function of NoisyDetector except EM multiplicative noise and EM gain has been included.
Returns
----------
Field
The final detector image.
'''
# Make sure not to overwrite output
output_field = self.accumulated_charge.copy()
# Adding photon noise.
if self.EM_gain is not None:
if self.include_photon_noise:
output_field = emgain_large_poisson(output_field, thresh=1e6)
else:
if self.include_photon_noise:
output_field = large_poisson(output_field, thresh=1e6)
# Adding flat field errors.
output_field *= self.flat_field
# Adding read-out noise.
output_field += np.random.normal(loc=0, scale=self.read_noise, size=output_field.size)
# If EM Gain is active, replace saturated pixels with either full well depth or nan.
if self.EM_gain is not None:
# Notify user that full well depth has been exceeded
for i in range(output_field.shape[0]):
if output_field[i]>self.full_well_depth/self.EM_gain:
print("Warning: Full Well Depth Exceeded")
break
# Set Saturated pixels to nan
if self.EM_saturate is np.nan:
output_field[output_field>self.full_well_depth/self.EM_gain] = np.nan
# Set Saturated pixels to full well depth
if self.EM_saturate is None:
output_field[output_field>self.full_well_depth/self.EM_gain] = self.full_well_depth/self.EM_gain
# Multiply Signal by EM Gain
output_field = self.EM_gain*output_field
# Reset detector
self.accumulated_charge = 0
return output_field
class iXon897(NoisyDetector):
'''A subclass of NoisyDetector class based on the iXon Ultra 897.\n
Details can be found at: \n
https://andor.oxinst.com/assets/uploads/products/andor/documents/andor-ixon-ultra-emccd-specifications.pdf \n
The parameters of this detector have been hardcoded into the subclass based on values drawn from
brochures and user manuals. These parameters include:\n
dark current rate - found in documentation \n
read noise - found in documentation (Note that when a range of read noises was given in the documentation,
the MAXIMUM read noise was always choosen. Read Noise generally increases as a function of frame rate
and given the speckle applications of this project, we presumed that the maximum frame rate was desired.
Presuming the maximum frame rate lead to the choice of the maximum read noise.)
flat field - presumed to be zero \n
include photon noise - presumed to be true \n
max fps - The maximum FPS at the size most relevant to the VIPER Project. \n
detector size - The size of the short length of the detector. Many detectors can have their regions of
interest reduced in order to increase frame rate. Some detectors reduce ROI into smaller sqaures
while others reduce ROI into rows with max length but reduced height. In the case of square ROIs
the detector size corresponds to the side length of the square. In the case of rectangular ROIs
the detector size corresponds the the length of the short side, as the long side remains unchanged. \n
shutter type - The electronic shutter that determines the way in which photons are captured and then read out
of the detector. Can be either Rolling or Global. \n
detector type - The classification of the detector. Either EMCCD or some form of CMOS camera. \n
quantum efficiency - The quantum efficiency of the detector calculated based on taking a weighted average
of the QE curves given in documentation with the weights being the transmission ratios of the filters
U, B, V, R, and I. \n
Parameters
----------
detector_grid : Grid
The grid on which the detector samples.
filter : string
A letter indicating the filter from UBVRI. Relevant for computing the quantum efficiency.
EM_gain: Scalar or None
The EM multiplication gain of the EMCCD. Used to determine the read noise and if the full well depth is exceeded.
None means EM Multiplicative noise will not be considered.
EM_saturate: None or np.nan
Choose the behavior of the detector if the full well depth is exceeded. If None, every instance that the full
well depth is exceeded is replaced with the maximum full well depth. If np.nan, it is replaced with np.nan.
subsampling : integer or scalar or ndarray
The number of subpixels per pixel along one axis. For example, a
value of 2 indicates that 2x2=4 subpixels are used per pixel. If
this is a scalar, it will be rounded to the nearest integer. If
this is an array, the subsampling factor will be different for
each dimension. Default: 1.
'''
def __init__(self, detector_grid, filter, EM_gain = None, EM_saturate= None , subsampling=1):
NoisyDetector.__init__(self, detector_grid, subsampling)
# Setting the start charge level.
self.accumulated_charge = 0
# The parameters.
self.dark_current_rate = 0.003
self.read_noise = 89
self.flat_field = 0
self.include_photon_noise = True
self.max_fps = 56
self.detector_size = 512
self.shutter_type = 'Global'
self.detector_type = "EMCCD"
self.EM_gain = EM_gain
self.EM_saturate = EM_saturate
self.full_well_depth = 180000
# Set Quantum Efficiency based on filter
if filter == 'U' or filter == 'u':
self.QE = 0.258
elif filter == 'B' or filter == 'b':
self.QE = 0.735
elif filter == 'V' or filter == 'v':
self.QE = 0.957
elif filter == 'R' or filter == 'r':
self.QE = 0.869
elif filter == 'I' or filter == 'i':
self.QE = 0.479
else:
raise ValueError("Error, invalid filter name.")
# Determine the read noise based on the EM Gain
if EM_gain is not None:
self.read_noise = self.read_noise/EM_gain
def integrate(self, wavefront, dt, weight=1):
'''Integrates the detector.
Identical to the integrate funcion of NoisyDetector except includes loss due to Quantum Efficiency.
Parameters
----------
wavefront : Wavefront or array_like
The wavefront sets the amount of power generated per unit time.
dt : scalar
The integration time in units of time.
weight : scalar
Weight of every unit of integration time.
'''
# The power that the detector detects during the integration.
if hasattr(wavefront, 'power'):
power = wavefront.power
else:
power = wavefront
self.accumulated_charge += self.QE*subsample_field(power, subsampling=self.subsamping, new_grid=self.detector_grid, statistic='sum') * dt * weight
# Adding the generated dark current.
self.accumulated_charge += self.dark_current_rate * dt * weight
def read_out(self):
'''Reads out the detector.
Identical to the read_out function of NoisyDetector except EM multiplicative noise and EM gain has been included.
Returns
----------
Field
The final detector image.
'''
# Make sure not to overwrite output
output_field = self.accumulated_charge.copy()
# Adding photon noise.
if self.EM_gain is not None:
if self.include_photon_noise:
output_field = emgain_large_poisson(output_field, thresh=1e6)
else:
if self.include_photon_noise:
output_field = large_poisson(output_field, thresh=1e6)
# Adding flat field errors.
output_field *= self.flat_field
# Adding read-out noise.
output_field += np.random.normal(loc=0, scale=self.read_noise, size=output_field.size)
# If EM Gain is active, replace saturated pixels with either full well depth or nan.
if self.EM_gain is not None:
# Notify user that full well depth has been exceeded
for i in range(output_field.shape[0]):
if output_field[i]>self.full_well_depth/self.EM_gain:
print("Warning: Full Well Depth Exceeded")
break
# Set Saturated pixels to nan
if self.EM_saturate is np.nan:
output_field[output_field>self.full_well_depth/self.EM_gain] = np.nan
# Set Saturated pixels to full well depth
if self.EM_saturate is None:
output_field[output_field>self.full_well_depth/self.EM_gain] = self.full_well_depth/self.EM_gain
# Multiply Signal by EM Gain
output_field = self.EM_gain*output_field
# Reset detector
self.accumulated_charge = 0
return output_field
class ORCA_Quest(NoisyDetector):
'''A subclass of NoisyDetector class based on the ORCA Quest.\n
Details can be found at: \n
https://www.hamamatsu.com/resources/pdf/sys/SCAS0154E_C15550-20UP_tec.pdf \n
The parameters of this detector have been hardcoded into the subclass based on values drawn from
brochures and user manuals. These parameters include:\n
dark current rate - found in documentation \n
read noise - found in documentation (Note that when a range of read noises was given in the documentation,
the MAXIMUM read noise was always choosen. Read Noise generally increases as a function of frame rate
and given the speckle applications of this project, we presumed that the maximum frame rate was desired.
Presuming the maximum frame rate lead to the choice of the maximum read noise.)
flat field - presumed to be zero \n
include photon noise - presumed to be true \n
max fps - The maximum FPS at the size most relevant to the VIPER Project. \n
detector size - The size of the short length of the detector. Many detectors can have their regions of
interest reduced in order to increase frame rate. Some detectors reduce ROI into smaller sqaures
while others reduce ROI into rows with max length but reduced height. In the case of square ROIs
the detector size corresponds to the side length of the square. In the case of rectangular ROIs
the detector size corresponds the the length of the short side, as the long side remains unchanged. \n
shutter type - The electronic shutter that determines the way in which photons are captured and then read out
of the detector. Can be either Rolling or Global. \n
detector type - The classification of the detector. Either EMCCD or some form of CMOS camera. \n
quantum efficiency - The quantum efficiency of the detector calculated based on taking a weighted average
of the QE curves given in documentation with the weights being the transmission ratios of the filters
U, B, V, R, and I. \n
Parameters
----------
detector_grid : Grid
The grid on which the detector samples.
filter : string
A letter indicating the filter from UBVRI. Relevant for computing the quantum efficiency.
subsampling : integer or scalar or ndarray
The number of subpixels per pixel along one axis. For example, a
value of 2 indicates that 2x2=4 subpixels are used per pixel. If
this is a scalar, it will be rounded to the nearest integer. If
this is an array, the subsampling factor will be different for
each dimension. Default: 1.
'''
def __init__(self, detector_grid, filter, subsampling=1):
NoisyDetector.__init__(self, detector_grid, subsampling)
# Setting the start charge level.
self.accumulated_charge = 0
# The parameters.
self.dark_current_rate = 0.006
self.read_noise = 0.43
self.flat_field = 0
self.include_photon_noise = True
self.max_fps = 532
self.detector_size = 512
self.shutter_type = 'Rolling'
self.detector_type = "sCMOS"
self.number_of_subdivisions = 32
# Set Quantum Efficiency based on filter
if filter == 'U' or filter == 'u':
self.QE = 0.459
elif filter == 'B' or filter == 'b':
self.QE = 0.865
elif filter == 'V' or filter == 'v':
self.QE = 0.835
elif filter == 'R' or filter == 'r':
self.QE = 0.648
elif filter == 'I' or filter == 'i':
self.QE = 0.362
else:
raise ValueError("Error, invalid filter name.")
def integrate(self, wavefront, dt, weight=1):
'''Integrates the detector.
Identical to the integrate funcion of NoisyDetector except includes loss due to Quantum Efficiency.
Parameters
----------
wavefront : Wavefront or array_like
The wavefront sets the amount of power generated per unit time.
dt : scalar
The integration time in units of time.
weight : scalar
Weight of every unit of integration time.
'''
# The power that the detector detects during the integration.
if hasattr(wavefront, 'power'):
power = wavefront.power
else:
power = wavefront
self.accumulated_charge += self.QE*subsample_field(power, subsampling=self.subsamping, new_grid=self.detector_grid, statistic='sum') * dt * weight
# Adding the generated dark current.
self.accumulated_charge += self.dark_current_rate * dt * weight
def roll_shutter(self, wavefronts, layer, prop, exposure_time):
'''Simulates a rolling shutter.
A combination of integrate and read_out that simulates the effects of a rolling shutter.
Parameters
----------
wavefront : Wavefront or array_like
The wavefront sets the amount of power generated per unit time.
layer: Atmospheric layer
The atmospheric layer
prop: Propagator
The propagator for the shutter
exposure_time: Scalar
The total exposure time in seconds
Returns
----------
Field.shaped
The final shaped detector image.
'''
number_of_rows = int(np.sqrt(self.detector_grid.size))
row_readout_time = 1/(self.max_fps*number_of_rows)
row_differential_time = row_readout_time*number_of_rows/self.number_of_subdivisions
layer.t += exposure_time-(row_differential_time*self.number_of_subdivisions)
for k in wavefronts:
self.integrate(prop((layer(k))),exposure_time-(row_differential_time*self.number_of_subdivisions))
read_noise_temp = self.read_noise
self.read_noise = 0 # Prevent double counting of the read noise when reading out the detector twice.
image_comb = self.read_out()
for j in range(self.number_of_subdivisions):
layer.t += row_differential_time
for k in wavefronts:
self.integrate(prop((layer(k))),row_differential_time)
self.read_noise = read_noise_temp
image_row = self.read_out()
start = int(self.detector_grid.size*(j)/self.number_of_subdivisions)
end = int(self.detector_grid.size*((j+1)/self.number_of_subdivisions))
image_comb[start:end]+=image_row[start:end]
return image_comb.shaped
class Marana(NoisyDetector):
'''A subclass of NoisyDetector class based on the Andor Marana.\n
Details can be found at: \n
https://andor.oxinst.com/assets/uploads/products/andor/documents/andor-marana-scmos-specifications.pdf \n
The parameters of this detector have been hardcoded into the subclass based on values drawn from
brochures and user manuals. These parameters include:\n
dark current rate - found in documentation \n
read noise - found in documentation (Note that when a range of read noises was given in the documentation,
the MAXIMUM read noise was always choosen. Read Noise generally increases as a function of frame rate
and given the speckle applications of this project, we presumed that the maximum frame rate was desired.
Presuming the maximum frame rate lead to the choice of the maximum read noise.)
flat field - presumed to be zero \n
include photon noise - presumed to be true \n
max fps - The maximum FPS at the size most relevant to the VIPER Project. \n
detector size - The size of the short length of the detector. Many detectors can have their regions of
interest reduced in order to increase frame rate. Some detectors reduce ROI into smaller sqaures
while others reduce ROI into rows with max length but reduced height. In the case of square ROIs
the detector size corresponds to the side length of the square. In the case of rectangular ROIs
the detector size corresponds the the length of the short side, as the long side remains unchanged. \n
shutter type - The electronic shutter that determines the way in which photons are captured and then read out
of the detector. Can be either Rolling or Global. \n
detector type - The classification of the detector. Either EMCCD or some form of CMOS camera. \n
quantum efficiency - The quantum efficiency of the detector calculated based on taking a weighted average
of the QE curves given in documentation with the weights being the transmission ratios of the filters
U, B, V, R, and I. \n
Parameters
----------
detector_grid : Grid
The grid on which the detector samples.
filter : string
A letter indicating the filter from UBVRI. Relevant for computing the quantum efficiency.
subsampling : integer or scalar or ndarray
The number of subpixels per pixel along one axis. For example, a
value of 2 indicates that 2x2=4 subpixels are used per pixel. If
this is a scalar, it will be rounded to the nearest integer. If
this is an array, the subsampling factor will be different for
each dimension. Default: 1.
'''
def __init__(self, detector_grid, filter, subsampling=1):
NoisyDetector.__init__(self, detector_grid, subsampling)
# Setting the start charge level.
self.accumulated_charge = 0
# The parameters.
self.dark_current_rate = 0.7
self.read_noise = 1.6
self.flat_field = 0
self.include_photon_noise = True
self.max_fps = 24
self.detector_size = 2048
self.shutter_type = 'Rolling'
self.detector_type = "sCMOS"
self.number_of_subdivisions = 32
# Set Quantum Efficiency based on filter
if filter == 'U' or filter == 'u':
self.QE = 0.439
elif filter == 'B' or filter == 'b':
self.QE = 0.782
elif filter == 'V' or filter == 'v':
self.QE = 0.941
elif filter == 'R' or filter == 'r':
self.QE = 0.813
elif filter == 'I' or filter == 'i':
self.QE = 0.424
else:
raise ValueError("Error, invalid filter name.")
def integrate(self, wavefront, dt, weight=1):
'''Integrates the detector.
Identical to the integrate funcion of NoisyDetector except includes loss due to Quantum Efficiency.
Parameters
----------
wavefront : Wavefront or array_like
The wavefront sets the amount of power generated per unit time.
dt : scalar
The integration time in units of time.
weight : scalar
Weight of every unit of integration time.
'''
# The power that the detector detects during the integration.
if hasattr(wavefront, 'power'):
power = wavefront.power
else:
power = wavefront
self.accumulated_charge += self.QE*subsample_field(power, subsampling=self.subsamping, new_grid=self.detector_grid, statistic='sum') * dt * weight
# Adding the generated dark current.
self.accumulated_charge += self.dark_current_rate * dt * weight
def roll_shutter(self, wavefronts, layer, prop, exposure_time):
'''Simulates a rolling shutter.
A combination of integrate and read_out that simulates the effects of a rolling shutter.
Parameters
----------
wavefront : Wavefront or array_like
The wavefront sets the amount of power generated per unit time.
layer: Atmospheric layer
The atmospheric layer
prop: Propagator
The propagator for the shutter
exposure_time: Scalar
The total exposure time in seconds
Returns
----------
Field.shaped
The final shaped detector image.
'''
number_of_rows = int(np.sqrt(self.detector_grid.size))
row_readout_time = 1/(self.max_fps*number_of_rows)
row_differential_time = row_readout_time*number_of_rows/self.number_of_subdivisions
layer.t += exposure_time-(row_differential_time*self.number_of_subdivisions)
for k in wavefronts:
self.integrate(prop((layer(k))),exposure_time-(row_differential_time*self.number_of_subdivisions))
read_noise_temp = self.read_noise
self.read_noise = 0 # Prevent double counting of the read noise when reading out the detector twice.
image_comb = self.read_out()
for j in range(self.number_of_subdivisions):
layer.t += row_differential_time
for k in wavefronts:
self.integrate(prop((layer(k))),row_differential_time)
self.read_noise = read_noise_temp
image_row = self.read_out()
start = int(self.detector_grid.size*(j)/self.number_of_subdivisions)
end = int(self.detector_grid.size*((j+1)/self.number_of_subdivisions))
image_comb[start:end]+=image_row[start:end]
return image_comb.shaped
class Kinetix(NoisyDetector):
'''A subclass of NoisyDetector class based on the Kinetix.\n
Details can be found at: \n
https://www.photometrics.com/wp-content/uploads/2019/10/Kinetix-Datasheet-Rev-A2-060082021.pdf \n
The parameters of this detector have been hardcoded into the subclass based on values drawn from
brochures and user manuals. These parameters include:\n
dark current rate - found in documentation \n
read noise - found in documentation (Note that when a range of read noises was given in the documentation,
the MAXIMUM read noise was always choosen. Read Noise generally increases as a function of frame rate
and given the speckle applications of this project, we presumed that the maximum frame rate was desired.
Presuming the maximum frame rate lead to the choice of the maximum read noise.)
flat field - presumed to be zero \n
include photon noise - presumed to be true \n
max fps - The maximum FPS at the size most relevant to the VIPER Project. \n
detector size - The size of the short length of the detector. Many detectors can have their regions of
interest reduced in order to increase frame rate. Some detectors reduce ROI into smaller sqaures
while others reduce ROI into rows with max length but reduced height. In the case of square ROIs
the detector size corresponds to the side length of the square. In the case of rectangular ROIs
the detector size corresponds the the length of the short side, as the long side remains unchanged. \n
shutter type - The electronic shutter that determines the way in which photons are captured and then read out
of the detector. Can be either Rolling or Global. \n
detector type - The classification of the detector. Either EMCCD or some form of CMOS camera. \n
quantum efficiency - The quantum efficiency of the detector calculated based on taking a weighted average
of the QE curves given in documentation with the weights being the transmission ratios of the filters
U, B, V, R, and I. \n
Parameters
----------
detector_grid : Grid
The grid on which the detector samples.
filter : string
A letter indicating the filter from UBVRI. Relevant for computing the quantum efficiency.
subsampling : integer or scalar or ndarray
The number of subpixels per pixel along one axis. For example, a
value of 2 indicates that 2x2=4 subpixels are used per pixel. If
this is a scalar, it will be rounded to the nearest integer. If
this is an array, the subsampling factor will be different for
each dimension. Default: 1.
'''
def __init__(self, detector_grid, filter, subsampling=1):
NoisyDetector.__init__(self, detector_grid, subsampling)
# Setting the start charge level.
self.accumulated_charge = 0
# The parameters.
self.dark_current_rate = 1.27
self.read_noise = 1.2
self.flat_field = 0
self.include_photon_noise = True
self.max_fps = 166
self.detector_size = 1500
self.shutter_type = 'Rolling'
self.detector_type = "sCMOS"
self.number_of_subdivisions = 32
# Set Quantum Efficiency based on filter
if filter == 'U' or filter == 'u':
self.QE = 0.427
elif filter == 'B' or filter == 'b':
self.QE = 0.797
elif filter == 'V' or filter == 'v':
self.QE = 0.946
elif filter == 'R' or filter == 'r':
self.QE = 0.859
elif filter == 'I' or filter == 'i':
self.QE = 0.503
else:
raise ValueError("Error, invalid filter name.")
def integrate(self, wavefront, dt, weight=1):
'''Integrates the detector.
Identical to the integrate funcion of NoisyDetector except includes loss due to Quantum Efficiency.
Parameters
----------
wavefront : Wavefront or array_like
The wavefront sets the amount of power generated per unit time.
dt : scalar
The integration time in units of time.
weight : scalar
Weight of every unit of integration time.
'''
# The power that the detector detects during the integration.
if hasattr(wavefront, 'power'):
power = wavefront.power
else:
power = wavefront
self.accumulated_charge += self.QE*subsample_field(power, subsampling=self.subsamping, new_grid=self.detector_grid, statistic='sum') * dt * weight
# Adding the generated dark current.
self.accumulated_charge += self.dark_current_rate * dt * weight
def roll_shutter(self, wavefronts, layer, prop, exposure_time):
'''Simulates a rolling shutter.
A combination of integrate and read_out that simulates the effects of a rolling shutter.
Parameters
----------
wavefront : Wavefront or array_like
The wavefront sets the amount of power generated per unit time.
layer: Atmospheric layer
The atmospheric layer
prop: Propagator
The propagator for the shutter
exposure_time: Scalar
The total exposure time in seconds
Returns
----------
Field.shaped
The final shaped detector image.
'''
number_of_rows = int(np.sqrt(self.detector_grid.size))
row_readout_time = 1/(self.max_fps*number_of_rows)
row_differential_time = row_readout_time*number_of_rows/self.number_of_subdivisions
layer.t += exposure_time-(row_differential_time*self.number_of_subdivisions)
for k in wavefronts:
self.integrate(prop((layer(k))),exposure_time-(row_differential_time*self.number_of_subdivisions))
read_noise_temp = self.read_noise
self.read_noise = 0 # Prevent double counting of the read noise when reading out the detector twice.
image_comb = self.read_out()
for j in range(self.number_of_subdivisions):
layer.t += row_differential_time
for k in wavefronts:
self.integrate(prop((layer(k))),row_differential_time)
self.read_noise = read_noise_temp
image_row = self.read_out()
start = int(self.detector_grid.size*(j)/self.number_of_subdivisions)
end = int(self.detector_grid.size*((j+1)/self.number_of_subdivisions))
image_comb[start:end]+=image_row[start:end]
return image_comb.shaped
class Prime_BSI(NoisyDetector):
'''A subclass of NoisyDetector class based on the Prime BSI.\n
Details can be found at: \n
https://www.photometrics.com/wp-content/uploads/2019/10/PrimeBSI-Datasheet_Rev_A4_-07312020.pdf \n
The parameters of this detector have been hardcoded into the subclass based on values drawn from
brochures and user manuals. These parameters include:\n
dark current rate - found in documentation \n
read noise - found in documentation (Note that when a range of read noises was given in the documentation,
the MAXIMUM read noise was always choosen. Read Noise generally increases as a function of frame rate
and given the speckle applications of this project, we presumed that the maximum frame rate was desired.
Presuming the maximum frame rate lead to the choice of the maximum read noise.)
flat field - presumed to be zero \n
include photon noise - presumed to be true \n
max fps - The maximum FPS at the size most relevant to the VIPER Project. \n
detector size - The size of the short length of the detector. Many detectors can have their regions of
interest reduced in order to increase frame rate. Some detectors reduce ROI into smaller sqaures
while others reduce ROI into rows with max length but reduced height. In the case of square ROIs
the detector size corresponds to the side length of the square. In the case of rectangular ROIs
the detector size corresponds the the length of the short side, as the long side remains unchanged. \n
shutter type - The electronic shutter that determines the way in which photons are captured and then read out
of the detector. Can be either Rolling or Global. \n
detector type - The classification of the detector. Either EMCCD or some form of CMOS camera. \n
quantum efficiency - The quantum efficiency of the detector calculated based on taking a weighted average
of the QE curves given in documentation with the weights being the transmission ratios of the filters
U, B, V, R, and I. \n
Parameters
----------
detector_grid : Grid
The grid on which the detector samples.
filter : string
A letter indicating the filter from UBVRI. Relevant for computing the quantum efficiency.
subsampling : integer or scalar or ndarray
The number of subpixels per pixel along one axis. For example, a
value of 2 indicates that 2x2=4 subpixels are used per pixel. If
this is a scalar, it will be rounded to the nearest integer. If
this is an array, the subsampling factor will be different for
each dimension. Default: 1.
'''
def __init__(self, detector_grid, filter, subsampling=1):
NoisyDetector.__init__(self, detector_grid, subsampling)
# Setting the start charge level.
self.accumulated_charge = 0
# The parameters.
self.dark_current_rate = 0.12
self.read_noise = 1.1
self.flat_field = 0
self.include_photon_noise = True
self.max_fps = 173
self.detector_size = 512
self.shutter_type = 'Rolling'
self.detector_type = "sCMOS"
self.number_of_subdivisions = 32
# Set Quantum Efficiency based on filter
if filter == 'U' or filter == 'u':
self.QE = 0.436
elif filter == 'B' or filter == 'b':
self.QE = 0.781
elif filter == 'V' or filter == 'v':
self.QE = 0.936
elif filter == 'R' or filter == 'r':
self.QE = 0.814
elif filter == 'I' or filter == 'i':
self.QE = 0.437
else:
raise ValueError("Error, invalid filter name.")
def integrate(self, wavefront, dt, weight=1):
'''Integrates the detector.
Identical to the integrate funcion of NoisyDetector except includes loss due to Quantum Efficiency.
Parameters
----------
wavefront : Wavefront or array_like
The wavefront sets the amount of power generated per unit time.
dt : scalar
The integration time in units of time.
weight : scalar
Weight of every unit of integration time.
'''
# The power that the detector detects during the integration.
if hasattr(wavefront, 'power'):
power = wavefront.power
else:
power = wavefront
self.accumulated_charge += self.QE*subsample_field(power, subsampling=self.subsamping, new_grid=self.detector_grid, statistic='sum') * dt * weight
# Adding the generated dark current.
self.accumulated_charge += self.dark_current_rate * dt * weight
def roll_shutter(self, wavefronts, layer, prop, exposure_time):
'''Simulates a rolling shutter.
A combination of integrate and read_out that simulates the effects of a rolling shutter.
Parameters
----------
wavefront : Wavefront or array_like
The wavefront sets the amount of power generated per unit time.
layer: Atmospheric layer
The atmospheric layer
prop: Propagator
The propagator for the shutter
exposure_time: Scalar
The total exposure time in seconds
Returns
----------
Field.shaped
The final shaped detector image.
'''
number_of_rows = int(np.sqrt(self.detector_grid.size))
row_readout_time = 1/(self.max_fps*number_of_rows)
row_differential_time = row_readout_time*number_of_rows/self.number_of_subdivisions
layer.t += exposure_time-(row_differential_time*self.number_of_subdivisions)
for k in wavefronts:
self.integrate(prop((layer(k))),exposure_time-(row_differential_time*self.number_of_subdivisions))
read_noise_temp = self.read_noise
self.read_noise = 0 # Prevent double counting of the read noise when reading out the detector twice.
image_comb = self.read_out()
for j in range(self.number_of_subdivisions):
layer.t += row_differential_time
for k in wavefronts:
self.integrate(prop((layer(k))),row_differential_time)
self.read_noise = read_noise_temp
image_row = self.read_out()
start = int(self.detector_grid.size*(j)/self.number_of_subdivisions)
end = int(self.detector_grid.size*((j+1)/self.number_of_subdivisions))
image_comb[start:end]+=image_row[start:end]
return image_comb.shaped
class Test_Global_50FPS(NoisyDetector):
'''A subclass of NoisyDetector. Used to test the rolling vs global shutter question.\n
Parameters based off the ProEM®-HS:512BX3\n
Parameters
----------
detector_grid : Grid
The grid on which the detector samples.
filter : string
A letter indicating the filter from UBVRI. Relevant for computing the quantum efficiency.
subsampling : integer or scalar or ndarray
The number of subpixels per pixel along one axis. For example, a
value of 2 indicates that 2x2=4 subpixels are used per pixel. If
this is a scalar, it will be rounded to the nearest integer. If
this is an array, the subsampling factor will be different for
each dimension. Default: 1.
'''
def __init__(self, detector_grid, filter, EM_gain = 1, EM_saturate = None , subsampling=1):
NoisyDetector.__init__(self, detector_grid, subsampling)
# Setting the start charge level.
self.accumulated_charge = 0
# The parameters.
self.dark_current_rate = 0.001
self.read_noise = 0.125
self.flat_field = 0
self.include_photon_noise = True
self.max_fps = 50
self.detector_size = 512
self.shutter_type = 'Global'
self.detector_type = "Test"
# Set Quantum Efficiency based on filter
if filter == 'U' or filter == 'u':
self.QE = 0.494
elif filter == 'B' or filter == 'b':
self.QE = 0.795
elif filter == 'V' or filter == 'v':
self.QE = 0.902
elif filter == 'R' or filter == 'r':
self.QE = 0.894
elif filter == 'I' or filter == 'i':
self.QE = 0.499
else:
raise ValueError("Error, invalid filter name.")
def integrate(self, wavefront, dt, weight=1):
'''Integrates the detector.
Identical to the integrate funcion of NoisyDetector except loss due to Quantum Efficiency is included.
Parameters
----------
wavefront : Wavefront or array_like
The wavefront sets the amount of power generated per unit time.
dt : scalar
The integration time in units of time.
weight : scalar
Weight of every unit of integration time.
'''
# The power that the detector detects during the integration.
if hasattr(wavefront, 'power'):
power = wavefront.power
else:
power = wavefront
self.accumulated_charge += self.QE*subsample_field(power, subsampling=self.subsamping, new_grid=self.detector_grid, statistic='sum') * dt * weight
# Adding the generated dark current.
self.accumulated_charge += self.dark_current_rate * dt * weight
class Test_Rolling_50FPS(NoisyDetector):
'''A subclass of NoisyDetector. Used to test the rolling vs global shutter question.\n
Parameters based off the ProEM®-HS:512BX3\n
Parameters
----------
detector_grid : Grid
The grid on which the detector samples.
filter : string