-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProfileExtraction.py
66 lines (39 loc) · 1.71 KB
/
ProfileExtraction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from __future__ import print_function
from __future__ import division
import numpy as np
def find_center(image,beam_stop=False):
"""
Find the center of the image
Inputs:
image : np.array, contains the diffraction data to analyze
beam_stop : boolean, represents whether the beamstop is present in the image
Outputs:
center: tuple(x,y), the index coordinates of the central peak
"""
if beam_stop:
raise ValueError("Beam stop analysis not implemented yet.")
else:
# We exclude the top n=3 pixels to avoid weird interactions on the detector
ordered_points = np.dstack(np.unravel_index(np.argsort(image.ravel()), image.shape))[:,:-2]
# Extract the nth pixel from the list ordered on intensity.
center = ordered_points[:,-3][0]
return center
def radial_profile(data, center,bins=1):
"""
Create the azimuthal integration from the data
Inputs:
data : np.array, contains the diffraction data to analyze
center : tuple(x,y), the index coordinates of the central peak
Outputs:
radius : np.array(1,N), range of pixel distance
brightness : np.array(1,N), array of values for the integration
"""
# Create the indicies array masked array
y,x = np.indices((data.shape)) # first determine radii of all pixels
# Modify the indicies to incorporate pixel distance
r = np.sqrt((x-center[1])**2+(y-center[0])**2)
# Radius of the image
r_max = np.max(r)
# Evaluate the brightnesses of each ring in the indicies array
ring_brightness, radius = np.histogram(r, weights=data, bins=int(r_max)//bins)
return radius[1:], ring_brightness