<jupyter_start><jupyter_text>Gaussian ComponentsHow to extract the background-subtracted Gaussian components of peaks, plot them, and display table with values<jupyter_code>import pandas as pd
from nasagamma import spectrum as sp
from nasagamma import peaksearch as ps
from nasagamma import peakfit as pf
import matplotlib.pyplot as plt
import numpy as np<jupyter_output><empty_output><jupyter_text>The next piece of code isidentical to "4.energy-calibration"<jupyter_code>file = "data/10-23-2020-800-3.csv"
# the columns are not in a 'nice' format (blank spaces)
# so, rename them
dict0 = {" Energy (keV)" : "Energy", " Counts":"Counts"}
dfi = pd.read_csv(file, nrows=5)
df = pd.read_csv(file, header=6)
df = df.rename(columns=dict0)

spect = sp.Spectrum(counts=df.Counts)
fwhm_at_0 = 1.0
ref_x = 1315
ref_fwhm = 42
search = ps.PeakSearch(spect, ref_x, ref_fwhm, fwhm_at_0, min_snr=4)

xrange = [1250, 1600]
bkg = "poly2"
fit = pf.PeakFit(search, xrange=xrange, bkg=bkg)

# energy calibration
ch = df.Channel.to_numpy(dtype=int) - 1
peak_info = fit.peak_info
mean_values = [peak_info[0]['mean1'], peak_info[1]['mean2']]
mean_values.insert(0,0) # add the origin
erg = [0, 1173.2, 1332.5] # in keV
pred_erg, efit = pf.ecalibration(mean_vals=mean_values, erg=erg, channels=ch, n=1,
                                plot=False)
pred_erg[0] = 0 # because negative entry

spect2 = sp.Spectrum(counts=df.Counts, energies=pred_erg, e_units="keV")<jupyter_output>Working with channel numbers
Found 2 peak(s) within range [1250, 1600]
Fit succeeded.<jupyter_text>Find peaks<jupyter_code>search2 = ps.PeakSearch(spect2, ref_x, ref_fwhm, fwhm_at_0, min_snr=3)
search2.plot_peaks(yscale="log")<jupyter_output><empty_output><jupyter_text>Create 2 lists of peak ranges and background functions. This was chosen one by one using the PeakFit class (not shown here, but same procedure as above)<jupyter_code>bkg_lst = ["poly2", "poly2", "poly1", "poly2", "poly1"]
xrange_lst = [[140, 320], [440, 610], [700, 950], [1110, 1550],
              [1670, 1950]]<jupyter_output><empty_output><jupyter_text>Create a list of PeakFit objects based on the lists created above using the auto_scan function. Of course, this can be done manually too, but the auto_scan function is in the process of figuring out the best ranges and backgrounds automatically.<jupyter_code>fit_lst = pf.auto_scan(search2, xlst=xrange_lst, bkglst=bkg_lst)<jupyter_output>Working with energy values
Found 3 peak(s) within range [140, 320]
Fit succeeded.
Working with energy values
Found 3 peak(s) within range [440, 610]
Fit succeeded.
Working with energy values
Found 2 peak(s) within range [700, 950]
Fit succeeded.
Working with energy values
Found 3 peak(s) within range [1110, 1550]
Fit succeeded.
Working with energy values
Found 1 peak(s) within range [1670, 1950]
Fit succeeded.<jupyter_text>Extract and plot the Gaussian components only, which are the net areas of the peaks<jupyter_code># plot gaussian components
gc2 = pf.GaussianComponents(fit_obj_lst=fit_lst)
gc2.plot_gauss(plot_type="full", table_scale=[1,3])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10641728474685586, 'fraction_numerical': 0.050628829409867786, 'mean_word_length': 5.817582417582417, 'pattern_counts': {'":': 1, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '323370', 'license': 'MIT', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1087, 'n_words': 328, 'path': 'examples/5.Gaussian-components.ipynb', 'repo_name': 'mauricioAyllon/NASA-gamma', 'size': '3101'}