Skip to content

Commit 0f3da24

Browse files
committed
Interpolator tweak as tweaked map_coordinates
1 parent a807b2f commit 0f3da24

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

src/core.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function reproject(input_data, output_projection; shape_out = nothing, order::In
3737
end
3838

3939
img_out = fill(NaN, shape_out)
40-
40+
array_in = pad_edges(array_in)
4141
itp = interpolator(array_in, order)
4242
shape_in = size(array_in)
4343

@@ -68,8 +68,8 @@ function reproject(input_data, output_projection; shape_out = nothing, order::In
6868

6969
pix_coord_out = world_to_pix(wcs_out, [rad2deg(lon(coord_out)), rad2deg(lat(coord_out))])
7070

71-
if 1 <= pix_coord_out[1] <= shape_in[1] && 1 <= pix_coord_out[2] <= shape_in[2]
72-
img_out[i,j] = itp(pix_coord_out[1], pix_coord_out[2])
71+
if 0.5 <= pix_coord_out[1] <= shape_in[1] - 1 && 0.5 <= pix_coord_out[2] <= shape_in[2] - 1
72+
img_out[i,j] = itp(pix_coord_out[1] + 1, pix_coord_out[2] + 1)
7373
end
7474
end
7575
end

src/utils.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,18 @@ function wcs_to_celestial_frame(wcs::WCSTransform)
2020

2121
return radesys
2222
end
23+
24+
"""
25+
pad_edges(array_in::Matrix{T}) where {T}
26+
27+
Pads a given array and creates a border with edge elements.
28+
"""
29+
function pad_edges(array_in::Matrix{T}) where {T}
30+
image = zeros(size(array_in)[1] + 2, size(array_in)[2] + 2)
31+
image[2:end-1,2:end-1] = array_in
32+
image[2:end-1,1] = array_in[:,1]
33+
image[2:end-1,end] = array_in[:,end]
34+
image[1,:] = image[2,:]
35+
image[end,:] = image[end-1,:]
36+
return image
37+
end

test/core.jl

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,12 @@ end
2525
hdu1 = astropy.io.fits.open(joinpath("data", "gc_2mass_k.fits"))[1]
2626
hdu2 = astropy.io.fits.open(joinpath("data", "gc_msx_e.fits"))[1]
2727

28-
function check_diff(arr1, arr2)
29-
diff = 1e-3
30-
count = 0
31-
for i in 1 : size(arr1)[1] - 1
32-
for j in 1 : size(arr2)[2] - 1
33-
if abs(arr1[i,j] - arr2[j,i]) > diff
34-
count+=1
35-
end
36-
end
37-
end
38-
return iszero(count)
39-
end
40-
41-
@test check_diff(reproject(imgin, imgout, order = 0)[1], rp.reproject_interp(hdu2, hdu1.header, order = 0)[1]) == true
42-
@test check_diff(reproject(imgout, imgin, order = 0)[1], rp.reproject_interp(hdu1, hdu2.header, order = 0)[1]) == true
43-
@test check_diff(reproject(imgin, imgout, order = 1)[1], rp.reproject_interp(hdu2, hdu1.header, order = 1)[1]) == true
44-
@test check_diff(reproject(imgin, imgout, order = 2)[1], rp.reproject_interp(hdu2, hdu1.header, order = 2)[1]) == true
45-
@test check_diff(reproject(imgin[1], imgout[1], shape_out = (1000,1000))[1],
46-
rp.reproject_interp(hdu2, astropy.wcs.WCS(hdu1.header), shape_out = (1000,1000))[1]) == true
28+
@test isapprox(reproject(imgin, imgout, order = 0)[1]', rp.reproject_interp(hdu2, hdu1.header, order = 0)[1], nans = true, atol = 1e-4)
29+
@test isapprox(reproject(imgout, imgin, order = 0)[1]', rp.reproject_interp(hdu1, hdu2.header, order = 0)[1], nans = true, atol = 1e-3)
30+
@test isapprox(reproject(imgin, imgout, order = 1)[1]', rp.reproject_interp(hdu2, hdu1.header, order = 1)[1], nans = true, atol = 1e-4)
31+
@test isapprox(reproject(imgin, imgout, order = 2)[1]', rp.reproject_interp(hdu2, hdu1.header, order = 2)[1], nans = true, atol = 1e-4)
32+
@test isapprox(reproject(imgin[1], imgout[1], shape_out = (1000,1000))[1]',
33+
rp.reproject_interp(hdu2, astropy.wcs.WCS(hdu1.header), shape_out = (1000,1000))[1], nans = true, atol = 1e-4)
4734

4835
wcs = WCSTransform(2; ctype = ["RA---AIR", "DEC--AIR"], radesys = "UNK")
4936
@test_throws ArgumentError reproject(imgin, wcs, shape_out = (100,100))

0 commit comments

Comments
 (0)