.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/create_signal/from_tabular_data_file.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_create_signal_from_tabular_data_file.py: Creates a signal1D from a text file =================================== This example creates a signal from tabular data imported from a txt file using :func:`numpy.loadtxt`. The signal axis and the EELS intensity values are given by the first and second columns, respectively. The tabular data are taken from https://eelsdb.eu/spectra/la2nio4-structure-of-k2nif4/ .. GENERATED FROM PYTHON SOURCE LINES 11-15 .. code-block:: Python import numpy as np import hyperspy.api as hs .. GENERATED FROM PYTHON SOURCE LINES 16-17 Read tabular data from a text file: .. GENERATED FROM PYTHON SOURCE LINES 17-19 .. code-block:: Python x, y = np.loadtxt("La2NiO4_eels.txt", unpack=True) .. GENERATED FROM PYTHON SOURCE LINES 20-21 Define the axes of the signal and then create the signal: .. GENERATED FROM PYTHON SOURCE LINES 21-29 .. code-block:: Python axes = [ # use values from first column to define non-uniform signal axis dict(axis=x, name="Energy", units="eV"), ] s = hs.signals.Signal1D(y, axes=axes) .. GENERATED FROM PYTHON SOURCE LINES 30-33 Convert the non-uniform axis to a uniform axis, because non-uniform axes do not support all functionalities of HyperSpy. In this case, the error introduced during conversion to uniform `scale` is negligeable. .. GENERATED FROM PYTHON SOURCE LINES 33-36 .. code-block:: Python s.axes_manager.signal_axes[0].convert_to_uniform_axis() .. GENERATED FROM PYTHON SOURCE LINES 37-38 Set title of the dataset and label for the data axis: .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python s.metadata.set_item("General.title", "La2NiO4 EELS") s.metadata.set_item("Signal.quantity", "Intensity (counts)") .. GENERATED FROM PYTHON SOURCE LINES 42-43 Plot the dataset: .. GENERATED FROM PYTHON SOURCE LINES 43-45 .. code-block:: Python s.plot() .. image-sg:: /auto_examples/create_signal/images/sphx_glr_from_tabular_data_file_001.png :alt: La2NiO4 EELS Signal :srcset: /auto_examples/create_signal/images/sphx_glr_from_tabular_data_file_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.444 seconds) .. _sphx_glr_download_auto_examples_create_signal_from_tabular_data_file.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: from_tabular_data_file.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: from_tabular_data_file.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_