From 02d1e3a84814da3f3ecc22c9ed094dc55383f2a2 Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Fri, 1 Jun 2012 11:19:55 -0400 Subject: Add a Photons.reduced() method that returns a new Photons object with a random subset of photons based on the reduction_factor given. --- chroma/event.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/chroma/event.py b/chroma/event.py index 6e0686a..f4971ce 100644 --- a/chroma/event.py +++ b/chroma/event.py @@ -117,13 +117,32 @@ class Photons(object): last_hit_triangles = np.concatenate((self.last_hit_triangles, other.last_hit_triangles)) flags = np.concatenate((self.flags, other.flags)) weights = np.concatenate((self.weights, other.weights)) - return Photons(pos, dir, pol, wavelengths, t, last_hit_triangles, flags, - weights) + return Photons(pos, dir, pol, wavelengths, t, + last_hit_triangles, flags, weights) def __len__(self): '''Returns the number of photons in self.''' return len(self.pos) + def reduced(self, reduction_factor=1.0): + '''Return a new Photons object with approximately + len(self)*reduction_factor photons. Photons are selected + randomly.''' + n = len(self) + choice = np.random.permutation(n)[:int(n*reduction_factor)] + print len(choice) + pos = self.pos[choice] + dir = self.dir[choice] + pol = self.pol[choice] + wavelengths = self.wavelengths[choice] + last_hit_triangles = self.last_hit_triangles[choice] + t = self.t[choice] + flags = self.flags[choice] + weights = self.weights[choice] + + return Photons(pos, dir, pol, wavelengths, t, + last_hit_triangles, flags, weights) + class Channels(object): def __init__(self, hit, t, q, flags=None): '''Create a list of n channels. All channels in the detector must -- cgit