holopy.core.io package
Submodules
holopy.core.io.io module
Common entry point for holopy io. Dispatches to the correct load/save functions.
- class Accumulator
Bases:
objectCalculates average and coefficient of variance for numerical data in one pass using Welford’s algorithm.
- mean()
- push(x)
- std()
- default_extension(inf, defext='.h5')
- get_example_data(name)
- get_example_data_path(name)
- load(inf, lazy=False)
Load data or results
- Parameters:
inf (string) – String specifying an hdf5 file containing holopy data
- Returns:
obj – The array object contained in the file
- Return type:
xarray.DataArray
- load_average(filepath, refimg=None, spacing=None, medium_index=None, illum_wavelen=None, illum_polarization=None, noise_sd=None, channel=None, image_glob='*.tif')
Average a set of images (usually as a background)
- Parameters:
filepath (string or list(string)) – Directory or list of filenames or filepaths. If filename is a directory, it will average all images matching image_glob.
refimg (xarray.DataArray) – reference image to provide spacing and metadata for the new image.
spacing (float) – Spacing between pixels in the images. Used preferentially over refimg value if both are provided.
medium_index (float) – Refractive index of the medium in the images. Used preferentially over refimg value if both are provided.
illum_wavelen (float) – Wavelength of illumination in the images. Used preferentially over refimg value if both are provided.
illum_polarization (list-like) – Polarization of illumination in the images. Used preferentially over refimg value if both are provided.
image_glob (string) – Glob used to select images (if images is a directory)
- Returns:
averaged_image – Image which is an average of images noise_sd attribute contains average pixel stdev normalized by total image intensity
- Return type:
xarray.DataArray
- load_image(inf, spacing=None, medium_index=None, illum_wavelen=None, illum_polarization=None, noise_sd=None, channel=None, name=None)
Load data or results
- Parameters:
inf (string) – File to load.
spacing (float or (float, float) (optional)) – pixel size of images in each dimension - assumes square pixels if single value. set equal to 1 if not passed in and issues warning.
medium_index (float (optional)) – refractive index of the medium
illum_wavelen (float (optional)) – wavelength (in vacuum) of illuminating light
illum_polarization ((float, float) (optional)) – (x, y) polarization vector of the illuminating light
noise_sd (float (optional)) – noise level in the image, normalized to image intensity
channel (int or tuple of ints (optional)) – number(s) of channel to load for a color image (in general 0=red, 1=green, 2=blue) name : str (optional) name to assign the xr.DataArray object resulting from load_image
- Returns:
obj
- Return type:
xarray.DataArray representation of the image with associated metadata
- pack_attrs(a, do_spacing=False)
- save(outf, obj)
Save a holopy object
Will save objects as yaml text containing all information about the object unless outf is a filename with an image extension, in which case it will save an image, truncating metadata.
- Parameters:
outf (basestring or file) – Location to save the object
obj (
holopy.core.holopy_object.HoloPyObject) – The object to save
- save_image(filename, im, scaling='auto', depth=8)
Save an ndarray or image as a tiff.
- Parameters:
filename (basestring) – filename in which to save image. If im is an image the function should default to the image’s name field if no filename is specified
im (ndarray or
holopy.image.Image) – image to save.scaling ('auto', None, or (Int, Int)) – How the image should be scaled for saving. Ignored for float output. It defaults to auto, use the full range of the output format. Other options are None, meaning no scaling, or a pair of integers specifying the values which should be set to the maximum and minimum values of the image format.
depth (8, 16 or 'float') – What type of image to save. Options other than 8bit may not be supported for many image types. You probably don’t want to save 8bit images without some kind of scaling.
- save_images(filenames, ims, scaling='auto', depth=8)
Saves a volume as separate images (think of reconstruction volumes).
- Parameters:
filenames (list) – List of filenames. There have to be the same number of filenames as of images to save. Each image will be saved in the corresponding file with the same index.
ims (ndarray or
holopy.image.Image) – Images to save, with separate z-coordinates from which they each will be selected.scaling ('auto', None, or (Int, Int)) – How the images should be scaled for saving. Ignored for float output. It defaults to auto, use the full range of the output format. Other options are None, meaning no scaling, or a pair of integers specifying the values which should be set to the maximum and minimum values of the image format.
depth (8, 16 or 'float') – What type of image to save. Options other than 8bit may not be supported for many image types. You probably don’t want to save 8bit images without some kind of scaling.
- unpack_attrs(a)
holopy.core.io.serialize module
Reading and writing of yaml files.
yaml files are structured text files designed to be easy for humans to read and write but also easy for computers to read. HoloPy uses them to store information about experimental conditions and to describe analysis procedures.
- class_loader(loader, node)
- class_representer(dumper, data)
- complex_constructor(loader, node)
- complex_representer(dumper, data)
- ignore_aliases(data)
- instancemethod_constructor(loader, node)
- instancemethod_representer(dumper, data)
- load(inf)
- ndarray_representer(dumper, data)
- numpy_float_representer(dumper, data)
- numpy_int_representer(dumper, data)
- numpy_ufunc_constructor(loader, node)
- numpy_ufunc_representer(dumper, data)
- save(outf, obj)
- tuple_representer(dumper, data)
holopy.core.io.vis module
Prepare HoloPy objects for display on screen or write to file.
- class Show2D(im)
Bases:
object- click(event)
- draw()
- format_coord(x, y)
- check_display()
Diagnostic test to check matplotlib backend.
You should see a white square inside a black square, with a colorbar. Pressing the left or right arrow keys should cycle through z.
You should see: Z = 0 : A white axes-aligned square Z = 1 : A white circle Z = 2 : A white diamond (square at 45 degrees)
- display_image(im, scaling='auto', vert_axis='x', horiz_axis='y', depth_axis='z', colour_axis='illumination')
- save_plot(filenames, data, scaling='auto', vert_axis='x', horiz_axis='y', depth_axis='z', colour_axis='illumination')
Saves a hologram or reconstruction to (a) file(s).
- Parameters:
filenames (list / str) – Name(s) of the file(s).
data (xarray.DataArray or ndarray) – Object to save.
scaling ((float, float), optional) – (min, max) value to display in image, default is full range of o.
vert_axis (str, optional) – axis to display vertically, default x.
horiz_axis (str, optional) – axis to display horizontally, default y.
depth_axis (str, optional) – axis to scroll with arrow keys, default ‘z’.
colour_axis (str, optional) – axis to display as RGB channels in colour image, default illumination.
Notes
Loads plotting library the first time it is required (so that we don’t have to import all of matplotlib or mayavi just to load holopy)
- show(obj, scaling='auto', vert_axis='x', horiz_axis='y', depth_axis='z', colour_axis='illumination')
Visualize a hologram or reconstruction
- Parameters:
obj (xarray.DataArray or ndarray) – Object to visualize
scaling ((float, float), optional) – (min, max) value to display in image, default is full range of o.
vert_axis (str, optional) – axis to display vertically, default x.
horiz_axis (str, optional) – axis to display horizontally, default y.
depth_axis (str, optional) – axis to scroll with arrow keys, default ‘z’.
colour_axis (str, optional) – axis to display as RGB channels in colour image, default illumination.
Notes
Loads plotting library the first time it is required (so that we don’t have to import all of matplotlib or mayavi just to load holopy)
- show_scatterer_slices(scatterer, spacing)
Show slices of a scatterer voxelation
- scatterer.Scatterer
scatterer to visualize
- spacingfloat or (float, float, float)
voxel spacing for the visualization
- show_sphere_cluster(s, color)
This function to show a 3D rendering of a Spheres obj hasn’t worked since HoloPy 3.0, due to Mayavi compatibility issues. We keep the code because we hope to re-implement this functionality eventually.