To do: \begin{itemize} \item{Rename flippy\_s function} \item{If time, vectorize "flippy\_s"} \item{Need more robust means to find the inflection point, maybe smooth curves before using?} \end{itemize}
pylab.rcParams['figure.figsize'] = 4,3 #Set plotsize
from skspec import specplot, areaplot, maxmin_xy, absplot
from skspec.IO.gwu_interfaces import from_spec_files, get_files_in_dir
from skspec.exampledata import get_exampledata
import sys
ts = from_spec_files(get_files_in_dir(get_exampledata('NPSAM'),sort=True), name='testname')
ts.baseline = 220
ts=ts.ix[420.0:700.0]
ts.sub_base()
ts.reference = 0 #Bug (?) reference must be added after subtraction
specplot(ts)
11-26 14:10:12 CRITICAL skspec.core.timespectra: Subtracting baseline, but may not have all: elements being equal. Fix index
<matplotlib.axes.AxesSubplot at 0x3853550>
plt.plot(ts.T)
print type(ts.T)
print ts.T.index
<class 'pandas.core.frame.DataFrame'> <class 'pandas.tseries.index.DatetimeIndex'> [2013-09-04 17:28:31, ..., 2013-09-04 17:34:09] Length: 99, Freq: None, Timezone: None
areaplot(ts)
11-21 17:56:05 WARNING skspec.pyplots.basic_plots: Recomputing area from shape (791, 99) to (1, 99) 11-21 17:56:05 WARNING skspec.pyplots.basic_plots: areaplot() forcing transpose on testname for plotting
<matplotlib.axes.AxesSubplot at 0x9a18d90>
tarea = ts.area()
tmin_idx = maxmin_xy(ts.area().T, style='min', arg=False, idx=True, val=False)
tmin_idx
Wavelength 420.04:699.9 2013-09-04 17:31:20 dtype: datetime64[ns]
def flippy_s(s,style='decrease'):
y_flippy_s = [s[0]]
shift = 0
for i in range(1,len(s)):
dy = s[i]-s[i-1]
if style == 'decrease':
if dy > 0:
shift -= 2*dy
elif style == 'increase':
if dy < 0:
shift -= 2*dy
else:
raise AttributeError('style should be decrease and increase')
y_flippy_s.append(s[i]+shift)
return y_flippy_s
ts_1=ts.apply(flippy_s,axis=1)
specplot(ts_1)
<matplotlib.axes.AxesSubplot at 0x9bebc90>
absplot(ts_1)
<matplotlib.axes.AxesSubplot at 0x8464390>
absplot(ts)
<matplotlib.axes.AxesSubplot at 0x8e9cd90>