Skip to content

Commit

Permalink
Lorentz factor is creating asymmetrical intensity in the y direction
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcraven committed Oct 21, 2024
1 parent ee5acfd commit dd86062
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
5 changes: 2 additions & 3 deletions xrd_simulator/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import numpy as np
import pandas as pd
# Default to False
fw = torch

fw = np

# ===============================================
try:
Expand All @@ -12,10 +11,10 @@
print("CUDA is available and GPUs are found.")
gpu = input("Do you want to run in GPU? [y/n]").strip().lower() or 'y'
if gpu == 'y':
fw = torch
torch.set_default_device('cuda')
print("Running in GPU...")
else:
torch.set_default_device('cpu')
print("Running in CPU...")
else:
print("CUDA is not available.")
Expand Down
13 changes: 12 additions & 1 deletion xrd_simulator/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def render(self,
"""
# Intersect scattering vectors with detector plane
zd_yd_angle = self.get_intersection(peaks[:,13:16],peaks[:,16:19])


if fw is np:
peaks = fw.concatenate((peaks,zd_yd_angle),axis=1)
else:
Expand All @@ -148,6 +150,7 @@ def render(self,
frames = fw.bucketize(peaks[:,6].contiguous(), bin_edges).unsqueeze(1)-1
peaks = fw.cat((peaks,frames),dim=1)

# Create a 3 colum matrix with X,Y and frame coordinates for each peak
if fw is np:
pixel_indices = fw.concatenate(
(((peaks[:, 21])/self.pixel_size_z).reshape(-1, 1),
Expand All @@ -166,8 +169,16 @@ def render(self,
rendered_frames = fw.zeros((frames_n,self.pixel_coordinates.shape[0],self.pixel_coordinates.shape[1]),dtype=fw.float32)
# Generate the relative intensity for all the diffraction peaks using the different factors.
structure_factors = peaks[:,5]
lorentz_factors = peaks[:,22]
lorentz_factors = peaks[:,22]
polarization_factors = peaks[:,23]
# peaks = peaks.cpu().numpy()
# plt.subplot(1,3,1)
# plt.scatter(peaks[:,22],peaks[:,5],s=1)
# plt.subplot(1,3,2)
# plt.scatter(peaks[:,22],peaks[:,22],s=1)
# plt.subplot(1,3,3)
# plt.scatter(peaks[:,22],peaks[:,23],s=1)
# plt.show()
relative_intensity = structure_factors*lorentz_factors*polarization_factors

# Turn from lists of peaks to rendered frames
Expand Down
27 changes: 13 additions & 14 deletions xrd_simulator/polycrystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,19 @@ def _diffract(dict):
peaks = fw.cat((peaks,Gxyz,K_out_xyz,Sources_xyz,lorentz_factors.unsqueeze(1),polarization_factors.unsqueeze(1)),dim=1)


"""
Column names of peaks are
0: 'grain_index' 10: 'Gx' 20: 'yd'
1: 'phase_number' 11: 'Gy' 21: 'Incident_angle'
2: 'h' 12: 'Gz' 22: 'lorentz_factors'
3: 'k' 13: 'K_out_x' 23: 'polarization_factors'
4: 'l' 14: 'K_out_y' 24: 'frames_to_render'
5: 'structure_factors' 15: 'K_out_z'
6: 'diffraction_times' 16: 'Source_x'
7: 'G0_x' 17: 'Source_y'
8: 'G0_y' 18: 'Source_z'
9: 'G0_z' 19: 'zd'
"""

"""
Column names of peaks are
0: 'grain_index' 10: 'Gx' 20: 'polarization_factors'
1: 'phase_number' 11: 'Gy'
2: 'h' 12: 'Gz'
3: 'k' 13: 'K_out_x'
4: 'l' 14: 'K_out_y'
5: 'structure_factors' 15: 'K_out_z'
6: 'diffraction_times' 16: 'Source_x'
7: 'G0_x' 17: 'Source_y'
8: 'G0_y' 18: 'Source_z'
9: 'G0_z' 19: 'lorentz_factors'
"""
# Filter out tets not illuminated
peaks = peaks[peaks[:,17] < (beam.vertices[:, 1].max())]
peaks = peaks[peaks[:,17] > (beam.vertices[:, 1].min())]
Expand Down

0 comments on commit dd86062

Please sign in to comment.