Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/RELEASE_next_patch' into RELEA…
Browse files Browse the repository at this point in the history
…SE_next_minor

# Conflicts:
#	doc/user_guide/eels.rst
#	hyperspy/_components/skew_normal.py
#	hyperspy/_components/voigt.py
#	hyperspy/tests/drawing/test_plot_signal.py
  • Loading branch information
ericpre committed Sep 5, 2021
2 parents b081662 + 11f26a7 commit 8c74de8
Show file tree
Hide file tree
Showing 35 changed files with 156 additions and 117 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
os: [ubuntu, windows, macos]
PYTHON_VERSION: [3.8, 3.9]
PIP_SELECTOR: ['[all, tests]']
DEPENDENCIES_DEV: [false]
include:
# test oldest supported version of main dependencies on python 3.6
- os: ubuntu
Expand All @@ -39,13 +38,6 @@ jobs:
PIP_SELECTOR: '[all, tests, coverage]'
PYTEST_ARGS_COVERAGE: --cov=. --cov-report=xml
LABEL: -coverage
# Run test suite against dependencies development version
- os: ubuntu
PYTHON_VERSION: 3.8
PIP_SELECTOR: '[all, tests]'
LABEL: -dependencies_dev
DEPENDENCIES_DEV: true
DEPENDENCIES: numpy scipy scikit-learn scikit-image
- os: ubuntu
PYTHON_VERSION: 3.7
PIP_SELECTOR: '[all, tests]'
Expand Down Expand Up @@ -77,13 +69,6 @@ jobs:
run: |
pip install ${{ matrix.DEPENDENCIES }}
- name: Install dependencies development version
if: ${{ matrix.DEPENDENCIES_DEV }}
run: |
pip install --upgrade --no-deps --pre \
-i https://pypi.anaconda.org/scipy-wheels-nightly/simple \
${{ matrix.DEPENDENCIES }}
- name: Run test suite
run: |
pytest ${{ env.PYTEST_ARGS }} ${{ matrix.PYTEST_ARGS_COVERAGE }}
Expand Down
34 changes: 19 additions & 15 deletions doc/user_guide/eels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ more information about the edges.
+-------+-------------------+-----------+-----------------------------+
The method :py:meth:`~._signals.eels.EELSSpectrum.edges_at_energy` allows
inspecting different sections of the signal for interactive edge
identification (the default). A region can be selected by dragging the mouse
across the signal and after clicking the `Update` button, edges with onset
energies within the selected energy range will be displayed. By toggling the
edge buttons, it will put or remove the corresponding edges on the signal. When
the `Complementary edge` box is ticked, edges outside the selected range with
the same element of edges within the selected energy range will be shown as well
inspecting different sections of the signal for interactive edge
identification (the default). A region can be selected by dragging the mouse
across the signal and after clicking the `Update` button, edges with onset
energies within the selected energy range will be displayed. By toggling the
edge buttons, it will put or remove the corresponding edges on the signal. When
the `Complementary edge` box is ticked, edges outside the selected range with
the same element of edges within the selected energy range will be shown as well
to aid identification of edges.

.. code-block:: python
Expand All @@ -94,7 +94,7 @@ to aid identification of edges.
:width: 500

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


.. _eels_thickness-label:

Expand Down Expand Up @@ -260,8 +260,9 @@ We must enable them to accurately fit this spectrum.
>>> m.enable_fine_structure()
We use smart_fit instead of standard fit method because smart_fit is optimized
to fit EELS core-loss spectra
We use :py:meth:`~.models.eelsmodel.EELSModel.smart_fit` instead of standard
fit method because :py:meth:`~.models.eelsmodel.EELSModel.smart_fit` is
optimized to fit EELS core-loss spectra

.. code-block:: python
Expand All @@ -277,12 +278,15 @@ 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 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.
`m.smart_fit()` and `m.multifit(kind='smart')` are methods specific to the
EELS model. The fitting procedure acts in 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.

Other, non-EELSCLEdge components, are never deactivated, and fitted on every iteration.
Other, non-EELSCLEdge components, are never deactivated, and fitted on every
iteration.

Print the result of the fit

Expand Down
4 changes: 2 additions & 2 deletions hyperspy/_components/error_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with HyperSpy. If not, see <http://www.gnu.org/licenses/>.

from hyperspy._components.expression import Expression
from distutils.version import LooseVersion
from packaging.version import Version
import sympy


Expand Down Expand Up @@ -51,7 +51,7 @@ class Erf(Expression):

def __init__(self, A=1., sigma=1., origin=0., module=["numpy", "scipy"],
**kwargs):
if LooseVersion(sympy.__version__) < LooseVersion("1.3"):
if Version(sympy.__version__) < Version("1.3"):
raise ImportError("The `ErrorFunction` component requires "
"SymPy >= 1.3")
super().__init__(
Expand Down
6 changes: 3 additions & 3 deletions hyperspy/_components/skew_normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
# You should have received a copy of the GNU General Public License
# along with HyperSpy. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import dask.array as da
import numpy as np
from packaging.version import Version
import sympy

from hyperspy.component import _get_scaling_factor
from hyperspy._components.expression import Expression
from hyperspy.misc.utils import is_binned # remove in v2.0

from distutils.version import LooseVersion

sqrt2pi = np.sqrt(2 * np.pi)

Expand Down Expand Up @@ -139,7 +139,7 @@ class SkewNormal(Expression):

def __init__(self, x0=0., A=1., scale=1., shape=0.,
module=['numpy', 'scipy'], **kwargs):
if LooseVersion(sympy.__version__) < LooseVersion("1.3"):
if Version(sympy.__version__) < Version("1.3"):
raise ImportError("The `SkewNormal` component requires "
"SymPy >= 1.3")
# We use `_shape` internally because `shape` is already taken in sympy
Expand Down
7 changes: 4 additions & 3 deletions hyperspy/_components/voigt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
# along with HyperSpy. If not, see <http://www.gnu.org/licenses/>.

import math
import sympy
import numpy as np
from packaging.version import Version
import sympy

from hyperspy.component import _get_scaling_factor
from hyperspy._components.expression import Expression
from hyperspy._components.gaussian import _estimate_gaussian_parameters
from hyperspy.misc.utils import is_binned # remove in v2.0
from distutils.version import LooseVersion


sqrt2pi = math.sqrt(2 * math.pi)
sigma2fwhm = 2 * math.sqrt(2 * math.log(2))
Expand Down Expand Up @@ -90,7 +91,7 @@ def __init__(self, centre=10., area=1., gamma=0.2, sigma=0.1,
# Not to break scripts once we remove the legacy Voigt
if "legacy" in kwargs:
del kwargs["legacy"]
if LooseVersion(sympy.__version__) < LooseVersion("1.3"):
if Version(sympy.__version__) < Version("1.3"):
raise ImportError("The `Voigt` component requires "
"SymPy >= 1.3")
# We use `_gamma` internally to workaround the use of the `gamma`
Expand Down
5 changes: 2 additions & 3 deletions hyperspy/_signals/lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
import dask
from dask.diagnostics import ProgressBar
from itertools import product
from distutils.version import LooseVersion

from packaging.version import Version

from hyperspy.signal import BaseSignal
from hyperspy.defaults_parser import preferences
Expand Down Expand Up @@ -1165,7 +1164,7 @@ def compute_navigator(self, index=None, chunks_number=None,
# Needs to reverse the chunks list to match dask chunking order
signal_chunks = list(signal_chunks)[::-1]
navigation_chunks = ['auto'] * len(self.axes_manager.navigation_shape)
if LooseVersion(dask.__version__) >= LooseVersion("2.30.0"):
if Version(dask.__version__) >= Version("2.30.0"):
kwargs = {'balance':True}
else:
kwargs = {}
Expand Down
11 changes: 5 additions & 6 deletions hyperspy/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2014,19 +2014,18 @@ def _update_attributes(self):
self.signal_axes = self.signal_axes[::-1]
self.navigation_axes = self.navigation_axes[::-1]
self._getitem_tuple = tuple(getitem_tuple)
self.signal_dimension = len(self.signal_axes)
if len(self.signal_axes) == 1 and self.signal_axes[0].size == 1:
self.signal_dimension = 0
else:
self.signal_dimension = len(self.signal_axes)
self.navigation_dimension = len(self.navigation_axes)
if self.navigation_dimension != 0:
self.navigation_shape = tuple([
axis.size for axis in self.navigation_axes])
else:
self.navigation_shape = ()

if self.signal_dimension != 0:
self.signal_shape = tuple([
axis.size for axis in self.signal_axes])
else:
self.signal_shape = ()
self.signal_shape = tuple([axis.size for axis in self.signal_axes])
self.navigation_size = (np.cumprod(self.navigation_shape)[-1]
if self.navigation_shape else 0)
self.signal_size = (np.cumprod(self.signal_shape)[-1]
Expand Down
4 changes: 2 additions & 2 deletions hyperspy/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from traits.trait_numeric import Array
import sympy
from sympy.utilities.lambdify import lambdify
from distutils.version import LooseVersion
from packaging.version import Version
from pathlib import Path

import hyperspy
Expand Down Expand Up @@ -1206,7 +1206,7 @@ def _load_dictionary(self, dic):

if dic['_id_name'] == self._id_name:
if (self._id_name == "Polynomial" and
LooseVersion(hyperspy.__version__) >= LooseVersion("2.0")):
Version(hyperspy.__version__) >= Version("2.0")):
# in HyperSpy 2.0 the polynomial definition changed
from hyperspy._components.polynomial import convert_to_polynomial
dic = convert_to_polynomial(dic)
Expand Down
4 changes: 2 additions & 2 deletions hyperspy/drawing/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with HyperSpy. If not, see <http://www.gnu.org/licenses/>.

import math
from distutils.version import LooseVersion
from packaging.version import Version

import numpy as np
import matplotlib
Expand Down Expand Up @@ -520,7 +520,7 @@ def format_coord(x, y):
sym_log_kwargs = {'linthresh':self.linthresh,
'linscale':self.linscale,
'vmin':vmin, 'vmax':vmax}
if LooseVersion(matplotlib.__version__) >= LooseVersion("3.2"):
if Version(matplotlib.__version__) >= Version("3.2"):
sym_log_kwargs['base'] = 10
norm = SymLogNorm(**sym_log_kwargs)
elif inspect.isclass(norm) and issubclass(norm, Normalize):
Expand Down
4 changes: 2 additions & 2 deletions hyperspy/drawing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import copy
import itertools
from distutils.version import LooseVersion
from packaging.version import Version
import textwrap
import traits.api as t
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -1645,7 +1645,7 @@ def plot_histograms(signal_list,

def picker_kwargs(value, kwargs={}):
# picker is deprecated in favor of pickradius
if LooseVersion(mpl.__version__) >= LooseVersion("3.3.0"):
if Version(mpl.__version__) >= Version("3.3.0"):
kwargs.update({'pickradius': value, 'picker':True})
else:
kwargs['picker'] = value
Expand Down
4 changes: 2 additions & 2 deletions hyperspy/external/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# You should have received a copy of the GNU General Public License
# along with HyperSpy. If not, see <http://www.gnu.org/licenses/>.

from distutils.version import LooseVersion
from packaging.version import Version
from tqdm import __version__ as tqdm_version

if LooseVersion(tqdm_version) >= LooseVersion("4.36.0"):
if Version(tqdm_version) >= Version("4.36.0"):
# API change for 5.0 https://github.com/tqdm/tqdm/pull/800
from tqdm import tqdm
from tqdm.notebook import tqdm as tqdm_notebook
Expand Down
18 changes: 9 additions & 9 deletions hyperspy/io_plugins/hspy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with HyperSpy. If not, see <http://www.gnu.org/licenses/>.

from distutils.version import LooseVersion
from packaging.version import Version
import warnings
import logging
import datetime
Expand Down Expand Up @@ -101,7 +101,7 @@
not_valid_format = 'The file is not a valid HyperSpy hdf5 file'

current_file_version = None # Format version of the file being read
default_version = LooseVersion(version)
default_version = Version(version)


def get_hspy_format_version(f):
Expand All @@ -119,7 +119,7 @@ def get_hspy_format_version(f):
version = "2.0"
else:
raise IOError(not_valid_format)
return LooseVersion(version)
return Version(version)


def file_reader(filename, backing_store=False,
Expand Down Expand Up @@ -212,7 +212,7 @@ def file_reader(filename, backing_store=False,
def hdfgroup2signaldict(group, lazy=False):
global current_file_version
global default_version
if current_file_version < LooseVersion("1.2"):
if current_file_version < Version("1.2"):
metadata = "mapped_parameters"
original_metadata = "original_parameters"
else:
Expand Down Expand Up @@ -281,7 +281,7 @@ def hdfgroup2signaldict(group, lazy=False):
if '__unnamed__' == exp['metadata']['General']['title']:
exp['metadata']["General"]['title'] = ''

if current_file_version < LooseVersion("1.1"):
if current_file_version < Version("1.1"):
# Load the decomposition results written with the old name,
# mva_results
if 'mva_results' in group.keys():
Expand All @@ -305,7 +305,7 @@ def hdfgroup2signaldict(group, lazy=False):
exp['metadata']['name']
del exp['metadata']['name']

if current_file_version < LooseVersion("1.2"):
if current_file_version < Version("1.2"):
if '_internal_parameters' in exp['metadata']:
exp['metadata']['_HyperSpy'] = \
exp['metadata']['_internal_parameters']
Expand Down Expand Up @@ -391,7 +391,7 @@ def hdfgroup2signaldict(group, lazy=False):
exp["metadata"]["Signal"][key] = exp["metadata"][key]
del exp["metadata"][key]

if current_file_version < LooseVersion("3.0"):
if current_file_version < Version("3.0"):
if "Acquisition_instrument" in exp["metadata"]:
# Move tilt_stage to Stage.tilt_alpha
# Move exposure time to Detector.Camera.exposure_time
Expand Down Expand Up @@ -722,7 +722,7 @@ def write_signal(signal, group, **kwds):
"Writes a hyperspy signal to a hdf5 group"

group.attrs.update(get_object_package_info(signal))
if default_version < LooseVersion("1.2"):
if default_version < Version("1.2"):
metadata = "mapped_parameters"
original_metadata = "original_parameters"
else:
Expand All @@ -742,7 +742,7 @@ def write_signal(signal, group, **kwds):
overwrite_dataset(group, signal.data, 'data',
signal_axes=signal.axes_manager.signal_indices_in_array,
**kwds)
if default_version < LooseVersion("1.2"):
if default_version < Version("1.2"):
metadata_dict["_internal_parameters"] = \
metadata_dict.pop("_HyperSpy")
# Remove chunks from the kwds since it wouldn't have the same rank as the
Expand Down
4 changes: 2 additions & 2 deletions hyperspy/io_plugins/mrcz.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with HyperSpy. If not, see <http://www.gnu.org/licenses/>.

from distutils.version import LooseVersion
from packaging.version import Version
import mrcz as _mrcz
import logging

Expand Down Expand Up @@ -46,7 +46,7 @@

# API changes in mrcz 0.5
def _parse_metadata(metadata):
if LooseVersion(_mrcz.__version__) < LooseVersion("0.5"):
if Version(_mrcz.__version__) < Version("0.5"):
return metadata[0]
else:
return metadata
Expand Down
4 changes: 2 additions & 2 deletions hyperspy/io_plugins/tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import tifffile
import traits.api as t
import numpy as np
from distutils.version import LooseVersion
from packaging.version import Version

from hyperspy.misc import rgb_tools
from hyperspy.misc.date_time_tools import get_date_time_from_metadata
Expand Down Expand Up @@ -170,7 +170,7 @@ def _read_serie(tiff, serie, filename, force_read_resolution=False,
'formats': [dtype] * lastshape})
shape = shape[:-1]

if LooseVersion(tifffile.__version__) >= LooseVersion("2020.2.16"):
if Version(tifffile.__version__) >= Version("2020.2.16"):
op = {tag.name: tag.value for tag in page.tags}
else:
op = {key: tag.value for key, tag in page.tags.items()}
Expand Down

0 comments on commit 8c74de8

Please sign in to comment.