18 BoundingEllipse class should be imported directly from xboa.bunch.weighting
30 The BoundingEllipse class defines an arbitrary dimensional ellipse that can
31 be taken as a boundary for VoronoiWeighting.
33 The bounding ellipse is defined by the locus of points \f$\vec{x}\f$ \n
34 \f$ (\vec{x}-\bar{x})^T \mathbf{V^{-1}} (\vec{x}-\bar{x}) = 1 \f$\n
35 where \f$\mathbf{V}\f$ is a matrix defining the ellipse orientation and
36 \f$ \bar{x} \f$ is a vector defining the ellipse centroid. The
37 BoundingEllipse can be used to eliminate points outside of the ellipse
38 and define a (finite) set of points distributed about the ellipse boundary.
41 def __init__(self, limit_ellipse, limit_mean, limit_n_per_dim):
43 Initialise the bounding ellipse
44 - limit_ellipse: defines the ellipse. Should be a numpy.array with shape
45 (dimension, dimension).
46 - limit_mean: defines the ellipse centroid. Should be a numpy.array with
48 - limit_n_per_dim: integer that defines the number \f$n\f$ of points on
49 the ellipse boundary. xboa will set up points distributed evenly
50 about the ellipse, with the number given by \f$n^{D}\f$ where \f$D\f$
51 is the ellipse dimension.
54 self.
dim = numpy.shape(limit_ellipse)[0]
55 if type(limit_n_per_dim) != type(1)
or limit_n_per_dim < 1:
56 raise ValueError(
"limit_n_per_dim should be an integer > 1")
57 if numpy.shape(limit_ellipse) != (self.
dim, self.
dim):
58 raise ValueError(
"limit_ellipse shape "+\
59 str(numpy.shape(limit_ellipse))+
" should be "+\
61 if numpy.shape(limit_mean) != (self.
dim,):
62 raise ValueError(
"limit_mean shape "+\
63 str(numpy.shape(limit_mean))+
" should be "+\
69 bp_temp[i] = [
None]*self.
dim
70 for j
in range(self.
dim):
71 bp_temp[i][j] = row[0, j]+limit_mean[j]
75 self.
mean = limit_mean
79 Iterate over the points, and delete items that are outside the ellipse.
80 - points_in. Set of n points in form of a numpy array with shape
82 Returns a tuple of (points_out, not_cut_indices) where points_out is a
83 numpy array of shape (m, dimension) containing all points that sit on or
84 inside the ellipse boundary and not_cut_indices is a list of integers
85 of length m corresponding to the position in points_in of each of the m
92 while i < len(points):
94 delta = point - self.
mean
95 delta_t = numpy.transpose(delta)
96 arg = delta.dot(self.ellipse_inv.dot(delta_t))
98 points = numpy.delete(points, i, 0)
100 not_cut_indices.append(index)
103 return points, not_cut_indices
common module defines common utility data and functions that are used elsewhere
def __init__
Initialise the bounding ellipse.
The BoundingEllipse class defines an arbitrary dimensional ellipse that can be taken as a boundary fo...
def cut_on_bound
Iterate over the points, and delete items that are outside the ellipse.