How to extract the first dimension in TimeSeries?

9

2

I want to extract the first dimension in TimeSeries,for example:

enter image description here

So I use this code:

data = Normal@AudioLocalMeasurements[ExampleData[{"Audio", "PianoScale"}],"MFCC"]; 
Thread[{data[[All, 1]], data[[All, 2, {1}]]}]

But it is a little complex,I want to know if there is more gentle way to do it?

partida

Posted 2016-10-28T13:28:46.083

Reputation: 6 452

Answers

7

You can also use TimeSeriesMap or MapAt:

audio = AudioLocalMeasurements[ExampleData[{"Audio", "PianoScale"}],"MFCC"];

res0 = TimeSeriesMap[{First@#}&, audio]["Path"];
res1 = MapAt[{First@#}&, audio["Path"],{{All,2}}];
res0 == res1 == res

True

kglr

Posted 2016-10-28T13:28:46.083

Reputation: 302 076

6

You can use the "Properties" specification of a TimeSeries, as introduced in the Details section of its reference page. This avoids normalizing it.

For instance, with the properties "Times" and "Values":

audio = AudioLocalMeasurements[ExampleData[{"Audio", "PianoScale"}], "MFCC"];

res = Transpose[{audio["Times"], audio["Values"][[All, {1}]]}];

The symbol res gives the expected output:

data = Normal@audio;
res === Thread[{data[[All, 1]], data[[All, 2, {1}]]}]
(* True *)

Alternatively, you can use the property "Path". Here is a possible way:

resBis = {#1, {#2[[1]]}} & @@@ audio["Path"];
resBis === res
(* True *)

Note that other objects of the language accept the "Properties" specification, once they are constructed through evaluation. These include SparseArray and QuantityArray:

spa = SparseArray[Range[10]];
spa["Properties"]
(* {"AdjacencyLists", "Background", "ColumnIndices", "Density", "MatrixColumns", 
    "NonzeroValues", "PatternArray", "Properties", "RowPointers"} *)

qa = QuantityArray[Range[10], "Meters"];
qa["Properties"]
(* {"Data", "Properties", "Structure"} *)

The specification "Methods" can also be used for these two last:

spa["Methods"]
(* {"AdjacencyLists", "Background", "ColumnIndices", "Density", "MatrixColumns", 
    "MethodInformation", "Methods", "NonzeroPositions", "NonzeroValues", "PatternArray", 
    "Properties", "RowPointers"} *)

qa["Methods"]
(* {"Data", "MethodInformation", "Methods", "Properties", "Structure"} *)

user31159

Posted 2016-10-28T13:28:46.083

Reputation:

1

The more elegant way:

In[15]:= ts = 
  AudioLocalMeasurements[ExampleData[{"Audio", "PianoScale"}], "MFCC"];

In[21]:= first = ts["PathComponent", {1}];

In[25]:= data = Normal[ts];

In[26]:= Thread[{data[[All, 1]], data[[All, 2, {1}]]}] == (first[
   "Path"])

Out[26]= True

Or without creating vector values:

In[15]:= ts = 
  AudioLocalMeasurements[ExampleData[{"Audio", "PianoScale"}], "MFCC"];

In[27]:= first = ts["PathComponent", 1];

In[28]:= data = Normal[ts];

In[29]:= Thread[{data[[All, 1]], data[[All, 2, 1]]}] == (first["Path"])

Out[29]= True

Gosia

Posted 2016-10-28T13:28:46.083

Reputation: 772

2(Tip: If you set SetOptions[$FrontEnd, ExportMultipleCellsOptions -> {"IncludeCellLabels" -> False}], then the pesky In[]/Out[] labels won't be copied. It will make it easier for others to test and use your code.) – Michael E2 – 2016-11-30T00:53:13.750

what is PathComponent.I can not find it in doc – partida – 2016-11-30T14:29:42.377

td = TemporalData[Array[x, {10, 2}], {0}, ValueDimensions -> 2]; td["DeveloperProperties"] – Gosia – 2016-12-01T16:49:03.297