From 8d64161afa6e4d75868376f321195d2cc71a026a Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Fri, 3 May 2024 05:14:18 -0500 Subject: [PATCH 1/4] BUG degrees mixed with radians in random draws --- healsparse/healSparseRandoms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/healsparse/healSparseRandoms.py b/healsparse/healSparseRandoms.py index 34b3080..4349a1f 100644 --- a/healsparse/healSparseRandoms.py +++ b/healsparse/healSparseRandoms.py @@ -87,7 +87,10 @@ def make_uniform_randoms(sparse_map, n_random, rng=None): # Get range of coverage pixels cov_theta, cov_phi = hpg.pixel_to_angle(sparse_map.nside_coverage, cov_pix, nest=True, lonlat=False) - extra_boundary = 2.0 * hpg.nside_to_resolution(sparse_map.nside_coverage) + extra_boundary = 2.0 * hpg.nside_to_resolution( + sparse_map.nside_coverage, + units="radians", + ) ra_range = np.clip([np.min(cov_phi - extra_boundary), np.max(cov_phi + extra_boundary)], From eaffdcc2f7a30b9af201321f063c159dc74894e0 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Fri, 3 May 2024 05:18:36 -0500 Subject: [PATCH 2/4] BUG need a sintheta factor --- healsparse/healSparseRandoms.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/healsparse/healSparseRandoms.py b/healsparse/healSparseRandoms.py index 4349a1f..d159c21 100644 --- a/healsparse/healSparseRandoms.py +++ b/healsparse/healSparseRandoms.py @@ -91,9 +91,10 @@ def make_uniform_randoms(sparse_map, n_random, rng=None): sparse_map.nside_coverage, units="radians", ) + sintheta = np.sin(cov_theta) - ra_range = np.clip([np.min(cov_phi - extra_boundary), - np.max(cov_phi + extra_boundary)], + 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)], From 14428188d63a08e9893481b198e0781836b049f7 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Fri, 3 May 2024 05:22:07 -0500 Subject: [PATCH 3/4] REF do not need min or max here --- healsparse/healSparseRandoms.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/healsparse/healSparseRandoms.py b/healsparse/healSparseRandoms.py index d159c21..e3d68bd 100644 --- a/healsparse/healSparseRandoms.py +++ b/healsparse/healSparseRandoms.py @@ -93,9 +93,10 @@ def make_uniform_randoms(sparse_map, n_random, rng=None): ) sintheta = np.sin(cov_theta) - ra_range = np.clip([np.min(cov_phi - extra_boundary / sintheta), - np.max(cov_phi + extra_boundary / sintheta)], - 0.0, 2.0 * np.pi) + ra_range = np.array([ + cov_phi - extra_boundary / sintheta, + cov_phi + extra_boundary / sintheta, + ]) 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.) From eac15532869825cfa100fc50a84c952238d58e60 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Fri, 3 May 2024 05:30:02 -0500 Subject: [PATCH 4/4] BUG that was dumb --- healsparse/healSparseRandoms.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/healsparse/healSparseRandoms.py b/healsparse/healSparseRandoms.py index e3d68bd..425e84a 100644 --- a/healsparse/healSparseRandoms.py +++ b/healsparse/healSparseRandoms.py @@ -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 @@ -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.) @@ -107,8 +108,8 @@ 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 @@ -116,7 +117,7 @@ def make_uniform_randoms(sparse_map, n_random, rng=None): 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) @@ -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)