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.
Note
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 and the ISO 22029:2022 standard.
API functions#
- rsciio.msa.file_reader(filename, lazy=False, encoding='latin-1')#
Read an MSA file.
- Parameters:
- filename
str
,pathlib.Path
Filename of the file to read or corresponding pathlib.Path.
- lazybool, default=False
Lazy loading is not supported.
- 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.
- filename
- Returns:
list
ofdict
List of dictionaries containing the following fields:
‘data’ – multidimensional
numpy.ndarray
ordask.array.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
- rsciio.msa.file_writer(filename, signal, format='Y', 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.
- filename
Examples
>>> from rsciio.msa import file_writer >>> file_writer("file.msa", signal, encoding="utf8")