IO module

This module provides the input/output tools to read/save maps and datasets.

It is made of 3 main modules:

Loaders

The edxia.io.loader module offers loader classes to be able to easily load component maps, composite or map stacks.

Three main loaders are defined:

The main functions are:

class edxia.io.loader.DefaultLoader(exp_manager, filters=None, no_BSE_filter=True)[source]

Bases: edxia.io.loader.base_loader.AbstractLoader

Default loader without loading.

load_edsmap_single(component)[source]

Load the map of a ‘component’.

class edxia.io.loader.PickleLoader(exp_manager, filters=None, no_BSE_filter=True, remove_previous=True)[source]

Bases: edxia.io.loader.base_loader.AbstractLoader

This loader cache filtered map so long filtering can be done only once.

denoise_and_renormalise()[source]

Denoise and renormalize all maps.

This can be used to correctly normalize the maps after filtering. Might be useful, or not, depending on the quality of the map.

get_path_picklemap(component)[source]

Return the path to the pickle map of ‘component’.

load_edsmap_single(component)[source]

Load a map.

Search the cache first if such a map exist.

remove_npy_files()[source]

Remove existing pickle files.

reset_filters(filters)[source]

Reset the filters

class edxia.io.loader.StackLoader(stack)[source]

Bases: edxia.io.loader.base_loader.AbstractLoader

Loader using a set of maps already read (and optionally filtered) using a different loader.

load_edsmap_single(component)[source]

Load the map of a ‘component’.

load_stack(components=None, factors=None)[source]

Copy and return the stack of maps of the loader.

class edxia.io.loader.base_loader.AbstractLoader(exp_manager, filters=None)[source]

Abstract base class for a map loader. This class is not intended for use, instead the user should use one of the class in edxia.io.loader.

add_filter(afilter)[source]

Add a filter to the list of filters to apply at loading.

exp_manager

Return the experience manager

filters

Return the list of filters to apply at loading.

get_path_map(component)[source]

Return the path to a component map.

load_composite(channels, is_rgb=True)[source]

Load a composite map

Parameters:
  • channels – the different channels to consider
  • is_rgb – if true, the map is reduced to an RGB image
load_composite_rgb(channels)[source]

Load a composite map.

load_edsmap(component)[source]

Load the map of ‘component’. It can be either a simple component (e.g. ‘BSE’, ‘Ca’), or a combination of components (e.g. “Si+Al/Ca”).

load_edsmap_complex(expr)[source]

Load an expresion map.

load_edsmap_single(component)[source]

Load the map of a ‘component’.

load_stack(components=None, factors=None)[source]

Load a stack of maps

Parameters:
  • components – the list of components, if not provided it is the entire list of components available
  • factors – the list of factors, default to 1
reset_filters(filters)[source]

Reset the list of filters.

Raw IO

This module provides raw loading and saving helper functions. It defines how the maps are read before any transformation from the algorithm.

Example: Read txt format from bruker Esprit software:

bse_map_asarray = load_txt_map("map234_BSE.txt", esprit_ascii_map_format)
class edxia.io.raw_io.TextMapFormat(delimiter, min_value, max_value, saveformat='%.4f')[source]

Bases: object

A struct-like class to contain formatting information about raw EDS maps.

copy()[source]

Copy the format

Returns:a copy of the text map format
delimiter

Return the column delimiter

escaped_delimiter

Return an escaped version of the delimiter

max_value

Return the maximum value allowed in the map

min_value

Return the minimum value allowed in the map

saveformat

Set the save format

edxia.io.raw_io.esprit_ascii_map_format = TextMapFormat(';',0,100)

Default EDS map format for the Bruker Esprit software

edxia.io.raw_io.esprit_ascii_bse_format = TextMapFormat(';',0,-1)

Default BSE map format for the Bruker Esprit software

edxia.io.raw_io.aztec_ascii_map_format = TextMapFormat(',',0,100)

Default EDS map format for the Oxford Aztec software

edxia.io.raw_io.aztec_ascii_bse_format = TextMapFormat(',',0,-1)

Default BSE map format for the Oxford Aztec software

edxia.io.raw_io.imagej_ascii_bse_format = TextMapFormat('\t',0,-1)

Format for a text image produced by ImageJ

edxia.io.raw_io.load_txt_map(filename, txtformat, resize=1)[source]

Load a 2D map

Parameters:
  • filename – filepath to the text map
  • txtformat – the format of the text map
  • resize – Stretch the map in each axis)
Returns:

a 2D numpy array normalized between [0,1]

Raises:

whatever numpy.loadtxt can raise

edxia.io.raw_io.save_txt_map(filename, amap, txtformat)[source]

Save a 2D map

Perform a copy first to normalize the data according the format.

Parameters:
  • filename – filepath to the file
  • amap – a 2D map
Format txtformat:
 

the format of the ascii saved map

edxia.io.raw_io.load_pickle_map(filepath)[source]

Load a map that was previously saved as a pickle dump

edxia.io.raw_io.save_pickle_map(filepath, data)[source]

Dump a map in a binary format

HDF5

edxia.io.hdf5.read_composite(hf5file, exp)[source]

Read a composite object from an open hdf5 file

edxia.io.hdf5.read_dataset(filepath)[source]

Read a set of edxia data from a hdf5 file

edxia.io.hdf5.read_experiment(h5file)[source]

Read an experiment from an open hdf5 file

edxia.io.hdf5.read_points(hf5file, exp)[source]

Read a points object from an open hdf5 file

edxia.io.hdf5.read_stack(hf5file, exp)[source]

Read a stack object from an open hdf5 file

edxia.io.hdf5.save_dataset(filepath, exp, stack=None, composite=None, points=None, extras=None, override=True)[source]

This function save a set of treated data into a hdf5 file.