From 6a98ffb8705e36bebd149846fa4bca9433667709 Mon Sep 17 00:00:00 2001 From: Eddie Schlafly Date: Fri, 3 May 2024 10:19:57 -0400 Subject: [PATCH] Convert counts to integer to avoid floating point weirdness. (#119) --- romanisim/l1.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/romanisim/l1.py b/romanisim/l1.py index 70090fd9..cbdd660c 100644 --- a/romanisim/l1.py +++ b/romanisim/l1.py @@ -241,6 +241,7 @@ def apportion_counts_to_resultants( if not np.all(counts == np.round(counts)): raise ValueError('apportion_counts_to_resultants expects the counts ' 'to be integers!') + counts = np.clip(counts, 0, 2 * 10**9).astype('i4') # Set rng for creating cosmic rays, persistence, and readnoise if rng is None and seed is None: @@ -264,7 +265,7 @@ def apportion_counts_to_resultants( # Create arrays to store various photon or electron counts and dq resultants = np.zeros((len(tij),) + counts.shape, dtype='f4') - counts_so_far = np.zeros(counts.shape, dtype='f4') + counts_so_far = np.zeros(counts.shape, dtype='i4') resultant_counts = np.zeros(counts.shape, dtype='f4') dq = np.zeros(resultants.shape, dtype=np.uint32) @@ -288,7 +289,7 @@ def apportion_counts_to_resultants( # Loop over resultant probabilities for j, p in enumerate(pi): # Set read counts - read = rng_numpy.binomial((counts - counts_so_far).astype('i4'), p) + read = rng_numpy.binomial(counts - counts_so_far, p) counts_so_far += read # Apply cosmic rays