网页 综合 更新时间 2026-11-14 09:56:29

Loading and saving data — HyperSpy 2.5.0 documentation

自动蜘蛛 hyperspy.org 正文约 6000 字
Fundamentals and Usage
Changed in version 2.0: File format support in HyperSpy is provided by the separate package RosettaSciIO. The IO plugins formerly developed within HyperSpy have been moved to RosettaSciIO in order to facilitate a wider use also by other packages.
For file format information and documentation, please refer to:
Supported File Formats - Complete list of supported formats
RosettaSciIO Documentation - Full documentation for file I/O functionality
RosettaSciIO GitHub Repository - Source code and development
Reporting Issues: File format specific issues should be reported to the RosettaSciIO issue tracker. Plugins supporting additional formats or corrections/enhancements to existing plugins should be contributed to the RosettaSciIO repository.
HyperSpy can read and write to multiple formats through the RosettaSciIO library (see Supported formats). RosettaSciIO provides the file format support that powers HyperSpy’s loading and saving capabilities.
To load data use the load() command. For example, to load the image spam.jpg, you can type:
If loading was successful, the variable s contains a HyperSpy signal or any type of signal defined in one of the HyperSpy extensions, see Specifying signal type for more details.
When the file contains several datasets, the load() function will return a list of HyperSpy signals, instead of a single HyperSpy signal. Each signal can then be accessed using list indexation.
Using indexation to access the first signal (index 0):
The load function returns an object that contains data read from the file. We assign this object to the variable s but you can choose any (valid) variable name you like. for the filename, don't forget to include the quotation marks and the file extension.
If no argument is passed to the load function, a window will be raised that allows to select a single file through your OS file manager, e.g.:
It is also possible to load multiple files at once or even stack multiple files. For more details read Loading multiple files.
HyperSpy (via RosettaSciIO) will attempt to infer the appropriate file reader to use based on the file extension (for example .hspy, .emd and so on). You can override this using the file_format keyword:
For a complete list of supported file formats and their capabilities, see the Supported formats documentation in RosettaSciIO.
HyperSpy will attempt to infer the most suitable signal type for the data being loaded. Domain specific signal types are provided by extension libraries. To list the signal types available on your local installation use:
When loading data, the signal type can be specified by providing the signal_type keyword, which has to correspond to one of the available subclasses of signal (The EELS signal type is provided by the extension eXSpy):
If the loaded file contains several datasets, the load() function will return a list of the corresponding signals:
Note for python programmers: the data is stored in a numpy array in the data attribute, but you will not normally need to access it there.
Most scientific file formats store some extra information about the data and the conditions under which it was acquired (metadata). HyperSpy reads most of them and stores them in the original_metadata attribute. Also, depending on the file format, a part of this information will be mapped by HyperSpy to the metadata attribute, where it can for example be used by routines operating on the signal. See the metadata structure for details.
Extensive metadata can slow down loading and processing, and loading the original_metadata can be disabled using the load_original_metadata argument of the load() function. If this argument is set to False, the metadata will still be populated.
To print the content of the attributes simply use:
The original_metadata and metadata can be exported to text files using the export() method, e.g.:
Added in version 1.2: lazy keyword argument.
Almost all file readers support lazy loading, which means accessing the data without loading it to memory (see Supported formats for a list). This feature can be useful when analysing large files. To use this feature, set lazy to True e.g.:
More details on lazy evaluation support can be found in Working with big data.
The units of the navigation and signal axes can be converted automatically during loading using the convert_units parameter. If True, the convert_to_units method of the axes_manager will be used for the conversion and if set to False, the units will not be converted (default).
Rather than loading files individually, several files can be loaded with a single command. This can be done by passing a list of filenames to the load functions, e.g.:
or by using shell-style wildcards:
Alternatively, regular expression type character classes can be used such as [a-z] for lowercase letters or [0-9] for one digit integers:
Wildcards are implemented using glob.glob(), which treats *, [ and ] as special characters for pattern matching. If your filename or path contains square brackets, you may want to set escape_square_brackets=True:
HyperSpy also supports `pathlib.Path <https://docs.python.org/3/library/pathlib.html>`_ objects, for example:
By default HyperSpy will return a list of all the files loaded. Alternatively, by setting stack=True, HyperSpy can be instructed to stack the data - given that the files contain data with exactly the same dimensions. If this is not the case, an error is raised. If each file contains multiple (N) signals, N stacks will be created. Here, the number of signals per file must also match, or an error will be raised.
HyperSpy is distributed with some example data that can be found in data:
Added in version 1.4: data (formerly hyperspy.api.datasets.artificial_data)
There are also artificial datasets, which are made to resemble real experimental data.
To save data to a file use the save() method. The first argument is the filename and the format is defined by the filename extension. If the filename does not con
访问原文 返回搜索 https://hyperspy.org/hyperspy-doc/current/user_guide/io.html
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。