Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert counts to integer to avoid floating point weirdness. #119

Merged
merged 1 commit into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions romanisim/l1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand All @@ -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
Expand Down