-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from jlaehne/doc-energy
Documentation: axis conversion
- Loading branch information
Showing
10 changed files
with
303 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
.. _fitting_luminescence: | ||
.. _fitting_luminescence-label: | ||
|
||
Fitting luminescence data | ||
************************* | ||
|
||
LumiSpy is compatible with model fitting as Hyperspy. It can fit both in linear and non-linear axes. | ||
LumiSpy is compatible with HyperSpy model fitting. It can fit both in linear and non-linear axes. | ||
|
||
TODO: Link to Hyperspy guide | ||
TODO: Note on advantages of fitting Gaussians in the ``eV`` axis. | ||
TODO: Show how to extract the *modeled signal* with all/one component. | ||
|
||
.. _fitting_variance-label: | ||
|
||
Signal variance (noise) | ||
======================= | ||
|
||
TODO: Documentation on variance handling in the context of fitting | ||
in particular using ``s.estimate_poissonian_noise_variance()`` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,158 @@ | ||
.. _signal_axis: | ||
.. _signal_axis-label: | ||
|
||
Non-uniform signal axes | ||
*********************** | ||
|
||
LumiSpy enables the use of non-linear axis (e.g. ``eV``) in an easy way. | ||
LumiSpy facilitates the use of `non-uniform axes | ||
<https://hyperspy.org/hyperspy-doc/current/user_guide/axes.html#non-uniform-data-axis>`_, | ||
where the points of the axis vector are not uniformly spaced. This situation | ||
occurs in particular when converting a wavelength scale to energy (eV) or | ||
wavenumbers (e.g. for Raman shifts). | ||
|
||
The function :py:func:`~.signals.luminescence_spectrum.LumiSpectrum.to_eV` simplifies the definition | ||
The conversion of the signal axis can be performed using the functions | ||
:py:meth:`~.signals.luminescence_spectrum.LumiSpectrum.to_eV`, | ||
:py:meth:`~.signals.luminescence_spectrum.LumiSpectrum.to_invcm` and | ||
:py:meth:`~.signals.luminescence_spectrum.LumiSpectrum.to_raman_shift` | ||
(alias for :py:meth:`~.signals.luminescence_spectrum.LumiSpectrum.to_invcm_relative`). | ||
If the unit of the signal axis is set, the functions can handle wavelengths in | ||
either nm or µm. | ||
|
||
TODO: Explain the Jacobian transform. | ||
TODO: Show how the transform is done ``s.to_eV()``. | ||
Accepted parameters are ``inplace=True/False`` (default is True), which | ||
determines whether the current signal object is modified or a new one is | ||
created, and ``jacobian=True/False`` (default is True, see | ||
:ref:`jacobian-label`). | ||
|
||
TODO: Note on signal noise. | ||
.. Note:: | ||
|
||
The non-uniform axis functionality will be available from HyperSpy v.1.7. | ||
If this version is not yet available, you need to use the `development | ||
branch <https://github.com/hyperspy/hyperspy>`_. | ||
|
||
|
||
.. _energy_axis-label: | ||
|
||
The energy axis | ||
=============== | ||
|
||
The transformation from wavelength :math:`\lambda` to energy :math:`E` is | ||
defined as :math:`E = h c/ \lambda`. Taking into account the permittivity of | ||
air and doing a conversion from nm to eV, we get: | ||
|
||
.. math:: | ||
E = \frac{10^9 h c}{e \epsilon_r \lambda}, | ||
where :math:`h` is the Planck constant, :math:`c` is the speed of light, | ||
:math:`e` is the elementary charge and :math:`\epsilon_r` is the relative | ||
permittivity of air. | ||
|
||
.. code-block:: python | ||
>>> s2 = s.to_eV(inplace=False) | ||
>>> s.to_eV() | ||
.. Note:: | ||
|
||
The relative permittivity of air :math:`\epsilon_r` is wavelength | ||
dependent. This dependence is taken into account by LumiSpy based on the | ||
analytical formula given by [Peck]_ valid from 185-1700 nm | ||
(outside of this range, the permittivity values at the edges of the range | ||
are used and a warning is raised). | ||
|
||
|
||
.. _wavenumber_axis-label: | ||
|
||
The wavenumber axis/Raman shifts | ||
================================ | ||
|
||
The transformation from wavelength :math:`\lambda` to wavenumber | ||
:math:`\tilde{\nu}` (spatial frequency of the wave) is defined as | ||
:math:`\tilde{\nu} = 1/ \lambda`. The wavenumber is usually given in units of | ||
:math:`\mathrm{cm}^{-1}`. | ||
|
||
When converting a signal to Raman shift, i.e. the shift in wavenumbers from | ||
the exciting laser wavelength, the laser wavelength has to be passed to the function using the parameter | ||
``laser`` using the same units as for the original axis (e.g. 325 for nm or | ||
0.325 for µm) unless it is contained in the :ref:`metadata_structure` under | ||
``Acquisition_instrument.Laser.wavelength``. | ||
|
||
TODO: Automatically read laser wavelength from metadata if given there. | ||
|
||
.. code-block:: python | ||
>>> s2 = s.to_invcm(inplace=False) | ||
>>> s.to_invcm() | ||
>>> s2 = s.to_raman_shift(inplace=False, laser=325) | ||
>>> s.to_raman_shift(laser=325) | ||
.. _jacobian-label: | ||
|
||
Jacobian transformation | ||
======================= | ||
|
||
When transforming the signal axis, the signal intensity is automatically | ||
rescaled (Jacobian transformation), unless the ``jacobian=False`` option is | ||
given. Only converting the signal axis, and leaving the signal intensity | ||
unchanged, implies that the integral of the signal over the same interval would | ||
lead to different results depending on the quantity on the axis (see e.g. | ||
[Mooney]_.). | ||
|
||
For the energy axis as example, if we require :math:`I(E)dE = I(\lambda)d\lambda`, | ||
then :math:`E=hc/\lambda` implies | ||
|
||
.. math :: | ||
I(E) = I(\lambda)\frac{d\lambda}{dE} = I(\lambda)\frac{d}{dE} | ||
\frac{h c}{\lambda} = - I(\lambda) \frac{h c}{E^2} | ||
The minus sign just reflects the different directions of integration in | ||
the wavelength and energy domains. The same argument holds for the conversion | ||
from wavelength to wavenumber (just without the additional prefactors in the | ||
equation). The renormalization in LumiSpy is defined such that the intensity is | ||
converted from counts/nm (or counts/µm) to counts/meV. The following | ||
figure illustrates the effect of the Jacobian transformation: | ||
|
||
.. image:: images/jacobian.png | ||
:width: 700 | ||
:alt: Illustration of the Jacobian transformation from wavelength (nm) to energy (eV). | ||
|
||
|
||
.. _jacobian_variance-label: | ||
|
||
Transformation of the variance | ||
------------------------------ | ||
|
||
Scaling the signal intensities implies that also the stored variance of the | ||
signal needs to be scaled accordingly. According to :math:`Var(aX) = a^2Var(X)`, | ||
the variance has to be multiplied with the square of the Jacobian. This squared | ||
renormalization is automatically performed by LumiSpy if ``jacobian=True``. | ||
In particular, homoscedastic (constant) noise will consequently become | ||
heteroscedastic (changing as a function of the signal axis vector). Therefore, | ||
if the ``metadata.Signal.Noise_properties.variance`` attribute is a constant, | ||
it is converted into a :external:py:class:`hyperspy.signal.BaseSignal` object | ||
before the transformation. | ||
|
||
See :ref:`fitting_variance-label` for more general information on data variance | ||
in the context of model fitting and the HyperSpy documentation on `setting | ||
the noise properties | ||
<https://hyperspy.org/hyperspy-doc/current/user_guide/signal.html?highlight=variance_linear_model#setting-the-noise-properties>`_. | ||
|
||
.. Note:: | ||
|
||
If the Jacobian transformation is performed, the values of | ||
``metadata.Signal.Noise_properties.Variance_linear_model`` are reset to | ||
their default values (``gain_factor=1``, ``gain_offset=0`` and ``correlation_factor=1``). | ||
Should these values deviate from the defaults, make sure to run | ||
:external:py:meth:`hyperspy.signal.BaseSignal.estimate_poissonian_noise_variance` | ||
prior to the transformation. | ||
|
||
|
||
.. rubric:: References | ||
|
||
.. [Peck] E.R. Peck and K. Reeder, J. Opt. Soc. Am. **62**, 958 | ||
(1972). `doi:10.1364/JOSA.62.000958 <https://doi.org/10.1364/JOSA.62.000958>`_ | ||
.. [Mooney] J. Mooney and P. Kambhampati, The Journal of | ||
Physical Chemistry Letters **4**, 3316 (2013). | ||
`doi:10.1021/jz401508t <https://doi.org/10.1021/jz401508t>`_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.