Menu

Colormap & Plotgroup

Help
Kesh Rao
2012-01-30
2012-12-12
  • Kesh Rao

    Kesh Rao - 2012-01-30

    Hi,
      I was hoping to get your advice on how to use the colormaps and save plotgroups. I found a some information on this on the website and in the examples; but I'm still having some trouble with the specific task.
    I want to create color images as you guys have on the main page of topographica. Ideally, I would like to have the LGN (OnEdges and OffEdges) as two colors and sheet (not necessarily physiological sheet, just for viewing) that combines the two LGN sheets but retains their two colors. So this way, on one sheet, I would be able to view the contribution of the OnEdges and OffEdges with two colors. I'm not sure if this would look great but I think it may look neat and may make for easy explanations of the edge detection process.
      Currently, I'm creating a plotgroup as such:

      

    from topo.command.analysis import update_activity
    from topo.plotting.plotgroup import create_plotgroup
    pg = create_plotgroup(name='Colored Activity',category='Basic', auto_refresh=True,
                 doc='Plot the activity for all Sheets, plot by color.',
                 pre_plot_hooks=[update_activity], plot_immediately=True)
    pg.add_plot('RGB Colored Activity',
                [('Red','Activity')])
    

    I can then save this plotgroup using the command

    save_plotgroup('Colored Activity')
    

    and it saves all the sheets that I have in that one color.

    In one of the examples, I also found a nice way to save "movies" using the following setup:

    print "%s: Making movie..."%name
    movie = ActivityMovie(name = name,
                        recorder = model.Recorder,
                        variables= ['Retinal Activity','DS Activity',
                                    'OnE Activity', 'OffE Activity'],
                        montage_params = dict(titles=['Eye','Dorsal Stream',
                                                        'On Edges', 'Off Edges'],
                                                        hooks=[None,None,None,
                                                        lambda x: x.transpose(Image.FLIP_LEFT_RIGHT)]),
                        frame_times = range(start,run_duration,step),
                        timecode_offset = -start,
                        filename_fmt="%n/frame%t.%T",
                        filename_prefix = 'C:\Users\TopoRelated\TestColorMap')
    
    print "%s: Saving movie."%name
    movie.save()
    

    But what I'm still having trouble with is incorporating the plotgroup into the version where it saves the movies and I'm also not sure how to combine LGN On/Off edges such that it retains it colors in one sheet.

    Thanks very much!

     
  • James A. Bednar

    James A. Bednar - 2012-01-31

    Busted!  The pictures on the front page of topographica.org were created before Topographica existed. :-)  They were from my earlier simulator and were part of the initial proposal for Topographica, which was then funded, and we've never updated them based on actual results from Topographica.  Scientifically, we could easily reproduce those results, but graphically, we have never actually implemented colormap support in Topographica.  Yes, you can use the RGB channels as you've shown above, but proper colormap support for things like KRYW maps (black, then red, then yellow, then white for increasing levels of activity) has never been implemented.  The code for it is very simple, and is actually currently in the code somewhere as a comment with pseudocode, but it's never been a priority for anyone.  So only single-hue colormaps will work currently, and only R, G, or B even then, which isn't all that good for what you are trying to do.

    And the other thing you're asking for has also been on the list for 10 years now - combining ON and OFF channels into a single plot.  That's what my old custom simulator used to do, but we have never worked out a general way to do that in Topographica, and again it's never been anyone's priority.  It would be very handy, because it would help cut down on the number of plots we need to look at, but combining information from different sheets to be plotted together violates all sorts of information encapsulation principles and opens up lots of difficulties with how we'd actually get data from one Sheet object to another.  We have some ideas summarized in a feature request somewhere, but no current plans for figuring out a clean way to implement that.

    If you're not up for implementing these features in Topographica, you can always grab the underlying arrays, subtract them, and visualize them using e.g. Matplotlib, which has colormap support already…

    Jim

     
  • Kesh Rao

    Kesh Rao - 2012-01-31

    Hey Jim,
      Haha, it's totally no problem. Marc and I were looking into those figures and we thought they looked really cool so I thought I'd give it a whirl and try and do it. I do agree that doing something like this isn't really all that much of a priority. It's just a superficial way of viewing the information.
      I'll try to look into it this week and if I find some convenient way of doing it, I'll definitely post it on the forum so we can talk about it. I think this will also end up becoming a side project. It's not super important but might be fun.
    Thanks again. We appreciate all the help!
    Kesh

     
  • James A. Bednar

    James A. Bednar - 2012-01-31

    Well, how the data is visualized can have a huge impact on how we interpret it, so it does matter.  The main reason we haven't messed with it is that we are usually using subplots, with e.g. orientation plotted in the hue while the activity is plotted in the value or saturation of an HSV plot.  And the retina is usually better in monochrome, so that it looks like a picture.  So really only the retinal ganglion cells and LGN cells would use colormaps in our own setup.

    In any case, if you want to tackle it, the current sketches of code are in topo/plotting/bitmap.py (class PaletteBitmap), and topo/plotting/pallet.py (entire file).  All of it should be treated as complete nonsense except the comments in palette.py that say how color mapping should work and provide pseudocode for StringBasedPalette; all the actual code is ancient sketches that have never been tested or used and are highly likely to be more confusing than useful.  The basic idea is definitely sound, as I did it in my old simulator, but the current sketches of Python implementation are probably more confusing than they are useful, and it's probably best simply to throw them away.  In fact, we were planning to do that in the next couple of weeks, so that they won't be in the 1.0 release, but we can always put them back in later once they are working.

     
  • Kesh Rao

    Kesh Rao - 2012-02-02

    I completely agree that visualization of the data is extremely important. Sorry, I didn't mean to imply that it wasn't. I just meant that the current set up with subplots works well so this colormap project would just improve on it.
    I have tentatively found a way to do what we talked about but I didn't do it in python. I reverted to exporting the data to matlab and working there. I still feel more comfortable with matlab than I do with python.

    Here is a picture of what it looks like:
    I'd be happy to share the matlab code if anyone wants to do something similar. The way I've done it is a little tedious (with exporting to matlab) but it works for now.

     
  • James A. Bednar

    James A. Bednar - 2012-02-02

    The picture hasn't shown up…

     

Log in to post a comment.