pyImagingMSpec package

Submodules

pyImagingMSpec.image_measures module

pyImagingMSpec.image_measures.isotope_image_correlation(images_flat, weights=None)[source]

Function for calculating a weighted average measure of image correlation with the principle image.

Parameters:
  • images_flat – 2d array (or sequence of 1d arrays) of pixel intensities with shape (d1, d2) where d1 is the number of images and d2 is the number of pixels per image, i.e. images_flat[i] is the i-th flattened image
  • weights – 1d array (or sequence) of weights with shape (d1 - 1), i.e weights[i] is the weight to put on the correlation between the first and the i-th image. If omitted, all correlations are weighted equally
Returns:

measure_value (zero if less than 2 images are given)

Raises:
  • TypeError – if images are not 1d
  • ValueError – if images are not equally shaped or if the number of correlations and the number of weights (if given) differ
pyImagingMSpec.image_measures.isotope_pattern_match(images_flat, theor_iso_intensities)[source]

This function calculates a match between a list of isotope ion images and a theoretical intensity vector.

Parameters:
  • images_flat – 2d array (or sequence of 1d arrays) of pixel intensities with shape (d1, d2) where d1 is the number of images and d2 is the number of pixels per image, i.e. images_flat[i] is the i-th flattened image
  • theor_iso_intensities – 1d array (or sequence) of theoretical isotope intensities with shape d1, i.e theor_iso_intensities[i] is the theoretical isotope intensity corresponding to the i-th image
Returns:

measure value between 0 and 1, bigger is better

Return type:

float

Raises:
  • TypeError – if images are not 1d
  • ValueError – if images are not equally shaped or if the number of images and the number of intensities differ
pyImagingMSpec.image_measures.measure_of_chaos(im, nlevels, overwrite=True, statistic=None)[source]

Compute a measure for the spatial chaos in given image using the level sets method.

Parameters:
  • im – 2d array
  • nlevels (int) – how many levels to use
  • overwrite (bool) – Whether the input image can be overwritten to save memory
  • statistic – callable that calculates a score (a number) for the object counts in the level sets. If

specified, this statistic will be used instead of the default one. The callable must take two arguments - the object counts (sequence of ints) and the number of non-zero pixels in the original image (int) - and output a number :return: the measured value :rtype: float :raises ValueError: if nlevels <= 0 or q_val is an invalid percentile or an unknown interp value is used

pyImagingMSpec.image_measures.measure_of_chaos_fit(im, nlevels, overwrite=True)[source]

This function is identical to measure_of_chaos except that it uses a different statistic.

pyImagingMSpec.imutils module

pyImagingMSpec.imutils.interpolate(im, notnull_mask=None)[source]

Use spline interpolation to fill in missing values.

Parameters:
  • im – the entire image, including nan or zero values
  • notnull_mask – index array for the values greater than zero. If None, no mask is used
Returns:

the interpolated array

pyImagingMSpec.imutils.nan_to_zero(im)[source]

Set all values to zero that are less than zero or nan; return the indices of all elements that are zero after the modification (i.e. those that have been nan or smaller than or equal to zero before calling this function). The returned boolean array has the same shape, False denotes that a value is zero now.

Parameters:im – the array which nan-values will be set to zero in-place
Returns:A boolean array of the same shape as im
pyImagingMSpec.imutils.quantile_threshold(im, q_val, notnull_mask=None)[source]

Set all values greater than the q_val-th percentile to the q_val-th percentile (i.e. flatten out everything greater than the q_val-th percentile). For determining the percentile, only nonzero pixels are taken into account, that is im[notnull_mask].

Parameters:
  • im – the array to remove the hotspots from
  • q_val – percentile to use
  • notnull_mask – index array for the values greater than zero. If None, no mask is used
Returns:

The q_val-th percentile

pyImagingMSpec.inMemoryIMS module

class pyImagingMSpec.inMemoryIMS.inMemoryIMS(filename, min_mz=0.0, max_mz=<sphinx.ext.autodoc._MockModule object>, min_int=0.0, index_range=[], cache_spectra=True, do_summary=True, norm='none')[source]
empty_datacube()[source]
generate_histogram_axis(ppm=1.0)[source]
generate_summary_spectrum(summary_type='mean', ppm=1.0)[source]
get_coords()[source]
get_coords_hdf5()[source]
get_coords_imzml()[source]
get_histogram_axis(ppm=1.0)[source]
get_ion_image(mzs, tols, tol_type='ppm')[source]
get_spectrum(index)[source]
get_spectrum_hdf5(index)[source]
get_spectrum_imzml(index)[source]
get_step_size()[source]
get_summary_image(summary_func='tic')[source]
load_file(filename, min_mz=0, max_mz=<sphinx.ext.autodoc._MockModule object>, min_int=0, index_range=[], cache_spectra=True, do_summary=True, norm=[])[source]

pyImagingMSpec.ion_datacube module

class pyImagingMSpec.ion_datacube.ion_datacube(step_size=[])[source]
add_coords(coords)[source]
add_xic(xic, mz, tol)[source]
apply_image_processing(smooth_method, **smooth_params)[source]

Function to apply pre-defined image processing methods to ion_datacube #todo: expose parameters in config :param ion_datacube:

object from pyImagingMSpec.ion_datacube already containing images
Returns:ion_datacube is updated in place. None returned
calculate_bounding_box()[source]
coord_to_index(transform_type='reg_grid', params=())[source]
image_to_xic(im)[source]

takes an image (presumably generated by xic to image) and returns a vector suitable for insertion into the datacube :param im:

numpy 2d array
Returns:numpy vector
remove_xic(mz)[source]
xic_to_image(xic_index)[source]

pyImagingMSpec.smoothing module

pyImagingMSpec.smoothing.hot_spot_removal(xic, q=99.0)[source]
pyImagingMSpec.smoothing.median(im, **kwargs)[source]

Module contents