tramway.analyzer package¶
-
class
tramway.analyzer.
RWAnalyzer
¶ Bases:
tramway.analyzer.attribute.WithLogger
A
RWAnalyzer
object gathers the parameters of all the processing steps of a standard processing chain, from SPT data loading/generation to inferring model parameters at microdomains.The supported steps are defined in a declarative way with special attributes; these steps and corresponding attributes are as follows:
images
: microscopy imageslocalizer
: single molecule localizationtracker
: single particle trackingspt_data
: SPT data loading or generationroi
: regions of interesttesseller
: spatial segmentationtime
: temporal segmentation of the tracking datasampler
: assignment of SPT data points to microdomainsmapper
: estimation of model parameters at each microdomains
Most attributes are self-morphing, i.e. they first are initializers and exhibit from_… methods (for example
from_dataframe()
andfrom_ascii_file()
forspt_data
) and then, once any such initializer method is called, they specialize into a new attribute and exhibit specific attributes depending on the chosen initializer:from tramway.analyzer import * a = RWAnalyzer() a.spt_data.from_ascii_files('my_data_repository/*.txt')
The more conventional assignment form is also available using functions of modules exported by the
tramway.analyzer
subpackage. These modules are named following the attribute they are dedicated to:a = RWAnalyzer() a.spt_data = spt_data.from_ascii_files('my_data_repository/*.txt')
In most cases, a third form is also available, with a class constructor:
a = RWAnalyzer() a.spt_data = spt_data.SPTAsciiFiles('my_data_repository/*.txt')
Anyway, most of the attributes of an
RWAnalyzer
object are properties that perform various checks and may raise exceptions if misused.Specialized attributes can also exhibit self-morphing attributes. For example, regions of interest can be defined globally using the main
roi
attribute, or on a per-SPT-datafile basis:a = RWAnalyzer() a.spt_data.from_ascii_files('my_data_repository/*.txt') a.roi.from_squares(roi_centers, square_size)
or
a = RWAnalyzer() a.spt_data.from_ascii_files('my_data_repository/*.txt') for spt_file in a.spt_data: spt_file.roi.from_squares(roi_centers, square_size)
In the above example, per-dataset ROI definition is useful when multiple datasets are loaded and the ROI may differ between datasets. The main
roi
attribute is still convenient as it allows to iterate over all the defined ROI, omitting thespt_data
loop (continues any of the code blocks above):for r in a.roi: roi_spt_data = r.crop()
The ROI object is denoted
r
here. Nameroi
already exists if theanalyzer
module is imported withfrom tramway.analyzer import *
. In this case,roi
points to theroi
module.Note there exists multiple iterators for the collections of ROI. In the further examples of iterated ROI, the preferred iterator is made explicit. See the documentation for the
roi
attribute for more information about the available iterators.While the
spt_data
androi
attributes act as data providers, thetime
,tesseller
,sampler
andmapper
attributes do not feature direct access to the data and require the SPT data to be passed as input argument to their main processing methods. For example:a.tesseller.from_plugin('kmeans') for r in a.roi.as_support_regions(): roi_spt_data = r.crop() tessellation = a.tesseller.tessellate(roi_spt_data)
Similarly, the
images
attribute defines data location, while thelocalizer
andtracker
attributes define processing steps on these data.Other attributes drive the execution of the processing chain. The
run()
method launches the processing chain, which is operated by thepipeline
attribute.Various parallelization schemes are available, and the platform-specific implementation of these schemes are provided by the
env
attribute.Last but not least, the
RWAnalyzer
features plotting utilities. Some of them are available through the mpl sub-attribute of some mainRWAnalyzer
attributes or items, for exampleimages.mpl
(Mpl
),spt_data.mpl
(Mpl
),tesseller.mpl
(Mpl
),mapper.mpl
(Mpl
). In addition, thebrowser
attribute can plot the inferred parameter maps from a Jupyter notebook, or calling thebokeh serve
command:from tramway.analyzer import * a = RWAnalyzer() # load the rwa files available in the current directory: a.spt_data.from_rwa_files('*.rwa') # help the analyzer locate this piece of code: try: a.script = __file__ except NameError: # in a notebook a.script = 'MyNotebook.ipynb' # this notebook's name (please adapt) a.browser.show_maps()
See also
Browser
for additional information on how to export data and figures while browsing the inferred parameter maps.-
spt_data
¶ SPT data accessor.
See
SPTDataInitializer
andSPTData
.
-
roi
¶ ROI accessor.
See
ROIInitializer
andROI
.
-
time
¶ Time segmentation procedure.
See
TimeInitializer
andTime
.
-
tesseller
¶ Tessellation procedure.
See
TessellerInitializer
andTesseller
.
-
sampler
¶ Sampling procedure.
See
SamplerInitializer
andSampler
.
-
mapper
¶ Inference procedure.
See
MapperInitializer
andMapper
.
-
images
¶ Microscopy image stacks.
See
ImagesInitializer
andImages
.
-
localizer
¶ Single molecule localization procedure.
See
LocalizerInitializer
andLocalizer
.
-
tracker
¶ Single particle tracking procedure.
See
TrackerInitializer
andTracker
.
-
env
¶ Environment backend for operating the pipeline.
If not set, the pipeline will run locally in the current interpreter.
See
environments
.
-
add_collectible
(collectible)¶ Designates a file generated on the worker side to be transferred back to the submit side.
Alias for
pipeline
add_collectible()
.
-
exception
tramway.analyzer.
SideEffectWarning
¶ Bases:
UserWarning
tramway.analyzer.artefact package¶
tramway.analyzer.attribute package¶
-
class
tramway.analyzer.attribute.
InitializerMethod
(method, attrname=None)¶ Bases:
object
Useful for explicit typing.
-
tramway.analyzer.attribute.
initializer_method
(method, attrname=None)¶ Properly set the docstring for the wrapped method.
tramway.analyzer.images package¶
-
class
tramway.analyzer.images.
Images
¶ Bases:
tramway.analyzer.attribute.abc.Attribute
Abstract base class for the
images
attribute of anRWAnalyzer
object.-
as_frames
(index=None, return_time=False)¶ Generator function; yields frames as arrays.
See for example
as_frames()
.
-
crop_frames
(bounding_box, index=None, return_time=False)¶ Generator function similar to
as_frames()
, with ROI cropping.See for example
crop_frames()
.
-
-
class
tramway.analyzer.images.
Image
¶ Bases:
object
Abstract base class for single image stacks an
Images
object contains.
-
class
tramway.analyzer.images.
ImagesInitializer
(attribute_setter, parent=None)¶ Bases:
tramway.analyzer.attribute.Initializer
Initial value for the
RWAnalyzer
images
attribute.from_… methods alters the parent attribute which specializes into an initialized
Images
object.-
from_tiff_file
(filepath)¶ Defines the raw single molecule imaging file.
Loading is not performed while calling this method.
-
from_tiff_files
(filepattern)¶ Defines the raw single molecule imaging files.
Loading is not performed while calling this method.
-
-
class
tramway.analyzer.images.
RawImages
(stacks, **kwargs)¶ Bases:
tramway.analyzer.images.ImageIterator
-
class
tramway.analyzer.images.
ImageFiles
(filepattern, **kwargs)¶ Bases:
tramway.analyzer.images.ImageIterator
-
class
tramway.analyzer.images.
TiffFiles
(filepattern, **kwargs)¶
tramway.analyzer.images.mpl module¶
-
class
tramway.analyzer.images.mpl.
Mpl
(parent=None)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
Matplotlib plotting utilities for 2D data; no time support.
-
plot
(x, *args, origin=None, frame=None, **kwargs)¶ Converts localization data from micrometers to pixels and plots them.
Can overlay locations onto a frame image as plotted with imshow and default parameters (
origin='upper'
).
-
roi
(frame, origin, *args, axes=None, colormap='gray', **kwargs)¶ Plots a frame corresponding to a region of interest.
origin should be provided by
cropping_bounds()
, if frame is given bycrop_frames()
.Extra input arguments are passed to the
imshow()
function.This method works in combination with
spt_data.mpl.Mpl.plot()
.
-
tramway.analyzer.localizer package¶
-
class
tramway.analyzer.localizer.
UNetLocalizer
(**kwargs)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
Loads the weights of a U-Net network for image deconvolution.
Not implemented yet, as long as the
UNet
package is broken.-
weights_locator
¶ Uniform resource locator for the U-Net weights
Type: str
-
-
class
tramway.analyzer.localizer.
LocalizerInitializer
(attribute_setter, parent=None)¶ Bases:
tramway.analyzer.attribute.Initializer
Initializer class for the
RWAnalyzer
localizer
main attribute.The
localizer
attribute self-modifies on calling any of the from_… methods.-
from_UNet
()¶ Loads a trained U-Net network for image deconvolution.
See also
UNetLocalizer
.
-
from_unet
()¶ Alias for
from_UNet()
.
-
-
class
tramway.analyzer.localizer.
Localizer
¶ Bases:
tramway.analyzer.attribute.abc.Attribute
Abstract base class for the
localizer
attribute of anRWAnalyzer
object.
tramway.analyzer.tracker package¶
-
class
tramway.analyzer.tracker.
NonTrackingTracker
(**kwargs)¶ Bases:
tramway.analyzer.tracker.BaseTracker
Non-tracking tracker.
-
class
tramway.analyzer.tracker.
Tracker
¶ Bases:
tramway.analyzer.attribute.abc.Attribute
Abstract base class for the
tracker
attribute of anRWAnalyzer
object.
-
class
tramway.analyzer.tracker.
TrackerInitializer
(attribute_setter, parent=None)¶ Bases:
tramway.analyzer.attribute.Initializer
Initializer class for the
RWAnalyzer
tracker
main attribute.The
tracker
attribute self-modifies on calling any of the from_… methods.-
from_single_particle
()¶ Considers every single molecule localization datablocks as single trajectories.
See also
SingleParticleTracker
.
-
from_non_tracking
()¶ Non-tracking tracker.
See also
NonTrackingTracker
.
-
tramway.analyzer.spt_data package¶
-
class
tramway.analyzer.spt_data.
SPTData
¶ Bases:
tramway.analyzer.attribute.abc.Attribute
Abstract base class for the
spt_data
attribute of anRWAnalyzer
object.-
as_dataframes
(source=None)¶ Generator function; yields
pandas.DataFrame
objects.source can be a source name (filepath) or a boolean function that takes a source string as input argument.
-
bounds
¶ Lower (index min) and upper (index max) bounds for the SPT data
Type: pandas.DataFrame
-
columns
¶ Data column names
Type: list of str
-
discard_static_trajectories
(dataframe=None, min_msd=None)¶ The minimum mean-square-displacement is set to the localization error per default.
If an input dataframe is given, then
discard_static_trajectories()
returns the processed dataframe and self does not maintain any copy of it.Otherwise,
discard_static_trajectories()
applies inplace to the internal dataframe and does not return any dataframe. Note that it may set a flag instead of actually processing the internal dataframe, for the parcimonious processing in regions of interest only.
-
frame_interval
¶ Time interval between successive frames, in seconds
Type: float
-
localization_error
¶ Localization error in \(\mu m^2\)
Type: float
-
reset_origin
(columns=None, same_origin=False)¶ Translates the lower bound of the spatial data to zero.
-
-
class
tramway.analyzer.spt_data.
SPTDataItem
¶ Bases:
object
Abstract base class for SPT data blocks an
SPTData
object contains.-
analyses
¶ Analysis tree
Type: Analyses
-
bounds
¶ Lower (index min) and upper (index max) bounds for the SPT data
Type: pandas.DataFrame
-
columns
¶ Data column names
Type: list of str
-
dataframe
¶ Raw SPT data
Type: pandas.DataFrame
-
frame_interval
¶ Time interval between successive frames, in seconds
Type: float
-
localization_error
¶ Localization error in \(\mu m^2\)
Type: float
-
source
¶ File path or identifier
Type: str
-
-
class
tramway.analyzer.spt_data.
SPTParameters
(localization_precision=None, localization_error=None)¶ Bases:
object
Mixin class for storing common experimental parameters, including the localization error, time interval and temperature.
Children classes should define the
_frame_interval
,_localization_error
and_temperature
attributes, or overload theframe_interval
,localization_error
andtemperature
properties.Default values should be
None
.-
discard_static_trajectories
(dataframe, min_msd=None, **kwargs)¶ The minimum mean-square-displacement is set to the localization error per default.
If an input dataframe is given, then
discard_static_trajectories()
returns the processed dataframe and self does not maintain any copy of it.Otherwise,
discard_static_trajectories()
applies inplace to the internal dataframe and does not return any dataframe. Note that it may set a flag instead of actually processing the internal dataframe, for the parcimonious processing in regions of interest only.
-
dt
¶ Alias for the
frame_interval
propertyType: float
-
frame_interval
¶ Time interval between successive frames, in seconds
Type: float
-
localization_error
¶ Localization error in \(\mu m^2\)
Type: float
-
localization_precision
¶ Localization precision in \(\mu m\);
localization_error
\(\sigma^2\) is affected bylocalization_precision
\(\sigma\) and vice versaType: float
-
set_precision
(precision)¶ Sets the numerical precision of the raw data.
Parameters: precision (dict or str) – any of 'half'
,'single'
,'double'
, or a dictionnary of dtypes with column names as keys, as admitted bypandas.DataFrame.astype()
.
-
temperature
¶ Temperature in K; can be set as a value-unit pair, with unit any of
'K'
,'C'
and'F'
Type: float
-
time_step
¶ Alias for the
frame_interval
propertyType: float
-
-
class
tramway.analyzer.spt_data.
StandaloneDataItem
¶ Bases:
object
Partial implementation for single data item
SPTData
attribute.
-
class
tramway.analyzer.spt_data.
SPTDataIterator
(**kwargs)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
,tramway.analyzer.spt_data.SPTParameters
Partial implementation for multi-item
SPTData
.Children classes must implement the
__iter__()
method.-
as_dataframes
(source=None, return_index=False)¶ Generator function; yields
pandas.DataFrame
objects.source can be a source name (filepath) or a boolean function that takes a source string as input argument.
-
bounds
¶ Lower (index min) and upper (index max) bounds for the SPT data
Type: pandas.DataFrame
-
discard_static_trajectories
(dataframe=None, min_msd=None, **kwargs)¶ The minimum mean-square-displacement is set to the localization error per default.
If an input dataframe is given, then
discard_static_trajectories()
returns the processed dataframe and self does not maintain any copy of it.Otherwise,
discard_static_trajectories()
applies inplace to the internal dataframe and does not return any dataframe. Note that it may set a flag instead of actually processing the internal dataframe, for the parcimonious processing in regions of interest only.
-
dt
¶ Alias for the
frame_interval
propertyType: float
-
filter_by_source
(source_filter, return_index=False)¶ Generator function; similar to
__iter__()
; yieldsSPTDataItem
objects.source can be a single str value, or a set of str values, or a sequence of str values (the order is followed), or a callable that takes a str value and returns a bool value.
-
frame_interval
¶ Time interval between successive frames, in seconds
Type: float
-
localization_error
¶ Localization error in \(\mu m^2\)
Type: float
-
reload_from_rwa_files
(skip_missing=False)¶ Reloads the SPT data and analysis tree from the corresponding rwa files.
The rwa file that corresponds to an SPT file should be available at the same path with the .rwa extension instead of the SPT file’s extension.
This method is known to fail with a
TypeError
exception in cases where not any matching .rwa file can be found.Note
As this operation modifies the SPT data source and filepath attributes, aliases should be favored when identifying or filtering SPT data items.
-
self_update
(new_self)¶
-
set_precision
(precision)¶ Sets the numerical precision of the raw data.
Parameters: precision (dict or str) – any of 'half'
,'single'
,'double'
, or a dictionnary of dtypes with column names as keys, as admitted bypandas.DataFrame.astype()
.
-
temperature
¶ Temperature in K; can be set as a value-unit pair, with unit any of
'K'
,'C'
and'F'
Type: float
-
time_step
¶ Alias for the
frame_interval
propertyType: float
-
-
class
tramway.analyzer.spt_data.
SPTDataInitializer
(attribute_setter, parent=None)¶ Bases:
tramway.analyzer.attribute.Initializer
Initial value for the
RWAnalyzer
spt_data
attribute.from_… methods alters the parent attribute which specializes into an initialized
SPTData
object.-
from_ascii_file
(filepath)¶ Sets a text file as the source of SPT data.
Note that data loading is NOT performed while calling this method. Loading is postponed until the data is actually required. This lets additional arguments to be provided to the
RWAnalyzer
spt_data
attribute before the data are loaded.See also
StandaloneSPTAsciiFile
.
-
from_ascii_files
(filepattern)¶ Sets text files, which paths match with a pattern, as the source of SPT data.
filepattern is a standard filepath with the
'*'
placeholder. For example: ‘dataset/*.txt’The parts of the filename that match the placeholder are used as keys.
Note that data loading is NOT performed while calling this method. Loading is postponed until the data is actually required. This lets additional arguments to be provided to the
RWAnalyzer
spt_data
attribute before the data are loaded.See also
SPTAsciiFiles
.
-
from_dataframe
(df)¶ See also
StandaloneSPTDataFrame
.
-
from_dataframes
(dfs)¶ See also
SPTDataFrames
.
-
from_mat_file
(filepath)¶ Sets a MatLab V7 file as the source of SPT data.
Similarly to
from_ascii_file()
, data loading is lazy.See also
StandaloneSPTMatFile
.
-
from_mat_files
(filepattern)¶ Sets MatLab V7 files, which paths match with a pattern, as the source of SPT data.
filepattern is a standard filepath with the
'*'
placeholder. For example: ‘datasets/*.txt’The parts of the filename that match the placeholder are used as keys.
Similarly to
from_ascii_files()
, data loading is lazy.See also
SPTMatFiles
.
-
from_rw_generator
(generator)¶ A random walk generator features a
generate()
method.See also
RWGenerator
.
-
from_rwa_file
(filepath)¶ Similar to
from_ascii_file()
, for .rwa files.See also
StandaloneRWAFile
.
-
from_rwa_files
(filepattern)¶ Similar to
from_ascii_files()
, for .rwa files.See also
RWAFiles
.
-
from_tracker
()¶ This initializer method does not need to be called; The
RWAnalyzer
tracker
attribute does this automatically.See also
TrackerOutput
.
-
-
class
tramway.analyzer.spt_data.
HasROI
(roi=<class 'tramway.analyzer.roi.ROIInitializer'>, **kwargs)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
Class to be inherited from by SPT data item classes.
Maintains a self-modifying
roi
attribute.-
_get_roi
()¶ ROI: Regions of interest for the parent data block
-
compatible_source
(source)¶ Returns
True
if filter source matches with self.source.Note
Does not check against the alias.
-
roi
¶ Regions of interest for the parent data block
Type: ROI
-
-
class
tramway.analyzer.spt_data.
HasAnalysisTree
(df=None, **kwargs)¶ Bases:
tramway.analyzer.roi.HasROI
Partial implementation for
SPTData
that complementsSPTParameters
.-
check_cache
(_raise=<class 'AttributeError'>)¶ Checks the parameter cache integrity.
If differences are found with the values in
dataframe
,check_cache()
raises an exception of type _raise.If _raise is
None
orFalse
, thencheck_cache()
returns a bool instead, that isFalse
if the cache is alright,True
otherwise. If _raise isTrue
, thencheck_cache()
returnsTrue
if the cache is alright,False
otherwise.
-
clear_cache
()¶ Clears the cached values and reads from the
dataframe
object.
-
commit_cache
(autoload=False)¶ Pushes the cached parameters into the
dataframe
object.
-
-
class
tramway.analyzer.spt_data.
_SPTDataFrame
(df, source=None, **kwargs)¶ Bases:
tramway.analyzer.spt_data.HasAnalysisTree
,tramway.analyzer.spt_data.SPTParameters
Basis for all concrete
SPTDataItem
classes.-
discard_static_trajectories
(dataframe=None, min_msd=None, **kwargs)¶ The minimum mean-square-displacement is set to the localization error per default.
If an input dataframe is given, then
discard_static_trajectories()
returns the processed dataframe and self does not maintain any copy of it.Otherwise,
discard_static_trajectories()
applies inplace to the internal dataframe and does not return any dataframe. Note that it may set a flag instead of actually processing the internal dataframe, for the parcimonious processing in regions of interest only.
-
mpl
¶ Matplotlib utilities
Type: tramway.analyzer.spt_data.mpl.Mpl
-
set_precision
(precision)¶ Sets the numerical precision of the raw data.
Parameters: precision (dict or str) – any of 'half'
,'single'
,'double'
, or a dictionnary of dtypes with column names as keys, as admitted bypandas.DataFrame.astype()
.
-
to_ascii_file
(filepath, columns=None, header=True, float_format='%.4f', **kwargs)¶ Exports the data to text file.
Beware: whitespaces in the column names should be avoided with
header=True
Parameters: - filepath (str or Path) – output filepath.
- columns (sequence of str) – columns to be exported.
- header (bool) – print column names on the first line.
- float_format (str) – see also
pandas.DataFrame.to_csv()
.
Additional keyword arguments are passed to
pandas.DataFrame.to_csv()
.
-
to_rwa_file
(filepath, **kwargs)¶ Exports the analysis tree to file.
Calls
save_rwa()
with argumentcompress=False
unless explicitly set.
-
-
class
tramway.analyzer.spt_data.
SPTDataFrame
(df, source=None, **kwargs)¶
-
class
tramway.analyzer.spt_data.
StandaloneSPTDataFrame
(df, source=None, **kwargs)¶ Bases:
tramway.analyzer.spt_data._SPTDataFrame
,tramway.analyzer.spt_data.StandaloneDataItem
SPTData
attribute for single dataframes.
-
class
tramway.analyzer.spt_data.
SPTDataFrames
(dfs, **kwargs)¶ Bases:
tramway.analyzer.spt_data.SPTDataIterator
SPTData
attribute for multiple dataframes.
-
class
tramway.analyzer.spt_data.
SPTFile
(filepath, dataframe=None, **kwargs)¶ Bases:
tramway.analyzer.spt_data._SPTDataFrame
Basis for
SPTDataItem
classes for data in a file.-
_trigger_discard_static_trajectories
()¶ Calls
SPTDataFrame.discard_static_trajectories()
; requires the data are already loaded.
-
_trigger_reset_origin
()¶ Calls
SPTDataFrame.reset_origin()
; requires the data are already loaded.
-
alias
¶ Identifier, shorter than
source
Type: str
-
discard_static_trajectories
(dataframe=None, min_msd=None, **kwargs)¶ The minimum mean-square-displacement is set to the localization error per default.
If an input dataframe is given, then
discard_static_trajectories()
returns the processed dataframe and self does not maintain any copy of it.Otherwise,
discard_static_trajectories()
applies inplace to the internal dataframe and does not return any dataframe. Note that it may set a flag instead of actually processing the internal dataframe, for the parcimonious processing in regions of interest only.
-
filepath
¶ Alias for the
source
propertyType: str
-
get_image
(match=None)¶ Looks for the corresponding localization microscopy image in the
images
attribute.The search is based on the object’s alias. The first item that contains the alias in its filename is returned as a match.
If the
alias
attribute is not set or images do not have a defined filepath, anAttributeError
exception is raised.The optional argument match is a 2-argument callable that takes the alias (str) of self and the filepath (str) of an
Image
stack of images, and returnsTrue
if the filepath and alias match.
-
-
class
tramway.analyzer.spt_data.
RawSPTFile
(filepath, dataframe=None, **kwargs)¶ Bases:
tramway.analyzer.spt_data.SPTFile
Basis for
SPTDataItem
classes for raw data in a file, possibly with non-standard column names or data units.
-
class
tramway.analyzer.spt_data.
SPTFiles
(filepattern, **kwargs)¶ Bases:
tramway.analyzer.spt_data.SPTDataFrames
-
alias
¶ Function that extracts an alias out of filepaths (write-only property)
Type: callable
-
aliases
¶ Aliases of the SPT data items (copy)
Type: list of str
-
filepaths
¶ File paths (copy)
Type: list of str
-
filepattern
¶ Filepath glob pattern
Type: str
-
files
¶ SPT file objects
Type: list
-
filter_by_source
(source_filter, return_index=False)¶ Generator function; similar to
__iter__()
; yieldsSPTDataItem
objects.source can be a single str value, or a set of str values, or a sequence of str values (the order is followed), or a callable that takes a str value and returns a bool value.
-
fully_reified
¶ True
if all the files have been loadedType: bool
-
list_files
()¶ Interprets the filepath glob pattern and lists the matching files.
-
partially_reified
¶ True
if any file has been loadedType: bool
-
-
class
tramway.analyzer.spt_data.
RawSPTFiles
(filepattern, **kwargs)¶
-
class
tramway.analyzer.spt_data.
_SPTAsciiFile
(filepath, dataframe=None, **kwargs)¶
-
class
tramway.analyzer.spt_data.
SPTAsciiFile
(filepath, dataframe=None, **kwargs)¶
-
class
tramway.analyzer.spt_data.
StandaloneSPTAsciiFile
(filepath, dataframe=None, **kwargs)¶ Bases:
tramway.analyzer.spt_data._SPTAsciiFile
,tramway.analyzer.spt_data.StandaloneDataItem
RWAnalyzer.spt_data attribute for single SPT text files.
-
class
tramway.analyzer.spt_data.
SPTAsciiFiles
(filepattern, **kwargs)¶ Bases:
tramway.analyzer.spt_data.RawSPTFiles
SPTData
class for multiple SPT text files.-
list_files
()¶ Interprets the filepath glob pattern and lists the matching files.
-
-
class
tramway.analyzer.spt_data.
_RWAFile
(filepath, **kwargs)¶ Bases:
tramway.analyzer.spt_data.SPTFile
-
filepath
¶ .rwa file path; distinct from
source
.Type: str
-
-
class
tramway.analyzer.spt_data.
RWAFile
(filepath, **kwargs)¶
-
class
tramway.analyzer.spt_data.
StandaloneRWAFile
(filepath, **kwargs)¶ Bases:
tramway.analyzer.spt_data._RWAFile
,tramway.analyzer.spt_data.StandaloneDataItem
SPTata
class for single RWA files.
-
class
tramway.analyzer.spt_data.
RWAFiles
(filepattern, **kwargs)¶ Bases:
tramway.analyzer.spt_data.SPTFiles
SPTData
class for multiple RWA files.-
list_files
()¶ Interprets the filepath glob pattern and lists the matching files.
-
reload_from_rwa_files
(skip_missing=False)¶ Reloads the SPT data and analysis tree from the corresponding rwa files.
The rwa file that corresponds to an SPT file should be available at the same path with the .rwa extension instead of the SPT file’s extension.
This method is known to fail with a
TypeError
exception in cases where not any matching .rwa file can be found.Note
As this operation modifies the SPT data source and filepath attributes, aliases should be favored when identifying or filtering SPT data items.
-
-
class
tramway.analyzer.spt_data.
_SPTMatFile
(filepath, dataframe=None, **kwargs)¶ Bases:
tramway.analyzer.spt_data.RawSPTFile
-
coord_scale
¶ Convertion factor for the loaded coordinates so that they read in \(\mu m\)
Type: float
-
pixel_size
¶ Former name for
coord_scale
; deprecatedType: float
-
-
class
tramway.analyzer.spt_data.
SPTMatFile
(filepath, dataframe=None, **kwargs)¶
-
class
tramway.analyzer.spt_data.
StandaloneSPTMatFile
(filepath, dataframe=None, **kwargs)¶ Bases:
tramway.analyzer.spt_data._SPTMatFile
,tramway.analyzer.spt_data.StandaloneDataItem
SPTData
class for single MatLab v7 data files.
-
class
tramway.analyzer.spt_data.
SPTMatFiles
(filepattern, **kwargs)¶ Bases:
tramway.analyzer.spt_data.RawSPTFiles
SPTData
class for multiple MatLab v7 data files.-
coord_scale
¶ Convertion factor for the loaded coordinates so that they read in \(\mu m\)
Type: float
-
list_files
()¶ Interprets the filepath glob pattern and lists the matching files.
-
pixel_size
¶ Former name for
coord_scale
; deprecatedType: float
-
-
class
tramway.analyzer.spt_data.
RWAnalyses
(analyses, copy=False, **kwargs)¶ Bases:
tramway.analyzer.spt_data.StandaloneSPTDataFrame
SPTData
class for single analysis trees as stored in .rwa files.Note
copying (initializing with
copy=True
) copies only the SPT data and NOT the subsequent analyses.Warning
not thouroughly tested.
-
class
tramway.analyzer.spt_data.
MultipleRWAnalyses
(analyses, copy=False, **kwargs)¶ Bases:
tramway.analyzer.spt_data.SPTDataFrames
SPTData
class for multiple analysis trees as stored in .rwa files.Note
copying (initializing with
copy=True
) copies only the SPT data and NOT the subsequent analyses.Warning
not tested.
-
class
tramway.analyzer.spt_data.
RWGenerator
(*args, **kwargs)¶ Bases:
tramway.analyzer.spt_data.SPTDataFrame
not implemented yet
-
class
tramway.analyzer.spt_data.
LocalizationFile
(filepath, dataframe=None, **kwargs)¶
-
class
tramway.analyzer.spt_data.
TrackerOutput
(**kwargs)¶ Bases:
tramway.analyzer.spt_data.SPTDataFrames
SPTData
class for SPT data yielded by thetracker
attribute.-
add_tracked_data
(trajectories, source=None, filepath=None)¶ Note
In most cases source and filepath are supposed to represent the same piece of information. Here, filepath should be preferred over source if the localization data come from a file.
-
filter_by_source
(source_filter, return_index=False)¶ Generator function; similar to
__iter__()
; yieldsSPTDataItem
objects.source can be a single str value, or a set of str values, or a sequence of str values (the order is followed), or a callable that takes a str value and returns a bool value.
-
-
tramway.analyzer.spt_data.
compute_dtypes
(df, precision)¶ Returns a dictionnary of dtypes to align the numerical precision of a
pandas.DataFrame
data.
-
tramway.analyzer.spt_data.
glob
(pattern)¶ Same as
glob.glob()
, with support for tilde.os.path.expanduser()
is applied to pattern, and then the expanded part is replaced back with tilde in the resulting paths.
tramway.analyzer.spt_data.mpl module¶
-
class
tramway.analyzer.spt_data.mpl.
LineDealer
(ax, n=None, colors=['darkgreen', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkviolet', 'deeppink', 'deepskyblue', 'dodgerblue', 'firebrick', 'forestgreen', 'gold', 'goldenrod', 'hotpink', 'indianred', 'indigo', 'lightblue', 'lightcoral', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightsteelblue', 'limegreen', 'maroon', 'mediumaquamarine', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'navajowhite', 'navy', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'purple', '#663399', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'sienna', 'skyblue', 'slateblue', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'yellowgreen'], **kwargs)¶ Bases:
object
Makes glyphs for trajectories to be drawn as lines and keeps track of the trajectories passed to animate so that glyphs are freed as soon as possible and can be assigned to new trajectories.
-
animate
(trajs, dt)¶ Makes the function to be passed as second positional argument to FuncAnimation.
Parameters: - trajs (DataFrame) – trajectories.
- dt (float) – time step.
Returns: function that takes a list of index slices.
Return type: callable
-
init_func
()¶ To be passed as argument init_func to FuncAnimation.
-
plot
(trajs)¶ Updates the glyphs with the active trajectories.
Parameters: trajs (list) – list of active trajectories (dataframes). Returns: sequence of updated glyphs. Return type: tuple
-
tramway.analyzer.roi package¶
-
class
tramway.analyzer.roi.
BaseRegion
(spt_data, label=None, **kwargs)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
This class should not be directly instanciated. It brings basic functionalities to all the available representations of regions of interest, merely labelling and analysis registration.
-
class
tramway.analyzer.roi.
IndividualROI
(spt_data, label=None, **kwargs)¶ Bases:
tramway.analyzer.roi.BaseRegion
for typing only
-
class
tramway.analyzer.roi.
BoundingBox
(bb, label, spt_data, **kwargs)¶ Bases:
tramway.analyzer.roi.IndividualROI
See
BoundingBoxes
.-
crop_frames
(**kwargs)¶ Iterates and crops the image frames.
kwargs are passed to the
Images
crop_frames()
method.
-
-
class
tramway.analyzer.roi.
SupportRegion
(r, regions, spt_data, **kwargs)¶ Bases:
tramway.analyzer.roi.BaseRegion
Union of overlapping ROI.
-
crop_frames
(**kwargs)¶ Iterates and crops the image frames, based on
bounding_box
.kwargs are passed to the
Images
crop_frames()
method.
-
add_metadata
(sampling, inplace=False)¶ Modifies sampling or returns a modified copy of sampling.
In both cases, returns the resulting
Partition
object.
-
add_sampling
(sampling, label=None, comment=None, metadata='inplace')¶ If
metadata=='inplace'
(default), sampling is modified to store ROI-related information.Pass
metadata=True
instead to store a copy of sampling in the analysis tree. Note however that sampling is copied only if modified.
-
-
class
tramway.analyzer.roi.
FullRegion
(spt_data, label=None, **kwargs)¶ Bases:
tramway.analyzer.roi.BaseRegion
Wraps the full dataset; does not actually crop.
A FullRegion can be both an individual ROI and a support region.
-
crop_frames
(**kwargs)¶ Note
Time cropping is not supported yet.
-
-
class
tramway.analyzer.roi.
DecentralizedROIManager
(first_record=None, **kwargs)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
This class allows to iterate over the ROI defined at the level of each SPT data item.
-
as_individual_roi
(index=None, collection=None, source=None, **kwargs)¶ Generator function; loops over all the individual roi.
Filtering is delegated to the individual SPTDataItem.roi attributes.
A callable filter takes a single key (int for indices, str for labels and paths) and returns a bool.
Parameters: - index (int, set of int, sequence of int, or callable) – individual ROI index filter; indices apply within a collection
- collection (str, set of str, sequence of str, or callable) – collection label filter
- source (str, set of str, sequence of str, or callable) – SPT data source filter
-
as_support_regions
(index=None, source=None, **kwargs)¶ Generator function; loops over all the support regions.
Support regions are equivalent to individual ROI if group_overlapping_roi was set to
False
.Filtering is delegated to the individual SPT data block
roi
attributes.A callable filter takes a single key (int for indices, str for paths) and returns a bool.
Parameters: - index (int, set of int, sequence of int, or callable) – support region index filter
- source (str, set of str, sequence of str, or callable) – SPT data source filter
-
-
class
tramway.analyzer.roi.
ROIInitializer
(attribute_setter, parent=None)¶ Bases:
tramway.analyzer.attribute.Initializer
Initial value for the
RWAnalyzer
roi
attribute.from_… methods alters the parent attribute which specializes into an initialized
ROI
object.-
from_bounding_boxes
(bb, label=None, group_overlapping_roi=False)¶ Defines ROI as bounding boxes.
Parameters: - bb (sequence) – collection of bounding boxes, each bounding boxes being a pair of lower and upper bounds (numpy.ndarray)
- label (str) – unique label for the collection
- group_overlapping_roi (bool) – if
False
,as_support_regions()
will behave similarly toas_individual_roi()
, otherwise support regions are unions of overlapping ROI
See also
BoundingBoxes
.
-
from_squares
(centers, side, label=None, group_overlapping_roi=False)¶ Defines spatial ROI as centers for squares/cubes of uniform size.
Centers should be provided as a sequence of
ndarray
or an NxD matrix, with D the number of spatial dimensions.See also
from_bounding_boxes()
.
-
from_ascii_file
(filepath, size=None, label=None, group_overlapping_roi=False)¶ Reads the ROI centers or bounds from a text file.
Note
This initializer can only be called from the decentralized
roi
attribute of anSPTDataItem
item of theRWAnalyzer
spt_data
main attribute.See also
ROIAsciiFile
.
-
from_ascii_files
(suffix='roi', extension='.txt', size=None, label=None, group_overlapping_roi=False, skip_missing=False)¶ Reads the ROI centers or bounds from text files – one file per item in
spt_data
.The file paths are inferred from the SPT data source files (source attribute). Files are looked for in the same directories as the corresponding SPT data file, and are expected to be named with the same basename, plus a suffix and the .txt extension.
A hyphen or underscore character is automatically appended left of the suffix if necessary.
If the source attribute of the
SPTDataItem
items is not defined, aValueError
exception is raised.Note
Calling this initializer method from a satellite roi attribute (nested in an
SPTDataItem
data block) is equivalent to calling the same initializer from theRWAnalyzer
roi
main attribute.See also
ROIAsciiFiles
.
-
from_dedicated_rwa_record
(label=None, version=None, **kwargs)¶ See also
v1_ROIRecord
andv2_ROIRecord
.
-
from_dedicated_rwa_records
(label=None, version=None, _impl=None)¶ See also
ROIRecords
.
-
as_support_regions
(index=None, source=None, return_index=False)¶ Generator function; loops over all the support regions.
A
ROIInitializer
attribute object does not define any ROI, as a consequence a singleFullRegion
object is yielded.
-
as_individual_roi
(index=None, collection=None, source=None, **kwargs)¶ Generator function; loops over all the individual ROI.
A
ROIInitializer
does not define any ROI, as a consequence a singleFullRegion
object is yielded.
-
-
class
tramway.analyzer.roi.
CommonROI
(roi, parent=None)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
Mirrors the global
roi
attribute.The individual SPTDataItem.roi attributes become
CommonROI
objects as soon as the globalroi
attribute is specialized, so thatas_support_regions()
andas_individual_roi()
iterators delegate to the global attribute.-
to_ascii_file
(filepath, collection=None, **kwargs)¶ Exports the regions of interest to a text file.
Parameters: - filepath (str or Path) – output filepath.
- collection (str) – roi collection label.
All keyword arguments are passed to the common ROI object’s to_ascii_file method. See for example
BoundingBoxes.to_ascii_file()
.
-
-
class
tramway.analyzer.roi.
SpecializedROI
(**kwargs)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
Basis for initialized
ROI
classes.-
as_support_regions
(index=None, source=None, return_index=False)¶ Generator function; iterates over the support regions.
Support regions are the regions to be processed. An individual ROI operates as a window on a support region.
-
get_support_region
(index, collection=None)¶ Returns the
SupportRegion
object corresponding to an individual ROI.Note
When using individual ROI indices and the parallelization capability of
pipeline
, beware thatas_individual_roi()
is not controlled by the proper filters, unlikeas_support_regions()
, in all the possible implementations.get_support_region()
may still be called on workers assigned to processing other regions and consequently raise aRuntimeError
exception.
-
-
class
tramway.analyzer.roi.
BoundingBoxes
(bb, label=None, group_overlapping_roi=False, **kwargs)¶ Bases:
tramway.analyzer.roi.SpecializedROI
Bounding boxes are a list of pairs of NumPy row arrays (1xD).
The first array specifies the lower bounds, the second array the upper bounds.
-
as_individual_roi
(index=None, collection=None, source=None, return_index=False)¶ Generator function; iterates over the individual ROI.
index is the index in the collection and collection should be defined if multiple collections of ROI are defined.
Note
Iterating over the individual ROI may be useful for visualization; favor
as_support_regions()
for data processing.
-
index_format
¶ Format of the numeric part of the label
Type: str
-
set_num_digits
(n)¶ Sets the number of digits in the numeric part of the label.
-
to_ascii_file
(filepath, collection=None, columns=None, header=True, float_format='%.4f', **kwargs)¶ Exports the bounding boxes to text file.
Parameters: - filepath (str or Path) – output filepath.
- collection (str) – roi collection label.
- columns (sequence of str) – column names; default is: [‘x’, ‘y’] for 2D, [‘x’, ‘y’, ‘t’] for 3D and [‘x’, ‘y’, ‘z’, ‘t’] for 4D.
- header (bool) – print column names on the first line.
- float_format (str) – see also
pandas.DataFrame.to_csv()
.
Additional keyword arguments are passed to
pandas.DataFrame.to_csv()
.
-
-
class
tramway.analyzer.roi.
ROIAsciiFile
(path, size=None, label=None, group_overlapping_roi=False, **kwargs)¶ Bases:
tramway.analyzer.roi.BoundingBoxes
ROI
class for the decentralizedHasROI.roi
attributes to be loaded from text files.A ROI file contains tab-separated columns with a header line.
The columns represent either centers or bounds.
ROI center information is formed by
'x'
and'y'
columns (and optionally'z'
but not't'
).ROI bounds are defined by two columns for each coordinate, for example labelled
'x min'
and'x max'
for coordinate x. Time can also be represented this way.Note that combining spatial center information and time bounds is allowed, i.e.
'x'
,'y'
,'t min'
and't max'
.The center information from a ROI file must be complemented with the size argument/attribute.
-
reified
¶ True
if the files have been loadedType: bool
-
filepath
¶ Path of the ROI file
Type: str
-
size
¶ ROI size for space components; apply solely to center-defined ROI
Type: float
-
as_support_regions
(*args, **kwargs)¶ Generator function; iterates over the support regions.
Support regions are the regions to be processed. An individual ROI operates as a window on a support region.
-
-
class
tramway.analyzer.roi.
ROIAsciiFiles
(suffix='roi', extension='.txt', side=None, label=None, group_overlapping_roi=False, skip_missing=False, **kwargs)¶ Bases:
tramway.analyzer.roi.DecentralizedROIManager
ROI
class for multiple ROI text files.The filepaths are inferred from the
source
attribute of eachSPTDataItem
in the mainspt_data
attribute. The SPT file extensions are replaced by a suffix (usually -roi) plus the .txt extension.See also
ROIAsciiFile
for more information on the format.
-
class
tramway.analyzer.roi.
v1_ROIRecord
(label=None, _impl=None, **kwargs)¶ Bases:
tramway.analyzer.roi.BoundingBoxes
ROI
class for the individual special partitions in an analysis tree.This storing strategy is likely to be marked as deprecated.
-
reified
¶ True
if the files have been loadedType: bool
-
as_support_regions
(*args, **kwargs)¶ Generator function; iterates over the support regions.
Support regions are the regions to be processed. An individual ROI operates as a window on a support region.
-
-
class
tramway.analyzer.roi.
ROIRecoveredFromSampling
(label=None, group_overlapping_roi=False, **kwargs)¶ Bases:
tramway.analyzer.roi.BoundingBoxes
ROI
class that recovers bounding-box information from the sampling (Partition
records) found in the analysis tree, provided that the records are labelled the default way, i.e. with no label or a static label prefix.The bounding boxes are inferred from the data and, if a sliding time window was defined, from the windowing start time. If the SPT data are location or trajectory data, they are converted into translocation data prior to determining the spatial bounding box.
The resulting bounding boxes may be tighter than the original bounding boxes, but the sampling should not be affected. This may work only if the original ROI were defined with group_overlapping_roi=False for the sampling step.
A major drawback of this approach lies in the fact that ROI centers cannot be recovered, as they are usually implicitly encoded in the bounds (middle point).
A word of warning, though: the procedure of determining the bounding boxes loads all the data from the .rwa files, if the analysis trees are to be loaded from files.
As the name hints, this class was designed for recovering ROI information in the cases this information is no longer available elsewhere.
-
reified
¶ True
if the files have been loadedType: bool
-
as_support_regions
(*args, **kwargs)¶ Generator function; iterates over the support regions.
Support regions are the regions to be processed. An individual ROI operates as a window on a support region.
-
-
tramway.analyzer.roi.
v2_ROIRecord
¶
-
class
tramway.analyzer.roi.
ROIRecords
(label=None, version=None, _impl=None, **kwargs)¶ Bases:
tramway.analyzer.roi.DecentralizedROIManager
ROI
class for the mainroi
attribute.See also the corresponding item class:
version=1
:v1_ROIRecord
for analysis trees with a meta-partition- for each ROI collection;
version=2
:v2_ROIRecord
to recover ROI definition from the- the sampling/partition records available in the analysis trees without any extra information (no meta-partition).
-
class
tramway.analyzer.roi.
HasROI
(roi=<class 'tramway.analyzer.roi.ROIInitializer'>, **kwargs)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
Class to be inherited from by SPT data item classes.
Maintains a self-modifying
roi
attribute.-
roi
¶ Regions of interest for the parent data block
Type: ROI
-
compatible_source
(source)¶ Returns
True
if filter source matches with self.source.Note
Does not check against the alias.
-
-
class
tramway.analyzer.roi.
ROI
¶ Bases:
tramway.analyzer.attribute.abc.Attribute
Abstract base class for the
roi
attribute of anRWAnalyzer
object.-
as_individual_roi
(index=None, collection=None)¶ Generator function; iterates over the individual ROI.
index is the index in the collection and collection should be defined if multiple collections of ROI are defined.
Note
Iterating over the individual ROI may be useful for visualization; favor
as_support_regions()
for data processing.
-
as_support_regions
(index=None)¶ Generator function; iterates over the support regions.
Support regions are the regions to be processed. An individual ROI operates as a window on a support region.
-
tramway.analyzer.roi.utils module¶
-
tramway.analyzer.roi.utils.
set_contiguous_time_support_by_count
(points, space_bounds, time_window, min_points, min_segments=1, group_overlapping_roi=False, start_stop_min_points=None)¶ Parameters: - points (DataFrame) – location or translocation data
- space_bounds (dict or sequence) – (collections of) boundaries, each boundary being a pair of NumPy arrays (lower, upper)
- time_window (float or pair of floats) – window duration or window duration and shift
- min_points (int) – desired minimum number of data rows per time segment
- min_segments (int) – desired minimum number of selected time segments.
- group_overlapping_roi (bool) – see
RoiCollections
Returns: - similar to points, with an additional column for time
in each bound array.
Return type: dict or list
-
tramway.analyzer.roi.utils.
group_roi
(a, *args, overlap=0.75, return_matches_only=False)¶ Returns the smallest rectangles that contain the ROI grouped depending on whether they overlap or not.
A ROI should be a pair (tuple) of numpy.ndarray for (lower-,upper-) bounds.
Time is handled just like any space coordinate. As a consequence, if time bounds are also specified, the corresponding values should be scaled so that time can be artificially related to space in the volume calculation carried out in the estimatation of the amount of overlap.
-
tramway.analyzer.roi.utils.
distance_to_roi_center
(roi_obj, sampling)¶ Parameters: - roi_obj (IndividualROI) – ROI object
- sampling (Partition or Analysis) – tessellation
Returns: distance between each cell center and the ROI center
Return type: ndarray
tramway.analyzer.tesseller package¶
-
class
tramway.analyzer.tesseller.
TessellerInitializer
(attribute_setter, parent=None)¶ Bases:
tramway.analyzer.attribute.Initializer
Initializer class for the
RWAnalyzer
tesseller
main attribute.The
tesseller
attribute self-modifies on calling any of the from_… methods.The easiest way to define a tesseller is to set the
tesseller
attribute with any of the tesseller classes provided by thetessellers
module:from tramway.analyzer import * a = RWAnalyzer() a.tesseller = tessellers.KMeans
Note that
tessellers
is made available by importingtramway.analyzer
.-
from_callable
(cls)¶ Argument:
- cls (callable):
- no-argument callable object (usually a class)
that returns a
Tesseller
object.
-
mpl
¶ Matplotlib utilities
Type: tramway.analyzer.tesseller.mpl.Mpl
-
-
class
tramway.analyzer.tesseller.
Tesseller
¶ Bases:
tramway.analyzer.attribute.abc.Attribute
Abstract base class for the
tesseller
attribute of anRWAnalyzer
object.-
resolution
¶ Desired spatial resolution in \(\mu m\)
Type: float
-
-
class
tramway.analyzer.tesseller.
TessellerProxy
(cls, **kwargs)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
Encapsulates a tessellation plugin as defined in the
tramway.tessellation
package.Attributes are managed with the following rules:
- if an attribute is set using a proxy property,
the value is flagged as
'explicit'
and overrides any default value; - the arguments in
_init_kwargs
are passed to the wrapped tesseller’s__init__()
; these arguments are intended to prevent__init__()
from crashing if the later requires some arguments to be defined; non-explicit values are likely to be overriden and both explicit and non-explicit values may be altered by__init__()
; - the arguments in
_tessellate_kwargs
are passed to the wrapped tesseller’stessellate()
method; all available arguments should be defined in the proxy’s__init__()
, with default values; - the wrapped tesseller’s attributes can be accessed using proxy properties;
as a consequence, any key in
_explicit_kwargs
, that is not in_init_kwargs
or_tessellate_kwargs
, is considered as an actual attribute; - an argument should not be defined both in
_init_kwargs
and_tessellate_kwargs
; - explicit
__init__()
arguments take precedence over standard attributes;
-
reset
(clear_explicit_attrs=False)¶ resets the tesseller to let the calibration parameters vary.
-
helper_cls
¶ Tessellation helper class, inheriting from
tramway.helper.tessellation.Tessellate
Type: type
-
tessellate
(spt_dataframe)¶ Grows and returns the tessellation.
-
mpl
¶ Matplotlib utilities
Type: tramway.analyzer.tesseller.mpl.Mpl
- if an attribute is set using a proxy property,
the value is flagged as
-
class
tramway.analyzer.tesseller.
TessellerPlugin
(name, **kwargs)¶ Bases:
tramway.analyzer.tesseller.proxy.TessellerProxy
Wraps any plugin referenced in tramway.tessellation.plugins.
-
class
tramway.analyzer.tesseller.
TessellationPostProcessing
¶ Bases:
tramway.analyzer.attribute.abc.Attribute
Abstract base class for the
post
attribute of aTesseller
object.
tramway.analyzer.tesseller.proxy module¶
-
class
tramway.analyzer.tesseller.proxy.
TessellerProxy
(cls, **kwargs)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
Encapsulates a tessellation plugin as defined in the
tramway.tessellation
package.Attributes are managed with the following rules:
- if an attribute is set using a proxy property,
the value is flagged as
'explicit'
and overrides any default value; - the arguments in
_init_kwargs
are passed to the wrapped tesseller’s__init__()
; these arguments are intended to prevent__init__()
from crashing if the later requires some arguments to be defined; non-explicit values are likely to be overriden and both explicit and non-explicit values may be altered by__init__()
; - the arguments in
_tessellate_kwargs
are passed to the wrapped tesseller’stessellate()
method; all available arguments should be defined in the proxy’s__init__()
, with default values; - the wrapped tesseller’s attributes can be accessed using proxy properties;
as a consequence, any key in
_explicit_kwargs
, that is not in_init_kwargs
or_tessellate_kwargs
, is considered as an actual attribute; - an argument should not be defined both in
_init_kwargs
and_tessellate_kwargs
; - explicit
__init__()
arguments take precedence over standard attributes;
-
helper_cls
¶ Tessellation helper class, inheriting from
tramway.helper.tessellation.Tessellate
Type: type
-
mpl
¶ Matplotlib utilities
Type: tramway.analyzer.tesseller.mpl.Mpl
-
reset
(clear_explicit_attrs=False)¶ resets the tesseller to let the calibration parameters vary.
-
tessellate
(spt_dataframe)¶ Grows and returns the tessellation.
- if an attribute is set using a proxy property,
the value is flagged as
-
tramway.analyzer.tesseller.proxy.
proxy_property
(propname, level='default', doc=None)¶ Property factory function similar to builtin property, dedicated to the
TessellerProxy
class.For
'tessellate'
level properties, the default level is safe.For
'__init__'
level properties, the level must be specified.For standard attributes, it is safer to make the level explicit, so that some conflicts may be detected earlier (e.g. at module loading).
-
class
tramway.analyzer.tesseller.proxy.
FreeResolutionTesseller
(cls, **kwargs)¶
tramway.analyzer.tesseller.proxied module¶
This module is exported by the tramway.analyzer
package
as tessellers.
-
class
tramway.analyzer.tesseller.proxied.
Squares
(**kwargs)¶ Bases:
tramway.analyzer.tesseller.proxy.FreeResolutionTesseller
Wraps
tramway.tessellation.grid.RegularMesh
.-
avg_distance
¶ Average distance between adjacent square centers or, equivalently, average square size; ignored if
avg_probability
is definedType: float
-
avg_probability
¶ Average probability for a point to fall within any given square
Type: float
-
count_per_dim
¶ Number of squares per space dimension
Type: int
-
lower_bound
¶ Scaled lower space bounds
Type: ndarray or Series
-
min_distance
¶ Minimum distance between adjacent square centers or, equivalently, minimum square size; ignored if
avg_distance
is definedType: float
-
upper_bound
¶ Scaled upper space bounds
Type: ndarray or Series
-
-
class
tramway.analyzer.tesseller.proxied.
Hexagons
(**kwargs)¶ Bases:
tramway.analyzer.tesseller.proxy.FreeResolutionTesseller
Wraps
tramway.tessellation.hexagon.HexagonalMesh
.-
avg_distance
¶ Average distance between adjacent hexagon centers or, equivalently, average diameter of the inscribed circle; ignored if
avg_probability
is definedType: float
-
avg_probability
¶ Average probability for a point to fall within any given hexagon
Type: float
-
lower_bound
¶ Scaled lower space bounds
Type: ndarray or Series
-
min_distance
¶ Minimum distance between adjacent hexagon centers or, equivalently, minimum diameter of the inscribed circle; ignored if
avg_distance
is definedType: float
-
tilt
¶ Angle of the “main” axis, in \(\frac{\pi}{6}\) radians; 0= the main axis is the x-axis; 1= the main axis is the y-axis
Type: float
-
upper_bound
¶ Scaled upper space bounds
Type: ndarray or Series
-
-
class
tramway.analyzer.tesseller.proxied.
KMeans
(**kwargs)¶ Bases:
tramway.analyzer.tesseller.proxy.FreeResolutionTesseller
Wraps
tramway.tessellation.kmeans.KMeansMesh
.-
avg_distance
¶ Average distance between adjacent cell centers; affects the
'grid'
initialization onlyType: float
-
avg_probability
¶ Average probability for a point to fall within any given cell
Type: float
-
initial
¶ Any of
'grid'
(default),'random'
and'center'
;'grid'
usesSquares
to initialize the cell centers;'random'
randomly samples the initial cell centers;'center'
is similar to'random'
but confines the random cell centers within a tiny area in the middleType: str
-
min_distance
¶ Minimum distance between adjacent cell centers; affects the
'grid'
initialization onlyType: float
-
prune
¶ Maximum edge length for the Voronoi graph, relative to the median edge length; if
True
, defaults to2.5
; the edges that exceed the derived threshold value are prunedType: bool or float
-
tol
¶ Error tolerance; passed as thresh to
scipy.cluster.vq.kmeans()
Type: float
-
-
class
tramway.analyzer.tesseller.proxied.
GWR
(**kwargs)¶ Bases:
tramway.analyzer.tesseller.proxy.TessellerProxy
Wraps
tramway.tessellation.gwr.GasMesh
.-
alpha_risk
¶ Threshold p-value in the comparison between distance distributions to determine whether the edges that are not in the Delaunay graph are still valid
Type: float
-
batch_size
¶ Number of points per epoch; this merely affects the node merging mechanism triggered between epochs
Type: int
-
collapse_tol
¶ Maximum ratio of the number of collapsed nodes over the total number of nodes
Type: float
-
complete_delaunay
¶ Use the Delaunay graph instead, for determining the cell adjacency; default is
True
Type: bool
-
error_count_tol
¶ Maximum rate of errors as defined by
residual_factor
and the batch size; as long as the rate does not fall below this threshold value,tessellate()
keeps on sampling batchesType: float
-
lifetime
¶ Edge lifetime in number of iterations; taken as absolute, if greater than 1; otherwise relative to the number of nodes in the graph
Type: float
-
min_growth
¶ Minimum relative increase in the number of nodes
Type: float
-
min_probability
¶ Minimum probability for a point to fall within any given cell
Type: float
-
pass_count
¶ Number of points to sample (with replacement), as a multiple of the total size of the data; a pair of values denotes the lower and upper bounds on the number of points; a single value is interpreted as the lower bound, and the upper bound is then set equal to
2 * pass_count
Type: float or (float, float)
-
residual_factor
¶ Maximum residual for each sample point, relative to
_max_distance
Type: float
-
tau
¶ Habituation scaling factor, in number of iterations, for the nearest and second nearest nodes respectively
Type: float or (float, float)
-
tessellate
(spt_dataframe)¶ Grows and returns the tessellation.
-
topology
¶ Any of
'approximate density'
and'displacement length'
(default for trajectory/translocation data)Type: str
-
trust
¶ Confidence in outstanding points to become new nodes; the new node is set as \(\frac{(1-\rm{trust})*w + (1+\rm{trust})*\eta}{2}\); the original GWR algorithm corresponds to
trust = 0
Type: float
-
verbose
¶ Verbose mode; default is
False
Type: bool
-
tramway.analyzer.tesseller.plugin module¶
-
class
tramway.analyzer.tesseller.plugin.
TessellerPlugin
(name, **kwargs)¶ Bases:
tramway.analyzer.tesseller.proxy.TessellerProxy
Wraps any plugin referenced in tramway.tessellation.plugins.
-
tramway.analyzer.tesseller.plugin.
tesseller_plugin
(name)¶ Translate plugin names into RWAnalyzer-ready tessellers as defined in the tessellers module, if available, else returns a generic TessellerPlugin initializer.
tramway.analyzer.tesseller.post package¶
-
class
tramway.analyzer.tesseller.post.
TessellationPostProcessingInitializer
(attribute_setter, parent=None)¶ Bases:
tramway.analyzer.attribute.Initializer
Initializer class for attribute
tesseller
post
.For now, a single use case is available:
a = RWAnalyzer() # initialize attribute `tesseller` a.tesseller = tessellers.KMeans # .. so that attribute `post` is exposed a.tesseller.post = cell_mergers.ByTranslocationCount # .. and now `tesseller.post` is initialized a.tesseller.post.count_threshold = 20
Note that
cell_mergers
is exported by thetramway.analyzer
module, just liketessellers
.See also
ByTranslocationCount
.-
from_callable
(cls)¶ Argument:
- cls (callable):
- no-argument callable object (usually a class) that returns a
TessellationPostProcessing
object.
-
tramway.analyzer.tesseller.post.merger module¶
This module is exported by the tramway.analyzer
package
as cell_mergers.
-
class
tramway.analyzer.tesseller.post.merger.
ByTranslocationCount
(**kwargs)¶ Bases:
tramway.analyzer.tesseller.post.merger.CellMerger
Merges the cells/microdomains that exhibit a number of translocations below some threshold.
Note
For now, all locations are counted instead of translocations only.
tramway.analyzer.tesseller.mpl module¶
-
class
tramway.analyzer.tesseller.mpl.
Mpl
(parent=None)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
Matplotlib plotting utilities for 2D data; no time support.
-
animate
(fig, sampling, axes=None, voronoi_options={}, location_options={}, **kwargs)¶ As this method is of limited interest, it has been poorly tested.
The RWAnalyzer.time attribute is accessed.
-
plot
(tessellation, locations=None, axes=None, voronoi_options={}, delaunay_options=None, location_options={}, **kwargs)¶ Plot the particle locations and the Voronoi graph (or tessellation).
plot does not access any RWAnalyzer attribute and can be safely called with no side effect.
-
plot_cell_indices
(tessellation, axes=None, voronoi_options={}, delaunay_options=None, aspect='equal', title=None, **kwargs)¶ Plot the Voronoi graph and Voronoi cell indices.
The placement of the text elements is not optimized.
-
tramway.analyzer.time package¶
-
class
tramway.analyzer.time.
DT
¶ Bases:
object
Implements the default behavior of methods common to the initializer and the specialized attributes.
It gives access to the frame interval (the
dt
andtime_step
attributes are aliases offrame_interval
), and features theas_time_segments()
slicer.The default implementation suits the initializer’s behavior, i.e. a single all-in time segment.
-
enable_regularization
()¶ This method is called before running the inference plugins that define time_prior parameters.
-
n_time_segments
(sampling)¶ Returns the number of time segments (int) that sampling includes, under the hypothesis that sampling was generated following this segments definition (self).
-
as_time_segments
(sampling, maps=None, index=None, return_index=False, return_times=True)¶ Generator function; yields single-segment sampling and map objects.
Slices sampling and maps and yields tuples with elements in the following order:
- segment index (int), if return_index is
True
, - segment start and stop times (float, float), if return_times is
True
(default), - segment
Partition
object, from sampling, - segment maps (pandas.DataFrame) from maps, if maps is defined.
index is a selector on the segment index, either as an int, a set of int, a sequence of int, or a callable that takes a segment index (int) as input argument and returns a bool.
- segment index (int), if return_index is
-
frame_interval
¶ See
frame_interval
Type: float
-
get_spatial_segmentation
(sampling, segment=None)¶ Returns the spatial tessellation.
-
-
class
tramway.analyzer.time.
TimeInitializer
(*args, **kwargs)¶ Bases:
tramway.analyzer.attribute.Initializer
,tramway.analyzer.time.DT
Initializer
Time
class for theRWAnalyzer
time
main attribute.The
time
attribute self-modifies on calling from_… methods.-
from_sliding_window
(duration=None, shift=None)¶ Defines a sliding time window.
Parameters: - duration (float) – window duration in seconds
- shift (float) – time shift between successive segments, in seconds; by default, equals to duration
See also
SlidingWindow
.
-
from_sampling
(sampling=None, verbose=False)¶ Extracts the time segmentation parameters stored in a
Partition
object and tries to initialize the parenttime
attribute correspondingly.This may fail, either silently or raising a
ValueError
exception, as this method covers only cases of sliding windows.If argument sampling is not an Analysis or Partition object, it is taken as the label of an artefact in any analysis tree.
-
-
class
tramway.analyzer.time.
SlidingWindow
(duration=None, shift=None, **kwargs)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
,tramway.analyzer.time.DT
Specialization for the
time
attribute.Defines the
segment()
method that segments the SPT data into time segments and combines with the spatial tessellation.-
duration
¶ Window duration in seconds
Type: float
-
shift
¶ Time shift between successive time segments, in seconds
Type: float
-
start_time
¶ Start time for running the sliding window. By default, the window starts from the first data point in the input data (usually the ROI-cropped data, NOT the entire SPT dataset).
Type: float
-
sync_start_times
()¶ aligns the start times of all the ROI to the same minimum time.
Beware this may load all the SPT data files. Setting the
bounds
attribute of thespt_data
main attribute discards the need for screening the SPT data.
-
segment
(spt_dataframe, tessellation=None)¶ Segments the SPT data, combines the segmentation with a spatial tessellation if any, and returns a
TimeLattice
object.
-
enable_regularization
()¶ This method is called before running the inference plugins that define time_prior parameters.
-
regularize_in_time
¶ True
if time regularization is enabledType: bool
-
get_time_segments
(sampling)¶ Returns the time segment bounds as an Nx2 array.
-
get_spatial_segmentation
(sampling, segment=None)¶ Returns the spatial tessellation.
-
n_time_segments
(sampling)¶ Returns the number of time segments (int) that sampling includes, under the hypothesis that sampling was generated following this segments definition (self).
-
as_time_segments
(sampling, maps=None, index=None, return_index=False, return_times=True)¶ Generator function; yields single-segment sampling and map objects.
Slices sampling and maps and yields tuples with elements in the following order:
- segment index (int), if return_index is
True
, - segment start and stop times (float, float), if return_times is
True
(default), - segment
Partition
object, from sampling, - segment maps (pandas.DataFrame) from maps, if maps is defined.
index is a selector on the segment index, either as an int, a set of int, a sequence of int, or a callable that takes a segment index (int) as input argument and returns a bool.
- segment index (int), if return_index is
-
segment_label
(map_label, times, sampling)¶ Makes a label combining the input label as prefix and time-related suffix.
-
-
class
tramway.analyzer.time.
Time
¶ Bases:
tramway.analyzer.attribute.abc.Attribute
Abstract base class for the
time
attribute of anRWAnalyzer
object.-
segment
(spt_dataframe, tessellation=None)¶ Segments the SPT data, combines the segmentation with a spatial tessellation if any, and returns a
TimeLattice
object.
-
as_time_segments
(sampling, maps=None, index=None, return_index=False, return_times=True)¶ Generator function; yields single-segment sampling and map objects.
Slices sampling and maps and yields tuples with elements in the following order:
- segment index (int), if return_index is
True
, - segment start and stop times (float, float), if return_times is
True
(default), - segment
Partition
object, from sampling, - segment maps (pandas.DataFrame) from maps, if maps is defined.
index is a selector on the segment index, either as an int, a set of int, a sequence of int, or a callable that takes a segment index (int) as input argument and returns a bool.
- segment index (int), if return_index is
-
tramway.analyzer.sampler package¶
-
class
tramway.analyzer.sampler.
BaseSampler
(**kwargs)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
wraps the Partition.cell_index logics that readily implements all the possibilities mentioned in this module.
-
min_location_count
¶ Minimum number of assigned (trans-)locations, as given by the default Voronoi sampling; any microdomain with too few assigned (trans-)locations are marked as disabled and are excluded from further analyses
Type: int
-
-
class
tramway.analyzer.sampler.
VoronoiSampler
(**kwargs)¶ Bases:
tramway.analyzer.sampler.BaseSampler
nearest neighbor assignment.
Each data point is assigned to exactly one cell/microdomain.
-
class
tramway.analyzer.sampler.
SamplerInitializer
(attribute_setter, parent=None)¶ Bases:
tramway.analyzer.attribute.Initializer
Initializer class for the
RWAnalyzer
sampler
main attribute.The
sampler
attribute self-modifies on calling any of the from_… methods.The default not-initialized
sampler
attribute behaves like:a = RWAnalyzer() a.sampler.from_voronoi()
-
from_voronoi
()¶ default sampler.
The data points are assigned to the nearest cell/microdomain.
See also
VoronoiSampler
.
-
from_spheres
(radius)¶ nearest neighbor assignment by distance.
Voronoi assignment is applied first and then, for each microdomain, the maximum distance of the assigned points to the center of the cell is considered. The radius argument defines a lower and/or upper bound(s) on the distance from the cell center. If the most distant assigned point is out of the specified bounds, additional points are selected (or assigned points are discarded) in order of distance from the corresponding cell center.
See also
SphericalSampler
.
-
from_nearest_neighbors
(knn)¶ nearest neighbor assignment by count.
The Voronoi assignment is applied first. The knn argument defines a lower and/or upper bound(s) on the number of neighbors. For each microdomain, if the number that results from Voronoi assignment is out of the specified bounds, additional points are selected (or assigned points are discarded) in order of distance from the corresponding cell center.
See also
Knn
.
-
from_nearest_time_neighbors
(knn)¶ similar to from_nearest_neighbors but cell/microdomain size is adjusted in time instead of space.
See also
TimeKnn
.
-
sample
(spt_data, segmentation=None)¶ main processing method.
-
-
class
tramway.analyzer.sampler.
SphericalSampler
(radius, **kwargs)¶ Bases:
tramway.analyzer.sampler.BaseSampler
nearest neighbor selection by distance.
-
radius
¶ Lower bound or (lower bound, upper bound) pair on the distance from a cell/microdomain center; alternatively, a function can define these bounds for each microdomain (takes the microdomain index as input argument)
Type: float or (float, float) or callable
-
-
class
tramway.analyzer.sampler.
Knn
(knn, **kwargs)¶ Bases:
tramway.analyzer.sampler.BaseSampler
nearest neighbor selection by count.
-
knn
¶ Lower bound or (lower bound, upper bound) pair on the number of data points which, if Voronoi assignment yields a number out of these bounds, triggers a procedure that picks extra points (or discards assigned points) wrt distance from the Voronoi cell center. This applies independently for each microdomain with insufficient or too many points. Alternatively, bounds can be defined on a per-microdomain basis with a function that takes the microdomain index as an int and returns either an int or a pair of int or
None
Type: int or (int, int) or callable
-
-
class
tramway.analyzer.sampler.
TimeKnn
(knn, **kwargs)¶ Bases:
tramway.analyzer.sampler.BaseSampler
nearest neighbor selection by count across time.
-
knn
¶ Lower bound or (lower bound, upper bound) pair on the number of data points which, if Voronoi assignment yields a number out of these bounds, triggers the shrinking or widening of the time window, centered on the original middle point of the time segment. This applies independently for each microdomain with insufficient or too many points. microdomain with insufficient or too many points. Alternatively, bounds can be defined on a per-microdomain basis with a function that takes the microdomain index as an int and returns either an int or a pair of int or
None
Type: int or (int, int) or callable
-
-
class
tramway.analyzer.sampler.
Sampler
¶ Bases:
tramway.analyzer.attribute.abc.Attribute
Abstract base class for the
sampler
attribute of anRWAnalyzer
object.
tramway.analyzer.mapper package¶
-
class
tramway.analyzer.mapper.
MapperInitializer
(attribute_setter, parent=None)¶ Bases:
tramway.analyzer.attribute.Initializer
,tramway.analyzer.mapper.plugin.MapperAttribute
-
from_maps
(label_or_maps=None, exclude_attrs=(), verbose=False)¶ Sets the mapper up on basis of parameters in a Maps object.
If a label is passed instead of a Maps object (or nothing), the corresponding artefact is sought for in the analysis tree, starting from the first branch (first sampling) in the first tree.
This method has been designed for the stochastic.dv plugin. Application to other plugins has not been tested.
Parameters: - label_or_maps (Maps or Analysis or int or str or tuple or list) – maps object or label(s) of the maps artefact to be found in any registered analysis tree
- exclude_attrs (iterable) – attributes of the maps object to be ignored
- verbose (bool) – prints the plugin name and loaded attributes
-
-
class
tramway.analyzer.mapper.
Mapper
¶ Bases:
tramway.analyzer.attribute.abc.Attribute
Abstract base class for the
mapper
attribute of anRWAnalyzer
object.
-
class
tramway.analyzer.mapper.
MapperPlugin
(plugin, **kwargs)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
,tramway.analyzer.mapper.plugin.MapperAttribute
tramway.analyzer.mapper.utils module¶
tramway.analyzer.mapper.mpl module¶
-
class
tramway.analyzer.mapper.mpl.
PatchCollection
(ax, mesh, bounding_box=None, overlay_locations=False, time_label_fmt='t= %t-%ts', time_label_loc=(0.01, 1.01), **kwargs)¶ Bases:
object
Makes glyphs for space bins to be drawn as patches.
For constant spatial mesh and 2D localization data only.
Vector maps are not supported yet.
-
animate
(map)¶ To be passed as second positional argument to FuncAnimation.
Parameters: map (Series) – parameter values; can also be a tuple with the actual map argument being last. Returns: list of glyphs to update. Return type: callable
-
init_func
()¶ To be passed as argument init_func to FuncAnimation.
-
plot
(map, times=None, locations=None)¶ Updates the color of the patches.
Parameters: - map (Series) – parameter values.
- times (tuple) – time segment bounds, in seconds.
- locations (DataFrame) – segment locations.
Returns: sequence of updated glyphs.
Return type: tuple
-
-
class
tramway.analyzer.mapper.mpl.
Mpl
(parent=None)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
Matplotlib interface for maps.
-
animate
(fig, maps, feature, sampling=None, overlay_locations=False, axes=None, aspect='equal', logscale=False, composable=True, **kwargs)¶ Animates the time-segmented inference parameters.
Vector features are represented as amplitude.
The RWAnalyzer.time attribute is accessed.
Parameters: - fig (matplotlib.figure.Figure) – figure.
- maps (Analysis or Maps) – map series.
- feature (str) – parameter to be drawn.
- sampling (Analysis or Partition) – spatial bins and time segments;
optional only if maps is an
Analysis
. - overlay_locations (bool or dict) – styling options for the overlaid locations.
- axes (matplotlib.axes.Axes) – figure axes.
- aspect (str or None) – aspect ratio.
- logscale (bool or str) – transform the color-coded values in natural logarithm; can also be ‘log’, ‘natural’ or ‘log10’.
- composable (bool) – returns an overloaded
FuncAnimation
object that can be passed in place of argument fig in later calls toanimate()
so to stack animations on different axes (axes) of a same figure (fig).
Returns: animation object.
Return type: matplotlib.animation.FuncAnimation
Extra input arguments are passed to
FuncAnimation
orPatchCollection
(andscalar_map_2d()
).Notebook example:
Note: the above example seems to work equally well without
composable=True
.
-
clabel
(feature, kwargs, logscale=None, map_kwargs=None)¶ Extracts from kwargs arguments related to the colorbar label and adds a
'unit'
orclabel
argument to map_kwargs if necessary.
-
plot
(maps, feature, sampling=None, axes=None, aspect='equal', interior_contour=None, overlay_locations=False, logscale=None, **kwargs)¶ Calls
map_plot()
.May be reworked in the future to remove the
helper
dependency.logscale applies only to the color-coded background of field maps.
new in 0.5.2: argument interior_contour is a :class`dict` with the following keys allowed: margin, linestyle, linewidth and color. The default value for margin (or relative_margin) is 0.01.
plot does not access any analyzer attributes and can be safely called from any analyzer:
from tramway.analyzer import RWAnalyzer
RWAnalyzer().mapper.mpl.plot(…)
or instanciating an Mpl object:
from tramway.analyzer.mapper.mpl import Mpl
Mpl().plot(…)
-
tramway.analyzer.pipeline package¶
-
class
tramway.analyzer.pipeline.
Pipeline
(*args, **kwargs)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
pipeline
attribute of anRWAnalyzer
object.The main methods are
append_stage()
andrun()
.-
add_collectible
(filepath)¶ Registers a file as to be collected after stage completion.
-
append_stage
(stage, granularity=None, requires_mutability=None, **options)¶ Appends a pipeline stage to the processing chain.
Parameters: - stage (callable) – function that takes an
RWAnalyzer
object as unique input argument. - granularity (str) – smallest data item stage can independently process;
any of
'coarsest'
or equivalently'full dataset'
,'source'
or equivalently'spt data'
,'data source'
or'spt data source'
,'roi'
or equivalently'region of interest'
,'time'
or equivalently'segment'
or'time segment'
(case-insensitive). new in 0.6.2: granularity can be prefixed withmin:
- requires_mutability (bool) – callable object stage alters input argument self.
Stages with this argument set to
True
are always run as dependencies. Default isFalse
. - update_existing_rwa_files (bool) – see also
PipelineStage
. - run_everywhere (bool) – new in 0.6.2; see also
PipelineStage
.
new in 0.6.2: the
min:
prefix for granularity can be passed to prevent flexible-level stages to be combined with others of incompatible granularity. For example, a fresh_start stage should operate no belowsource
, because it may delete source-level files, which is not compatible with a roi-level stage that may be split into multiple jobs working on the same source file. Note however that passingrun_everywhere=True
to a fresh_start stage is preferred as this is more portable.- stage (callable) – function that takes an
-
early_setup
(**kwargs)¶ Sets the submit_side/worker_side properties of the
env
attribute.early_setup()
can be called onceenv
is initialized and beforerun()
is called. This allows to run some conditional code, specifically on the submit side or on the worker side.This method returns silently if
env
is not initialized and both theenv.EnvironmentInitializer.submit_side
andenv.EnvironmentInitializer.worker_side
properties areFalse
.
-
reset
()¶ Empties the pipeline processing chain.
-
resume
(**kwargs)¶ Looks for orphaned remote jobs and collect the generated files.
Works as a replacement for the
run()
method to recover after connection loss.Recovery procedures featured by the
env
backend may fail or recover some of the generated files only.See also the
resume()
method of theenv
attribute, if available.
-
run
()¶ Sequentially runs the different stages of the pipeline.
-
-
class
tramway.analyzer.pipeline.
PipelineStage
(run, granularity=None, requires_mutability=None, update_existing_rwa_files=None, run_everywhere=None, **options)¶ Bases:
object
Wrapper for callables to be run on calling
Pipeline.run()
.requires_mutability defaults to
False
.update_existing_rwa_files defaults to
False
as of version 5.2.new in 0.6.2: boolean argument and attribute run_everywhere. The main difference with requires_mutability is that the run_everywhere stage runs at most once on each host.
A fresh_start stage will typically set run_everywhere to
True
, while a reload stage will set requires_mutability toTrue
instead.-
granularity
¶ -
Type: str
-
name
¶ Callable’s name
Type: str
-
requires_mutability
¶ -
Type: bool
-
run_everywhere
¶ Run once on every host, both local and remote
Type: bool
-
tramway.analyzer.pipeline.stages module¶
This module is exported by the tramway.analyzer
package.
Standard analysis steps for RWAnalyzer.pipeline
-
tramway.analyzer.pipeline.stages.
tessellate
(label=None, roi_expected=False, spt_data=True, tessellation='freeze', **kwargs)¶ Returns a standard pipeline stage for SPT data sampling.
Although the name ‘tessellate’ refers merely to the spatial segmentation, time segmentation is also handled, if defined. The name alludes to the standalone
tramway.helper.tessellation.tessellate()
function.The default granulariy is set to ‘spt data’, whereas in principle the finest valid granularity is ‘roi’. The tessellation step is fast enough to a avoid the overhead of saving as many files as regions of interest.
Important
If the input SPT data is defined as ascii file(s), the corresponding .rwa files will be overwritten.
If analysis trees already reference analysis artefacts for the specified label, these artefacts are also overwritten.
This stage building function features two mechanisms to make the resulting .rwa files smaller in size:
- with option spt_data=’placeholder’, the SPT data can be
omitted in the .rwa files;
see also
restore_spt_data()
; - the spatial tessellation can be freezed (default); this implies the tesellation cannot be updated any longer with extra data.
- with option spt_data=’placeholder’, the SPT data can be
omitted in the .rwa files;
see also
-
tramway.analyzer.pipeline.stages.
infer
(map_label=None, sampling_label=None, roi_expected=False, overwrite=False, single_path=False, **kwargs)¶ Returns a standard pipeline stage for inferring model parameters on each region of interest, or SPT data item if no roi are defined.
The default granularity is set to ‘roi’, which is suitable for computer-intensive inferences such as ‘DV’.
With default
overwrite=False
, if the specified output label map_label already exists in analysis trees, the inference is skipped for these analysis trees and the corresponding artefact not overwritten. However, if map_label isNone
, overwrite is ignored and the stage acts like if overwrite wereTrue
.
-
tramway.analyzer.pipeline.stages.
reload
(skip_missing=True)¶ Returns a pipeline stage to reload the generated .rwa files.
This is useful if a first computation - e.g. tessellate - was dispatched (including with the environments.LocalHost environment) and the .rwa files were generated and retrieved from the worker environments. In the case a second stage has to be dispatched - e.g. infer, the local pipeline must be updated with the content of these retrieved files.
This may also be required on the worker side for the next stages, for example if the SPT data was initially defined from ascii files and the coming stages should take over from the corresponding .rwa files. As a consequence, this reload stage is set with requires_mutability=True.
-
tramway.analyzer.pipeline.stages.
restore_spt_data
()¶ Reintroduces the original SPT dataframe into the .rwa files.
This post-processing stage - typically post-infer stage - is expected to be called only when the tessellate stage was called before with option spt_data=’placeholder’.
This stage was tested with SPT data defined as
SPTAsciiFiles
orspt_data.RWAFiles
. However, withSPTAsciiFiles
, the alias attribute should be defined.
-
tramway.analyzer.pipeline.stages.
tessellate_and_infer
(map_label=None, sampling_label=None, spt_data=True, overwrite=False, roi_expected=False, load_rwa_files=None, **kwargs)¶ Combines tessellate and infer at roi granularity.
See
infer()
for important notes on overwrite argument.new in 0.6: unless
load_rwa_files=False
, .rwa files are loaded if the SPT data source has not already been loaded from such files.
tramway.analyzer.env package¶
-
class
tramway.analyzer.env.
EnvironmentInitializer
(attribute_setter, parent=None)¶ Bases:
tramway.analyzer.attribute.Initializer
Can be left not-initialized.
For local multi-processing:
a.env = environments.LocalHost
For sbatch job scheduling on an SSH-reachable server:
a.env = environments.SlurmOverSSH
See
LocalHost
andSlurmOverSSH
.-
script
¶ Path to the local script; this compatibility attribute is actually used by the
browser
Type: str
-
collectibles
¶ Compatilibity attribute; not used
Type: set
-
-
class
tramway.analyzer.env.
Environment
¶ Bases:
tramway.analyzer.attribute.abc.Attribute
Abstract base class for the
env
attribute of anRWAnalyzer
object.-
script
¶ Path to the local script; usually a filename
Type: str
-
dispatch
(**kwargs)¶ Input arguments must be keyworded.
Parameters: - stage_index (int) – index of the pipeline stage which material has to be dispatched.
- source (str) – source name of the spt dataset to be dispatched.
-
tramway.analyzer.env.environments module¶
This module is exported by the tramway.analyzer
package
as environments.
-
class
tramway.analyzer.env.environments.
Environment
¶ Bases:
tramway.analyzer.attribute.abc.Attribute
Abstract base class for the
env
attribute of anRWAnalyzer
object.-
dispatch
(**kwargs)¶ Input arguments must be keyworded.
Parameters: - stage_index (int) – index of the pipeline stage which material has to be dispatched.
- source (str) – source name of the spt dataset to be dispatched.
-
script
¶ Path to the local script; usually a filename
Type: str
-
-
class
tramway.analyzer.env.environments.
LocalHost
(**kwargs)¶ Bases:
tramway.analyzer.env.environments.Env
Runs jobs in local python processes.
Because of a design limitation in tramway.analyzer.pipeline (type check), Every class that similarly implements local-only parallel processing should ideally be derived from this class. This may not be critical, as failure to do so will only make run_everywhere stages to run twice instead of once.
-
interrupt_jobs
()¶ Interrupts the running jobs.
-
worker_count
¶ Desired number of workers
Type: int
-
-
class
tramway.analyzer.env.environments.
SlurmOverSSH
(**kwargs)¶ Bases:
tramway.analyzer.env.environments.Slurm
,tramway.analyzer.env.environments.RemoteHost
Calls sbatch through an SSH connection to a Slurm server.
Note
All filepaths should be absolute or relative to the $HOME directory. This applies especially to all file-based initializers.
-
collect_results
(stage_index=None, inplace=False, reload_existing_rwa_files=False)¶ Downloads the reported collectibles from the remote host (worker side) to the local host (submit side).
See
Env.collect_results()
for information on the distinct behavior of the inplace=True case.
-
delete_temporary_data
()¶ Deletes all the temporary data, on both the submit and worker sides.
-
dispatch
(**kwargs)¶ Prepares the worker side. To be called from the submit side only.
-
early_setup
(*argv, connect=False, **kwargs)¶ Determines which side is running and sets the submit_side/worker_side attributes.
Takes command-line arguments (
sys.argv
).
-
filter_script_content
(content)¶ Processes the script content for its dispatch onto the worker side.
Parameters: content (list of str) – lines with the 'n'
character at the end of each lineReturns: modified lines Return type: list of str
-
make_job
(stage_index=None, source=None, region_index=None, segment_index=None)¶ Registers a new pending job.
Parameters: - stage_index (int or list of int) – stage index(ices)
- source (str) – SPT datablock identifier (source path or alias)
- region_index (int) – index of the support region
(see also
as_support_regions()
) - segment_index (int) – index of the time segment
-
pack_temporary_rwa_files
(log=None, wd=None, stage_index=None, job_id=None)¶ Similarly to
resume()
, pack_temporary_rwa_files combines the intermediate .rwa files in the temporary directory for a running instance on the compute host.This does not move files out of the temporary directory. Instead, the intermediate .rwa files are replaced by new (but fewer) intermediate .rwa files that result from combining the former files.
This may be useful to save disk space, as the localization data is duplicated as many times as there are intermediate files.
Warning
not tested yet
-
resume
(log=None, wd=None, stage_index=None, job_id=None)¶ Parses log output of the disconnected instance, looks for the current stage index, and tries to collect the resulting files.
This completes the current stage only. Further stages are not run.
Parameters: - log (str) – log output; progress information can be omitted
- wd (str) – location of the working directory on the remote host
- stage_index (int or list) – index of the stage(s) to resume
- job_id (str) – Slurm job array ID
-
setup
(*argv, connect=True, **kwargs)¶ Determines which side is running and alters iterators of the main
RWAnalyzer
attributes.Takes command-line arguments (
sys.argv
).
-
-
class
tramway.analyzer.env.environments.
Tars
(**kwargs)¶ Bases:
tramway.analyzer.env.environments.SingularitySlurm
Designed for server tars.pasteur.fr.
The server is closed.
-
class
tramway.analyzer.env.environments.
GPULab
(**kwargs)¶ Bases:
tramway.analyzer.env.environments.SingularitySlurm
Designed for server adm.inception.hubbioit.pasteur.fr.
-
class
tramway.analyzer.env.environments.
Maestro
(**kwargs)¶ Bases:
tramway.analyzer.env.environments.SingularitySlurm
Designed for server maestro.pasteur.fr.
tramway.analyzer.browser package¶
-
class
tramway.analyzer.browser.
Browser
(analyzer)¶ Bases:
tramway.analyzer.attribute.AnalyzerNode
browser
attribute of anRWAnalyzer
object.Rendering is based on bokeh and is performed in a web browser tab. An optional side panel with experimental export features is shown if argument
side_panel=True
is passed toshow_maps()
or argument webdriver is defined:from tramway.analyzer import * a = RWAnalyzer() a.spt_data.from_rwa_files('*.rwa') from selenium import webdriver a.browser.show_maps(webdriver=webdriver.Firefox)
Defining a webdriver is required for exporting figures. Supported file formats are .png and .svg. Note that package selenium is required.
The above example can be explicitly run with
bokeh serve
, or else it can be run with the standard Python interpreter or in a Jupyter notebook as long as the script attribute is defined:from tramway.analyzer import * a = RWAnalyzer() a.spt_data.from_rwa_files('*.rwa') try: a.script = __file__ except NameError: # in a notebook a.script = 'MyNotebook.ipynb' # this notebook's name; please adapt from selenium import webdriver a.browser.show_maps(webdriver=webdriver.Firefox)
The later example will call
bokeh serve --show
on the file specified in the script attribute.The showed parameter values can also be exported with the side panel. Note that all features are exported together with the spatial bin center coordinates.
-
clim
¶ Color lower and upper values (dict values) for each feature (dict keys)
Type: dict of 2-element array-like
-
colormap
¶ Colormap for inferred parameter maps.
See also
scalar_map_2d()
.Type: str
-
show_maps
(**kwargs)¶ See also
browse_maps()
.
-