mesoSPIM.src.utils package
Submodules
mesoSPIM.src.utils.acquisitions module
acquisitions.py
Helper classes for mesoSPIM acquisitions
- class mesoSPIM.src.utils.acquisitions.Acquisition(*args: Any, **kwargs: Any)[source]
Bases:
IndexedOrderedDictCustom acquisition dictionary. Contains all the information to run a single acquisition.
- Parameters:
x_pos (float) – X start position in microns
y_pos (float) – Y start position in microns
z_start (float) – Z start position in microns
z_end (float) – Z end position in microns
z_step (float) – Z stepsize in microns ,
theta_pos (float) – Rotation angle in microns
f_pos (float) – Focus position in microns
laser (str) – Laser designation
intensity (int) – Laser intensity in 0-100
filter (str) – Filter designation (has to be in the config)
zoom (str) – Zoom designation
filename (str) – Filename for the file to be saved
Attributes:
Note
Getting keys:
keys = [key for key in acq1.keys()]Example
Getting keys:
keys = [key for key in acq1.keys()]Todo
Testtodo-Entry
- get_acquisition_time(framerate)[source]
Method to return the time the acquisition will take at a certain framerate.
- Parameters:
float – framerate of the microscope
- Returns:
Acquisition time in seconds
- Return type:
- get_capitalized_keylist()[source]
Here, a list of capitalized keys is returned for usage as a table header
- get_delta_z_and_delta_f_dict(inverted=False)[source]
Returns relative movement dict for z- and f-steps
- get_focus_stepsize_generator(f_stage_min_step_um=0.25)[source]
‘ Provides a generator object to correct rounding errors for focus tracking acquisitions.
The focus stage has to travel a shorter distance than the sample z-stage, ideally only a fraction of the z-step size. However, due to the limited minimum step size of the focus stage, rounding errors can accumulate over thousands of steps.
Therefore, the generator tracks the rounding error and applies correcting steps here and there to minimize the error.
This assumes a minimum step size of around 0.25 micron that the focus stage is capable of.
This method contains lots of round functions to keep residual rounding errors at bay.
- class mesoSPIM.src.utils.acquisitions.AcquisitionList(*args)[source]
Bases:
listClass for a list of acquisition objects
Examples: “([acq1,acq2,acq3])” is due to the fact that list takes only a single argument acq_list = AcquisitionList([acq1,acq2,acq3]) acq_list.time() > 3600 acq_list.planes() > 18000
acq_list[2](2) >10 acq_list[2][‘y_pos’] >10 acq_list[2][‘y_pos’] = 34
- check_filename_extensions()[source]
Returns files that have no extension, so their format is undefined.
- find_value_index(value: str = '488 nm', key: str = 'laser')[source]
Find the attribute index in the acquisition list. Example: al = AcquisitionList([Acquisition(), Acquisition(), Acquisition(), Acquisition()]) al[0][‘laser’] = ‘488 nm’ # al[1][‘laser’] = ‘488 nm’ # gets removed because non-unique al[2][‘laser’] = ‘561 nm’ # al[3][‘laser’] = ‘637 nm’ # Output: al.find_value_index(‘488 nm’, ‘laser’) # -> 0 al.find_value_index(‘561 nm’, ‘laser’) # -> 1 al.find_value_index(‘637 nm’, ‘laser’) # -> 2
mesoSPIM.src.utils.delegates module
- class mesoSPIM.src.utils.delegates.ChooseFolderDelegate(*args: Any, **kwargs: Any)[source]
Bases:
QItemDelegateA delegate that has a button, in turn opening a set folder dialog and displaying the folder name.
- class mesoSPIM.src.utils.delegates.ComboDelegate(*args: Any, **kwargs: Any)[source]
Bases:
QItemDelegateA delegate that places a fully functioning QComboBox in every cell of the column to which it’s applied
TODO: Provide list for entries during __init__
- class mesoSPIM.src.utils.delegates.ETLSpinBoxDelegate(*args: Any, **kwargs: Any)[source]
Bases:
QStyledItemDelegateDelegate with Spinbox, very fine steps
- class mesoSPIM.src.utils.delegates.IntensitySpinBoxDelegate(*args: Any, **kwargs: Any)[source]
Bases:
QStyledItemDelegateDelegate with Spinbox for laser intensity
- class mesoSPIM.src.utils.delegates.MarkFocusPositionDelegate(*args: Any, **kwargs: Any)[source]
Bases:
MarkPositionDelegate
- class mesoSPIM.src.utils.delegates.MarkPositionDelegate(*args: Any, **kwargs: Any)[source]
Bases:
QStyledItemDelegateDelegate with a Mark button
Upon hitting the mark button, it should take the current value from e.g. the coordinates and put them into the model set it into
There is only a single delegate per row instantiated.
- class mesoSPIM.src.utils.delegates.MarkRotationPositionDelegate(*args: Any, **kwargs: Any)[source]
Bases:
MarkPositionDelegate
- class mesoSPIM.src.utils.delegates.MarkXPositionDelegate(*args: Any, **kwargs: Any)[source]
Bases:
MarkPositionDelegate
- class mesoSPIM.src.utils.delegates.MarkYPositionDelegate(*args: Any, **kwargs: Any)[source]
Bases:
MarkPositionDelegate
- class mesoSPIM.src.utils.delegates.MarkZPositionDelegate(*args: Any, **kwargs: Any)[source]
Bases:
MarkPositionDelegate
- class mesoSPIM.src.utils.delegates.ProgressBarDelegate(*args: Any, **kwargs: Any)[source]
Bases:
QStyledItemDelegateA progress bar as a delegate
Of course, it does not have an editing function, instead it only serves to display data
TODO: How to set value properly?
- class mesoSPIM.src.utils.delegates.RotationSpinBoxDelegate(*args: Any, **kwargs: Any)[source]
Bases:
QStyledItemDelegateDelegate with Spinbox, very fine steps
- class mesoSPIM.src.utils.delegates.SliderDelegate(*args: Any, **kwargs: Any)[source]
Bases:
QStyledItemDelegateA slider delegate
- class mesoSPIM.src.utils.delegates.SliderWithValueDelegate(*args: Any, **kwargs: Any)[source]
Bases:
QStyledItemDelegate
mesoSPIM.src.utils.filename_wizard module
Contains Nonlinear Filename Wizard Class: autogenerates Filenames
- class mesoSPIM.src.utils.filename_wizard.AbstractSelectionPage(*args: Any, **kwargs: Any)[source]
Bases:
QWizardPage
- class mesoSPIM.src.utils.filename_wizard.FilenameWizard(*args: Any, **kwargs: Any)[source]
Bases:
QWizard- bigtiff = 3
- done(r)[source]
Reimplementation of the done function
if r == 0: canceled if r == 1: finished properly
- finished = 5
- generate_filename_list(increment_number=True)[source]
Go through the model, entry for entry and populate the filenames
- num_of_pages = 6
- raw = 1
- single_hdf5 = 4
- tiff = 2
- welcome = 0
- class mesoSPIM.src.utils.filename_wizard.FilenameWizardBigTiffSelectionPage(*args: Any, **kwargs: Any)[source]
Bases:
AbstractSelectionPage
- class mesoSPIM.src.utils.filename_wizard.FilenameWizardCheckResultsPage(*args: Any, **kwargs: Any)[source]
Bases:
QWizardPage
- class mesoSPIM.src.utils.filename_wizard.FilenameWizardRawSelectionPage(*args: Any, **kwargs: Any)[source]
Bases:
QWizardPage
- class mesoSPIM.src.utils.filename_wizard.FilenameWizardSingleHDF5SelectionPage(*args: Any, **kwargs: Any)[source]
Bases:
AbstractSelectionPage
- class mesoSPIM.src.utils.filename_wizard.FilenameWizardTiffSelectionPage(*args: Any, **kwargs: Any)[source]
Bases:
AbstractSelectionPage
mesoSPIM.src.utils.focus_tracking_wizard module
Contains Focus Tracking Wizard Class: autogenerates start end end foci from reference / anchor positions
- class mesoSPIM.src.utils.focus_tracking_wizard.FocusTrackingWizard(*args: Any, **kwargs: Any)[source]
Bases:
QWizardWizard to run
The parent is the Window class of the microscope
- class mesoSPIM.src.utils.focus_tracking_wizard.FocusTrackingWizardCheckResultsPage(*args: Any, **kwargs: Any)[source]
Bases:
QWizardPage
mesoSPIM.src.utils.image_processing_wizard module
Contains Image Processing Wizard Class: Sets online processing options
- class mesoSPIM.src.utils.image_processing_wizard.ImageProcessingWizard(*args: Any, **kwargs: Any)[source]
Bases:
QWizardWizard to run
The parent is the Window class of the microscope
- class mesoSPIM.src.utils.image_processing_wizard.ImageProcessingWizardCheckResultsPage(*args: Any, **kwargs: Any)[source]
Bases:
QWizardPage
mesoSPIM.src.utils.models module
- class mesoSPIM.src.utils.models.AcquisitionModel(*args: Any, **kwargs: Any)[source]
Bases:
QAbstractTableModelModel class containing a AcquisitionList
The headers are derived from the keys of the first acquisition dictionary.
TODO: Typecheck in __init__ for AcquisitionList as table
- dropMimeData(data, action, row, col, parent)[source]
Here, the model needs to deserialize the entries in a QMimeData object
Always move the entire row, and don’t allow column “shifting”
- flags(index)[source]
Return Editability for arbitrary elements Drag and drop flags are also set here
- headerData(section, orientation, role)[source]
What to display in the table headers
Orientation: Row part or column part Section: Which index
- insertRows(position, rows, parent=PyQt5.QtCore.QModelIndex)[source]
Method to add entries to the model
Rows: how many rows are inserted at once.
The views expect a zero-based index
self.beginInsertRows(index, first, last) to send signals
- mimeData(indices)[source]
Here, the model needs to provide a serialization of the entries in a QMimeData object
- rowCount(parent=PyQt5.QtCore.QModelIndex)[source]
Tells the view how many items this model contains
- send_data_changed()[source]
Helper method that allows to send a dataChanged Signal for the whole table
mesoSPIM.src.utils.multicolor_acquisition_builder module
Classes that define acquisition builders:
Take a dict with information and return an acquisition list
- class mesoSPIM.src.utils.multicolor_acquisition_builder.AcquisitionListBuilder[source]
Bases:
objectGeneric Acquisition List Builder as parent class?
TODO: Write this class
- class mesoSPIM.src.utils.multicolor_acquisition_builder.MulticolorTilingAcquisitionListBuilder(dict)[source]
Bases:
objectTODO: Filename generation
self.dict[‘x_start’] self.dict[‘x_end’] self.dict[‘y_start’] self.dict[‘y_end’] self.dict[‘z_start’] self.dict[‘z_end’] self.dict[‘z_step’] self.dict[‘theta_pos’] self.dict[‘f_pos’] self.dict[‘x_offset’] # Offset always larger than 0 self.dict[‘y_offset’] # Offset always larger than 0 self.dict[‘x_image_count’] self.dict[‘y_image_count’]
- y_end
Reverse direction of the offset if pos_end < pos_start
mesoSPIM.src.utils.multicolor_acquisition_wizard module
Contains Multicolor Acquisition Wizard Classes:
Widgets that take user input and create acquisition lists
- class mesoSPIM.src.utils.multicolor_acquisition_wizard.CheckTilingPage(*args: Any, **kwargs: Any)[source]
Bases:
QWizardPage
- class mesoSPIM.src.utils.multicolor_acquisition_wizard.DefineBoundingBoxPage(*args: Any, **kwargs: Any)[source]
Bases:
QWizardPage
- class mesoSPIM.src.utils.multicolor_acquisition_wizard.DefineFolderPage(*args: Any, **kwargs: Any)[source]
Bases:
QWizardPage
- class mesoSPIM.src.utils.multicolor_acquisition_wizard.DefineGeneralParametersPage(*args: Any, **kwargs: Any)[source]
Bases:
QWizardPage- update_fov_size()
Should be invoked whenever the zoom selection is changed
- update_other_acquisition_parameters()[source]
Here, all the Tiling parameters are filled in the parent (TilingWizard) This method should be called when the “Next” Button is pressed
- update_shutt_seq()
- update_x_and_y_offset()
- class mesoSPIM.src.utils.multicolor_acquisition_wizard.FifthChannelPage(*args: Any, **kwargs: Any)[source]
Bases:
GenericChannelPage
- class mesoSPIM.src.utils.multicolor_acquisition_wizard.FinishedTilingPage(*args: Any, **kwargs: Any)[source]
Bases:
QWizardPage
- class mesoSPIM.src.utils.multicolor_acquisition_wizard.FirstChannelPage(*args: Any, **kwargs: Any)[source]
Bases:
GenericChannelPage
- class mesoSPIM.src.utils.multicolor_acquisition_wizard.FourthChannelPage(*args: Any, **kwargs: Any)[source]
Bases:
GenericChannelPage
- class mesoSPIM.src.utils.multicolor_acquisition_wizard.GenericChannelPage(*args: Any, **kwargs: Any)[source]
Bases:
QWizardPage
- class mesoSPIM.src.utils.multicolor_acquisition_wizard.MulticolorTilingWizard(*args: Any, **kwargs: Any)[source]
Bases:
QWizardWizard to run
The parent is the Window class of the microscope
- done(r)[source]
Reimplementation of the done function
if r == 0: canceled if r == 1: finished properly
- state
Instance variables
- class mesoSPIM.src.utils.multicolor_acquisition_wizard.SecondChannelPage(*args: Any, **kwargs: Any)[source]
Bases:
GenericChannelPage
- class mesoSPIM.src.utils.multicolor_acquisition_wizard.ThirdChannelPage(*args: Any, **kwargs: Any)[source]
Bases:
GenericChannelPage
mesoSPIM.src.utils.optimization module
Utilities for fast image-based optimization (auto-focus, etc) Auto-focus is based on Autopilot paper (Royer at al, Nat Biotechnol. 2016 Dec;34(12):1267-1278. doi: 10.1038/nbt.3708.) author: Nikita Vladimirov, @nvladimus, 2021 License: GPL-3
- mesoSPIM.src.utils.optimization.fit_gaussian_1d(f_arr, x_arr)[source]
Fit measured values f_arr(x_arr) with a gaussian function. The true gaussian peak must lie withing the x_arr limits, so the measurements must ‘clamp’ the gaussian from left and right.
Parameters:
- f_arr: 1d-array
Measured function values.
- x_arr: 1d-array
Positions where the function was measured.
Returns:
- (xcenter, sigma, f_amp, f_offset): tuple
Parameters of gaussian fit: f = f_offset + f_amp * np.exp(-((x_arr - xcenter)**2) / (2 * sigma ** 2))
- mesoSPIM.src.utils.optimization.fit_parabola_1d(f_arr, x_arr)[source]
Fit measured values f_arr(x_arr) with a parabola function f=a(x-x0)**2 + b. The true peak must lie withing the x_arr limits, so the measurements must ‘clamp’ the function from left and right.
Parameters:
- f_arr: 1d-array
Measured function values.
- x_arr: 1d-array
Positions where the function was measured.
Returns:
- (xcenter, f_amp, f_offset): tuple
Parameters of parabola fit: f = f_offset + f_amp(x-xcenter)**2
- mesoSPIM.src.utils.optimization.gaussian_1d(x_arr, xo, sigma, amplitude=1, offset=0)[source]
“Return 1D gaussian function as array
mesoSPIM.src.utils.utility_functions module
Contains a variety of mesoSPIM utility functions
- mesoSPIM.src.utils.utility_functions.GetCurrentProcessorNumber()
- mesoSPIM.src.utils.utility_functions.convert_seconds_to_string(delta_t)[source]
Converts an input value in seconds into a string in the format hh:mm:ss
Interestingly, a variant using np.divmod is around 4-5x slower in initial tests.
- mesoSPIM.src.utils.utility_functions.format_data_size(bytes)[source]
Converts bytes into human-readable format (kb, MB, GB)
- mesoSPIM.src.utils.utility_functions.gb_size_of_array_shape(shape)[source]
Given a tuple of array shape, return the size in GB of at uint16 array
mesoSPIM.src.utils.waveforms module
mesoSPIM Module for creating waveforms and analog output signals
Author: Fabian Voigt
#TODO * Usage of amplitude is not consistent (peak-to-peak in single_pulse)
- mesoSPIM.src.utils.waveforms.sawtooth(samplerate=100000, sweeptime=0.4, frequency=10, amplitude=0, offset=0, dutycycle=50, phase=1.5707963267948966)[source]
Returns a numpy array with a sawtooth function
Used for creating the galvo signal.
Example: galvosignal = sawtooth(100000, 0.4, 199, 3.67, 0, 50, np.pi)
- mesoSPIM.src.utils.waveforms.single_pulse(samplerate=100000, sweeptime=0.4, delay=10, pulsewidth=1, amplitude=0, offset=0)[source]
Returns a numpy array with a single pulse
Used for creating TTL pulses out of analog outputs and laser intensity pulses.
Units: samplerate: Integer sweeptime: Seconds delay: Percent pulsewidth: Percent amplitude: Volts offset: Volts
Examples:
typical_TTL_pulse = single_pulse(samplerate, sweeptime, 10, 1, 5, 0) typical_laser_pulse = single_pulse(samplerate, sweeptime, 10, 80, 1.25, 0)
- mesoSPIM.src.utils.waveforms.square(samplerate=100000, sweeptime=0.4, frequency=10, amplitude=0, offset=0, dutycycle=50, phase=3.141592653589793)[source]
Returns a numpy array with a rectangular waveform
- mesoSPIM.src.utils.waveforms.tunable_lens_ramp(samplerate=100000, sweeptime=0.4, delay=7.5, rise=85, fall=2.5, amplitude=0, offset=0)[source]
Returns a numpy array with a ETL ramp
The waveform starts at offset and stays there for the delay period, then rises linearly to 2x amplitude (amplitude here refers to 1/2 peak-to-peak) and drops back down to the offset voltage during the fall period.
Switching from a left to right ETL ramp is possible by exchanging the rise and fall periods.
Units of parameters samplerate: Integer sweeptime: Seconds delay: Percent rise: Percent fall: Percent amplitude: Volts offset: Volts