-
Notifications
You must be signed in to change notification settings - Fork 1
/
dspacing.py
42 lines (34 loc) · 1.01 KB
/
dspacing.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
import csv
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib import pyplot as plt
from scipy.signal import find_peaks
import numpy as np
def get_column_data(numcol, numrows, datacsv):
datatotal = []
for i in range(1, numrows):
data = datacsv[i][numcol]
if data != '':
data = float(data)
datatotal.append(data)
return np.asarray(datatotal).astype(float)
datacsv = []
csvfile = open('values.csv')
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
datacsv.append(row)
csvfile.close()
numrows = len(datacsv)
numcolumns = len(datacsv[1])
xdata = get_column_data(0, numrows, datacsv)
ydata = get_column_data(1, numrows, datacsv)
peaks, _ = find_peaks(ydata, height=3)
print(peaks)
print(xdata[peaks])
maxspacings = xdata[peaks]
dspacings = [x - maxspacings[i - 1] for i, x in enumerate(maxspacings)][1:]
print("d spacing (nm): ", np.nanmedian(dspacings))
plt.plot(xdata, ydata)
plt.plot(xdata[peaks], ydata[peaks], "x")
plt.tight_layout()
plt.show()