From 89b3e817e6542e11b2ff3e7bfb9c9af10fb987a7 Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Tue, 16 Jul 2024 21:39:32 +0200 Subject: [PATCH 01/27] support Dirac GOS --- doc/user_guide/eels.rst | 1 + examples/model_fitting/EELS_curve_fitting.py | 9 ++ exspy/components/eels_cl_edge.py | 9 +- exspy/docstrings/model.py | 4 +- exspy/misc/eels/__init__.py | 3 +- exspy/misc/eels/dirac_gos.py | 137 +++++++++++++++++++ exspy/models/eelsmodel.py | 1 + exspy/signals/eels.py | 1 + exspy/tests/misc/test_gos.py | 22 +++ 9 files changed, 182 insertions(+), 5 deletions(-) create mode 100644 exspy/misc/eels/dirac_gos.py diff --git a/doc/user_guide/eels.rst b/doc/user_guide/eels.rst index fd1066e71..cdd54fd15 100644 --- a/doc/user_guide/eels.rst +++ b/doc/user_guide/eels.rst @@ -274,6 +274,7 @@ The model for the GOS can be specified with the ``GOS`` argument By default, a freely usable tabulated dataset, in `gosh `__ format, is downloaded from Zenodo: `doi:10.5281/zenodo.7645765 `_. +As alternative, one can use the `Dirac GOS `__ to include the relativistic effects, which is downloaded from Zenodo: `doi:10.5281/zenodo.12751756 `_ and also follows the `gosh` format. Custom GOS saved in the `gosh `__ format can be used, the following example download a previous version (1.0) of the GOS file from Zenodo diff --git a/examples/model_fitting/EELS_curve_fitting.py b/examples/model_fitting/EELS_curve_fitting.py index 4087127c8..cca37f979 100644 --- a/examples/model_fitting/EELS_curve_fitting.py +++ b/examples/model_fitting/EELS_curve_fitting.py @@ -1,3 +1,4 @@ +# %% """ EELS curve fitting ================== @@ -21,3 +22,11 @@ m.enable_fine_structure() m.multifit(kind="smart") m.plot() + +# one can also use the Dirac GOS by specifying the GOS parameter +m = s.create_model(low_loss=ll, GOS="Dirac") +m.enable_fine_structure() +m.multifit(kind="smart") +m.plot() + +# %% diff --git a/exspy/components/eels_cl_edge.py b/exspy/components/eels_cl_edge.py index 3a2f9d8dd..aad155660 100644 --- a/exspy/components/eels_cl_edge.py +++ b/exspy/components/eels_cl_edge.py @@ -26,6 +26,7 @@ from hyperspy.component import Component from exspy.misc.eels.gosh_gos import GoshGOS, _GOSH_DOI +from exspy.misc.eels.dirac_gos import DiracGOS from exspy.misc.eels.hartree_slater_gos import HartreeSlaterGOS from exspy.misc.eels.hydrogenic_gos import HydrogenicGOS from exspy.misc.eels.effective_angle import effective_angle @@ -92,7 +93,7 @@ class EELSCLEdge(Component): Usually a string, for example, ``'Ti_L3'`` for the GOS of the titanium L3 subshell. If a dictionary is passed, it is assumed that Hartree Slater GOS was exported using `GOS.as_dictionary`, and will be reconstructed. - GOS : ``'gosh'``, ``'hydrogenic'``, ``'Hartree-Slater'`` or str + GOS : ``'gosh'``,``'Dirac'``, ``'hydrogenic'``, ``'Hartree-Slater'`` or str The GOS to use. Default is ``'gosh'``. If str, it must the path to gosh GOS file. gos_file_path : str, None @@ -169,13 +170,15 @@ def __init__(self, element_subshell, GOS="gosh", gos_file_path=None): if GOS == "gosh": self.GOS = GoshGOS(element_subshell, gos_file_path=gos_file_path) + elif GOS == "Dirac": + self.GOS = DiracGOS(element_subshell,gos_file_path=gos_file_path) elif GOS == "Hartree-Slater": # pragma: no cover self.GOS = HartreeSlaterGOS(element_subshell) elif GOS == "hydrogenic": self.GOS = HydrogenicGOS(element_subshell) else: raise ValueError( - "GOS must be one of 'gosh', 'hydrogenic' or 'Hartree-Slater'." + "GOS must be one of 'gosh', 'Dirac','hydrogenic' or 'Hartree-Slater'." ) self.onset_energy.value = self.GOS.onset_energy self.onset_energy.free = False @@ -189,6 +192,8 @@ def __init__(self, element_subshell, GOS="gosh", gos_file_path=None): self._whitelist["GOS"] = ("init", GOS) if GOS == "gosh": self._whitelist["element_subshell"] = ("init", self.GOS.as_dictionary(True)) + elif GOS == "Dirac": + self._whitelist["element_subshell"] = ("init", self.GOS.as_dictionary(True)) elif GOS == "Hartree-Slater": # pragma: no cover self._whitelist["element_subshell"] = ("init", self.GOS.as_dictionary(True)) elif GOS == "hydrogenic": diff --git a/exspy/docstrings/model.py b/exspy/docstrings/model.py index 30db3d820..7f9465845 100644 --- a/exspy/docstrings/model.py +++ b/exspy/docstrings/model.py @@ -21,11 +21,11 @@ from exspy.misc.eels.gosh_gos import _GOSH_DOI -GOS_PARAMETER = """GOS : 'hydrogenic', 'gosh', 'Hartree-Slater'. +GOS_PARAMETER = """GOS : 'hydrogenic', 'gosh', 'Dirac', 'Hartree-Slater'. The GOS to use. Default is ``'gosh'``. gos_file_path : str, None - Only with GOS='gosh'. Specify the file path of the gosh file + Only with GOS='gosh' or 'Dirac'. Specify the file path of the gosh file to use. If None, use the file from doi:{}""".format(_GOSH_DOI) EELSMODEL_PARAMETERS = """ll : None or EELSSpectrum diff --git a/exspy/misc/eels/__init__.py b/exspy/misc/eels/__init__.py index 76a0d5eb9..3dd45ad3b 100644 --- a/exspy/misc/eels/__init__.py +++ b/exspy/misc/eels/__init__.py @@ -1,5 +1,6 @@ from exspy.misc.eels.hydrogenic_gos import HydrogenicGOS from exspy.misc.eels.gosh_gos import GoshGOS +from exspy.misc.eels.dirac_gos import DiracGOS from exspy.misc.eels.hartree_slater_gos import HartreeSlaterGOS -__all__ = ["HydrogenicGOS", "GoshGOS", "HartreeSlaterGOS"] +__all__ = ["HydrogenicGOS", "GoshGOS", "DiracGOS", "HartreeSlaterGOS"] diff --git a/exspy/misc/eels/dirac_gos.py b/exspy/misc/eels/dirac_gos.py new file mode 100644 index 000000000..cfcea99e2 --- /dev/null +++ b/exspy/misc/eels/dirac_gos.py @@ -0,0 +1,137 @@ +# -*- coding: utf-8 -*- +# Copyright 2007-2024 The eXSpy developers +# +# This file is part of eXSpy. +# +# eXSpy is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# eXSpy is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with eXSpy. If not, see . + +import logging + +import h5py +import numpy as np +import pooch +from scipy import constants + +from hyperspy.defaults_parser import preferences +from exspy.misc.eels.base_gos import TabulatedGOS + + +_logger = logging.getLogger(__name__) + +R = constants.value("Rydberg constant times hc in eV") +a0 = constants.value("Bohr radius") + +_Dirac_GOSH_DOI = "10.5281/zenodo.12752410" +_Dirac_GOSH_URL = f"doi:{_Dirac_GOSH_DOI}/Dirac_GOS.gosh" +_Dirac_GOSH_KNOWN_HASH = "md5:02fb22ab55e39e51eb03c08dbf699545" + + +class DiracGOS(TabulatedGOS): + """Read Generalized Oscillator Strength from a Dirac GOSH database. + + Parameters + ---------- + element_subshell : {str, dict} + Usually a string, for example, 'Ti_L3' for the GOS of the titanium L3 + subshell. If a dictionary is passed, it is assumed that a GOSH GOS was + exported using `GOS.as_dictionary`, and will be reconstructed. + + Methods + ------- + readgosarray() + Read the GOS files of the element subshell from the location + defined in Preferences. + get_qaxis_and_gos(ienergy, qmin, qmax) + given the energy axis index and qmin and qmax values returns + the qaxis and gos between qmin and qmax using linear + interpolation to include qmin and qmax in the range. + + Attributes + ---------- + energy_axis : array + The tabulated energy axis + qaxis : array + The tabulated qaxis + energy_onset: float + The energy onset for the given element subshell as obtained + from iternal tables. + + """ + + _name = "gosh" + _whitelist = { + "gos_array": None, + "rel_energy_axis": None, + "qaxis": None, + "element": None, + "subshell": None, + "subshell_factor": None, + } + + def __init__(self, element_subshell, gos_file_path=None): + """ + Parameters + ---------- + element_subshell : str + For example, 'Ti_L3' for the GOS of the titanium L3 subshell + gos_file_path : str + The path of the gosh file to use. + """ + + if gos_file_path is None: + gos_file_path = pooch.retrieve( + url=_Dirac_GOSH_URL, + known_hash=_Dirac_GOSH_KNOWN_HASH, + progressbar=preferences.General.show_progressbar, + ) + self.gos_file_path = gos_file_path + super().__init__(element_subshell=element_subshell) + + def read_gos_data(self): + _logger.info( + "GOSH precomputed GOS\n" + f"\tElement: {self.element} " + f"\tSubshell: {self.subshell}" + f"\tOnset Energy = {self.onset_energy}" + ) + element = self.element + subshell = self.subshell + + error_message = ( + "The GOSH Parametrized GOS database does not " + f"contain a valid entry the {subshell} subshell " + f"of {element}. Please select a different database." + ) + + with h5py.File(self.gos_file_path, "r") as h: + conventions = h["metadata/edges_info"] + if subshell not in conventions: + raise ValueError(error_message) + table = conventions[subshell].attrs["table"] + self.subshell_factor = conventions[subshell].attrs["occupancy_ratio"] + stem = f"/{element}/{table}" + if stem not in h: + raise ValueError(error_message) + gos_group = h[stem] + gos = gos_group["data"][:] + q = gos_group["q"][:] + free_energies = gos_group["free_energies"][:] + doi = h["/metadata/data_ref"].attrs["data_doi"] + + gos = np.squeeze(gos.T) + self.doi = doi + self.gos_array = gos + self.qaxis = q + self.rel_energy_axis = free_energies - min(free_energies) + self.energy_axis = self.rel_energy_axis + self.onset_energy diff --git a/exspy/models/eelsmodel.py b/exspy/models/eelsmodel.py index b6b6a8d8d..b1b590e99 100644 --- a/exspy/models/eelsmodel.py +++ b/exspy/models/eelsmodel.py @@ -75,6 +75,7 @@ def __init__( Parameters ---------- + GOS : Generalized Oscillator Strength, availiable option in ['hydrogenic', 'gosh', 'Dirac', 'Hartree-Slater'], default is 'gosh'. spectrum : a EELSSpectrum instance %s diff --git a/exspy/signals/eels.py b/exspy/signals/eels.py index 4dbf0bcc2..67e372c4f 100644 --- a/exspy/signals/eels.py +++ b/exspy/signals/eels.py @@ -1635,6 +1635,7 @@ def create_model( Parameters ---------- %s + GOS: Generalized Oscillator Strength, availiable option in ['hydrogenic', 'gosh', 'Dirac', 'Hartree-Slater'], default is 'gosh' Returns ------- diff --git a/exspy/tests/misc/test_gos.py b/exspy/tests/misc/test_gos.py index dccb8bc0c..06b157046 100644 --- a/exspy/tests/misc/test_gos.py +++ b/exspy/tests/misc/test_gos.py @@ -24,6 +24,7 @@ from exspy._defaults_parser import preferences from exspy.misc.eels.gosh_gos import GoshGOS +from exspy.misc.eels.dirac_gos import DiracGOS from exspy.misc.eels.hartree_slater_gos import HartreeSlaterGOS from exspy.misc.eels import HydrogenicGOS from exspy.misc.elements import elements @@ -80,3 +81,24 @@ def test_binding_energy_database(): # These elements are not in the database if element not in ["Bk", "Cf", "Cm", "metadata"]: assert "Binding_energies" in elements[element]["Atomic_properties"].keys() + +def test_dirac_gosh_not_in_conventions(): + gos = DiracGOS("Ti_L2") + gos.subshell = "L234" + with pytest.raises(ValueError): + gos.read_gos_data() + + +def test_dirac_gosh_not_in_file(): + # Use version 1.0 which doesn't have the Ac element + with pytest.raises(ValueError): + _ = DiracGOS("Ac_L3", gos_file_path=GOSH10) + + +def test_dirac_binding_energy_database(): + gos = DiracGOS("Ti_L3") + gosh15 = h5py.File(gos.gos_file_path) + for element in gosh15.keys(): + # These elements are not in the database + if element not in ["Bk", "Cf", "Cm", "metadata"]: + assert "Binding_energies" in elements[element]["Atomic_properties"].keys() From e765f2b2eafaa2d6fad3e7887e656222aed6aef3 Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Tue, 16 Jul 2024 22:12:23 +0200 Subject: [PATCH 02/27] remove test as the database has more elements than the dict --- exspy/tests/misc/test_gos.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/exspy/tests/misc/test_gos.py b/exspy/tests/misc/test_gos.py index 06b157046..d74e750f5 100644 --- a/exspy/tests/misc/test_gos.py +++ b/exspy/tests/misc/test_gos.py @@ -90,15 +90,6 @@ def test_dirac_gosh_not_in_conventions(): def test_dirac_gosh_not_in_file(): - # Use version 1.0 which doesn't have the Ac element + # Dirac GOS which doesn't have the Uue element with pytest.raises(ValueError): - _ = DiracGOS("Ac_L3", gos_file_path=GOSH10) - - -def test_dirac_binding_energy_database(): - gos = DiracGOS("Ti_L3") - gosh15 = h5py.File(gos.gos_file_path) - for element in gosh15.keys(): - # These elements are not in the database - if element not in ["Bk", "Cf", "Cm", "metadata"]: - assert "Binding_energies" in elements[element]["Atomic_properties"].keys() + _ = DiracGOS("Uue_L3") \ No newline at end of file From 7c4d4b9cd5be5071c535c26fcb0128b5ba1e20a5 Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Tue, 16 Jul 2024 22:17:04 +0200 Subject: [PATCH 03/27] fix rst format --- doc/user_guide/eels.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/user_guide/eels.rst b/doc/user_guide/eels.rst index cdd54fd15..380cb9ac0 100644 --- a/doc/user_guide/eels.rst +++ b/doc/user_guide/eels.rst @@ -274,7 +274,7 @@ The model for the GOS can be specified with the ``GOS`` argument By default, a freely usable tabulated dataset, in `gosh `__ format, is downloaded from Zenodo: `doi:10.5281/zenodo.7645765 `_. -As alternative, one can use the `Dirac GOS `__ to include the relativistic effects, which is downloaded from Zenodo: `doi:10.5281/zenodo.12751756 `_ and also follows the `gosh` format. +As an alternative, one can use the `Dirac GOS `_ to include the relativistic effects. It can be downloaded from Zenodo: `doi:10.5281/zenodo.12751756 `_ and also follows the `gosh` format. Custom GOS saved in the `gosh `__ format can be used, the following example download a previous version (1.0) of the GOS file from Zenodo From 8f177319aa08f37b4207b944e1f412b573bc97f5 Mon Sep 17 00:00:00 2001 From: Zezhong Date: Mon, 22 Jul 2024 16:56:04 +0200 Subject: [PATCH 04/27] use the registry in GoshGOS to support Dirac GOS --- doc/user_guide/eels.rst | 2 +- examples/model_fitting/EELS_curve_fitting.py | 2 +- exspy/components/eels_cl_edge.py | 31 ++--- exspy/docstrings/model.py | 10 +- exspy/misc/eels/__init__.py | 3 +- exspy/misc/eels/dirac_gos.py | 137 ------------------- exspy/misc/eels/gosh_gos.py | 29 +++- exspy/models/eelsmodel.py | 8 +- exspy/signals/eels.py | 7 +- exspy/tests/misc/test_gos.py | 5 +- exspy/tests/models/test_eelsmodel.py | 2 +- 11 files changed, 58 insertions(+), 178 deletions(-) delete mode 100644 exspy/misc/eels/dirac_gos.py diff --git a/doc/user_guide/eels.rst b/doc/user_guide/eels.rst index 380cb9ac0..db9ee74f3 100644 --- a/doc/user_guide/eels.rst +++ b/doc/user_guide/eels.rst @@ -274,7 +274,7 @@ The model for the GOS can be specified with the ``GOS`` argument By default, a freely usable tabulated dataset, in `gosh `__ format, is downloaded from Zenodo: `doi:10.5281/zenodo.7645765 `_. -As an alternative, one can use the `Dirac GOS `_ to include the relativistic effects. It can be downloaded from Zenodo: `doi:10.5281/zenodo.12751756 `_ and also follows the `gosh` format. +As an alternative, one can use the `Dirac GOS `_ to include the relativistic effects using the Dirac solution, which can be downloaded from Zenodo: `doi:10.5281/zenodo.12751756 `_. Custom GOS saved in the `gosh `__ format can be used, the following example download a previous version (1.0) of the GOS file from Zenodo diff --git a/examples/model_fitting/EELS_curve_fitting.py b/examples/model_fitting/EELS_curve_fitting.py index cca37f979..783fe9db3 100644 --- a/examples/model_fitting/EELS_curve_fitting.py +++ b/examples/model_fitting/EELS_curve_fitting.py @@ -24,7 +24,7 @@ m.plot() # one can also use the Dirac GOS by specifying the GOS parameter -m = s.create_model(low_loss=ll, GOS="Dirac") +m = s.create_model(low_loss=ll, GOS="dirac") m.enable_fine_structure() m.multifit(kind="smart") m.plot() diff --git a/exspy/components/eels_cl_edge.py b/exspy/components/eels_cl_edge.py index aad155660..521d6f5b8 100644 --- a/exspy/components/eels_cl_edge.py +++ b/exspy/components/eels_cl_edge.py @@ -25,8 +25,7 @@ from scipy.interpolate import splev from hyperspy.component import Component -from exspy.misc.eels.gosh_gos import GoshGOS, _GOSH_DOI -from exspy.misc.eels.dirac_gos import DiracGOS +from exspy.misc.eels.gosh_gos import GoshGOS, DFT_GOSH from exspy.misc.eels.hartree_slater_gos import HartreeSlaterGOS from exspy.misc.eels.hydrogenic_gos import HydrogenicGOS from exspy.misc.eels.effective_angle import effective_angle @@ -77,7 +76,7 @@ class EELSCLEdge(Component): The preferred option is to use a database of cross sections in GOSH format. One such database can be freely downloaded from Zenodo at: https://doi.org/%s while information on the GOSH format - are available at: https://gitlab.com/gguzzina/gosh . + are available at: https://gitlab.com/gguzzina/gosh. eXSpy also supports Peter Rez's Hartree Slater cross sections parametrised as distributed by Gatan in their Digital Micrograph (DM) @@ -93,11 +92,11 @@ class EELSCLEdge(Component): Usually a string, for example, ``'Ti_L3'`` for the GOS of the titanium L3 subshell. If a dictionary is passed, it is assumed that Hartree Slater GOS was exported using `GOS.as_dictionary`, and will be reconstructed. - GOS : ``'gosh'``,``'Dirac'``, ``'hydrogenic'``, ``'Hartree-Slater'`` or str - The GOS to use. Default is ``'gosh'``. If str, it must the path to gosh - GOS file. + GOS : ``'dft'``,``'dirac'``, ``'hydrogenic'``, ``'Hartree-Slater'`` or str + The GOS to use. Default is ``'dft'``. If str, it must the path to gosh GOS file. + The ``'dft'`` and ``'dirac'`` databases are in the ``'gosh'`` format. gos_file_path : str, None - Only with ``GOS='gosh'``. Specify the file path of the gosh file + Only with ``GOS='dft' or 'dirac'``. Specify the file path of the gosh file to use. If None, use the file from https://doi.org/%s Attributes @@ -147,7 +146,7 @@ class EELSCLEdge(Component): _fine_structure_coeff_free = True _fine_structure_spline_active = True - def __init__(self, element_subshell, GOS="gosh", gos_file_path=None): + def __init__(self, element_subshell, GOS="dft", gos_file_path=None): # Declare the parameters self.fine_structure_components = FSet(component=self) Component.__init__( @@ -168,17 +167,17 @@ def __init__(self, element_subshell, GOS="gosh", gos_file_path=None): self.fine_structure_coeff.ext_force_positive = False self.GOS = None - if GOS == "gosh": - self.GOS = GoshGOS(element_subshell, gos_file_path=gos_file_path) - elif GOS == "Dirac": - self.GOS = DiracGOS(element_subshell,gos_file_path=gos_file_path) + if GOS == "dft": + self.GOS = GoshGOS(element_subshell, gos_file_path=gos_file_path, source="dft") + elif GOS == "dirac": + self.GOS = GoshGOS(element_subshell,gos_file_path=gos_file_path, source="dirac") elif GOS == "Hartree-Slater": # pragma: no cover self.GOS = HartreeSlaterGOS(element_subshell) elif GOS == "hydrogenic": self.GOS = HydrogenicGOS(element_subshell) else: raise ValueError( - "GOS must be one of 'gosh', 'Dirac','hydrogenic' or 'Hartree-Slater'." + "GOS must be one of 'dft', 'dirac','hydrogenic' or 'Hartree-Slater'." ) self.onset_energy.value = self.GOS.onset_energy self.onset_energy.free = False @@ -190,9 +189,9 @@ def __init__(self, element_subshell, GOS="gosh", gos_file_path=None): self.intensity.bmax = None self._whitelist["GOS"] = ("init", GOS) - if GOS == "gosh": + if GOS == "dft": self._whitelist["element_subshell"] = ("init", self.GOS.as_dictionary(True)) - elif GOS == "Dirac": + elif GOS == "dirac": self._whitelist["element_subshell"] = ("init", self.GOS.as_dictionary(True)) elif GOS == "Hartree-Slater": # pragma: no cover self._whitelist["element_subshell"] = ("init", self.GOS.as_dictionary(True)) @@ -540,4 +539,4 @@ def as_dictionary(self, fullcopy=True): return dic -EELSCLEdge.__doc__ %= (_GOSH_DOI, _GOSH_DOI) +EELSCLEdge.__doc__ %= (DFT_GOSH['DOI'], DFT_GOSH['DOI']) diff --git a/exspy/docstrings/model.py b/exspy/docstrings/model.py index 7f9465845..27c5465a5 100644 --- a/exspy/docstrings/model.py +++ b/exspy/docstrings/model.py @@ -19,14 +19,14 @@ """Common docstring snippets for model.""" -from exspy.misc.eels.gosh_gos import _GOSH_DOI +from exspy.misc.eels.gosh_gos import GOSH_SOURCES -GOS_PARAMETER = """GOS : 'hydrogenic', 'gosh', 'Dirac', 'Hartree-Slater'. - The GOS to use. Default is ``'gosh'``. +GOS_PARAMETER = """GOS : 'hydrogenic', 'dft', 'dirac', 'Hartree-Slater'. + The GOS to use. Default is ``'dft'``. gos_file_path : str, None - Only with GOS='gosh' or 'Dirac'. Specify the file path of the gosh file - to use. If None, use the file from doi:{}""".format(_GOSH_DOI) + Only with GOS='dft' or 'dirac'. Specify the file path of the gosh file + to use. If None, use the file from doi:{}""".format(GOSH_SOURCES['dft']['DOI']) EELSMODEL_PARAMETERS = """ll : None or EELSSpectrum If an EELSSpectrum is provided, it will be assumed that it is diff --git a/exspy/misc/eels/__init__.py b/exspy/misc/eels/__init__.py index 3dd45ad3b..76a0d5eb9 100644 --- a/exspy/misc/eels/__init__.py +++ b/exspy/misc/eels/__init__.py @@ -1,6 +1,5 @@ from exspy.misc.eels.hydrogenic_gos import HydrogenicGOS from exspy.misc.eels.gosh_gos import GoshGOS -from exspy.misc.eels.dirac_gos import DiracGOS from exspy.misc.eels.hartree_slater_gos import HartreeSlaterGOS -__all__ = ["HydrogenicGOS", "GoshGOS", "DiracGOS", "HartreeSlaterGOS"] +__all__ = ["HydrogenicGOS", "GoshGOS", "HartreeSlaterGOS"] diff --git a/exspy/misc/eels/dirac_gos.py b/exspy/misc/eels/dirac_gos.py deleted file mode 100644 index cfcea99e2..000000000 --- a/exspy/misc/eels/dirac_gos.py +++ /dev/null @@ -1,137 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2007-2024 The eXSpy developers -# -# This file is part of eXSpy. -# -# eXSpy is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# eXSpy is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with eXSpy. If not, see . - -import logging - -import h5py -import numpy as np -import pooch -from scipy import constants - -from hyperspy.defaults_parser import preferences -from exspy.misc.eels.base_gos import TabulatedGOS - - -_logger = logging.getLogger(__name__) - -R = constants.value("Rydberg constant times hc in eV") -a0 = constants.value("Bohr radius") - -_Dirac_GOSH_DOI = "10.5281/zenodo.12752410" -_Dirac_GOSH_URL = f"doi:{_Dirac_GOSH_DOI}/Dirac_GOS.gosh" -_Dirac_GOSH_KNOWN_HASH = "md5:02fb22ab55e39e51eb03c08dbf699545" - - -class DiracGOS(TabulatedGOS): - """Read Generalized Oscillator Strength from a Dirac GOSH database. - - Parameters - ---------- - element_subshell : {str, dict} - Usually a string, for example, 'Ti_L3' for the GOS of the titanium L3 - subshell. If a dictionary is passed, it is assumed that a GOSH GOS was - exported using `GOS.as_dictionary`, and will be reconstructed. - - Methods - ------- - readgosarray() - Read the GOS files of the element subshell from the location - defined in Preferences. - get_qaxis_and_gos(ienergy, qmin, qmax) - given the energy axis index and qmin and qmax values returns - the qaxis and gos between qmin and qmax using linear - interpolation to include qmin and qmax in the range. - - Attributes - ---------- - energy_axis : array - The tabulated energy axis - qaxis : array - The tabulated qaxis - energy_onset: float - The energy onset for the given element subshell as obtained - from iternal tables. - - """ - - _name = "gosh" - _whitelist = { - "gos_array": None, - "rel_energy_axis": None, - "qaxis": None, - "element": None, - "subshell": None, - "subshell_factor": None, - } - - def __init__(self, element_subshell, gos_file_path=None): - """ - Parameters - ---------- - element_subshell : str - For example, 'Ti_L3' for the GOS of the titanium L3 subshell - gos_file_path : str - The path of the gosh file to use. - """ - - if gos_file_path is None: - gos_file_path = pooch.retrieve( - url=_Dirac_GOSH_URL, - known_hash=_Dirac_GOSH_KNOWN_HASH, - progressbar=preferences.General.show_progressbar, - ) - self.gos_file_path = gos_file_path - super().__init__(element_subshell=element_subshell) - - def read_gos_data(self): - _logger.info( - "GOSH precomputed GOS\n" - f"\tElement: {self.element} " - f"\tSubshell: {self.subshell}" - f"\tOnset Energy = {self.onset_energy}" - ) - element = self.element - subshell = self.subshell - - error_message = ( - "The GOSH Parametrized GOS database does not " - f"contain a valid entry the {subshell} subshell " - f"of {element}. Please select a different database." - ) - - with h5py.File(self.gos_file_path, "r") as h: - conventions = h["metadata/edges_info"] - if subshell not in conventions: - raise ValueError(error_message) - table = conventions[subshell].attrs["table"] - self.subshell_factor = conventions[subshell].attrs["occupancy_ratio"] - stem = f"/{element}/{table}" - if stem not in h: - raise ValueError(error_message) - gos_group = h[stem] - gos = gos_group["data"][:] - q = gos_group["q"][:] - free_energies = gos_group["free_energies"][:] - doi = h["/metadata/data_ref"].attrs["data_doi"] - - gos = np.squeeze(gos.T) - self.doi = doi - self.gos_array = gos - self.qaxis = q - self.rel_energy_axis = free_energies - min(free_energies) - self.energy_axis = self.rel_energy_axis + self.onset_energy diff --git a/exspy/misc/eels/gosh_gos.py b/exspy/misc/eels/gosh_gos.py index 74f355df6..6d503ce08 100644 --- a/exspy/misc/eels/gosh_gos.py +++ b/exspy/misc/eels/gosh_gos.py @@ -32,9 +32,21 @@ R = constants.value("Rydberg constant times hc in eV") a0 = constants.value("Bohr radius") -_GOSH_DOI = "10.5281/zenodo.7645765" -_GOSH_URL = f"doi:{_GOSH_DOI}/Segger_Guzzinati_Kohl_1.5.0.gosh" -_GOSH_KNOWN_HASH = "md5:7fee8891c147a4f769668403b54c529b" +DFT_GOSH = { + "DOI": "10.5281/zenodo.7645765", + "URL": "doi:10.5281/zenodo.7645765/Segger_Guzzinati_Kohl_1.5.0.gosh", + "KNOWN_HASH": "md5:7fee8891c147a4f769668403b54c529b" +} +DIRAC_GOSH = { + "DOI": "10.5281/zenodo.12752410", + "URL": "doi:10.5281/zenodo.12752410/Dirac_GOS.gosh", + "KNOWN_HASH": "md5:02fb22ab55e39e51eb03c08dbf699545" +} +GOSH_SOURCES = { + "dft": DFT_GOSH, + "dirac": DIRAC_GOSH +} + class GoshGOS(TabulatedGOS): @@ -79,7 +91,7 @@ class GoshGOS(TabulatedGOS): "subshell_factor": None, } - def __init__(self, element_subshell, gos_file_path=None): + def __init__(self, element_subshell, gos_file_path=None, source="dft"): """ Parameters ---------- @@ -87,12 +99,17 @@ def __init__(self, element_subshell, gos_file_path=None): For example, 'Ti_L3' for the GOS of the titanium L3 subshell gos_file_path : str The path of the gosh file to use. + source : str + The source of the GOS data. Options are 'dft' or 'dirac'. """ if gos_file_path is None: + source = source.lower() + assert source in GOSH_SOURCES.keys(), f"Invalid source: {source}" + self._name = source gos_file_path = pooch.retrieve( - url=_GOSH_URL, - known_hash=_GOSH_KNOWN_HASH, + url=GOSH_SOURCES[source]["URL"], + known_hash=GOSH_SOURCES[source]["KNOWN_HASH"], progressbar=preferences.General.show_progressbar, ) self.gos_file_path = gos_file_path diff --git a/exspy/models/eelsmodel.py b/exspy/models/eelsmodel.py index b1b590e99..a2bf594e9 100644 --- a/exspy/models/eelsmodel.py +++ b/exspy/models/eelsmodel.py @@ -67,15 +67,16 @@ def __init__( auto_background=True, auto_add_edges=True, low_loss=None, - GOS="gosh", + GOS="dft", dictionary=None, + gos_file_path=None, ): """ Build an EELS model. Parameters ---------- - GOS : Generalized Oscillator Strength, availiable option in ['hydrogenic', 'gosh', 'Dirac', 'Hartree-Slater'], default is 'gosh'. + GOS : Generalized Oscillator Strength, availiable option in ['hydrogenic', 'dft', 'dirac', 'Hartree-Slater'], default is 'dft'. spectrum : a EELSSpectrum instance %s @@ -95,6 +96,7 @@ def __init__( self.convolution_axis = None self.low_loss = low_loss self.GOS = GOS + self.gos_file_path = gos_file_path self.edges = [] self._background_components = [] self._whitelist.update( @@ -411,7 +413,7 @@ def _add_edges_from_subshells_names(self, e_shells=None): if e_shells is None: e_shells = list(self.signal.subshells) e_shells.sort() - master_edge = EELSCLEdge(e_shells.pop(), self.GOS) + master_edge = EELSCLEdge(e_shells.pop(), self.GOS, gos_file_path=self.gos_file_path) # If self.GOS was None, the GOS is set by eels_cl_edge so # we reassing the value of self.GOS self.GOS = master_edge.GOS._name diff --git a/exspy/signals/eels.py b/exspy/signals/eels.py index 67e372c4f..5f2097d43 100644 --- a/exspy/signals/eels.py +++ b/exspy/signals/eels.py @@ -1626,7 +1626,7 @@ def create_model( low_loss=None, auto_background=True, auto_add_edges=True, - GOS="gosh", + GOS="dft", gos_file_path=None, dictionary=None, ): @@ -1635,7 +1635,7 @@ def create_model( Parameters ---------- %s - GOS: Generalized Oscillator Strength, availiable option in ['hydrogenic', 'gosh', 'Dirac', 'Hartree-Slater'], default is 'gosh' + GOS: Generalized Oscillator Strength, availiable option in ['hydrogenic', 'dft', 'dirac', 'Hartree-Slater'], default is 'dft' Returns ------- @@ -1659,8 +1659,9 @@ def create_model( low_loss=low_loss, auto_background=auto_background, auto_add_edges=auto_add_edges, - GOS=GOS, + GOS=GOS.lower(), dictionary=dictionary, + gos_file_path=gos_file_path, ) return model diff --git a/exspy/tests/misc/test_gos.py b/exspy/tests/misc/test_gos.py index d74e750f5..09e466380 100644 --- a/exspy/tests/misc/test_gos.py +++ b/exspy/tests/misc/test_gos.py @@ -24,7 +24,6 @@ from exspy._defaults_parser import preferences from exspy.misc.eels.gosh_gos import GoshGOS -from exspy.misc.eels.dirac_gos import DiracGOS from exspy.misc.eels.hartree_slater_gos import HartreeSlaterGOS from exspy.misc.eels import HydrogenicGOS from exspy.misc.elements import elements @@ -83,7 +82,7 @@ def test_binding_energy_database(): assert "Binding_energies" in elements[element]["Atomic_properties"].keys() def test_dirac_gosh_not_in_conventions(): - gos = DiracGOS("Ti_L2") + gos = GoshGOS("Ti_L2", source="dirac") gos.subshell = "L234" with pytest.raises(ValueError): gos.read_gos_data() @@ -92,4 +91,4 @@ def test_dirac_gosh_not_in_conventions(): def test_dirac_gosh_not_in_file(): # Dirac GOS which doesn't have the Uue element with pytest.raises(ValueError): - _ = DiracGOS("Uue_L3") \ No newline at end of file + _ = GoshGOS("Uue_L3", source="dirac") \ No newline at end of file diff --git a/exspy/tests/models/test_eelsmodel.py b/exspy/tests/models/test_eelsmodel.py index e2fcd1a1e..ad8c7929b 100644 --- a/exspy/tests/models/test_eelsmodel.py +++ b/exspy/tests/models/test_eelsmodel.py @@ -72,7 +72,7 @@ def test_gos_hydrogenic(self): m.fit() def test_gos_gosh(self): - m = self.s.create_model(auto_add_edges=True, GOS="gosh") + m = self.s.create_model(auto_add_edges=True, GOS="dft") assert m["B_K"].GOS._name == "gosh" m.fit() From bfd8890a93a017908c9ac2f9381b1787497e0998 Mon Sep 17 00:00:00 2001 From: Zezhong Date: Mon, 22 Jul 2024 17:18:33 +0200 Subject: [PATCH 05/27] fix name error --- exspy/misc/eels/gosh_gos.py | 4 ++-- exspy/models/eelsmodel.py | 2 +- exspy/tests/models/test_eelsmodel.py | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/exspy/misc/eels/gosh_gos.py b/exspy/misc/eels/gosh_gos.py index 6d503ce08..a5a7a9777 100644 --- a/exspy/misc/eels/gosh_gos.py +++ b/exspy/misc/eels/gosh_gos.py @@ -81,7 +81,7 @@ class GoshGOS(TabulatedGOS): """ - _name = "gosh" + _name = "dft_gosh" _whitelist = { "gos_array": None, "rel_energy_axis": None, @@ -106,7 +106,7 @@ def __init__(self, element_subshell, gos_file_path=None, source="dft"): if gos_file_path is None: source = source.lower() assert source in GOSH_SOURCES.keys(), f"Invalid source: {source}" - self._name = source + self._name = f"{source}_gosh" gos_file_path = pooch.retrieve( url=GOSH_SOURCES[source]["URL"], known_hash=GOSH_SOURCES[source]["KNOWN_HASH"], diff --git a/exspy/models/eelsmodel.py b/exspy/models/eelsmodel.py index a2bf594e9..ad237df06 100644 --- a/exspy/models/eelsmodel.py +++ b/exspy/models/eelsmodel.py @@ -416,7 +416,7 @@ def _add_edges_from_subshells_names(self, e_shells=None): master_edge = EELSCLEdge(e_shells.pop(), self.GOS, gos_file_path=self.gos_file_path) # If self.GOS was None, the GOS is set by eels_cl_edge so # we reassing the value of self.GOS - self.GOS = master_edge.GOS._name + self.GOS = master_edge.GOS._name.split("_")[0] self.append(master_edge) element = master_edge.element while len(e_shells) > 0: diff --git a/exspy/tests/models/test_eelsmodel.py b/exspy/tests/models/test_eelsmodel.py index ad8c7929b..eb55975f4 100644 --- a/exspy/tests/models/test_eelsmodel.py +++ b/exspy/tests/models/test_eelsmodel.py @@ -27,7 +27,7 @@ import hyperspy.api as hs from exspy.misc.elements import elements_db as elements from hyperspy.decorators import lazifyTestClass -from exspy.misc.eels.gosh_gos import _GOSH_URL, _GOSH_KNOWN_HASH +from exspy.misc.eels.gosh_gos import DFT_GOSH,DIRAC_GOSH from exspy.signals import EELSSpectrum @@ -73,7 +73,7 @@ def test_gos_hydrogenic(self): def test_gos_gosh(self): m = self.s.create_model(auto_add_edges=True, GOS="dft") - assert m["B_K"].GOS._name == "gosh" + assert m["B_K"].GOS._name == "dft_gosh" m.fit() with pytest.raises(ValueError): @@ -81,8 +81,8 @@ def test_gos_gosh(self): def test_gos_file(self): gos_file_path = pooch.retrieve( - url=_GOSH_URL, - known_hash=_GOSH_KNOWN_HASH, + url=DFT_GOSH["URL"], + known_hash=DFT_GOSH["KNOWN_HASH"], ) self.s.create_model(auto_add_edges=True, gos_file_path=gos_file_path) From 9f5694e74c72fe4b655a5f474ddce14608e3a79b Mon Sep 17 00:00:00 2001 From: Zezhong Date: Mon, 22 Jul 2024 17:24:41 +0200 Subject: [PATCH 06/27] apply ruff format --- exspy/components/eels_cl_edge.py | 12 ++++++++---- exspy/docstrings/model.py | 4 +++- exspy/misc/eels/gosh_gos.py | 10 +++------- exspy/models/eelsmodel.py | 4 +++- exspy/tests/misc/test_gos.py | 3 ++- exspy/tests/models/test_eelsmodel.py | 2 +- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/exspy/components/eels_cl_edge.py b/exspy/components/eels_cl_edge.py index 521d6f5b8..5b1781e35 100644 --- a/exspy/components/eels_cl_edge.py +++ b/exspy/components/eels_cl_edge.py @@ -94,7 +94,7 @@ class EELSCLEdge(Component): GOS was exported using `GOS.as_dictionary`, and will be reconstructed. GOS : ``'dft'``,``'dirac'``, ``'hydrogenic'``, ``'Hartree-Slater'`` or str The GOS to use. Default is ``'dft'``. If str, it must the path to gosh GOS file. - The ``'dft'`` and ``'dirac'`` databases are in the ``'gosh'`` format. + The ``'dft'`` and ``'dirac'`` databases are in the ``'gosh'`` format. gos_file_path : str, None Only with ``GOS='dft' or 'dirac'``. Specify the file path of the gosh file to use. If None, use the file from https://doi.org/%s @@ -168,9 +168,13 @@ def __init__(self, element_subshell, GOS="dft", gos_file_path=None): self.GOS = None if GOS == "dft": - self.GOS = GoshGOS(element_subshell, gos_file_path=gos_file_path, source="dft") + self.GOS = GoshGOS( + element_subshell, gos_file_path=gos_file_path, source="dft" + ) elif GOS == "dirac": - self.GOS = GoshGOS(element_subshell,gos_file_path=gos_file_path, source="dirac") + self.GOS = GoshGOS( + element_subshell, gos_file_path=gos_file_path, source="dirac" + ) elif GOS == "Hartree-Slater": # pragma: no cover self.GOS = HartreeSlaterGOS(element_subshell) elif GOS == "hydrogenic": @@ -539,4 +543,4 @@ def as_dictionary(self, fullcopy=True): return dic -EELSCLEdge.__doc__ %= (DFT_GOSH['DOI'], DFT_GOSH['DOI']) +EELSCLEdge.__doc__ %= (DFT_GOSH["DOI"], DFT_GOSH["DOI"]) diff --git a/exspy/docstrings/model.py b/exspy/docstrings/model.py index 27c5465a5..0d76d0de7 100644 --- a/exspy/docstrings/model.py +++ b/exspy/docstrings/model.py @@ -26,7 +26,9 @@ gos_file_path : str, None Only with GOS='dft' or 'dirac'. Specify the file path of the gosh file - to use. If None, use the file from doi:{}""".format(GOSH_SOURCES['dft']['DOI']) + to use. If None, use the file from doi:{}""".format( + GOSH_SOURCES["dft"]["DOI"] +) EELSMODEL_PARAMETERS = """ll : None or EELSSpectrum If an EELSSpectrum is provided, it will be assumed that it is diff --git a/exspy/misc/eels/gosh_gos.py b/exspy/misc/eels/gosh_gos.py index a5a7a9777..1f66afb18 100644 --- a/exspy/misc/eels/gosh_gos.py +++ b/exspy/misc/eels/gosh_gos.py @@ -35,18 +35,14 @@ DFT_GOSH = { "DOI": "10.5281/zenodo.7645765", "URL": "doi:10.5281/zenodo.7645765/Segger_Guzzinati_Kohl_1.5.0.gosh", - "KNOWN_HASH": "md5:7fee8891c147a4f769668403b54c529b" + "KNOWN_HASH": "md5:7fee8891c147a4f769668403b54c529b", } DIRAC_GOSH = { "DOI": "10.5281/zenodo.12752410", "URL": "doi:10.5281/zenodo.12752410/Dirac_GOS.gosh", - "KNOWN_HASH": "md5:02fb22ab55e39e51eb03c08dbf699545" + "KNOWN_HASH": "md5:02fb22ab55e39e51eb03c08dbf699545", } -GOSH_SOURCES = { - "dft": DFT_GOSH, - "dirac": DIRAC_GOSH -} - +GOSH_SOURCES = {"dft": DFT_GOSH, "dirac": DIRAC_GOSH} class GoshGOS(TabulatedGOS): diff --git a/exspy/models/eelsmodel.py b/exspy/models/eelsmodel.py index ad237df06..bf2257458 100644 --- a/exspy/models/eelsmodel.py +++ b/exspy/models/eelsmodel.py @@ -413,7 +413,9 @@ def _add_edges_from_subshells_names(self, e_shells=None): if e_shells is None: e_shells = list(self.signal.subshells) e_shells.sort() - master_edge = EELSCLEdge(e_shells.pop(), self.GOS, gos_file_path=self.gos_file_path) + master_edge = EELSCLEdge( + e_shells.pop(), self.GOS, gos_file_path=self.gos_file_path + ) # If self.GOS was None, the GOS is set by eels_cl_edge so # we reassing the value of self.GOS self.GOS = master_edge.GOS._name.split("_")[0] diff --git a/exspy/tests/misc/test_gos.py b/exspy/tests/misc/test_gos.py index 09e466380..eaac1e787 100644 --- a/exspy/tests/misc/test_gos.py +++ b/exspy/tests/misc/test_gos.py @@ -81,6 +81,7 @@ def test_binding_energy_database(): if element not in ["Bk", "Cf", "Cm", "metadata"]: assert "Binding_energies" in elements[element]["Atomic_properties"].keys() + def test_dirac_gosh_not_in_conventions(): gos = GoshGOS("Ti_L2", source="dirac") gos.subshell = "L234" @@ -91,4 +92,4 @@ def test_dirac_gosh_not_in_conventions(): def test_dirac_gosh_not_in_file(): # Dirac GOS which doesn't have the Uue element with pytest.raises(ValueError): - _ = GoshGOS("Uue_L3", source="dirac") \ No newline at end of file + _ = GoshGOS("Uue_L3", source="dirac") diff --git a/exspy/tests/models/test_eelsmodel.py b/exspy/tests/models/test_eelsmodel.py index eb55975f4..de5b5b314 100644 --- a/exspy/tests/models/test_eelsmodel.py +++ b/exspy/tests/models/test_eelsmodel.py @@ -27,7 +27,7 @@ import hyperspy.api as hs from exspy.misc.elements import elements_db as elements from hyperspy.decorators import lazifyTestClass -from exspy.misc.eels.gosh_gos import DFT_GOSH,DIRAC_GOSH +from exspy.misc.eels.gosh_gos import DFT_GOSH from exspy.signals import EELSSpectrum From e48c06b76bfe70536dd61eea03a47c0c20db22db Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Tue, 23 Jul 2024 10:43:26 +0200 Subject: [PATCH 07/27] minor changes on the GOS _name and doc --- exspy/components/eels_cl_edge.py | 9 +++++---- exspy/misc/eels/gosh_gos.py | 2 +- exspy/models/eelsmodel.py | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/exspy/components/eels_cl_edge.py b/exspy/components/eels_cl_edge.py index 5b1781e35..31cd33089 100644 --- a/exspy/components/eels_cl_edge.py +++ b/exspy/components/eels_cl_edge.py @@ -25,7 +25,7 @@ from scipy.interpolate import splev from hyperspy.component import Component -from exspy.misc.eels.gosh_gos import GoshGOS, DFT_GOSH +from exspy.misc.eels.gosh_gos import GoshGOS, GOSH_SOURCES from exspy.misc.eels.hartree_slater_gos import HartreeSlaterGOS from exspy.misc.eels.hydrogenic_gos import HydrogenicGOS from exspy.misc.eels.effective_angle import effective_angle @@ -75,8 +75,9 @@ class EELSCLEdge(Component): The preferred option is to use a database of cross sections in GOSH format. One such database can be freely downloaded from Zenodo at: - https://doi.org/%s while information on the GOSH format - are available at: https://gitlab.com/gguzzina/gosh. + https://doi.org/%s while information on the GOSH format are available at: https://gitlab.com/gguzzina/gosh. Alternatively, + one can use the Dirac GOSH database to include relativistic effects, + available at: https://doi.org/%s. eXSpy also supports Peter Rez's Hartree Slater cross sections parametrised as distributed by Gatan in their Digital Micrograph (DM) @@ -543,4 +544,4 @@ def as_dictionary(self, fullcopy=True): return dic -EELSCLEdge.__doc__ %= (DFT_GOSH["DOI"], DFT_GOSH["DOI"]) +EELSCLEdge.__doc__ %= (GOSH_SOURCES['dft']["DOI"],GOSH_SOURCES['dirac']["DOI"], GOSH_SOURCES['dft']["DOI"]) diff --git a/exspy/misc/eels/gosh_gos.py b/exspy/misc/eels/gosh_gos.py index 1f66afb18..c4e8b4e45 100644 --- a/exspy/misc/eels/gosh_gos.py +++ b/exspy/misc/eels/gosh_gos.py @@ -77,7 +77,7 @@ class GoshGOS(TabulatedGOS): """ - _name = "dft_gosh" + _name = "gosh" _whitelist = { "gos_array": None, "rel_energy_axis": None, diff --git a/exspy/models/eelsmodel.py b/exspy/models/eelsmodel.py index bf2257458..545cea17e 100644 --- a/exspy/models/eelsmodel.py +++ b/exspy/models/eelsmodel.py @@ -418,7 +418,8 @@ def _add_edges_from_subshells_names(self, e_shells=None): ) # If self.GOS was None, the GOS is set by eels_cl_edge so # we reassing the value of self.GOS - self.GOS = master_edge.GOS._name.split("_")[0] + if self.GOS is None: + self.GOS = master_edge.GOS._name.split("_")[0] self.append(master_edge) element = master_edge.element while len(e_shells) > 0: From 93868342792bc17b4fab87475f709efdf7f96d82 Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Tue, 23 Jul 2024 10:45:29 +0200 Subject: [PATCH 08/27] apply ruff format --- exspy/components/eels_cl_edge.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/exspy/components/eels_cl_edge.py b/exspy/components/eels_cl_edge.py index 31cd33089..ac86db819 100644 --- a/exspy/components/eels_cl_edge.py +++ b/exspy/components/eels_cl_edge.py @@ -544,4 +544,8 @@ def as_dictionary(self, fullcopy=True): return dic -EELSCLEdge.__doc__ %= (GOSH_SOURCES['dft']["DOI"],GOSH_SOURCES['dirac']["DOI"], GOSH_SOURCES['dft']["DOI"]) +EELSCLEdge.__doc__ %= ( + GOSH_SOURCES["dft"]["DOI"], + GOSH_SOURCES["dirac"]["DOI"], + GOSH_SOURCES["dft"]["DOI"], +) From b7c4bfffd6a2bc3fa042da576b89e3aa4b10d6b4 Mon Sep 17 00:00:00 2001 From: Zezhong Date: Tue, 23 Jul 2024 11:25:48 +0200 Subject: [PATCH 09/27] add test for dirac gos --- exspy/tests/models/test_eelsmodel.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/exspy/tests/models/test_eelsmodel.py b/exspy/tests/models/test_eelsmodel.py index de5b5b314..778748ac8 100644 --- a/exspy/tests/models/test_eelsmodel.py +++ b/exspy/tests/models/test_eelsmodel.py @@ -27,7 +27,7 @@ import hyperspy.api as hs from exspy.misc.elements import elements_db as elements from hyperspy.decorators import lazifyTestClass -from exspy.misc.eels.gosh_gos import DFT_GOSH +from exspy.misc.eels.gosh_gos import DFT_GOSH, DIRAC_GOSH from exspy.signals import EELSSpectrum @@ -79,6 +79,14 @@ def test_gos_gosh(self): with pytest.raises(ValueError): self.s.create_model(auto_add_edges=True, GOS="not_a_GOS") + def test_gos_gosh_dirac(self): + m = self.s.create_model(auto_add_edges=True, GOS="dirac") + assert m["B_K"].GOS._name == "dirac_gosh" + m.fit() + + with pytest.raises(ValueError): + self.s.create_model(auto_add_edges=True, GOS="not_a_GOS") + def test_gos_file(self): gos_file_path = pooch.retrieve( url=DFT_GOSH["URL"], @@ -86,6 +94,13 @@ def test_gos_file(self): ) self.s.create_model(auto_add_edges=True, gos_file_path=gos_file_path) + def test_gos_file_dirac(self): + gos_file_path = pooch.retrieve( + url=DIRAC_GOSH["URL"], + known_hash=DIRAC_GOSH["KNOWN_HASH"], + ) + self.s.create_model(auto_add_edges=True, gos_file_path=gos_file_path, GOS="dirac") + def test_auto_add_background_true(self): m = self.s.create_model(auto_background=True) from hyperspy.components1d import PowerLaw From b9db10af2ddbf012f0ff050853c03a3afabd7069 Mon Sep 17 00:00:00 2001 From: Zezhong Date: Tue, 23 Jul 2024 11:26:53 +0200 Subject: [PATCH 10/27] apply ruff format --- exspy/tests/models/test_eelsmodel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exspy/tests/models/test_eelsmodel.py b/exspy/tests/models/test_eelsmodel.py index 778748ac8..78004619a 100644 --- a/exspy/tests/models/test_eelsmodel.py +++ b/exspy/tests/models/test_eelsmodel.py @@ -99,7 +99,9 @@ def test_gos_file_dirac(self): url=DIRAC_GOSH["URL"], known_hash=DIRAC_GOSH["KNOWN_HASH"], ) - self.s.create_model(auto_add_edges=True, gos_file_path=gos_file_path, GOS="dirac") + self.s.create_model( + auto_add_edges=True, gos_file_path=gos_file_path, GOS="dirac" + ) def test_auto_add_background_true(self): m = self.s.create_model(auto_background=True) From adb65ac3120d973b998debcfc2afaa1cf06def0e Mon Sep 17 00:00:00 2001 From: Zezhong Date: Tue, 23 Jul 2024 11:43:55 +0200 Subject: [PATCH 11/27] add gos_file_path when append subshells --- exspy/models/eelsmodel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exspy/models/eelsmodel.py b/exspy/models/eelsmodel.py index 545cea17e..b3918d308 100644 --- a/exspy/models/eelsmodel.py +++ b/exspy/models/eelsmodel.py @@ -435,7 +435,9 @@ def _add_edges_from_subshells_names(self, e_shells=None): # Add the other subshells of the same element # and couple their intensity and onset_energy to that of the # master edge - edge = EELSCLEdge(e_shells.pop(), GOS=self.GOS) + edge = EELSCLEdge( + e_shells.pop(), GOS=self.GOS, gos_file_path=self.gos_file_path + ) edge.intensity.twin = master_edge.intensity edge.onset_energy.twin = master_edge.onset_energy From b58cd02bbf3ceb763ef44f1fed6cef68f077cb8a Mon Sep 17 00:00:00 2001 From: Zezhong Date: Tue, 23 Jul 2024 11:53:09 +0200 Subject: [PATCH 12/27] add dirac gos in test_eels_cl_edge --- exspy/tests/components/test_eels_cl_edge.py | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/exspy/tests/components/test_eels_cl_edge.py b/exspy/tests/components/test_eels_cl_edge.py index 88eb9e111..2d25e2de3 100644 --- a/exspy/tests/components/test_eels_cl_edge.py +++ b/exspy/tests/components/test_eels_cl_edge.py @@ -49,3 +49,29 @@ def test_restore_EELS_model(tmp_path): s2 = hs.load(fname) m3 = s2.models.restore(model_name) np.testing.assert_allclose(m.as_signal(), m3.as_signal()) + + +def test_restore_EELS_model_dirac(tmp_path): + s = hs.load(TEST_DATA_DIR / "coreloss_spectrum.msa", signal_type="EELS") + ll = hs.load(TEST_DATA_DIR / "lowloss_spectrum.msa", signal_type="EELS") + + s.add_elements(("Mn", "O")) + s.set_microscope_parameters( + beam_energy=300, convergence_angle=24.6, collection_angle=13.6 + ) + + m = s.create_model(low_loss=ll, GOS="dirac") + m.enable_fine_structure() + m.multifit(kind="smart") + + model_name = "fit1" + m.store(model_name) + fname = tmp_path / "test_save_eelsmodel.hspy" + s.save(tmp_path / fname) + m2 = s.models.restore(model_name) + + np.testing.assert_allclose(m.as_signal(), m2.as_signal()) + + s2 = hs.load(fname) + m3 = s2.models.restore(model_name) + np.testing.assert_allclose(m.as_signal(), m3.as_signal()) From 79f2ceb7b1d11780e594b16a21f16ca05761a46a Mon Sep 17 00:00:00 2001 From: Zezhong Date: Tue, 23 Jul 2024 15:34:26 +0200 Subject: [PATCH 13/27] remove the self.GOS reset as not necessary --- exspy/models/eelsmodel.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/exspy/models/eelsmodel.py b/exspy/models/eelsmodel.py index b3918d308..accbcef6f 100644 --- a/exspy/models/eelsmodel.py +++ b/exspy/models/eelsmodel.py @@ -416,10 +416,6 @@ def _add_edges_from_subshells_names(self, e_shells=None): master_edge = EELSCLEdge( e_shells.pop(), self.GOS, gos_file_path=self.gos_file_path ) - # If self.GOS was None, the GOS is set by eels_cl_edge so - # we reassing the value of self.GOS - if self.GOS is None: - self.GOS = master_edge.GOS._name.split("_")[0] self.append(master_edge) element = master_edge.element while len(e_shells) > 0: From 155ea20e1cdec904feb86bc0d6e014d2a3fd3116 Mon Sep 17 00:00:00 2001 From: Zezhong Date: Tue, 23 Jul 2024 16:19:25 +0200 Subject: [PATCH 14/27] update the doi to the compact dirac gos --- exspy/misc/eels/gosh_gos.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exspy/misc/eels/gosh_gos.py b/exspy/misc/eels/gosh_gos.py index c4e8b4e45..631b68e98 100644 --- a/exspy/misc/eels/gosh_gos.py +++ b/exspy/misc/eels/gosh_gos.py @@ -38,9 +38,9 @@ "KNOWN_HASH": "md5:7fee8891c147a4f769668403b54c529b", } DIRAC_GOSH = { - "DOI": "10.5281/zenodo.12752410", - "URL": "doi:10.5281/zenodo.12752410/Dirac_GOS.gosh", - "KNOWN_HASH": "md5:02fb22ab55e39e51eb03c08dbf699545", + "DOI": "10.5281/zenodo.12800856", + "URL": "doi:10.5281/zenodo.12800856/Dirac_GOS_compact.gosh", + "KNOWN_HASH": "md5:01a855d3750d2c063955248358dbee8d", } GOSH_SOURCES = {"dft": DFT_GOSH, "dirac": DIRAC_GOSH} From 118aa786594f7f63d68516b242551e17932e40ff Mon Sep 17 00:00:00 2001 From: Zezhong Date: Tue, 23 Jul 2024 17:02:58 +0200 Subject: [PATCH 15/27] add changelog --- CHANGES.rst | 12 ++++++++++++ upcoming_changes/72.new.rst | 4 ++++ 2 files changed, 16 insertions(+) create mode 100644 upcoming_changes/72.new.rst diff --git a/CHANGES.rst b/CHANGES.rst index 9046db862..f112b1b3c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,6 +9,18 @@ https://exspy.readthedocs.io/en/latest/changes.html .. towncrier release notes start +0.2.2 (2024-07-23) +================== + +New features +------------ + +- 5678.new.rst + ============ + + Support for [Dirac GOS](https://zenodo.org/records/12800856) in the gosh format for EELS quantification, which includes the relativistic effects (e.g. spin-orbit coupling) based on Dirac equation. (`#72 `_) + + 0.2.1 (2024-07-12) ================== diff --git a/upcoming_changes/72.new.rst b/upcoming_changes/72.new.rst new file mode 100644 index 000000000..63f5eb220 --- /dev/null +++ b/upcoming_changes/72.new.rst @@ -0,0 +1,4 @@ +5678.new.rst +============ + +Support for [Dirac GOS](https://zenodo.org/records/12800856) in the gosh format for EELS quantification, which includes the relativistic effects (e.g. spin-orbit coupling) based on Dirac equation. \ No newline at end of file From c13bfa87553331d01aef2acff97ddaa680a3f5ad Mon Sep 17 00:00:00 2001 From: Zezhong Date: Tue, 23 Jul 2024 17:11:46 +0200 Subject: [PATCH 16/27] update link in the doc and add example --- doc/user_guide/eels.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/user_guide/eels.rst b/doc/user_guide/eels.rst index db9ee74f3..ddfbfcb2e 100644 --- a/doc/user_guide/eels.rst +++ b/doc/user_guide/eels.rst @@ -274,7 +274,12 @@ The model for the GOS can be specified with the ``GOS`` argument By default, a freely usable tabulated dataset, in `gosh `__ format, is downloaded from Zenodo: `doi:10.5281/zenodo.7645765 `_. -As an alternative, one can use the `Dirac GOS `_ to include the relativistic effects using the Dirac solution, which can be downloaded from Zenodo: `doi:10.5281/zenodo.12751756 `_. +As an alternative, one can use the `Dirac GOS `_ to include the relativistic effects using the Dirac solution, which can be downloaded from Zenodo: `doi:10.5281/zenodo.12800856 `_. The Dirac GOS can be used as follows: + +.. code-block:: python + + >>> m = s.create_model(ll=ll, GOS="Dirac") + Custom GOS saved in the `gosh `__ format can be used, the following example download a previous version (1.0) of the GOS file from Zenodo From 4ad86344923d1fc9a7efd43fd9f0512561c56889 Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Tue, 23 Jul 2024 22:12:55 +0200 Subject: [PATCH 17/27] remove extra title in the changelog --- CHANGES.rst | 5 +---- upcoming_changes/72.new.rst | 3 --- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index f112b1b3c..d04157f5e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -15,10 +15,7 @@ https://exspy.readthedocs.io/en/latest/changes.html New features ------------ -- 5678.new.rst - ============ - - Support for [Dirac GOS](https://zenodo.org/records/12800856) in the gosh format for EELS quantification, which includes the relativistic effects (e.g. spin-orbit coupling) based on Dirac equation. (`#72 `_) +- Support for [Dirac GOS](https://zenodo.org/records/12800856) in the gosh format for EELS quantification, which includes the relativistic effects (e.g. spin-orbit coupling) based on Dirac equation. (`#72 `_) 0.2.1 (2024-07-12) diff --git a/upcoming_changes/72.new.rst b/upcoming_changes/72.new.rst index 63f5eb220..b647a7983 100644 --- a/upcoming_changes/72.new.rst +++ b/upcoming_changes/72.new.rst @@ -1,4 +1 @@ -5678.new.rst -============ - Support for [Dirac GOS](https://zenodo.org/records/12800856) in the gosh format for EELS quantification, which includes the relativistic effects (e.g. spin-orbit coupling) based on Dirac equation. \ No newline at end of file From 47a7e7c019568a6f4df57b608995f87ee58d7251 Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Wed, 24 Jul 2024 10:55:28 +0200 Subject: [PATCH 18/27] Update upcoming_changes/72.new.rst Co-authored-by: Eric Prestat --- upcoming_changes/72.new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upcoming_changes/72.new.rst b/upcoming_changes/72.new.rst index b647a7983..735cb482b 100644 --- a/upcoming_changes/72.new.rst +++ b/upcoming_changes/72.new.rst @@ -1 +1 @@ -Support for [Dirac GOS](https://zenodo.org/records/12800856) in the gosh format for EELS quantification, which includes the relativistic effects (e.g. spin-orbit coupling) based on Dirac equation. \ No newline at end of file +Support for `Dirac GOS `_ in the gosh format for EELS quantification, which includes the relativistic effects (e.g. spin-orbit coupling) based on Dirac equation. \ No newline at end of file From 720075a49e912c117c23c065839ac438614f53d4 Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Wed, 24 Jul 2024 10:55:38 +0200 Subject: [PATCH 19/27] Update CHANGES.rst Co-authored-by: Eric Prestat --- CHANGES.rst | 9 --------- 1 file changed, 9 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index d04157f5e..9046db862 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,15 +9,6 @@ https://exspy.readthedocs.io/en/latest/changes.html .. towncrier release notes start -0.2.2 (2024-07-23) -================== - -New features ------------- - -- Support for [Dirac GOS](https://zenodo.org/records/12800856) in the gosh format for EELS quantification, which includes the relativistic effects (e.g. spin-orbit coupling) based on Dirac equation. (`#72 `_) - - 0.2.1 (2024-07-12) ================== From dc71ae19cab246660c030c4df9520004c42bc32e Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Wed, 24 Jul 2024 11:02:37 +0200 Subject: [PATCH 20/27] Update exspy/components/eels_cl_edge.py redirect "gosh" to "dft" to avoid the name breaking Co-authored-by: Eric Prestat --- exspy/components/eels_cl_edge.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/exspy/components/eels_cl_edge.py b/exspy/components/eels_cl_edge.py index ac86db819..0e025a090 100644 --- a/exspy/components/eels_cl_edge.py +++ b/exspy/components/eels_cl_edge.py @@ -168,6 +168,14 @@ def __init__(self, element_subshell, GOS="dft", gos_file_path=None): self.fine_structure_coeff.ext_force_positive = False self.GOS = None + if GOS == "gosh": + warnings.warn( + "The value 'gosh' of the `GOS` parameter has been renamed to 'dft' in " + "eXSpy 0.3.0, use `GOS='dft'` instead. " + "Using `GOS='gosh'` will stop working in eXSpy 1.0.", + VisibleDeprecationWarning, + ) + GOS = "dft" if GOS == "dft": self.GOS = GoshGOS( element_subshell, gos_file_path=gos_file_path, source="dft" From fe6a99b3504f5c6c8eff22292261f5d323532e82 Mon Sep 17 00:00:00 2001 From: Zezhong Date: Wed, 24 Jul 2024 11:10:25 +0200 Subject: [PATCH 21/27] import warnings --- exspy/components/eels_cl_edge.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exspy/components/eels_cl_edge.py b/exspy/components/eels_cl_edge.py index 0e025a090..56f4eb965 100644 --- a/exspy/components/eels_cl_edge.py +++ b/exspy/components/eels_cl_edge.py @@ -19,6 +19,7 @@ import functools import logging +import warnings import math import numpy as np @@ -30,7 +31,7 @@ from exspy.misc.eels.hydrogenic_gos import HydrogenicGOS from exspy.misc.eels.effective_angle import effective_angle from hyperspy.ui_registry import add_gui_method - +from hyperspy.exceptions import VisibleDeprecationWarning _logger = logging.getLogger(__name__) @@ -169,7 +170,7 @@ def __init__(self, element_subshell, GOS="dft", gos_file_path=None): self.GOS = None if GOS == "gosh": - warnings.warn( + warnings.warn( "The value 'gosh' of the `GOS` parameter has been renamed to 'dft' in " "eXSpy 0.3.0, use `GOS='dft'` instead. " "Using `GOS='gosh'` will stop working in eXSpy 1.0.", From 971ef5be10c8475740f589e434181100fd64e5a9 Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Wed, 24 Jul 2024 19:42:25 +0200 Subject: [PATCH 22/27] test gosh redirect --- exspy/tests/models/test_eelsmodel.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/exspy/tests/models/test_eelsmodel.py b/exspy/tests/models/test_eelsmodel.py index 78004619a..07bde06db 100644 --- a/exspy/tests/models/test_eelsmodel.py +++ b/exspy/tests/models/test_eelsmodel.py @@ -72,6 +72,14 @@ def test_gos_hydrogenic(self): m.fit() def test_gos_gosh(self): + m = self.s.create_model(auto_add_edges=True, GOS="gosh") + assert m["B_K"].GOS._name == "dft_gosh" + m.fit() + + with pytest.raises(ValueError): + self.s.create_model(auto_add_edges=True, GOS="not_a_GOS") + + def test_gos_gosh_dft(self): m = self.s.create_model(auto_add_edges=True, GOS="dft") assert m["B_K"].GOS._name == "dft_gosh" m.fit() From 5ce710bcfd2794a85f16c0d06a8314592fbecdb7 Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Sat, 27 Jul 2024 14:20:35 +0200 Subject: [PATCH 23/27] Update exspy/tests/models/test_eelsmodel.py Co-authored-by: Eric Prestat --- exspy/tests/models/test_eelsmodel.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exspy/tests/models/test_eelsmodel.py b/exspy/tests/models/test_eelsmodel.py index 07bde06db..55ce28a8c 100644 --- a/exspy/tests/models/test_eelsmodel.py +++ b/exspy/tests/models/test_eelsmodel.py @@ -72,7 +72,8 @@ def test_gos_hydrogenic(self): m.fit() def test_gos_gosh(self): - m = self.s.create_model(auto_add_edges=True, GOS="gosh") + with pytest.warns(VisibleDeprecationWarning): + m = self.s.create_model(auto_add_edges=True, GOS="gosh") assert m["B_K"].GOS._name == "dft_gosh" m.fit() From 3263d6ec29bec6dde66f74d8beb9f77354029385 Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Sat, 27 Jul 2024 14:20:42 +0200 Subject: [PATCH 24/27] Update exspy/misc/eels/gosh_gos.py Co-authored-by: Eric Prestat --- exspy/misc/eels/gosh_gos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exspy/misc/eels/gosh_gos.py b/exspy/misc/eels/gosh_gos.py index 631b68e98..e3e710ce0 100644 --- a/exspy/misc/eels/gosh_gos.py +++ b/exspy/misc/eels/gosh_gos.py @@ -102,7 +102,7 @@ def __init__(self, element_subshell, gos_file_path=None, source="dft"): if gos_file_path is None: source = source.lower() assert source in GOSH_SOURCES.keys(), f"Invalid source: {source}" - self._name = f"{source}_gosh" + self._name = source gos_file_path = pooch.retrieve( url=GOSH_SOURCES[source]["URL"], known_hash=GOSH_SOURCES[source]["KNOWN_HASH"], From ff943f78c8f7575e362867ade1180a0cacf154e7 Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Sat, 27 Jul 2024 14:22:28 +0200 Subject: [PATCH 25/27] add missing import --- exspy/tests/models/test_eelsmodel.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exspy/tests/models/test_eelsmodel.py b/exspy/tests/models/test_eelsmodel.py index 55ce28a8c..160c2528f 100644 --- a/exspy/tests/models/test_eelsmodel.py +++ b/exspy/tests/models/test_eelsmodel.py @@ -29,6 +29,7 @@ from hyperspy.decorators import lazifyTestClass from exspy.misc.eels.gosh_gos import DFT_GOSH, DIRAC_GOSH from exspy.signals import EELSSpectrum +from hyperspy.exceptions import VisibleDeprecationWarning # Dask does not always work nicely with np.errstate, From 7b84b5dfaceef4abd020bb0f43b698abac0fd231 Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Sat, 27 Jul 2024 14:32:13 +0200 Subject: [PATCH 26/27] remove GOS.lower() as Hartree-Slater has upper case --- exspy/signals/eels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exspy/signals/eels.py b/exspy/signals/eels.py index 5f2097d43..c30524307 100644 --- a/exspy/signals/eels.py +++ b/exspy/signals/eels.py @@ -1659,7 +1659,7 @@ def create_model( low_loss=low_loss, auto_background=auto_background, auto_add_edges=auto_add_edges, - GOS=GOS.lower(), + GOS=GOS, dictionary=dictionary, gos_file_path=gos_file_path, ) From c46b5d314e9f74598a07ef652a40f0bec7c6ab2e Mon Sep 17 00:00:00 2001 From: Zezhong Zhang Date: Sat, 27 Jul 2024 14:39:42 +0200 Subject: [PATCH 27/27] update gosh tests --- exspy/tests/models/test_eelsmodel.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exspy/tests/models/test_eelsmodel.py b/exspy/tests/models/test_eelsmodel.py index 160c2528f..1e8155478 100644 --- a/exspy/tests/models/test_eelsmodel.py +++ b/exspy/tests/models/test_eelsmodel.py @@ -75,7 +75,7 @@ def test_gos_hydrogenic(self): def test_gos_gosh(self): with pytest.warns(VisibleDeprecationWarning): m = self.s.create_model(auto_add_edges=True, GOS="gosh") - assert m["B_K"].GOS._name == "dft_gosh" + assert m["B_K"].GOS._name == "dft" m.fit() with pytest.raises(ValueError): @@ -83,7 +83,7 @@ def test_gos_gosh(self): def test_gos_gosh_dft(self): m = self.s.create_model(auto_add_edges=True, GOS="dft") - assert m["B_K"].GOS._name == "dft_gosh" + assert m["B_K"].GOS._name == "dft" m.fit() with pytest.raises(ValueError): @@ -91,7 +91,7 @@ def test_gos_gosh_dft(self): def test_gos_gosh_dirac(self): m = self.s.create_model(auto_add_edges=True, GOS="dirac") - assert m["B_K"].GOS._name == "dirac_gosh" + assert m["B_K"].GOS._name == "dirac" m.fit() with pytest.raises(ValueError):