The experimentatl X-ray Photon Correlation Sepectroscopy(XPCS) data are fitted with Intermediate Scattering Factor(ISF) using lmfit Model (http://lmfit.github.io/lmfit-py/model.html)
In [1]:
# analysis tools from scikit-xray (https://github.com/scikit-xray/scikit-xray/tree/master/skxray/core)
import skxray.core.roi as roi
import skxray.core.correlation as corr
import skxray.core.utils as utils
from lmfit import minimize, Parameters, Model
# plotting tools from xray_vision (https://github.com/Nikea/xray-vision/blob/master/xray_vision/mpl_plotting/roi.py)
import xray_vision.mpl_plotting as mpl_plot
import numpy as np
import os, sys
import zipfile
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
from matplotlib.colors import LogNorm
In [9]:
interactive_mode = False
if interactive_mode:
%matplotlib notebook
else:
%matplotlib inline
backend = mpl.get_backend()
In [3]:
#folder = "/Volumes/Data/BeamLines/CHX/Luxi_description_files_for_duke/Duke_data"
folder = os.path.join(*__file__.split(os.sep)[:-1])
# Get the data and the mask
try:
duke_data = np.load(os.path.join(folder, "duke_data", "duke_data.npy"))
N_mask = np.load(os.path.join(folder, "duke_data", "N_mask.npy"))
except IOError:
zipfile.ZipFile(os.path.join(folder, "duke_data.zip")).extractall()
duke_data = np.load(os.path.join(folder, "duke_data", "duke_data.npy"))
N_mask = np.load(os.path.join(folder, "duke_data", "N_mask.npy"))
# get the average image
avg_img = np.average(duke_data, axis=0)
# plot the average image data after masking
plt.figure()
plt.imshow(N_mask*avg_img, vmax=1e0, cmap="Dark2" )
plt.title("Averaged masked data for Duke Silica Gel ")
plt.colorbar()
plt.show()
Use the skxray.core.roi module to create Ring ROIs (ROI Mask)¶ (https://github.com/scikit-xray/scikit-xray/blob/master/skxray/core/roi.py)
In [4]:
inner_radius = 24 # radius of the first ring
width = 1 # width of each ring
spacing = 0 # no spacing between rings
num_rings = 5 # number of rings
center = (133, 143) # center of the spckle pattern
# find the edges of the required rings
edges = roi.ring_edges(inner_radius, width, spacing, num_rings)
edges
Out[4]:
In [5]:
dpix = 0.055 # The physical size of the pixels
lambda_ = 1.5498 # wavelength of the X-rays
Ldet = 2200. # # detector to sample distance
two_theta = utils.radius_to_twotheta(Ldet, edges*dpix)
q_val = utils.twotheta_to_q(two_theta, lambda_)
q_val
Out[5]:
In [6]:
q_ring = np.mean(q_val, axis=1)
q_ring
Out[6]:
In [8]:
rings = roi.rings(edges, center, avg_img.shape)
mask_data2 = N_mask*duke_data[0:4999]
ring_mask = rings*N_mask
# plot the figure
fig, axes = plt.subplots()
axes.set_title("Ring Mask")
im = mpl_plot.show_label_array(axes, ring_mask, cmap="Dark2")
plt.show()
Use the skxray.core.correlation module (https://github.com/scikit-xray/scikit-xray/blob/master/skxray/core/correlation.py)
In [10]:
num_levels = 7
num_bufs = 8
g2, lag_steps = corr.multi_tau_auto_corr(num_levels, num_bufs, ring_mask,
mask_data2)
exposuretime=0.001;
deadtime=60e-6;
timeperframe = exposuretime+deadtime
lags = lag_steps*timeperframe
roi_names = ['gray', 'orange', 'brown', 'red', 'green']
fig, axes = plt.subplots(num_rings, sharex=True, figsize=(5, 14))
axes[num_rings-1].set_xlabel("lags")
for i, roi_color in zip(range(num_rings), roi_names):
axes[i].set_ylabel("g2")
axes[i].set_title(" Q ring value " + str(q_ring[i]))
axes[i].semilogx(lags, g2[:, i], 'o', markerfacecolor=roi_color, markersize=6)
axes[i].set_ylim(bottom=1, top=np.max(g2[1:, i]))
plt.show()
One time correlation data is fitted using the model in skxray.core.correlation module (auto_corr_scat_factor) (https://github.com/scikit-xray/scikit-xray/blob/master/skxray/core/correlation.py)
In [11]:
mod = Model(corr.auto_corr_scat_factor)
In [12]:
out1 = mod.eval(lags=lags, beta=0.2234, relaxation_rate = 6.2567, baseline=1.0)
result1 = mod.fit(out1, lags=lags, beta=0.2230, relaxation_rate = 6.2500, baseline=1.0)
plt.figure()
plt.semilogx(lags, g2[:, 0], 'ro')
plt.semilogx(lags, result1.best_fit, '-b')
plt.ylim(1.0, 1.3)
plt.title("Q ring value "+str(q_ring[0]))
plt.show()
In [14]:
out2 = mod.eval(lags=lags, beta=0.2234, relaxation_rate=6.9879, baseline=1.000)
result2 = mod.fit(out2, lags=lags, beta=0.22456, relaxation_rate=6.98789, beseline=1.00)
plt.figure()
plt.semilogx(lags, g2[:, 2], 'ro')
plt.semilogx(lags, result2.best_fit, '-b')
plt.ylim(1., 1.3)
plt.title("Q ring value "+ str(q_ring[2]))
plt.show()
In [15]:
import skxray
print(skxray.__version__)
In [ ]: