tools/draw-diagram/draw.py
author Aravindakshan Babu <akshan@stanford.edu>
Thu, 08 Jul 2010 23:50:39 -0700
branchdev
changeset 217 64a272a34cb2
parent 171 a172b960aaaa
child 243 c9b8c98187a8
permissions -rwxr-xr-x
Added extra functionality to Point class( an iterator ) and PersistenceDiagram( dimension property and __len__ func ). persistence-diagram.h: Added a new read-only dimension member and member function to access it. With a new constructor that that takes in an int type to initialize dimension. persistence-diagram.cpp: Added new bp::init constructor. Takes in an integer type to initialize the dimension. Exposed the dimension property. Exposed the size property via a __len__ method. __init__.py: Added an iterator for Point objects. This iterates over the coords and then the data( if present ).

#!/usr/bin/env python

import  pd
from    sys         import argv, exit

if len(argv) < 2:
    print "Usage: %s FILENAME [MULTIPLIER=1] [NOISE=0] [RADIUS=.15] [DIMENSIONS=XMIN,YMIN,XMAX,YMAX]" % argv[0]
    print "  MULTIPLIER -   multiply coordinates of each point by this quantity"
    print "  NOISE -        filter out points below this persistence"
    print "  RADIUS -       radius of a point in the persistence diagram"
    print "  DIMENSIONS -   dimensions of the persistence diagram"
    print 
    print "  Example: %s torus.dgm 1 0 .05 -1,-1,10,10" % argv[0]
    exit()

multiplier =    float(argv[2])                  if len(argv) > 2    else 1
noise =         float(argv[3])                  if len(argv) > 3    else 0
R =             float(argv[4])                  if len(argv) > 4    else .15
dimensions =    map(float, argv[5].split(','))  if len(argv) > 5    else None

noise_filter =   pd.noise_filter(noise)
amplify_filter = pd.amplify_filter(multiplier)

dgm = pd.PersistenceDiagram(argv[1], lambda x,y: noise_filter(x,y) and amplify_filter(x,y))
dgm.savePDF(argv[1] + '.', radius = R, dimensions = dimensions)