ioam / topographica

A general-purpose neural simulator focusing on topographic maps.
topographica.org
BSD 3-Clause "New" or "Revised" License
53 stars 32 forks source link

how to create a new plot group so that it is added to the menus #615

Closed antolikjan closed 7 years ago

antolikjan commented 9 years ago

Hello everybody,

I have now proceeded to reimplement my modulation ratio analysis in the new topographica. I have cleaned up and significantly trimmed the code. In any case at the end I have the code that used to add the new analysis and related visualization gui into the topographica menus, it goes like this:

pg= create_plotgroup(name='Orientation Preference and Complexity',category="Preference Maps", doc='Measure preference for sine grating orientation.', pre_plot_hooks=[measure_and_analyze_complexity.instance( preference_fn=DSF_WeightedAverage( value_scale=(0., 1./numpy.pi),selectivity_scale=(0.,17.0)))])

pg.add_plot('Orientation Preference',[('Hue','OrientationPreference')]) pg.add_plot('Orientation Preference&Selectivity',[('Hue','OrientationPreference'), ('Confidence','OrientationSelectivity')]) pg.add_plot('Orientation Selectivity',[('Strength','OrientationSelectivity')]) pg.add_plot('Modulation Ratio',[('Strength','ComplexSelectivity')]) pg.add_plot('Phase Preference',[('Hue','PhasePreference')]) pg.add_static_image('Color Key','static/or_key_white_vert_small.png')

I have the file containing this code in analysis/vision.py file, and I also tried to explicitly import this file after loading up a model. In either case I do not get a new menu item as I used to in the old topographica. Is this supposed to work or did the mechanism changed now?

Many thanks, Jan

jbednar commented 9 years ago

It should work if you make sure that this code is loaded before the -g option to topographica on the commandline. Where -g is located might not have mattered long ago, but it's important now because the GUI is launched when the parser reaches -g going left to right on the commandline, and once the GUI has been launched it does not try to update the menus. I hope this will solve the issue...

antolikjan commented 9 years ago

I see. I am still surprised, since I have that file in the topo/analysis directory, and the __init__.py file in that directory seems to have the autoloading code there which should import it. Does that mean that the analysis is not imported before 'the -g option is activated'? In general is there a prefered way currently how should users add their own analysis into topographica?

jbednar commented 9 years ago

The autoloading code in topo.analysis means that if someone does from topo.analysis import *, any user-supplied file in that directory will get loaded. Meanwhile, when the GUI launches, it does (in topo.tkgui.__init__.py) from topo.X import *, where X is coordmapper, base, learningfn, transferfn, pattern, projection, responsefn, and sheet. I.e., topo.analysis is not in that list. I don't recall why it isn't, except that those other directories are the "library" of primitives for making models, while analysis isn't. Anyway, we can certainly consider adding analysis to this list; I can't think of any reason not to. Meanwhile, you can make sure it's loaded by doing from topo.analysis import * or import topo.analysis.yourfile before -g.

antolikjan commented 9 years ago

Ok thanks, I thought of that workaround but was wondering whether you have some established way to do it. You can close this issue as far as I am concerned...

jbednar commented 9 years ago

Ok. Just to be clear, do you vote that we add topo.analysis and topo.plotting to the directories that the tkgui automatically imports? I don't think anyone will vote against it, since other people don't currently use the tkgui.