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
  • Loading branch information
ericpre committed Apr 27, 2023
2 parents f5203eb + e4eb9ac commit e5023ad
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 13 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ jobs:
- os: ubuntu
PYTHON_VERSION: '3.10'
PIP_SELECTOR: '[all, tests, coverage]'
- os: ubuntu
PYTHON_VERSION: '3.11'
PIP_SELECTOR: '[all, tests, coverage]'

steps:
- uses: actions/checkout@v3.3.0
Expand All @@ -54,6 +57,13 @@ jobs:
python --version
pip --version
- name: Install numba rc
if: contains(matrix.PYTHON_VERSION, '3.11')
# Require for python 3.11 support, remove when numba 0.57 is release
shell: bash
run: |
pip install numba --pre
- name: Install oldest supported version
if: ${{ matrix.OLDEST_SUPPORTED_VERSION }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion conda_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
# dask-core < 2021.3.1 doesn't have fsspec as dependency
- fsspec
- h5py
- imageio
- imageio <2.28
- ipyparallel
- ipython !=8.0.*
- jinja2
Expand Down
28 changes: 26 additions & 2 deletions hyperspy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,22 @@ def __init__(self):
The Model that the event belongs to
""", arguments=['obj'])

# The private _binned attribute is created to store temporarily
# axes.is_binned or not. This avoids evaluating it during call of
# the model function, which is detrimental to the performances of
# multifit(). Setting it to None ensures that the existing behaviour
# is preserved.
self._binned = None

def __hash__(self):
# This is needed to simulate a hashable object so that PySide does not
# raise an exception when using windows.connect
return id(self)

def __call__(self, non_convolved=False, onlyactive=False, component_list=None, binned=None):
"""Evaluate the model numerically. Implementation requested in all sub-classes"""
raise NotImplementedError

def store(self, name=None):
"""Stores current model in the original signal
Expand Down Expand Up @@ -942,7 +953,7 @@ def _model2plot(self, axes_manager, out_of_range2nans=True):
def _model_function(self, param):
self.p0 = param
self._fetch_values_from_p0()
to_return = self.__call__(non_convolved=False, onlyactive=True)
to_return = self.__call__(non_convolved=False, onlyactive=True, binned=self._binned)
return to_return

@property
Expand Down Expand Up @@ -1221,7 +1232,7 @@ def _get_variance(self, only_current=True):

def _calculate_chisq(self):
variance = self._get_variance()
d = self(onlyactive=True).ravel() - self.signal(as_numpy=True)[
d = self(onlyactive=True, binned=self._binned).ravel() - self.signal(as_numpy=True)[
np.where(self.channel_switches)]
d *= d / (1. * variance) # d = difference^2 / variance.
self.chisq.data[self.signal.axes_manager.indices[::-1]] = d.sum()
Expand Down Expand Up @@ -1902,6 +1913,10 @@ def multifit(
maxval = self.axes_manager._get_iterpath_size(masked_elements)
show_progressbar = show_progressbar and (maxval != 0)

#The _binned attribute is evaluated only once in the multifit procedure
#and stored in an instance variable
self._binned = is_binned(self.signal)

if linear_fitting:
# Check that all non-free parameters don't change accross
# the navigation dimension. If this is the case, we can fit the
Expand Down Expand Up @@ -1993,6 +2008,10 @@ def multifit(
para.map['std'] = para.std
para.map['is_set'] = True

# _binned attribute is re-set to None before early return so the
# behaviour of future fit() calls is not altered. In future
# implementation, a more elegant implementation could be found
self._binned = None
return

i = 0
Expand Down Expand Up @@ -2031,6 +2050,11 @@ def multifit(
_logger.info(f"Deleting temporary file: {autosave_fn}.npz")
os.remove(autosave_fn + ".npz")

#_binned attribute is re-set to None so the behaviour of future fit() calls
#is not altered. In future implementation, a more elegant implementation
# could be found
self._binned = None

multifit.__doc__ %= (SHOW_PROGRESSBAR_ARG)

def save_parameters2file(self, filename):
Expand Down
15 changes: 6 additions & 9 deletions hyperspy/utils/peakfinders2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ def find_local_max(z, **kwargs):
z : :py:class:`numpy.ndarray`
Array of image intensities.
**kwargs : dict
Keyword arguments to be passed to the ``peak_local_max`` method of
the ``scikit-image`` library. See its documentation for details
https://scikit-image.org/docs/dev/api/skimage.feature.html#peak-local-max
Keyword arguments to be passed to the
:py:func:`skimage.feature.peak_local_max` function.
Returns
-------
Expand Down Expand Up @@ -457,9 +456,8 @@ def find_peaks_dog(z, min_sigma=1., max_sigma=50., sigma_ratio=1.6,
z : :py:class:`numpy.ndarray`
2-d array of intensities
min_sigma, max_sigma, sigma_ratio, threshold, overlap, exclude_border :
Additional parameters to be passed to the algorithm. See `blob_dog`
documentation for details:
https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-dog
Additional parameters to be passed to the
:py:func:`skimage.feature.blob_dog` function
Returns
-------
Expand Down Expand Up @@ -502,9 +500,8 @@ def find_peaks_log(z, min_sigma=1., max_sigma=50., num_sigma=10,
z : :py:class:`numpy.ndarray`
Array of image intensities.
min_sigma, max_sigma, num_sigma, threshold, overlap, log_scale, exclude_border :
Additional parameters to be passed to the ``blob_log`` method of the
``scikit-image`` library. See its documentation for details:
https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-log
Additional parameters to be passed to the
:py:func:`skimage.feature.blob_log` function.
Returns
-------
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
'pint>=0.10',
'numexpr',
'sparse',
'imageio',
'imageio<2.28',
'pyyaml',
# prettytable and ptable are API compatible
# prettytable is maintained and ptable is an unmaintained fork
Expand Down Expand Up @@ -421,6 +421,7 @@ def __exit__(self, type, value, traceback):
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Science/Research",
Expand Down
1 change: 1 addition & 0 deletions upcoming_changes/3125.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use intersphinx links to fix links to scikit-image documentation
1 change: 1 addition & 0 deletions upcoming_changes/3126.enhancements.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve performance of `model.multifit` by avoiding `axes.is_binned` repeated evaluation
1 change: 1 addition & 0 deletions upcoming_changes/3134.maintenance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for python 3.11
1 change: 1 addition & 0 deletions upcoming_changes/3138.maintenance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pin ``imageio`` to <2.28

0 comments on commit e5023ad

Please sign in to comment.