haussio module

Module for importing and exporting 2p imaging datasets

(c) 2015 C. Schmidt-Hieber GPLv3

class haussio.DoricHaussIO(dirname, chan='A', xml_path=None, sync_path=None, width_idx=4, maxtime=None, xycal=350.0)[source]

Object representing 2p imaging data acquired with ScanImage 4

class haussio.HaussIO(dirname, chan='A', xml_path=None, sync_path=None, width_idx=4, maxtime=None)[source]

Base class for objects representing 2p imaging data.

xsize

float – Width of frames in specimen dimensions (e.g. um)

ysize

float – Height of frames in specimen dimensions (e.g. um)

xpx

int – Width of frames in pixels

ypx

int – Height of frames in pixels

timing

numpy.ndarray – Time points of frame acquisitions

fps

float – Acquisition rate in frames per seconds

fps

float – Acquisition interval in seconds

movie_fn

str – File path (full path) for exported movie

scale_png

str – File path (full path) for png showing scale bar

sima_dir

str – Full path to directory for sima exports

basefile

str – File name trunk for individual tiffs (without path) (e.g. ChanA_0001_)

filetrunk

str – Full path and file name trunk for individual tiffs (e.g. /home/cs/data/ChanA_0001_)

ffmpeg_fn

str – File name filter (full path) used as input to ffmpeg (e.g. /home/cs/data/ChanA_0001_%04d.tif)

filenames

list of str – List of file paths (full paths) of individual tiffs

width_idx

str – Width of index string in file names

maxtime

float – Limit data to maxtime

format_index(n, width_idx=None)[source]

Return formatted index string

Parameters:
  • n (int or str) – Index as int, or ”?” (returns series of ”?”), or “%” (returns old-school formatter)
  • width_idx (int, optional) – Override default width of index string. Default: None
Returns:

format – Formatted index string, or series of ”?”, or old-school formatter

Return type:

string

get_normframe()[source]

Return a representative frame that will be used to normalize the brightness in movies

Returns:arr – Frame converted to numpy.ndarray
Return type:numpy.ndarray
get_scale_bar(prop=0.125)[source]

Returns lengths in specimen dimensions (e.g. um) and in pixels of a scale bar that fills the given fraction of the width of the image

Parameters:prop (float, optional) – Length of scale bar expressed as fraction of image width
Returns:
  • scale_length_int (int) – Scale bar length in specimen dimensions (e.g. um)
  • scale_length_px (int) – Scale bar length in pixels
make_movie(norm=16.0, scalebar=True, crf=28.0)[source]

Produce a movie of the experiment

Parameters:
  • norm (float, optional) – Normalize min, norm*median and max brightness to 0, 0.5 and 1.0 None for no normalization. Default: 16.0
  • scalebar (bool, optional) – Show a scale bar in the movie.
  • crf (int, optional) – crf value to be passed to ffmpeg. Default: 28
Returns:

html_movie – An html tag containing the complete movie

Return type:

str

make_movie_extern(path_extern, norm=16.0, scalebar=True, crf=28, width_idx=None)[source]

Produce a movie from a directory with individual tiffs, using the present experimental settings for scale bar and frame rate

Parameters:
  • path_extern (str) – Full path to the directory that contains the individual tiffs
  • norm (float, optional) – Normalize min, norm*median and max brightness to 0, 0.5 and 1.0 None for no normalization. Default: 16.0
  • scalebar (bool, optional) – Show a scale bar in the movie.
  • crf (int, optional) – crf value to be passed to ffmpeg. Default: 28
  • width_idx (int, optional) – Override default index string width. Default: None
Returns:

html_movie – An html tag containing the complete movie

Return type:

str

plot_scale_bar(ax)[source]

Add scale bar to a matplotlib axis

Parameters:ax (matplotlib.axes.Axes) – matplotlib axes on which to plot the scale bar, as e.g. returned by ‘fig.add_suplot(1,1,1)’
save_scale_bar()[source]

Save scale bar as png (using file name stored in self.scale_png) so that it can be used in a movie

tosima(startIdx=0, stopIdx=None)[source]

Convert the experiment to a sima.ImagingDataset

Parameters:
  • startIdx (int, optional) – Starting index (inclusive) for conversion.
  • stopIdx (int) – Last index (exclusive) for conversion.
Returns:

dataset – A sima.ImagingDataset

Return type:

sima.ImagingDataset

class haussio.MovieHaussIO(dirname, dx, dt, chan='A', xml_path=None, sync_path=None, width_idx=4)[source]

Object representing 2p imaging data for which only a movie is available

class haussio.PrairieHaussIO(dirname, chan='A', xml_path=None, sync_path=None, width_idx=4, maxtime=None)[source]

Object representing 2p imaging data acquired with Prairie scopes

class haussio.SI4HaussIO(dirname, chan='A', xml_path=None, sync_path=None, width_idx=4, maxtime=None, xycal=1200.0)[source]

Object representing 2p imaging data acquired with ScanImage 4

class haussio.ThorHaussIO(dirname, chan='A', xml_path=None, sync_path=None, width_idx=4, maxtime=None)[source]

Object representing 2p imaging data acquired with ThorImageLS

haussio.sima_export_frames(dataset, path, filenames, startIdx=0, stopIdx=None, ftype='tiff', compress=False)[source]

Export a sima.ImagingDataset to individual tiffs. Works around sima only producing multipage tiffs.

Parameters:
  • dataset (sima.ImagingDataset) – The sima.ImagingDataset to be exported
  • path (string) – Full path to target directory for exported tiffs
  • filenames (list of strings) – Filenames to be used for the export. While these can be full paths, only the file name part will be used.
  • startIdx (int, optional) – Index of first frame to be exported (inclusive). Default: 0
  • stopIdx (int, optional) – Index of last frame to be exported (exclusive). Default: None
  • ftype (stf, optional) – file type, one of “tiff” or “raw”. Default: “tiff”
  • compress (boolean, optional) – Compress raw file with xz. Default: False
class haussio.HaussIO(dirname, chan='A', xml_path=None, sync_path=None, width_idx=4, maxtime=None)[source]

Base class for objects representing 2p imaging data.

xsize

float – Width of frames in specimen dimensions (e.g. um)

ysize

float – Height of frames in specimen dimensions (e.g. um)

xpx

int – Width of frames in pixels

ypx

int – Height of frames in pixels

timing

numpy.ndarray – Time points of frame acquisitions

fps

float – Acquisition rate in frames per seconds

fps

float – Acquisition interval in seconds

movie_fn

str – File path (full path) for exported movie

scale_png

str – File path (full path) for png showing scale bar

sima_dir

str – Full path to directory for sima exports

basefile

str – File name trunk for individual tiffs (without path) (e.g. ChanA_0001_)

filetrunk

str – Full path and file name trunk for individual tiffs (e.g. /home/cs/data/ChanA_0001_)

ffmpeg_fn

str – File name filter (full path) used as input to ffmpeg (e.g. /home/cs/data/ChanA_0001_%04d.tif)

filenames

list of str – List of file paths (full paths) of individual tiffs

width_idx

str – Width of index string in file names

maxtime

float – Limit data to maxtime

format_index(n, width_idx=None)[source]

Return formatted index string

Parameters:
  • n (int or str) – Index as int, or ”?” (returns series of ”?”), or “%” (returns old-school formatter)
  • width_idx (int, optional) – Override default width of index string. Default: None
Returns:

format – Formatted index string, or series of ”?”, or old-school formatter

Return type:

string

get_normframe()[source]

Return a representative frame that will be used to normalize the brightness in movies

Returns:arr – Frame converted to numpy.ndarray
Return type:numpy.ndarray
get_scale_bar(prop=0.125)[source]

Returns lengths in specimen dimensions (e.g. um) and in pixels of a scale bar that fills the given fraction of the width of the image

Parameters:prop (float, optional) – Length of scale bar expressed as fraction of image width
Returns:
  • scale_length_int (int) – Scale bar length in specimen dimensions (e.g. um)
  • scale_length_px (int) – Scale bar length in pixels
make_movie(norm=16.0, scalebar=True, crf=28.0)[source]

Produce a movie of the experiment

Parameters:
  • norm (float, optional) – Normalize min, norm*median and max brightness to 0, 0.5 and 1.0 None for no normalization. Default: 16.0
  • scalebar (bool, optional) – Show a scale bar in the movie.
  • crf (int, optional) – crf value to be passed to ffmpeg. Default: 28
Returns:

html_movie – An html tag containing the complete movie

Return type:

str

make_movie_extern(path_extern, norm=16.0, scalebar=True, crf=28, width_idx=None)[source]

Produce a movie from a directory with individual tiffs, using the present experimental settings for scale bar and frame rate

Parameters:
  • path_extern (str) – Full path to the directory that contains the individual tiffs
  • norm (float, optional) – Normalize min, norm*median and max brightness to 0, 0.5 and 1.0 None for no normalization. Default: 16.0
  • scalebar (bool, optional) – Show a scale bar in the movie.
  • crf (int, optional) – crf value to be passed to ffmpeg. Default: 28
  • width_idx (int, optional) – Override default index string width. Default: None
Returns:

html_movie – An html tag containing the complete movie

Return type:

str

plot_scale_bar(ax)[source]

Add scale bar to a matplotlib axis

Parameters:ax (matplotlib.axes.Axes) – matplotlib axes on which to plot the scale bar, as e.g. returned by ‘fig.add_suplot(1,1,1)’
save_scale_bar()[source]

Save scale bar as png (using file name stored in self.scale_png) so that it can be used in a movie

tosima(startIdx=0, stopIdx=None)[source]

Convert the experiment to a sima.ImagingDataset

Parameters:
  • startIdx (int, optional) – Starting index (inclusive) for conversion.
  • stopIdx (int) – Last index (exclusive) for conversion.
Returns:

dataset – A sima.ImagingDataset

Return type:

sima.ImagingDataset

class haussio.ThorHaussIO(dirname, chan='A', xml_path=None, sync_path=None, width_idx=4, maxtime=None)[source]

Object representing 2p imaging data acquired with ThorImageLS

class haussio.PrairieHaussIO(dirname, chan='A', xml_path=None, sync_path=None, width_idx=4, maxtime=None)[source]

Object representing 2p imaging data acquired with Prairie scopes