@@ -426,30 +426,6 @@ def pointlist_to_array(
426426 return points_array
427427
428428
429- def pointlist_differences (aperture_position , points_array ):
430- """
431- calculates Euclidean distances between a specific aperture position
432- and a whole list of detected points for a dataset
433-
434- Parameters
435- ----------
436- aperture_position: tuple
437- 2-element vector of the diffraction space shape of a position of an aperture
438- points_array: numpy array
439- as produced by pointlist_to_array and defined in docstring for that function
440-
441- Returns
442- ----------
443- diff: numpy array
444- the Euclidean distances as a 1D numpy array
445- """
446- subtractor = np .array (
447- [[aperture_position [0 ], aperture_position [1 ]] * points_array .shape [0 ]]
448- ).reshape ((points_array .shape [0 ], 2 ))
449- diff = ((points_array [:, :2 ] - subtractor ) ** 2 ).sum (axis = 1 ) ** 0.5
450- return diff
451-
452-
453429def DDFimage (points_array , aperture_positions , Rshape = None , tol = 1 ):
454430 """
455431 Calculates a Digital Dark Field image from a list of detected diffraction peak positions in a points_array and a list of aperture_positions, within a defined matching tolerance
@@ -481,19 +457,27 @@ def DDFimage(points_array, aperture_positions, Rshape=None, tol=1):
481457 )
482458
483459 image = np .zeros (Rshape )
460+
484461 for aperture_index in tqdmnd (len (aperture_positions )):
462+ # Pick one of the aperture positions
485463 aperture_position = aperture_positions [aperture_index ]
486- intensities = np .vstack (
464+ # Calculate vector differences
465+ differences = points_array [:, :2 ] - aperture_position
466+ # Calculate normalised distances
467+ diffnorm = (differences ** 2 ).sum (axis = 1 ) ** 0.5
468+ # Append these norms to the ends of each row for each spot
469+ intensities = np .hstack (
487470 (
488- points_array [:, 2 :5 ]. T ,
489- pointlist_differences ( aperture_position , points_array ) ,
471+ points_array [:, 2 :5 ],
472+ diffnorm [:, np . newaxis ] ,
490473 )
491- ).T
474+ )
475+ # Delete all spots for which the norm is larger than tolerance
492476 intensities2 = np .delete (intensities , np .where (intensities [:, 3 ] > tol ), axis = 0 )
493- for row in range ( intensities2 [:, 0 ]. shape [ 0 ]):
494- image [
495- intensities2 [row , 1 ].astype (int ), intensities2 [row , 2 ].astype (int )
496- ] += intensities2 [row , 0 ]
477+ # Update the image with the remaining intensities sliced by the Rx and Ry positions
478+ image [
479+ intensities2 [: , 1 ].astype (int ), intensities2 [: , 2 ].astype (int )
480+ ] += intensities2 [: , 0 ]
497481 return image
498482
499483
0 commit comments