Skip to content

Commit

Permalink
add EclipticCoords
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin committed Jan 13, 2023
1 parent 6c8849b commit e1af8a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/SkyCoords.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,15 @@ function precess_from_j2000(equinox)
zrotmat(-z) * yrotmat(theta) * zrotmat(-zeta)
end

ecliptic_obliquity(y) = deg2rad(23.439291 - 0.0130042 * (y - 2000.0))

# -----------------------------------------------------------------------------
# Type-dependent methods

lon(c::GalCoords) = c.l
lat(c::GalCoords) = c.b
lat(c::EclipticCoords) = c.lat
lon(c::EclipticCoords) = c.lon
lon(c::AbstractSkyCoords) = c.ra
lat(c::AbstractSkyCoords) = c.dec

Expand All @@ -121,6 +125,9 @@ rotmat(::Type{<:ICRSCoords}, ::Type{<:ICRSCoords}) = I
rotmat(::Type{<:GalCoords}, ::Type{<:GalCoords}) = I
rotmat(::Type{<:FK5Coords{e}}, ::Type{<:FK5Coords{e}}) where {e} = I

@generated rotmat(::Type{<:EclipticCoords{e}}, ::Type{<:ICRSCoords}) where {e} = xrotmat(ecliptic_obliquity(e))
@generated rotmat(::Type{<:ICRSCoords}, ::Type{<:EclipticCoords{e}}) where {e} = xrotmat(-ecliptic_obliquity(e))

@generated rotmat(::Type{<:FK5Coords{e1}}, ::Type{<:ICRSCoords}) where {e1} =
precess_from_j2000(e1) * ICRS_TO_FK5J2000
@generated rotmat(::Type{<:FK5Coords{e1}}, ::Type{<:GalCoords}) where {e1} =
Expand Down
13 changes: 13 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ FK5Coords{e,F}(c::T) where {e,F,T<:AbstractSkyCoords} = convert(FK5Coords{e,F},
constructorof(::Type{<:FK5Coords{e}}) where {e} = FK5Coords{e}


struct EclipticCoords{e,T<:AbstractFloat} <: AbstractSkyCoords
lon::T
lat::T
EclipticCoords{e,T}(lon, lat) where {e,T<:AbstractFloat} = new(mod2pi(lon), lat)
end
EclipticCoords{e}(lon::T, lat::T) where {e,T<:AbstractFloat} = EclipticCoords{e,T}(lon, lat)
EclipticCoords{e}(lon::Real, lat::Real) where {e} = EclipticCoords(promote(float(lon), float(lat))...)
EclipticCoords{e}(c::AbstractSkyCoords) where {e} = convert(EclipticCoords{e}, c)
EclipticCoords{e,F}(c::AbstractSkyCoords) where {e,F} = convert(EclipticCoords{e,F}, c)
constructorof(::Type{<:EclipticCoords{e}}) where {e} = EclipticCoords{e}


# Scalar coordinate conversions
Base.convert(::Type{T}, c::T) where {T<:AbstractSkyCoords} = c

Expand All @@ -85,3 +97,4 @@ Base.:(==)(a::T, b::T) where {T<:AbstractSkyCoords} = lon(a) == lon(b) && lat(a)
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::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 e1af8a5

Please sign in to comment.