/usr/lib/python2.7/dist-packages/chaco/grid_data_source.py is in python-chaco 4.4.1-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | """ Defines the GridDataSource class.
"""
# Major library imports
from numpy import array
# Enthougth library imports
from traits.api import Constant, Instance, Tuple
# Chaco imports
from abstract_data_source import AbstractDataSource
from array_data_source import ArrayDataSource
from base import SortOrderTrait
class GridDataSource(AbstractDataSource):
""" Implements a structured gridded 2-D data source (suitable as an index
for an image, for example).
"""
#------------------------------------------------------------------------
# AbstractDataSource traits
#------------------------------------------------------------------------
# The dimensionality of the indices into this data source (overrides
# AbstractDataSource).
index_dimension = Constant('image')
# The dimensionality of the value at each index point (overrides
# AbstractDataSource).
value_dimension = Constant('scalar')
# The sort order of the data (overrides AbstractDataSource). There is no
# overall sort order on 2-D data, but for gridded 2-D data, each axis can
# have a sort order.
sort_order =Tuple(SortOrderTrait, SortOrderTrait)
#------------------------------------------------------------------------
# Private traits
#------------------------------------------------------------------------
# Data grid ticks along the x (horizontal) axis.
_xdata = Instance(ArrayDataSource, args=())
# Data grid ticks along the y (vertical) axis
_ydata = Instance(ArrayDataSource, args=())
# Cached values of min and max as long as **_data** doesn't change
# (overrides ArrayDataSource). ((min_x, max_x), (min_y, max_y))
_cached_bounds = Tuple
#------------------------------------------------------------------------
# Public methods
#------------------------------------------------------------------------
def __init__(self, xdata=array([]), ydata=array([]),
sort_order=("none","none"), **kwargs):
super(GridDataSource, self).__init__(**kwargs)
self.set_data(xdata, ydata, sort_order)
def set_data(self, xdata, ydata, sort_order=None):
""" Sets the data, and optionally the sort order, for this data source.
Parameters
----------
xdata, ydata : array
The data to use.
sort_order : SortOrderTrait
The sort order of the data
"""
if sort_order is not None:
self.sort_order = sort_order
self._xdata.set_data(xdata, sort_order[0])
self._ydata.set_data(ydata, sort_order[1])
else:
self._xdata.set_data(xdata)
self._ydata.set_data(ydata)
self._compute_bounds()
self.data_changed = True
#------------------------------------------------------------------------
# AbstractDataSource interface
#------------------------------------------------------------------------
def get_data(self):
"""get_data() -> (xdata, ydata)
Implements AbstractDataSource. Because this class uses structured
(gridded) data, this method returns the pair of data axes, instead of,
for example, a full mesh-grid. This behavious differs from
other data sources.
"""
if self._xdata is not None:
xdata = self._xdata
else:
xdata = ArrayDataSource(array([]))
if self._ydata is not None:
ydata = self._ydata
else:
ydata = ArrayDataSource(array([]))
return xdata, ydata
def get_bounds(self):
"""get_bounds() -> ((LLx, LLy), (URx, URy))
Implements AbstractDataSource. Returns two 2-D points, min and max, that
represent the bounding corners of a rectangle enclosing the data set.
Note that these values are not view-dependent, but represent intrinsic
properties of the DataSource.
If data axis is the empty set, then the min and max valuess are 0.0.
"""
if self._cached_bounds == ():
self._compute_bounds()
return self._cached_bounds
#------------------------------------------------------------------------
# Private methods
#------------------------------------------------------------------------
def _compute_bounds(self, data=None):
""" Computes the minimum and maximum points (LLx, LLy) and (URx, URy) of
the data.
"""
if data is None:
xdata, ydata = self.get_data()
else:
xdata, ydata = data
xbds = xdata.get_bounds()
ybds = ydata.get_bounds()
self._cached_bounds = ((xbds[0], ybds[0]), (xbds[1], ybds[1]))
#------------------------------------------------------------------------
# Event handlers
#------------------------------------------------------------------------
def _metadata_changed(self, event):
self.metadata_changed = True
def _metadata_items_changed(self, event):
self.metadata_changed = True
|