@@ -0,0 +1,2309 @@
+import omx,numpy%0A%0A# Create some data%0Aones = numpy.ones((100,100))%0Atwos = 2.0*ones%0A%0A%0A# Create an OMX file (will overwrite existing file!)%0Amyfile = omx.openFile('myfile.omx','w')   # use 'a' to append/edit an existing file%0A%0A%0A# Write to the file.%0Amyfile%5B'm1'%5D = ones%0Amyfile%5B'm2'%5D = twos%0Amyfile%5B'm3'%5D = ones + twos           # numpy array math is fast%0Amyfile.close()%0A%0A%0A# Open an OMX file for reading only%0Amyfile = omx.openFile('myfile.omx')%0A%0Aprint myfile.shape()                 # (100,100)%0Alen(myfile)                          # 3%0Amyfile.listMatrices()                # %5B'm1','m2',',m3'%5D%0A%0A%0A# Work with data. Pass a string to select matrix by name:%0A# -------------------------------------------------------%0Am1 = myfile%5B'm1'%5D%0Am2 = myfile%5B'm2'%5D%0Am3 = myfile%5B'm3'%5D%0A%0A# halves = m1 * 0.5  # CRASH!  Don't modify an OMX object directly.%0A#                    # Create a new numpy array, and then edit it.%0Ahalves = numpy.array(m1) * 0.5%0A%0Afirst_row = m2%5B0%5D%0Afirst_row%5B:%5D = 0.5 * first_row%5B:%5D%0A%0Amy_very_special_zone_value = m2%5B10%5D%5B25%5D%0A%0A%0A# FANCY: Use tags to find matrices%0A# -----------------------------------%0Amyfile.close()                           # was opened read-only, so let's reopen.%0Amyfile = omx.openFile('myfile.omx','a')  # append mode: read/write existing file%0A%0Amyfile%5B'm1'%5D.attrs.tags = %5B'trips','am','hwy'%5D%0Amyfile%5B'm2'%5D.attrs.tags = %5B'trips','md','hwy'%5D%0Amyfile%5B'm3'%5D.attrs.tags = %5B'trips','md','trn'%5D%0A%0Amyfile.listAllTags()                 # %5B'am','hwy','md','trips','trn'%5D%0A%0A# Use a TUPLE to select matrices via tags:%0Aall_hwy_trips = myfile%5B ('trips','hwy') %5D   # %5Bm1,m2%5D%0Aall_md_trips = myfile%5B ('md',) %5D            # %5Bm2,m3%5D%0A%0Aprint numpy.sum(all_md_trips)%0A%0A%0A# SUPER FANCY: Create a mapping to use TAZ numbers instead of matrix offsets%0A# --------------------------------------------------------------------------%0A# (any mapping would work, such as a mapping with large gaps between zone%0A#  numbers. For this simple case we'll just assume TAZ numbers are 1-100.)%0A%0Ataz_equivs = range(1,101)                  # 1-100 inclusive%0A%0Amyfile.createMapping('taz', taz_equivs)%0Amyfile.listMappings()                 # %5B'taz'%5D%0A%0Atazs = myfile.mapping('taz')          # Returns a dict:  %7B1:0, 2:1, 3:2, ..., 100:99%7D%0A%0Am3 = myfile%5B'm3'%5D%0A%0Aprint m3%5Btazs%5B100%5D%5D%5Btazs%5B100%5D%5D      # 3.0  (taz (100,100) is cell %5B99%5D%5B99%5D)%0A%0Amyfile.close()%0A%0A

Add test.py (same file as on Python API sites page)