Skip to content

Commit

Permalink
implemented SuperGalCoords
Browse files Browse the repository at this point in the history
  • Loading branch information
LudwigBoess committed Feb 24, 2023
1 parent f69923e commit 917a43b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/SkyCoords.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using StaticArrays
export AbstractSkyCoords,
ICRSCoords,
GalCoords,
SuperGalCoords,
FK5Coords,
EclipticCoords,
CartesianCoords,
Expand Down Expand Up @@ -66,6 +67,22 @@ const GAL_TO_FK5J2000 = FK5J2000_TO_GAL'
const GAL_TO_ICRS = FK5J2000_TO_ICRS * GAL_TO_FK5J2000
const ICRS_TO_GAL = GAL_TO_ICRS'


# Gal --> SuperGal
# we use the same parameters as in astropy
sgp_l = deg2rad(47.37)
sgp_b = deg2rad(6.32)
# rotation matrix compared to astropy
const GAL_TO_SUPERGAL = RotZYZ(-π / 2, sgp_b - π / 2, -sgp_l)'
const SUPERGAL_TO_GAL = GAL_TO_SUPERGAL'
# SuperGal --> ICRS: chain through GAL
const SuperGal_TO_ICRS = GAL_TO_ICRS * SUPERGAL_TO_GAL
const ICRS_TO_SuperGAL = SuperGal_TO_ICRS'
# SuperGal --> FK5J2000: chain through GAL
const SuperGal_TO_FK5J2000 = GAL_TO_FK5J2000 * SUPERGAL_TO_GAL
const FK5J2000_TO_SuperGAL = SuperGal_TO_FK5J2000'


# FK5J2000 --> FK5{epoch}
# Computes the precession matrix from J2000 to the given Julian equinox.
# Expression from from Capitaine et al. 2003 as expressed in the USNO
Expand Down Expand Up @@ -99,6 +116,8 @@ end

lon(c::GalCoords) = c.l
lat(c::GalCoords) = c.b
lon(c::SuperGalCoords) = c.l
lat(c::SuperGalCoords) = c.b
lat(c::EclipticCoords) = c.lat
lon(c::EclipticCoords) = c.lon
lon(c::AbstractSkyCoords) = c.ra
Expand All @@ -115,6 +134,12 @@ rotmat(::Type{<:ICRSCoords}, ::Type{<:GalCoords}) = GAL_TO_ICRS
rotmat(::Type{<:ICRSCoords}, ::Type{<:ICRSCoords}) = I
rotmat(::Type{<:GalCoords}, ::Type{<:GalCoords}) = I
rotmat(::Type{<:FK5Coords{e}}, ::Type{<:FK5Coords{e}}) where {e} = I
rotmat(::Type{<:GalCoords}, ::Type{<:SuperGalCoords}) = GAL_TO_SUPERGAL
rotmat(::Type{<:SuperGalCoords}, ::Type{<:GalCoords}) = SUPERGAL_TO_GAL
rotmat(::Type{<:SuperGalCoords}, ::Type{<:SuperGalCoords}) = I
rotmat(::Type{<:SuperGalCoords}, ::Type{<:ICRSCoords}) = SuperGal_TO_ICRS
rotmat(::Type{<:ICRSCoords}, ::Type{<:SuperGalCoords}) = ICRS_TO_SuperGAL


@generated rotmat(::Type{<:EclipticCoords{e}}, ::Type{<:FK5Coords{e}}) where {e} = RotX(-ecliptic_obliquity(e))
@generated rotmat(::Type{<:FK5Coords{e}}, ::Type{<:EclipticCoords{e}}) where {e} = RotX(ecliptic_obliquity(e))
Expand All @@ -127,10 +152,14 @@ rotmat(::Type{<:FK5Coords{e}}, ::Type{<:FK5Coords{e}}) where {e} = I
precess_from_j2000(e1) * ICRS_TO_FK5J2000
@generated rotmat(::Type{<:FK5Coords{e1}}, ::Type{<:GalCoords}) where {e1} =
precess_from_j2000(e1) * GAL_TO_FK5J2000
@generated rotmat(::Type{<:FK5Coords{e1}}, ::Type{<:SuperGalCoords}) where {e1} =
precess_from_j2000(e1) * SuperGal_TO_FK5J2000
@generated rotmat(::Type{<:ICRSCoords}, ::Type{<:FK5Coords{e2}}) where {e2} =
FK5J2000_TO_ICRS * precess_from_j2000(e2)'
@generated rotmat(::Type{<:GalCoords}, ::Type{<:FK5Coords{e2}}) where {e2} =
FK5J2000_TO_GAL * precess_from_j2000(e2)'
@generated rotmat(::Type{<:SuperGalCoords}, ::Type{<:FK5Coords{e2}}) where {e2} =
FK5J2000_TO_SuperGAL * precess_from_j2000(e2)'
@generated rotmat(::Type{<:FK5Coords{e1}}, ::Type{<:FK5Coords{e2}}) where {e1,e2} =
precess_from_j2000(e1) * precess_from_j2000(e2)'

Expand Down
24 changes: 24 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,29 @@ GalCoords(l::Real, b::Real) = GalCoords(promote(float(l), float(b))...)
GalCoords(c::T) where {T<:AbstractSkyCoords} = convert(GalCoords, c)
GalCoords{F}(c::T) where {F,T<:AbstractSkyCoords} = convert(GalCoords{F}, c)

"""
SuperGalCoords(l, b)
[Supergalactic Coordinate System](https://en.wikipedia.org/wiki/Supergalactic_coordinate_system)
The supergalactic plane is part of a reference frame for the supercluster of galaxies that contains the Milky Way galaxy.
The supergalactic plane as so-far observed is more or less perpendicular to the plane of the Milky Way, the angle is 84.5 degrees. Viewed from the Earth, the plane traces a great circle across the sky through the constellations
# Coordinates
- `l` - SuperGalCoords longitude in radians (-π, π)
- `b` - SuperGalCoords latitude in radians (-π/2, π/2)
"""
struct SuperGalCoords{T<:AbstractFloat} <: AbstractSkyCoords
l::T
b::T
SuperGalCoords{T}(l, b) where {T<:AbstractFloat} = new(mod2pi(l), b)
end
SuperGalCoords(l::T, b::T) where {T<:AbstractFloat} = SuperGalCoords{T}(l, b)
SuperGalCoords(l::Real, b::Real) = SuperGalCoords(promote(float(l), float(b))...)
SuperGalCoords(c::T) where {T<:AbstractSkyCoords} = convert(SuperGalCoords, c)
SuperGalCoords{F}(c::T) where {F,T<:AbstractSkyCoords} = convert(SuperGalCoords{F}, c)


"""
FK5Coords{equinox}(ra, dec)
Expand Down Expand Up @@ -107,5 +130,6 @@ end
Base.:(==)(a::T, b::T) where {T<:AbstractSkyCoords} = lon(a) == lon(b) && lat(a) == lat(b)
Base.isapprox(a::ICRSCoords, b::ICRSCoords; kwargs...) = isapprox(SVector(lon(a), lat(a)), SVector(lon(b), lat(b)); kwargs...)
Base.isapprox(a::GalCoords, b::GalCoords; kwargs...) = isapprox(SVector(lon(a), lat(a)), SVector(lon(b), lat(b)); kwargs...)
Base.isapprox(a::SuperGalCoords, b::SuperGalCoords; kwargs...) = isapprox(SVector(lon(a), lat(a)), SVector(lon(b), lat(b)); kwargs...)
Base.isapprox(a::FK5Coords{e}, b::FK5Coords{e}; kwargs...) where {e} = isapprox(SVector(lon(a), lat(a)), SVector(lon(b), lat(b)); kwargs...)
Base.isapprox(a::EclipticCoords{e}, b::EclipticCoords{e}; kwargs...) where {e} = isapprox(SVector(lon(a), lat(a)), SVector(lon(b), lat(b)); kwargs...)

0 comments on commit 917a43b

Please sign in to comment.