PYME.IO.image module

exception PYME.IO.image.FileSelectionError

Bases: Exception

Custom error type to raise when we cancel file selection

PYME.IO.image.GeneratedImage(img, imgBounds, pixelSize, sliceSize, channelNames, mdh=None)

Helper function for LMVis which creates an image and fills in a few metadata parameters

class PYME.IO.image.ImageBounds(x0, y0, x1, y1, z0=0, z1=0)

Bases: object

property bounds
classmethod estimateFromSource(ds)
property extent
classmethod extractFromMetadata(mdh)
height()
width()
class PYME.IO.image.ImageStack(data=None, mdh=None, filename=None, queueURI=None, events=[], titleStub='Untitled Image', haveGUI=False, load_prompt=None)

Bases: object

An Image Stack. This is the core PYME image type and wraps around the various different supported file formats.

This is a essentially a wrapper of the image data and any ascociated metadata. The class can be given a ndarray like* data source, or alternatively supports loading from file, or from a PYME task queue URI, in which case individual slices will be fetched from the server as required.

For details on the file type support, see the Load method.

You should provide one of the ‘data’ or ‘filename’ parmeters, with all other parameters being optional.

Parameters
data

Image data. Something that supports ndarray like slicing and exposes a .shape parameter, something implementing the PYME.IO.DataSources interface, or a list of either of the above. Dimensionality can be between 1 and 4, with the dimensions being interpreted as x, y, z/t, colour. A mangled (will support slicing, but not necessarily other array operations) version of the data will be stored as the .data member of the class.

mdhsomething derived from PYME.IO.MetaDataHandler.MDHandlerBase

Image metadata. If None, and empty one will be created.

filenamestr

filename of the data to load (see Load), or PYME queue identifier

queueURIstr

PYRO URI of the task server. This exists to optionally speed up loading from a queue by eliminating the PYRO nameserver lookup. The queue name itself should be passed in the filename, with a leading QUEUE://.

eventslist / array

An array of time series events (TODO - more doc)

haveGUIbool

Whether we have a wx GUI available, so that we can display dialogs asking for, e.g. a file name if no data or filename is supplied, or for missing metadata entries

Attributes
dataPYME.IO.DataSources data source.

Compatiblity property for old style data access.

mdhPYME.IO.MetdataHandler metadata source

This contains image metadata. It behaves like a dictionary, and individual metadata entries can be accessed by key.

eventslist/array

Any events which occured during image acquisition

voxelsize3-tuple (float)

Returns voxel size, in nm, as a 3-tuple.

pixelsizefloat

The pixelsize in nm (shortcut for voxelsize[0])

nameslist of str

Return the names of the colour channels

origintuple of float

position, in nm, of the top-left pixel in the image from the camera origin. Useful for lining up images taken with different ROIs.

Load(filename=None, prompt=None, haveGUI=False)

Load a file from disk / queue / cluster

NB: this is usually called from __init__. Call ImageStack(filename = filename) rather than calling this function directly.

Parameters
filenamestr [optional]
filename or URI of data to load. Natively supported types are:
  • .tif

  • .h5 (PYME HDF5 format)

  • .npy (numpy array)

  • .psf (PYME PSF files)

  • .dbl (Bewersdorf STED files)

  • .dcimg (Hamamatsu .dcimg)

  • QUEUE:// (PYME task queue data)

  • PYME-CLUSTER:// (Data stored in our custom cluster file system)

  • .md (sequence of images with a type supported by PIL, described by a .md metadta file)

If the filename doesn’t match one of these patterns, we fall back on bioformats, if available. This works well for most biological file formats, but can be fairly slow. At present, .tif is handled by our native handler (which falls back on the excellent Gohlke tiffile library) and .tiff is handled by bioformats.

If no filename is given, we display an open file dialog box.

Returns
Save(filename=None, crop=False, roi=None, progressCallback=None)

Saves an image to file.

Parameters
filenamestr

The filename to save to. File type is deduced by the extension. For supported data types, see PYME.IO.dataExporter. If no filename is given, we display a dialog box to ask.

cropbool

Do we want to crop the image? Note that this displays a cropping dialog box (ie needs a GUI) and requires that view be defined. TODO - remove GUI dependance

viewPYME.DSView.arrayViewPanel instance

Our current view of the data. Used to get selection information to provide starting values for our crop region TODO - make this GUI independant by passing the selection / crop region to save.

Returns
SetData(data)

Set / replace the data associated with the image. This is primarily used in the acquisition program when we want a live view of constantly updating data. It is also used for the same purpose during deconvolution.

Parameters
datanumpy array or PYME.IO.DataSources datasource
Returns
property data

Compatiblity property for old style data access. Currently equivalent to data_xytc, + a deprecation warning.

The old behaviour is available as data_xytc

Might (eventually) change to data_xyztc once transition is complete

Returns
property data_xytc

Old-style data access with z & t dimensions flattened

Returns
property data_xyztc

Provides voxel data in a form that is accessible as though it was a 5D array with X, Y, Z, T, C as the dimensions

Implemented as a property to facilitate transition from old 4D data model

Returns
PYME.IO.DataSources.BaseDataSource.XYZTC data source (or class derived from this
property imgBounds

Return the bounds (or valid area) of the image in nm as (x0, y0, x1, y1, z0, z1)

property metadata
property names

Return the names of the colour channels

property origin
property pixelSize
property sliceSize
property voxels

A shorter alias of data_xyztc

property voxelsize

Returns voxel size, in nm, as a 3-tuple. Expects metadata voxel size to be in um

property voxelsize_nm

alias of self.voxelsize for interface compatibilty with metadatahandler

differs from self.voxelsize in that we will propagate any exception generated if, e.g., ‘voxelsize.x’ is not present in the metadata.

exception PYME.IO.image.PYMEDeprecationWarning

Bases: DeprecationWarning