12
$\begingroup$

I work with a lot of dynamic data in {{date, datum}. . .} format,

datedatalist={{{2001, 1, 1}, 45.2}, {{2002, 1, 1}, 132.}, {{2003, 1, 2}, 121.1}};

and I have historically attached a header to each object in a format like

datedataObject={{header version, data series name, type (value, % change, etc.)}, datedatalist};

I can see advantages to using Mathematica's TemporalData[] type, and to using MetaInformation[] for recording the header. I would set this up with something like

newObject = TemporalData[datedatalist, MetaInformation -> {"name" -> "whatever", "type" -> "value"}];

and extract header items with, for example

newObject["name"]

But this leaves me with two puzzles,

  1. How do I add MetaInformation after the object has been created? and
  2. How do I change existing MetaInformation?
$\endgroup$

3 Answers 3

4
$\begingroup$

What about this?

Load your sample data

datedatalist={{{2001, 1, 1}, 45.2}, {{2002, 1, 1}, 132.}, {{2003, 1, 2}, 121.1}};
ct = TemporalData[datedatalist, MetaInformation -> {"name" -> "whatever", "type" -> "value"}];

Modify its meta information

ct=TemporalData[ct, MetaInformation->{"name"->"Johnny", "fat"->True}];
ct["MetaInformation"]
(* {"name" -> "Johnny", "fat" -> True, "type" -> "value"} *)
$\endgroup$
3
  • $\begingroup$ Very nice. How did you figure that out? $\endgroup$ Jul 24, 2014 at 10:36
  • 2
    $\begingroup$ @MichaelStern luck. I just felt it was sensible for nested temporal data's to be flattened out, tried it and worked. $\endgroup$
    – Rojo
    Jul 24, 2014 at 13:52
  • 1
    $\begingroup$ To make this more general I would suggest to use the information contained in the first part of the TemporalData object. For example, addMetaInformation[ td_, metarules_ ] := Which[ td[[1]] === TimeSeries, TimeSeries[ td, MetaInformation -> metarules], ...=== EventSeries, EventSeries[...], True, TemporalData[ td, MetaInformation -> metarules ]. Also one might define addMetaInformation[ td_, None] := td /. (MetaInformation -> _) :> Sequence[]. $\endgroup$
    – gwr
    Jul 8, 2015 at 11:57
3
$\begingroup$

I sure hope there is a cleaner way to get both tasks than the following which is based on accessing and changing Parts of a temporal data object:

 s = Accumulate[
 RandomInteger[{-5, 1}, 10]~Join~RandomInteger[{-1, 5}, 10]]; 
 td = TemporalData[s, {1, 20}];
 td["Properties"]
(* {"Part","Path","PathComponents","PathCount","PathFunction",
   "PathFunctions","PathLengths","Paths","PathStates","PathTimes",
   "Properties","SliceData","SliceDistribution","StateDimensions",
    "States","Times"} *)

Add MetaInformation:

 td[[2, -1]] = AppendTo[td[[2, -1]], MetaInformation -> {"Event" -> 10}];
 td["Properties"]
 (* {"Event","Part","Path","PathComponents","PathCount","PathFunction",
    "PathFunctions","PathLengths","Paths","PathStates","PathTimes",
    "Properties","SliceData","SliceDistribution","StateDimensions",
    "States","Times"} *)

 td["Event"]
 (* 10 *)

Change the value of a MetaInformation element:

 d[[2, -1, 1, 2, 1, 2]] = 20;
 td["Event"]
 (* 20 *)

Add another MetaInformation element:

 td[[2, -1, 1, 2]] = AppendTo[td[[2, -1, 1, 2]], "name" -> "abc"];  
 td["MetaInformation"]
 (*{"Event" -> 20,"name" ->"abc"} *)
 td["name"]
 (* "abc" *)

Note: This approach works in version 9.0.1.0. Version 10 seems to have quite a few new features related to TemporalData. However, documentation information related to MetaInformation has not changed.

$\endgroup$
4
  • $\begingroup$ This works in V10, not in V9: td = TemporalData[td, "MetaInformation" -> {"Event" -> 20}] $\endgroup$
    – Michael E2
    Jul 15, 2014 at 1:15
  • $\begingroup$ @MichaelE2, right. MetaInformation->..." (without string quotes) also works in Version 10. Although documentation on MetaInformation` says the values can be changed using SetOptions it does not work for TemporalData. And, although MetaInformation is listed as an Option for TemporalData, Options[td] gives {}; and one needs to use td["Options"] to get MetaInformation -> {...}. $\endgroup$
    – kglr
    Jul 15, 2014 at 1:49
  • $\begingroup$ Yes, the quotes were a typo that happened to work. $\endgroup$
    – Michael E2
    Jul 15, 2014 at 2:37
  • $\begingroup$ I think the ultimate solution will have to come from Wolfram, but I appreciate the kludge in the meantime. $\endgroup$ Jul 17, 2014 at 13:58
2
$\begingroup$

David Reiss came up with a nice kludge over in the Wolfram Communities --

newObject = newObject /. {("name" -> _) :> ("name" -> "Happy feet")}

changes the "name" part of the MetaInformation in newObject. And

newObject = 
 newObject /. {(MetaInformation -> x_) :> (MetaInformation -> Flatten[{x, "another" -> "Something"}])} 

adds the "another" -> "Something" rule to the MetaInformation of newObject.

This does seem like a bug in Mathematica though; the behavior is illogical and at odds with the documentation.

$\endgroup$
7
  • $\begingroup$ Seems to me that if designed "properly" it should work with SetOptions and also probably CurrentValue (analogous to how TaggingRules works). I wonder if this is a bug or intentional? Have you asked tech support about this? $\endgroup$ Jul 16, 2014 at 1:43
  • $\begingroup$ I reported this as a bug. They haven't responded, but I don't think I ever get responses to bug reports. $\endgroup$ Jul 16, 2014 at 2:00
  • $\begingroup$ They never use the word "bug" but normally I get a reply saying that it has been forwarded to developers and I'll be emailed when an update occurs ...or words to that effect. $\endgroup$ Jul 16, 2014 at 2:24
  • $\begingroup$ I had an exchange with tech support and provided them with a detailed notebook. They have "reported this issue into [their] database." $\endgroup$ Jul 17, 2014 at 17:06
  • $\begingroup$ @MikeHoneychurch Hah. Tech support says that this behavior is "by design." I asked them to record it as a bug anyway. $\endgroup$ Jul 18, 2014 at 21:19

Your Answer

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

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