EMSA/MSA format#

The .msa format is an open standard format widely used to exchange single spectrum data, but does not support multidimensional data. It can for example be used to exchange single spectra with Gatan’s Digital Micrograph or other software packages. A wide range of programs supports exporting to and reading from the .msa format.

Warning

If several spectra are loaded and stacked in HyperSpy (hs.load('pattern', stack_signals=True)) the calibration is read from the first spectrum and applied to all other spectra.

Reference#

For specifications of the format, see the documentation by the Microscopy Society of America.

API functions#

rsciio.msa.file_reader(filename, encoding='latin-1', **kwds)#

Read an MSA file.

Parameters:
  • filename (str, pathlib.Path) – Filename of the file to read or corresponding pathlib.Path.

  • encoding (str, Default="latin-1") – The encoding used to read the content of the file. Different file encodings, such as "utf8" can be set via this argument.

Returns:

List of dictionaries containing the following fields:

  • ’data’ – multidimensional numpy array

  • ’axes’ – list of dictionaries describing the axes containing the fields ‘name’, ‘units’, ‘index_in_array’, and either ‘size’, ‘offset’, and ‘scale’ or a numpy array ‘axis’ containing the full axes vector

  • ’metadata’ – dictionary containing the parsed metadata

  • ’original_metadata’ – dictionary containing the full metadata tree from the input file

Return type:

list of dicts

rsciio.msa.file_writer(filename, signal, format=None, separator=', ', encoding='latin-1')#

Write signal to an MSA file.

Parameters:
  • filename (str, pathlib.Path) – Filename of the file to write to or corresponding pathlib.Path.

  • signal (dict) –

    Dictionary containing the signal object. Should contain the following fields:

    • ’data’ – multidimensional numpy array

    • ’axes’ – list of dictionaries describing the axes containing the fields ‘name’, ‘units’, ‘index_in_array’, and either ‘size’, ‘offset’, and ‘scale’ or a numpy array ‘axis’ containing the full axes vector

    • ’metadata’ – dictionary containing the metadata tree

  • format (str, Default="Y") – Specify whether the X-axis (energy/wavelength) should also be saved with the data. The default, "Y" omits the X-axis in the file. The alternative, "XY", saves the calibrated signal axis as first column.

  • separator (str, Default=", ") – Change the column separator. However, if a different separator is chosen the resulting file will not comply with the MSA/EMSA standard and RosettaSciIO and other software may not be able to read it.

  • encoding (str, Default="latin-1") – The encoding used to write the content of the file. Different file encodings, such as "utf8" can be set via this argument.

Examples

>>> from rsciio.msa import file_writer
>>> file_writer("file.msa", signal, encoding="utf8")
rsciio.msa.parse_msa_string(string, filename=None)#

Parse an EMSA/MSA file content.

Parameters:
  • string (string or file object) – It must complain with the EMSA/MSA standard.

  • filename (string or None) – The filename.

Returns:

file_data_list – The list containts a dictionary that contains the parsed information. It can be used to create a BaseSignal using dict2signal().

Return type:

list