-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constructors #26
Merged
Merged
Constructors #26
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
04ff4db
put types into their own file and add constructor from other type
mileslucas 3491fee
add tests and write code allowing unit conversion with pipe
mileslucas ee418f0
rebase branch and add version
mileslucas 73c9a3e
add conversion docs to documentation
mileslucas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# ----------------------------------------------------------------------------- | ||
# Types | ||
|
||
""" | ||
The supertype for all sky coordinate systems. | ||
""" | ||
abstract type AbstractSkyCoords end | ||
|
||
""" | ||
ICRSCoords(ra, dec) | ||
|
||
[International Celestial Reference System](https://en.wikipedia.org/wiki/International_Celestial_Reference_System) | ||
|
||
This is the current standard adopted by the International Astronomical Union notably due to its high level of accuracy compared to standard equatorial coordinate systems. What sets this apart from [`FK5Coords`](@ref) is that it is completely defined using extragalactic radio sources rather than a geocentric frame, which means the reference frame will not change due to Earth's motion. | ||
|
||
# Coordinates | ||
- `ra` - Right ascension in radians (0, 2π) | ||
- `dec` - Declination in radians (-π/2, π/2) | ||
""" | ||
struct ICRSCoords{T <: AbstractFloat} <: AbstractSkyCoords | ||
ra::T | ||
dec::T | ||
ICRSCoords{T}(ra, dec) where {T <: AbstractFloat} = new(mod2pi(ra), dec) | ||
end | ||
ICRSCoords(ra::T, dec::T) where {T <: AbstractFloat} = ICRSCoords{T}(ra, dec) | ||
ICRSCoords(ra::Real, dec::Real) = ICRSCoords(promote(float(ra), float(dec))...) | ||
ICRSCoords(c::T) where {T <: AbstractSkyCoords} = convert(ICRSCoords, c) | ||
ICRSCoords{F}(c::T) where {F,T <: AbstractSkyCoords} = convert(ICRSCoords{F}, c) | ||
|
||
""" | ||
GalCoords(l, b) | ||
|
||
[Galactic Coordinate System](https://en.wikipedia.org/wiki/Galactic_coordinate_system) | ||
|
||
This coordinate system is defined based on the projection of the Milky Way galaxy onto our celestial sphere, with (0, 0) being approximately the center of our galaxy. | ||
|
||
# Coordinates | ||
- `l` - Galactic longitude in radians (-π, π) | ||
- `b` - Galactic latitude in radians (-π/2, π/2) | ||
""" | ||
struct GalCoords{T <: AbstractFloat} <: AbstractSkyCoords | ||
l::T | ||
b::T | ||
GalCoords{T}(l, b) where {T <: AbstractFloat} = new(mod2pi(l), b) | ||
end | ||
GalCoords(l::T, b::T) where {T <: AbstractFloat} = GalCoords{T}(l, b) | ||
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) | ||
|
||
""" | ||
FK5Coords{equinox}(ra, dec) | ||
|
||
[Equatorial Coordinate System](https://en.wikipedia.org/wiki/Equatorial_coordinate_system) | ||
|
||
This coordinate system maps the celestial sphere based on a geocentric observer. Historically the oldest, this coordinate system has been shown to be inaccurate due to its definitions based on the Earth, which has long-scale precession causing the reference frame to change. Because of this, an equinox must be provided (typically 2000, commonly known as J2000) which defines the reference frame. | ||
|
||
# Coordinates | ||
- `ra` - Right ascension in radians (0, 2π) | ||
- `dec` - Declination in radians (-π/2, π/2) | ||
""" | ||
struct FK5Coords{e,T <: AbstractFloat} <: AbstractSkyCoords | ||
ra::T | ||
dec::T | ||
FK5Coords{e,T}(ra, dec) where {T <: AbstractFloat,e} = new(mod2pi(ra), dec) | ||
end | ||
FK5Coords{e}(ra::T, dec::T) where {e,T <: AbstractFloat} = FK5Coords{e,T}(ra, dec) | ||
FK5Coords{e}(ra::Real, dec::Real) where {e} = | ||
FK5Coords{e}(promote(float(ra), float(dec))...) | ||
FK5Coords{e}(c::T) where {e,T <: AbstractSkyCoords} = convert(FK5Coords{e}, c) | ||
FK5Coords{e,F}(c::T) where {e,F,T <: AbstractSkyCoords} = convert(FK5Coords{e,F}, c) | ||
|
||
|
||
# Scalar coordinate conversions | ||
Base.convert(::Type{T}, c::T) where {T <: AbstractSkyCoords} = c | ||
|
||
function Base.convert(::Type{T}, c::S) where {T <: AbstractSkyCoords,S <: AbstractSkyCoords} | ||
r = rotmat(T, S) * coords2cart(c) | ||
lon, lat = cart2coords(r) | ||
T(lon, lat) | ||
end | ||
|
||
Base.:(==)(a::T, b::T) where {T <: AbstractSkyCoords} = lon(a) == lon(b) && lat(a) == lat(b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can directly use
0.5.0
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have plans for another PR after this one to allow string construction, which is mostly written already so it could make sense to push that one as 0.5.0