Skip to content

Commit

Permalink
Merge pull request #2900 from hakonanes/fix-2881
Browse files Browse the repository at this point in the history
Make Bruker .bcf reader less restrictive if no element selection is found
  • Loading branch information
ericpre committed Mar 30, 2022
2 parents d9e27b0 + b2350f4 commit e56209a
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 60 deletions.
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
'hyperspyweb': ('https://hyperspy.org/', None),
'matplotlib': ('https://matplotlib.org', None),
'numpy': ('https://docs.scipy.org/doc/numpy', None),
'scipy': ('https://docs.scipy.org/doc/scipy/reference/', None),
'scipy': ('https://docs.scipy.org/doc/scipy/reference', None),
'dask': ('https://docs.dask.org/en/latest', None),
'astroML': ('https://www.astroml.org/', None),
'sklearn': ('https://scikit-learn.org/stable', None),
Expand Down
6 changes: 3 additions & 3 deletions doc/dev_guide/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Or, from HyperSpy's project folder, simply:
<https://docs.pytest.org/en/latest/customize.html>`_ for more details.

The HyperSpy test suite can also be run in parallel if you have multiple CPUs
available, using the ```pytest-xdist`` plugin <https://pypi.org/project/pytest-xdist/>`_.
available, using the `pytest-xdist plugin <https://pypi.org/project/pytest-xdist/>`_.
If you have the plugin installed, HyperSpy will automatically run the test suite in
parallel on your machine.

Expand All @@ -106,7 +106,7 @@ that all tests in a file run in the same worker.

Running tests in parallel using ``pytest-xdist`` will change the content
and format of the output of ``pytest`` to the console. We recommend installing
```pytest-sugar`` <https://pypi.org/project/pytest-sugar/>`_ to produce
`pytest-sugar <https://pypi.org/project/pytest-sugar/>`_ to produce
nicer-looking output including an animated progressbar.


Expand All @@ -118,7 +118,7 @@ random or non-deterministic behaviour. They may sometimes pass or sometimes fail
it won't always be clear why. These are usually known as "flaky" tests.

One way to approach flaky tests is to rerun them, to see if the failure was a one-off.
This can be achieved using the ```pytest-rerunfailures`` plugin <https://pypi.org/project/pytest-rerunfailures/>`_.
This can be achieved using the `pytest-rerunfailures plugin <https://pypi.org/project/pytest-rerunfailures/>`_.

.. code:: bash
Expand Down
2 changes: 1 addition & 1 deletion doc/dev_guide/writing_docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Build the documentation
To check the output of what you wrote, you can build
the documentation by running the ``make`` command in the ``hyperspy/doc``
directory. For example ``make html`` will build the whole documentation in
html format. See the make command documentation for more details.
html format. See the ``make`` command documentation for more details.

To install the documentation dependencies, run either

Expand Down
34 changes: 17 additions & 17 deletions doc/user_guide/eds.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ Loading data
All data are loaded with the :py:func:`~.io.load` function, as described in
detail in :ref:`Loading files<loading_files>`. HyperSpy is able to import
different formats, among them ".msa" and ".rpl" (the raw format of Oxford
Instruments and Brucker).
Instruments and Bruker).

Here are three example for files exported by Oxford Instruments software
Here are three examples of files exported by Oxford Instruments software
(INCA). For a single spectrum:

.. code-block:: python
Expand Down Expand Up @@ -518,7 +518,7 @@ EDS curve fitting
-----------------

The intensity of X-ray lines can be extracted using curve-fitting in HyperSpy.
This example uses an EDS-SEM spectrum of a a test material (EDS-TM001) provided
This example uses an EDS-SEM spectrum of a test material (EDS-TM001) provided
by `BAM <http://www.webshop.bam.de>`_.

First, we load the spectrum, define the chemical composition of the sample and
Expand Down Expand Up @@ -594,7 +594,7 @@ ranges containing no X-ray lines:
>>> m.fit_background()
The width of the X-ray lines is defined from the energy resolution (FWHM at
Mn Ka) provided by `energy_resolution_MnKa` in `metadata`. This parameters
Mn Ka) provided by `energy_resolution_MnKa` in `metadata`. This parameter
can be calibrated by fitting with
:py:meth:`~.models.edsmodel.EDSModel.calibrate_energy_axis`:

Expand Down Expand Up @@ -714,7 +714,7 @@ transformed into weight percent either with the option
>>> # With s, intensities and kfactors from before
>>> s.quantification(intensities, method='CL', factors=kfactors,
>>> composition_units='weight')
... composition_units='weight')
Fe (Fe_Ka): Composition = 4.96 weight percent
Pt (Pt_La): Composition = 95.04 weight percent
Expand Down Expand Up @@ -785,19 +785,19 @@ Absorption Correction
^^^^^^^^^^^^^^^^^^^^^

Absorption correction can be included into any of the three quantification
methods by adding the parameter absorption_correction=True to the function.
By default the function iterates the quantification function until of
tolerance value of 0.5% up to a maximum number of iterations. The maximum
number of iterations is set to 30 by default but can be increased by
specifying max_interations= in the function call. However, typically for TEM
experiments convergence is witness after less then 5 iterations.
methods by adding the parameter ``absorption_correction=True`` to the function.
By default, the function iterates the quantification function until a
tolerance value of 0.5% up to a maximum number of iterations is reached. The
maximum number of iterations is set to 30 by default, but can be increased by
specifying ``max_iterations`` in the function call. However, typically for TEM
experiments convergence is achieved after less then 5 iterations.

For example:

.. code-block:: python
>>> s.quantification(intensities, method='cross_section',
>>> factors=factors, absorption_correction=True)
... factors=factors, absorption_correction=True)
However for the kfactor method the user must additionally provide a sample
thickness (in nm) either as a single float value or as a numpy array with the
Expand All @@ -808,8 +808,8 @@ composition maps for each element.
.. code-block:: python
>>> s.quantification(intensities, method='CL',
>>> factors=factors, absorption_correction=True
>>> thickness = 100.)
... factors=factors, absorption_correction=True
... thickness=100.)
At this stage absorption correction is only applicable for parallel-sided,
thin-film samples. Absorption correction is calculated on a pixel by pixel
Expand All @@ -835,13 +835,13 @@ is available:
.. code-block:: python
>>> hs.material.mass_absorption_coefficient(
>>> element='Al', energies=['C_Ka','Al_Ka'])
... element='Al', energies=['C_Ka','Al_Ka'])
array([ 26330.38933818, 372.02616732])
.. code-block:: python
>>> hs.material.mass_absorption_mixture(
>>> elements=['Al','Zn'], weight_percent=[50,50], energies='Al_Ka')
... elements=['Al','Zn'], weight_percent=[50,50], energies='Al_Ka')
2587.4161643905127
Electron and X-ray range
Expand All @@ -862,7 +862,7 @@ To calculate the X-ray range of Cu Ka in pure Carbon at 30kV in micron:
.. code-block:: python
>>> hs.eds.xray_range('Cu_Ka', 30., hs.material.elements.C.
>>> Physical_properties.density_gcm3)
... Physical_properties.density_gcm3)
7.6418811280855454
To calculate the electron range in pure Copper at 30 kV in micron
Expand Down
40 changes: 20 additions & 20 deletions doc/user_guide/eels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Tools for EELS data analysis

The functions described in this chapter are only available for the
:py:class:`~._signals.eels.EELSSpectrum` class. To transform a
:py:class:`~.signal.BaseSignal` (or subclass) into a
:py:class:`~.signal.BaseSignal` (or subclass) into an
:py:class:`~._signals.eels.EELSSpectrum`:

.. code-block:: python
Expand Down Expand Up @@ -52,8 +52,6 @@ they are arranged in the order closest to 849 eV.
>>> get_edges_near_energy(849, width=6)
['La_M4', 'Fe_L1']
`
The static method :py:meth:`~._signals.eels.EELSSpectrum.print_edges_near_energy`
in :py:class:`~._signals.eels.EELSSpectrum` will print out a table containing
more information about the edges.
Expand Down Expand Up @@ -93,7 +91,7 @@ to aid identification of edges.
:align: center
:width: 500

Labels of edges can be put or remove by toggling the edge buttons.
Labels of edges can be put or removed by toggling the edge buttons.


.. _eels_thickness-label:
Expand All @@ -120,13 +118,13 @@ Zero-loss peak centre and alignment

The
:py:meth:`~._signals.eels.EELSSpectrum.estimate_zero_loss_peak_centre`
can be used to estimate the position of the zero-loss peak. The method assumes
can be used to estimate the position of the zero-loss peak (ZLP). The method assumes
that the ZLP is the most intense feature in the spectra. For a more general
approach see :py:meth:`~.signal.Signal1DTools.find_peaks1D_ohaver`.

The :py:meth:`~._signals.eels.EELSSpectrum.align_zero_loss_peak` can
align the ZLP with subpixel accuracy. It is more robust and easy to use than
:py:meth:`~.signal.Signal1DTools.align1D` for the task. Note that it is
align the ZLP with subpixel accuracy. It is more robust and easy to use for the task
than :py:meth:`~.signal.Signal1DTools.align1D`. Note that it is
possible to apply the same alignment to other spectra using the `also_align`
argument. This can be useful e.g. to align core-loss spectra acquired
quasi-simultaneously. If there are other features in the low loss signal
Expand Down Expand Up @@ -161,7 +159,7 @@ of the signal and assigns the inflexion point to the first point below a
certain tolerance. This tolerance value can be set using the `tol` keyword.
Currently, the method uses smoothing to reduce the impact of the noise in the
measure. The number of points used for the smoothing window can be specified by
the npoints keyword.
the `npoints` keyword.


.. _eels.kk:
Expand Down Expand Up @@ -220,10 +218,13 @@ Define the chemical composition of the sample
>>> s.add_elements(('B', 'N'))
It is worth noting that in this case the experimental parameters and the list of elements are actually automatically imported from the EELS Data Base.
It is worth noting that in this case the experimental parameters and the list of
elements are actually automatically imported from the EELS Data Base.
However, with real life data, these must often be added by hand.

In order to include the effect of plural scattering, the model is convolved with the loss loss spectrum in which case the low loss spectrum needs to be provided to :py:meth:`~._signals.eels.EELSSpectrum.create_model`:
In order to include the effect of plural scattering, the model is convolved with the
low-loss spectrum in which case the low-loss spectrum needs to be provided to
:py:meth:`~._signals.eels.EELSSpectrum.create_model`:

.. code-block:: python
Expand All @@ -242,7 +243,7 @@ HyperSpy has created the model and configured it automatically:
2 | B_K | B_K | EELSCLEdge
Conveniently, all the EELS core-loss components of the added elements are added
automatically, names after its element symbol.
automatically, named after its element symbol:

.. code-block:: python
Expand All @@ -253,14 +254,14 @@ automatically, names after its element symbol.
By default the fine structure features are disabled (although
the default value can be configured (see :ref:`configuring-hyperspy-label`).
We must enable them to accurately fit this spectrum.
We must enable them to accurately fit this spectrum:

.. code-block:: python
>>> m.enable_fine_structure()
We use :py:meth:`~.models.eelsmodel.EELSModel.smart_fit` instead of standard
We use :py:meth:`~.models.eelsmodel.EELSModel.smart_fit` instead of the standard
fit method because :py:meth:`~.models.eelsmodel.EELSModel.smart_fit` is
optimized to fit EELS core-loss spectra

Expand All @@ -279,11 +280,11 @@ image
.. NOTE::

`m.smart_fit()` and `m.multifit(kind='smart')` are methods specific to the
EELS model. The fitting procedure acts in iterative manner along the
EELS model. The fitting procedure acts in an iterative manner along the
energy-loss-axis. First it fits only the background up to the first edge.
It continues by deactivating all edges except the first one, then performs
the fit. Then it only activates the the first two, fits, and repeats this
until all edges are fitted simultanously.
until all edges are fitted simultaneously.

Other, non-EELSCLEdge components, are never deactivated, and fitted on every
iteration.
Expand Down Expand Up @@ -328,7 +329,7 @@ There are several methods that are only available in
convolving with a zero-loss peak.

The following methods permit to easily enable/disable background and ionisation
edges components:
edge components:

* :py:meth:`~.models.eelsmodel.EELSModel.enable_edges`
* :py:meth:`~.models.eelsmodel.EELSModel.enable_background`
Expand All @@ -353,10 +354,9 @@ When fitting edges with fine structure enabled it is often desirable that the
fine structure region of nearby ionization edges does not overlap. HyperSpy
provides a method,
:py:meth:`~.models.eelsmodel.EELSModel.resolve_fine_structure`, to
automatically adjust the fine structure to prevent fine structure to avoid
overlapping. This method is executed automatically when e.g. components are
added or removed from the model, but sometimes is necessary to call it
manually.
automatically adjust the fine structure to avoid overlap. This method is executed
automatically when e.g. components are added or removed from the model, but
sometimes is necessary to call it manually.

Sometimes it is desirable to disable the automatic adjustment of the fine
structure width. It is possible to suspend this feature by calling
Expand Down
4 changes: 2 additions & 2 deletions doc/user_guide/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ Strategies

During operation SAMFire uses a list of strategies to determine how to select
the next pixel and estimate its starting parameters. Only one strategy is used
at a time. Next strategy is chosen when no new pixels are can be fitted with
at a time. Next strategy is chosen when no new pixels can be fitted with
the current strategy. Once either the strategy list is exhausted or the full
dataset fitted, the algorithm terminates.

Expand Down Expand Up @@ -1645,7 +1645,7 @@ it's recommended specify it explicitly via the ``ipyparallel=False`` argument,
to use the fall-back option of `multiprocessing`.

By default a new SAMFire object already has two (and currently only) strategies
added to its strategist list:
added to its ``strategies`` list:

.. code-block:: python
Expand Down
7 changes: 5 additions & 2 deletions hyperspy/io_plugins/bruker.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,11 @@ def _set_elements(self, root):
for j in elements.findall(
"./ClassInstance[@Type='TRTSpectrumRegion']"):
tmp_d = dictionarize(j)
self.elements[tmp_d['XmlClassName']] = {'line': tmp_d['Line'],
'energy': tmp_d['Energy']}
# In case no information on the specific selected X-ray line is
# available, assume it is a 'Ka' line, reflecting the fact that element
# tables in Bruker Esprit (1.9 and 2.1) store a single K line for Li-Al
self.elements[tmp_d['XmlClassName']] = {'line': tmp_d.get('Line', 'Ka'),
'energy': tmp_d.get('Energy')}
except AttributeError:
_logger.info('no element selection present in the spectra..')

Expand Down
11 changes: 5 additions & 6 deletions hyperspy/models/edsmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,10 @@ def calibrate_energy_axis(self,
calibrate: 'resolution' or 'scale' or 'offset'
If 'resolution', fits the width of Gaussians place at all x-ray
lines. The width is given by a model of the detector resolution,
obtained by extrapolating the `energy_resolution_MnKa` in `metadata`
`metadata`.
obtained by extrapolating the `energy_resolution_MnKa` in `metadata`.
This method will update the value of `energy_resolution_MnKa`.
If 'scale', calibrate the scale of the energy axis
If 'offset', calibrate the offset of the energy axis
If 'scale', calibrate the scale of the energy axis.
If 'offset', calibrate the offset of the energy axis.
xray_lines: list of str or 'all_alpha'
The Xray lines. If 'all_alpha', fit all using all alpha lines
**kwargs : extra key word arguments
Expand Down Expand Up @@ -641,9 +640,9 @@ def free_sub_xray_lines_weight(self, xray_lines='all', bound=0.01):
Parameters
----------
xray_lines: list of str or 'all'
xray_lines : list of str or 'all'
The Xray lines. If 'all', fit all lines
bounds: float
bound : float
Bound the height of the peak to a fraction of
its height
"""
Expand Down
2 changes: 2 additions & 0 deletions upcoming_changes/2881.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In case the Bruker defined XML element node at SpectrumRegion contains no information on the
specific selected X-ray line (if there is only single line available), suppose it is 'Ka' line.
14 changes: 6 additions & 8 deletions upcoming_changes/README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This directory contains "newsfragments" which are short files that contain a small **ReST**-formatted
This directory contains "news fragments" which are short files that contain a small **ReST**-formatted
text that will be added to the next ``CHANGELOG``.

The ``CHANGELOG`` will be read by **users**, so this description should be aimed to hyperspy users
Expand All @@ -12,27 +12,25 @@ Each file should be named like ``<ISSUE>.<TYPE>.rst``, where
* ``doc``: documentation improvement, like rewording an entire session or adding missing docs.
* ``deprecation``: feature deprecation.
* ``enhancements``: improvement of existing functionality, usually without requiring user intervention.
* ``api``: a change which may break existing script, such as feature removal or behavior change.
* ``api``: a change which may break an existing script, such as feature removal or behavior change.
* ``maintenance``: a change related to the test suite, packaging, etc.

So for example: ``123.new.rst``, ``456.bugfix.rst``.
So for example ``1412.new.rst`` or ``2773.bugfix.rst``.

If your PR fixes an issue, use that number here. If there is no issue,
If your PR fixes an issue, use the number of the issue here. If there is no issue,
then after you submit the PR and get the PR number you can add a
changelog using that instead.

If you are not sure what issue type to use, don't hesitate to ask in your PR.

``towncrier`` preserves multiple paragraphs and formatting (code blocks, lists, and so on), but for entries
other than ``new`` it is usually better to stick to a single paragraph to keep it concise. For ``new``,
it is recommended to add hyperlink to the user guide.
it is recommended to add a hyperlink to the user guide.


To previous a draft of the changelog, run from the command line:
To make a draft of the changelog, run from the command line:

.. code-block:: bash
$ towncrier build --draft
See https://github.com/twisted/towncrier for more details.

0 comments on commit e56209a

Please sign in to comment.