hyperspy.io_plugins package¶
Submodules¶
hyperspy.io_plugins.bcf module¶
-
class
hyperspy.io_plugins.bcf.
BCF_reader
(filename)¶ Bases:
hyperspy.io_plugins.bcf.SFS_reader
Class to read bcf (Bruker hypermapping) file.
Inherits SFS_reader and all its attributes and methods.
Attributes: filename
Methods: print_the_metadata, persistent_parse_hypermap, parse_hypermap, py_parse_hypermap (Inherited from SFS_reader: print_file_tree, get_file)
The class instantiates HyperHeader class as self.header attribute where all metadata, sum eds spectras, (SEM) imagery are stored. if persistent_parse_hypermap is called, the hypermap is stored as instance of HyperMap inside the self.hypermap dictionary, where index of the hypermap (default 0) is the key to the instance.
-
parse_hypermap
(index=0, downsample=1, cutoff_at_kV=None)¶ Unpack the Delphi/Bruker binary spectral map and return numpy array in memory efficient way.
Pure python/numpy implimentation – slow, or cython/memoryview/numpy implimentation if compilied and present (fast) is used.
Arguments: index – the index of hypermap in bcf if there is more than one
hyper map in file.- downsample – downsampling factor (integer). Diferently than
- block_reduce from skimage.measure, the parser populates reduced array by suming results of pixels, thus having lower memory requiriments. (default 1)
- cutoff_at_kV – value in keV to truncate the array at. Helps reducing
- size of array. (default None)
Returns: numpy array of bruker hypermap, with (y,x,E) shape.
-
persistent_parse_hypermap
(index=0, downsample=None, cutoff_at_kV=None)¶ Parse and assign the hypermap to the HyperMap instance.
Arguments: index – index of hypermap in bcf if v2 (default 0) downsample – downsampling factor of hypermap (default None) cutoff_at_kV – low pass cutoff value at keV (default None)
Method does not return anything, it adds the HyperMap instance to self.hypermap dictionary.
See also: HyperMap, parse_hypermap
-
py_parse_hypermap
(index=0, downsample=1, cutoff_at_channel=None)¶ Unpack the Delphi/Bruker binary spectral map and return numpy array in memory efficient way using pure python implementation. (Slow!)
The function is long and complicated because Delphi/Bruker array packing is complicated. Whole parsing is done in one function/method to reduce overhead from python function calls. For cleaner parsing logic check out fast cython implementation at hyperspy/io_plugins/unbcf_fast.pyx
The method is only meant to be used if for some reason c (generated with cython) version of the parser is not compiled.
- index – the index of hypermap in bcf if there is more than one
- hyper map in file.
- downsample – downsampling factor (integer). Diferently than
- block_reduce from skimage.measure, the parser populates reduced array by suming results of pixels, thus having lower memory requiriments. (default 1)
- cutoff_at_kV – value in keV to truncate the array at. Helps reducing
- size of array. (default None)
numpy array of bruker hypermap, with (y,x,E) shape.
-
-
class
hyperspy.io_plugins.bcf.
Container
¶ Bases:
object
-
class
hyperspy.io_plugins.bcf.
EDXSpectrum
(spectrum)¶ Bases:
object
-
energy_to_channel
(energy, kV=True)¶ convert energy to channel index, optional kwarg ‘kV’ (default: True) should be set to False if given energy units is in V
-
-
class
hyperspy.io_plugins.bcf.
HyperHeader
(xml_str)¶ Bases:
object
Wrap Bruker HyperMaping xml header into python object.
Arguments: xml_str – the uncompressed to be provided with extracted Header xml from bcf.
Methods: estimate_map_channels, estimate_map_depth
If Bcf is version 2, the bcf can contain stacks of hypermaps - thus header part can contain multiply sum eds spectras and it’s metadata per hypermap slice which can be selected using index. Bcf can record number of imagery from different imagining detectors (BSE, SEI, ARGUS, etc...): access to imagery is throught image index.
-
estimate_map_channels
(index=0)¶ estimate minimal size of energy axis so any spectra from any pixel would not be truncated.
Arguments: index – index of the map if multiply hypermaps are present in the same bcf.
Returns: optimal channel number
-
estimate_map_depth
(index=0, downsample=1, for_numpy=False)¶ estimate minimal dtype of array using cumulative spectra of the all pixels so that no data would be truncated.
Arguments: index – index of the hypermap if multiply hypermaps are present in the same bcf. (default 0) downsample – downsample factor (should be integer; default 1) for_numpy – if estimation will be used in parsing using oure python
and numpy inplace integer addition will be used, so the dtype should be signed; if cython implementation will be used (default), then any returned dtypes can be safely unsigned. (default False)Returns: numpy dtype large enought to use in final hypermap numpy array.
The method estimates the value from sum eds spectra, dividing the maximum energy pulse value from raster x and y and to be on the safe side multiplying by 2.
-
get_spectra_metadata
(index=0)¶ return objectified xml with spectra metadata Arguments: index – index of hypermap/spectra (default 0)
-
-
class
hyperspy.io_plugins.bcf.
HyperMap
(nparray, parent, index=0, downsample=1)¶ Bases:
object
Container class to hold the parsed bruker hypermap and its scale calibrations
-
class
hyperspy.io_plugins.bcf.
SFSTreeItem
(item_raw_string, parent)¶ Bases:
object
Class to manage one internal sfs file.
Reading, reading in chunks, reading and extracting, reading without extracting even if compression is pressent.
Attributes: item_raw_string – the bytes from sfs file table describing the file parent – the item higher hierarchicaly in the sfs file tree
Methods: read_piece, setup_compression_metadata, get_iter_and_properties, get_as_BytesIO_string
-
get_as_BytesIO_string
()¶ Get the whole file as io.BytesIO object (in memory!).
-
get_iter_and_properties
()¶ Generate and return the iterator of data chunks and properties of such chunks such as size and count.
Method detects if data is compressed and uses iterator with decompression involved, else uses simple iterator of chunks.
Returns: (iterator, chunk_size, number_of_chunks)
-
read_piece
(offset, length)¶ Read and returns raw byte string of the file without applying any decompression.
Arguments: offset: seek value length: length of the data counting from the offset
Returns: io.ByteIO object
-
setup_compression_metadata
()¶ parse and setup the number of compression chunks
and uncompressed chunk size as class attributes.
Sets up attributes: self.uncompressed_blk_size, self.no_of_compr_blk
-
-
class
hyperspy.io_plugins.bcf.
SFS_reader
(filename)¶ Bases:
object
Class to read sfs file.
SFS is AidAim software’s(tm) single file system. The class provides basic reading capabilities of such container. It is capable to read compressed data in zlib, but SFS can contain other compression which is not implemented here. It is also not able to read encrypted sfs containers.
This class can be used stand alone or inherited in construction of file readers using sfs technolgy.
Attributes: filename
Methods: get_file
-
get_file
(path)¶ Return the SFSTreeItem (aka internal file) object from sfs container.
Arguments: path – internal file path in sfs file tree. Path accepts only
standard - forward slash for directories.Returns: object (SFSTreeItem), which can be read into byte stream, in chunks or whole using objects methods.
Example: to get “file” object ‘kitten.png’ in folder ‘catz’ which resides in root directory of sfs, you would use:
>>> instance_of_SFSReader.get_file('catz/kitten.png')
See also: SFSTreeItem
-
-
hyperspy.io_plugins.bcf.
bcf_hyperspectra
(obj_bcf, index=0, downsample=None, cutoff_at_kV=None, instrument=None)¶ Return hyperspy required list of dict with eds hyperspectra and metadata.
-
hyperspy.io_plugins.bcf.
bcf_imagery
(obj_bcf, instrument=None)¶ return hyperspy required list of dict with sem imagery and metadata.
-
hyperspy.io_plugins.bcf.
file_reader
(filename, select_type=None, index=0, downsample=1, cutoff_at_kV=None, instrument=None)¶ Reads a bruker bcf file and loads the data into the appropriate class, then wraps it into appropriate hyperspy required list of dictionaries used by hyperspy.api.load() method.
Keyword arguments: select_type – One of: spectrum, image. If none specified, then function
loads everything, else if specified, loads either just sem imagery, or just hyper spectral mapping data. (default None)index – index of dataset in bcf v2 (delaut 0) downsample – the downsample ratio of hyperspectral array (downsampling
hight and width only), can be integer from 1 to inf, where ‘1’ means no downsampling will be applied (default 1).- cutoff_at_kV – if set (can be int of float >= 0) can be used either, to
- crop or enlarge energy range at max values. (default None)
instrument – str, either ‘TEM’ or ‘SEM’. Default is None.
-
hyperspy.io_plugins.bcf.
gen_elem_list
(the_dict)¶
-
hyperspy.io_plugins.bcf.
parse_line
(line_string)¶ standardize line describtion.
Bruker saves line describtion in all caps and omits the type if only one exists instead of using alfa
hyperspy.io_plugins.blockfile module¶
-
hyperspy.io_plugins.blockfile.
file_reader
(filename, endianess='<', load_to_memory=True, mmap_mode='c', **kwds)¶
-
hyperspy.io_plugins.blockfile.
file_writer
(filename, signal, **kwds)¶
-
hyperspy.io_plugins.blockfile.
get_default_header
(endianess='<')¶ Returns a header pre-populated with default values.
-
hyperspy.io_plugins.blockfile.
get_header_dtype_list
(endianess='<')¶
-
hyperspy.io_plugins.blockfile.
get_header_from_signal
(signal, endianess='<')¶
hyperspy.io_plugins.digital_micrograph module¶
-
class
hyperspy.io_plugins.digital_micrograph.
DigitalMicrographReader
(f)¶ Bases:
object
Class to read Gatan Digital Micrograph (TM) files.
Currently it supports versions 3 and 4.
-
dm_version, endian, tags_dict
-
parse_file, parse_header, get_image_dictionaries
-
check_data_tag_delimiter
()¶
-
find_next_data_tag
()¶
-
find_next_tag
()¶
-
get_data_reader
(enc_dtype)¶
-
get_image_dictionaries
()¶ Returns the image dictionaries of all images in the file except the thumbnails.
Returns: Return type: dict, None
-
parse_array_definition
()¶ Reads and returns the element type and length of the array.
The position in the file must be just after the array encoded dtype.
-
parse_file
()¶
-
parse_header
()¶
-
parse_string_definition
()¶ Reads and returns the length of the string.
The position in the file must be just after the string encoded dtype.
-
parse_struct_definition
()¶ Reads and returns the struct definition tuple.
The position in the file must be just after the struct encoded dtype.
-
parse_tag_group
(skip4=1)¶ Parse the root TagGroup of the given DM3 file f. Returns the tuple (is_sorted, is_open, n_tags). endian can be either ‘big’ or ‘little’.
-
parse_tag_header
()¶
Parse the DM file into a dictionary.
-
read_array
(size, enc_eltype, extra=None, skip=False)¶ Read an array, defined by iarray, from file f with a given endianness (byte order). endian can be either ‘big’ or ‘little’.
-
read_simple_data
(etype)¶ Parse the data of the given DM3 file f with the given endianness (byte order). The infoArray iarray specifies how to read the data. Returns the tuple (file address, data). The tag data is stored in the platform’s byte order: ‘little’ endian for Intel, PC; ‘big’ endian for Mac, Motorola. If skip != 0 the data is actually skipped.
-
read_string
(length, skip=False)¶ - Read a string defined by the infoArray iarray from
- file f with a given endianness (byte order).
endian can be either ‘big’ or ‘little’.
If it’s a tag name, each char is 1-Byte; if it’s a tag data, each char is 2-Bytes Unicode,
-
read_struct
(definition, skip=False)¶ Read a struct, defined by iarray, from file f with a given endianness (byte order). Returns a list of 2-tuples in the form (fieldAddress, fieldValue). endian can be either ‘big’ or ‘little’.
-
simple_type
= (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)¶
-
skipif4
(n=1)¶
-
-
class
hyperspy.io_plugins.digital_micrograph.
ImageObject
(imdict, file, order='C', record_by=None)¶ Bases:
object
-
dtype
¶
-
get_axes_dict
()¶
-
get_data
()¶
-
get_mapping
()¶
-
get_metadata
(metadata={})¶
-
intensity_calibration
¶
-
names
¶
-
offsets
¶
-
order
¶
-
record_by
¶
-
scales
¶
-
shape
¶
-
signal_type
¶
-
size
¶
-
title
¶
-
to_spectrum
¶
-
units
¶
-
unpack_new_packed_complex
(data)¶
-
unpack_packed_complex
(tmpdata)¶
-
-
hyperspy.io_plugins.digital_micrograph.
file_reader
(filename, record_by=None, order=None)¶ Reads a DM3 file and loads the data into the appropriate class. data_id can be specified to load a given image within a DM3 file that contains more than one dataset.
Parameters: - record_by (Str) – One of: SI, Signal2D
- order (Str) – One of ‘C’ or ‘F’
hyperspy.io_plugins.emd module¶
-
class
hyperspy.io_plugins.emd.
EMD
(signals=None, user=None, microscope=None, sample=None, comments=None)¶ Bases:
object
Class for storing electron microscopy datasets.
The
EMD
class can hold an arbitrary amount of datasets in the signals dictionary. These are saved as HyperSpySignal
instances. Global metadata are saved in four dictionaries (user, microscope, sample, comments). To print relevant information about the EMD instance use thelog_info()
function. EMD instances can be loaded from and saved to emd-files, an hdf5 standard developed at Lawrence Berkeley National Lab (http://emdatasets.lbl.gov/).-
signals
¶ dictionary – Dictionary which contains all datasets as
Signal
instances.
-
user
¶ dictionary – Dictionary which contains user related metadata.
-
microscope
¶ dictionary – Dictionary which contains microscope related metadata.
-
sample
¶ dictionary – Dictionary which contains sample related metadata.
-
comments
¶ dictionary – Dictionary which contains additional commentary metadata.
-
add_signal
(signal, name=None, metadata=None)¶ Add a hyperspy signal to the EMD instance and make sure all metadata is present.
Parameters: - signal (
Signal
) – HyperSpy signal which should be added to the EMD instance. - name (string, optional) – Name of the (used as a key for the signals dictionary). If not specified, signal.metadata.General.title will be used. If this is an empty string, both name and signal title are set to ‘dataset’ per default. If specified, name overwrites the signal title.
- metadata (dictionary) – Dictionary which holds signal specific metadata which will be added to the signal.
Returns: Return type: None
Notes
This is the preferred way to add signals to the EMD instance. Directly adding to the signals dictionary is possible but does not make sure all metadata are correct. This method is also called in the standard constructor on all entries in the signals dictionary!
- signal (
-
classmethod
load_from_emd
(filename, load_to_memory=True)¶ Construct
EMD
object from an emd-file.Parameters: Returns: emd – A
EMD
object containing the loaded signals.Return type:
-
log_info
()¶ Print all relevant information about the EMD instance.
-
-
hyperspy.io_plugins.emd.
file_reader
(filename, load_to_memory=True, log_info=False, **kwds)¶
-
hyperspy.io_plugins.emd.
file_writer
(filename, signal, signal_metadata=None, user=None, microscope=None, sample=None, comments=None, **kwds)¶
hyperspy.io_plugins.fei module¶
-
hyperspy.io_plugins.fei.
convert_xml_to_dict
(xml_object)¶
-
hyperspy.io_plugins.fei.
dimension_array_dtype
(n, DescriptionLength, UnitsLength)¶
-
hyperspy.io_plugins.fei.
emi_reader
(filename, dump_xml=False, **kwds)¶
-
hyperspy.io_plugins.fei.
emixml2dtb
(et, dictree)¶
-
hyperspy.io_plugins.fei.
file_reader
(filename, *args, **kwds)¶
-
hyperspy.io_plugins.fei.
get_axes_from_position
(header, data)¶
-
hyperspy.io_plugins.fei.
get_calibration_from_position
(position)¶ Compute the size, scale and offset of a linear axis from coordinates.
This function assumes rastering on a regular grid for the full size of each dimension before rastering over another one. Fox example: a11, a12, a13, a21, a22, a23 for a 2x3 grid.
Parameters: position (numpy array.) – Position coordinates of the axis. Normally as in PositionX/Y of the ser file. Returns: axis_attr Return type: dictionary with size, scale, offeset keys.
-
hyperspy.io_plugins.fei.
get_data_dtype_list
(file, offset, record_by)¶
-
hyperspy.io_plugins.fei.
get_data_tag_dtype_list
(data_type_id)¶
-
hyperspy.io_plugins.fei.
get_header_dtype_list
(file)¶
-
hyperspy.io_plugins.fei.
get_lengths
(file)¶
-
hyperspy.io_plugins.fei.
get_xml_info_from_emi
(emi_file)¶
-
hyperspy.io_plugins.fei.
guess_record_by
(record_by_id)¶
-
hyperspy.io_plugins.fei.
load_ser_file
(filename)¶
-
hyperspy.io_plugins.fei.
log_struct_array_values
(struct_array)¶
-
hyperspy.io_plugins.fei.
parse_ExperimentalDescription
(et, dictree)¶
-
hyperspy.io_plugins.fei.
parse_TrueImageHeaderInfo
(et, dictree)¶
-
hyperspy.io_plugins.fei.
readLELong
(file)¶ Read 4 bytes as little endian integer in file
-
hyperspy.io_plugins.fei.
readLELongLong
(file)¶ Read 8 bytes as little endian integer in file
-
hyperspy.io_plugins.fei.
readLEShort
(file)¶ Read 2 bytes as little endian integer in file
-
hyperspy.io_plugins.fei.
ser_reader
(filename, objects=None, *args, **kwds)¶ Reads the information from the file and returns it in the HyperSpy required format.
hyperspy.io_plugins.hdf5 module¶
-
hyperspy.io_plugins.hdf5.
dict2hdfgroup
(dictionary, group, **kwds)¶
-
hyperspy.io_plugins.hdf5.
file_reader
(filename, mode='r', driver='core', backing_store=False, load_to_memory=True, **kwds)¶
-
hyperspy.io_plugins.hdf5.
file_writer
(filename, signal, *args, **kwds)¶
-
hyperspy.io_plugins.hdf5.
get_hspy_format_version
(f)¶
-
hyperspy.io_plugins.hdf5.
hdfgroup2dict
(group, dictionary=None, load_to_memory=True)¶
-
hyperspy.io_plugins.hdf5.
hdfgroup2signaldict
(group, load_to_memory=True)¶
-
hyperspy.io_plugins.hdf5.
write_signal
(signal, group, **kwds)¶
hyperspy.io_plugins.image module¶
-
hyperspy.io_plugins.image.
file_reader
(filename, **kwds)¶ Read data from any format supported by PIL.
Parameters: filename (str) –
-
hyperspy.io_plugins.image.
file_writer
(filename, signal, file_format='png', **kwds)¶ Writes data to any format supported by PIL
Parameters: - filename (str) –
- signal (a Signal instance) –
- file_format (str) – The fileformat defined by its extension that is any one supported by PIL.
hyperspy.io_plugins.mrc module¶
-
hyperspy.io_plugins.mrc.
file_reader
(filename, endianess='<', **kwds)¶
-
hyperspy.io_plugins.mrc.
get_data_type
(index, endianess='<')¶
-
hyperspy.io_plugins.mrc.
get_fei_dtype_list
(endianess='<')¶
-
hyperspy.io_plugins.mrc.
get_std_dtype_list
(endianess='<')¶
hyperspy.io_plugins.msa module¶
-
hyperspy.io_plugins.msa.
file_reader
(filename, encoding='latin-1', **kwds)¶
-
hyperspy.io_plugins.msa.
file_writer
(filename, signal, format=None, separator=', ', encoding='latin-1')¶
-
hyperspy.io_plugins.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 (list) – The list containts a dictionary that contains the parsed information. It can be used to create a :class:BaseSignal using :func:hyperspy.io.dict2signal.
hyperspy.io_plugins.netcdf module¶
-
hyperspy.io_plugins.netcdf.
file_reader
(filename, *args, **kwds)¶
-
hyperspy.io_plugins.netcdf.
nc_hyperspy_reader_0dot1
(ncfile, filename, *args, **kwds)¶
hyperspy.io_plugins.protochips module¶
-
class
hyperspy.io_plugins.protochips.
ProtochipsCSV
(filename, header_line_number=10)¶ Bases:
object
-
get_dictionary
(quantity)¶
-
-
hyperspy.io_plugins.protochips.
file_reader
(filename, *args, **kwds)¶
hyperspy.io_plugins.ripple module¶
-
hyperspy.io_plugins.ripple.
correct_INCA_format
(fp)¶
-
hyperspy.io_plugins.ripple.
file_reader
(filename, rpl_info=None, encoding='latin-1', mmap_mode='c', *args, **kwds)¶ Parses a Lispix (http://www.nist.gov/lispix/) ripple (.rpl) file and reads the data from the corresponding raw (.raw) file; or, read a raw file if the dictionary rpl_info is provided.
This format is often uses in EDS/EDX experiments.
Images and spectral images or data cubes that are written in the (Lispix) raw file format are just a continuous string of numbers.
Data cubes can be stored image by image, or spectrum by spectrum. Single images are stored row by row, vector cubes are stored row by row (each row spectrum by spectrum), image cubes are stored image by image.
All of the numbers are in the same format, such as 16 bit signed integer, IEEE 8-byte real, 8-bit unsigned byte, etc.
The “raw” file should be accompanied by text file with the same name and ”.rpl” extension. This file lists the characteristics of the raw file so that it can be loaded without human intervention.
Alternatively, dictionary ‘rpl_info’ containing the information can be given.
Some keys are specific to HyperSpy and will be ignored by other software.
RPL stands for “Raw Parameter List”, an ASCII text, tab delimited file in which HyperSpy reads the image parameters for a raw file.
TABLE OF RPL PARAMETERSkey type description
———- ———— ——————– # Mandatory keys: width int # pixels per row height int # number of rows depth int # number of images or spectral pts offset int # bytes to skip data-type str # ‘signed’, ‘unsigned’, or ‘float’ data-length str # bytes per pixel ‘1’, ‘2’, ‘4’, or ‘8’ byte-order str # ‘big-endian’, ‘little-endian’, or ‘dont-care’ record-by str # ‘image’, ‘vector’, or ‘dont-care’ # X-ray keys: ev-per-chan int # optional, eV per channel detector-peak-width-ev int # optional, FWHM for the Mn K-alpha line # HyperSpy-specific keys depth-origin int # energy offset in pixels depth-scale float # energy scaling (units per pixel) depth-units str # energy units, usually eV depth-name str # Name of the magnitude stored as depth width-origin int # column offset in pixels width-scale float # column scaling (units per pixel) width-units str # column units, usually nm width-name str # Name of the magnitude stored as width height-origin int # row offset in pixels height-scale float # row scaling (units per pixel) height-units str # row units, usually nm height-name str # Name of the magnitude stored as height signal str # Name of the signal stored, e.g. HAADF convergence-angle float # TEM convergence angle in mrad collection-angle float # EELS spectrometer collection semi-angle in mrad beam-energy float # TEM beam energy in keV elevation-angle float # Elevation angle of the EDS detector azimuth-angle float # Elevation angle of the EDS detector live-time float # Live time per spectrum energy-resolution float # Resolution of the EDS (FHWM of MnKa) tilt-stage float # The tilt of the stage date str # date in ISO 8601 time str # time in ISO 8601
NOTES
When ‘data-length’ is 1, the ‘byte order’ is not relevant as there is only one byte per datum, and ‘byte-order’ should be ‘dont-care’.
When ‘depth’ is 1, the file has one image, ‘record-by’ is not relevant and should be ‘dont-care’. For spectral images, ‘record-by’ is ‘vector’. For stacks of images, ‘record-by’ is ‘image’.
Floating point numbers can be IEEE 4-byte, or IEEE 8-byte. Therefore if data-type is float, data-length MUST be 4 or 8.
The rpl file is read in a case-insensitive manner. However, when providing a dictionary as input, the keys MUST be lowercase.
Comment lines, beginning with a semi-colon ‘;’ are allowed anywhere.
The first non-comment in the rpl file line MUST have two column names: ‘name_1’<TAB>’name_2’; any name would do e.g. ‘key’<TAB>’value’.
Parameters can be in ANY order.
In the rpl file, the parameter name is followed by ONE tab (spaces are ignored) e.g.: ‘data-length’<TAB>‘2’
In the rpl file, other data and more tabs can follow the two items on each row, and are ignored.
Other keys and values can be included and are ignored.
Any number of spaces can go along with each tab.
-
hyperspy.io_plugins.ripple.
file_writer
(filename, signal, encoding='latin-1', *args, **kwds)¶
-
hyperspy.io_plugins.ripple.
parse_ripple
(fp)¶ Parse information from ripple (.rpl) file. Accepts file object ‘fp. Returns dictionary rpl_info.
-
hyperspy.io_plugins.ripple.
read_raw
(rpl_info, fp, mmap_mode='c')¶ Read the raw file object ‘fp’ based on the information given in the ‘rpl_info’ dictionary.
Parameters: - rpl_info (dict) – A dictionary containing the keywords as parsed by read_rpl
- fp –
- mmap_mode ({None, 'r+', 'r', 'w+', 'c'}, optional) –
- not None, then memory-map the file, using the given mode (If) –
- numpy.memmap). The mode has no effect for pickled or ((see) –
- files. (zipped) –
- memory-mapped array is stored on disk, and not directly loaded (A) –
- memory. However, it can be accessed and sliced like any (into) –
- Memory mapping is especially useful for accessing (ndarray.) –
- fragments of large files without reading the entire file (small) –
- memory. (into) –
-
hyperspy.io_plugins.ripple.
write_raw
(filename, signal, record_by)¶ Writes the raw file object
- filename : string
- the filename, either with the extension or without it
- record_by : string
- ‘vector’ or ‘image’
-
hyperspy.io_plugins.ripple.
write_rpl
(filename, keys_dictionary, encoding='ascii')¶
hyperspy.io_plugins.semper_unf module¶
-
class
hyperspy.io_plugins.semper_unf.
SemperFormat
(data, title='', offsets=(0.0, 0.0, 0.0), scales=(1.0, 1.0, 1.0), units=(<undefined>, <undefined>, <undefined>), metadata=None)¶ Bases:
object
Class for importing and exporting SEMPER .unf-files.
The
SemperFormat
class represents a SEMPER binary file format with a header, which holds additional information. .unf-files can be saved and read from files.-
data
¶ ndarray
(N=3) – The phase map or magnetization information in a 3D array (with one slice).
-
title
¶ string – Title of the file (not to be confused with the filename).
-
offsets
¶ tuple (N=3) of floats – Offset shifts (in nm) of the grid origin (does not have to start at 0) in x, y, z.
-
scales
¶ tuple (N=3) of floats – Grid spacing (nm per pixel) in x, y, z.
-
units
¶ tuple (N=3) of strings – Units of the grid in x, y, z.
-
metadata
¶ dictionary – A dictionary of all flags and metadata present in the .unf-file.
-
HEADER_DTYPES
= [('NCOL', '<i2'), ('NROW', '<i2'), ('NLAY', '<i2'), ('ICLASS', '<i2'), ('IFORM', '<i2'), ('IFLAG', '<i2'), ('IFORM', '<i2')]¶
-
ICLASS_DICT
= {1: 'image', 2: 'macro', 3: 'fourier', 4: 'spectrum', 5: 'correlation', 6: <undefined>, 7: 'walsh', 8: 'position list', 9: 'histogram', 10: 'display look-up table'}¶
-
ICLASS_DICT_INV
= {'spectrum': 4, 'macro': 2, 'fourier': 3, 'position list': 8, 'correlation': 5, 'display look-up table': 10, <undefined>: 6, 'walsh': 7, 'histogram': 9, 'image': 1}¶
-
IFORM_DICT
= {0: <class 'numpy.int8'>, 1: <class 'numpy.int16'>, 2: <class 'numpy.float32'>, 3: <class 'numpy.complex64'>, 4: <class 'numpy.int32'>}¶
-
IFORM_DICT_INV
= {<class 'numpy.float32'>: 2, <class 'numpy.complex64'>: 3, <class 'numpy.int32'>: 4, <class 'numpy.int16'>: 1, <class 'numpy.int8'>: 0}¶
-
LABEL_DTYPES
= [('SEMPER', ('<i2', 6)), ('NCOL', ('<i2', 2)), ('NROW', ('<i2', 2)), ('NLAY', ('<i2', 2)), ('ICCOLN', ('<i2', 2)), ('ICROWN', ('<i2', 2)), ('ICLAYN', ('<i2', 2)), ('ICLASS', '<i2'), ('IFORM', '<i2'), ('IWP', '<i2'), ('DATE', ('<i2', 6)), ('NCRANG', '<i2'), ('RANGE', ('<i2', 27)), ('IPLTYP', '<i2'), ('NCOLH', '<i2'), ('NROWH', '<i2'), ('NLAYH', '<i2'), ('ICCOLNH', '<i2'), ('ICROWNH', '<i2'), ('ICLAYNH', '<i2'), ('REALCO', '<i2'), ('NBLOCK', '<i2'), ('FREE', ('<i2', 3)), ('DATAV6', ('<i2', 4)), ('DATAV7', ('<i2', 4)), ('DZV5', ('<i2', 4)), ('Z0V4', ('<i2', 4)), ('DYV3', ('<i2', 4)), ('Y0V2', ('<i2', 4)), ('DXV1', ('<i2', 4)), ('X0V0', ('<i2', 4)), ('NTITLE', '<i2'), ('TITLE', ('<i2', 144)), ('XUNIT', ('<i2', 4)), ('YUNIT', ('<i2', 4)), ('ZUNIT', ('<i2', 4))]¶
-
classmethod
from_signal
(signal)¶ Import a
SemperFormat
object from aSignal
object.Parameters: signal ( Signal
) – The signal which should be imported.Returns: Return type: None
-
classmethod
load_from_unf
(filename)¶ Load a .unf-file into a
SemperFormat
object.Parameters: filename (string) – The name of the unf-file from which to load the data. Standard format is ‘*.unf’. Returns: semper – SEMPER file format object containing the loaded information. Return type: SemperFormat
(N=1)
-
log_info
()¶ log important flag information of the
SemperFormat
object.Parameters: None – Returns: Return type: None
-
save_to_unf
(filename='semper.unf', skip_header=False)¶ Save a
SemperFormat
to a file.Parameters: - filename (string, optional) – The name of the unf-file to which the data should be written.
- skip_header (boolean, optional) – Determines if the header, title and label should be skipped (useful for some other programs). Default is False.
Returns: Return type: None
-
to_signal
()¶ Export a
SemperFormat
object to aSignal
object.Parameters: None – Returns: signal – The exported signal. Return type: Signal
-
-
hyperspy.io_plugins.semper_unf.
file_reader
(filename, **kwds)¶
-
hyperspy.io_plugins.semper_unf.
file_writer
(filename, signal, **kwds)¶
-
hyperspy.io_plugins.semper_unf.
pack_to_intbytes
(fmt, value)¶ Pack a value into a byte list using format fmt and represent it as int (range 0-255).
-
hyperspy.io_plugins.semper_unf.
unpack_from_intbytes
(fmt, byte_list)¶ Read in a list of bytes (as int with range 0-255) and unpack them with format fmt.
hyperspy.io_plugins.tiff module¶
-
hyperspy.io_plugins.tiff.
file_reader
(filename, record_by='image', force_read_resolution=False, **kwds)¶ Read data from tif files using Christoph Gohlke’s tifffile library. The units and the scale of images saved with ImageJ or Digital Micrograph is read. There is limited support for reading the scale of files created with Zeiss and FEI SEMs.
Parameters: - filename (str) –
- record_by ({'image'}) – Has no effect because this format only supports recording by image.
- force_read_resolution (Bool) – Default: False. Force reading the x_resolution, y_resolution and the resolution_unit of the tiff tags. See http://www.awaresystems.be/imaging/tiff/tifftags/resolutionunit.html
- optional (**kwds,) –
-
hyperspy.io_plugins.tiff.
file_writer
(filename, signal, export_scale=True, extratags=[], **kwds)¶ Writes data to tif using Christoph Gohlke’s tifffile library
Parameters: - filename (str) –
- signal (a BaseSignal instance) –
- export_scale (bool) – default: True Export the scale and the units (compatible with DM and ImageJ) to appropriate tags. If the scikit-image version is too old, use the hyperspy embedded tifffile library to allow exporting the scale and the unit.