Skip to content

Commit

Permalink
updates to end to end tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
AxelHenningsson committed Aug 7, 2024
1 parent 75d31b3 commit 21e58b6
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 268 deletions.
2 changes: 1 addition & 1 deletion tests/end_to_end_tests/fast_s3dxrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def orientation_density_function(x, q): return 1. / (np.pi**2) # uniform ODF.
os.path.join(
os.path.dirname(__file__),
'saves'),
'fast_polycrystal_from_odf')
'fast_polycrystal_from_odf.pc')

if 1:
def strain_tensor(x): return np.array(
Expand Down
82 changes: 0 additions & 82 deletions tests/end_to_end_tests/laue_powder.py

This file was deleted.

13 changes: 11 additions & 2 deletions tests/end_to_end_tests/powder.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,17 @@
translation = np.array([0, 0, 0])
motion = RigidBodyMotion(rotation_axis, rotation_angle, translation)

polycrystal.diffract(beam, detector, motion)
diffraction_pattern = detector.render(frames_to_render=0, method='project')
polycrystal.diffract(beam,
detector,
motion,
proximity=True,
BB_intersection=True)

diffraction_pattern = detector.render(frames_to_render=0,
method='project',
lorentz=False,
polarization=False,
structure_factor=False)

plt.imshow(diffraction_pattern > 0, cmap='gray')
plt.title("Hits: " + str(len(detector.frames[0])))
Expand Down
49 changes: 23 additions & 26 deletions tests/end_to_end_tests/s3dxrd_odf_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,72 +12,70 @@

parameters = {
"detector_distance": 191023.9164,
"detector_center_pixel_z": 256.2345,
"detector_center_pixel_y": 255.1129,
"pixel_side_length_z": 181.4234,
"pixel_side_length_y": 180.2343,
"number_of_detector_pixels_z": 512,
"number_of_detector_pixels_y": 512,
"detector_center_pixel_z": 1024.938,
"detector_center_pixel_y": 1020.4516,
"pixel_side_length_z": 45.35585,
"pixel_side_length_y": 45.058575,
"number_of_detector_pixels_z": 2048,
"number_of_detector_pixels_y": 2048,
"wavelength": 0.285227,
"beam_side_length_z": 512 * 200.,
"beam_side_length_y": 512 * 200.,
"rotation_step": np.radians(10.0),
"beam_side_length_z": 102400.0,
"beam_side_length_y": 102400.0,
"rotation_step": np.radians(2.0),
"rotation_axis": np.array([0., 0., 1.0])
}

beam, detector, motion = templates.s3dxrd(parameters)

unit_cell = [4.926, 4.926, 5.4189, 90., 90., 120.]
sgname = 'P3221' # Quartz
path_to_cif_file = None
def orientation_density_function(x, q): return 1. / (np.pi**2) # uniform ODF.


number_of_crystals = 500
sample_bounding_cylinder_height = 256 * 180 / 128.
sample_bounding_cylinder_radius = 256 * 180 / 128.
number_of_crystals = 10000
sample_bounding_cylinder_height = parameters['pixel_side_length_z']
sample_bounding_cylinder_radius = parameters['pixel_side_length_y']
maximum_sampling_bin_seperation = np.radians(10.0)
# Linear strain gradient along rotation axis.


# Linear strain gradient along rotation axis.
def strain_tensor(x): return np.array(
[[0, 0, 0], [0, 0, 0], [0, 0, 0.02 * x[2] / sample_bounding_cylinder_height]])

# Make the beam much smaller than the sample
# vertices = beam.vertices.copy()
# vertices[:,1:] = 0.180*vertices[:,1:]/np.max(vertices[:,1:])
# beam.set_beam_vertices(vertices)


polycrystal = templates.polycrystal_from_odf(orientation_density_function,
number_of_crystals,
sample_bounding_cylinder_height,
sample_bounding_cylinder_radius,
unit_cell,
sgname,
path_to_cif_file,
maximum_sampling_bin_seperation,
strain_tensor)
path = os.path.join(
os.path.join(
os.path.dirname(__file__),
'saves'),
'polycrystal_from_odf')
'polycrystal_from_odf.pc')
polycrystal.save(path, save_mesh_as_xdmf=True)
polycrystal = Polycrystal.load(path)

# Full field diffraction.
# Full-field diffraction.
polycrystal.diffract(
beam,
detector,
motion,
min_bragg_angle=0,
max_bragg_angle=None,
verbose=True)
verbose=True,
proximity=True,
BB_intersection=True)

diffraction_pattern = detector.render(
frames_to_render=0,
lorentz=False,
polarization=False,
structure_factor=False,
method="centroid",
method="centroid_with_scintillator",
verbose=True)

pr.disable()
Expand All @@ -86,6 +84,5 @@ def strain_tensor(x): return np.array(
ps.print_stats(15)
print("")

diffraction_pattern[diffraction_pattern > 0] = 1
plt.imshow(diffraction_pattern, cmap='gray')
plt.imshow(diffraction_pattern, cmap='jet')
plt.show()
Binary file modified tests/end_to_end_tests/saves/fast_polycrystal_from_odf.h5
Binary file not shown.
Binary file modified tests/end_to_end_tests/saves/fast_polycrystal_from_odf.pc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<Xdmf Version="3.0"><Domain><Grid Name="Grid"><Geometry GeometryType="XYZ"><DataItem DataType="Float" Dimensions="27 3" Format="HDF" Precision="4">fast_polycrystal_from_odf.h5:/data0</DataItem></Geometry><Topology TopologyType="Tetrahedron" NumberOfElements="55" NodesPerElement="4"><DataItem DataType="Int" Dimensions="55 4" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data1</DataItem></Topology><Attribute Name="$\epsilon_{11}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data2</DataItem></Attribute><Attribute Name="$\epsilon_{22}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data3</DataItem></Attribute><Attribute Name="$\epsilon_{33}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data4</DataItem></Attribute><Attribute Name="$\epsilon_{12}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data5</DataItem></Attribute><Attribute Name="$\epsilon_{13}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data6</DataItem></Attribute><Attribute Name="$\epsilon_{23}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data7</DataItem></Attribute><Attribute Name="$\varphi_{1}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data8</DataItem></Attribute><Attribute Name="$\Phi$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data9</DataItem></Attribute><Attribute Name="$\varphi_{2}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data10</DataItem></Attribute><Attribute Name="Phases" AttributeType="Scalar" Center="Cell"><DataItem DataType="Int" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data11</DataItem></Attribute></Grid></Domain></Xdmf>
<Xdmf Version="3.0"><Domain><Grid Name="Grid"><Geometry GeometryType="XYZ"><DataItem DataType="Float" Dimensions="27 3" Format="HDF" Precision="4">fast_polycrystal_from_odf.h5:/data0</DataItem></Geometry><Topology TopologyType="Tetrahedron" NumberOfElements="55" NodesPerElement="4"><DataItem DataType="Int" Dimensions="55 4" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data1</DataItem></Topology><Attribute Name="Strain Tensor Component xx" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data2</DataItem></Attribute><Attribute Name="Strain Tensor Component yy" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data3</DataItem></Attribute><Attribute Name="Strain Tensor Component zz" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data4</DataItem></Attribute><Attribute Name="Strain Tensor Component xy" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data5</DataItem></Attribute><Attribute Name="Strain Tensor Component xz" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data6</DataItem></Attribute><Attribute Name="Strain Tensor Component yz" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data7</DataItem></Attribute><Attribute Name="Bunge Euler Angle phi_1 [degrees]" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data8</DataItem></Attribute><Attribute Name="Bunge Euler Angle Phi [degrees]" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data9</DataItem></Attribute><Attribute Name="Bunge Euler Angle phi_2 [degrees]" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data10</DataItem></Attribute><Attribute Name="Misorientation from mean orientation [degrees]" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data11</DataItem></Attribute><Attribute Name="Material Phase Index" AttributeType="Scalar" Center="Cell"><DataItem DataType="Int" Dimensions="55" Format="HDF" Precision="8">fast_polycrystal_from_odf.h5:/data12</DataItem></Attribute></Grid></Domain></Xdmf>
Binary file modified tests/end_to_end_tests/saves/polycrystal_from_odf.h5
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/end_to_end_tests/saves/polycrystal_from_odf.xdmf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<Xdmf Version="3.0"><Domain><Grid Name="Grid"><Geometry GeometryType="XYZ"><DataItem DataType="Float" Dimensions="88 3" Format="HDF" Precision="4">polycrystal_from_odf.h5:/data0</DataItem></Geometry><Topology TopologyType="Tetrahedron" NumberOfElements="280" NodesPerElement="4"><DataItem DataType="Int" Dimensions="280 4" Format="HDF" Precision="4">polycrystal_from_odf.h5:/data1</DataItem></Topology><Attribute Name="$\epsilon_{11}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="280" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data2</DataItem></Attribute><Attribute Name="$\epsilon_{22}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="280" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data3</DataItem></Attribute><Attribute Name="$\epsilon_{33}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="280" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data4</DataItem></Attribute><Attribute Name="$\epsilon_{12}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="280" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data5</DataItem></Attribute><Attribute Name="$\epsilon_{13}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="280" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data6</DataItem></Attribute><Attribute Name="$\epsilon_{23}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="280" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data7</DataItem></Attribute><Attribute Name="$\varphi_{1}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="280" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data8</DataItem></Attribute><Attribute Name="$\Phi$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="280" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data9</DataItem></Attribute><Attribute Name="$\varphi_{2}$" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="280" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data10</DataItem></Attribute><Attribute Name="Phases" AttributeType="Scalar" Center="Cell"><DataItem DataType="Int" Dimensions="280" Format="HDF" Precision="4">polycrystal_from_odf.h5:/data11</DataItem></Attribute></Grid></Domain></Xdmf>
<Xdmf Version="3.0"><Domain><Grid Name="Grid"><Geometry GeometryType="XYZ"><DataItem DataType="Float" Dimensions="2030 3" Format="HDF" Precision="4">polycrystal_from_odf.h5:/data0</DataItem></Geometry><Topology TopologyType="Tetrahedron" NumberOfElements="9748" NodesPerElement="4"><DataItem DataType="Int" Dimensions="9748 4" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data1</DataItem></Topology><Attribute Name="Strain Tensor Component xx" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="9748" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data2</DataItem></Attribute><Attribute Name="Strain Tensor Component yy" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="9748" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data3</DataItem></Attribute><Attribute Name="Strain Tensor Component zz" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="9748" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data4</DataItem></Attribute><Attribute Name="Strain Tensor Component xy" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="9748" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data5</DataItem></Attribute><Attribute Name="Strain Tensor Component xz" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="9748" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data6</DataItem></Attribute><Attribute Name="Strain Tensor Component yz" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="9748" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data7</DataItem></Attribute><Attribute Name="Bunge Euler Angle phi_1 [degrees]" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="9748" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data8</DataItem></Attribute><Attribute Name="Bunge Euler Angle Phi [degrees]" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="9748" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data9</DataItem></Attribute><Attribute Name="Bunge Euler Angle phi_2 [degrees]" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="9748" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data10</DataItem></Attribute><Attribute Name="Misorientation from mean orientation [degrees]" AttributeType="Scalar" Center="Cell"><DataItem DataType="Float" Dimensions="9748" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data11</DataItem></Attribute><Attribute Name="Material Phase Index" AttributeType="Scalar" Center="Cell"><DataItem DataType="Int" Dimensions="9748" Format="HDF" Precision="8">polycrystal_from_odf.h5:/data12</DataItem></Attribute></Grid></Domain></Xdmf>
Loading

0 comments on commit 21e58b6

Please sign in to comment.