7
$\begingroup$

Mathematica introduced TemporalData in Mathematica 9. Mathematica 10 added several fantastic new TimeSeries manipulation tools -- tools that would come in handy for non-temporal data.

For example, I would love to use Resampling, MovingAverage, TimeSeriesAggregate, etc on wavelength scans, ie Fluorescence Intensity vs wavelength. At the moment, I have been treating wavelength as AbsoluteTime values.

filter = TimeSeries[{{0.525, 0.}, {0.526, 0.}, {0.527, 0.}, {0.528, 
     0.}, {0.529, 0.}, {0.53, 0.001}, {0.531, 0.001}, {0.532, 
     0.002}, {0.533, 0.002}, {0.534, 0.003}, {0.535, 0.004}, {0.536, 
     0.006}, {0.537, 0.01}, {0.538, 0.015}, {0.539, 0.026}, {0.54, 
     0.046}, {0.541, 0.092}, {0.542, 0.132}, {0.542, 0.189}, {0.542, 
     0.256}, {0.543, 0.361}, {0.544, 0.464}, {0.544, 0.556}, {0.544, 
     0.618}, {0.545, 0.644}, {0.546, 0.644}, {0.546, 0.626}, {0.546, 
     0.605}, {0.547, 0.575}, {0.548, 0.533}, {0.548, 0.476}, {0.548, 
     0.396}, {0.549, 0.324}, {0.55, 0.241}, {0.55, 0.178}, {0.55, 
     0.13}, {0.551, 0.094}, {0.552, 0.069}, {0.552, 0.051}, {0.553, 
     0.03}, {0.554, 0.019}, {0.555, 0.012}, {0.556, 0.008}, {0.557, 
     0.006}, {0.558, 0.004}, {0.559, 0.003}, {0.56, 0.002}, {0.561, 
     0.002}, {0.562, 0.001}, {0.563, 0.001}, {0.564, 0.001}, {0.565, 
     0.}, {0.566, 0.}, {0.567, 0.}, {0.568, 0.}, {0.569, 0.}, {0.570, 
     0.}, {0.571, 0.}, {0.572, 0.}, {0.573, 0.}, {0.574, 0.}, {0.575, 
     0.}}];
filter["Times"][[1 ;; 4]]
DateString /@ filter["Dates"][[1 ;; 4]]

Yields

{0.525, 0.526, 0.527, 0.528}
{"Mon 1 Jan 1900 00:00:00", "Mon 1 Jan 1900 00:00:00", "Mon 1 Jan \
1900 00:00:00", "Mon 1 Jan 1900 00:00:00"}

It appears to work, but it seems a bit of a kludge. Is there an equivalent Series that allows non-temporal independent variable with appropriate units?

$\endgroup$

1 Answer 1

2
$\begingroup$

I'll go into this answer admitting it's not ideal, because I also haven't found anything that packages non-temporal data as nicely as TimeSeries does. And maybe you already know that there are plenty of built-in functions that replicate the behavior of TimeSeriesResample, MovingAverage, TimeSeriesAggregate, etc. for non-temporal data arrays. But one of the things I love about Mathematica is the workhorse list of lists data structure. So my answer really just shows the function equivalents to the ones you mentioned for a straightforward two-dimensional array. Apologies if it's not a real answer for you, but here are the examples of the functions in which you specifically expressed interest.

(* TimeSeriesResample *)
resampledFilter = ArrayResample[filter, {2 Length[filter], 2}];
(* MovingAverage *)
movingAveragedFilter = MovingAverage[filter, 2];
(* TimeSeriesAggregate *)
movingMapped = MovingMap[StandardDeviation, filter, Quantity[3, "Events"]];

ListLinePlot[{filter, resampledFilter, movingAveragedFilter, movingMapped},
    ImageSize -> Large,
    PlotLegends -> LineLegend[{"original", "resampled", "moving averaged", "moving mapped SD"}]
]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.