44# Suitable for both s3DXRD using pencil beam and box-beam 3DXRD
55# Haixing Fang, haixing.fang@esrf.fr
66# Jan 2nd, 2025
7- # updated on January 30, 2025
7+ # version 1.0: updated on January 30, 2025
8+ # version 1.1: fixed a bug with ray origin on December 10, 2025
89
910import numpy as np
1011from matplotlib import pyplot as plt
@@ -726,7 +727,7 @@ def read_cf(self):
726727 self .cf_4d = colfile_from_hdf (self .cf_4d_file )
727728 self .peaks_4d = io .convert_cf_to_fwd_peaks (self .cf_4d )
728729 if self .verbose >= 1 :
729- logging .info ('loaded 4D peaks from {}' .format (self .cf_4d_file ))
730+ logging .info ('loaded 4D peaks from {}' .format (self .cf_4d_file ))
730731 else :
731732 self .get_cf ()
732733
@@ -973,11 +974,17 @@ def intersected_sample_pos(mask, dty = 0.0, y0_offset = 0.0, voxel_size = [1.0,
973974
974975 if not isinstance (voxel_size , np .ndarray ):
975976 voxel_size = np .array (voxel_size , dtype = 'float' )
977+ #Omega = forward_model.get_omega_matrix(np.deg2rad(-omega))
978+ #ray_direction = np.dot(Omega, [1.0, 0.0, 0.0])
979+ #grid_size = mask.shape
980+ #assert len(grid_size) == 3, "The input mask must be in 3D"
981+ #ray_origin = [0.0, -dty - y0_offset, 0.0]
982+
976983 Omega = forward_model .get_omega_matrix (np .deg2rad (- omega ))
977984 ray_direction = np .dot (Omega , [1.0 , 0.0 , 0.0 ])
978985 grid_size = mask .shape
979986 assert len (grid_size ) == 3 , "The input mask must be in 3D"
980- ray_origin = [0.0 , - dty - y0_offset , 0.0 ]
987+ ray_origin = np . dot ( Omega , [0.0 , - dty - y0_offset , 0.0 ]) # the absolute distance between the ray and the rotation center keeps as a constant of dty+y0_offset
981988
982989 intersected_voxels = intersected_voxels_3d (grid_size , ray_origin , ray_direction , voxel_size = voxel_size ,
983990 ray_size = ray_size , weight = weight , weight_pos = weight_pos , mask = mask , plot_flag = plot_flag )
@@ -1028,8 +1035,12 @@ def intersected_voxels_3d(grid_size, ray_origin, ray_direction, voxel_size = [1.
10281035 grid_extent = np .array (grid_size ) * voxel_size
10291036 max_extent = np .linalg .norm (grid_extent )
10301037
1031- t_values = np .linspace (- 0.707 * max_extent + ray_origin [1 ], 0.707 * max_extent + ray_origin [1 ], int (max (grid_size )* 1.414 ))
1032- ray_shift = np .array ([grid_size [1 ] / 2 + 0.5 , grid_size [1 ] / 2 + 0.5 , 0.0 ]) * voxel_size
1038+ #t_values = np.linspace(-0.707 * max_extent + ray_origin[1], 0.707 * max_extent + ray_origin[1], int(max(grid_size)*1.414))
1039+ #ray_shift = np.array([grid_size[1] / 2 + 0.5, grid_size[1] / 2 + 0.5, 0.0]) * voxel_size
1040+ #ray_path = np.array(ray_origin) / voxel_size + ray_shift + np.outer(t_values, ray_direction)
1041+
1042+ t_values = np .linspace (- 0.707 * max_extent + np .linalg .norm (ray_origin ), 0.707 * max_extent + np .linalg .norm (ray_origin ), int (max (grid_size )* 1.414 ))
1043+ ray_shift = np .array ([grid_size [0 ] / 2 + 0.5 , grid_size [1 ] / 2 + 0.5 , 0.0 ]) * voxel_size
10331044 ray_path = np .array (ray_origin ) / voxel_size + ray_shift + np .outer (t_values , ray_direction )
10341045
10351046 tol_distances = np .array (weight_pos )* ray_size
@@ -1348,11 +1359,11 @@ def ensure_2d_array(target_hkls):
13481359
13491360def plot_fwd_peaks (fwd_peaks ):
13501361 assert fwd_peaks .shape [1 ] == 25 , "fwd_peaks shapes are not qualified"
1351- f , ax = plt .subplots (1 , 2 , figsize = (15 , 9 ))
1362+ f , ax = plt .subplots (1 , 2 , figsize = (12 , 6 ))
13521363
13531364 sc = ax [0 ].scatter (fwd_peaks [:, 18 ], fwd_peaks [:, 19 ], c = fwd_peaks [:, 23 ], cmap = 'viridis' , s = 8 )
13541365 ax [0 ].set_aspect ('equal' , 'box' )
1355- cb = f .colorbar (sc , ax = ax [0 ])
1366+ cb = f .colorbar (sc , ax = ax [0 ], fraction = 0.046 , pad = 0.04 )
13561367 # cb.set_label('Intensity', fontsize = 20)
13571368 cb .ax .tick_params (labelsize = 14 )
13581369 ax [0 ].set_xlabel ('fc (pixel)' , fontsize = 20 )
@@ -1363,7 +1374,7 @@ def plot_fwd_peaks(fwd_peaks):
13631374
13641375 sc = ax [1 ].scatter (fwd_peaks [:, 5 ], fwd_peaks [:, 6 ], c = fwd_peaks [:, 23 ], cmap = 'viridis' , s = 8 )
13651376 ax [1 ].set_aspect ('equal' , 'box' )
1366- cb = f .colorbar (sc , ax = ax [1 ])
1377+ cb = f .colorbar (sc , ax = ax [1 ], fraction = 0.046 , pad = 0.04 )
13671378 cb .set_label ('Intensity' , fontsize = 20 )
13681379 cb .ax .tick_params (labelsize = 14 )
13691380 ax [1 ].set_xlabel ('X (mm)' , fontsize = 20 )
0 commit comments