Loading data

Data is loaded by using two specialized loading functions:

Both these functions are accessible through pixstem.api.

Real datasets (and sometimes processing scripts) you can use for testing the functionality are found in Open datasets.

Pixelated STEM

You can either use generated test dataset, or your own data. To generate a test pixelated STEM dataset:

>>> import pixstem.dummy_data as dd
>>> s = dd.get_holz_simple_test_signal()
>>> s.save("test_data.hdf5")

Load the data using load_ps_signal():

>>> import pixstem.api as ps
>>> s = ps.load_ps_signal("test_data.hdf5", lazy=True)

Here lazy=True was used. Essentially this does not load all the data into memory, meaning very large datasets can be processed. However, this also means that the processing will take longer to do, and some care needs to be taken when actually doing the processing. See the HyperSpy documentation for information on how to do this.

Here the dataset is fairly small, so it should easily fit into memory.:

>>> import pixstem.api as ps
>>> s = ps.load_ps_signal("test_data.hdf5")

Note: for larger datasets this might take a long time, and might use all of your memory. This might cause the computer to crash, so be careful when loading large datasets.

To visualize the data, use plot:

>>> s.plot()

From NumPy array to PixelatedSTEM object

The PixelatedSTEM class can also be created using a NumPy array directly.

>>> import pixstem.api as ps
>>> import numpy as np
>>> data = np.random.random((10, 15, 30, 35))
>>> s = ps.PixelatedSTEM(data)
>>> s
<PixelatedSTEM, title: , dimensions: (15, 10|35, 30)>

Note that dimensions 0/1 and 2/3 are flipped in the PixelatedSTEM signal and the NumPy array. This is due to how HyperSpy handles the input data. In this case it leads to the signal x-dimension having a size of 35, and a y-dimension a size of 30. While the navigation x-dimension has a size of 15, and a y-size of 10.

From Dask array to LazyPixelatedSTEM object

When working with very large datasets, lazy loading is preferred. One way of doing this is by using the dask library. See the HyperSpy big data documentation for more information on how to utilize lazy loading the pixstem library.

>>> import pixstem.api as ps
>>> import dask.array as da
>>> data = da.random.random((10, 7, 15, 32), chunks=((2, 2, 2, 2)))
>>> s = ps.LazyPixelatedSTEM(data)
>>> s
<LazyPixelatedSTEM, title: , dimensions: (7, 10|32, 15)>

From HyperSpy signal to PixelatedSTEM

To retain the axes manager and metadata, use the pixstem.io_tools.signal_to_pixelated_stem() function.

>>> import numpy as np
>>> import hyperspy.api as hs
>>> data = np.random.random((10, 15, 30, 35))
>>> s = hs.signals.Signal2D(data)
>>> import pixstem.io_tools as it
>>> s_new = it.signal_to_pixelated_stem(s)

Differential phase contrast (beam shift) data

Differential phase contrast (DPC) datasets are loaded using pixstem.io_tools.load_dpc_signal(). These datasets must have one navigation dimensions with two indices, where the first navigation index is the x-direction beam shift, and the second navigation dimension is the y-direction beam shift. The signal dimensions must be either two, one or zero, giving either DPCSignal2D, DPCSignal1D or DPCBaseSignal.

Files saved using HyperSpy can also be opened directly, as long as the dataset has one navigation dimension with a shape of 2.

You can either use a generated test dataset, or your own data. To generate a test DPC dataset:

>>> import pixstem.dummy_data as dd
>>> s = dd.get_simple_dpc_signal()
>>> s.save("test_dpc_data.hdf5")

To load the test file (or your own file):

>>> import pixstem.api as ps
>>> s = ps.load_dpc_signal("test_dpc_data.hdf5")

Plotting the data:

>>> s.plot()
>>> s.get_color_signal().plot()

From NumPy array to DPCSignal objects

The DPCSignal2D object can be created using

>>> import pixstem.api as ps
>>> import numpy as np
>>> data = np.random.random((2, 21, 54))
>>> s = ps.DPCSignal2D(data)
>>> s
<DPCSignal2D, title: , dimensions: (2|54, 21)>

Note the switch of the x/y signal axis.

The DPCSignal1D object can be created using:

>>> data = np.random.random((2, 109))
>>> s = ps.DPCSignal1D(data)
>>> s
<DPCSignal1D, title: , dimensions: (2|109)>

The DPCBaseSignal object can be created using:

>>> data = np.random.random((2, ))
>>> s = ps.DPCBaseSignal(data)
>>> s
<DPCBaseSignal, title: , dimensions: (|2)>