Skip to content

Commit

Permalink
updated tests and minor bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
din14970 committed Oct 5, 2020
1 parent 41fd716 commit dce083a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
21 changes: 15 additions & 6 deletions diffsims/generators/rotation_list_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ def get_uv_sphere_mesh_vertices(resolution):
----------
https://medium.com/game-dev-daily/four-ways-to-create-a-mesh-for-a-sphere-d7956b825db4
"""
steps_theta = int(np.ceil(180 / resolution)) # elevation
steps_psi = int(np.ceil(360 / resolution)) # azimuthal
steps_theta = int(np.ceil(180 / resolution))+1 # elevation
steps_psi = int(np.ceil(360 / resolution)) # azimuthal

psi = np.linspace(0, 2 * np.pi, num=steps_psi, endpoint=False)
theta = np.linspace(0, np.pi, num=steps_theta, endpoint=True)
Expand Down Expand Up @@ -612,10 +612,8 @@ def get_beam_directions_grid(crystal_system, resolution,
'orthorhombic','monoclinic','triclinic'
resolution : float
An angle in degrees characterizing the finesse of the grid. Depending
on the meshing method there can be a slight variation in the
interpretation, but it is intended to mean the worst-case angular
distance to a nearest neighbor grid point.
An angle in degrees representing the worst-case angular
distance to a first nearest neighbor grid point.
mesh : str
Type of meshing of the sphere that defines how the grid is created.
Expand All @@ -630,9 +628,20 @@ def get_beam_directions_grid(crystal_system, resolution,
if mesh == "uv_sphere":
points_in_cartesians = get_uv_sphere_mesh_vertices(resolution)
elif mesh == "normalized_cube":
# special case: hexagon is a very small slice and 001 point can
# be isolated. Hence we increase resolution to ensure minimum angle.
if crystal_system == "hexagonal":
resolution = np.rad2deg(
np.arctan(np.tan(np.deg2rad(resolution))/np.sqrt(2)))
points_in_cartesians = get_cube_mesh_vertices(resolution,
grid_type="normalized")

elif mesh == "spherified_cube_edge":
# special case: hexagon is a very small slice and 001 point can
# be isolated. Hence we increase resolution to ensure minimum angle.
if crystal_system == "hexagonal":
resolution = np.rad2deg(
np.arctan(np.tan(np.deg2rad(resolution))/np.sqrt(2)))
points_in_cartesians = get_cube_mesh_vertices(resolution,
grid_type="spherified_edge")
elif mesh == "spherified_cube_corner":
Expand Down
20 changes: 16 additions & 4 deletions diffsims/tests/test_generators/test_rotation_list_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
get_grid_around_beam_direction,
get_fundamental_zone_grid,
get_beam_directions_grid,
_get_max_grid_angle
)


@pytest.mark.parametrize(
"grid",
[
pytest.param(
get_local_grid(resolution=30, center=(0,1,0), grid_width=35)
get_local_grid(resolution=30, center=(0, 1, 0), grid_width=35)
),
get_fundamental_zone_grid(space_group=20, resolution=20),
],
Expand All @@ -51,6 +52,16 @@ def test_get_grid_around_beam_direction():
assert np.allclose([x[1] for x in grid], 90) # taking z to y


@pytest.mark.parametrize(
"mesh",
[
"uv_sphere",
"normalized_cube",
"spherified_cube_edge",
"spherified_cube_corner",
"icosahedral",
]
)
@pytest.mark.parametrize(
"crystal_system",
[
Expand All @@ -63,6 +74,7 @@ def test_get_grid_around_beam_direction():
"triclinic",
],
)
def test_get_beam_directions_grid(crystal_system):
for equal in ["angle", "area"]:
_ = get_beam_directions_grid(crystal_system, 5, equal=equal)
def test_get_beam_directions_grid(crystal_system, mesh):
grid = get_beam_directions_grid(crystal_system, 5, mesh=mesh)
max_angle = _get_max_grid_angle(grid)
assert max_angle <= 5

0 comments on commit dce083a

Please sign in to comment.