In [1]:
import os
import sys
root_folder = os.path.dirname(os.getcwd())
sys.path.append(root_folder)
import ResoFit
from ResoFit.calibration import Calibration
from ResoFit.fitresonance import FitResonance
from ResoFit.experiment import Experiment
from ResoFit._utilities import Layer
import numpy as np
import matplotlib.pyplot as plt
In [2]:
energy_min = 7
energy_max = 150
energy_step = 0.01
In [3]:
folder = 'data/_data_for_tutorial'
data_file = 'raw_data.csv'
spectra_file = 'spectra.txt'
In [4]:
experiment = Experiment(data_file=data_file,
spectra_file=spectra_file,
folder=folder)
In [5]:
experiment.data
Out[5]:
In [6]:
experiment.spectra
Out[6]:
In [7]:
experiment.slice(slice_start=3, slice_end=2801, reset_index=False)
Out[7]:
In [8]:
experiment.x_raw(offset_us=0., source_to_detector_m=16)
Out[8]:
In [9]:
experiment.x_raw(angstrom=True, offset_us=0., source_to_detector_m=16)
Out[9]:
In [10]:
experiment.y_raw()
Out[10]:
In [11]:
experiment.y_raw(transmission=True)
Out[11]:
In [12]:
experiment.y_raw(baseline=True)
Out[12]:
In [13]:
experiment.xy_scaled(energy_min=energy_min, energy_max=energy_max, energy_step=energy_step,
angstrom=False, transmission=False,
offset_us=0, source_to_detector_m=15,
baseline=True)
Out[13]:
In [14]:
experiment.plot_raw(x_axis='number')
plt.show()
In [15]:
experiment.plot_raw(x_axis='time')
plt.show()
In [16]:
experiment.plot_raw(x_axis='time', time_unit='s')
plt.show()
In [17]:
experiment.plot_raw(x_axis='lambda', lambda_xmax=0.12,
offset_us=0, source_to_detector_m=16)
plt.show()
In [18]:
experiment.plot_raw(x_axis='energy', energy_xmax=150,
offset_us=0, source_to_detector_m=16)
plt.show()
In [19]:
experiment.plot_raw(offset_us=0, source_to_detector_m=16,
x_axis='energy', baseline=True,
energy_xmax=150)
plt.show()
In [20]:
layer_1 = 'U'
thickness_1 = 0.05 # mm
density_1 = None # g/cm^3 (if None or omitted, pure solid density will be used in fitting step)
layer_2 = 'Gd'
thickness_2 = 0.05 # mm
density_2 = None # g/cm^3 (if None or omitted, pure solid density will be used in fitting step)
Note: Input each element as single layer.
In [21]:
layer = Layer()
layer.add_layer(layer=layer_1, thickness_mm=thickness_1, density_gcm3=density_1)
layer.add_layer(layer=layer_2, thickness_mm=thickness_2, density_gcm3=density_2)
Note: a separated Experiment() will be created after the initialization of Calibration(). Calibration.slice() is needed if you would like to remove unwanted data points by indexes.
In [22]:
source_to_detector_m = 16.
offset_us = 0
In [23]:
calibration = Calibration(data_file=data_file,
spectra_file=spectra_file,
raw_layer=layer,
energy_min=energy_min,
energy_max=energy_max,
energy_step=energy_step,
folder=folder,
baseline=True)
$E$ : energy in (meV),
$\lambda$ : wavelength in (Å).
$$\lambda = 0.3956\frac{t_{record} + t_{offset}}{L}$$$t_{record}$ : recorded time in (µs),
$t_{offset}$ : recorded time offset in (µs),
$L$ : source to detector distance in (cm).
In [24]:
calibration.calibrate(source_to_detector_m=source_to_detector_m,
offset_us=offset_us,
vary='all')
Out[24]:
In [25]:
calibration.calibrated_offset_us
Out[25]:
In [26]:
calibration.calibrated_source_to_detector_m
Out[26]:
In [27]:
calibration.plot()
In [28]:
calibration.plot(table=False)
In [29]:
calibration.plot(table=False, grid=False)
In [30]:
calibration.plot(table=False, grid=False, before=True)
In [31]:
calibration.plot(table=False, grid=False, all_elements=True)
In [32]:
calibration.plot(table=False, grid=False, all_isotopes=True)
In [33]:
calibration.plot(table=False, grid=False, items_to_plot=['U', 'U-238', 'Gd-156'])
Note: 'U*' can be used to represent all the isotopes of uranium
In [34]:
calibration.plot(table=False, grid=False, items_to_plot=['U', 'U*', 'Gd-156'])
In [35]:
fit = FitResonance(spectra_file=spectra_file,
data_file=data_file,
folder=folder,
energy_min=energy_min,
energy_max=energy_max,
energy_step=energy_step,
calibrated_offset_us=calibration.calibrated_offset_us,
calibrated_source_to_detector_m=calibration.calibrated_source_to_detector_m,
baseline=True)
${ N }_{ i }$ : number of atoms per unit volume of element $i$,
${ d }_{ i }$ : effective thickness along the neutron path of element $i$,
${ \sigma }_{ ij }\left( E \right)$ : energy-dependent neutron total cross-section for the isotope $j$ of element $i$,
${ A }_{ ij }$ : abundance for the isotope $j$ of element $i$.
$${N_i} = {N_A}{C_i} = \frac { {N_A}{\rho_i}} {\sum\nolimits_j {m_{ij}{A_{ij}}}}$$${N_A}$ : Avogadro’s number,
${C_i}$ : molar concentration of element $i$,
${\rho_i}$ : density of the element $i$,
$m_{ij}$ : atomic mass values for the isotope $j$ of element $i$.
In [36]:
fit_result = fit.fit(layer, vary='density')
In [37]:
fit.molar_conc()
Out[37]:
In [38]:
fit.plot()
In [39]:
fit.plot(error=False)
In [40]:
fit.plot(table=False)
In [41]:
fit.plot(table=False, grid=False, before=True)
In [42]:
fit.plot(table=False, grid=False, all_elements=True)
In [43]:
fit.plot(table=False, grid=False, all_isotopes=True)
In [44]:
fit.plot(table=False, grid=False, items_to_plot=['U', 'U-238', 'Gd-156'])
In [45]:
fit.plot(table=False, grid=False, items_to_plot=['U', 'U*', 'Gd-156'])
In [46]:
fit.fit_iso(layer='U')
In [47]:
fit.molar_conc()
Out[47]:
In [48]:
fit.plot()