Esempio n. 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--project', default='ProjectInfo.h5')
    parser.add_argument('-a', '--assignments', default='Data/Assignments.h5')
    args = parser.parse_args()

    a = Serializer.LoadData(args.assignments)
    p = Project.LoadFromHDF(args.project)
    maxx, maxy, minx, miny = -np.inf, -np.inf, np.inf, np.inf
    n_states = np.max(a) + 1

    x = np.concatenate([p.LoadTraj(i)['XYZList'][:, 0, 0] for i in range(p['NumTrajs'])])
    y = np.concatenate([p.LoadTraj(i)['XYZList'][:, 0, 1] for i in range(p['NumTrajs'])])
    a = np.concatenate([a[i, :] for i in range(p['NumTrajs'])])
    
    plot_v(minx=np.min(x), maxx=np.max(x), miny=np.min(y), maxy=np.max(y))
    colors = ['b', 'r', 'm', 'c', 'g']
    for j in xrange(n_states):
        w = np.where(a == j)[0]    
        pp.scatter(x[w], y[w], marker='x', c=colors[j], label='State %d' % j,
                   edgecolor=colors[j], alpha=0.5)

    
    pp.legend()
    pp.show()
Esempio n. 2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-g', '--generators', default='Data/Gens.lh5', help='Path to Gens.lh5')
    parser.add_argument('-p', '--project', default='ProjectInfo.h5', help='Path to ProjectInfo.h5')
    parser.add_argument('-s', '--stride', default=5, type=int, help='Stride to plot the data at')
    args = parser.parse_args()
    
    
    gens = Trajectory.LoadTrajectoryFile(args.generators)
    gens_x = gens['XYZList'][:,0,0]
    gens_y =  gens['XYZList'][:,0,1]
    points = np.array([gens_x, gens_y]).transpose()
    
    
    
    tri = Delaunay(points)

    PL = []
    for p in points:
        PL.append(Voronoi.Site(x=p[0],y=p[1]))

    v,eqn,edges,wtf = Voronoi.computeVoronoiDiagram(PL)

    edge_points=[]
    for (l,x1,x2) in edges:
        if x1>=0 and x2>=0:
            edge_points.append((v[x1],v[x2]))

    lines = LineCollection(edge_points, linewidths=0.5, color='k')
    
    fig = pp.figure()
    ax = fig.add_subplot(111)
    
    fig.gca().add_collection(lines)

    maxx, minx= np.max(gens_x), np.min(gens_x)
    maxy, miny = np.max(gens_y), np.min(gens_y)
    # plot the background
    plot_v(minx=minx, maxx=maxx, miny=miny, maxy=maxy, ax=ax)
    pp.xlim(minx, maxx)
    pp.ylim(miny, maxy)

    # plot a single trajectory
    p = Project.LoadFromHDF(args.project)
    t = p.LoadTraj(0)
    x = t['XYZList'][:,0,0][::args.stride]
    y = t['XYZList'][:,0,1][::args.stride]
    cm = pp.get_cmap('spectral')

    n_points = len(x)
    ax.set_color_cycle([cm(1.*i/(n_points-1)) for i in range(n_points-1)])
    for i in range(n_points-1):
        ax.plot(x[i:i+2],y[i:i+2])

    pp.title('Voronoi Microstate Decomposition, with first trajectory')
    


    pp.show()
Esempio n. 3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--project', default='ProjectInfo.h5')
    parser.add_argument(
        '-t',
        '--trajectories',
        nargs='+',
        help='''Supply either the path to a trajectory file (i.e. Data/Gens.lh5),
         or an integer, which will be interepreted as a trajectory index
         into the trajectories that accompany the project. default: plot all
         of the trajectories''',
        default=['-1'])
    args = parser.parse_args()

    p = Project.LoadFromHDF(args.project)

    # record the bounding box of the points so that we know
    # what to render for the background
    maxx, minx, maxy, miny = 1.2, -1.5, 2, -0.2

    # if -1 is included, add in ALL of the trajectories
    if '-1' in args.trajectories:
        args.trajectories.remove('-1')
        args.trajectories.extend(range(p['NumTrajs']))
    # remove duplicates
    args.trajectories = set(args.trajectories)

    for requested in args.trajectories:
        if os.path.exists(str(requested)):
            traj = Trajectory.LoadTrajectoryFile(str(requested))
            print 'plotting %s' % requested
            markersize = 50
        else:
            try:
                i = int(requested)
                traj = p.LoadTraj(i)
                print 'plotting %s' % i
                markersize = 5
            except ValueError:
                print >> sys.stderr, 'I couldnt figure out how to deal with the argument %s' % requested
                continue
            except IOError as e:
                print >> sys.stderr, str(e)
                continue

        xyz = traj['XYZList']
        x = xyz[:, 0, 0]
        y = xyz[:, 0, 1]

        maxx, maxy = max(np.max(x), maxx), max(np.max(y), maxy)
        minx, miny = min(np.min(x), minx), min(np.min(y), miny)
        pp.plot(x, y, '.', markersize=markersize, alpha=0.5)

    plot_v(minx=minx, maxx=maxx, miny=miny, maxy=maxy)
    pp.show()
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--project', default='ProjectInfo.h5')
    parser.add_argument('-t', '--trajectories', nargs='+',
        help='''Supply either the path to a trajectory file (i.e. Data/Gens.lh5),
         or an integer, which will be interepreted as a trajectory index
         into the trajectories that accompany the project. default: plot all
         of the trajectories''', default=['-1'])
    args = parser.parse_args()
    
    p = Project.LoadFromHDF(args.project)
    
    # record the bounding box of the points so that we know
    # what to render for the background
    maxx, minx, maxy, miny = 1.2, -1.5, 2, -0.2
    
    # if -1 is included, add in ALL of the trajectories
    if '-1' in args.trajectories:
        args.trajectories.remove('-1')
        args.trajectories.extend(range(p['NumTrajs']))
    # remove duplicates
    args.trajectories = set(args.trajectories)
    
    for requested in args.trajectories:
        if os.path.exists(str(requested)):
            traj = Trajectory.LoadTrajectoryFile(str(requested))
            print 'plotting %s' % requested
            markersize = 50
        else:
            try:
                i = int(requested)
                traj = p.LoadTraj(i)
                print 'plotting %s' % i
                markersize=5
            except ValueError:
                print >> sys.stderr, 'I couldnt figure out how to deal with the argument %s' % requested
                continue
            except IOError as e: 
                print >> sys.stderr, str(e)
                continue
    
        xyz = traj['XYZList']
        x = xyz[:,0,0]
        y = xyz[:,0,1]
        
        maxx, maxy = max(np.max(x), maxx), max(np.max(y), maxy)
        minx, miny = min(np.min(x), minx), min(np.min(y), miny)
        pp.plot(x, y, '.', markersize=markersize, alpha=0.5)
    
    plot_v(minx=minx, maxx=maxx, miny=miny, maxy=maxy)
    pp.show()
Esempio n. 5
0
for i, fn in enumerate(traj_list):
    print fn
    t = np.load(fn)
    c.train(t, ass[i])
    #c.train(t)

C, Sigma = c.get_current_estimate()

vals, vecs = scipy.linalg.eig(C, b=Sigma)

print vals
print vecs

io.saveh(args.out, vals=vals, vecs=vecs, C=C, Sigma=Sigma)

muller.plot_v()


ref = io.loadh('ref.h5')
ref['vecs'][:,0] *= -1

vecs[:,0] *= -1

plot([0, vecs[0,0]], [0, vecs[1,0]], color='white', lw=3)
plot([0, vecs[0,1]], [0, vecs[1,1]], color='white', ls='dashed', lw=3)

plot([0, ref['vecs'][0,0]], [0, ref['vecs'][1,0]], color='red', lw=3)
plot([0, ref['vecs'][0,1]], [0, ref['vecs'][1,1]], color='red', ls='dashed', lw=3)

show()