ClearMap.IO package

This sub-package provides routines to read and write data

Two types of data files are discriminated:

The image data are stacks from microscopes obtained by volume imaging, or the results of analysis representing the visualization of the detected objects for instance.

The point data are lists of cell coordinates or measured intensities for instance.

Image data

Images are represented internally as numpy arrays. ClearMap assumes images in arrays are arranged as [x,y], [x,y,z] or [x,y,z,c] where x,y,z correspond to the x,y,z coordinates as when viewed in an image viewer such as ImageJ. The c coordinate is a possible color channel.

Note

Many image libraries read images as [y,x,z] or [y,x] arrays!

The ClearMap toolbox supports a range of (volumetric) image formats:

Format Descrition Module
TIF tif images and stacks TIF
RAW / MHD raw image files with optional mhd header file RAW
NRRD nearly raw raster data files NRRD
IMS imaris image file Imaris
reg exp folder, file list or file pattern of a stack of 2d images FileList

Note

ClearMap can read the image data from a Bitplane’s Imaris, but can’t export image data as an Imaris file.

The image format is inferred automatically from the file name extension.

For example to read image data use readData():

>>> import os
>>> import ClearMap.IO as io
>>> import ClearMap.Settings as settings
>>> filename = os.path.join(settings.ClearMapPath,'Test/Data/Tif/test.tif');
>>> data = io.readData(filename);
>>> print data.shape
(20, 50, 10)

To write image data use writeData():

>>> import os, numpy
>>> import ClearMap.IO as io
>>> import ClearMap.Settings as settings
>>> filename = os.path.join(settings.ClearMapPath,'Test/Data/Tif/test.tif');
>>> data = numpy.random.rand(20,50,10);
>>> data[5:15, 20:45, 2:9] = 0;
>>> data = 20 * data;
>>> data = data.astype('int32');
>>> res = io.writeData(filename, data);
>>> print io.dataSize(res);
(20, 50, 10)

Generally, the IO module is designed to work with image sources which can be either files or already loaded numpy arrays. This is important to enable flexible parallel processing, without rewriting the data analysis routines.

For example:

>>> import numpy
>>> import ClearMap.IO as io
>>> data = numpy.random.rand(20,50,10);
>>> res = io.writeData(None, data);
>>> print res.shape;
(20, 50, 10)

Range parameter can be passed in order to only load sub sets of image data, useful when the images are very large. For example to load a sub-image:

>>> import os, numpy
>>> import ClearMap.IO as io
>>> import ClearMap.Settings as settings
>>> filename = os.path.join(settings.ClearMapPath,'Test/Data/Tif/test.tif');
>>> res = io.readData(filename, data, x = (0,3), y = (4,6), z = (1,4));
>>> print res.shape;
(3, 2, 3)

Point data

ClearMap also supports several data formats for storing arrays of points, such as cell center coordinates or intensities.

Points are assumed to be an array of coordinates where the first array index is the point number and the second the spatial dimension, i.e. [i,d] The spatial dimension can be extended with additional dimensions for intensity ,easires or other properties.

Points can also be given as tuples (coordinate arrray, property array).

ClearMap supports the following files formats for point like data:

Format Description Module
CSV comma separated values in text file CSV
NPY numpy binary file NPY
VTK vtk point data file VTK

Note

ClearMap can write points data to a pre-existing Bitplane’s Imaris file, but can’t import the points from them.

The point file format is inferred automatically from the file name extension.

For example to read point data use readPoints():

>>> import os
>>> import ClearMap.IO as io
>>> import ClearMap.Settings as settings
>>> filename = os.path.join(settings.ClearMapPath, 'Test/ImageProcessing/points.txt');
>>> points = io.readPoints(filename);
>>> print points.shape
(5, 3)

and to write it use writePoints():

>>> import os, numpy
>>> import ClearMap.IO as io
>>> import ClearMap.Settings as settings
>>> filename = os.path.join(settings.ClearMapPath, 'Test/ImageProcessing/points.txt');
>>> points = numpy.random.rand(5,3);
>>> io.writePoints(filename, points);

Summary

  • All routines accessing data or data properties accept file name strings or numpy arrays or None
  • Numerical arrays represent data and point coordinates as [x,y,z] or [x,y]

ClearMap.IO.IO module

IO interface to read microscope and point data

This is the main module to distribute the reading and writing of individual data formats to the specialized sub-modules.

See ClearMap.IO for details.

pointFileExtensions = ['csv', 'txt', 'npy', 'vtk', 'ims']

list of extensions supported as a point data file

pointFileTypes = ['CSV', 'NPY', 'VTK', 'Imaris']

list of point data file types

pointFileExtensionToType = {'txt': 'CSV', 'vtk': 'VTK', 'csv': 'CSV', 'npy': 'NPY', 'ims': 'Imaris'}

map from point file extensions to point file types

dataFileExtensions = ['tif', 'tiff', 'mhd', 'raw', 'ims', 'nrrd']

list of extensions supported as a image data file

dataFileTypes = ['FileList', 'TIF', 'RAW', 'NRRD', 'Imaris']

list of image data file types

dataFileExtensionToType = {'tiff': 'TIF', 'mhd': 'RAW', 'nrrd': 'NRRD', 'raw': 'RAW', 'ims': 'Imaris', 'tif': 'TIF'}

map from image file extensions to image file types

fileExtension(filename)[source]

Returns file extension if exists

Parameters:filename (str) – file name
Returns:str – file extension or None
isFile(source)[source]

Checks if filename is a real file, returns false if it is directory or regular expression

Parameters:source (str) – source file name
Returns:bool – true if source is a real file
isFileExpression(source)[source]

Checks if filename is a regular expression denoting a file list

Parameters:source (str) – source file name
Returns:bool – true if source is regular expression with a digit label
isPointFile(source)[source]

Checks if a file is a valid point data file

Parameters:source (str) – source file name
Returns:bool – true if source is a point data file
isDataFile(source)[source]

Checks if a file is a valid image data file

Parameters:source (str) – source file name
Returns:bool – true if source is an image data file
createDirectory(filename)[source]

Creates the directory of the file if it does not exists

Parameters:filename (str) – file name
Returns:str – directory name
pointFileNameToType(filename)[source]

Returns type of a point file

Parameters:filename (str) – file name
Returns:str – point data type in pointFileTypes
dataFileNameToType(filename)[source]

Returns type of a image data file

Parameters:filename (str) – file name
Returns:str – image data type in dataFileTypes
dataFileNameToModule(filename)[source]

Return the module that handles io for a data file

Parameters:filename (str) – file name
Returns:object – sub-module that handles a specific data type
pointFileNameToModule(filename)[source]

Return the module that handles io for a point file

Parameters:filename (str) – file name
Returns:object – sub-module that handles a specific point file type
dataSize(source, x=<built-in function all>, y=<built-in function all>, z=<built-in function all>, **args)[source]

Returns array size of the image data needed when read from file and reduced to specified ranges

Parameters:
  • source (array or str) – source data
  • x,y,z (tuple or all) – range specifications, all is full range
Returns:

tuple – size of the image data after reading and range reduction

dataZSize(source, z=<built-in function all>, **args)[source]

Returns size of the array in the third dimension, None if 2D data

Parameters:
  • source (array or str) – source data
  • z (tuple or all) – z-range specification, all is full range
Returns:

int – size of the image data in z after reading and range reduction

toDataRange(size, r=<built-in function all>)[source]

Converts range r to numeric range (min,max) given the full array size

Parameters:
  • size (tuple) – source data size
  • r (tuple or all) – range specification, all is full range
Returns:

tuple – absolute range as pair of integers

toDataSize(size, r=<built-in function all>)[source]

Converts full size to actual size given range r

Parameters:
  • size (tuple) – data size
  • r (tuple or all) – range specification, all is full range
Returns:

int – data size

dataSizeFromDataRange(dataSize, x=<built-in function all>, y=<built-in function all>, z=<built-in function all>, **args)[source]

Converts full data size to actual size given ranges for x,y,z

Parameters:
  • dataSize (tuple) – data size
  • x,z,y (tuple or all) – range specifications, all is full range
Returns:

tuple – data size as tuple of integers

dataToRange(data, x=<built-in function all>, y=<built-in function all>, z=<built-in function all>, **args)[source]

Reduces data to specified ranges

Parameters:
  • data (array) – full data array
  • x,z,y (tuple or all) – range specifications, all is full range
Returns:

array – reduced data

readData(source, **args)[source]

Read data from one of the supported formats

Parameters:
  • source (str, array or None) – full data array, if numpy array simply reduce its range
  • x,z,y (tuple or all) – range specifications, all is full range
  • **args – further arguments specific to image data format reader
Returns:

array – data as numpy array

See also

writeData()

writeData(sink, data, **args)[source]

Write data to one of the supported formats

Parameters:
  • sink (str, array or None) – the destination for the data, if None the data is returned directly
  • data (array or None) – data to be written
  • **args – further arguments specific to image data format writer
Returns:

array, str or None – data or file name of the written data

See also

readData()

copyFile(source, sink)[source]

Copy a file from source to sink

Parameters:
  • source (str) – file name of source
  • sink (str) – file name of sink
Returns:

str – name of the copied file

copyData(source, sink)[source]

Copy a data file from source to sink, which can consist of multiple files

Parameters:
  • source (str) – file name of source
  • sink (str) – file name of sink
Returns:

str – name of the copied file

convertData(source, sink, **args)[source]

Transforms data from source format to sink format

Parameters:
  • source (str) – file name of source
  • sink (str) – file name of sink
Returns:

str – name of the copied file

Warning

Not optimized for large image data sets

toMultiChannelData(*args)[source]

Concatenate single channel arrays to one multi channel array

Parameters:*args (arrays) – arrays to be concatenated
Returns:array – concatenated multi-channel array
pointsToCoordinates(points)[source]

Converts a (coordiantes, properties) tuple to the coordinates only

Parameters:points (array or tuple) – point data to be reduced to coordinates
Returns:array – coordiante data

Notes

Todo: Move this to a class that handles points and their meta data

pointsToProperties(points)[source]

Converts a (coordiante, properties) tuple to the properties only

Parameters:points (array or tuple) – point data to be reduced to properties
Returns:array – property data

Notes

Todo: Move this to a class that handles points and their meta data

pointsToCoordinatesAndProperties(points)[source]

Converts points in various formats to a (coordinates, properties) tuple

Parameters:points (array or tuple) – point data to be converted to (coordinates, properties) tuple
Returns:tuple – (coordinates, properties) tuple

Notes

Todo: Move this to a class that handles points and their meta data

pointsToCoordinatesAndPropertiesFileNames(filename, propertiesPostfix='_intensities', **args)[source]

Generates a tuple of filenames to store coordinates and properties data separately

Parameters:
  • filename (str) – point data file name
  • propertiesPostfix (str) – postfix on file name to indicate property data
Returns:

tuple – (file name, file name for properties)

Notes

Todo: Move this to a class that handles points and their meta data

pointShiftFromRange(dataSize, x=<built-in function all>, y=<built-in function all>, z=<built-in function all>, **args)[source]

Calculate shift of points given a specific range restriction

Parameters:
  • dataSize (str) – data size of the full image
  • x,y,z (tuples or all) – range specifications
Returns:

tuple – shift of points from original origin of data to origin of range reduced data

pointsToRange(points, dataSize=<built-in function all>, x=<built-in function all>, y=<built-in function all>, z=<built-in function all>, shift=False, **args)[source]

Restrict points to a specific range

Parameters:
  • points (array or str) – point source
  • dataSize (str) – data size of the full image
  • x,y,z (tuples or all) – range specifications
  • shift (bool) – shift points to relative coordinates in the reduced image
Returns:

tuple – points reduced in range and optionally shifted to the range reduced origin

readPoints(source, **args)[source]

Read a list of points from csv or vtk

Parameters:
  • source (str, array, tuple or None) – the data source file
  • **args – further arguments specific to point data format reader
Returns:

array or tuple or None – point data of source

See also

writePoints()

writePoints(sink, points, **args)[source]

Write a list of points to csv, vtk or ims files

Parameters:
  • sink (str or None) – the destination for the point data
  • points (array or tuple or None) – the point data, optionally as (coordinates, properties) tuple
  • **args – further arguments specific to point data format writer
Returns:

str or array or tuple or None – point data of source

See also

readPoints()

writeTable(filename, table)[source]

Writes a numpy array with column names to a csv file.

Parameters:
  • filename (str) – filename to save table to
  • table (annotated array) – table to write to file
Returns:

str – file name

ClearMap.IO.CSV module

Interface to write csv files of cell coordinates / intensities

The module utilizes the csv file writer/reader from numpy.

Example

>>> import os, numpy
>>> import ClearMap.IO.CSV as csv
>>> import ClearMap.Settings as settings
>>> filename = os.path.join(settings.ClearMapPath, 'Test/ImageProcessing/points.txt');
>>> points = numpy.random.rand(5,3);
>>> csv.writePoints(filename, points);
>>> points2 = csv.readPoints(filename);
>>> print points2.shape
(5, 3)
writePoints(filename, points, **args)[source]

Write point data to csv file

Parameters:
  • filename (str) – file name
  • points (array) – point data
Returns:

str – file name

readPoints(filename, **args)[source]

Read point data to csv file

Parameters:
  • filename (str) – file name
  • **args – arguments for pointsToRange()
Returns:

str – file name

test()[source]

Test CSV module

ClearMap.IO.FileList module

Interface to read/write image stacks saved as a list of files

The filename is given as regular expression as described here.

It is assumd that there is a single digit like regular expression in the file name, i.e. \d{4} indicates a placeholder for an integer with four digits using traling 0s and \d{} would jus asume an integer with variable size.

For example: /test\d{4}.tif or /test\d{}.tif

Examples

>>> import os, numpy
>>> import ClearMap.Settings as settings
>>> import ClearMap.IO.FileList as fl
>>> filename = os.path.join(settings.ClearMapPath, 'Test/Data/FileList/test\d{4}.tif')
>>> data = numpy.random.rand(20,50,10);
>>> data = data.astype('int32');
>>> fl.writeData(filename, data);
>>> img = fl.readData(filename);
>>> print img.shape
(20, 50, 10)
readFileList(filename)[source]

Returns list of files that match the regular expression

Parameters:filename (str) – file name as regular expression
Returns:str, list – path of files, file names that match the regular expression
splitFileExpression(filename, fileext='.tif')[source]

Split the regular expression at the digit place holder

Parameters:
  • filename (str) – file name as regular expression
  • fileext (str or None) – file extension tu use if filename is a fileheader only
Returns:

tuple – file header, file extension, digit format

fileExpressionToFileName(filename, z)[source]

Insert a number into the regular expression

Parameters:
  • filename (str) – file name as regular expression
  • z (int or str) – z slice index or string to insert
Returns:

str – file name

dataSize(filename, **args)[source]

Returns size of data stored as a file list

Parameters:
  • filename (str) – file name as regular expression
  • x,y,z (tuple) – data range specifications
Returns:

tuple – data size

dataZSize(filename, z=<built-in function all>, **args)[source]

Returns size of data stored as a file list

Parameters:
  • filename (str) – file name as regular expression
  • z (tuple) – z data range specification
Returns:

int – z data size

readDataFiles(filename, x=<built-in function all>, y=<built-in function all>, z=<built-in function all>, **args)[source]

Read data from individual images assuming they are the z slices

Parameters:
  • filename (str) – file name as regular expression
  • x,y,z (tuple) – data range specifications
Returns:

array – image data

readData(filename, **args)[source]

Read image stack from single or multiple images

Parameters:
  • filename (str) – file name as regular expression
  • x,y,z (tuple) – data range specifications
Returns:

array – image data

writeData(filename, data, startIndex=0)[source]

Write image stack to single or multiple image files

Parameters:
  • filename (str) – file name as regular expression
  • data (array) – image data
  • startIndex (int) – index of first z-slice
Returns:

str – file name as regular expression

copyData(source, sink)[source]

Copy a data file from source to sink when for entire list of files

Parameters:
  • source (str) – file name pattern of source
  • sink (str) – file name pattern of sink
Returns:

str – file name patttern of the copy

test()[source]

Test FileList module

ClearMap.IO.Imaris module

Interface to Imaris Files

Module to read data and write points to Imaris files.

Note

To write points without errors make sure the original file has at least one spot object! You can create a fake point in Imaris, then save the file. The point will be overwritten by ClearMap.

Example

>>> import os, numpy
>>> import ClearMap.IO.Imaris as ims
>>> from ClearMap.Settings import ClearMapPath
>>> filename = os.path.join(ClearMapPath,'Test/Data/Imaris/test for spots added spot.ims')
>>> ims.dataSize(filename);
(256, 320, 256)
openFile(filename, mode='a')[source]

Open Imaris file as hdf5 object

Parameters:
  • filename (str) – file name
  • mode (str) – argument to h5py.File
Returns:

object – h5py object

closeFile(h5file)[source]

Close Imaris hdf5 file object

Parameters:h5file (object) – h5py opject
Returns:bool – success
readDataSet(h5file, resolution=0, channel=0, timepoint=0)[source]

Open Imaris file and returns hdf5 image data

Parameters:
  • h5file (object) – h5py object
  • resolution (int) – resolution level
  • channel (int) – color channel
  • timepoint (int) – time point
Returns:

array – image data

dataSize(filename, resolution=0, channel=0, timepoint=0, **args)[source]

Read data size of the imaris image data set

Parameters:
  • filename (str) – imaris file name
  • resolution (int) – resolution level
  • channel (int) – color channel
  • timepoint (int) – time point
Returns:

tuple – image data size

dataZSize(filename, **args)[source]

Read z data size of the imaris image data set

Parameters:
  • filename (str) – imaris file name
  • resolution (int) – resolution level
  • channel (int) – color channel
  • timepoint (int) – time point
Returns:

int – image z data size

readData(filename, x=<built-in function all>, y=<built-in function all>, z=<built-in function all>, resolution=0, channel=0, timepoint=0, **args)[source]

Read data from imaris file

Parameters:
  • filename (str) – file name as regular expression
  • x,y,z (tuple) – data range specifications
  • resolution (int) – resolution level
  • channel (int) – color channel
  • timepoint (int) – time point
Returns:

array – image data

getDataSize(h5file)[source]

Get the full data size in pixel from h5py imaris object

Parameters:h5file (object) – h5py object
Returns:tuple – image data size
getDataExtent(h5file)[source]

Get the spatial extent of data from h5py imaris object

Parameters:h5file (object) – h5py object
Returns:array – spatial extend of image
getScaleAndOffset(h5file)[source]

Determine scale and offset to transform pixel to spatial coordinates as used by imaris

Parameters:h5file (object) – h5py object
Returns:tuple – image scale (length / pixel) and offset (from origin)
transformPointsToImaris(points, scale=(4.0625, 4.0625, 3), offset=(0, 0, 0))[source]

Transform pixel coordinates of cell centers to work in Imaris

Parameters:
  • points (array) – point coordinate array
  • scale (tuple) – spatial scale of the image data
  • offset (tuple) – spatial offset of the image data
Returns:

array – scaled points

writePoints(filename, points, mode='o', radius=0.5, scale=<built-in function all>, offset=None)[source]

Write points to Imaris file

Parameters:
  • filename (str) – imaris file name
  • points (array) – point data
  • mode (str) – ‘o’= override, ‘a’=add
  • radius (float) – size of each point
  • scale (tuple or all) – spatial scaling of points
  • offset (tuple or None) – spatial offset of points
Returns:

str – file name of imaris file

Note

This routine is still experimental !

writeData(filename, **args)[source]

Write image data to imaris file

Note

Not implemented yet !

readPoints(filename)[source]

Read points from imaris file

Note

Not implemented yet !

copyData(source, sink)[source]

Copy a imaris file from source to sink

Parameters:
  • source (str) – file name pattern of source
  • sink (str) – file name pattern of sink
Returns:

str – file name patttern of the copy

test()[source]

Test Imaris module

ClearMap.IO.NPY module

Interface to write binary files for point like data

The interface is based on the numpy library.

Example

>>> import os, numpy
>>> import ClearMap.Settings as settings
>>> import ClearMap.IO.NPY as npy
>>> filename = os.path.join(settings.ClearMapPath, 'Test/Data/NPY/points.npy');
>>> points = npy.readPoints(filename);
>>> print points.shape
(5, 3)
writePoints(filename, points, **args)[source]
readPoints(filename, **args)[source]
test()[source]

Test NPY module

ClearMap.IO.NRRD module

Interface to NRRD volumetric image data files.

The interface is based on nrrd.py, an all-python (and numpy) implementation for reading and writing nrrd files. See http://teem.sourceforge.net/nrrd/format.html for the specification.

Example

>>> import os, numpy
>>> import ClearMap.Settings as settings
>>> import ClearMap.IO.NRRD as nrrd
>>> filename = os.path.join(settings.ClearMapPath, 'Test/Data/Nrrd/test.nrrd');
>>> data = nrrd.readData(filename);
>>> print data.shape
(20, 50, 10)

Author

Copyright 2011 Maarten Everts and David Hammond.

Modified to integrate into ClearMap framework by Christoph Kirst, The Rockefeller University, New York City, 2015

exception NrrdError[source]

Bases: exceptions.Exception

Exceptions for Nrrd class.

parse_nrrdvector(inp)[source]

Parse a vector from a nrrd header, return a list.

parse_optional_nrrdvector(inp)[source]

Parse a vector from a nrrd header that can also be none.

readHeader(filename)[source]

Parse the fields in the nrrd header

nrrdfile can be any object which supports the iterator protocol and returns a string each time its next() method is called — file objects and list objects are both suitable. If csvfile is a file object, it must be opened with the ‘b’ flag on platforms where that makes a difference (e.g. Windows)

>>> readHeader(("NRRD0005", "type: float", "dimension: 3"))
{'type': 'float', 'dimension': 3, 'keyvaluepairs': {}}
>>> readHeader(("NRRD0005", "my extra info:=my : colon-separated : values"))
{'keyvaluepairs': {'my extra info': 'my : colon-separated : values'}}
readData(filename, **args)[source]

Read nrrd file image data

Parameters:
  • filename (str) – file name as regular expression
  • x,y,z (tuple) – data range specifications
Returns:

array – image data

writeData(filename, data, options={}, separateHeader=False)[source]

Write data to nrrd file

Parameters:
  • filename (str) – file name as regular expression
  • data (array) – image data
  • options (dict) – options dictionary
  • separateHeader (bool) – write a separate header file
Returns:

str – nrrd output file name

To sample date use options[‘spacings’] = [s1, s2, s3] for 3d data with sampling deltas s1, s2, and s3 in each dimension.

dataSize(filename, **args)[source]

Read data size from nrrd image

Parameters:
  • filename (str) – file name as regular expression
  • x,y,z (tuple) – data range specifications
Returns:

tuple – data size

dataZSize(filename, z=<built-in function all>, **args)[source]

Read data z size from nrrd image

Parameters:
  • filename (str) – file name as regular expression
  • z (tuple) – z data range specification
Returns:

int – z data size

copyData(source, sink)[source]

Copy an nrrd file from source to sink

Parameters:
  • source (str) – file name pattern of source
  • sink (str) – file name pattern of sink
Returns:

str – file name of the copy

Notes

Todo: dealt with nrdh header files!

test()[source]

Test NRRD IO module

ClearMap.IO.RAW module

Simple Interface to read RAW/MHD files e.g. created by elastix

Todo: read subsets efficiently

Example

>>> import os, numpy
>>> from ClearMap.Settings import ClearMapPath
>>> import ClearMap.IO.RAW as raw
>>> filename = os.path.join(ClearMapPath, 'Test/Data/Raw/test.mhd')
>>> raw.dataSize(filename);
(20, 50, 10)
dataSize(filename, **args)[source]

Read data size from raw/mhd image

Parameters:
  • filename (str) – imaris file name
  • x,y,z (tuple or all) – range specifications
Returns:

int – raw image data size

dataZSize(filename, z=<built-in function all>, **args)[source]

Read z data size from raw/mhd image

Parameters:
  • filename (str) – imaris file name
  • z (tuple or all) – range specification
Returns:

int – raw image z data size

readData(filename, x=<built-in function all>, y=<built-in function all>, z=<built-in function all>)[source]

Read data from raw/mhd image

Parameters:
  • filename (str) – file name as regular expression
  • x,y,z (tuple) – data range specifications
Returns:

array – image data

writeHeader(filename, meta_dict)[source]

Write raw header mhd file

Parameters:
  • filename (str) – file name of header
  • meta_dict (dict) – dictionary of meta data
Returns:

str – header file name

writeRawData(filename, data)[source]

Write the data into a raw format file.

Parameters:
  • filename (str) – file name as regular expression
  • data (array) – data to write to raw file
Returns:

str – file name of raw file

writeData(filename, data, **args)[source]

Write data into to raw/mhd file pair

Parameters:
  • filename (str) – file name as regular expression
  • data (array) – data to write to raw file
Returns:

str – file name of mhd file

copyData(source, sink)[source]

Copy a raw/mhd file pair from source to sink

Parameters:
  • source (str) – file name of source
  • sink (str) – file name of sink
Returns:

str – file name of the copy

test()[source]

Test RAW io module

ClearMap.IO.TIF module

Interface to tif image files and stacks.

The interface makes use of the tifffile library.

Example

>>> import os, numpy
>>> import ClearMap.IO.TIF as tif
>>> from ClearMap.Settings import ClearMapPath
>>> filename = os.path.join(ClearMapPath,'Test/Data/Tif/composite.tif')
>>> data = tif.readData(filename);
>>> print data.shape
(50, 100, 30, 4)
dataSize(filename, **args)[source]

Returns size of data in tif file

Parameters:
  • filename (str) – file name as regular expression
  • x,y,z (tuple) – data range specifications
Returns:

tuple – data size

dataZSize(filename, z=<built-in function all>, **args)[source]

Returns z size of data in tif file

Parameters:
  • filename (str) – file name as regular expression
  • z (tuple) – z data range specification
Returns:

int – z data size

readData(filename, x=<built-in function all>, y=<built-in function all>, z=<built-in function all>, **args)[source]

Read data from a single tif image or stack

Parameters:
  • filename (str) – file name as regular expression
  • x,y,z (tuple) – data range specifications
Returns:

array – image data

writeData(filename, data)[source]

Write image data to tif file

Parameters:
  • filename (str) – file name
  • data (array) – image data
Returns:

str – tif file name

copyData(source, sink)[source]

Copy a data file from source to sink

Parameters:
  • source (str) – file name pattern of source
  • sink (str) – file name pattern of sink
Returns:

str – file name of the copy

test()[source]

Test TIF module

ClearMap.IO.VTK module

Interface to write points to VTK files

Notes

  • points are assumed to be in [x,y,z] coordinates as standard in ClearMap
  • reading of points not supported at the moment!
writePoints(filename, points, labelImage=None)[source]

Write point data to vtk file

Parameters:
  • filename (str) – file name
  • points (array) – point data
  • labelImage (str, array or None) – optional label image to determine point label
Returns:

str – file name

readPoints(filename, **args)[source]

Read points form vtk file

Notes

  • Not implmented yet !