hyperspy.io_plugins.sur module

class hyperspy.io_plugins.sur.DigitalSurfHandler(filename=None)

Bases: object

Class to read Digital Surf MountainsMap files.

filename, signal_dict, _work_dict, _list_sur_file_content, _Object_type,
_N_data_object, _N_data_channels, _initialized
parse_file, parse_header, get_image_dictionaries
Class Variables
---------------
_object_type : dict key: int containing the mountainsmap object types
_MS_parse(strMS, prefix, delimiter)

Parses a string containing metadata information. The string can be read from the comment section of a .sur file, or, alternatively, a file containing them with a similar formatting.

Parameters:
  • strMS (string containing metadata) –

  • prefix (string (or char) character assumed to start each line.) –

  • file. ('$' if a .sur) –

  • delimiter (string that delimits the keyword from value. always '=') –

Returns:

dictMS

Return type:

dictionnary in the correct hyperspy metadata format

_append_work_dict_to_content()

Save the values stored in the work dict in the surface file list

_build_1D_series()

Build a series of 1D objects. The T axis is navigation and set from the first object

_build_RGB_image()

Build an RGB image. The T axis is navigation and set from P Size

_build_RGB_surface()

Build a series of surfaces. The T axis is navigation and set from P Size

_build_Tax(unpacked_dict, size_key, ind=0, nav=True, binned=False)

Return T axis dictionary from an unpacked surface object dict. Unlike x and y axes, the size key can be determined from various keys: _14_W_Size, _15_Size_of_Points or _03_Number_of_Objects. index int and navigate boolean can be optionally passed. Default 0 and True respectively.

_build_Xax(unpacked_dict, ind=0, nav=False, binned=False)

Return X axis dictionary from an unpacked dict. index int and navigate boolean can be optionally passed. Default 0 and False respectively.

_build_Yax(unpacked_dict, ind=1, nav=False, binned=False)

Return X axis dictionary from an unpacked dict. index int and navigate boolean can be optionally passed. Default 1 and False respectively.

_build_general_1D_data()

Build general 1D Data objects. Currently work with spectra

_build_hyperspectral_map()

Build a hyperspectral map. Hyperspectral maps are single-object files with datapoints of _14_W_Size length

_build_metadata(unpacked_dict)

Return a minimalistic metadata dictionary according to hyperspy format. Accept a dictionary as an input because dictionary with the headers of a mountians object.

Parameters:

unpacked_dict (dictionary from the header of a surface file) –

Returns:

metadict

Return type:

dictionnary in the hyperspy metadata format

_build_original_metadata()

Builds a metadata dictionnary from the header

_build_spectrum()

Build spectra objects. Spectra and 1D series of spectra are saved in the same object.

_build_sur_dict()

Create a signal dict with an unpacked object

_build_surface()

Build a surface

_build_surface_series()

Build a series of surfaces. The T axis is navigation and set from the first object

_check_comments(commentsstr, prefix, delimiter)

Check if comment string is parsable into metadata dictionary. Some specific lines (empty or starting with @@) will be ignored, but any non-ignored line must conform to being a title line (beginning with the TITLESTART indicator) or being parsable (starting with Prefix and containing the key data delimiter). At the end, the comment is considered parsable if it contains minimum 1 parsable line and no non-ignorable non-parsable non-title line.

Parameters:
  • commentstr (string containing comments) –

  • prefix (string (or char) character assumed to start each line.) –

  • file. ('$' if a .sur) –

  • delimiter (string that delimits the keyword from value. always '=') –

Returns:

valid

Return type:

boolean

_get_float(file, default=None)

Read a 4-bytes (single precision) float from a binary file f with a default value if no file is given

_get_int16(file, default=None, signed=True)

Read a 16-bits int with a user-definable default value if no file is given

_get_int32(file, default=None)

Read a 32-bits int with a user-definable default value if no file is given

_get_str(file, size, default=None, encoding='latin-1')

Read a str of defined size in bytes with a user-definable default value if no file is given

_pack_data(file, val, encoding='latin-1')

This needs to be special because it writes until the end of file.

_read_sur_file()

Read the binary, possibly compressed, content of the surface file. Surface files can be encoded as single or a succession of objects. The file is thus read iteratively and from metadata of the first file

_set_float(val)

write a 4-bytes (single precision) float in a file

_set_int32(file, val)

Write a 32-bits int in a file f

_set_metadata_and_original_metadata(unpacked_dict)

Run successively _build_metadata and _build_original_metadata and set signal dictionary with results

_set_str(file, val, size, encoding='latin-1')

Write a str of defined size in bytes to a file. struct.pack will automatically trim the string if it is too long

_unpack_data(file, encoding='latin-1')

This needs to be special because it reads until the end of file. This causes an error in the series of data

hyperspy.io_plugins.sur.file_reader(filename, **kwds)

Read a mountainsmap .sur file and return a dictionnary containing the information necessary for creating the data object

Parameters:

filename (name of the .sur file to be read) –

Returns:

  • signal_dict (dictionnary in the appropriate format. The dictionnary can)

  • contain several keys including ‘data’, ‘axes’, ‘metadata’, ‘original_metadata’,

  • ’post_process’, ‘mapping’, ‘attributes’.