-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSBAccess.py
More file actions
4317 lines (3388 loc) · 127 KB
/
SBAccess.py
File metadata and controls
4317 lines (3388 loc) · 127 KB
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
from __future__ import annotations
__copyright__ = "Copyright (c) 2022-2025, Intelligent Imaging Innovations, Inc. All rights reserved. All rights reserved."
__license__ = "This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree."
#Help obtained with the command:
#python -c "import SBAccess ; help(SBAccess)"
#check syntax with: pyflakes SBaccess.py
#Must set the right put to where CMetadataLib.py and Basedecode.py are
#import sys
#they are in the sandbox, or on github
#sys.path.append('C:/Users/Nicola Papp/Perforce/Nicola_MSI_552/dev/SB_7.0_BCG/SBReadFile/dist/Python/Format 7')
import io
from CMetadataLib import BaseDecoder
from CMetadataLib import CLensDef70
from CMetadataLib import CFluorDef70
from CMetadataLib import COptovarDef70
from enum import Enum
import yaml
from dataclasses import dataclass
import ByteUtil as bu
import numpy as np
@dataclass
class PointStruct:
x: float
y: float
z: float
aux_z: float
IsAuxZ: bool
class AuxDataTypes(Enum):
"""
Enumeration of auxiliary data types
"""
eXMLData = 0 # XML String data
eSInt32Data = 1 # Signed Int32 Data
eSInt64Data = 2 # Signed Int64 Data
eFloatData = 3 # float data (4 bytes)
eDoubleData = 4 # double float data (8 bytes)
class MicroscopeStates(Enum):
"""
Enumeration of microscope state codes used to represent various
hardware settings or readouts from a microscope control system.
"""
CurrentObjective = 1
"""Current objective lens in use."""
CurrentFilter = 2
"""Current filter in use."""
CurrentMagnification = 3
"""Current total magnification."""
CurrentLaserPower = 4
"""Current laser power setting."""
CurrentNDPrimary = 5
"""Current position of the primary neutral density (ND) filter."""
CurrentNDAux = 6
"""Current position of the auxiliary ND filter."""
CurrentLampVoltage = 7
"""Current lamp voltage level."""
CurrentFLshutter = 8
"""Current state of the fluorescence shutter (open/closed)."""
CurrentBFshutter = 9
"""Current state of the brightfield shutter (open/closed)."""
CurrentAltSource = 10
"""Current alternative illumination source."""
CurrentXYstagePosition = 11
"""Current XY stage coordinates."""
CurrentZstagePosition = 12
"""Current Z stage position."""
CurrentAltZstagePosition = 13
"""Current position of an alternate Z stage (if present)."""
CurrentCondenserPrismPosition = 14
"""Current position of the condenser prism."""
CurrentVideoOrCameraPosition = 15
"""Current position of the video/camera selector."""
CurrentCondenserAperture = 16
"""Current condenser aperture setting."""
CurrentBin = 17
"""Current camera binning setting."""
CurrentFilterSet = 18
"""Current active filter set."""
class MicroscopeHardwareComponent(Enum):
"""
Enumeration of direct microscope hardware components for low-level access
and control within microscope systems.
"""
ExcitationFilterWheel = 0 #:The excitation filter wheel component.
FilterTurret = 1 #:The filter turret (e.g., for dichroics or filter sets).
EmissionFilterWheel = 2
"""The emission filter wheel component."""
FluorescenceShutter = 3
"""Shutter controlling the fluorescence light path."""
BrightfieldShutter = 4
"""Shutter controlling the brightfield light path."""
BrightfieldLamp = 5
"""The brightfield illumination source."""
LCDFilter = 6
"""LCD-based filter or attenuator component."""
XYStage = 7
"""Motorized XY stage."""
ZStage = 8
"""Primary motorized Z-axis stage."""
ObjectiveTurret = 9
"""Turret for switching microscope objectives."""
OptovarTurret = 10
"""Optovar turret for magnification adjustment."""
OcularPhotoPrism = 11
"""Selector between ocular and photo/camera paths."""
CameraVideoPrism = 12
"""Prism directing light to camera or video system."""
AltSourceSelection = 13
"""Selector for alternate illumination sources."""
FluorescenceLamp = 14
"""Main fluorescence lamp (e.g., mercury or LED)."""
AuxZStage = 15
"""Auxiliary Z-axis stage."""
AuxFluorescenceLamp = 16
"""Secondary fluorescence lamp."""
AuxFilterWheel = 17
"""First auxiliary filter wheel."""
AuxFilterWheel2 = 18
"""Second auxiliary filter wheel."""
AuxFilterWheel3 = 19
"""Third auxiliary filter wheel."""
LaserAblationDevice = 20
"""Laser ablation or photoactivation system."""
SACorrection = 21
"""Spherical aberration correction mechanism."""
ReuseThisPosition = 22
"""Special placeholder for reusing previous hardware positions."""
AuxFilterWheel4 = 23
"""Fourth auxiliary filter wheel."""
TIRFSlider = 24
"""Total internal reflection fluorescence (TIRF) slider."""
LaserPowerControl = 25
"""Laser power control module."""
AdaptiveOptics = 26
"""Adaptive optics component for wavefront correction."""
BeamExpander = 27
"""Optical beam expander system."""
AuxFilterWheel5 = 28
"""Fifth auxiliary filter wheel."""
AuxFilterWheel6 = 29
"""Sixth auxiliary filter wheel."""
IncubatorControl = 30
"""Environmental control system (e.g., incubator)."""
LaserTemperatureControl = 31
"""Laser temperature stabilization or monitoring module."""
LaserPowerMeter = 32
"""First laser power meter."""
Lightsheet = 33
"""Lightsheet illumination system."""
AuxFilterWheel7 = 34
"""Seventh auxiliary filter wheel."""
LaserPowerMeter2 = 35
"""Second laser power meter."""
LaserPowerMeter3 = 36
"""Third laser power meter."""
LaserPowerMeter4 = 37
"""Fourth laser power meter."""
AuxFilterWheel8 = 41
"""Eighth auxiliary filter wheel."""
AuxFilterWheel9 = 42
"""Ninth auxiliary filter wheel."""
AuxFilterWheel10 = 43
"""Tenth auxiliary filter wheel."""
PMTController1 = 44
"""First photomultiplier tube (PMT) controller."""
PMTController2 = 45
"""Second PMT controller."""
PMTController3 = 46
"""Third PMT controller."""
class SequentialCaptureMode(Enum):
"""
Enumeration of 6D Multicapture modes
"""
Sequential = 0
"""Sequential (standard)."""
SequentialFreeRun = 1
"""Sequential (free run)"""
SequentialTriggered = 2
"""Sequential (triggerd)"""
SequentialDirectToDisk = 3
"""Sequential (direct to disk)"""
#: Descriptions for each MicroscopeHardwareComponent enum member.
descriptions = {
MicroscopeHardwareComponent.ExcitationFilterWheel: "The excitation filter wheel component.",
MicroscopeHardwareComponent.FilterTurret: "The filter turret (e.g., for dichroics or filter sets).",
MicroscopeHardwareComponent.EmissionFilterWheel: "The emission filter wheel component.",
MicroscopeHardwareComponent.FluorescenceShutter: "Shutter controlling the fluorescence light path.",
MicroscopeHardwareComponent.BrightfieldShutter: "Shutter controlling the brightfield light path.",
MicroscopeHardwareComponent.BrightfieldLamp: "The brightfield illumination source.",
MicroscopeHardwareComponent.LCDFilter: "LCD-based filter or attenuator component.",
MicroscopeHardwareComponent.XYStage: "Motorized XY stage.",
MicroscopeHardwareComponent.ZStage: "Primary motorized Z-axis stage.",
MicroscopeHardwareComponent.ObjectiveTurret: "Turret for switching microscope objectives.",
MicroscopeHardwareComponent.OptovarTurret: "Optovar turret for magnification adjustment.",
MicroscopeHardwareComponent.OcularPhotoPrism: "Selector between ocular and photo/camera paths.",
MicroscopeHardwareComponent.CameraVideoPrism: "Prism directing light to camera or video system.",
MicroscopeHardwareComponent.AltSourceSelection: "Selector for alternate illumination sources.",
MicroscopeHardwareComponent.FluorescenceLamp: "Main fluorescence lamp (e.g., mercury or LED).",
MicroscopeHardwareComponent.AuxZStage: "Auxiliary Z-axis stage.",
MicroscopeHardwareComponent.AuxFluorescenceLamp: "Secondary fluorescence lamp.",
MicroscopeHardwareComponent.AuxFilterWheel: "First auxiliary filter wheel.",
MicroscopeHardwareComponent.AuxFilterWheel2: "Second auxiliary filter wheel.",
MicroscopeHardwareComponent.AuxFilterWheel3: "Third auxiliary filter wheel.",
MicroscopeHardwareComponent.LaserAblationDevice: "Laser ablation or photoactivation system.",
MicroscopeHardwareComponent.SACorrection: "Spherical aberration correction mechanism.",
MicroscopeHardwareComponent.ReuseThisPosition: "Special placeholder for reusing previous hardware positions.",
MicroscopeHardwareComponent.AuxFilterWheel4: "Fourth auxiliary filter wheel.",
MicroscopeHardwareComponent.TIRFSlider: "Total internal reflection fluorescence (TIRF) slider.",
MicroscopeHardwareComponent.LaserPowerControl: "Laser power control module.",
MicroscopeHardwareComponent.AdaptiveOptics: "Adaptive optics component for wavefront correction.",
MicroscopeHardwareComponent.BeamExpander: "Optical beam expander system.",
MicroscopeHardwareComponent.AuxFilterWheel5: "Fifth auxiliary filter wheel.",
MicroscopeHardwareComponent.AuxFilterWheel6: "Sixth auxiliary filter wheel.",
MicroscopeHardwareComponent.IncubatorControl: "Environmental control system (e.g., incubator).",
MicroscopeHardwareComponent.LaserTemperatureControl: "Laser temperature stabilization or monitoring module.",
MicroscopeHardwareComponent.LaserPowerMeter: "First laser power meter.",
MicroscopeHardwareComponent.Lightsheet: "Lightsheet illumination system.",
MicroscopeHardwareComponent.AuxFilterWheel7: "Seventh auxiliary filter wheel.",
MicroscopeHardwareComponent.LaserPowerMeter2: "Second laser power meter.",
MicroscopeHardwareComponent.LaserPowerMeter3: "Third laser power meter.",
MicroscopeHardwareComponent.LaserPowerMeter4: "Fourth laser power meter.",
MicroscopeHardwareComponent.AuxFilterWheel8: "Eighth auxiliary filter wheel.",
MicroscopeHardwareComponent.AuxFilterWheel9: "Ninth auxiliary filter wheel.",
MicroscopeHardwareComponent.AuxFilterWheel10: "Tenth auxiliary filter wheel.",
MicroscopeHardwareComponent.PMTController1: "First photomultiplier tube (PMT) controller.",
MicroscopeHardwareComponent.PMTController2: "Second PMT controller.",
MicroscopeHardwareComponent.PMTController3: "Third PMT controller.",
}
class SBAccess(object):
""" A Class to Read Slide Book Format 7 Files """
# All access functions as in SBReadFile.h
def __init__(self, inSocket):
self.mSocket = inSocket
def SendCommand(self,inCommand):
theBytes = bu.string_to_bytes(inCommand)
self.mSocket.send(theBytes)
def SendVal(self,inVal,inType):
theBytes = bu.type_to_bytes(inVal,inType)
self.mSocket.send(theBytes)
def mysend(self, inBytes):
totalsent = 0
MSGLEN = len(inBytes)
while totalsent < MSGLEN:
sent = self.mSocket.send(inBytes[totalsent:])
#print("sent: ",sent)
if sent == 0:
raise Exception("Socket connection broken, unable to send")
totalsent = totalsent + sent
#print("totalsent: ",totalsent)
def SendByteArray(self,inBytes):
#self.mSocket.send(inBytes)
self.mysend(inBytes)
def RecvBigData(self,n):
# Helper function to recv n bytes or return None if EOF is hit
data = bytearray()
while len(data) < n:
packet = self.mSocket.recv(n - len(data))
if not packet:
return None
data.extend(packet)
return data
def Recv(self):
theRecvBuf = b''
b = self.mSocket.recv(1)
if b != b'&':
raise Exception("First character in answer must be a: &")
while True:
b = self.mSocket.recv(1)
if b == b'(':
continue
if b == b')':
break
theRecvBuf += bytes(b)
# parse the string
str = bu.bytes_to_string(theRecvBuf)
#print("str is: ",str)
#split in list of arguments
largs = str.split(',')
#receive all the largs
if(len(largs) != 1):
raise Exception("Can only receive n values of same type")
arg = largs[0]
#split is size and format
prop = arg.split(":")
if(len(prop) != 2):
raise Exception("Invalid argument format: " + str)
theNum = int(prop[0])
theType = prop[1]
theSize = 1
if (theType == 'i4' or theType == 'u4' or theType == 'f4'):
theSize = 4
elif (theType == 'i2' or theType == 'u2'):
theSize = 2
elif (theType == 'i8' or theType == 'u8' or theType == 'f8'):
theSize = 8
theValBuf = b''
theValBuf = self.RecvBigData(theNum * theSize)
#print('theValBuf is: ',theValBuf)
if(len(theValBuf) != theNum * theSize):
raise Exception("Did not receive enough data")
if theType == 's':
theStr = bu.bytes_to_string(theValBuf)
return theStr
else:
theArr = bu.bytes_to_type(theValBuf,theType)
return theNum,theArr
def SendIntParam(self,inCommandName,inIntParam):
self.SendCommand('$'+inCommandName+'(IntParam=i4)')
self.SendVal(int(inIntParam),'i4')
theNum,theVals = self.Recv()
if( theNum != 1 and theVals[0] != 1):
raise Exception(inCommandName+': error')
return theVals[0]
def SendFloatParam(self,inCommandName,inFloatParam):
self.SendCommand('$'+inCommandName+'(FloatParam=f4)')
self.SendVal(float(inFloatParam),'f4')
theNum,theVals = self.Recv()
if( theNum != 1 and theVals[0] != 1):
raise Exception(inCommandName+': error')
return theVals[0]
def SendStringParam(self,inCommandName,inStringParam):
l = len(inStringParam)
self.SendCommand('$'+inCommandName+'(StringParam='+str(l)+':s)')
self.SendVal(inStringParam,'s')
theNum,theVals = self.Recv()
if( theNum != 1 or theVals[0] == -1):
raise Exception(inCommandName+': error')
return theVals[0]
def SendNullParam(self,inCommandName):
self.SendCommand('$'+inCommandName+'()')
theNum,theVals = self.Recv()
if( theNum != 1 and theVals[0] != 1):
raise Exception(inCommandName+': error')
return theVals[0]
def Open(self,inPath):
"""Open a SlideBook file and loads the Metadata
Parameters
----------
inPath : str
The path of the SlideBook file to open
Returns
-------
int
The Slide Id
"""
l = len(inPath)
self.SendCommand('$Open(FileName='+str(l)+':s)')
self.SendVal(inPath,'s')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("OpenFile: colud not open path: "+inPath)
return theVals[0]
def GetCurrentSlideId(self):
"""Gets the Slide Id of the active slide
Parameters
----------
none
Returns
-------
int
The Slide Id
"""
self.SendCommand('$GetCurrentSlideId()')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetCurrentSlideId: error")
return theVals[0]
def GetOpenSlides(self):
"""Gets a dictionary of Slide Id vs Pathname of all open slides
Parameters
----------
none
Returns
-------
dict
The dictionary of IDs/SlideName(Pathname)
"""
self.SendCommand('$GetOpenSlides()')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetOpenSlides: error")
theDict = dict()
for id in range(theVals[0]):
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetOpenSlides: error")
theId = theVals[0]
thePath = self.Recv()
theDict[int(theId)]= thePath
return dict(sorted(theDict.items()))
def SetTargetSlide(self,inSlideId):
"""Sets the target slide for subsequent operations
Parameters
----------
int
The Slide Id
Returns
-------
int
1 on success
"""
self.SendCommand('$SetTargetSlide(SlideId=i4)')
self.SendVal(int(inSlideId),'i4')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("SetTargetSlide: invalid value")
if( theVals[0] != 1):
raise Exception("SetTargetSlide: failed")
return
def CreateNewSlide(self):
"""Creates a new Slide
Returns
-------
int
The Slide Id
"""
self.SendCommand('$CreateNewSlide()')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("CreateNewSlide: error")
return theVals[0]
def CloseSlide(self,inSlideId,inSaveChanges):
"""Close a slide
Parameters
----------
inSlideId : int
The Slide Id
inSaveChanges
If the slide has been modified, save changes?
Returns
-------
int
True if successful and false if failure (failure to save is most commonly caused by a new file without a pathname)
"""
self.SendCommand('$CloseSlide(SlideId=i4,SaveChanges=i4)')
self.SendVal(int(inSlideId),'i4')
self.SendVal(int(inSaveChanges),'i4')
theNum,theStatus = self.Recv()
if( theNum != 1):
raise Exception("SaveSlide: invalid statuc")
return theStatus[0]
def GetIsSlideModified(self, inSlideId):
"""Get modified status of slide
Parameters
----------
inSlideId : int
The Slide Id
Returns
-------
bool
True if file has been modified since last save, false if the file has not been modified
int
True if successful and false if failure
"""
self.SendCommand('$GetIsSlideModified(SlideId=i4)')
self.SendVal(int(inSlideId), 'i4')
theNum, theStatus = self.Recv()
if (theNum != 1):
raise Exception("SaveSlide: invalid status")
theNum, theReturn = self.Recv()
if (theNum != 1):
raise Exception("SaveSlide: invalid return")
return theStatus[0], theReturn[0]
def SaveSlide(self,inSlideId):
"""Saves a slide
Parameters
----------
inSlideId : int
The Slide Id
Returns
-------
int
1 on success
"""
self.SendCommand('$SaveSlide(SlideId=i4)')
self.SendVal(int(inSlideId),'i4')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("SaveSlide: invalid value")
if( theVals[0] != 1):
raise Exception("SaveSlide: failed")
return
def SaveAsSlide(self,inSlideId,inPathname):
"""Saves a slide
Parameters
----------
inSlideId : int
The Slide Id
inPathname : str
The pathname to save the slide with
Returns
-------
int
1 on success
"""
l = len(inPathname)
self.SendCommand('$SaveAsSlide(SlideId=i4,Pathname='+str(l)+':s)')
self.SendVal(int(inSlideId),'i4')
self.SendVal(inPathname,'s')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("SaveAsSlide: invalid value")
if( theVals[0] != 1):
raise Exception("SaveAsSlide: failed")
return
def GetNumCaptures(self):
""" Gets the number of captures (image groups) in the file
Returns
-------
int
The number of captures
"""
self.SendCommand('$GetNumCaptures()')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetNumCaptures: invalid value")
print("GetNumCaptures: ",theVals[0])
return theVals[0]
def GetNumLiveCaptures(self):
""" Gets the number of live captures (image groups) in the file
Returns
-------
int
The number of live captures
"""
self.SendCommand('$GetNumLiveCaptures()')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetNumLiveCaptures: invalid value")
print("GetNumLiveCaptures: ",theVals[0])
return theVals[0]
def GetNumMasks(self,inCaptureIndex):
""" Gets the number of masks in an image group
Parameters
----------
inCaptureIndex: int
The index of the image group. Must be in range(0,number of captures)
Returns
-------
int
The number of masks
"""
self.SendCommand('$GetNumMasks(CaptureIndex=i4)')
self.SendVal(int(inCaptureIndex),'i4')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetNumMasks: invalid value")
return theVals[0]
def GetNumPositions(self,inCaptureIndex):
""" Gets the number of (montage) positions in an image group
Parameters
----------
inCaptureIndex: int
The index of the image group. Must be in range(0,number of captures)
Returns
-------
int
The number of positions
"""
self.SendCommand('$GetNumPositions(CaptureIndex=i4)')
self.SendVal(int(inCaptureIndex),'i4')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetNumPositions: invalid value")
return theVals[0]
def GetNumXColumns(self,inCaptureIndex):
""" Gets the number of columns (width) of an image in an image group
Parameters
----------
inCaptureIndex: int
The index of the image group. Must be in range(0,number of captures)
Returns
-------
int
The number of columns or width of the image
"""
self.SendCommand('$GetNumXColumns(CaptureIndex=i4)')
self.SendVal(int(inCaptureIndex),'i4')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetNumXColumns: invalid value")
print("GetNumXColumns: ",theVals[0])
return theVals[0]
def GetNumYRows(self,inCaptureIndex):
""" Gets the number of rows (height) of an image in an image group
Parameters
----------
inCaptureIndex: int
The index of the image group. Must be in range(0,number of captures)
Returns
-------
int
The number of rows or height of the image
"""
self.SendCommand('$GetNumYRows(CaptureIndex=i4)')
self.SendVal(int(inCaptureIndex),'i4')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetNumYRows: invalid value")
print("GetNumYRows: ",theVals[0])
return theVals[0]
def GetNumZPlanes(self,inCaptureIndex):
""" Gets the number of z planes of an image in an image group
Parameters
----------
inCaptureIndex: int
The index of the image group. Must be in range(0,number of captures)
Returns
-------
int
The number of z planes of the image
"""
self.SendCommand('$GetNumZPlanes(CaptureIndex=i4)')
self.SendVal(int(inCaptureIndex),'i4')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetNumZPlanes: invalid value")
print("GetNumZPlanes: ",theVals[0])
return theVals[0]
def GetNumImages(self,inCaptureIndex):
""" Gets the number of images in an image group
Parameters
----------
inCaptureIndex: int
The index of the image group. Must be in range(0,number of captures)
Returns
-------
int
The number of images
"""
version = self.GetAPIVersion()
if (version < 47415):
raise Exception("GetNumImages: not available in current API")
self.SendCommand('$GetNumImages(CaptureIndex=i4)')
self.SendVal(int(inCaptureIndex),'i4')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetNumImages: invalid value")
return theVals[0]
def GetNumTimepoints(self,inCaptureIndex):
""" Gets the number of time points in an image group
Parameters
----------
inCaptureIndex: int
The index of the image group. Must be in range(0,number of captures)
Returns
-------
int
The number of time points
"""
self.SendCommand('$GetNumTimepoints(CaptureIndex=i4)')
self.SendVal(int(inCaptureIndex),'i4')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetNumTimepoints: invalid value")
return theVals[0]
def GetNumChannels(self,inCaptureIndex):
""" Gets the number of channels in an image group
Parameters
----------
inCaptureIndex: int
The index of the image group. Must be in range(0,number of captures)
Returns
-------
int
The number of channels
"""
self.SendCommand('$GetNumChannels(CaptureIndex=i4)')
self.SendVal(int(inCaptureIndex),'i4')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetNumChannels: invalid value")
return theVals[0]
def GetExposureTime(self,inCaptureIndex,inChannelIndex):
""" Gets the exposure time in ms for a particular channel of an image group
Parameters
----------
inCaptureIndex: int
The index of the image group. Must be in range(0,number of captures)
inChannelIndex: int
The index of the channel. Must be in range(0,number of channels)
Returns
-------
int
The exposure time in ms
"""
self.SendCommand('$GetExposureTime(CaptureIndex=i4,ChannelIndex=i4)')
self.SendVal(int(inCaptureIndex),'i4')
self.SendVal(int(inChannelIndex),'i4')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetExposureTime: invalid value")
return theVals[0]
def GetVoxelSize(self,inCaptureIndex):
""" Gets the voxel size in microns of an image group
Parameters
----------
inCaptureIndex: int
The index of the image group. Must be in range(0,number of captures)
Returns
-------
float
The X voxel size in um
float
The Y voxel size in um
float
The Z voxel size in um
"""
self.SendCommand('$GetVoxelSize(CaptureIndex=i4)')
self.SendVal(int(inCaptureIndex),'i4')
theNum,theVoxelX = self.Recv()
if( theNum != 1):
raise Exception("GetVoxelSize: invalid value")
theNum,theVoxelY = self.Recv()
if( theNum != 1):
raise Exception("GetVoxelSize: invalid value")
theNum,theVoxelZ = self.Recv()
if( theNum != 1):
raise Exception("GetVoxelSize: invalid value")
return theVoxelX[0],theVoxelY[0],theVoxelZ[0]
def GetXPosition(self,inCaptureIndex,inPositionIndex):
""" Gets the X position in microns of the center of an image of an image group
Parameters
----------
inCaptureIndex: int
The index of the image group. Must be in range(0,number of captures)
inPositionIndex: int
The index of the image in the montage, or 0 if all images are at the same location
Returns
-------
float
The X position in um
"""
self.SendCommand('$GetXPosition(CaptureIndex=i4,PositionIndex=i4)')
self.SendVal(int(inCaptureIndex),'i4')
self.SendVal(int(inPositionIndex),'i4')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetXPosition: invalid value")
return theVals[0]
def GetYPosition(self,inCaptureIndex,inPositionIndex):
""" Gets the Y position in microns of the center of an image of an image group
Parameters
----------
inCaptureIndex: int
The index of the image group. Must be in range(0,number of captures)
inPositionIndex: int
The index of the image in the montage, or 0 if all images are at the same location
Returns
-------
float
The Y position in um
"""
self.SendCommand('$GetYPosition(CaptureIndex=i4,PositionIndex=i4)')
self.SendVal(int(inCaptureIndex),'i4')
self.SendVal(int(inPositionIndex),'i4')
theNum,theVals = self.Recv()
if( theNum != 1):
raise Exception("GetYPosition: invalid value")
return theVals[0]
def GetZPosition(self,inCaptureIndex,inPositionIndex,inZPlaneIndex):
""" Gets the Z position in microns of the center of an image of an image group
Parameters
----------
inCaptureIndex: int
The index of the image group. Must be in range(0,number of captures)
inPositionIndex: int
The index of the image in the montage, or 0 if all images are at the same location
Returns
-------
float