|
| 1 | +# Coordinate Systems |
| 2 | + |
| 3 | +Similart to the definitions in [Astropy](https://docs.astropy.org/en/stable/coordinates/definitions.html): we adopt the following terminology: |
| 4 | + |
| 5 | +- A **Coordinate Representation** (chart) is a particular way of describing a unique point in a vector space. |
| 6 | + Common ones include `Cartesian3`, `Spherical`, and `Geodetic` based on [`AbstractRepresentation`](@ref). |
| 7 | +- A **Reference System** is a scheme for orienting points in a space and describing how they transform to other systems. |
| 8 | + For example, the Earth-centered, Earth-fixed (ECEF) reference system tells you (i) origin at the geocenter, (ii) axes rotate with the Earth. But it does not uniquely specify: (i) whether Z is ITRF pole, [Conventional International Origin pole](https://www.wikiwand.com/en/articles/Conventional_International_Origin), "instantaneous rotation axis", etc (ii) whether the axes are aligned to a particular [geodetic datum](https://www.wikiwand.com/en/articles/Geodetic_datum). |
| 9 | +- A **Reference Frame** is a specific realization of a reference system (e.g., the [ICRF](https://www.wikiwand.com/en/articles/International_Celestial_Reference_System_and_its_realizations), or J2000 equatorial coordinates). |
| 10 | + For example, GEO is a simplified ECEF realization suitable for space-physics transformations (GEO↔GSE/GSM/SM/MAG). It differs from “true” geodesy realization like [ITRF](https://www.wikiwand.com/en/articles/International_Terrestrial_Reference_System_and_Frame) in that it ignores small corrections like polar motion and uses a simplified Earth rotation model. |
| 11 | +- A **Coordinate** is a combination of all of the above that specifies a unique point. |
| 12 | + |
| 13 | +<!-- - A **Coordinate Transformation** is a mapping between different coordinate systems. --> |
| 14 | + |
| 15 | +The package exports the following types [`AbstractReferenceSystem`](@ref), [`AbstractRepresentation`](@ref), [`AbstractReferenceFrame`](@ref), and [`AbstractCoordinateVector`](@ref): |
| 16 | + |
| 17 | +And related functions: |
| 18 | + |
| 19 | +- [`getcsys`](@ref): Function to retrieve the coordinate system from an object |
| 20 | + |
| 21 | + |
| 22 | +!!! note "Notes" |
| 23 | + Because of the ambiguity of meaning of "coordinate system", this term should be avoided wherever possible. However, for backward compatibility, we still export [`AbstractCoordinateSystem`](@ref) which serves a practical purpose of combining reference frame and coordinate representation. |
| 24 | + |
| 25 | +## Implementation Approaches |
| 26 | + |
| 27 | +Here we demonstrate two approaches to implementing coordinate vectors and their associated systems: |
| 28 | + |
| 29 | +### Approach 1: Explicit Coordinate System Field |
| 30 | + |
| 31 | +Store the coordinate system directly as a field in the vector type: |
| 32 | + |
| 33 | +```@repl coord |
| 34 | +using SpaceDataModel: Cartesian3, AbstractReferenceFrame, AbstractCoordinateVector |
| 35 | +import SpaceDataModel: getcsys |
| 36 | +# Define a reference frame |
| 37 | +struct GEO <: AbstractReferenceFrame end |
| 38 | +
|
| 39 | +# Define a vector with an explicit reference frame and representation |
| 40 | +struct CoordinateVector{F, R, T} <: AbstractCoordinateVector |
| 41 | + x::T |
| 42 | + y::T |
| 43 | + z::T |
| 44 | +end |
| 45 | +
|
| 46 | +𝐫 = CoordinateVector{GEO, Cartesian3, Float64}(1, 2, 3) |
| 47 | +
|
| 48 | +# Implementation of getcsys |
| 49 | +getcsys(::CoordinateVector{F, R}) where {F, R} = (F(), R()) |
| 50 | +getcsys(𝐫) |
| 51 | +``` |
| 52 | + |
| 53 | +### Approach 2: Implicit Coordinate System |
| 54 | + |
| 55 | +Associate a specific coordinate system with a vector type: |
| 56 | + |
| 57 | +```@repl coord |
| 58 | +# Define a vector type specific to a coordinate system |
| 59 | +struct GEOVector{D} <: AbstractCoordinateVector |
| 60 | + data::D |
| 61 | +end |
| 62 | +
|
| 63 | +# Implementation of getcsys returns the appropriate system |
| 64 | +getcsys(::GEOVector) = (GEO(), Cartesian3()) |
| 65 | +𝐫2 = GEOVector([1, 2, 3]) |
| 66 | +getcsys(𝐫2) |
| 67 | +``` |
| 68 | + |
| 69 | +Both approaches are highly efficient and provide equivalent performance due to Julia's type inference system. |
| 70 | + |
| 71 | +```@example coord |
| 72 | +using Chairmarks |
| 73 | +@b getcsys($𝐫), getcsys($𝐫2) |
| 74 | +``` |
| 75 | + |
| 76 | +## Elsewhere |
| 77 | + |
| 78 | +- [Astronomical Coordinate Systems (astropy.coordinates) — Astropy](https://docs.astropy.org/en/stable/coordinates/index.html) |
| 79 | +- [CoordRefSystems.jl](https://github.com/JuliaEarth/CoordRefSystems.jl) provides conversions between Coordinate Reference Systems (CRS) for cartography use cases. |
| 80 | +- [Geodesy.jl](https://github.com/JuliaGeo/Geodesy.jl) for working with points in various world and local coordinate systems. |
| 81 | +- [WCS.jl](https://juliaastro.org/WCS/stable/) : Astronomical World Coordinate System library |
0 commit comments