Skip to content

Commit

Permalink
add Makie plotting (#56)
Browse files Browse the repository at this point in the history
* add lonlat() function

* add Makie plotting

* Update runtests.jl

* Update test/runtests.jl

---------

Co-authored-by: Mosè Giordano <[email protected]>
  • Loading branch information
aplavin and giordano authored Jan 12, 2025
1 parent cde2093 commit 87db735
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[weakdeps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[extensions]
AccessorsExt = "Accessors"
MakieExt = "Makie"
UnitfulExt = "Unitful"

[compat]
Accessors = "0.1"
AstroAngles = "0.2"
ConstructionBase = "1"
Makie = "0.21.18"
Rotations = "1"
StaticArrays = "0.8, 0.9, 1"
Unitful = "1.15"
julia = "1.6"

[extras]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
11 changes: 11 additions & 0 deletions ext/MakieExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module MakieExt

using Makie
using SkyCoords: AbstractSkyCoords, lonlat

Makie.convert_arguments(ct::PointBased, c::AbstractSkyCoords) = convert_arguments(ct, [c])

Makie.convert_arguments(ct::PointBased, cs::AbstractVector{<:AbstractSkyCoords}) =
convert_arguments(ct, map(c -> Point(lonlat(c)...), cs))

end
1 change: 1 addition & 0 deletions ext/UnitfulExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _COORDTYPES_LATLON = Union{ICRSCoords, GalCoords, FK5Coords, EclipticCoords}

SkyCoords.lon(u::Unitful.Units, c) = SkyCoords.lon(c) * u"rad" |> u
SkyCoords.lat(u::Unitful.Units, c) = SkyCoords.lat(c) * u"rad" |> u
SkyCoords.lonlat(u::Unitful.Units, c) = SkyCoords.lonlat(c) .* u"rad" .|> u

SkyCoords.separation(u::Unitful.Units, c1, c2) = SkyCoords.separation(c1, c2) * u"rad" |> u
SkyCoords.position_angle(u::Unitful.Units, c1, c2) = SkyCoords.position_angle(c1, c2) * u"rad" |> u
Expand Down
2 changes: 2 additions & 0 deletions src/SkyCoords.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ lon(c::EclipticCoords) = c.lon
lon(c::AbstractSkyCoords) = c.ra
lat(c::AbstractSkyCoords) = c.dec

lonlat(c::AbstractSkyCoords) = (lon(c), lat(c))

# Abstract away specific field names (ra, dec vs l, b)
coords2cart(c::AbstractSkyCoords) = coords2cart(lon(c), lat(c))

Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using SkyCoords
using StableRNGs
using Statistics
using Test
import Makie

import SkyCoords: lat, lon

Expand Down Expand Up @@ -242,3 +243,12 @@ end
@test coord_out == coord_in |> OUT_SYS
end
end

VERSION >= v"1.9" && @testset "plotting with Makie" begin
coo = ICRSCoords(1, 2)

@test Makie.convert_arguments(Makie.Scatter, coo) == ([Makie.Point(1, 2)],)
@test Makie.convert_arguments(Makie.Scatter, [coo]) == ([Makie.Point(1, 2)],)
@test Makie.convert_arguments(Makie.Lines, [coo, coo]) == ([Makie.Point(1, 2), Makie.Point(1, 2)],)
@test Makie.convert_arguments(Makie.Lines, [coo][1:0]) == ([],)
end

0 comments on commit 87db735

Please sign in to comment.