Skip to content

Commit

Permalink
fix python image processor test
Browse files Browse the repository at this point in the history
  • Loading branch information
henrypinkard committed Jun 14, 2024
1 parent 4622764 commit 6607cd0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def saving_thread(acq):
if acq.data_sink_:
if acq.debug_mode_:
acq.core_.log_message("Saving image")
if not img.pix and not img.tags:
if img.tags is None and img.pix is None:
break
acq.save_image(img)
if acq.debug_mode_:
Expand Down
12 changes: 10 additions & 2 deletions pycromanager/acquisition/python_backend_acquisitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,17 @@ def _process(self):
# this is a signal to stop
self.output_queue.put(tagged_image)
break
process_fn_result = self._pycromanager_acq._call_image_process_fn(tagged_image.tags, tagged_image.pix)
process_fn_result = self._pycromanager_acq._call_image_process_fn(tagged_image.pix, tagged_image.tags)
try:
self._pycromanager_acq._check_for_exceptions()
except Exception as e:
# unclear if this is functioning properly, check later
self._acq.abort()
if process_fn_result is not None:
self.output_queue.put(process_fn_result)
# turn it into the expected tagged_image
# TODO: change this on later unification of acq engines
tagged_image.pix, tagged_image.tags = process_fn_result
self.output_queue.put(tagged_image)
# otherwise the image processor intercepted the image and nothing to do here

class AcquisitionHook:
Expand Down
20 changes: 19 additions & 1 deletion pycromanager/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ def _find_versions():
raise ValueError(f"Unsupported OS: {platform}")
return re.findall(r'class="rowDefault" href="([^"]+)', webpage.text)

def find_existing_mm_install():
"""
Check if Micro-Manager is installed in the default auto-download paths
Returns
-------
str
The path to the installed Micro-Manager directory, or None if not found
"""
platform = _get_platform()
if platform == 'Windows':
if os.path.isdir(r'C:\Program Files\Micro-Manager'):
return r'C:\Program Files\Micro-Manager'
elif platform == 'Mac':
if os.path.isdir(str(os.path.expanduser('~')) + '/Micro-Manager'):
return str(os.path.expanduser('~')) + '/Micro-Manager'
else:
raise ValueError(f"Unsupported OS: {platform}")

def download_and_install(destination='auto', mm_install_log_path=None):
"""
Expand Down Expand Up @@ -84,7 +102,7 @@ def bar(curr, total, width):
return destination
else:
if destination == 'auto':
destination = os.path.expanduser('~') + '/Micro-Manager'
destination = str(os.path.expanduser('~')) + '/Micro-Manager'
try:
# unmount if already mounted
subprocess.run(['hdiutil', 'detach', '/Volumes/Micro-Manager'])
Expand Down
5 changes: 4 additions & 1 deletion pycromanager/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pycromanager import start_headless
from pycromanager.headless import stop_headless
import socket
from pycromanager.install import download_and_install
from pycromanager.install import download_and_install, find_existing_mm_install

def is_port_in_use(port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
Expand Down Expand Up @@ -61,6 +61,9 @@ def install_mm():
if is_port_in_use(4827):
print('Using Micro-manager running on port 4827 for testing')
yield
elif find_existing_mm_install():
print('Micro-Manager is already installed, skipping installation')
yield find_existing_mm_install()
else:
# Download an install latest nightly build
mm_install_dir = download_and_install(destination='auto')
Expand Down
4 changes: 2 additions & 2 deletions pycromanager/test/test_callback_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def test_img_process_fn(launch_mm_headless, setup_data_folder):
events = multi_d_acquisition_events(num_time_points=3)

def hook_fn(image, metadata):
def image_proc_fn(image, metadata):
assert np.sum(image) > 0
assert isinstance(metadata, dict)

Expand All @@ -18,7 +18,7 @@ def hook_fn(image, metadata):
return image, metadata

with Acquisition(setup_data_folder, 'acq', show_display=False,
image_process_fn=hook_fn) as acq:
image_process_fn=image_proc_fn) as acq:
acq.acquire(events)

dataset = acq.get_dataset()
Expand Down

0 comments on commit 6607cd0

Please sign in to comment.