Ejemplo n.º 1
0
def visualizeGFSName(gfsFileName,
                     outFileBase,
                     imgFormat='png',
                     cMap=ColorMap.BlackBodyMap(),
                     mapRange=1.0,
                     mapLimits=None,
                     sitesName=None,
                     obstacles=None):
    '''Visualizes a grid file sequence with the given color map.

    @param      gfsFileName     A string.  The name of the GridFileSequence to visualize.
    @param      outFileBase     A string.  The basic name of the images to be output.
                                For each grid in the sequence, it outputs outFileBase_###.imgFormat.
                                The path must already exist.
    @param      imgFormat       A string.  The output image format (png, jpg, or bmp )
    @param      cMap            An instance of ColorMap.  Indicates how the visualization works.
    @param      mapRange        A float.  Determines what fraction of the data range maps to the color
                                range.  For example, if mapRange is 0.75, then the value that is
                                75% of the way between the min and max value achieves the maximum
                                color value.  Ignored if mapLimits is not None.
    @param      mapLimits       A tuple which defines the map range independent of the real values in
                                the data (minVal, maxVal).  If the tuple has two values, that defines the range.
                                If either is None, then the corresponding value from the data is used.
    @param      sitesName       A string.  The path to a set of trajectory sites
    @param      obstacles       An instance of ObstacleSet (optional).  If obstacle are provided,
                                Then they will be drawn over the top of the data.
    '''
    reader = GFS.GridFileSequenceReader(gfsFileName)
    reader.setNext(0)
    try:
        sites = loadTrajectory(sitesName)
    except:
        sites = None
    visualizeGFS(reader, cMap, outFileBase, imgFormat, mapRange, mapLimits,
                 sites, obstacles)
Ejemplo n.º 2
0
    def main():
        import optparse
        import ColorMap
        import sys, os
        import obstacles
        from trajectory import loadTrajectory
        parser = optparse.OptionParser()
        parser.add_option( '-i', '--input', help='A path to a grid file sequence - the data to visualize',
                           action='store', dest='input', default='' )
        parser.add_option( '-t', '--trajectory', help='(Optional) The path to the pedestrian data which produced the voronoi diagrams.',
                           action='store', dest='trajName', default=None )
        parser.add_option( '-o', '--output', help='The path and base filename for the output images (Default is "vis").',
                           action='store', dest='output', default='./vis' )
        parser.add_option( '-c', '--colorMap', help='Specify the color map to use.  Valid values are: %s.  Defaults to "black_body".' % ColorMap.getValidColorMaps(),
                           action='store', dest='cmapName', default='black_body' )
        parser.add_option( '-e', '--extension', help='Image format: [png, jpg, bmp] (default is png)',
                           action='store', dest='ext', default='png' )
        parser.add_option( '-b', '--obstacles', help='Path to an obstacle xml file',
                           action='store', dest='obstXML', default=None )
        options, args = parser.parse_args()

        if ( options.input == '' ):
            print '\n *** You must specify an input file'
            parser.print_help()
            sys.exit(1)

        try:
            colorMap = ColorMap.getColorMapByName( options.cmapName )
        except KeyError:
            print '\n *** You have selected an invalid color map: %s' % ( options.cmapName )
            parser.print_help()
            sys.exit(1)

        if ( not options.ext.lower() in ( 'png', 'jpg', 'bmp' ) ):
            print '\n *** You have selected an invalid file format: %s' % ( options.ext )
            parser.print_help()
            sys.exit(1)

        trajData = None
        if ( not options.trajName is None ):
            try:
                trajData = loadTrajectory( options.trajName )
            except ValueError:
                print "Unable to recognize the data in the file: %s" % ( options.trajName )

        folder, baseName = os.path.split( options.output )
        if ( folder ):
            if ( not os.path.exists( folder ) ):
                os.makedirs( folder )

        reader = GFS.GridFileSequenceReader( options.input )
        reader.setNext( 0 )    

        obstacles = None
        if ( options.obstXML ):
            obstacles, bb = obstacles.readObstacles( options.obstXML )

        visualizeGFS( reader, colorMap, options.output, options.ext, 1.0, trajData, obstacles )
Ejemplo n.º 3
0
def getcolormap(**kwargs):
    colors = kwargs.pop('colors', None)
    issingle = False
    if colors is None:
        colors = kwargs.pop('color', None)
        issingle = True
    if not colors is None:
        if issingle or isinstance(colors, str):
            c = getcolor(colors)
            cmap = ColorMap(c)
        else:
            cs = []
            for cc in colors:
                c = getcolor(cc)
                cs.append(c)
            cmap = ColorMap(cs)
    else:
        cmapstr = kwargs.pop('cmap', 'matlab_jet')
        if cmapstr is None:
            cmapstr = 'matlab_jet'
        fn = cmapstr + '.rgb'
        fn = os.path.join(migl.get_cmap_folder(), fn)
        if not os.path.exists(fn):
            raise IOError('cmap file not exists: %s' % fn)
        alpha = kwargs.pop('alpha', None)
        if alpha is None:
            cmap = ColorUtil.loadColorMap(fn)
        else:
            alpha = (int)(alpha * 255)
            cmap = ColorUtil.loadColorMap(fn, alpha)
    reverse = kwargs.pop('cmapreverse', False)
    if reverse:
        cmap.reverse()
    return cmap
Ejemplo n.º 4
0
def getcolormap(**kwargs):
    colors = kwargs.pop('colors', None)
    issingle = False
    if colors is None:
        colors = kwargs.pop('color', None)
        issingle = True
    if not colors is None:
        if issingle or isinstance(colors, str):
            c = getcolor(colors)
            cmap = ColorMap(c)
        else:
            cs = []
            for cc in colors:
                c = getcolor(cc)
                cs.append(c)
            cmap = ColorMap(cs)
    else:
        cmapstr = kwargs.pop('cmap', 'matlab_jet')
        if cmapstr is None:
            cmapstr = 'matlab_jet'
        alpha = kwargs.pop('alpha', None)
        if alpha is None:
            cmap = ColorUtil.getColorMap(cmapstr)
        else:
            alpha = (int)(alpha * 255)
            cmap = ColorUtil.getColorMap(cmapstr, alpha)
    reverse = kwargs.pop('cmapreverse', False)
    if reverse:
        cmap.reverse()
    return cmap
Ejemplo n.º 5
0
    def plot(self, width_in=400, height_in=400):

        import ColorMap
        import Tkinter

        cmax = max(self.values())
        cmin = min(self.values())

        offset = 0.05 * min(width_in, height_in)
        xmin, ymin, xmax, ymax = 0, 0, self.size()[0], self.size()[1]
        scale = min(0.9 * width_in, 0.9 * height_in) / max(
            xmax - xmin, ymax - ymin)

        root = Tkinter.Tk()
        frame = Tkinter.Frame(root)
        frame.pack()

        text = Tkinter.Label(width=20, height=10, text='matrix sparsity')
        text.pack()

        canvas = Tkinter.Canvas(bg="black", width=width_in, height=height_in)
        canvas.pack()

        button = Tkinter.Button(frame,
                                text="OK?",
                                fg="red",
                                command=frame.quit)
        button.pack()

        for index in self.keys():
            ix, iy = index[0], ymax - index[1] - 1
            ya, xa = offset + scale * (ix), height_in - offset - scale * (iy)
            yb, xb = offset + scale * (ix +
                                       1), height_in - offset - scale * (iy)
            yc, xc = offset + scale * (ix + 1), height_in - offset - scale * (
                iy + 1)
            yd, xd = offset + scale * (ix), height_in - offset - scale * (iy +
                                                                          1)
            color = ColorMap.strRgb(self[index], cmin, cmax)
            canvas.create_polygon(xa, ya, xb, yb, xc, yc, xd, yd, fill=color)

        root.mainloop()
Ejemplo n.º 6
0
    def plot(self, width_in=400, height_in=400):

        import ColorMap
        import Tkinter

        cmax = max(self.values())
        cmin = min(self.values())
        
        offset = 0.05*min(width_in, height_in)
        xmin, ymin, xmax, ymax = 0, 0, self.size()[0], self.size()[1]
        scale = min(0.9*width_in, 0.9*height_in)/max(xmax-xmin, ymax-ymin)

        root = Tkinter.Tk()
        frame = Tkinter.Frame(root)
        frame.pack()
        
        text = Tkinter.Label(width=20, height=10, text='matrix sparsity')
        text.pack()
        

        canvas = Tkinter.Canvas(bg="black", width=width_in, height=height_in)
        canvas.pack()

        button = Tkinter.Button(frame, text="OK?", fg="red",
                                command=frame.quit)
        button.pack()

        for index in self.keys():
            ix, iy = index[0], ymax-index[1]-1
            ya, xa = offset+scale*(ix), height_in -offset-scale*(iy)
            yb, xb = offset+scale*(ix+1), height_in -offset-scale*(iy)
            yc, xc = offset+scale*(ix+1), height_in -offset-scale*(iy+1)
            yd, xd = offset+scale*(ix), height_in -offset-scale*(iy+1)
            color = ColorMap.strRgb(self[index], cmin, cmax)
            canvas.create_polygon(xa, ya, xb, yb, xc, yc, xd, yd, fill=color)
        
        root.mainloop()
Ejemplo n.º 7
0
        else:
            # middle, connect with -256, +256, -1, +1
            g.add_edge(i, i - 256)
            g.add_edge(i, i + 256)
            g.add_edge(i, i - 1)
            g.add_edge(i, i + 1)

printStats(g)
s = (256, 256)
p1 = np.zeros(s, dtype=np.float64)
p2 = np.zeros(s, dtype=np.float64)
p3 = np.zeros(s, dtype=np.float64)

for i in range(0, GRAPH_SIZE / 256):
    for j in range(0, GRAPH_SIZE / 256):
        payload = g_payload[g.vertex(i + j)]
        p1[i,j] = payload.susceptible + payload.immune
        p2[i,j] = payload.incubation1 + payload.incubation2 + payload.incubation3 + payload.incubation4
        p3[i,j] = payload.contagious1a + payload.contagious2a

import ColorMap
img1 = Image.fromarray(ColorMap.colorMap(p1))
# img1.save("/Users/paul.warren/Documents/ebola/images/mapped.png")
img1.show()