Skip to content

Commit

Permalink
Format this PR
Browse files Browse the repository at this point in the history
  • Loading branch information
ptiede committed Feb 24, 2025
1 parent 06f7e4b commit 681fc82
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 46 deletions.
49 changes: 22 additions & 27 deletions ext/VLBISkyModelsMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ Makie.@recipe(PolImage, img) do scene
end

# # We need this because DimensionalData tries to be too dang smart
function Makie.convert_arguments(::Type{<:PolImage}, img::IntensityMap{<:StokesParams,2}, args...)
function Makie.convert_arguments(::Type{<:PolImage}, img::IntensityMap{<:StokesParams,2},
args...)
return (img,)
end


# function Makie.MakieCore.conversion_trait(P::Type{<:PolImage})
# # @info "HERE"
# return P
Expand Down Expand Up @@ -252,13 +252,12 @@ function Makie.plot!(plot::PolImage{<:Tuple{<:IntensityMap{<:StokesParams}}})
# return crange
# end
hm = heatmap!(plot, Xo, Yo, imgI;
colormap=plot.colormap,
colorscale=plot.colorscale,
colorrange=plot.colorrange,
alpha=plot.alpha,
nan_color=plot.nan_color,
lowclip=plot.lowclip,
)
colormap=plot.colormap,
colorscale=plot.colorscale,
colorrange=plot.colorrange,
alpha=plot.alpha,
nan_color=plot.nan_color,
lowclip=plot.lowclip,)

rotate!(hm, pa[])

Expand Down Expand Up @@ -389,10 +388,10 @@ function imageviz(img::IntensityMap;
dkwargs = Dict(kwargs)
if eltype(img) <: Real
res = get(dkwargs, :size, (625, 500))
cmap= get(dkwargs, :colormap, :inferno)
cmap = get(dkwargs, :colormap, :inferno)
else
res = get(dkwargs, :size, (640, 600))
cmap= get(dkwargs, :colormap, :grayC)
cmap = get(dkwargs, :colormap, :grayC)
end

bkgcolor = isnothing(backgroundcolor) ? Makie.to_colormap(cmap)[begin] : backgroundcolor
Expand All @@ -406,9 +405,8 @@ function imageviz(img::IntensityMap;
dxdy = prod(rad2μas.(values(pixelsizes(img))))

imguas = IntensityMap(parent(img) ./ dxdy,
RectiGrid((X(rad2μas(img.X)), Y(rad2μas(img.Y)));
posang=ComradeBase.posang(axisdims(img)))
)
RectiGrid((X(rad2μas(img.X)), Y(rad2μas(img.Y)));
posang=ComradeBase.posang(axisdims(img))))
pl = _imgviz!(fig, ax, imguas; scale_length, dkwargs...)
resize_to_layout!(fig)
return pl
Expand Down Expand Up @@ -510,22 +508,19 @@ function DDM._surface2(A::IntensityMap, plotfunc, attributes, replacements)

# Plot attribute generation
dx, dy = DD.dims(A2)
user_attributes = Makie.Attributes(;
transformation=(;rotation=-ComradeBase.posang(axisdims(A))),
interpolate=false,
attributes...)
plot_attributes = Makie.Attributes(;
axis=(;
xlabel=DD.label(dx),
ylabel=DD.label(dy),
title=DD.refdims_title(A),
),
)
user_attributes = Makie.Attributes(;
transformation=(;
rotation=-ComradeBase.posang(axisdims(A))),
interpolate=false,
attributes...)
plot_attributes = Makie.Attributes(;
axis=(;
xlabel=DD.label(dx),
ylabel=DD.label(dy),
title=DD.refdims_title(A),),)
merged_attributes = merge(user_attributes, plot_attributes, lookup_attributes)

return A1, A2, args, merged_attributes
end



end
2 changes: 1 addition & 1 deletion src/fourierdomain/nuft/dft_alg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function plan_nuft_spatial(::DFTAlg, imagegrid::AbstractRectiGrid,
dft = similar(Array{Complex{eltype(imagegrid)}}, length(visdomain),
size(imagegrid)[1:2]...)
@fastmath for i in eachindex(Y), j in eachindex(X), k in eachindex(visp)
uvr = rmat*SVector(uv.U[k], uv.V[k])
uvr = rmat * SVector(uv.U[k], uv.V[k])
u = uvr[1]
v = uvr[2]
# - sign is taken care of in _visibilitymap
Expand Down
3 changes: 2 additions & 1 deletion src/fourierdomain/nuft/nfft_alg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ function make_phases(::NFFTAlg, imgdomain::AbstractRectiGrid, visdomain::Unstruc
v = visp.V
rm = ComradeBase.rotmat(imgdomain)'
# Correct for the nFFT phase center and the img phase center
return cispi.((_rotatex.(u, v, Ref(rm)) .* (dx - 2 * x0) .+ _rotatey.(u, v, Ref(rm)) .* (dy - 2 * y0)))
return cispi.((_rotatex.(u, v, Ref(rm)) .* (dx - 2 * x0) .+
_rotatey.(u, v, Ref(rm)) .* (dy - 2 * y0)))
end

# Allow NFFT to work with ForwardDiff.
Expand Down
1 change: 0 additions & 1 deletion src/models/modifiers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ function modify(m::AbstractModel, transforms...)
return ModifiedModel(m, transforms)
end


@inline function visibility_point(m::M, p) where {M<:ModifiedModel}
mbase = m.model
transform = m.transform
Expand Down
3 changes: 1 addition & 2 deletions src/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ function convolve!(img::IntensityMap{<:Real}, m::AbstractModel)
ds = (u, v, dims(img)[3:end]...)
griduv = RectiGrid(ds;
executor=executor(img), header=header(img),
posang=ComradeBase.posang(axisdims(img))
)
posang=ComradeBase.posang(axisdims(img)))
puv = domainpoints(griduv)

# TODO maybe ask a user to pass a vis buffer as well?
Expand Down
26 changes: 12 additions & 14 deletions test/rotgrid.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
function testrot(m, g, gr, uv; alg=NFFTAlg(), atoli=5e-4, atolu=1e-6)
Ut = uv.*ones(length(uv))'
Ut = uv .* ones(length(uv))'
Vt = ones(length(uv)) .* uv'

guv = UnstructuredDomain((U=vec(Ut), V=vec(Vt)))
gfour = FourierDualDomain(g, guv, NFFTAlg())
grfour = FourierDualDomain(gr, guv, NFFTAlg())

mn= VLBISkyModels.NonAnalyticTest(m)
mn = VLBISkyModels.NonAnalyticTest(m)
img = intensitymap(m, g)
imgr= intensitymap(m, gr)
imgr = intensitymap(m, gr)

@test isapprox(img, regrid(imgr, g), atol=atoli)

Expand All @@ -24,7 +24,7 @@ end

@testset "Rotated Grid" begin
g = imagepixels(6.0, 6.0, 256, 256)
gr= imagepixels(6.0, 6.0, 256, 256; posang=π/4)
gr = imagepixels(6.0, 6.0, 256, 256; posang=π / 4)

uv = range(-2.0, 2.0)

Expand All @@ -36,7 +36,7 @@ end

@testset "Rotated Grid and shifted" begin
g = imagepixels(6.0, 6.0, 256, 256, 0.25, 0.25)
gr= imagepixels(6.0, 6.0, 256, 256, 0.25, 0.25; posang=π/4)
gr = imagepixels(6.0, 6.0, 256, 256, 0.25, 0.25; posang=π / 4)

uv = range(-2.0, 2.0)

Expand All @@ -48,7 +48,7 @@ end

@testset "Rotated Grid and shifted model" begin
g = imagepixels(6.0, 6.0, 256, 256)
gr= imagepixels(6.0, 6.0, 256, 256; posang=π/4)
gr = imagepixels(6.0, 6.0, 256, 256; posang=π / 4)

uv = range(-2.0, 2.0)

Expand All @@ -60,41 +60,39 @@ end

@testset "Polarized Rotated Grid" begin
g = imagepixels(6.0, 6.0, 256, 256)
gr= imagepixels(6.0, 6.0, 256, 256; posang=π/4)
gr = imagepixels(6.0, 6.0, 256, 256; posang=π / 4)

uv = range(-2.0, 2.0)

m = modify(Gaussian(), Stretch(0.25, 0.5))
pm = PolarizedModel(m, 0.1 * m, -0.2*m, 0.01*m)
pm = PolarizedModel(m, 0.1 * m, -0.2 * m, 0.01 * m)
testrot(pm, g, gr, uv)
testrot(pm, g, gr, uv; alg=FFTAlg())
testrot(pm, g, gr, uv; alg=DFTAlg())
end

@testset "Rotated Grid and shifted" begin
g = imagepixels(6.0, 6.0, 256, 256, 0.25, 0.25)
gr= imagepixels(6.0, 6.0, 256, 256, 0.25, 0.25; posang=π/4)
gr = imagepixels(6.0, 6.0, 256, 256, 0.25, 0.25; posang=π / 4)

uv = range(-2.0, 2.0)

m = modify(Gaussian(), Stretch(0.25, 0.5))
pm = PolarizedModel(m, 0.1 * m, -0.2*m, 0.01*m)
pm = PolarizedModel(m, 0.1 * m, -0.2 * m, 0.01 * m)
testrot(pm, g, gr, uv)
testrot(pm, g, gr, uv; alg=FFTAlg())
testrot(pm, g, gr, uv; alg=DFTAlg())
end

@testset "Rotated Grid and shifted model" begin
g = imagepixels(6.0, 6.0, 256, 256)
gr= imagepixels(6.0, 6.0, 256, 256; posang=π/4)
gr = imagepixels(6.0, 6.0, 256, 256; posang=π / 4)

uv = range(-2.0, 2.0)

m = modify(Gaussian(), Stretch(0.25, 0.5), Shift(0.1, 0.1))
pm = PolarizedModel(m, 0.1 * m, -0.2*m, 0.01*m)
pm = PolarizedModel(m, 0.1 * m, -0.2 * m, 0.01 * m)
testrot(pm, g, gr, uv)
testrot(pm, g, gr, uv; alg=FFTAlg())
testrot(pm, g, gr, uv; alg=DFTAlg())
end


0 comments on commit 681fc82

Please sign in to comment.