Skip to content

Commit a99acc4

Browse files
committed
healpix workspace renamed
1 parent 08a8c92 commit a99acc4

File tree

10 files changed

+51
-46
lines changed

10 files changed

+51
-46
lines changed

docs/src/ksz.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ To generate Healpix maps, you'll need the [Healpix.jl](https://github.com/ziotom
6969

7070
```@example ksz
7171
using Healpix
72+
using XGPaint
7273
7374
nside = 2048
7475
m_hp = HealpixMap{Float64,RingOrder}(nside)
75-
max_radius = deg2rad(5.0) # maximum radius to consider for the profile
76-
w = HealpixProfileWorkspace(nside, max_radius)
76+
res = Healpix.Resolution(nside)
77+
w = HealpixRingProfileWorkspace{Float64}(res)
7778
7879
@time paint!(m_hp, w, model_interp, halo_mass, redshift, ra, dec, proj_v_over_c)
7980
# Healpix.saveToFITS(m_hp, "!y.fits", typechar="D") # to save, uncomment

docs/src/sz.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ To generate Healpix maps, you'll need the [Healpix.jl](https://github.com/ziotom
7979

8080
```@example tsz
8181
using Healpix
82+
using XGPaint
8283
8384
nside = 4096
8485
m_hp = HealpixMap{Float64,RingOrder}(nside)
85-
max_radius = deg2rad(5.0) # maximum radius to consider for the profile
86-
w = HealpixProfileWorkspace(nside, max_radius)
86+
res = Healpix.Resolution(nside)
87+
w = HealpixRingProfileWorkspace{Float64}(res)
8788
@time paint!(m_hp, w, y_model_interp, halo_mass, redshift, ra, dec)
8889
# Healpix.saveToFITS(m_hp, "!y.fits", typechar="D") # to save, uncomment
8990

src/XGPaint.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ export Radio_Sehgal2009, CIB_Planck2013, CIB_Scarfy, CO_CROWNED, LRG_Yuan23
5151
export paint!, generate_sources, process_sources, profile_grid, profile_paint!
5252
export profileworkspace, paint_szp!, profile_grid_szp, profile_paint_szp!, paint_rsz!, profile_grid_rsz, profile_paint_rsz!
5353
export build_interpolator, Battaglia16ThermalSZProfile, RSZPerturbativeProfile, build_interpolator_szp, build_interpolator_rsz
54-
export SZPackRSZProfile, nu_to_X, X_to_nu, BattagliaTauProfile, HealpixProfileWorkspace
54+
export SZPackRSZProfile, nu_to_X, X_to_nu, BattagliaTauProfile, HealpixRingProfileWorkspace
5555

5656
end # module

src/healpixworkspace.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

2-
# Ring workspace for fast disc queries
3-
struct RingWorkspace{T<:AbstractFloat}
2+
# Ring workspace for fast disc queries; this is designed for CPU for now
3+
struct HealpixRingProfileWorkspace{T<:AbstractFloat}
44
res::Healpix.Resolution
55
ring_thetas::Vector{T} # Colatitude of each ring
66
ring_shifts::Vector{T} # Shift offset for each ring (0.0 or 0.5)
77
ring_num_pixels::Vector{Int} # Number of pixels in each ring
88
ring_first_pixels::Vector{Int} # First pixel index for each ring
99
end
1010

11-
function RingWorkspace{T}(res::Healpix.Resolution) where T<:AbstractFloat
11+
function HealpixRingProfileWorkspace{T}(res::Healpix.Resolution) where T<:AbstractFloat
1212
num_rings = res.nsideTimesFour - 1
1313

1414
ring_thetas = Vector{T}(undef, num_rings)
@@ -24,10 +24,10 @@ function RingWorkspace{T}(res::Healpix.Resolution) where T<:AbstractFloat
2424
ring_first_pixels[ring_idx] = ringinfo.firstPixIdx
2525
end
2626

27-
RingWorkspace{T}(res, ring_thetas, ring_shifts, ring_num_pixels, ring_first_pixels)
27+
HealpixRingProfileWorkspace{T}(res, ring_thetas, ring_shifts, ring_num_pixels, ring_first_pixels)
2828
end
2929

30-
RingWorkspace(res::Healpix.Resolution) = RingWorkspace{Float64}(res)
30+
HealpixRingProfileWorkspace(res::Healpix.Resolution) = HealpixRingProfileWorkspace{Float64}(res)
3131

3232
function get_relevant_rings(res::Healpix.Resolution, θ_center, radius)
3333
z_top = cos(max(0, θ_center - radius))
@@ -53,8 +53,11 @@ Returns two ranges to handle φ wraparound at the 0/2π boundary:
5353
- range1: Main contiguous range of pixels
5454
- range2: Additional range when disc crosses φ=0/2π seam (empty if no crossing)
5555
"""
56-
function get_ring_disc_ranges(workspace::RingWorkspace, ring_idx::Int,
56+
function get_ring_disc_ranges(workspace::HealpixRingProfileWorkspace{T}, ring_idx::Int,
5757
center_theta::T, center_phi::T, radius::T) where T
58+
# Validate that phi is in the valid range [0, 2π)
59+
@assert 0 <= center_phi < T(2π) "center_phi must be in the range [0, 2π), got $(center_phi)"
60+
5861
nr = workspace.ring_num_pixels[ring_idx]
5962
ring_theta = workspace.ring_thetas[ring_idx]
6063
shift = workspace.ring_shifts[ring_idx]

src/profiles.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@ end
350350
# end
351351
# end
352352

353-
function profile_paint_generic!(m::HealpixMap{T, RingOrder}, workspace::RingWorkspace{T},
353+
function profile_paint_generic!(m::HealpixMap{T, RingOrder}, workspace::HealpixRingProfileWorkspace{T},
354354
model, Mh, z, α₀, δ₀, θmax, normalization=1) where T
355-
ϕ₀ = α₀
355+
ϕ₀ = mod(T(α₀), T(2π)) # Normalize RA to [0, 2π)
356356
θ₀ = T(π)/2 - δ₀
357357
x₀, y₀, z₀ = ang2vec(θ₀, ϕ₀)
358358
θmin = compute_θmin(model)
@@ -391,7 +391,7 @@ function profile_paint_generic!(m::HealpixMap{T, RingOrder}, workspace::RingWork
391391
end
392392

393393
# fall back to generic profile painter if no specialized painter is defined for the model
394-
function profile_paint!(m::HealpixMap{T, RingOrder}, w::RingWorkspace{T}, model,
394+
function profile_paint!(m::HealpixMap{T, RingOrder}, w::HealpixRingProfileWorkspace{T}, model,
395395
Mh, z, α₀, δ₀, θmax, normalization=1) where T
396396
profile_paint_generic!(m, w, model, Mh, z, α₀, δ₀, θmax, normalization)
397397
end

src/profiles_rsz.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ end
133133

134134
# like the usual paint, but use the sign of the null as the sign of the perturbation
135135
function profile_paint!(m::HealpixMap{T, RingOrder},
136-
workspace::RingWorkspace{T}, model::RSZPerturbativeProfile,
136+
workspace::HealpixRingProfileWorkspace{T}, model::RSZPerturbativeProfile,
137137
Mh, z, α₀, δ₀, θmax) where T
138138
X_0 = calc_null(model, Mh, z)
139139
profile_paint_generic!(m, workspace, model, Mh, z, α₀, δ₀, θmax, sign(model.X - X_0))

src/profiles_szp.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function profile_paint!(m::Enmap{T, 2, Matrix{T}, CarClenshawCurtis{T}},
9999
end
100100

101101
function profile_paint!(m::HealpixMap{T, RingOrder},
102-
workspace::RingWorkspace{T}, model::SZPackRSZProfile,
102+
workspace::HealpixRingProfileWorkspace{T}, model::SZPackRSZProfile,
103103
Mh, z, α₀, δ₀, θmax) where T
104104
rsz_factor_I_over_y = compute_rsz_factor_I_over_y(model, Mh, z)
105105
profile_paint_generic!(m, workspace, model.y_model_interp, Mh, z, α₀, δ₀, θmax, rsz_factor_I_over_y)

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using PhysicalConstants.CODATA2018
1010

1111
# Include HEALPix ring workspace tests
1212
include("test_healpix_rings.jl")
13-
include("test_ringworkspace.jl")
13+
include("test_HealpixRingProfileWorkspace.jl")
1414

1515
# relative background evolutions differ by 1e-3 between Julia and Python 2
1616
rtol = 1e-3

test/test_healpix_rings.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ using XGPaint
44

55
@testset "Ring-Slice HEALPix Disc Query Tests" begin
66

7-
@testset "RingWorkspace Construction" begin
7+
@testset "HealpixRingProfileWorkspace Construction" begin
88
nside = 32
99
res = Healpix.Resolution(nside)
10-
workspace = XGPaint.RingWorkspace(res)
10+
workspace = XGPaint.HealpixRingProfileWorkspace(res)
1111

1212
@test workspace.res === res
1313
@test length(workspace.ring_thetas) == res.nsideTimesFour - 1
@@ -17,7 +17,7 @@ using XGPaint
1717
@test eltype(workspace.ring_shifts) == Float64
1818

1919
# Test type parameter
20-
workspace_f32 = XGPaint.RingWorkspace{Float32}(res)
20+
workspace_f32 = XGPaint.HealpixRingProfileWorkspace{Float32}(res)
2121
@test eltype(workspace_f32.ring_thetas) == Float32
2222
@test eltype(workspace_f32.ring_shifts) == Float32
2323
end
@@ -44,7 +44,7 @@ using XGPaint
4444
@testset "get_ring_disc_ranges Basic Cases" begin
4545
nside = 32
4646
res = Healpix.Resolution(nside)
47-
workspace = XGPaint.RingWorkspace(res)
47+
workspace = XGPaint.HealpixRingProfileWorkspace(res)
4848

4949
# Test empty disc (radius = 0)
5050
range1, range2 = XGPaint.get_ring_disc_ranges(workspace, 10, π/4, 0.0, 0.0)
@@ -61,9 +61,9 @@ using XGPaint
6161
@testset "Systematic Validation vs HEALPix Reference" begin
6262
nside = 32 # Smaller for faster testing
6363
res = Healpix.Resolution(nside)
64-
workspace = XGPaint.RingWorkspace(res)
64+
workspace = XGPaint.HealpixRingProfileWorkspace(res)
6565

66-
function query_disc_rings!(pixel_list::Vector{Int}, workspace::XGPaint.RingWorkspace,
66+
function query_disc_rings!(pixel_list::Vector{Int}, workspace::XGPaint.HealpixRingProfileWorkspace,
6767
θ_center, ϕ_center, radius)
6868
empty!(pixel_list)
6969
ring_min, ring_max = XGPaint.get_relevant_rings(workspace.res, θ_center, radius)
@@ -105,9 +105,9 @@ using XGPaint
105105
@testset "Random Points Validation" begin
106106
nside = 32
107107
res = Healpix.Resolution(nside)
108-
workspace = XGPaint.RingWorkspace(res)
108+
workspace = XGPaint.HealpixRingProfileWorkspace(res)
109109

110-
function query_disc_rings!(pixel_list::Vector{Int}, workspace::XGPaint.RingWorkspace,
110+
function query_disc_rings!(pixel_list::Vector{Int}, workspace::XGPaint.HealpixRingProfileWorkspace,
111111
θ_center, ϕ_center, radius)
112112
empty!(pixel_list)
113113
ring_min, ring_max = XGPaint.get_relevant_rings(workspace.res, θ_center, radius)
@@ -150,7 +150,7 @@ using XGPaint
150150
@testset "Edge Cases" begin
151151
nside = 32
152152
res = Healpix.Resolution(nside)
153-
workspace = XGPaint.RingWorkspace(res)
153+
workspace = XGPaint.HealpixRingProfileWorkspace(res)
154154

155155
# Test exact north pole
156156
range1, range2 = XGPaint.get_ring_disc_ranges(workspace, 1, 0.0, 0.0, deg2rad(5.0))

test/test_ringworkspace.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using XGPaint
2-
using XGPaint: RingWorkspace
2+
using XGPaint: HealpixRingProfileWorkspace
33
using Healpix
44
using Test
55

@@ -42,16 +42,16 @@ end
4242
(m::TestModel)(θ, Mh, z) = m.value
4343
XGPaint.compute_θmin(::TestModel{T}) where T = eps(T)
4444

45-
@testset "RingWorkspace Profile Painting Tests" begin
45+
@testset "HealpixRingProfileWorkspace Profile Painting Tests" begin
4646

47-
@testset "RingWorkspace vs Brute Force" begin
47+
@testset "HealpixRingProfileWorkspace vs Brute Force" begin
4848
# Setup
4949
nside = 64
5050
res = Healpix.Resolution(nside)
51-
workspace = RingWorkspace(res)
51+
workspace = HealpixRingProfileWorkspace(res)
5252

5353
# Create test maps
54-
map_ringworkspace = HealpixMap{Float64, RingOrder}(zeros(Float64, nside2npix(nside)))
54+
map_HealpixRingProfileWorkspace = HealpixMap{Float64, RingOrder}(zeros(Float64, nside2npix(nside)))
5555
map_bruteforce = HealpixMap{Float64, RingOrder}(zeros(Float64, nside2npix(nside)))
5656

5757
# Test model
@@ -69,26 +69,26 @@ XGPaint.compute_θmin(::TestModel{T}) where T = eps(T)
6969

7070
for (i, test_case) in enumerate(test_cases)
7171
# Reset maps
72-
fill!(map_ringworkspace.pixels, 0.0)
72+
fill!(map_HealpixRingProfileWorkspace.pixels, 0.0)
7373
fill!(map_bruteforce.pixels, 0.0)
7474

7575
# Paint with both methods
76-
XGPaint.profile_paint_generic!(map_ringworkspace, workspace, model,
76+
XGPaint.profile_paint_generic!(map_HealpixRingProfileWorkspace, workspace, model,
7777
test_case.Mh, test_case.z, test_case.α₀, test_case.δ₀, test_case.θmax)
7878

7979
profile_paint_bruteforce!(map_bruteforce, model,
8080
test_case.Mh, test_case.z, test_case.α₀, test_case.δ₀, test_case.θmax)
8181

8282
# Compare results - should be exactly equal for constant model
83-
@test map_ringworkspace.pixels map_bruteforce.pixels
84-
@test count(x -> x != 0, map_ringworkspace.pixels) == count(x -> x != 0, map_bruteforce.pixels)
83+
@test map_HealpixRingProfileWorkspace.pixels map_bruteforce.pixels
84+
@test count(x -> x != 0, map_HealpixRingProfileWorkspace.pixels) == count(x -> x != 0, map_bruteforce.pixels)
8585
end
8686
end
8787

88-
@testset "RingWorkspace Edge Cases" begin
88+
@testset "HealpixRingProfileWorkspace Edge Cases" begin
8989
nside = 64
9090
res = Healpix.Resolution(nside)
91-
workspace = RingWorkspace(res)
91+
workspace = HealpixRingProfileWorkspace(res)
9292

9393
map_test = HealpixMap{Float64, RingOrder}(zeros(Float64, nside2npix(nside)))
9494
model = TestModel(1.0)
@@ -110,14 +110,14 @@ XGPaint.compute_θmin(::TestModel{T}) where T = eps(T)
110110
end
111111
end
112112

113-
@testset "RingWorkspace vs Brute Force with Real Y Profile" begin
113+
@testset "HealpixRingProfileWorkspace vs Brute Force with Real Y Profile" begin
114114
# Setup with real y profile model
115115
nside = 32 # Smaller for faster testing with real profile
116116
res = Healpix.Resolution(nside)
117-
workspace = RingWorkspace(res)
117+
workspace = HealpixRingProfileWorkspace(res)
118118

119119
# Create test maps
120-
map_ringworkspace = HealpixMap{Float64, RingOrder}(zeros(Float64, nside2npix(nside)))
120+
map_HealpixRingProfileWorkspace = HealpixMap{Float64, RingOrder}(zeros(Float64, nside2npix(nside)))
121121
map_bruteforce = HealpixMap{Float64, RingOrder}(zeros(Float64, nside2npix(nside)))
122122

123123
# Real y profile model
@@ -132,26 +132,26 @@ XGPaint.compute_θmin(::TestModel{T}) where T = eps(T)
132132

133133
for (i, test_case) in enumerate(test_cases)
134134
# Reset maps
135-
fill!(map_ringworkspace.pixels, 0.0)
135+
fill!(map_HealpixRingProfileWorkspace.pixels, 0.0)
136136
fill!(map_bruteforce.pixels, 0.0)
137137

138138
# Paint with both methods
139-
XGPaint.profile_paint_generic!(map_ringworkspace, workspace, y_model,
139+
XGPaint.profile_paint_generic!(map_HealpixRingProfileWorkspace, workspace, y_model,
140140
test_case.Mh, test_case.z, test_case.α₀, test_case.δ₀, test_case.θmax)
141141

142142
profile_paint_bruteforce!(map_bruteforce, y_model,
143143
test_case.Mh, test_case.z, test_case.α₀, test_case.δ₀, test_case.θmax)
144144

145145
# Compare results - should be very close (allowing for floating point differences)
146-
@test map_ringworkspace.pixels map_bruteforce.pixels rtol=1e-12
146+
@test map_HealpixRingProfileWorkspace.pixels map_bruteforce.pixels rtol=1e-12
147147

148148
# Check that we actually painted something non-zero
149-
@test count(x -> x != 0, map_ringworkspace.pixels) > 0
149+
@test count(x -> x != 0, map_HealpixRingProfileWorkspace.pixels) > 0
150150
@test count(x -> x != 0, map_bruteforce.pixels) > 0
151151

152152
# Check same number of non-zero pixels
153-
@test count(x -> x != 0, map_ringworkspace.pixels) == count(x -> x != 0, map_bruteforce.pixels)
153+
@test count(x -> x != 0, map_HealpixRingProfileWorkspace.pixels) == count(x -> x != 0, map_bruteforce.pixels)
154154
end
155155
end
156156

157-
end # RingWorkspace Profile Painting Tests
157+
end # HealpixRingProfileWorkspace Profile Painting Tests

0 commit comments

Comments
 (0)