auxiliary_code package

Submodules

auxiliary_code.concurrency_tools module

class auxiliary_code.concurrency_tools.CustodyThread(first_resource=None, group=None, target=None, name=None, args=(), kwargs=None)

Bases: ResultThread

Threads that can access shared resources in the order they were launched. Class from Andrew York et al. Check out: https://github.com/AndrewGYork/tools

See the docstring at the top of this module for examples.

__init__(first_resource=None, group=None, target=None, name=None, args=(), kwargs=None)

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is the argument tuple for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

class auxiliary_code.concurrency_tools.ObjectInSubprocess(initializer, *initargs, custom_loop=None, close_method_name=None, closeargs=None, closekwargs=None, **initkwargs)

Bases: object

__init__(initializer, *initargs, custom_loop=None, close_method_name=None, closeargs=None, closekwargs=None, **initkwargs)

Make an object in a child process, that acts like it isn’t. Class from Andrew York et al. Check out: https://github.com/AndrewGYork/tools

As much as possible, we try to make instances of ObjectInSubprocess behave as if they’re an instance of the object living in the parent process. They’re not, of course: they live in a child process. If you have spare cores on your machine, this turns CPU-bound operations (which threading can’t parallelize) into IO-bound operations (which threading CAN parallelize), without too much mental overhead for the coder.

Parameters:
  • initializer – Callable that returns an instance of a Python object

  • initargs – Arguments to ‘initializer’

  • initkwargs – Arguments to ‘initializer’

  • close_method_name – String, optional, name of our object’s method to be called automatically when the child process exits

  • closeargs – Arguments to ‘close_method’

  • closekwargs – Arguments to ‘close_method’

class auxiliary_code.concurrency_tools.ResultThread(group=None, target=None, name=None, args=(), kwargs=None)

Bases: Thread

threading.Thread with all the simple features we wish it had.

Class from Andrew York et al. Check out: https://github.com/AndrewGYork/tools

We added a ‘get_result’ method that returns values/raises exceptions.

We changed the return value of ‘start’ from ‘None’ to ‘self’ – just to trivially save us a line of code when launching threads.

Example

def f(a):

‘’’ A function that does something… ‘’’ return a.sum()

## Getting Results: a = np.ones((2,), dtype=’uint8’)

res_th = ResultThread(target=f, args=(a,)).start()

res = res_th.get_result() # returns f(a)

assert res == 2

## Error handling a = 1

res_th = ResultThread(target=f, args=(a,)).start() # try:

# res = res_th.get_result()

# except AttributeError:

# print(“AttributeError was raised in thread!”)

# else:

# raise AssertionError(‘We expected an AttributeError to be raised on join!’)

This module modifies threading.excepthook. You can’t just copy/paste this class definition and expect it to work.

__init__(group=None, target=None, name=None, args=(), kwargs=None)

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is the argument tuple for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

get_result(timeout=None)

Either returns a value or raises an exception.

Optionally accepts a timeout in seconds. If thread has not returned after timeout seconds, raises a TimeoutError.

Parameters:

timeout – Set timeout value to wait for join of threads. Default is None.

run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

start()

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

class auxiliary_code.concurrency_tools.SharedNDArray(shape=None, dtype=<class 'float'>, shared_memory_name=None, offset=0, strides=None, order=None)

Bases: ndarray

A numpy array that lives in shared memory. Class from Andrew York et al. Check out: https://github.com/AndrewGYork/tools

Inputs and outputs to/from ObjectInSubprocess are ‘serialized’, which is pretty fast - except for large in-memory objects. The only large in-memory objects we regularly deal with are numpy arrays, so it makes sense to provide a way to pass large numpy arrays via shared memory (which avoids slow serialization).

Example

data_buf = SharedNDArray(shape=(400, 2000, 2000), dtype=’uint16’) display_buf = SharedNDArray(shape=(2000, 2000), dtype=’uint8’)

camera = ObjectInSubprocess(Camera) preprocessor = ObjectInSubprocess(Preprocessor) display = ObjectInSubprocess(Display)

camera.record(num_images=400, out=data_buf) preprocessor.process(in=data_buf, out=display_buf) display.show(display_buf)

Here, each object gets its own CPU core, AND passing large numpy arrays between the processes is still really fast!

To implement this we used memmap from numpy.core as a template.

auxiliary_code.constants module

class auxiliary_code.constants.ASLM_parameters

Bases: object

ASLM parameters. Define here the parameters for the ASLM voltage.

remote_mirror_maxVol = 2.5
remote_mirror_minVol = -2.5
simultaneous_lines = 17
class auxiliary_code.constants.Camera_parameters

Bases: object

Camera configuration values. Define here settings for the Photometrics cameras.

HR_height_pixel = 2048
HR_width_pixel = 2048
LR_height_pixel = 2960
LR_width_pixel = 5056
highres_line_digitization_time = 0.0112
low_to_highres_calibration_height = 130
low_to_highres_calibration_width = 159
lowres_line_digitization_time = 0.01026
class auxiliary_code.constants.FilterWheel_parameters

Bases: object

Filter wheel configuration class. Define which filters are available and which comport to use for connection.

avail_filters = {'515-30-25': 1, '572/20-25': 2, '615/20-25': 3, '676/37-25': 4, 'block': 0, 'transmission': 5}
comport = 'COM6'
class auxiliary_code.constants.Image_parameters

Bases: object

Image parameters. Define here values for the xy lateral pixel sizes.

xy_pixelsize_highres_um = 0.117
xy_pixelsize_lowres_um = 0.3825
class auxiliary_code.constants.NI_board_parameters

Bases: object

NI board parameters. Define here the on which channels the hardware components are connected to.

LED_line = 'Dev1/ao30'
adjustmentfactor = 3
ao_nchannels = 8
ao_type = '6738'
ao_type_constant = '6738_constant'
flip_mirror_line = 'Dev1/ao26'
highres_camera = 0
laser488 = 3
laser552 = 4
laser594 = 5
laser640 = 6
led = -1
line_selection = 'Dev1/ao0, Dev1/ao1, Dev1/ao3, Dev1/ao5, Dev1/ao6, Dev1/ao8, Dev1/ao11, Dev1/ao12'
lowres_camera = 1
mSPIM_mirror_line = 'Dev1/ao29'
mSPIM_mirror_voltage = 0.1
maxVol_constant = 5
max_mSPIM_constant = 2
minVol_constant = 0
power_488_line = 'Dev1/ao17'
power_552_line = 'Dev1/ao18'
power_594_line = 'Dev1/ao22'
power_640_line = 'Dev1/ao25'
rate = 20000.0
stage = 2
voicecoil = 7
class auxiliary_code.constants.Stage_parameters

Bases: object

Stage configuration. Define the connection values for the Smaract stages.

adjustableslit_max = 4024
stage_id_XYZ = 'network:sn:MCS2-00000382'
stage_id_rot = 'usb:id:3948963323'
class auxiliary_code.constants.microscope_configuration

Bases: object

Microscope configuration class. Define which hardware to use here and where to save images.

disktosave = 'D:\\'
filterwheel = 'Synthetic_Filterwheel'
highres_camera = 'Synthetic_camera'
lowres_camera = 'Synthetic_camera'
ni_board = 'Synthetic_niBoard'
parentdir = 'D:/multiScope_Data/'
rotationstage = 'Synthetic_RotationStage'
translationstage = 'Synthetic_TranslationStage'

auxiliary_code.napari_in_subprocess module

auxiliary_code.napari_in_subprocess.display(display_type=None)

Creates a simplified non-blocking napari viewer in a subprocess. Class from Andrew York et al. Check out: https://github.com/AndrewGYork/tools

If you’re using a custom _NapariDisplay, pass it as display_type.

auxiliary_code.write_parameters module

class auxiliary_code.write_parameters.write_Params(view)

Bases: object

Writes the experiment_settings.txt file with the current microscope model parameters.

__init__(view)

Initiate the writer class by importing the view object where all user parameters are set.

Parameters:

view – view object of the MVC design pattern.

write_to_textfile(filePath, roilowres, roihighres)

Writes the Experiment_settings.txt file to disk.

Parameters:
  • filePath – File path to save the Experiment_settings.txt file.

  • roilowres – The current ROI of the low-resolution camera .

  • roihighres – The current ROI of the high-resolution camera.

Module contents