Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting the credits correct (hopefully) #113

Merged
merged 21 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions diffsims/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@

from .sims.diffraction_simulation import DiffractionSimulation

from .utils.atomic_diffraction_generator_support.probe_utils import (
ProbeFunction,
BesselProbe,
)
from .utils.atomic_diffraction_generator_support.fourier_transform import (
to_recip,
from_recip,
get_recip_points,
get_DFT,
)
from .utils.atomic_diffraction_generator_support.discretise_utils import (
get_discretisation,
)

from . import release_info

__version__ = release_info.version
Expand Down
6 changes: 2 additions & 4 deletions diffsims/generators/diffraction_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
get_vectorized_list_for_atomic_scattering_factors,
is_lattice_hexagonal,
)
from diffsims.utils.atomic_diffraction_generator_support.fourier_transform import (
from_recip,
)
from diffsims.utils.fourier_transform import from_recip


class DiffractionGenerator(object):
Expand Down Expand Up @@ -432,7 +430,7 @@ def calculate_ed_data(
]

if mode == "kinematic":
from diffsims.utils import atomic_diffraction_generator_utils as simlib
from diffsims.utils import kinematic_simulation_utils as simlib
else:
raise NotImplementedError(
"<mode> = %s is not currently supported" % repr(mode)
Expand Down
20 changes: 13 additions & 7 deletions diffsims/generators/rotation_list_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"triclinic": [180, 360, 0],
}

def get_list_from_orix(grid,rounding=2):

def get_list_from_orix(grid, rounding=2):
"""
Converts an orix sample to a rotation list

Expand All @@ -64,12 +65,13 @@ def get_list_from_orix(grid,rounding=2):
rotation_list = z.data.tolist()
i = 0
while i < len(rotation_list):
rotation_list[i] = tuple(np.round(rotation_list[i],decimals=rounding))
rotation_list[i] = tuple(np.round(rotation_list[i], decimals=rounding))
i += 1

return rotation_list

def get_fundamental_zone_grid(resolution=2, point_group=None,space_group=None):

def get_fundamental_zone_grid(resolution=2, point_group=None, space_group=None):
"""
Generates an equispaced grid of rotations within a fundamental zone.

Expand All @@ -88,10 +90,11 @@ def get_fundamental_zone_grid(resolution=2, point_group=None,space_group=None):
Grid of rotations lying within the specified fundamental zone
"""

orix_grid = get_sample_fundamental(resolution=resolution,space_group=space_group)
rotation_list = get_list_from_orix(orix_grid,rounding=2)
orix_grid = get_sample_fundamental(resolution=resolution, space_group=space_group)
rotation_list = get_list_from_orix(orix_grid, rounding=2)
return rotation_list


def get_local_grid(resolution=2, center=None, grid_width=10):
"""
Generates a grid of rotations about a given rotation
Expand All @@ -112,10 +115,13 @@ def get_local_grid(resolution=2, center=None, grid_width=10):
-------
rotation_list : list of tuples
"""
orix_grid = get_sample_local(resolution=resolution, center=center, grid_width=grid_width)
rotation_list = get_list_from_orix(orix_grid,rounding=2)
orix_grid = get_sample_local(
resolution=resolution, center=center, grid_width=grid_width
)
rotation_list = get_list_from_orix(orix_grid, rounding=2)
return rotation_list


def get_grid_around_beam_direction(beam_rotation, resolution, angular_range=(0, 360)):
"""
Creates a rotation list of rotations for which the rotation is about given beam direction
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-2019 The diffsims developers
# Copyright 2017-2020 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
4 changes: 3 additions & 1 deletion diffsims/libraries/structure_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ def from_crystal_systems(
NotImplementedError:
"This function has been removed in version 0.3.0, in favour of creation from orientation lists"
"""
raise NotImplementedError("This function has been removed in version 0.3.0, in favour of creation from orientation lists")
raise NotImplementedError(
"This function has been removed in version 0.3.0, in favour of creation from orientation lists"
)

def get_library_size(self, to_print=False):
"""
Expand Down
9 changes: 5 additions & 4 deletions diffsims/sims/diffraction_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,17 @@ def get_diffraction_pattern(self, size=512, sigma=10):
the order of 0.5nm and a the default size and sigma are used.
"""
side_length = np.min(np.multiply((size / 2), self.calibration))
mask_for_sides = np.all((np.abs(self.coordinates[:, 0:2]) < side_length), axis=1)

mask_for_sides = np.all(
(np.abs(self.coordinates[:, 0:2]) < side_length), axis=1
)

spot_coords = np.add(
self.calibrated_coordinates[mask_for_sides], size / 2
).astype(int)
spot_intens = self.intensities[mask_for_sides]
pattern = np.zeros([size, size])
#checks that we have some spots
if spot_intens.shape[0]==0:
# checks that we have some spots
if spot_intens.shape[0] == 0:
return pattern
else:
pattern[spot_coords[:, 0], spot_coords[:, 1]] = spot_intens
Expand Down
35 changes: 28 additions & 7 deletions diffsims/tests/test_generators/test_rotation_list_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@
get_local_grid,
get_grid_around_beam_direction,
get_fundamental_zone_grid,
get_beam_directions_grid
)
get_beam_directions_grid,
)

@pytest.mark.parametrize("grid",[pytest.param(get_local_grid(resolution=30,center=None,grid_width=35),marks=pytest.mark.xfail(reason="Downstream bug")),
get_fundamental_zone_grid(space_group=20, resolution=20)])

@pytest.mark.parametrize(
"grid",
[
pytest.param(
get_local_grid(resolution=30, center=None, grid_width=35),
marks=pytest.mark.xfail(reason="Downstream bug"),
),
get_fundamental_zone_grid(space_group=20, resolution=20),
],
)
def test_get_grid(grid):
assert isinstance(grid, list)
assert len(grid) > 0
Expand All @@ -40,7 +49,19 @@ def test_get_grid_around_beam_direction():
assert isinstance(grid_simple[0], tuple)
assert len(grid_simple) == 360

@pytest.mark.parametrize("crystal_system",['cubic','hexagonal','trigonal','tetragonal','orthorhombic','monoclinic','triclinic'])

@pytest.mark.parametrize(
"crystal_system",
[
"cubic",
"hexagonal",
"trigonal",
"tetragonal",
"orthorhombic",
"monoclinic",
"triclinic",
],
)
def test_get_beam_directions_grid(crystal_system):
for equal in ["angle","area"]:
_ = get_beam_directions_grid(crystal_system, 5, equal=equal)
for equal in ["angle", "area"]:
_ = get_beam_directions_grid(crystal_system, 5, equal=equal)
2 changes: 1 addition & 1 deletion diffsims/tests/test_generators/test_zap_map_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2019 The diffsims developers
# Copyright 2017-2020 The diffsims developers
#
# This file is part of diffsims.
#
Expand Down
5 changes: 4 additions & 1 deletion diffsims/tests/test_library/test_structure_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ def test_from_orientations_method():
np.testing.assert_equal(library.struct_lib["a"], (1, 3))
np.testing.assert_equal(library.struct_lib["b"], (2, 4))


@pytest.mark.xfail(reason="Functionality removed")
def test_from_systems_methods():
identifiers = ["a", "b"]
structures = [1, 2]
systems = ["cubic", "hexagonal"]
library = StructureLibrary.from_crystal_systems(identifiers, structures, systems, resolution=2)
library = StructureLibrary.from_crystal_systems(
identifiers, structures, systems, resolution=2
)


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion diffsims/tests/test_sims/test_diffraction_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_assertion_free_get_diffraction_pattern(self):
)

z = short_sim.get_diffraction_pattern()

empty_sim = DiffractionSimulation(
coordinates=np.asarray([[0.3, 1000, 0]]),
intensities=np.ones(1),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
"""
Created on 3 Nov 2019

@author: Rob Tovey
"""
# -*- coding: utf-8 -*-
# Copyright 2017-2020 The diffsims developers
#
# This file is part of diffsims.
#
# diffsims is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffsims is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffsims. If not, see <http://www.gnu.org/licenses/>.

import pytest
import numpy as np
Expand Down
24 changes: 18 additions & 6 deletions diffsims/tests/test_utils/test_discretise_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
"""
Created on 1 Nov 2019

@author: Rob Tovey
"""
# -*- coding: utf-8 -*-
# Copyright 2017-2020 The diffsims developers
#
# This file is part of diffsims.
#
# diffsims is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffsims is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffsims. If not, see <http://www.gnu.org/licenses/>.

import pytest
import numpy as np
from diffsims.utils.atomic_diffraction_generator_support.discretise_utils import (
from diffsims.utils.discretise_utils import (
get_atoms,
get_discretisation,
_CUDA,
Expand Down
28 changes: 19 additions & 9 deletions diffsims/tests/test_utils/test_fourier_transform.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
"""
Created on 2 Nov 2019

@author: Rob Tovey
"""
# -*- coding: utf-8 -*-
# Copyright 2017-2020 The diffsims developers
#
# This file is part of diffsims.
#
# diffsims is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffsims is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffsims. If not, see <http://www.gnu.org/licenses/>.

import pytest
import numpy as np
from diffsims.utils.atomic_diffraction_generator_support.fourier_transform import (
from diffsims.utils.fourier_transform import (
plan_fft,
plan_ifft,
fftn,
Expand All @@ -21,9 +33,7 @@
get_DFT,
convolve,
)
from diffsims.utils.atomic_diffraction_generator_support.discretise_utils import (
get_atoms,
)
from diffsims.utils.discretise_utils import get_atoms


def _toMesh(x):
Expand Down
24 changes: 18 additions & 6 deletions diffsims/tests/test_utils/test_generic_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
"""
Created on 3 Dec 2019

@author: Rob Tovey
"""
# -*- coding: utf-8 -*-
# Copyright 2017-2020 The diffsims developers
#
# This file is part of diffsims.
#
# diffsims is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffsims is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffsims. If not, see <http://www.gnu.org/licenses/>.

import pytest
from diffsims.utils.atomic_diffraction_generator_support.generic_utils import (
from diffsims.utils.generic_utils import (
GLOBAL_BOOL,
get_grid,
to_mesh,
Expand Down
Loading