Message Boards Message Boards

0
|
1692 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Advice on How to Store An Association for Later Use?

Posted 1 year ago

Hi,

I have what I'm using currently as an Association, that being some names of musical notes and their frequency. Instead of copy and paste each time I use this, and instead of having to make it part of a notebook, is there any advice on how to save this?

Some thoughts are that maybe as a Dataset instead of Association, but moreover, I'm thinking about the actual file format. I don't know when a package is appropriate, or a script, or some other format other than a notebook. Any advice?

Incidentally, this is my Association to be used later in different uses, and I have no idea how "naive" this implementation is:

notes = <|"c2" -> 65.9, "c\[Sharp]2" -> 69.9, "d2" -> 73.9, 
  "d\[Sharp]2" -> 78.1, "e2" -> 82.7, "f2" -> 87.9, 
  "f\[Sharp]2" -> 92.7, "g2" -> 97.5, "g\[Sharp]2" -> 104.4, 
  "a2" -> 109.9, "a\[Sharp]2" -> 117.3, "b2" -> 124.4, "c3" -> 131.4, 
  "c\[Sharp]3" -> 139.4, "d3" -> 147.5, "d\[Sharp]3" -> 155.9, 
  "e3" -> 165.0, "f3" -> 173.3, "f\[Sharp]3" -> 184.1, "g3" -> 195.6, 
  "g\[Sharp]3" -> 207.8, "a3" -> 219.1, "a\[Sharp]3" -> 233.3, 
  "b3" -> 245.9, "c4" -> 260.5, "c\[Sharp]4" -> 277.5, "d4" -> 292.3, 
  "d\[Sharp]4" -> 311.2, "e4" -> 331.1, "f4" -> 347.5, 
  "f\[Sharp]4" -> 370.3, "g4" -> 390.2, "g\[Sharp]4" -> 415.1, 
  "a4" -> 439.9, "a\[Sharp]4" -> 467.2, "b4" -> 495.1, "d5" -> 589.7, 
  "d\[Sharp]5" -> 623.8, "e5" -> 660.2, "f5" -> 699.6, 
  "f\[Sharp]5" -> 741.6, "g5" -> 785.7, "g\[Sharp]5" -> 832.6, 
  "a5" -> 881.1, "a\[Sharp]5" -> 932.5, "b5" -> 991.6, "c6" -> 1046.3,
   "c\[Sharp]6" -> 1112.6, "d6" -> 1178.8, "d\[Sharp]6" -> 1249.0, 
  "e6" -> 1323.4, "f6" -> 1402.0, "f\[Sharp]6" -> 1484.4, 
  "g6" -> 1573.4, "g\[Sharp]6" -> 1666.1, "a6" -> 1765.1, 
  "a\[Sharp]6" -> 1870.7, "b6" -> 1981.2, "c7" -> 2100.1|>

So if there is any advice on either the data format, or the storage format, I'd like to hear it!

POSTED BY: Dan Stimits
2 Replies

Hi Dan,

The choice of data structure really depends on how you intend to use the data. Hard to advise without that information. As far as storage for reuse, here is one option

dataDirectory = $UserDocumentsDirectory (* Change to any existing directory *)
DumpSave[FileNameJoin@{dataDirectory, "notes.mx"}, notes]

Clear the definition of notes and read it back from the file

ClearAll[notes]
Get[FileNameJoin@{dataDirectory, "notes.mx"}]

notes
POSTED BY: Rohit Namjoshi
Posted 1 year ago

Thanks, I am going with that suggestion. I previously had some issues trying to save and reuse notebooks with maps, but it turns out that it is probably because of a bug in dynamic content in the notebook; when I have to "Enable Dynamics" Associations also fail, and I have to put the cursor back into the notebook's Association and shift-enter, but apparently it isn't a bug of Associations per se. The DumpSave and Get solves that (at least it seems that way for now, I might find other problems later for a new forum thread).

POSTED BY: Dan Stimits
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract