imfun.fseq

Functions and variables

imfun.fseq.open_seq(path, *args, **kwargs)

Dispatch to an appropriate class constructor depending on the file name

Parameters:
  • path: (str) – path to load data from. Can be a glob-style pattern or a single file name.
  • *args, **kwargs: will be dispatched to the actual class’ __init__ call
Returns:
  • instance of an appropriate Frame Sequence class
imfun.fseq.sorted_file_names(pattern)

Return a sorted list of file names matching a pattern

imfun.fseq.iter_files(pattern, loadfn)

Return iterator over data frames, file names matching a pattern, loaded by a user-provided function loadfn

imfun.fseq.img_getter(frame, ch)

A wrapper to extract color channel from image files. :returns: 2D matrix with intensity values

imfun.fseq.fseq_from_glob(pattern, ch=None, loadfn=<Mock name='mock.load' id='140508897444432'>)

Return sequence of frames from filenames matching a glob.

Parameters:
  • pattern: (str) – glob-style pattern for file names.
  • ch: (int or None) – color channel to extract if a number, all colors if None.
  • loadfn: (func) – a function to load data from a file by its name [np.load].
Returns:
  • iterator over frames. 2D if ch is int, 3D if ch is None

Classes

class imfun.fseq.FrameSequence

Base class for sequence of frames

as3darray(fslice=None, crop=None, dtype=<Mock name='mock.float64' id='140508897355408'>)

Return the frames as a 3D array.

//An alternative way is to use the __getitem__ interface: //data = np.asarray(fs[10:100])

Parameters:
  • fslice: (int, tuple-like or None) –

[start,] stop [, step] to go through frames - crop: (slice or None) – a crop (tuple of slices) to take from each frame - dtype: (type) – data type to use. Default, np.float64

Returns:
3D array d, where frames are stored in higher dimensions, such that d[0] is the first frame, etc.
asiter(fslice=None, crop=None)

Return an iterator over the frames taking frames from fslice and f[crop] for each frame

aslist(max_frames=None, crop=None)

Return the frames as a list up to max_frames frames taking f[crop] slices.

data_percentile(p)

Return a percentile p value on data.

Parameters:
  • p : float in range of [0,100] (or sequence of floats)

    Percentile to compute which must be between 0 and 100 inclusive.

data_range()

Return global range (min, max) values for the sequence

export_img(path, base='fseq-export-', figsize=(4, 4), start=0, stop=None, show_title=True, format='.png', vmin=None, vmax=None, **kwargs)

Export frames as images by drawing them with pylab.imshow.

Parameters:
  • path : (str) – directory where to save images to. Will be created if doesn’t exist
  • base : (str) – a prefix for the created file names
  • figsize: (tuple or array-like) – size of the figures in inches
  • start : (int) – start at this frame
  • stop : (int or None) – stop at this frame
  • show_title: (Bool) – flag whether to show a title over the frame
  • format: (str) – output format, can be png, svg, eps, pdf, bmp,tif
  • vmin : (number or None) – to be passed to imshow. If None, global minimum over the frame sequence is used.
  • vmax : (number or None) – to be passed to imshow. If None, global maximum over the frame sequence is used.
  • **kwargs: other arguments that will be passed to imshow
Returns:
  • a list of names for the created files
export_movie_anim(video_name, fps=None, start=0, stop=None, show_title=True, fig_size=(4, 4), bitrate=-1, writer='avconv', codec=None, frame_on=False, marker_idx=None, vmin=None, vmax=None, **kwargs)

Create an mpg movie from the frame sequence using mencoder. and mpl.Animation

Parameters:
  • video_name: (str) – a name (without extension) for the movie to be created

  • fps: (number) – frames per second.

    If None, use 10/self.meta[‘axes’][0][0]

  • marker_idx: (array_like) – indices when to show a marker (e.g. for stimulation)

  • **kwargs : keyword arguments to be passed to self.export_png

frame_idx()

Return a vector of time stamps, if frame sequence is timelapse and dt is set, or just arange(nframes)

frame_slices(crop)

Return iterator over subframes (slices defined by crop parameter). When crop is None, full frames are returned

length()

Return number of frames in the sequence

mask_reduce(mask)

Return 1D vector from a mask (or slice), taking average value within this mask in each frame

max_project(fslice=None)

Return max-projection image over a number of frames (all by default).

see fseq.mean_frame docstring for details

mean_frame(fslice=None)

Return average image over a number of frames (all by default).

frame range is given as argument fslice. if it’s int, use N first frames, if it’s tuple-like, it can be of the form [start,] stop [,step]

pipeline()

Return the composite function to process frames based on self.fns

pix_iter(pmask=None, fslice=None, rand=False, crop=None, **kwargs)

Return iterator over time signals from each pixel.

Parameters:
  • mask: (2D Bool array or None) – skip pixels where mask is False if mask is None, take all pixels
  • fslice: (int, slice or None) –

[start,] stop [, step] to go through frames - rand: (Bool) – whether to go through pixels in a random order - **kwargs: keyword arguments to be passed to self.as3darray

Yields:
tuples of (v,row,col), where v is the time-series in a pixel at row,col
pw_transform(pwfn, verbose=False, **kwargs)

Spawn another frame sequence, pixelwise applying a user-provided function.

Parameters:
  • pwfn: (func) – a f(vector) -> vector function
  • verbose: (Bool) – whether to be verbose while going through the pixels
  • **kwargs`: keyword arguments to be passed to self.pix_iter
shape(crop=None)

Return the shape of frames in the sequence

softmask_reduce(mask)

Return 1D vector from a mask (or slice), taking average value within this mask in each frame, weighted by mask values between 0 and 1

std(axis=None)

get standard deviation of the data

time_project(fslice=None, fn=<Mock name='mock.mean' id='140508897394640'>, crop=None)

Apply an f(vector) -> scalar function for each pixel.

This is a more general (and sometimes faster) function than self.mean_frame or self.max_project. However, it requires more memory as it makes a call to self.as3darray, while the other two don’t

Parameters:
  • fslice: (int, tuple-like or None) –

[start,] stop [, step] go through these frames - fn (func) – function to apply (np.mean by default)

Returns:
  • 2D array – a projected frame
class imfun.fseq.FSeq_arr(arr, fns=, []meta=None)

A FrameSequence class as a wrapper around a 3D Numpy array

frames()

Return iterator over frames.

The composition of functions in self.fns list is applied to each frame. By default, this list is empty. Examples of function”hooks” to put into self.fns are imfun.lib.DFoSD, imfun.lib.DFoF or functions from scipy.ndimage.

pix_iter(pmask=None, fslice=None, rand=False, **kwargs)

Iterator over time signals from each pixel (FSeq_arr)

class imfun.fseq.FSeq_imgleic(pattern, ch=0, fns=, []xmlname=None, meta=None)

FrameSequence around the image files created by LeicaSoftware. It is just a wrapper around FSeq_img, only it also looks for an xml file in Leica’s format with the Job description