Skip to content

Commit

Permalink
Merge pull request #362 from hakonanes/release-v0.3.4
Browse files Browse the repository at this point in the history
Prepare v0.3.x branch for a v0.3.4 patch release
  • Loading branch information
hakonanes committed May 26, 2021
2 parents 21a3b4e + 11b30fb commit eb7f9df
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 64 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/build.yml
Expand Up @@ -13,7 +13,13 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.7, 3.8]
python-version: [3.8, 3.9]
include:
# Oldest supported version of main dependencies on Python 3.7
- os: ubuntu-latest
python-version: 3.7
OLDEST_SUPPORTED_VERSION: true
DEPENDENCIES: dask==2.18 diffsims==0.4.0 hyperspy==1.5.2 matplotlib==3.3 numpy==1.19 orix==0.6.0 scikit-image==0.16.2
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -43,4 +49,4 @@ jobs:
- name: Coveralls finished
uses: AndreMiras/coveralls-python-action@develop
with:
parallel-finished: true
parallel-finished: true
14 changes: 13 additions & 1 deletion doc/changelog.rst
Expand Up @@ -12,6 +12,18 @@ project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.
Contributors to each release are listed in alphabetical order by first name.
List entries are sorted in descending chronological order.

0.3.4 (2021-05-26)
==================

Contributors
------------
- Håkon Wiik Ånes

Added
-----
- Restricted newest version of dask<=2021.03.1 and pinned orix==0.6.0.
(`#360 <https://github.com/pyxem/kikuchipy/pull/360>`_)

0.3.3 (2021-04-18)
==================

Expand All @@ -22,7 +34,7 @@ Contributors

Fixed
-----
- Reading of EBSD patterns from Bruker h5ebsd with a region of interest
- Reading of EBSD patterns from Bruker h5ebsd with a region of interest.
(`#339 <https://github.com/pyxem/kikuchipy/pull/339>`_)
- Merging of (typically refined) crystal maps, where either a simulation indices
array is not present or the array contains more indices per point than scores.
Expand Down
18 changes: 9 additions & 9 deletions kikuchipy/projections/gnomonic_projection.py
Expand Up @@ -51,23 +51,23 @@ def project(cls, v: Union[Vector3d, np.ndarray]) -> np.ndarray:
>>> v = np.random.random_sample(30).reshape((10, 3))
>>> xy = GnomonicProjection.project(v)
"""
polar = super().project(v)
theta, phi = polar[..., 0], polar[..., 1]
polar_coordinates = super().project(v)
polar, azimuth = polar_coordinates[..., 0], polar_coordinates[..., 1]

# Map to upper hemisphere
if isinstance(v, Vector3d):
is_upper = v.z > 0
else:
is_upper = v[..., 2] > 0
theta[is_upper] -= np.pi
polar[is_upper] -= np.pi

# Formula for gnomonic projection
r = np.tan(theta)
r = np.tan(polar)

# Compute coordinates
gnomonic = np.zeros(r.shape + (2,), dtype=r.dtype)
gnomonic[..., 0] = np.cos(phi) * r
gnomonic[..., 1] = np.sin(phi) * r
gnomonic[..., 0] = np.cos(azimuth) * r
gnomonic[..., 1] = np.sin(azimuth) * r

return gnomonic

Expand Down Expand Up @@ -98,6 +98,6 @@ def iproject(xy: np.ndarray) -> Vector3d:
>>> xyz = GnomonicProjection.iproject(xy_g)
"""
x, y = xy[..., 0], xy[..., 1]
theta = np.arctan(np.sqrt(x ** 2 + y ** 2))
phi = np.arctan2(y, x)
return Vector3d.from_polar(theta=theta, phi=phi)
polar = np.arctan(np.sqrt(x ** 2 + y ** 2))
azimuth = np.arctan2(y, x)
return Vector3d.from_polar(polar=polar, azimuth=azimuth)
10 changes: 5 additions & 5 deletions kikuchipy/projections/hesse_normal_form.py
Expand Up @@ -24,7 +24,7 @@

import numpy as np

from kikuchipy.projections.spherical_projection import get_theta
from kikuchipy.projections.spherical_projection import get_polar


class HesseNormalForm:
Expand All @@ -40,7 +40,7 @@ def project_polar(
Parameters
----------
polar
Spherical coordinates theta, phi, r.
The polar, azimuthal and radial spherical coordinates.
radius
Hesse radius. Default is 10.
Expand Down Expand Up @@ -74,9 +74,9 @@ def project_cartesian(
hesse
Hesse normal form coordinates distance and angle.
"""
theta = get_theta(cartesian)
hesse = np.zeros((theta.size, 2))
hesse_distance = np.tan(0.5 * np.pi - theta)
polar = get_polar(cartesian)
hesse = np.zeros((polar.size, 2))
hesse_distance = np.tan(0.5 * np.pi - polar)
hesse[..., 0] = hesse_distance
hesse[..., 1] = np.arccos(hesse_distance / radius)
return hesse
42 changes: 21 additions & 21 deletions kikuchipy/projections/spherical_projection.py
Expand Up @@ -69,27 +69,27 @@ def project(cls, v: Union[Vector3d, np.ndarray]) -> np.ndarray:
>>> np.allclose(np.arctan2(v[:, 1], v[:, 2]), phi)
True
"""
return _get_polar(v)
return _get_polar_coordinates(v)


def _get_polar(v: Union[Vector3d, np.ndarray]) -> np.ndarray:
def _get_polar_coordinates(v: Union[Vector3d, np.ndarray]) -> np.ndarray:
if isinstance(v, Vector3d):
x, y, z = v.xyz
else:
x, y, z = v[..., 0], v[..., 1], v[..., 2]
polar = np.zeros(x.shape + (3,), dtype=x.dtype)
polar[..., 1] = np.where(
np.arctan2(y, x) < 0, np.arctan2(y, x) + 2 * np.pi, np.arctan2(y, x)
) # Phi
) # Azimuth
polar[..., 2] = np.sqrt(x ** 2 + y ** 2 + z ** 2) # r
polar[..., 0] = np.arccos(z / polar[..., 2]) # Theta
polar[..., 0] = np.arccos(z / polar[..., 2]) # Polar

return polar


def get_theta(v: Union[Vector3d, np.ndarray]) -> np.ndarray:
"""Get spherical coordinate theta from cartesian according to the
ISO 31-11 standard [SphericalWolfram]_.
def get_polar(v: Union[Vector3d, np.ndarray]) -> np.ndarray:
"""Get the polar spherical coordinate from cartesian according to
the ISO 31-11 standard [SphericalWolfram]_.
Parameters
----------
Expand All @@ -98,8 +98,8 @@ def get_theta(v: Union[Vector3d, np.ndarray]) -> np.ndarray:
Returns
-------
theta
Spherical coordinate theta.
polar
Polar spherical coordinate.
"""
if isinstance(v, Vector3d):
x, y, z = v.xyz
Expand All @@ -109,9 +109,9 @@ def get_theta(v: Union[Vector3d, np.ndarray]) -> np.ndarray:
return np.arccos(z / r)


def get_phi(v: Union[Vector3d, np.ndarray]) -> np.ndarray:
"""Get spherical coordinate phi from cartesian according to the ISO
31-11 standard [SphericalWolfram]_.
def get_azimuth(v: Union[Vector3d, np.ndarray]) -> np.ndarray:
"""Get the azimuthal spherical coordinate from cartesian according
to the ISO 31-11 standard [SphericalWolfram]_.
Parameters
----------
Expand All @@ -120,20 +120,20 @@ def get_phi(v: Union[Vector3d, np.ndarray]) -> np.ndarray:
Returns
-------
phi
Spherical coordinate phi.
azimuth
Azimuthal spherical coordinate.
"""
if isinstance(v, Vector3d):
x, y, _ = v.xyz
else:
x, y = v[..., 0], v[..., 1]
phi = np.arctan2(y, x)
phi += (phi < 0) * 2 * np.pi
return phi
azimuth = np.arctan2(y, x)
azimuth += (azimuth < 0) * 2 * np.pi
return azimuth


def get_r(v: Union[Vector3d, np.ndarray]) -> np.ndarray:
"""Get radial spherical coordinate from cartesian coordinates.
def get_radial(v: Union[Vector3d, np.ndarray]) -> np.ndarray:
"""Get the radial spherical coordinate from cartesian coordinates.
Parameters
----------
Expand All @@ -142,8 +142,8 @@ def get_r(v: Union[Vector3d, np.ndarray]) -> np.ndarray:
Returns
-------
phi
Spherical coordinate phi.
radial
Radial spherical coordinate.
"""
if isinstance(v, Vector3d):
x, y, z = v.xyz
Expand Down
4 changes: 2 additions & 2 deletions kikuchipy/projections/tests/test_hesse_normal_form.py
Expand Up @@ -20,7 +20,7 @@
import pytest

from kikuchipy.projections.hesse_normal_form import HesseNormalForm
from kikuchipy.projections.spherical_projection import _get_polar
from kikuchipy.projections.spherical_projection import _get_polar_coordinates


class TestHesseNormalForm:
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_project_polar(self, radius, desired_result):
[0.7605, 0.0647, 0.9848],
]
)
polar = _get_polar(v)
polar = _get_polar_coordinates(v)
assert np.allclose(
HesseNormalForm.project_polar(polar, radius=radius),
desired_result,
Expand Down
30 changes: 15 additions & 15 deletions kikuchipy/projections/tests/test_spherical_projection.py
Expand Up @@ -21,9 +21,9 @@

from kikuchipy.projections.spherical_projection import (
SphericalProjection,
get_theta,
get_phi,
get_r,
get_polar,
get_azimuth,
get_radial,
)


Expand All @@ -35,18 +35,18 @@ def test_spherical_projection():

# Vector3d
polar = SphericalProjection.project(v_arr)
assert np.allclose(polar[..., 0], v.theta.data)
assert np.allclose(polar[..., 1], v.phi.data)
assert np.allclose(polar[..., 2], v.r.data)
assert np.allclose(get_theta(v), v.theta.data)
assert np.allclose(get_phi(v), v.phi.data)
assert np.allclose(get_r(v), v.r.data)
assert np.allclose(polar[..., 0], v.polar.data)
assert np.allclose(polar[..., 1], v.azimuth.data)
assert np.allclose(polar[..., 2], v.radial.data)
assert np.allclose(get_polar(v), v.polar.data)
assert np.allclose(get_azimuth(v), v.azimuth.data)
assert np.allclose(get_radial(v), v.radial.data)

# NumPy array
polar2 = SphericalProjection.project(v)
assert np.allclose(polar2[..., 0], v.theta.data)
assert np.allclose(polar2[..., 1], v.phi.data)
assert np.allclose(polar2[..., 2], v.r.data)
assert np.allclose(get_theta(v_arr), v.theta.data)
assert np.allclose(get_phi(v_arr), v.phi.data)
assert np.allclose(get_r(v_arr), v.r.data)
assert np.allclose(polar2[..., 0], v.polar.data)
assert np.allclose(polar2[..., 1], v.azimuth.data)
assert np.allclose(polar2[..., 2], v.radial.data)
assert np.allclose(get_polar(v_arr), v.polar.data)
assert np.allclose(get_azimuth(v_arr), v.azimuth.data)
assert np.allclose(get_radial(v_arr), v.radial.data)
2 changes: 1 addition & 1 deletion kikuchipy/release.py
Expand Up @@ -34,4 +34,4 @@
name = "kikuchipy"
platforms = ["Linux", "MacOS X", "Windows"]
status = "Development"
version = "0.3.3"
version = "0.3.4"
12 changes: 6 additions & 6 deletions kikuchipy/simulations/features.py
Expand Up @@ -173,7 +173,7 @@ def hesse_distance(self) -> np.ndarray:
"""Distance from the PC (origin) per band, i.e. the right-angle
component of the distance to the pole.
"""
return np.tan(0.5 * np.pi - self.hkl_detector.theta.data)
return np.tan(0.5 * np.pi - self.hkl_detector.polar.data)

@property
def within_gnomonic_radius(self) -> np.ndarray:
Expand Down Expand Up @@ -209,11 +209,11 @@ def plane_trace_coordinates(self) -> np.ndarray:
to NaN.
"""
# Get alpha1 and alpha2 angles (NaN for bands outside gnomonic radius)
phi = self.hkl_detector.phi.data
azimuth = self.hkl_detector.azimuth.data
hesse_alpha = self.hesse_alpha
plane_trace = np.zeros(self.navigation_shape + (self.size, 4))
alpha1 = phi - np.pi + hesse_alpha
alpha2 = phi - np.pi - hesse_alpha
alpha1 = azimuth - np.pi + hesse_alpha
alpha2 = azimuth - np.pi - hesse_alpha

# Calculate start and end points for the plane traces
plane_trace[..., 0] = np.cos(alpha1)
Expand All @@ -227,11 +227,11 @@ def plane_trace_coordinates(self) -> np.ndarray:

@property
def hesse_line_x(self) -> np.ndarray:
return -self.hesse_distance * np.cos(self.hkl_detector.phi.data)
return -self.hesse_distance * np.cos(self.hkl_detector.azimuth.data)

@property
def hesse_line_y(self) -> np.ndarray:
return -self.hesse_distance * np.sin(self.hkl_detector.phi.data)
return -self.hesse_distance * np.sin(self.hkl_detector.azimuth.data)

def __getitem__(self, key):
"""Get a deepcopy subset of the KikuchiBand object.
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Expand Up @@ -115,14 +115,16 @@
# Dependencies
extras_require=extra_feature_requirements,
install_requires=[
"dask[array] >= 2.14",
# Restrict newest dask version until
# https://github.com/dask/dask/issues/7583 is resolved
"dask[array] >= 2.18, <= 2021.03.1",
"diffsims >= 0.4",
"hyperspy >= 1.5.2",
"h5py >= 2.10",
"matplotlib >= 3.2",
"numpy >= 1.18",
"numba >= 0.48",
"orix >= 0.5",
"orix >= 0.6.0",
"pooch >= 0.13",
"psutil",
"tqdm >= 0.5.2",
Expand Down

0 comments on commit eb7f9df

Please sign in to comment.