Skip to content

Commit

Permalink
Merge #191 from hakonanes/fix-allowed-vectors
Browse files Browse the repository at this point in the history
Fix allowed vectors when (hkl) are slightly off integers
  • Loading branch information
pc494 authored Jan 26, 2023
2 parents 2196e06 + 18a06f4 commit 715ea14
Show file tree
Hide file tree
Showing 78 changed files with 184 additions and 136 deletions.
53 changes: 32 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
name: build

on: [push, pull_request]
on:
push:
branches:
- '*'
pull_request:
branches:
- '*'
workflow_dispatch:
workflow: '*'

env:
MPLBACKEND: agg

jobs:
# Make sure all necessary files will be included in a release
manifest:
name: check manifest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions/setup-python@v2
- uses: actions/setup-python@v4

- name: Install dependencies
run: pip install manifix
Expand All @@ -19,58 +30,58 @@ jobs:
run: python setup.py manifix

build-with-pip:
name: ${{ matrix.os }}-py${{ matrix.python-version }}${{ matrix.label }}
name: ${{ matrix.os }}-py${{ matrix.python-version }}${{ matrix.LABEL }}
runs-on: ${{ matrix.os }}
timeout-minutes: 15
env:
MPLBACKEND: agg
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.9, '3.10']
include:
# Oldest supported version of main dependencies on Python 3.6
- os: ubuntu-latest
- os: ubuntu-20.04
python-version: 3.6
OLDEST_SUPPORTED_VERSION: true
DEPENDENCIES: diffpy.structure==3.0.0 matplotlib==3.3 numpy==1.17 orix==0.9.0 scipy==1.0 tqdm==4.9
LABEL: -oldest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Display Python and pip versions
run: |
python -V
pip -V
- name: Install dependencies and package
shell: bash
run: pip install -U -e .'[tests]'
run: |
pip install -U -e .'[tests]'
- name: Install oldest supported version
if: ${{ matrix.OLDEST_SUPPORTED_VERSION }}
run: pip install ${{ matrix.DEPENDENCIES }}
run: |
pip install ${{ matrix.DEPENDENCIES }}
- name: Display package versions
run: pip list
- name: Display Python, pip and package versions
run: |
python -V
pip -V
pip list
- name: Run docstring tests
if: ${{ matrix.os == 'ubuntu-latest' }}
continue-on-error: true
run: pytest --doctest-modules --ignore-glob=diffsims/tests/*
run: |
pytest --doctest-modules --doctest-continue-on-failure --ignore-glob=diffsims/tests/*
- name: Run tests
run: pytest --cov=diffsims --pyargs diffsims
run: pytest -n 2 --cov=diffsims --pyargs diffsims

- name: Generate line coverage
if: ${{ matrix.os == 'ubuntu-latest' }}
run: coverage report --show-missing
run: |
coverage report --show-missing
- name: Upload coverage to Coveralls
if: ${{ matrix.os == 'ubuntu-latest' }}
Expand Down
15 changes: 14 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0>`_
and this project adheres to `Semantic Versioning
<https://semver.org/spec/v2.0.0.html>`_.

2023-01-25 - version 0.5.1
==========================

Fixed
-----
- ``ReciprocalLatticeVector.allowed`` rounds indices (hkl) internally to ensure correct
selection of which vectors are allowed or not given a lattice centering. Integer
indices are assumed.

Deprecated
----------
- Support for Python 3.6 is deprecated and will be removed in v0.6.

2022-06-10 - version 0.5.0
==========================

Expand Down Expand Up @@ -67,7 +80,7 @@ Fixed

Added
-----
- API reference documentation via Read The Docs: https://diffsims.readthedocs.io
- API reference documentation via Read The Docs: https://diffsims.readthedocs.io/en/latest/
- New module: `sphere_mesh_generators`
- New module: `detector_functions`
- New module: `ring_pattern_utils`
Expand Down
27 changes: 13 additions & 14 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ this guide boils down to using that platform well. so visit the following link a
around the code, issues, and pull requests (PRs): `diffsims
on GitHub <https://github.com/pyxem/diffsims>`_.

It's probably also worth visiting the `GitHub guides <https://guides.github.com>`_ to
It's probably also worth visiting the `GitHub guides <https://docs.github.com/en>`_ to
get a feel for the terminology.

In brief, to give you a hint on the terminology to search for, the contribution pattern
Expand Down Expand Up @@ -70,7 +70,7 @@ Git is an open source "version control" system that enables you to can separate
modifications to the code into many versions (called branches) and switch between them
easily. Later you can choose which version you want to have integrated into diffsims.

You can learn all about Git `here <http://www.git-scm.com/about>`_!
You can learn all about Git `here <https://www.git-scm.com/about>`_!

The most important thing is to separate your contributions so that each branch is a
small advancement on the "master" code or on another branch.
Expand All @@ -80,7 +80,7 @@ Get the style right

diffsims closely follows the Style Guide for Python Code - these are just some rules for
consistency that you can read all about in the `Python Style Guide
<https://www.python.org/dev/peps/pep-0008/>`_.
<https://peps.python.org/pep-0008/>`_.

Please run the latest version of
`black <https://black.readthedocs.io/en/stable/the_black_code_style/index.html>`_ on
Expand All @@ -89,18 +89,18 @@ your newly added and modified files prior to each PR.
Run and write tests
-------------------

All functionality in diffsims is tested via the `pytest <https://docs.pytest.org>`_
framework. The tests reside in the ``diffsims.tests`` module. Tests are short functions
that call functions in diffsims and compare resulting output values with known answers.
Good tests should depend on as few other features as possible so that when they break we
know exactly what caused it.
All functionality in diffsims is tested via the `pytest
<https://docs.pytest.org/en/stable/>`_ framework. The tests reside in the
``diffsims.tests`` module. Tests are short functions that call functions in diffsims and
compare resulting output values with known answers. Good tests should depend on as few
other features as possible so that when they break we know exactly what caused it.

Install necessary dependencies to run the tests::

pip install --editable .[tests]

Some useful `fixtures <https://docs.pytest.org/en/latest/fixture.html>`_ are available
in the ``conftest.py`` file.
Some useful `fixtures <https://docs.pytest.org/en/latest/explanation/fixtures.html>`_
are available in the ``conftest.py`` file.

To run the tests::

Expand All @@ -122,16 +122,15 @@ Useful hints on testing:
- ``@pytest.mark.parametrize()`` is a convenient decorator to test several parameters of
the same function without having to write to much repetitive code, which is often
error-prone. See `pytest documentation for more details
<http://doc.pytest.org/en/latest/parametrize.html>`_.
<https://doc.pytest.org/en/latest/how-to/parametrize.html>`_.

Build and write documentation
-----------------------------

Docstrings -- written at the start of a function -- give essential information about how
it should be used, such as which arguments can be passed to it and what the syntax
should be. The docstrings follow the `NumPy specification
<https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard>`_,
as shown in `this example <https://github.com/numpy/numpy/blob/master/doc/example.py>`_.
should be. The docstrings mostly follow the `numpydoc
<https://numpydoc.readthedocs.io/en/latest/format.html>`_ standard.

We use `Sphinx <https://www.sphinx-doc.org/en/master>`_ for documenting functionality.
Install necessary dependencies to build the documentation::
Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
.. |docs| image:: https://readthedocs.org/projects/diffsims/badge/?version=latest
.. _docs: https://diffsims.readthedocs.io/en/latest

.. |pypi_version| image:: http://img.shields.io/pypi/v/diffsims.svg?style=flat
.. _pypi_version: https://pypi.python.org/pypi/diffsims
.. |pypi_version| image:: https://img.shields.io/pypi/v/diffsims.svg?style=flat
.. _pypi_version: https://pypi.org/project/diffsims/

.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
.. _black: https://github.com/psf/black
Expand All @@ -23,7 +23,7 @@ diffsims is an open-source Python library for simulating diffraction.
If simulations performed using diffsims form a part of published work please
cite the DOI at the top of this page. You can find demos in the `diffsims-demos
<https://github.com/pyxem/diffsims-demos>`_ repository. See the `documentation
<https://diffsims.readthedocs.io>`_ for installation instructions, the API reference,
the changelog and more.
<https://diffsims.readthedocs.io/en/latest/>`_ for installation instructions, the API
reference, the changelog and more.

diffsims is released under the GPL v3 license.
2 changes: 1 addition & 1 deletion diffsims/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
2 changes: 1 addition & 1 deletion diffsims/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
2 changes: 1 addition & 1 deletion diffsims/crystallography/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
2 changes: 1 addition & 1 deletion diffsims/crystallography/reciprocal_lattice_point.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
22 changes: 13 additions & 9 deletions diffsims/crystallography/reciprocal_lattice_vector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2021 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down Expand Up @@ -59,8 +59,8 @@ class ReciprocalLatticeVector(Vector3d):
Create a set of reciprocal lattice vectors from :math:`(hkl)` or
:math:`(hkil)`.
The vectors are internally as cartesian coordinates in the ``data``
attribute.
The vectors are stored internally as cartesian coordinates in
:attr:`data`.
Parameters
----------
Expand Down Expand Up @@ -583,6 +583,8 @@ def allowed(self):
"""Return whether vectors diffract according to diffraction
selection rules assuming kinematic scattering theory.
Integer vectors are assumed.
Returns
-------
allowed : numpy.ndarray
Expand Down Expand Up @@ -614,20 +616,22 @@ def allowed(self):
# Translational symmetry
centering = self.phase.space_group.short_name[0]

hkl = self.hkl.round().astype(int).reshape(-1, 3)

if centering == "A": # Centred on A faces only
return np.isclose(np.mod(self.k + self.l, 2), 0)
return np.isclose(np.mod(hkl[:, 1] + hkl[:, 2], 2), 0)
elif centering == "B": # Centred on B faces only
return np.isclose(np.mod(self.h + self.l, 2), 0)
return np.isclose(np.mod(hkl[:, 0] + hkl[:, 2], 2), 0)
elif centering == "C": # Centred on C faces only
return np.isclose(np.mod(self.h + self.k, 2), 0)
return np.isclose(np.mod(hkl[:, 0] + hkl[:, 1], 2), 0)
elif centering == "F": # Face-centred, hkl all odd/even
selection = np.sum(np.mod(self.hkl, 2), axis=-1)
selection = np.sum(np.mod(hkl, 2), axis=-1)
return np.array([i not in [1, 2] for i in selection], dtype=bool)
elif centering == "I": # Body-centred, h + k + l = 2n (even)
return np.isclose(np.mod(np.sum(self.hkl, axis=-1), 2), 0)
return np.isclose(np.mod(np.sum(hkl, axis=-1), 2), 0)
elif centering in ["R", "H"]: # Rhombohedral obverse
# Consider Rhombohedral reverse?
return np.isclose(np.mod(-self.h + self.k + self.l, 3), 0)
return np.isclose(np.mod(-hkl[:, 0] + hkl[:, 1] + hkl[:, 2], 3), 0)
elif centering == "P": # Primitive
if self.has_hexagonal_lattice:
# TODO: See rules in e.g.
Expand Down
2 changes: 1 addition & 1 deletion diffsims/generators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
2 changes: 1 addition & 1 deletion diffsims/generators/diffraction_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
2 changes: 1 addition & 1 deletion diffsims/generators/library_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
2 changes: 1 addition & 1 deletion diffsims/generators/rotation_list_generators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
7 changes: 3 additions & 4 deletions diffsims/generators/sphere_mesh_generators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down Expand Up @@ -143,7 +143,7 @@ def get_cube_mesh_vertices(resolution, grid_type="spherified_corner"):
References
----------
.. [Cajaravelli2015] O. S. Cajaravelli, "Four Ways to Create a Mesh for a Sphere,"
https://medium.com/game-dev-daily/four-ways-to-create-a-mesh-for-a-sphere-d7956b825db4.
https://medium.com/@oscarsc/four-ways-to-create-a-mesh-for-a-sphere-d7956b825db4.
"""
# the angle between 001 and 011
max_angle = np.deg2rad(45)
Expand Down Expand Up @@ -385,8 +385,7 @@ def get_icosahedral_mesh_vertices(resolution):
References
----------
.. [Meshzoo] The `meshzoo.sphere` module,
https://github.com/nschloe/meshzoo/blob/master/meshzoo/sphere.py.
.. [Meshzoo] The `meshzoo.sphere` module.
"""
t = (1.0 + np.sqrt(5.0)) / 2.0
corners = np.array(
Expand Down
2 changes: 1 addition & 1 deletion diffsims/generators/zap_map_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
2 changes: 1 addition & 1 deletion diffsims/libraries/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
2 changes: 1 addition & 1 deletion diffsims/libraries/diffraction_library.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
2 changes: 1 addition & 1 deletion diffsims/libraries/structure_library.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
# Copyright 2017-2023 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
Loading

0 comments on commit 715ea14

Please sign in to comment.