Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. #imports
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. import plotly.graph_objects as go
  5. from scipy.signal import find_peaks
  6. from tabulate import tabulate
  7.  
  8. #silicon standard
  9. SiNIST = np.loadtxt('SiNIST.csv', delimiter=',')
  10.  
  11. SiX = SiNIST[:,0]
  12. SiY = SiNIST[:,1]
  13.  
  14. SiIndices = find_peaks(SiY, prominence = 200)[0]
  15.  
  16. fig = go.Figure()
  17. fig.add_trace(go.Scatter(
  18.     y = SiY,
  19.     mode = 'lines',
  20.     line = dict(
  21.         color ='firebrick',
  22.         width = 1,
  23.     ),
  24.     showlegend = False
  25.     )
  26. )
  27.  
  28. fig.add_trace(go.Scatter(
  29.     x = SiIndices,
  30.     y = [SiY[j] for j in SiIndices],
  31.     mode ='markers',
  32.     marker = dict(
  33.         size = 5,
  34.         color = 'black',
  35.         symbol = 'x'
  36.     ),
  37.     name = 'Detected Peaks'
  38.     )
  39. )
  40.  
  41. fig.update_layout(
  42.     title = ({
  43.         'text': 'Silicon Standard Diffractogram',
  44.         'y': 0.9,
  45.         'x': 0.5,
  46.         'xanchor': 'center',
  47.         'yanchor': 'top'}),
  48.     xaxis_title = "2θ",
  49.     yaxis_title = "Intensity",
  50.     xaxis_showgrid = False,
  51.     font = dict(
  52.         family = 'Courier New, monospace',
  53.         size = 12,
  54.         color = '#000000'
  55.     )
  56. )
  57.  
  58. fig.update_xaxes(showticklabels = False),
  59.  
  60. fig.show()
  61.  
  62. plt.xlabel('2θ')
  63. plt.ylabel('Intensity')
  64. hideAxes = plt.gca()
  65. hideAxes.axes.get_xaxis().set_ticks([])
  66. hideAxes.axes.get_yaxis().set_ticks([])
  67. plt.plot(SiX, SiY, linewidth = '.5', color = 'black')
  68. plt.show()
  69.  
  70. for i, x, y in zip(SiIndices, SiX[SiIndices], SiY[SiIndices]):
  71.     headers = ['Peak', '2θ', 'Intensity']
  72.     table = zip(SiIndices, SiX[SiIndices], SiY[SiIndices])
  73.  
  74. print('\033[1m' + 'Detected Peaks:' + '\033[0m')
  75. print(tabulate(table, headers, tablefmt = 'pretty'))
  76.  
  77. #silicon standard full list
  78. peakSi = []
  79.  
  80. for i, (x, y) in enumerate(zip(SiX, SiY)):
  81.     peakSi.append(i)
  82.  
  83. headers = ['Peak', '2θ', 'Intensity']
  84. table = zip(peakSi, SiX, SiY)
  85.  
  86. np.set_printoptions(threshold = np.inf)
  87. print(tabulate(table, headers, tablefmt = 'pretty'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement