1
2 """
3 Topographica SheetView objects and its subclasses.
4
5 For use with the Topographica plotting and data analysis mechanisms.
6 A Sheet object has its internal data which remains hidden, but it will
7 create views of this data depending on the Sheet defaults or the
8 information requested. This way there can be multiple views recorded
9 for a single sheet, and a view can be passed around independent of the
10 originating source object.
11
12 $Id: sheetview.py 10672 2009-10-28 01:00:50Z ceball $
13 """
14 __version__='$Revision: 10672 $'
15
16 import types
17 import operator
18
19 import param
20
21 import sheet
22
23
24
25
26
27
28
29
30
31
32
33 ADD = 'ADD'
34 SUBTRACT = 'SUB'
35 MULTIPLY = 'MUL'
36 DIVIDE = 'DIV'
37
38 operations = {ADD : operator.add,
39 SUBTRACT : operator.sub,
40 MULTIPLY : operator.mul,
41 DIVIDE : operator.truediv}
42
43
45 """
46 A SheetView is constructed from a matrix of values, a bounding box
47 for that matrix, and a name. There are two major ways to create a
48 SheetView: one is from a single matrix of data from a single
49 sheet, the other is by combining the matrices from multiple
50 matrices or SheetViews.
51 """
52
53 cyclic = param.Boolean(default=False,doc=
54 """Whether or not the values in this View's matrix represent a cyclic dimension.""")
55
56
57
58
59
60 norm_factor = param.Parameter(None,doc="""If cyclic is True, this value is the cyclic range.""")
61
62
63
64
65 - def __init__(self, (term_1, term_2), src_name=None, precedence = 0.0, timestamp = -1, row_precedence = 0.5, **params):
66 """
67 For ``__init__(self, input_tuple, **params)``, there are three
68 types of input_tuples::
69
70 (matrix_data, matrix_bbox)
71
72 This form locks the value of the sheetview to a single matrix.
73 Terminating case of a composite SheetView.
74
75 (operation, [tuple_list])
76
77 'operation' is performed on the matrices collected from
78 tuple_list. See the list of valid operations in
79 operations.keys().
80
81 Each tuple in the tuple_list is one of the following::
82
83 (SheetView, None)
84 Another SheetView may be passed in to create nested plots.
85 (matrix_data, bounding_box)
86 Static matrix data complete with bounding box.
87 (Sheet, sheet_view_name)
88 This gets sheet_name.sheet_view(sheet_view_name) each time
89 the current SheetView has its data requested by .view().
90
91 (Sheet, sheet_view_name)
92
93 Degenerate case that will pull data from another SheetView
94 and not do any additional processing. Don't yet know a
95 use for this case, but documented for possible future use.
96 """
97 super(SheetView,self).__init__(**params)
98
99 self.src_name = src_name
100 self.precedence = precedence
101 self.row_precedence = row_precedence
102 self.timestamp = timestamp
103
104
105
106
107 if term_1 not in operations.keys():
108 self.operation = ADD
109 self._view_list = [(term_1, term_2)]
110 else:
111 self.operation = operations[term_1]
112 self._view_list = term_2
113 if not isinstance(self._view_list,types.ListType):
114 self._view_list = [self._view_list]
115
116
118 """
119 Return the requested view as a (matrix, bbox) tuple.
120
121 If the constructor was given multiple maps, the view must be
122 built before being returned, which may lock in new views of
123 data from the specified sheets.
124
125 Inputs are in the variable self._view_list which is a list of
126 tuples, with each tuple being a matrix and a bounding box, or
127 a sheet and a map name. The sequence cannot be dumped into
128 maps just once because the raw maps may have changed, so other
129 sheets must be queried for the data repeatedly.
130 """
131 maps = []
132 for tup in self._view_list:
133 (term_1, term_2) = tup
134 if isinstance(term_1,sheet.Sheet):
135 maps.append(term_1.sheet_views[term_2])
136 elif isinstance(term_1,SheetView):
137 maps.append(term_1.view())
138 else:
139 maps.append((term_1, term_2))
140
141
142
143 return self.sum_maps(maps)
144
145
147 """
148 Convert the list of (matrix, bbox) tuples into a single matrix
149 and another bounding box. Not a protected function as it could
150 prove useful to other areas of the simulator.
151
152 THIS MUST BE EXPANDED IN THE FUTURE TO MAKE PROPER USE OF THE
153 BOUNDING BOX INFORMATION. CURRENT (8/04) IMPLEMENTATION
154 PASSES THE FIRST MAP IN THE LIST AS THE BOUNDING BOX FOR THE
155 CONSTRUCTED VIEW.
156
157 WOULD HAVE DONE AN ADD/INTERSECTION/UNION, BUT BOUNDINGREGION
158 DOES NOT YET SUPPORT SUCH OPERATIONS.
159 """
160 result = maps.pop(0)
161 for m in maps:
162
163 result = (apply(self.operation, (result[0], m[0])), result[1])
164 return result
165
166
167
169 """
170 SPRING 2005: Currently does not extend any functions, but can do
171 so to add outlines, and other interesting features.
172
173 Consists of an X,Y position for the unit that this View is
174 created for. Subclasses the SheetView class.
175
176 UnitViews should be stored in Sheets via a tuple
177 ('Weights',Sheet,Projection,X,Y). The dictionary in Sheets can be
178 accessed by any valid key.
179 """
180
181
182 - def __init__(self, term_tuple, x, y, projection, timestamp, **params):
190
191
193 """
194 ProjectionViews should be stored in Sheets via a tuple
195 ('Weights',Sheet,Projection).
196 """
197
198 - def __init__(self, term_tuple,projection,timestamp,**params):
204