title: Storing and reloading large multidimensional data sets in Python
body: <p>I'm going to be running a large number of simulations producing a large amount of data that needs to be stored and accessed again later. Output data from my simulation program is written to text files (one per simulation). I plan on writing a Python program that reads these text files and then stores the data in a format more convenient for analyzing later. After quite a bit of searching, I think I'm suffering from information overload, so I'm putting this question to Stack Overflow for some advice. Here are the details:</p>
  
  <p>My data will basically take the form of a multidimensional array where each entry will look something like this:</p>
  
  <pre><code>data[ stringArg1, stringArg2, stringArg3, stringArg4, intArg1 ] = [ floatResult01, floatResult02, ..., floatResult12 ]
  </code></pre>
  
  <p>Each argument has roughly the following numbers of potential values:</p>
  
  <p>stringArg1: 50</p>
  
  <p>stringArg2: 20</p>
  
  <p>stringArg3: 6</p>
  
  <p>stringArg4: 24</p>
  
  <p>intArg1: 10,000</p>
  
  <p>Note, however, that the data set will be sparse. For example, for a given value of stringArg1, only about 16 values of stringArg2 will be filled in. Also, for a given combination of (stringArg1, stringArg2) roughly 5000 values of intArg1 will be filled in. The 3rd and 4th string arguments are always completely filled.</p>
  
  <p>So, with these numbers my array will have roughly 50*16*6*24*5000 = 576,000,000 result lists.</p>
  
  <p>I'm looking for the best way to store this array such that I can save it and reopen it later to either add more data, update existing data, or query existing data for analysis. Thus far I've looked into three different approaches:</p>
  
  <ol>
  <li><p>a relational database</p></li>
  <li><p>PyTables</p></li>
  <li><p>Python dictionary that uses tuples as the dictionary keys (using pickle to save &amp; reload)</p></li>
  </ol>
  
  <p>There's one issue I run into in all three approaches, I always end up storing every tuple combination of (stringArg1, stringArg2, stringArg3, stringArg4, intArg1), either as a field in a table, or as the keys in the Python dictionary. From my (possibly naive) point of view, it seems like this shouldn't be necessary. If these were all integer arguments then they would just form the address of each data entry in the array, and there wouldn't be any need to store all the potential address combinations in a separate field. For example, if I had a 2x2 array = [[100, 200] , [300, 400]] you would retrieve values by asking for the value at an address array[0][1]. You wouldn't need to store all the possible address tuples (0,0) (0,1) (1,0) (1,1) somewhere else. So I'm hoping to find a way around this.</p>
  
  <p>What I would love to be able to do is define a table in PyTables, where cells in this first table contain other tables. For example, the top-level tables would have two columns. Entries in the first column would be the possible values of stringArg1. Each entry in the second column would be a table. These sub-tables would then have two columns, the first being all the possible values of stringArg2, the second being another column of sub-sub-tables...</p>
  
  <p>That kind of solution would be straightforward to browse and query (particularly if I could use ViTables to browse the data). The problem is PyTables doesn't seem to support having the cells of one table contain other tables. So I seem to have hit a dead end there.</p>
  
  <p>I've been reading up on data warehousing and the star schema approach, but it still seems like your fact table would need to contain tuples of every possible argument combination.</p>
  
  <p>Okay, so that's pretty much where I am. Any and all advice would be very much appreciated. At this point I've been searching around so much that my brain hurts. I figure it's time to ask the experts. </p>