velocity calibration
[1]:
import nexus as nx
import numpy as np
import matplotlib.pyplot as plt
import scipy
data loading
[2]:
data = np.loadtxt('Fe_calibration.dat')
processed_data = data
plt.plot(data)
plt.xlabel("data point")
plt.ylabel("counts")
plt.show()
print('number of data points: {}'.format(len(data)))
number of data points: 1024
folding
[3]:
# in version 1
#processed_data, lag = nx.data.AutoFold(processed_data,
# flip = 'right', # determies which part of the spectrum is fliped
# factor = 100, # interpolation on a 100 times finer grid
# method = "linear") # or cubic, PChip, Akima
# since version 2
processed_data, lag, additional_data = nx.data.AutoFold(processed_data,
flip = 'right', # determies which part of the spectrum is fliped
factor = 100, # interpolation on a 100 times finer grid
method = "linear") # or cubic, PChip, Akima
print('lag: {}'.format(lag))
lag: -0.92
normalization
[4]:
processed_data, norm_factor = nx.data.Normalize(processed_data,
method = "baseline", # 'max', 'min'
#left_point=20,
#right_point=250,
#poly_order = 1 # use in case you want to correct a tilted baseline
)
velocity calibration
[5]:
# provide approximate velocity of experiment
approximate_veclocity = 9.7
[6]:
velocities, offset, scaling, vel_theo, int_theo = nx.data.CalibrateChannelsAlphaFe(
intensity = processed_data,
velocity = approximate_veclocity,
thickness = 10e3,
Bhf = 33.3,
mode = "constant",
shift = 0.0)
print("min / max velocity in experiment (mm/s): {} and {}\n".format(min(velocities), max(velocities)))
print("offset (mm/s): {}".format(offset))
min / max velocity in experiment (mm/s): -9.980639600297627 and 10.012891688745439
offset (mm/s): -0.01612604422390662
[7]:
plt.plot(velocities, processed_data)
plt.plot(vel_theo, int_theo)
plt.xlabel("velocity (mm/s)")
plt.ylabel("intensity")
plt.show()
[8]:
# save a file with the velocity calibration
np.savetxt('velocity_calibration.dat', velocities)
line fits - resolution and area ratio
[9]:
# provide number of peaks in spectrum
number_of_peaks = 6
[10]:
# get a fit of n Lorentzians
n_peaks, p_indices, p_velocity, p_intensity, p_widths, p_areas, baseline, Lorentzian_fit = nx.data.GetLorentzian(
velocities,
processed_data,
n = number_of_peaks,
neg = True,
#baseline = 1.0, # provide a fixed baseline if needed
rel_prominence = 0.1
)
print(n_peaks)
6
[11]:
plt.plot(velocities, processed_data)
plt.plot(velocities, Lorentzian_fit)
plt.xlabel("velocity (mm/s)")
plt.ylabel("intensity")
plt.show()
[12]:
print("peaks at index:")
print(*p_indices)
print("")
print("peaks at velocity (mm/s):")
print(*p_velocity)
peaks at index:
118 176 234 276 334 392
peaks at velocity (mm/s):
-5.366797051460252 -3.1071924231402313 -0.8461511790180146 0.8490115868522181 3.100029091227008 5.367881168963467
[13]:
print("line width values (FWHM, mm/s):")
print(*p_widths)
print("")
widths = []
for i in range(len(p_widths)//2):
widths.append( (p_widths[i] + p_widths[-(i+1)]) / 2)
print("average of lines (FWHM, mm/s):")
print(*widths)
line width values (FWHM, mm/s):
0.3045169050884089 0.2922414810772542 0.277993646109264 0.32744885627768977 0.2940628802185117 0.3113054562669307
average of lines (FWHM, mm/s):
0.30791118067766976 0.29315218064788295 0.3027212511934769
[14]:
# resolution from the two inner lines
resolution_value = widths[-1]
print("resolution value (mm/s): {:.3f}\n".format(resolution_value))
resolution_gamma = nx.conversions.VelocityToGamma(resolution_value, nx.lib.moessbauer.Fe57)
print("resolution value (\u0393): {:.3f}\n".format(resolution_gamma))
experiment_resolution = resolution_gamma - 1
print("experimental resolution (resolution value - natural linewidth) (\u0393): {:.3f}".format(experiment_resolution))
print("")
print("use this value as the resolution input when fitting a MoessbauerSpectrum, e.g.")
print("... = MoessbauerSpectrum(..., resolution = experiment_resolution, ...)")
resolution value (mm/s): 0.303
resolution value (Γ): 3.120
experimental resolution (resolution value - natural linewidth) (Γ): 2.120
use this value as the resolution input when fitting a MoessbauerSpectrum, e.g.
... = MoessbauerSpectrum(..., resolution = experiment_resolution, ...)
[15]:
areas, area_ratio = nx.data.GetAreas(velocities,
processed_data,
n = number_of_peaks,
neg = True)
norm_ar = np.array(area_ratio) / np.min(area_ratio)
print("area ratios of total area:")
print(*area_ratio)
print("")
print("normalized area ratios (to 3rd line):")
print(*norm_ar)
print("")
A23 = areas[1]/areas[2]
print("A23: {}".format(A23))
area ratios of total area:
0.15761494665629888 0.10486322351441205 0.05649166267638642
normalized area ratios (to 3rd line):
2.7900567834088927 1.856260172675799 1.0
A23: 1.856260172675799
[ ]: