ImzMLWriter

pyimzml.ImzMLWriter module

class pyimzml.ImzMLWriter.ImzMLWriter(output_filename, mz_dtype=<class 'numpy.float64'>, intensity_dtype=<class 'numpy.float32'>, mode='auto', spec_type='centroid', scan_direction='top_down', line_scan_direction='line_left_right', scan_pattern='one_way', scan_type='horizontal_line', mz_compression=<pyimzml.compression.NoCompression object>, intensity_compression=<pyimzml.compression.NoCompression object>, polarity=None)[source]

Create an imzML+ibd file.

Parameters
  • output_filename – is used to make the base name by removing the extension (if any). two files will be made by adding “.ibd” and “.imzML” to the base name

  • intensity_dtype – The numpy data type to use for saving intensity values

  • mz_dtype – The numpy data type to use for saving mz array values

  • mode

    • “continuous” mode will save the first mz array only

    • ”processed” mode save every mz array separately

    • ”auto” mode writes only mz arrays that have not already been written

  • intensity_compression – How to compress the intensity data before saving must be an instance of NoCompression or ZlibCompression

  • mz_compression – How to compress the mz array data before saving

addSpectrum(mzs, intensities, coords, userParams=[])[source]

Add a mass spectrum to the file.

Parameters
  • mz – mz array

  • intensities – intensity array

  • coords

    • 2-tuple of x and y position OR

    • 3-tuple of x, y, and z position

    note some applications want coords to be 1-indexed

close()[source]

Writes the XML file and closes all files. Will be called automatically if with-pattern is used.

finish()[source]

alias of close()

pyimzml.compression module

This module holds adapters for compressing an ImzML file’s binary data, currently only usable with ImzMLWriter.

class pyimzml.compression.NoCompression[source]

No compression.

compress(bytes)[source]
decompress(bytes)[source]
name = 'no compression'
rounding(data)[source]
class pyimzml.compression.ZlibCompression(round_amt=None)[source]

Zlib compression with optional rounding of values. Rounding helps the compression, but is lossy.

Parameters

round_amt – Number of digits after comma. None means no rounding.

compress(bytes)[source]
decompress(bytes)[source]
name = 'zlib compression'
rounding(data)[source]