<jupyter_start><jupyter_text>TO DO:- Improve fit by aligning the waveforms: just roll waveform by +/- 5-10 indices in steps of 1 and keep best score. Using convolution might be unnecessarily complex.  Define the DetObjectFunc<jupyter_code>import smalldata_tools.DetObject as dobj
from smalldata_tools.DetObject import DetObjectFunc

from smd_svd import *<jupyter_output><empty_output><jupyter_text>Test the multipulse fit DetObjectFunc  (i) On single pulse<jupyter_code>expname ='xcsx35017'
run = 112
ds = ps.MPIDataSource('exp=%s:run=%d'%(expname, int(run)))
dsenv = ds.env()
ds.detnames()
# ds.detnames('epics')
acq = dobj.DetObject('acq01', dsenv, int(run)) # best way to do it
fbasis = './wave_basis_acq01_20200810_121230.h5'
data_basis = h5.File(fbasis,'r')
print(data_basis.keys())
acq.addFunc(svdFit(return_reconstructed=True, basis_file=fbasis))
print(acq.svdFit.regressor.A.shape)
fig, ax = plt.subplots()
ax.plot(acq.svdFit.regressor.A[0,:])
ax.plot(0.5*acq.svdFit.regressor.A[1,:])
plt.show()
nevt_max = 5
fig, axs = plt.subplots(nrows=2, ncols=3, figsize=(14,10))
axs = axs.ravel()
for nevt,evt in enumerate(ds.events()):
    if nevt>nevt_max:
        break
    acq.getData(evt)
    acq.processFuncs()
    dat = getUserData(acq)
    axs[nevt].set_title('Score: {:.3}'.format(dat['svdFit_score'][0]))
    axs[nevt].plot(acq.evt.dat[0][acq.svdFit.roi[0]:acq.svdFit.roi[1]])
    axs[nevt].plot(dat['svdFit_reconstructed'].T)
plt.tight_layout()
plt.show()
acq.evt.dat.shape<jupyter_output><empty_output><jupyter_text>(ii) On multi pulse<jupyter_code>expname ='xcsx35017'
run = 70
ds = ps.MPIDataSource('exp=%s:run=%d'%(expname, int(run)))
dsenv = ds.env()
acq = dobj.DetObject('acq01', dsenv, int(run)) # best way to do it
fbasis = './wave_basis_acq01_20200810_121230.h5'
data_basis = h5.File(fbasis,'r')
print(data_basis.keys())
kwargs = {
    'n_pulse': 4,
    'delay': [-1, 16, 50, 67],
    'return_reconstructed': True
#     'basis_file': fbasis
}
acq.addFunc(svdFit(**kwargs))
acq.svdFit.__dict__
print(acq.svdFit.regressor.A.shape)
fig, ax = plt.subplots(ncols=2, figsize=(12,5))
ax[0].plot(acq.svdFit.regressor.A[0,:])
ax[0].plot(acq.svdFit.regressor.A[5,:])
ax[0].plot(acq.svdFit.regressor.A[10,:])
ax[0].plot(acq.svdFit.regressor.A[15,:])
ax[1].plot(np.sum(acq.svdFit.regressor.A[::5,:], axis=0))
plt.show()
nevt_max = 5
fig, axs = plt.subplots(nrows=2, ncols=3, figsize=(14,10))
axs = axs.ravel()
for nevt,evt in enumerate(ds.events()):
    if nevt>nevt_max:
        break
    acq.getData(evt)
    acq.processFuncs()
    dat = getUserData(acq)
    axs[nevt].set_title('Score: {:.3}'.format(dat['svdFit_score'][0]))
    axs[nevt].plot(acq.evt.dat[0][acq.svdFit.roi[0]:acq.svdFit.roi[1]])
    axs[nevt].plot(dat['svdFit_reconstructed'].T)
    axs[nevt].set_xlim(100,230)
plt.tight_layout()
plt.show()
dat
acq.__dict__<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1812783793223891, 'fraction_numerical': 0.04121550820817325, 'mean_word_length': 5.645011600928075, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '560896', 'license': 'MIT', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1268, 'n_words': 190, 'path': 'waveform_analysis/smd_multipulse_svd/implement_smalldata_tools.ipynb', 'repo_name': 'vespos/data_processing', 'size': '2863'}