Skip to content

Commit

Permalink
Merge pull request #694 from hakonanes/hs2-io-compat
Browse files Browse the repository at this point in the history
Adopt RosettaSciIO's plugin design
  • Loading branch information
hakonanes authored Oct 29, 2024
2 parents d69ff03 + 099349e commit b229aa8
Show file tree
Hide file tree
Showing 93 changed files with 1,522 additions and 1,496 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ Unreleased

Added
-----
- Dependency on RosettaSciIO for read/write of some file formats.
(`#? <https://github.com/pyxem/kikuchipy/pull/?>`_)

Changed
-------
- Minimum Python version is now 3.10.
(`#? <https://github.com/pyxem/kikuchipy/pull/?>`_)
(`#689 <https://github.com/pyxem/kikuchipy/pull/689>`_)

Removed
-------
Expand Down
5 changes: 5 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ def save_path_hdf5(request, tmpdir) -> Generator[Path, None, None]:
yield Path(tmpdir / f"patterns.{ext}")


@pytest.fixture()
def save_path_nordif(tmpdir) -> Generator[Path, None, None]:
yield Path(tmpdir / "nordif/save_temp.dat")


@pytest.fixture
def ni_small_axes_manager() -> Generator[dict, None, None]:
"""Axes manager for :func:`kikuchipy.data.nickel_ebsd_small`."""
Expand Down
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"pyvista": ("https://docs.pyvista.org", None),
"pyxem": ("https://pyxem.readthedocs.io/en/latest", None),
"readthedocs": ("https://docs.readthedocs.io/en/stable", None),
"rosettasciio": ("https://rosettasciio.readthedocs.io/en/stable", None),
"scipy": ("https://docs.scipy.org/doc/scipy", None),
"skimage": ("https://scikit-image.org/docs/stable", None),
"sklearn": ("https://scikit-learn.org/stable", None),
Expand Down
3 changes: 2 additions & 1 deletion doc/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ channels:
dependencies:
- pip
- python=3.11
- pandoc>=2.14.2, <4.0.0
- pandoc>=2.14.2, <4.0.0
- ipykernel
2 changes: 1 addition & 1 deletion doc/user/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ This is a list of core package dependencies:
* :doc:`orix <orix:index>`: Handling of rotations and vectors using crystal symmetry
* :doc:`pooch <pooch:api/index>`: Downloading and caching of datasets
* `pyyaml <https://pyyaml.org/>`__: Parcing of YAML files
* `tqdm <https://tqdm.github.io/>`__: Progressbars
* :doc:`scikit-image <skimage:index>`: Image processing like adaptive histogram
equalization
* `scikit-learn <https://scikit-learn.org/stable/>`__: Multivariate analysis
* :doc:`scipy <scipy:index>`: Optimization algorithms, filtering and more
* `tqdm <https://tqdm.github.io/>`__: Progressbars

.. _lazy_loader: https://scientific-python.org/specs/spec-0001/#lazy_loader

Expand Down
6 changes: 3 additions & 3 deletions examples/selecting_data/crop_signal_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This example shows various ways to crop the signal axes of an
:class:`~kikuchipy.signals.EBSD` signal using HyperSpy's ``isig`` slicer and the
:meth:`~kikuchipy.signals.EBSD.crop` and
:meth:`~hyperspy._signals.signal2d.Signal2D.crop_image` methods (see
:meth:`~hyperspy._signals.signal2d.Signal2D.crop_signal` methods (see
:ref:`hyperspy:signal.indexing` for details).
"""

Expand Down Expand Up @@ -49,10 +49,10 @@
print(s3.detector)

# %%
# Do the same inplace using ``crop_image()``
# Do the same inplace using ``crop_signal()``

s4 = s.deepcopy()
s4.crop_image(top=10, bottom=50, left=5, right=55)
s4.crop_signal(top=10, bottom=50, left=5, right=55)

_ = hs.plot.plot_images(s4, **plot_kwds)
print(s4)
Expand Down
75 changes: 0 additions & 75 deletions hyperspy_extension.yaml

This file was deleted.

46 changes: 25 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
requires = ["hatchling"]
build-backend = "hatchling.build"

# ----------------------------- Project ------------------------------ #

[project]
name = "kikuchipy"
authors = [{name = "kikuchipy developers"}]
Expand Down Expand Up @@ -40,33 +42,23 @@ dependencies = [
"dask[array] >= 2021.8.1",
"diffpy.structure >= 3",
"diffsims >= 0.5.2",
"hyperspy >= 2",
# TODO: Replace with HyperSpy 2.2 once it's out
"hyperspy @ git+https://github.com/hyperspy/hyperspy.git@RELEASE_next_patch",
"h5py >= 2.10",
"imageio",
"lazy_loader",
"matplotlib >= 3.5",
"numba >= 0.57",
# TODO: Remove pinning of NumPy <2 once HyperSpy 2.0 is supported
"numpy >= 1.23.0, <2",
"numpy >= 1.23.0",
"orix >= 0.12.1",
"pooch >= 1.3.0",
"pyyaml",
"tqdm >= 0.5.2",
"scikit-image >= 0.16.2",
"scikit-learn",
"scipy >= 1.7",
"tqdm >= 0.5.2",
]

[project.entry-points."hyperspy.extensions"]
kikuchipy = "kikuchipy"

[project.urls]
Documentation = "https://kikuchipy.org"
Download = "https://pypi.python.org/pypi/kikuchipy"
"Bug Tracker" = "https://github.com/pyxem/kikuchipy/issues"
"Source Code" = "https://github.com/pyxem/kikuchipy"
Changelog = "https://kikuchipy.org/en/stable/changelog.html"

[project.optional-dependencies]
all = [
"nlopt",
Expand Down Expand Up @@ -108,22 +100,34 @@ dev = [
"kikuchipy[doc,tests,coverage]",
]

[project.entry-points."hyperspy.extensions"]
kikuchipy = "kikuchipy"

[project.urls]
Documentation = "https://kikuchipy.org"
Download = "https://pypi.python.org/pypi/kikuchipy"
"Bug Tracker" = "https://github.com/pyxem/kikuchipy/issues"
"Source Code" = "https://github.com/pyxem/kikuchipy"
Changelog = "https://kikuchipy.org/en/stable/changelog.html"

# ------------------------------- Tool ------------------------------- #

[tool.hatch.version]
path = "src/kikuchipy/__init__.py"

# TODO: Remove this section and the duplicated file when HS 2.0 is
# supported
[tool.hatch.build.force-include]
"hyperspy_extension.yaml" = "hyperspy_extension.yaml"

# https://github.com/pypa/hatch/discussions/427
# https://github.com/pypa/hatch/issues/492
[tool.hatch.build.targets.wheel.sources]
src = ""

[tool.hatch.build.targets.wheel]
include = [
"src/kikuchipy",
]
[tool.hatch.build.targets.wheel.sources]
"src" = ""

# TODO: Remove once HyperSpy is not installed from a direct reference (GitHub)
[tool.hatch.metadata]
allow-direct-references = true

[tool.coverage.report]
precision = 2
Expand Down
10 changes: 5 additions & 5 deletions src/kikuchipy/_util/_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from typing import Callable
import warnings

import numpy as np
from kikuchipy.constants import VisibleDeprecationWarning


class deprecated:
Expand Down Expand Up @@ -93,12 +93,12 @@ def __call__(self, func: Callable) -> None:
@functools.wraps(func)
def wrapped(*args, **kwargs) -> Callable:
warnings.simplefilter(
action="always", category=np.VisibleDeprecationWarning, append=True
action="always", category=VisibleDeprecationWarning, append=True
)
func_code = func.__code__
warnings.warn_explicit(
message=msg,
category=np.VisibleDeprecationWarning,
category=VisibleDeprecationWarning,
filename=func_code.co_filename,
lineno=func_code.co_firstlineno + 1,
)
Expand Down Expand Up @@ -151,12 +151,12 @@ def wrapped(*args, **kwargs):
msg += f"Use `{self.alternative}` instead. "
msg += f"See the documentation of `{func.__name__}()` for more details."
warnings.simplefilter(
action="always", category=np.VisibleDeprecationWarning
action="always", category=VisibleDeprecationWarning
)
func_code = func.__code__
warnings.warn_explicit(
message=msg,
category=np.VisibleDeprecationWarning,
category=VisibleDeprecationWarning,
filename=func_code.co_filename,
lineno=func_code.co_firstlineno + 1,
)
Expand Down
12 changes: 12 additions & 0 deletions src/kikuchipy/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@
# Have to use bare except because PyOpenCL might raise its own
# LogicError, but we also want to catch import errors here
pyopencl_context_available = False


# TODO: Remove and use numpy.exceptions.VisibleDeprecationWarning once
# NumPy 1.25 is minimal supported version
try:
# Added in NumPy 1.25.0
from numpy.exceptions import VisibleDeprecationWarning
except ImportError: # pragma: no cover
# Removed in NumPy 2.0.0
from numpy import VisibleDeprecationWarning

del optional_deps, version
4 changes: 2 additions & 2 deletions src/kikuchipy/detectors/ebsd_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ def __init__(

def __repr__(self) -> str:
decimals = 3
pc_average = tuple(self.pc_average.round(decimals))
pc_average = tuple(map(float, self.pc_average.round(decimals)))
sample_tilt = np.round(self.sample_tilt, decimals)
tilt = np.round(self.tilt, decimals)
azimuthal = np.round(self.azimuthal, decimals)
px_size = np.round(self.px_size, decimals)
return (
f"{type(self).__name__}"
f"(shape={self.shape}, "
f"pc={pc_average!r}, "
f"pc={pc_average}, "
f"sample_tilt={sample_tilt}, "
f"tilt={tilt}, "
f"azimuthal={azimuthal}, "
Expand Down
Loading

0 comments on commit b229aa8

Please sign in to comment.