Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
beniroquai committed Mar 5, 2024
2 parents 5bb6c7c + 44cca1c commit d249c21
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
47 changes: 32 additions & 15 deletions imswitch/imcontrol/controller/controllers/MCTController.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def __init__(self, *args, **kwargs):
allDetectorNames = self._master.detectorsManager.getAllDeviceNames()
self.detector = self._master.detectorsManager[allDetectorNames[0]]
self.detectorWidth, self.detectorHeight = self.detector._camera.SensorWidth, self.detector._camera.SensorHeight
self.isRGB = self.detector._camera.isRGB
self.detectorPixelSize = self.detector.pixelSizeUm

# select lasers
Expand Down Expand Up @@ -104,13 +105,13 @@ def __init__(self, *args, **kwargs):
self._widget.mctShowLastButton.setEnabled(False)

# setup gui limits for sliders
if len(self.availableIlliminations) >= 0:
if len(self.availableIlliminations) == 1:
self._widget.sliderIllu1.setMaximum(self.availableIlliminations[0].valueRangeMax)
self._widget.sliderIllu1.setMinimum(self.availableIlliminations[0].valueRangeMin)
if len(self.availableIlliminations) >= 1:
if len(self.availableIlliminations) > 1:
self._widget.sliderIllu2.setMaximum(self.availableIlliminations[1].valueRangeMax)
self._widget.sliderIllu2.setMinimum(self.availableIlliminations[1].valueRangeMin)
if len(self.availableIlliminations) >= 2:
if len(self.availableIlliminations) > 2:
self._widget.sliderIllu3.setMaximum(self.availableIlliminations[2].valueRangeMax)
self._widget.sliderIllu3.setMinimum(self.availableIlliminations[2].valueRangeMin)

Expand Down Expand Up @@ -269,7 +270,10 @@ def takeTimelapseThread(self, tperiod, nImagesToCapture,
yScanMin, yScanMax, yScanStep):
# this wil run in the background
self.timeLast = 0
nZStack = int(np.ceil((zStackMax-zStackMin)/zStackStep))
if zStackEnabled:
nZStack = int(np.ceil((zStackMax-zStackMin)/zStackStep))
else:
nZStack = 1
# get current position
if self.positioner is not None:
currentPositions = self.positioner.getPosition()
Expand All @@ -284,9 +288,14 @@ def takeTimelapseThread(self, tperiod, nImagesToCapture,
fileName = self.getSaveFilePath(date=MCTDate,
filename=MCTFilename,
extension=fileExtension)
init_dims = (1, len(self.activeIlluminations), nZStack, self.detectorWidth, self.detectorHeight) # time, channels, z, y, x
max_dims = (None, 3, nZStack, None, None) # Allow unlimited time points and z slices
self.h5File = HDF5File(filename=fileName, init_dims=init_dims, max_dims=max_dims)
if self.isRGB:
init_dims = (1, len(self.activeIlluminations), nZStack, self.detectorWidth, self.detectorHeight, 3) # time, channels, z, y, x, RGB
max_dims = (None, 3, nZStack, None, None, 3) # Allow unlimited time points and z slices
else:
init_dims = (1, len(self.activeIlluminations), nZStack, self.detectorWidth, self.detectorHeight) # time, channels, z, y, x
max_dims = (None, 3, nZStack, None, None) # Allow unlimited time points and z slices

self.h5File = HDF5File(filename=fileName, init_dims=init_dims, max_dims=max_dims, isRGB=self.isRGB)

# run as long as the MCT is active
while(self.isMCTrunning):
Expand Down Expand Up @@ -479,8 +488,15 @@ def acquireCZXYScan(self):
'''
allZStackFrames.append(allChannelFrames)


# ensure all illus are off
self.switchOffIllumination()

# save to HDF5
framesToSave = np.transpose(np.array(allZStackFrames), (1,0,2,3))
if self.isRGB:
framesToSave = np.transpose(np.array(allZStackFrames), (1,0,3,2,4)) # time, # todo check order!!
else:
framesToSave = np.transpose(np.array(allZStackFrames), (1,0,2,3)) # time,
self.h5File.append_data(self.nImagesTaken, framesToSave, np.array(allPositions))
del framesToSave

Expand Down Expand Up @@ -515,12 +531,9 @@ def acquireCZXYScan(self):
if self.zStackEnabled and self.positioner is not None:
self.positioner.move(value=(self.initialPositionZ), axis="Z", is_absolute=True, is_blocking=True)

# ensure all illus are off
#self.switchOffIllumination()

# disable motors to prevent overheating
if self.positioner is not None:
self._logger.debug("Setting enable to: "+str(self.positioner.is_enabled))
self.positioner.enalbeMotors(enable=self.positioner.is_enabled)

def switchOffIllumination(self):
Expand Down Expand Up @@ -608,16 +621,17 @@ def crop_center(self, image, size):


class HDF5File(object):
def __init__(self, filename, init_dims, max_dims=None):
def __init__(self, filename, init_dims, max_dims=None, isRGB=False):
self.filename = filename
self.init_dims = init_dims # time, channels, z, y, x
self.max_dims = max_dims # time, channels, z, y, x
self.isRGB=isRGB
self.create_dataset()

def create_dataset(self):
with h5py.File(self.filename, 'w') as file:
# Create a resizable dataset for the image data
dset = file.create_dataset('ImageData', shape=self.init_dims, maxshape=self.max_dims, dtype='float32', compression="gzip")
dset = file.create_dataset('ImageData', shape=self.init_dims, maxshape=self.max_dims, dtype='uint16', compression="gzip")

# Initialize a group for storing metadata
meta_group = file.create_group('Metadata')
Expand All @@ -632,11 +646,14 @@ def append_data(self, timepoint, frame_data, xyz_coordinates):
dset.resize(current_size + 1, axis=0)

# Add the new frame data
dset[current_size, :, :, :, :] = frame_data
if self.isRGB:
dset[current_size, :, :, :, :, :] = np.uint16(frame_data)
else:
dset[current_size, :, :, :, :] = np.uint16(frame_data)

# Add metadata for the new frame
for channel, xyz in enumerate(xyz_coordinates):
meta_group.create_dataset(f'Time_{timepoint}_Channel_{channel}', data=xyz)
meta_group.create_dataset(f'Time_{timepoint}_Channel_{channel}', data=np.float32(xyz))



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@ def __init__(self, LEDMatrixInfo, name, **lowLevelManagers):
self.__logger = initLogger(self, instanceName=name)
self.power = 0
self.I_max = 255
self.setEnabled = False
self.intensity=0
self.enabled = False

try:
self.Nx = LEDMatrixInfo.managerProperties['Nx']
self.Ny = LEDMatrixInfo.managerProperties['Ny']
except:
self.Nx = 8
self.Ny = 8

# extract the special patterns from the user defined file
try:
self.SpecialPattern1 = LEDMatrixInfo.managerProperties['SpecialPattern1']
self.SpecialPattern2 = LEDMatrixInfo.managerProperties['SpecialPattern2']
except:
self.SpecialPattern1 = 0
self.SpecialPattern2 = 0

self.NLeds = self.Nx*self.Ny

self._rs232manager = lowLevelManagers['rs232sManager'][
LEDMatrixInfo.managerProperties['rs232device']
]

# initialize the LEDMatrix device that holds all necessary states^
self.mLEDmatrix = self._rs232manager._esp32.led

Expand All @@ -52,22 +52,22 @@ def __init__(self, LEDMatrixInfo, name, **lowLevelManagers):
def setIndividualPattern(self, pattern, getReturn=False):
r = self.mLEDmatrix.send_LEDMatrix_array(pattern, getReturn = getReturn)
return r

def setAll(self, state=(0,0,0), intensity=None):
# dealing with on or off,
# intensity is adjjusting the global value
self.mLEDmatrix.setAll(state, intensity)

def setPattern(self, pattern):
self.mLEDmatrix.pattern(pattern)

def getPattern(self):
return self.mLEDmatrix.getPattern()

def setEnabled(self, enabled):
"""Turn on (N) or off (F) LEDMatrix emission"""
self.setEnabled = enabled
self.enabled = enabled

def setLEDSingle(self, indexled=0, state=(0,0,0)):
"""Handles output power.
Sends a RS232 command to the LEDMatrix specifying the new intensity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ def finalize(self) -> None:
def recordFlatfieldImage(self, image: np.ndarray) -> np.ndarray:
""" Performs flatfield correction on the specified image. """
return image

def getIsRGB(self):
return self.isRGB

# Copyright (C) 2020-2023 ImSwitch developers
# This file is part of ImSwitch.
Expand Down

0 comments on commit d249c21

Please sign in to comment.