1 """
2 Topographica cortical map simulator package.
3
4 Topographica is designed as a collection of packages from which
5 elements can be selected to model specific systems. For more
6 information, see the individual subpackages::
7
8 base - Core Topographica functions and classes
9 plotting - Visualization functions and classes
10 analysis - Analysis functions and classes (besides plotting)
11 tkgui - Tk-based graphical user interface (GUI)
12 command - High-level user commands
13 misc - Various useful independent modules
14
15 The Topographica primitives library consists of a family of classes
16 that can be used with the above functions and classes::
17
18 sheet - Sheet classes: 2D arrays of processing units
19 projection - Projection classes: connections between Sheets
20 pattern - PatternGenerator classes: 2D input or weight patterns
21 ep - EventProcessor classes: other simulation objects
22 transferfn - Transfer functions, for e.g. normalization or squashing
23 responsefn - Calculate the response of a Projection
24 learningfn - Adjust weights for a Projection
25 coordmapper - CoordinateMapperFn classes: map coords between Sheets
26
27 Each of the library directories can be extended with new classes of
28 the appropriate type, just by adding a new .py file to that directory.
29 E.g. new PatternGenerator classes can be added to pattern/, and will
30 then show up in the GUI menus as potential input patterns.
31
32 $Id: __init__.py 11201 2010-07-14 13:07:21Z ceball $
33 """
34 __version__ = "$Revision: 11201 $"
35
36
37
38 __all__ = ['analysis',
39 'base',
40 'command',
41 'coordmapper',
42 'ep',
43 'learningfn',
44 'misc',
45 'numbergen',
46 'transferfn',
47 'pattern',
48 'plotting',
49 'projection',
50 'responsefn',
51 'sheet']
52
53
54 release = ''
55 version = ''
56
57
58 import param
59 import os
60
61
62
63 _default_output_path = os.path.join(os.path.expanduser("~"),'topographica')
64 if not os.path.exists(_default_output_path):
65 print "Creating %s"%_default_output_path
66 os.mkdir(_default_output_path)
67
68
69
70 _package_path = os.path.split(__file__)[0]
71
72 param.normalize_path.prefix = _default_output_path
73 param.resolve_path.search_paths+=([_default_output_path] + [_package_path])
74
75
76
77
78
79
80 try:
81 import Image
82 except ImportError:
83 from PIL import Image, ImageOps, ImageDraw, ImageFont
84 import sys
85 sys.modules['Image']=Image
86 sys.modules['ImageOps']=ImageOps
87 sys.modules['ImageDraw']=ImageDraw
88 sys.modules['ImageFont']=ImageFont
89
90
91 try:
92 import ImageTk
93 except ImportError:
94 try:
95 from PIL import ImageTk
96 import sys
97 sys.modules['ImageTk']=ImageTk
98 except ImportError:
99 pass
100
101
102
103
104
105
106
107
108
109
110
111
112
114 """
115 Allow instances of numpy.ufunc to pickle.
116 """
117
118
119
120 from numpy import ufunc
121 import copy_reg
122
123 def ufunc_pickler(ufunc):
124 """Return the ufunc's name"""
125 return ufunc.__name__
126
127 copy_reg.pickle(ufunc,ufunc_pickler)
128
129 _numpy_ufunc_pickle_support()
130
131
132
133
134
135
137 """Allow instances of gmpy.mpq to pickle."""
138 from gmpy import mpq
139 mpq_type = type(mpq(1,10))
140 import copy_reg
141 copy_reg.pickle(mpq_type,lambda q: (mpq,(q.digits(),)))
142
143
144
146 """Allow instance methods to pickle."""
147
148
149
150
151
152 def _pickle_instance_method(mthd):
153 mthd_name = mthd.im_func.__name__
154 obj = mthd.im_self
155 return getattr, (obj,mthd_name)
156
157 import copy_reg, types
158 copy_reg.pickle(types.MethodType, _pickle_instance_method)
159
160 _instance_method_pickle_support()
161
162
163
164
165
166
167
168 time_type = None
169 try:
170 import gmpy
171 time_type = gmpy.mpq
172 time_type_args = ()
173 _mpq_pickle_support()
174 except ImportError:
175 import topo.misc.fixedpoint as fixedpoint
176 param.Parameterized().warning('gmpy.mpq not available; using slower fixedpoint.FixedPoint for simulation time.')
177 time_type = fixedpoint.FixedPoint
178 time_type_args = (4,)
179
180 from topo.misc.util import gmpyImporter
181 import sys
182 sys.meta_path.append(gmpyImporter())
183
184 from topo.base.simulation import Simulation
185
186 if time_type is not None:
187 Simulation.time_type = time_type
188 Simulation.time_type_args = time_type_args
189
190 sim = Simulation()
191
192
193
194
195
197 """Print release and licensing information."""
198
199 ABOUT_TEXT = """
200 Pre-release version %s (%s) of Topographica; an updated
201 version may be available from topographica.org.
202
203 This program is free, open-source software available under the BSD
204 license (http://www.opensource.org/licenses/bsd-license.php).
205 """%(release,version)
206 if display:
207 print ABOUT_TEXT
208 else:
209 return ABOUT_TEXT
210
211
212
213
214
215
216
217
218 from numpy import seterr
219 old_seterr_settings=seterr(all="raise",under="ignore")
220