Example #1
0
    def test_arraydict(self):
        def _check(a):
            self.assertEqual(a['na'], na)
            self.assertEqual(a['maa'], maa)
            self.assertEqual(a['na'][500:-500], na[500:-500])
            self.assertEqual(a['maa'][500:-500], maa[500:-500])
            scatter = Numeric.array(xrange(0, len(na), 3))
            self.assertEqual(a['na'].take(scatter), Numeric.take(na, scatter))
            self.assertEqual(Numeric.take(a['na'],scatter), 
                             Numeric.take(na, scatter))
            self.assertEqual(MA.take(a['maa'], scatter), MA.take(maa, scatter))

        tmpfile = TempFile('soomtestarray_tmpfile')
        try:
            a = soomarray.ArrayDict(tmpfile.fn(), 'w')
            self.assertEqual(len(a), 0)
            self.assertRaises(KeyError, a.__getitem__, 'not_found')
            na = Numeric.arrayrange(10000)
            a['na'] = na
            na[1000] = -2222
            # MmapArray __setitem__
            a['na'][1000] = -2222

            maa = MA.arrayrange(10000)
            for i in xrange(0, len(maa), 5):
                maa[i] = MA.masked
            a['maa'] = maa
            maa[1000] = -2222
            a['maa'][1000] = -2222

            _check(a)
            del a

            a = soomarray.ArrayDict(tmpfile.fn(), 'r')
            _check(a)
        finally:
            try: del a
            except UnboundLocalError: pass
            tmpfile.done()
# Tutorial for xmgrace module, using Numeric only

# it is recomended to run it usibng parser.py or just read it

print 'it is recomended to run this file using parser.py or just read it'

import MA

TEMPDIR = './'

# First let's create some data
npoints=50
X=MA.arrayrange(npoints,typecode=MA.Float)
X=X/float(npoints)*2.*MA.pi

Y1=MA.sin(X)
Y2=MA.cos(X)
Y3=MA.tan(X)

# Now the real grace thing, plot the 2 on one graph and the diff on another graph

from genutil import xmgrace # first we need to import xmgrace module

x=xmgrace.init() # create our xmgrace object

# First let's set our graphs area
# graph 0, exist by default, but we need to add 1 graph, therefore:
x.add_graph() # adds one graph to our graph list (x.Graph)

# Let's change the orientation of the page to portrait
x.portrait()