From dd8606205cc867de5c64a3385bd502a5e2738a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Ravent=C3=B3s?= Date: Mon, 21 Oct 2024 12:10:06 +0200 Subject: [PATCH] Lorentz factor is creating asymmetrical intensity in the y direction --- xrd_simulator/cuda.py | 5 ++--- xrd_simulator/detector.py | 13 ++++++++++++- xrd_simulator/polycrystal.py | 27 +++++++++++++-------------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/xrd_simulator/cuda.py b/xrd_simulator/cuda.py index 5158fc5..cee2761 100644 --- a/xrd_simulator/cuda.py +++ b/xrd_simulator/cuda.py @@ -2,8 +2,7 @@ import numpy as np import pandas as pd # Default to False -fw = torch - +fw = np # =============================================== try: @@ -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.") diff --git a/xrd_simulator/detector.py b/xrd_simulator/detector.py index 9122f41..7d08780 100644 --- a/xrd_simulator/detector.py +++ b/xrd_simulator/detector.py @@ -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: @@ -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), @@ -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 diff --git a/xrd_simulator/polycrystal.py b/xrd_simulator/polycrystal.py index 424492f..863ba53 100644 --- a/xrd_simulator/polycrystal.py +++ b/xrd_simulator/polycrystal.py @@ -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())]