This module implements the essential components of a microscopy setup. By
assembling an excitation beam, a STED beam, a detector, and fluorescence
molecules, to obtain a microscope setup. The following code gives an example of
how to create such setup and use it to measure and plot the detected signal
given some data_model.
Deng, S., Liu, L., Cheng, Y., Li, R., & Xu, Z. (2010).
Effects of primary aberrations on the fluorescence depletion patterns
of STED microscopy. Optics Express, 18(2), 1657–1666.
[Garcia2000]
Garcia-Parajo, M. F., Segers-Nolten, G. M. J., Veerman, J.-A-.,
Greve, J., & Van Hulst, N. F. (2000).
Real-time light-driven dynamics of the fluorescence emission in single green
fluorescent protein molecules.
Proceedings of the National Academy of Sciences, 97(13), 7237-7242.
Höller, M. (2011).
Advanced fluorescence fluctuation spectroscopy with pulsed
interleaved excitation. PhD thesis, LMU, Munich (Germany).
[Jerker1999]
Jerker, W., Ülo, M., & Rudolf, R. (1999).
Photodynamic properties of green fluorescent proteins investigated by
fluorescence correlation spectroscopy. Chemical Physics, 250(2), 171-186.
Oracz, Joanna, et al. (2017)
Photobleaching in STED Nanoscopy and Its Dependence on the Photon Flux
Applied for Reversible Silencing of the Fluorophore.
Scientific Reports, vol. 7, no. 1, Sept. 2017, p. 11354.
www.nature.com.
Staudt, T. M. (2009).
Strategies to reduce photobleaching, dark state transitions and phototoxicity
in subdiffraction optical microscopy. Dissertation, University of Heidelberg,
Heidelberg (Germany).
Xie, H., Liu, Y., Jin, D., Santangelo, P. J., & Xi, P. (2013).
Analytical description of high-aperture STED resolution with 0–2pi
vortex phase modulation.
Journal of the Optical Society of America A (JOSA A), 30(8), 1640–1645.
This class implements a microscopy setup described by an excitation beam, a STED (depletion) beam, a detector, some fluorescence molecules, and the parameters of the objective.
This temporal experiment will run on a loop based on the action selections instead of on the time to make it easier to integrate the agent/gym stuff :)
Clock class to keep track of time in experiments involving time
Parameters:
time_quantum_us – The minimal time increment on which the experiment loop will happen. All other time
increments in the experiment should be a multiple of this value (in micro seconds (us))
(int)
Note
The time_quantum_us is an int and so is the current_time attribute. This means the longest time an experiment
can last is determined by the size of the biggest int64, which means it is 9223372036854775807 us, or
9223372036854.775807 s, which I think should be ample time :)
This class implements a datamap, containing a disposition of molecules and a ROI to image.
The Datamap can be a composition of multiple parts, for instance, a ‘base’, which is static, a ‘flashes’ part,
which represents only the flashes occuring in the Datamap, or a ‘diffusing’ part, which would represent only
the moving molecules in the Datamap.
The ROI represents the portion of the Datamap that will be imaged. Since the microscope’s lasers are represented by
arrays, we must ensure that the laser array’s edges are contained within the whole Datamap array for every pixel
of the ROI. To facilitated this, the ROI can be set to ‘max’, which will simply 0 pad the passed whole_datamap so
the laser stays confined when scanning over the pixels of the whole_datamap.
Parameters:
whole_datamap – The disposition of the molecules in the sample. This represents the whole sample, from which
only a region will be imaged (roi). (numpy array)
datamap_pixelsize – The size of a pixel of the datamap. (m)
This functions updates the datamap.whole_datamap attribute to the bleached version. I put this in case the user
does not want to update the datamap after bleaching it directly through the microscope’s get_signal_and_bleach
method, in order to do multiple experiments on the same setting.
Parameters:
bleached_datamap – An array of the datamap after the lasers have passed over it (after it has bleached).
Has to be of the same shape as self.whole_datamap
Uses a laser generated by the microscope object to determine the biggest ROI allowed, sets the ROI if valid
Parameters:
laser – An array of the same shape as the lasers which will be used on the datamap
intervals – Values to set the ROI to. Either ‘max’, a dict like {‘rows’: [min_row, max_row],
‘cols’: [min_col, max_col]} or None. If ‘max’, the whole datamap will be padded with 0s, and
the original array will be used as ROI. If None, will prompt the user to enter an ROI.
parameters – One or more parameters as described in the following
table, optional.
Parameter
Default
Details
polarization
pi/2
The phase difference between \(x\)
and \(y\) oscillations (rad).
beta
pi/4
The beam incident angle, in
\([0, \pi/2]\) (rad).
tau
400e-12
The beam pulse length (s).
rate
40e6
The beam pulse rate (Hz).
zero_residual
0
The ratio between minimum and maximum
intensity (ratio).
anti_stoke
True
Presence of anti-stoke (sted beam)
excitation
Polarization :
\(\pi/2\) is left-circular
\(0\) is linear
\(-\pi/2\) is right-circular
get_intensity(power, f, n, na, transmission, datamap_pixelsize)
Compute the transmitted STED intensity field (W/m²). The technique
essentially follows the method described in [Xie2013], where
\(z = 0\), along with some equations from [Deng2010], and
[RPPhoto2015].
Parameters:
power – The power of the beam (W).
f – The focal length of the objective (m).
n – The refractive index of the objective.
na – The numerical aperture.
transmission – The transmission ratio of the objective (given the
wavelength of the STED beam).
datamap_pixelsize – The size of an element in the intensity matrix (m).
The photobleaching rate for a 4 level system from [Oracz2017] is used. The
population of S1+S1*, from where the photobleaching happen, was estimated using
the simplified model used for eq. 3 in [Leutenegger2010]. The triplet dynamic
(dependent on the dwelltime) was estimated from the tree level system rate
equations 2.14 in [Staudt2009], approximating that the population S1 is constant.
Parameters:
lambda_ex – Wavelength of the the excitation beam (m).
lambda_sted – Wavelength of the STED beam (m).
phi_ex – Spatial map of the excitation photon flux (\(m^{-2}s^{-1}\)).
phi_sted – Spatial map of the STED photon flux (\(m^{-2}s^{-1}\)).
tau_sted – STED pulse temporal width (s).
tau_rep – Period of the lasers (s).
dwelltime – Time continuously passed centered on a pixel (s).
Returns:
A 2D array of the bleaching rate d(Bleached)/dt (\(s^{-1}\)).
This class implements a Gaussian beam (excitation).
Parameters:
lambda – The wavelength of the beam (m).
kwargs – One or more parameters as described in the following table,
optional.
Parameter
Default
Details
polarization
pi/2
The phase difference between \(x\)
and \(y\) oscillations (rad).
beta
pi/4
The beam incident angle, in
\([0, \pi/2]\) (rad).
Polarization :
\(\pi/2\) is left-circular
\(0\) is linear
\(-\pi/2\) is right-circular
get_intensity(power, f, n, na, transmission, datamap_pixelsize)
Compute the transmitted excitation intensity field (W/m²). The
technique essentially follows the method described in [Xie2013],
where \(z = 0\), along with some equations from [Deng2010], and
[RPPhoto2015].
Parameters:
power – The time averaged power of the beam (W).
f – The focal length of the objective (m).
n – The refractive index of the objective.
na – The numerical aperture of the objective.
transmission – The transmission ratio of the objective (given the
wavelength of the excitation beam).
datamap_pixelsize – The size of an element in the intensity matrix (m).
Returns:
A 2D array of the time averaged intensity (W/m^2).
This class implements a microscopy setup described by an excitation beam,
a STED (depletion) beam, a detector, some fluorescence molecules, and the
parameters of the objective.
Parameters:
excitation – A GaussianBeam object
representing the excitation laser beam.
sted – A DonutBeam object representing the
STED laser beam.
detector – A Detector object describing the
microscope detector.
objective – A Objective object describing the
microscope objective.
fluo – A Fluorescence object describing the
fluorescence molecules to be used.
load_cache – A bool which determines whether or not the microscope’s lasers will be generated from scratch
(load_cache=False) or if they will be loaded from the previous save (load_cache=True). Generating
the lasers from scratch can take a long time (takes longer as the pixel_size decreases), so
loading the cache can save time when doing multiple experiments using the same pixel_size.
It is important to empty the cache if any of the components
excitation, sted, detector,
objective, or fluorescence are internally modified
or replaced.
Defined here as the spatial map of time averaged detected power per molecule,
taking the sted de-excitation, anti-stoke excitation and the detector properties
(detection psf and gating) into account.
The technique follows the method and equations described in
[Willig2006], [Leutenegger2010] and [Holler2011]. Notable approximations from [Leutenegger2010] include the assumption that the excitation pulse width is infinitely small and that the sted pulse is of perfect rectangular shape and starts at the beginning of the period. Also, a two energy levels (plus their vibrational sub-levels) with two rate equations is used. To include the vibrational decay dynamics (parametrized by the vibrational decay rate), an effective saturation factor is used.
To account for the detection gating, the bounds in the integral from [Leutenegger2010] eq. 3 were adjusted.
Anti-stokes excitation at the beginnning of the period was by added by modeling the sted beam as an infinitely small pulse, similarly to the excitation pulse. This leads to an underestimation of its effect on the detected signal, since excitation by the STED beam near the end of the STED beam, for example, would have less time to be depleted.
Parameters:
datamap_pixelsize – The size of one pixel of the simulated image (m).
p_ex – The time averaged power of the excitation beam (W).
p_sted – The power of the STED beam (W).
data_pixelsize – The size of one pixel of the raw data (m).
It makes a call to compiled C code for speed, so make sure the raster.pyx file is compiled!
Parameters:
datamap – The datamap on which the acquisition is done, either a Datamap object or TemporalDatamap
pixelsize – The pixelsize of the acquisition. (m)
pdt – The pixel dwelltime. Can be either a single float value or an array of the same size as the ROI
being imaged. (s)
p_ex – The excitation beam power. Can be either a single float value or an array of the same size as the
ROI being imaged. (W)
p_sted – The depletion beam power. Can be either a single float value or an array of the same size as the
ROI being imaged. (W)
indices – A dictionary containing the indices of the subdatamaps used. This is used to apply bleaching to
the future subdatamaps. If acquiring on a static Datamap, leave as None.
acquired_intensity – The result of the last incomplete acquisition. This is useful in a time routine where
flashes can occur mid acquisition. Leave as None if it is not the case. (array)
pixel_list – The list of pixels to be iterated on. If none, a pixel_list of a raster scan will be
generated. (list of tuples (row, col))
bleach – Determines whether bleaching is active or not. (Bool)
update – Determines whether the datamap is updated in place. If set to false, the datamap can still be
updated later with the returned bleached datamap. (Bool)
seed – Sets a seed for the random number generator.
filter_bypass – Whether or not to filter the pixel list.
This is useful if you know your pixel list is adequate and ordered differently from a
raster scan (i.e. a left to right, row by row scan), as filtering the list return it
in raster order.
If pixel_list is none, this must be True then.
bleach_func – The bleaching function to be applied.
steps – list containing the pixeldwelltimes for the sub steps of an acquisition. Is none by default.
Should be used if trying to implement a DyMin type acquisition, where decisions are made
after some time on whether or not to continue the acq.
Returns:
returned_acquired_photons, the acquired photon for the acquisition.
bleached_sub_datamaps_dict, a dict containing the results of bleaching on the subdatamaps
acquired_intensity, the intensity of the acquisition, used for interrupted acquisitions
Class which selects a random action from :
0 - Confocal acquisition
1 - STED acquisition
2 - Wait (for the time of 1 acquisition)
..note::
For now we have are pre setting the pdt, p_ex and p_sted that will be used for the actions.
A real agent would select the powers / dwellit me individually
Parameters:
pdt – The pixel dwell time that will be used in the acquisitions
p_ex – The excitation beam power that will be used when the selected action is confocal or sted
p_sted – The STED beam power that will be used when the selected action is sted
This class inherits from Datamap, adding the t dimension to it for managing Ca2+ flashes and diffusion.
The TemporalDatamap object is split into subdatamaps. In the simplest case, the only subdatamap is the base, which
does not change with time (unless being acquired on with bleaching). In the case of Ca2+ flashes, we can add a
subdatamap containing the flashes separately from the base datamap. Thus, for a certain time step t, the
whole_datamap is the sum of the base and the flash at idx t.
Currently, as there is only the Ca2+ flash dynamics implemented, the TemporalDatamap is initialized by passing
the whole molecule disposition and the pixelsize, as for Datamap, with the addition of a list containing all of
the synapse objects in the Datamap.
Parameters:
whole_datamap – The disposition of the molecules in the sample. This represents the whole sample, from which
only a region will be imaged (roi). (numpy array)
datamap_pixelsize – The size of a pixel of the datamap. (m)
synapses – The list of synapses present in the whole_datamap
Applies bleaching to the future flash subdatamaps according to the bleaching that occured to the current flash
subdatamap
Parameters:
indices – A dictionary containing the indices of the time steps we are currently at for the subdatamaps.
For now, as there is only the flash subdatamap implemented, the dictionary will simply be
indices = {“flashes”: idx}, with idx being an >=0 integer.
bleached_sub_datamaps_dict – A dictionary containing the bleached subdatamaps (base, flashes)
Updates the dictionnaries to confirm that flash subdatamaps exist
and to initialize the flash time step at 0. Generates a flash_tstack, a 3D array containing the evolution
of the flashes for every time step. For time step t, the whole_datamap is thus base + flash_tstack[t]
Parameters:
acq_time – The time for which the acquisition will last, determines how many flash steps will occur. (s)
min_timestep – The smallest discrete time steps on which the experiment will be run. For instance, if we
want an experiment to last 10 seconds, we need to define a loop that will iterate through
minimal time increments, which could be 1s, 0.1s, …
fwhm_step_sec_correspondance – Tuple containing the correspondance between the width of the FWHM of a
a flash in arbitrary time step units, and how long we want that FWHM to
last. Usually (10, 1.5) is used. MODIFY THIS SO THIS IS A DEFAULT VALUE.
curves_path – Path to the .npy file of the light curves being sampled in order to generate random
flashes.
probability – The probability of a flash starting on a synapse.
This temporal experiment will run on a loop based on the action selections instead of on the time to make it easier
to integrate the agent/gym stuff :)
quand un épisode commence on crée un objet TemporalExperimentV2p1 avec un certain exp_runtime
l’agent choisit une action et la joue
dans la méthode de jouer l’action (ici) on fait toute la gestion des updates de flash mid acq si c’est
le cas, finir l’action early si on run out de temps, …
* pdt can be a float value, I will convert it into an array filled with that value if this is the case *
Applies bleaching to the future flash subdatamaps according to the bleaching that occured to the current flash
subdatamap
Parameters:
indices – A dictionary containing the indices of the time steps we are currently at for the subdatamaps.
For now, as there is only the flash subdatamap implemented, the dictionary will simply be
indices = {“flashes”: idx}, with idx being an >=0 integer.
bleached_sub_datamaps_dict – A dictionary containing the bleached subdatamaps (base, flashes)
Update de whole datamap using the indices of the sub datamaps.
Whole datamap is the base datamap + all the sub datamaps (for flashes, diffusion, etc).
:param flash_idx: The index of the flash for the most recent acquisition.
Creates the t stack for the evolution of the flash of the nanodmains in the synapse.
Very similar implementation to TemporalDatamap’s create_t_stack_dmap method
Assumes the roi is set