We demonstrate representing data as intervals vs. datetimes.
Configure notebook style (see NBCONFIG.ipynb), add imports and paths. The %run magic used below requires IPython 2.0 or higher.
%run NBCONFIG.ipynb
Populating the interactive namespace from numpy and matplotlib
from skspec.data import aunps_glass
from skspec.plotting import areaplot
ts=aunps_glass()
ts.plot(cbar=True)
areaplot(ts)
ts.columns
WARNING:skspec.core.timespectra:SpecIndex unit was changed internally from "None" to "nm" WARNING:skspec.plotting.basic_plots:Recomputing area from shape (704, 100) to (1, 100) WARNING:skspec.plotting.basic_plots:areaplot() forcing transpose on AuNPs Glass (good) for plotting
<class 'pandas.tseries.index.DatetimeIndex'> [2014-05-22 15:38:23, ..., 2014-05-22 15:44:25] Length: 100, Freq: None, Timezone: None
ts.list_intvlunits()
Key Description ------------------- d Days h Hours intvl Time Delta m Minutes ms Milliseconds ns Nanoseconds s Seconds us Microseconds y Years
We can convert the datetimeindex to an interval using ts.as_interval()
. This will return a Float64Index (yup, would def benefit from an honest to goodness IntervalIndex)
ts = ts.as_interval('s')
ts.plot(cbar=True)
areaplot(ts)
ts.columns
WARNING:skspec.plotting.basic_plots:Recomputing area from shape (704, 100) to (1, 100) WARNING:skspec.plotting.basic_plots:areaplot() forcing transpose on AuNPs Glass (good) for plotting
Spectra(): Float64Index([0.0, 3.0, 7.0, 11.0, 14.0, 18.0, 22.0, 25.0, 29.0, 33.0, 36.0, 40.0, 44.0, 47.0, 51.0, 55.0, 58.0, 62.0, 66.0, 70.0, 73.0, 77.0, 81.0, 84.0, 88.0, 92.0, 95.0, 99.0, 103.0, 106.0, 110.0, 114.0, 117.0, 121.0, 125.0, 128.0, 132.0, 135.0, 139.0, 143.0, 146.0, 150.0, 154.0, 157.0, 161.0, 165.0, 168.0, 172.0, 176.0, 179.0, 183.0, 187.0, 190.0, 194.0, 198.0, 201.0, 205.0, 209.0, 212.0, 216.0, 219.0, 223.0, 227.0, 230.0, 234.0, 238.0, 241.0, 245.0, 249.0, 252.0, 256.0, 260.0, 263.0, 267.0, 271.0, 274.0, 278.0, 282.0, 285.0, 289.0, 292.0, 296.0, 300.0, 303.0, 307.0, 311.0, 314.0, 318.0, 322.0, 325.0, 329.0, 333.0, 336.0, 340.0, 344.0, 347.0, 351.0, 355.0, 359.0, 362.0], dtype='float64')
For general unit, we use time deltas. Can be done by setting the interval unit to "intvl" or just using None
ts.intvlunit = None
ts.plot(cbar=True)
areaplot(ts)
ts.columns
WARNING:skspec.plotting.basic_plots:Recomputing area from shape (704, 100) to (1, 100) WARNING:skspec.plotting.basic_plots:areaplot() forcing transpose on AuNPs Glass (good) for plotting
Defaulting intvlunit to "intvl"
Spectra(): Index([0:00:00, 0:00:03, 0:00:07, 0:00:11, 0:00:14, 0:00:18, 0:00:22, 0:00:25, 0:00:29, 0:00:33, 0:00:36, 0:00:40, 0:00:44, 0:00:47, 0:00:51, 0:00:55, 0:00:58, 0:01:02, 0:01:06, 0:01:10, 0:01:13, 0:01:17, 0:01:21, 0:01:24, 0:01:28, 0:01:32, 0:01:35, 0:01:39, 0:01:43, 0:01:46, 0:01:50, 0:01:54, 0:01:57, 0:02:01, 0:02:05, 0:02:08, 0:02:12, 0:02:15, 0:02:19, 0:02:23, 0:02:26, 0:02:30, 0:02:34, 0:02:37, 0:02:41, 0:02:45, 0:02:48, 0:02:52, 0:02:56, 0:02:59, 0:03:03, 0:03:07, 0:03:10, 0:03:14, 0:03:18, 0:03:21, 0:03:25, 0:03:29, 0:03:32, 0:03:36, 0:03:39, 0:03:43, 0:03:47, 0:03:50, 0:03:54, 0:03:58, 0:04:01, 0:04:05, 0:04:09, 0:04:12, 0:04:16, 0:04:20, 0:04:23, 0:04:27, 0:04:31, 0:04:34, 0:04:38, 0:04:42, 0:04:45, 0:04:49, 0:04:52, 0:04:56, 0:05:00, 0:05:03, 0:05:07, 0:05:11, 0:05:14, 0:05:18, 0:05:22, 0:05:25, 0:05:29, 0:05:33, 0:05:36, 0:05:40, 0:05:44, 0:05:47, 0:05:51, 0:05:55, 0:05:59, 0:06:02], dtype='object')
ts = ts.as_datetime()
ts.plot(cbar=True)
areaplot(ts)
ts.columns
WARNING:skspec.plotting.basic_plots:Recomputing area from shape (704, 100) to (1, 100) WARNING:skspec.plotting.basic_plots:areaplot() forcing transpose on AuNPs Glass (good) for plotting
<class 'pandas.tseries.index.DatetimeIndex'> [2014-05-22 15:38:23, ..., 2014-05-22 15:44:25] Length: 100, Freq: None, Timezone: None