Skip to content

Commit ec032b3

Browse files
committed
update hypha function names, fix return of snapimage numpy
1 parent 1af51c2 commit ec032b3

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

imswitch/imcontrol/controller/controllers/HyphaController.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def on_ended():
132132
print(f"Track {track.kind} ended")
133133

134134

135-
def laserActivate(self, laserId=0, value=0):
135+
def setLaserActive(self, laserId=0, value=0):
136136
"""
137137
Activates or deactivates a laser by setting its enabled state.
138138
@@ -155,7 +155,7 @@ def laserActivate(self, laserId=0, value=0):
155155
"""
156156
self.lasers[laserId].setEnabled(value)
157157

158-
def laserValue(self, laserId=0, value=0):
158+
def setLaserValue(self, laserId=0, value=0):
159159
"""
160160
Sets the value of a laser.
161161
@@ -178,7 +178,7 @@ def laserValue(self, laserId=0, value=0):
178178
"""
179179
self.lasers[laserId].setValue(value)
180180

181-
def ledValue(self, ledId=0, value=0):
181+
def setLEDValue(self, ledId=0, value=0):
182182
"""
183183
Sets the value of an LED in an LED matrix.
184184
@@ -200,7 +200,7 @@ def ledValue(self, ledId=0, value=0):
200200
"""
201201
self.ledMatrix[ledId].setValue(value)
202202

203-
def snapImage(self, path="Default.tif"):
203+
def getImage(self, path="Default.tif"):
204204
"""
205205
Captures a single microscopic image and saves it to a specified path.
206206
@@ -234,7 +234,7 @@ def snapImage(self, path="Default.tif"):
234234
tif.imsave(path,mImage)
235235
return mImage
236236

237-
def move(self, value, axis, is_absolute=True, is_blocking=True):
237+
def setPosition(self, value, axis, is_absolute=True, is_blocking=True):
238238
"""
239239
Moves the microscope stage in the specified axis by a certain distance.
240240
@@ -249,10 +249,10 @@ def move(self, value, axis, is_absolute=True, is_blocking=True):
249249
250250
Example Use:
251251
# Move the stage 10000 µm in the positive X direction in absolute coordinates and wait for the stage to arrive.
252-
self.move(value=10000, axis="X", is_absolute=True, is_blocking=True)
252+
self.setPosition(value=10000, axis="X", is_absolute=True, is_blocking=True)
253253
254254
# move the stage 10000 µm in the negative Y direction in relative coordinates and return immediately.
255-
self.move(value=-10000, axis="Y", is_absolute=False, is_blocking=False)
255+
self.setPosition(value=-10000, axis="Y", is_absolute=False, is_blocking=False)
256256
257257
Notes:
258258
- Successful movement requires supported axis.
@@ -295,11 +295,11 @@ def start_service(self, service_id, server_url="https://ai.imjoy.io/", workspace
295295
"require_context": True,
296296
},
297297
"type": "microscope",
298-
"move": self.move,
299-
"laserActivate": self.laserActivate,
300-
"laserValue": self.laserValue,
301-
"ledValue": self.ledValue,
302-
"snapImage": self.snapImage
298+
"move": self.setPosition,
299+
"setLaserActive": self.setLaserActive,
300+
"setLaserValue": self.setLaserValue,
301+
"setLEDValue": self.setLEDValue,
302+
"getImage": self.getImage
303303
}
304304
)
305305
# print("Workspace: ", workspace, "Token:", await server.generate_token({"expires_in": 3600*24*100}))

imswitch/imcontrol/controller/controllers/RecordingController.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from fastapi.responses import StreamingResponse
77
from fastapi import FastAPI, Response
88
import cv2
9+
from PIL import Image
10+
import io
911

1012
from imswitch.imcommon.framework import Timer
1113
from imswitch.imcommon.model import ostools, APIExport
@@ -380,8 +382,6 @@ def sendScanFreq(self):
380382
def getTimelapseFreq(self):
381383
return self._widget.getTimelapseFreq()
382384

383-
384-
385385
def start_stream(self):
386386
'''
387387
return a generator that converts frames into jpeg's reads to stream
@@ -421,7 +421,6 @@ def streamer(self):
421421
def video_feeder(self):
422422
return StreamingResponse(self.streamer(), media_type="multipart/x-mixed-replace;boundary=frame")
423423

424-
425424
'''
426425
def snapImage(self, name=None) -> None:
427426
self.snap(name)
@@ -431,7 +430,7 @@ def snapImageToPath(self, fileName: str = "."):
431430
""" Take a snap and save it to a .tiff file at the given fileName. """
432431
self.snap(name = fileName)
433432

434-
@APIExport(runOnUIThread=True)
433+
@APIExport(runOnUIThread=False)
435434
def snapImage(self, output: bool = False):# -> np.ndarray:
436435
""" Take a snap and save it to a .tiff file at the set file path. """
437436
if output:
@@ -440,14 +439,18 @@ def snapImage(self, output: bool = False):# -> np.ndarray:
440439
self.snap()
441440

442441
@APIExport(runOnUIThread=False)
443-
def snapNumpyToFastAPI(self, ) -> Response:
442+
def snapNumpyToFastAPI(self, detectorName=None) -> Response:
444443
# Create a 2D NumPy array representing the image
445-
image = self.snap()
446-
image = np.random.randint(0, 255, size=(100, 100), dtype=np.uint8)
444+
images = self.snapNumpy()
445+
446+
# get the image from the first detector if detectorName is not specified
447+
if detectorName is None:
448+
detectorName = self.getDetectorNamesToCapture()[0]
449+
450+
# get the image from the specified detector
451+
image = images[detectorName]
447452

448453
# using an in-memory image
449-
from PIL import Image
450-
import io
451454
im = Image.fromarray(image)
452455

453456
# save image to an in-memory bytes buffer
@@ -457,7 +460,6 @@ def snapNumpyToFastAPI(self, ) -> Response:
457460

458461
headers = {'Content-Disposition': 'inline; filename="test.png"'}
459462
return Response(im_bytes, headers=headers, media_type='image/png')
460-
461463

462464
@APIExport(runOnUIThread=True)
463465
def startRecording(self) -> None:

0 commit comments

Comments
 (0)