Skip to content

Commit

Permalink
adaptive markersize [doc]
Browse files Browse the repository at this point in the history
  • Loading branch information
islent committed Dec 7, 2021
1 parent fce7ed9 commit e4c1f21
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 22 deletions.
1 change: 0 additions & 1 deletion docs/src/manual/mosaic.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plot_positionslice("mosaic/", "snapshot_", collect(1:9:100), ".gadget2", gadget2
dpi = 300, resolution = (800,800),
xlims = (-0.06, +0.06), ylims = (-0.06, +0.06),
times = collect(0.0:0.00005:0.005) * u"Gyr",
markersize = 5.0,
);
mosaicview("mosaic", "pos_", collect(1:9:100), ".png"; fillvalue = 0.5, npad = 3, ncol = 4, rowmajor = true)
```
1 change: 0 additions & 1 deletion docs/src/manual/snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plot_positionslice("mosaic/", "snapshot_", collect(0:100), ".gadget2", gadget2()
dpi = 300, resolution = (800,800),
xlims = (-0.06, +0.06), ylims = (-0.06, +0.06),
times = collect(0.0:0.00005:0.005) * u"Gyr",
markersize = 5.0,
)
```

Expand Down
49 changes: 41 additions & 8 deletions src/PhysicalParticles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ function point3(p::PVector)
return Makie.Point3(p.x, p.y, p.z)
end

function estimate_markersize(S::Real)
return 0.0001 / sqrt(S)
end

function estimate_markersize(data, u; xaxis = :x, yaxis = :y)
e = extent(data)
xMax = getfield(e, Symbol(string(xaxis) * "Max"))
xMin = getfield(e, Symbol(string(xaxis) * "Min"))
yMax = getfield(e, Symbol(string(yaxis) * "Max"))
yMin = getfield(e, Symbol(string(yaxis) * "Min"))
return estimate_markersize(ustrip(u*u, (xMax - xMin) * (yMax - yMin)))
end

"""
plot_makie(data::Array{T,1}, u::Union{Nothing, Unitful.FreeUnits} = u"kpc"; kw...) where T<:PVector
plot_makie(data::Array{T,1}, u::Union{Nothing, Unitful.FreeUnits} = u"kpc"; kw...) where T<:AbstractParticle3D
Expand All @@ -22,14 +35,24 @@ d = randn_pvector(50, u"km")
plot_makie(d, u"m")
```
"""
function plot_makie(data::Array{T,1}, u::Union{Nothing, Unitful.FreeUnits} = u"kpc"; kw...) where T<:PVector
function plot_makie(data::Array{T,1}, u::Union{Nothing, Unitful.FreeUnits} = u"kpc";
markersize = estimate_markersize(data, u),
markerspace=SceneSpace,
resolution = (1000, 1000),
kw...
) where T<:PVector
d = [point3(ustrip(u, p)) for p in data]
return Makie.scatter(d; kw...)
return Makie.scatter(d; markersize, markerspace, figure = (resolution = resolution,), kw...)
end

function plot_makie(data::Array{T,1}, u::Union{Nothing, Unitful.FreeUnits} = u"kpc"; kw...) where T<:AbstractParticle3D
function plot_makie(data::Array{T,1}, u::Union{Nothing, Unitful.FreeUnits} = u"kpc";
markersize = estimate_markersize(data, u),
markerspace=SceneSpace,
resolution = (1000, 1000),
kw...
) where T<:AbstractParticle3D
d = [point3(ustrip(u, p.Pos)) for p in data]
return Makie.scatter(d; kw...)
return Makie.scatter(d; markersize, markerspace, figure = (resolution = resolution,), kw...)
end

function plot_makie(data::StructArray, u::Union{Nothing, Unitful.FreeUnits} = u"kpc"; kw...)
Expand Down Expand Up @@ -66,14 +89,24 @@ d = randn_pvector(50, u"km")
plot_makie!(scene, d, u"m")
```
"""
function plot_makie!(scene, data::Array{T,1}, u::Union{Nothing, Unitful.FreeUnits} = u"kpc"; kw...) where T<:PVector
function plot_makie!(scene, data::Array{T,1}, u::Union{Nothing, Unitful.FreeUnits} = u"kpc";
markersize = estimate_markersize(data, u),
markerspace=SceneSpace,
resolution = (1000, 1000),
kw...
) where T<:PVector
d = [point3(ustrip(u, p)) for p in data]
Makie.scatter!(scene, d; kw...)
Makie.scatter!(scene, d; markersize, markerspace, figure = (resolution = resolution,), kw...)
end

function plot_makie!(scene, data::Array{T,1}, u::Union{Nothing, Unitful.FreeUnits} = u"kpc"; kw...) where T<:AbstractParticle3D
function plot_makie!(scene, data::Array{T,1}, u::Union{Nothing, Unitful.FreeUnits} = u"kpc";
markersize = estimate_markersize(data, u),
markerspace=SceneSpace,
resolution = (1000, 1000),
kw...
) where T<:AbstractParticle3D
d = [point3(ustrip(u, p.Pos)) for p in data]
Makie.scatter!(scene, d; kw...)
Makie.scatter!(scene, d; markersize, markerspace, figure = (resolution = resolution,), kw...)
end

function plot_makie!(scene, data::StructArray{T,N,NT,Tu}, u::Union{Nothing, Unitful.FreeUnits} = u"kpc"; kw...) where T<:AbstractParticle3D where N where NT where Tu
Expand Down
6 changes: 3 additions & 3 deletions src/mesh/projection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ function projection_density(mesh::MeshCartesianStatic;
rho = reshape(sum(mesh.rho, dims = d), s...)
pos = slice3d(mesh.pos, d, 1)

x, y = pack_xy(pos; xaxis, yaxis)
xy = pack_xy(pos; xaxis, yaxis)

f = Figure(; resolution)
ax = CairoMakie.Axis(f[1,1]; xlabel, ylabel, title, aspect = AxisAspect(aspect_ratio))

if xid > yid
CairoMakie.heatmap!(ax, x, y, transpose(rho); kw...)
CairoMakie.heatmap!(ax, xy[:,1], xy[:,2], transpose(rho); kw...)
else
CairoMakie.heatmap!(ax, x, y, rho; kw...)
CairoMakie.heatmap!(ax, xy[:,1], xy[:,2], rho; kw...)
end
return f
end
22 changes: 14 additions & 8 deletions src/snapshots/positions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ $_common_keyword_axis
function plot_positionslice!(scene, data, u::Union{Nothing, Unitful.FreeUnits} = nothing;
xaxis = :x,
yaxis = :y,
markersize = estimate_markersize(data, u; xaxis, yaxis),
markerspace=SceneSpace,
kw...)
x, y = pack_xy(data, u; xaxis, yaxis)
Makie.scatter!(scene, x, y; kw...)
xy = pack_xy(data; xaxis, yaxis)
Makie.scatter!(scene, ustrip.(u, xy); markersize, markerspace, kw...)
end

function plot_positionslice!(scene, data, collection::Collection, u::Union{Nothing, Unitful.FreeUnits} = nothing; kw...)
Expand Down Expand Up @@ -55,9 +57,11 @@ function plot_positionslice(data, u::Union{Nothing, Unitful.FreeUnits} = nothing
ylims = nothing,
aspect_ratio = 1.0,
title = "Positions",
resolution = (1600, 900),
markersize = (isnothing(xlims) && isnothing(ylims)) ? estimate_markersize(data, u; xaxis, yaxis) : estimate_markersize((xlims[2] - xlims[1]) * (ylims[2] - ylims[1])),
markerspace=SceneSpace,
resolution = (1000, 1000),
kw...)
x, y = pack_xy(data, u; xaxis, yaxis)
xy = pack_xy(data; xaxis, yaxis)

scene, layout = layoutscene(; resolution)

Expand All @@ -66,7 +70,7 @@ function plot_positionslice(data, u::Union{Nothing, Unitful.FreeUnits} = nothing
aspect = AxisAspect(aspect_ratio),
)

Makie.scatter!(ax, x, y; kw...)
Makie.scatter!(ax, ustrip.(u, xy); markersize, markerspace, kw...)

if !isnothing(xlims)
Makie.xlims!(ax, xlims)
Expand Down Expand Up @@ -177,9 +181,11 @@ function plot_positionslice_adapt(data, u::Union{Nothing, Unitful.FreeUnits} = n
ylen::Float64 = 1.0,
aspect_ratio = 1.0,
title = "Positions",
resolution = (1600, 900),
markersize = estimate_markersize(xlen * ylen),
markerspace=SceneSpace,
resolution = (1000, 1000),
kw...)
x, y = pack_xy(data, u; xaxis, yaxis)
xy = pack_xy(data; xaxis, yaxis)

xcenter = middle(x)
ycenter = middle(y)
Expand All @@ -191,7 +197,7 @@ function plot_positionslice_adapt(data, u::Union{Nothing, Unitful.FreeUnits} = n
aspect = AxisAspect(aspect_ratio),
)

Makie.scatter!(ax, x, y; kw...)
Makie.scatter!(ax, ustrip.(u, xy); markersize, markerspace, kw...)

xlims!(ax, xcenter - 0.5 * xlen, xcenter + 0.5 * xlen)
ylims!(ax, ycenter - 0.5 * ylen, ycenter + 0.5 * ylen)
Expand Down
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ end
dpi = 300, resolution = (800,800),
xlims = (-0.06, +0.06), ylims = (-0.06, +0.06),
times = collect(0.0:0.00005:0.005) * u"Gyr",
markersize = 5.0,
)
plt = mosaicview("mosaic/", "pos_", collect(1:9:100), ".png"; fillvalue = 0.5, npad = 3, ncol = 4, rowmajor = true)
save("mosaic-TDE-pseudo.png", plt)
Expand Down

0 comments on commit e4c1f21

Please sign in to comment.