Skip to content

Commit

Permalink
BUG that was dumb
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr authored May 3, 2024
1 parent 1442818 commit eac1553
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions healsparse/healSparseRandoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def make_uniform_randoms(sparse_map, n_random, rng=None):
rng = np.random.RandomState()

# Generate uniform points on a unit sphere
r = 1.0
min_gen = 10000
max_gen = 1000000

Expand All @@ -93,10 +92,12 @@ def make_uniform_randoms(sparse_map, n_random, rng=None):
)
sintheta = np.sin(cov_theta)

ra_range = np.array([
cov_phi - extra_boundary / sintheta,
cov_phi + extra_boundary / sintheta,
])
ra_range = np.clip(
[np.min(cov_phi - extra_boundary / sintheta),
np.max(cov_phi + extra_boundary / sintheta)],
0.0,
2.0 * np.pi,
)
dec_range = np.clip([np.min((np.pi/2. - cov_theta) - extra_boundary),
np.max((np.pi/2. - cov_theta) + extra_boundary)],
-np.pi/2., np.pi/2.)
Expand All @@ -107,16 +108,16 @@ def make_uniform_randoms(sparse_map, n_random, rng=None):
cov_phi_rot = cov_phi + np.pi
test, = np.where(cov_phi_rot > 2.0 * np.pi)
cov_phi_rot[test] -= 2.0 * np.pi
ra_range_rot = np.clip([np.min(cov_phi_rot - extra_boundary),
np.max(cov_phi_rot + extra_boundary)],
ra_range_rot = np.clip([np.min(cov_phi_rot - extra_boundary / sintheta),
np.max(cov_phi_rot + extra_boundary / sintheta)],
0.0, 2.0 * np.pi)
if ((ra_range_rot[1] - ra_range_rot[0]) < ((ra_range[1] - ra_range[0]) - 0.1)):
# This is a more efficient range in rotated space
ra_range = ra_range_rot
rotated = True

# And the spherical coverage
z_range = r * np.sin(dec_range)
z_range = np.sin(dec_range)
phi_range = ra_range

ra_rand = np.zeros(n_random)
Expand All @@ -133,7 +134,7 @@ def make_uniform_randoms(sparse_map, n_random, rng=None):

z = rng.uniform(low=z_range[0], high=z_range[1], size=n_gen)
phi = rng.uniform(low=phi_range[0], high=phi_range[1], size=n_gen)
theta = np.arcsin(z / r)
theta = np.arcsin(z)

ra_rand_temp = np.degrees(phi)
dec_rand_temp = np.degrees(theta)
Expand Down

0 comments on commit eac1553

Please sign in to comment.