import numpy as np
sample_list = np.genfromtxt('./sample_list.txt', dtype=str, delimiter='\n', comments='#')

sample_list

"""
Explanation: Example of long-file splitting and analysis
Load the Sample List
Text File
End of explanation
"""


import pandas as pd
sample_list = pd.read_excel('./sample_list.xlsx')

sample_list

"""
Explanation: Excel File
End of explanation
"""


import latools as la

# read in the long file, and split it into individual ablations
fig, ax = la.preprocessing.long_file('./long_data_file.csv', 
                                     dataformat='./long_data_file_format.json', 
                                     sample_list=sample_list.loc[:, 'Samples'])

"""
Explanation: Load and split the data file
End of explanation
"""


fig, ax = la.preprocessing.long_file('./long_data_file.csv', 
                                     dataformat='./long_data_file_format.json', 
                                     sample_list=sample_list.loc[:, 'Samples'], 
                                     swin=10)

"""
Explanation: FAILURE!! How to deal with it?
Looking at the right-hand-side of the plot here, something is not right... There's a sudden drop in signal in the second-to-last ablation, which is making autorange identify them as two separate ablations.
We can fix this by asking it to smooth the signals before identifying signal and backgroudn regions. We do this by setting the swin parameter, which is passed directly to autorange for signal splitting.
In this case, I've set swin=10, as it seems to do a good job.
End of explanation
"""


from latools.helpers.io import read_dataformat

df = read_dataformat('REPRODUCE')

dat = la.analyse('./long_data_file_split/', 
                 config='REPRODUCE', 
                 srm_identifier='NIST')
dat.despike()

dat.autorange(off_mult=[1, 4.5])
dat.bkg_calc_weightedmean(weight_fwhm=1200)
dat.bkg_plot()

dat.bkg_subtract()
dat.ratio()
dat.calibrate(srms_used=['NIST610', 'NIST612'])

_ = dat.calibration_plot()

"""
Explanation: Working with Split Data
End of explanation
"""


