summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Seibert <stan@mtrr.org>2012-06-01 11:19:55 -0400
committertlatorre <tlatorre@uchicago.edu>2021-05-09 08:42:39 -0700
commit02d1e3a84814da3f3ecc22c9ed094dc55383f2a2 (patch)
treeff82540c994310a86e91e17f219a653eb3a23fb7
parent3400bcdaea699db49199d09ef045d75b28fc9cd7 (diff)
downloadchroma-02d1e3a84814da3f3ecc22c9ed094dc55383f2a2.tar.gz
chroma-02d1e3a84814da3f3ecc22c9ed094dc55383f2a2.tar.bz2
chroma-02d1e3a84814da3f3ecc22c9ed094dc55383f2a2.zip
Add a Photons.reduced() method that returns a new Photons object with
a random subset of photons based on the reduction_factor given.
-rw-r--r--chroma/event.py23
1 files 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