# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # XRR & XRD Plotting
# ## This program plots XRR and XRD in separate plots, and puts an insert into the XRR of the XRD (002) peak

# +
import lattice
import xrayutilities as xu
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib import cm, rcParams, gridspec
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
import matplotlib.ticker as ticker
import numpy as np
import os

rcParams.update({'figure.autolayout': True})

# plot settings for matplotlib
mpl.rcParams['font.family'] = 'Arial'
mpl.rcParams['font.size'] = 10.0
mpl.rcParams['axes.labelsize'] = 'medium'
mpl.rcParams['figure.subplot.bottom'] = 0.16
mpl.rcParams['figure.subplot.left'] = 0.17
mpl.rcParams['savefig.dpi'] = 200
mpl.rcParams['axes.grid'] = False

# +
fxrd = r'C:\Users\olive\UNSW\<NAME> - Samples_Ralph_Dan\2017\DS17113_BFO_STO_110\DS17113_2theta.xrdml'


# %matplotlib widget
fig, ax = plt.subplots( figsize=(1,1) )
#ax.axis('off')
#gs = gridspec.GridSpec(nrows=2, ncols=2)


#xrdFile = ( xu.io.rigaku_ras.RASFile(fxrd) )

#ax1, dat1 = xu.io.getras_scan(xrdFile.filename+'%s', '', xrdFile.scans.scan_axis)
scatter = lattice()
om, ax1, dat1 = lattice.xrdml_file( fxrd )

#f2 = xrdFile.filename.rfind('\\')

#ax = fig.add_subplot( gs[:,:] ) 
ax.plot(dat1['TwoThetaOmega'], dat1['int']*dat1['att'], label='Data', color = 'black')
ax.set_xlabel( '2Theta (degrees)')
ax.set_ylabel( 'Intensity (a.u.)')
ax.set_yscale('log')
ax.set_xlim(15, 115)
#ax.set_title( xrdFile.filename[f2+1:-1 -3 ] )





# -

# # Add code to get thickness out of XRR oscillations

# +
x = dat0['TwoThetaOmega']
q = 4 * np.pi/1.54 * np.sin(np.radians(x[100:]/2))
y = dat0['int'][100:]*dat0['att'][100:]

fig, ax = plt.subplots()
ax.plot(q, y)
ax.set_xlim(0.03,0.4)
ax.set_yscale('log')
ax.set_ylabel('Intensity (a.u.)')
ax.set_xlabel('Q (A-1)')

# -



# +
x = dat0['TwoThetaOmega']
q = 4 * np.pi/1.54 * np.sin(np.radians(x[100:]/2))
#q = [val for val in q if val > 0.05 and val < 0.3]
y = np.log10( dat0['int'][100:]*dat0['att'][100:] )


# -

plt.plot(q, y)

# +
x = dat0['TwoThetaOmega']
q = 4 * np.pi/1.54 * np.sin(np.radians(x/2))
q = [val for val in q if val > 0.1 and val < 0.3]
y = np.log10( dat0['int']*dat0['att'] )
#y = [val if b in q < for val in y if b fo]

yt = [ i  for i in y if ( (x > 0.1 and x < 0.3) for x in q)  ]

N = int(len(q)/2)
T = q[1] - q[0]
d = 2* np.pi / np.array(q)
xf = np.linspace(0, 1 /(2.0*T), N//2)
yf = 2.0/ N * np.abs(fft(np.log10(y[0:N//2])))

print(len(q))
print(len(yt))
#fig, ax = plt.subplots()
#ax.plot(d, yf )
#ax.set_yscale('log')
#2.0/N * np.abs(yf[0:N//2])
# -

len(x)

len(y)

x[0]

fig, ax = plt.subplots()
ax.plot(fft_y)
#ax.set_xlim(0.03,1000)
#ax.set_yscale('log')
#ax.set_ylabel('Intensity (a.u.)')
#ax.set_xlabel('Q (A-1)')




StarcoderdataJupyterScriptsDedupFiltered