leicaexperiment API reference

leicaexperiment package

class leicaexperiment.Experiment(path)[source]
compress(delete_tif=False, folder=None)[source]

Lossless compress all images in experiment to PNG. If folder is omitted, images will not be moved.

Images which already exists in PNG are omitted.

Parameters:
  • folder (string) – Where to store PNGs. Defaults to the folder they are in.
  • delete_tif (bool) – If set to truthy value, ome.tifs will be deleted after compression.
Returns:

Filenames of PNG images. Files which already exists before compression are also returned.

Return type:

list

field_columns(well_row, well_column)[source]

Field columns for given well. Equivalent to –X in files.

Parameters:
  • well_row (int) – Starts at 0. Same as –V in files.
  • well_column (int) – Starts at 0. Same as –U in files.
Returns:

Columns found for specified well.

Return type:

list of ints

field_metadata(well_row=0, well_column=0, field_row=0, field_column=0)[source]

Get OME-XML metadata of given field.

Parameters:
  • well_row (int) – Y well coordinate. Same as –V in files.
  • well_column (int) – X well coordinate. Same as –U in files.
  • field_row (int) – Y field coordinate. Same as –Y in files.
  • field_column (int) – X field coordinate. Same as –X in files.
Returns:

lxml object of OME-XML found in slide/chamber/field/metadata.

Return type:

lxml.objectify.ObjectifiedElement

field_rows(well_row, well_column)[source]

Field rows for given well. Equivalent to –Y in files.

Parameters:
  • well_column (int) – Starts at 0. Same as –U in files.
  • well_row (int) – Starts at 0. Same as –V in files.
Returns:

Rows found for specified well.

Return type:

list of ints

fields

List of paths to fields.

image(well_row, well_column, field_row, field_column)[source]

Get path of specified image.

Parameters:
  • well_row (int) – Starts at 0. Same as –U in files.
  • well_column (int) – Starts at 0. Same as –V in files.
  • field_row (int) – Starts at 0. Same as –Y in files.
  • field_column (int) – Starts at 0. Same as –X in files.
Returns:

Path to image or empty string if image is not found.

Return type:

string

images

List of paths to images.

scanning_template

Path to {ScanningTemplate}name.xml of experiment.

slides

List of paths to slides.

stitch(folder=None)[source]

Stitches all wells in experiment with ImageJ. Stitched images are saved in experiment root.

Images which already exists are omitted stitching.

Parameters:folder (string) – Where to store stitched images. Defaults to experiment path.
Returns:Filenames of stitched images. Files which already exists before stitching are also returned.
Return type:list
stitch_coordinates(well_row=0, well_column=0)[source]

Get a list of stitch coordinates for the given well.

Parameters:
  • well_row (int) – Y well coordinate. Same as –V in files.
  • well_column (int) – X well coordinate. Same as –U in files.
Returns:

(xs, ys, attr) – Tuple of x’s, y’s and attributes.

Return type:

tuples with float and collections.OrderedDict

stitched

List of stitched images if they are in experiment folder.

well_columns

All well columns in experiment. Equivalent to –V in files.

Returns:
Return type:list of ints
well_images(well_row, well_column)[source]

Get list of paths to images in specified well.

Parameters:
  • well_row (int) – Starts at 0. Same as –V in files.
  • well_column (int) – Starts at 0. Save as –U in files.
Returns:

Paths to images or empty list if no images are found.

Return type:

list of strings

well_rows

All well rows in experiment. Equivalent to –U in files.

Returns:
Return type:list of ints
wells

List of paths to wells.

leicaexperiment.compress(images, delete_tif=False, folder=None)[source]

Lossless compression. Save images as PNG and TIFF tags to json. Can be reversed with decompress. Will run in multiprocessing, where number of workers is decided by leicaexperiment.experiment._pools.

Parameters:
  • images (list of filenames) – Images to lossless compress.
  • delete_tif (bool) – Wheter to delete original images.
  • folder (string) – Where to store images. Basename will be kept.
Returns:

List of compressed files.

Return type:

list of filenames

leicaexperiment.decompress(images, delete_png=False, delete_json=False, folder=None)[source]

Reverse compression from tif to png and save them in original format (ome.tif). TIFF-tags are gotten from json-files named the same as given images.

Parameters:
  • images (list of filenames) – Image to decompress.
  • delete_png (bool) – Wheter to delete PNG images.
  • delete_json (bool) – Wheter to delete TIFF-tags stored in json files on compress.
Returns:

List of decompressed files.

Return type:

list of filenames

leicaexperiment.attribute(path, name)[source]

Returns the two numbers found behind –[A-Z] in path. If several matches are found, the last one is returned.

Parameters:
  • path (string) – String with path of file/folder to get attribute from.
  • name (string) – Name of attribute to get. Should be A-Z or a-z (implicit converted to uppercase).
Returns:

Returns number found in path behind –name as an integer.

Return type:

integer

leicaexperiment.attribute_as_str(path, name)[source]

Returns the two numbers found behind –[A-Z] in path. If several matches are found, the last one is returned.

Parameters:
  • path (string) – String with path of file/folder to get attribute from.
  • name (string) – Name of attribute to get. Should be A-Z or a-z (implicit converted to uppercase).
Returns:

Returns two digit number found in path behind –name.

Return type:

string

leicaexperiment.attributes(path)[source]

Get attributes from path based on format –[A-Z]. Returns namedtuple with upper case attributes equal to what found in path (string) and lower case as int. If path holds several occurrences of same character, only the last one is kept.

>>> attrs = attributes('/folder/file--X00-X01.tif')
>>> print(attrs)
namedtuple('attributes', 'X x')('01', 1)
>>> print(attrs.x)
1
Parameters:path (string) –
Returns:
Return type:collections.namedtuple

Submodules

leicaexperiment.experiment module

Access matrix scans from Leica LAS AF MatrixScreener (Data Exporter) through an object.

class leicaexperiment.experiment.Experiment(path)[source]
compress(delete_tif=False, folder=None)[source]

Lossless compress all images in experiment to PNG. If folder is omitted, images will not be moved.

Images which already exists in PNG are omitted.

Parameters:
  • folder (string) – Where to store PNGs. Defaults to the folder they are in.
  • delete_tif (bool) – If set to truthy value, ome.tifs will be deleted after compression.
Returns:

Filenames of PNG images. Files which already exists before compression are also returned.

Return type:

list

field_columns(well_row, well_column)[source]

Field columns for given well. Equivalent to –X in files.

Parameters:
  • well_row (int) – Starts at 0. Same as –V in files.
  • well_column (int) – Starts at 0. Same as –U in files.
Returns:

Columns found for specified well.

Return type:

list of ints

field_metadata(well_row=0, well_column=0, field_row=0, field_column=0)[source]

Get OME-XML metadata of given field.

Parameters:
  • well_row (int) – Y well coordinate. Same as –V in files.
  • well_column (int) – X well coordinate. Same as –U in files.
  • field_row (int) – Y field coordinate. Same as –Y in files.
  • field_column (int) – X field coordinate. Same as –X in files.
Returns:

lxml object of OME-XML found in slide/chamber/field/metadata.

Return type:

lxml.objectify.ObjectifiedElement

field_rows(well_row, well_column)[source]

Field rows for given well. Equivalent to –Y in files.

Parameters:
  • well_column (int) – Starts at 0. Same as –U in files.
  • well_row (int) – Starts at 0. Same as –V in files.
Returns:

Rows found for specified well.

Return type:

list of ints

fields

List of paths to fields.

image(well_row, well_column, field_row, field_column)[source]

Get path of specified image.

Parameters:
  • well_row (int) – Starts at 0. Same as –U in files.
  • well_column (int) – Starts at 0. Same as –V in files.
  • field_row (int) – Starts at 0. Same as –Y in files.
  • field_column (int) – Starts at 0. Same as –X in files.
Returns:

Path to image or empty string if image is not found.

Return type:

string

images

List of paths to images.

scanning_template

Path to {ScanningTemplate}name.xml of experiment.

slides

List of paths to slides.

stitch(folder=None)[source]

Stitches all wells in experiment with ImageJ. Stitched images are saved in experiment root.

Images which already exists are omitted stitching.

Parameters:folder (string) – Where to store stitched images. Defaults to experiment path.
Returns:Filenames of stitched images. Files which already exists before stitching are also returned.
Return type:list
stitch_coordinates(well_row=0, well_column=0)[source]

Get a list of stitch coordinates for the given well.

Parameters:
  • well_row (int) – Y well coordinate. Same as –V in files.
  • well_column (int) – X well coordinate. Same as –U in files.
Returns:

(xs, ys, attr) – Tuple of x’s, y’s and attributes.

Return type:

tuples with float and collections.OrderedDict

stitched

List of stitched images if they are in experiment folder.

well_columns

All well columns in experiment. Equivalent to –V in files.

Returns:
Return type:list of ints
well_images(well_row, well_column)[source]

Get list of paths to images in specified well.

Parameters:
  • well_row (int) – Starts at 0. Same as –V in files.
  • well_column (int) – Starts at 0. Save as –U in files.
Returns:

Paths to images or empty list if no images are found.

Return type:

list of strings

well_rows

All well rows in experiment. Equivalent to –U in files.

Returns:
Return type:list of ints
wells

List of paths to wells.

leicaexperiment.experiment.attribute(path, name)[source]

Returns the two numbers found behind –[A-Z] in path. If several matches are found, the last one is returned.

Parameters:
  • path (string) – String with path of file/folder to get attribute from.
  • name (string) – Name of attribute to get. Should be A-Z or a-z (implicit converted to uppercase).
Returns:

Returns number found in path behind –name as an integer.

Return type:

integer

leicaexperiment.experiment.attribute_as_str(path, name)[source]

Returns the two numbers found behind –[A-Z] in path. If several matches are found, the last one is returned.

Parameters:
  • path (string) – String with path of file/folder to get attribute from.
  • name (string) – Name of attribute to get. Should be A-Z or a-z (implicit converted to uppercase).
Returns:

Returns two digit number found in path behind –name.

Return type:

string

leicaexperiment.experiment.attributes(path)[source]

Get attributes from path based on format –[A-Z]. Returns namedtuple with upper case attributes equal to what found in path (string) and lower case as int. If path holds several occurrences of same character, only the last one is kept.

>>> attrs = attributes('/folder/file--X00-X01.tif')
>>> print(attrs)
namedtuple('attributes', 'X x')('01', 1)
>>> print(attrs.x)
1
Parameters:path (string) –
Returns:
Return type:collections.namedtuple
leicaexperiment.experiment.compress(images, delete_tif=False, folder=None)[source]

Lossless compression. Save images as PNG and TIFF tags to json. Can be reversed with decompress. Will run in multiprocessing, where number of workers is decided by leicaexperiment.experiment._pools.

Parameters:
  • images (list of filenames) – Images to lossless compress.
  • delete_tif (bool) – Wheter to delete original images.
  • folder (string) – Where to store images. Basename will be kept.
Returns:

List of compressed files.

Return type:

list of filenames

leicaexperiment.experiment.compress_blocking(image, delete_tif=False, folder=None, force=False)[source]

Lossless compression. Save image as PNG and TIFF tags to json. Process can be reversed with decompress.

Parameters:
  • image (string) – TIF-image which should be compressed lossless.
  • delete_tif (bool) – Wheter to delete original images.
  • force (bool) – Wheter to compress even if .png already exists.
Returns:

Filename of compressed image, or empty string if compress failed.

Return type:

string

leicaexperiment.experiment.decompress(images, delete_png=False, delete_json=False, folder=None)[source]

Reverse compression from tif to png and save them in original format (ome.tif). TIFF-tags are gotten from json-files named the same as given images.

Parameters:
  • images (list of filenames) – Image to decompress.
  • delete_png (bool) – Wheter to delete PNG images.
  • delete_json (bool) – Wheter to delete TIFF-tags stored in json files on compress.
Returns:

List of decompressed files.

Return type:

list of filenames

leicaexperiment.experiment.glob(pattern)[source]

Sorted glob.

leicaexperiment.experiment.stitch_macro(path, output_folder=None)[source]

Create fiji-macros for stitching all channels and z-stacks for a well.

Parameters:
  • path (string) – Well path.
  • output_folder (string) – Folder to store images. If not given well path is used.
Returns:

output_files, macros – Tuple with filenames and macros for stitched well.

Return type:

tuple

leicaexperiment.utils module

leicaexperiment.utils.chop(list_, n)[source]

Chop list_ into n chunks. Returns a list.