Adding a New Solar Position Algorithm
Use an existing algorithm in src/Positioning/ as a starting point:
iqbal.jlfor an algorithm without default refractionnoaa.jlfor an algorithm with default refraction
1. Implement the algorithm
Create src/Positioning/<name>.jl with:
- A struct that subtypes
SolarAlgorithm. - A docstring that states the claimed accuracy and cites the relevant literature.
- A method
_solar_position(obs::Observer{T}, dt::DateTime, alg)that returns aSolPos{T}.
All returned angles must be in degrees:
| Angle | Convention |
|---|---|
| Azimuth | 0° is north, positive clockwise, in the range [0°, 360°) |
| Elevation | Angle above the horizon, in the range [-90°, 90°] |
| Zenith | 90° - elevation |
Compute the result at the observer's precision T:
- Take the time from
julian_day_j2000(T, dt),julian_century(T, dt)orfractional_hour(T, dt). Never calldatetime2juliandirectly. - Wrap the argument of
asinandacosinunit_clampto prevent numerical issues. Seeiqbal.jlfor an example.
2. Set the default refraction
You can skip this step if the algorithm applies no refraction by default.
Otherwise, you may define these two methods with your appropriate refraction model:
using ..Refraction: HUGHES, DefaultRefractionfunction _solar_position(obs::Observer{T}, dt, alg::MyAlgorithm, ::DefaultRefraction) where {T} return _solar_position(obs, dt, alg, HUGHES{T}())endresult_type(::Type{MyAlgorithm}, ::Type{DefaultRefraction}, ::Type{T}) where {T} = ApparentSolPos{T}Write HUGHES{T}() and not HUGHES(), which would promote a Float32 result to Float64.
3. Export it
In src/Positioning/Positioning.jl, include the new file and add the algorithm to the export list.
4. Add tests
- In
test/positioning/expected-values.jl, add the algorithm to theusing SolarPositionline and totest_algorithms(). - Create
test/positioning/test-<name>.jland compare against reference values. Files namedtest-*.jlare discovered automatically.
Use timestamps at multiples of 11 min 15 s from noon UTC, such as 13:30:00. Other timestamps can add rounding errors to the reference values through the Julian Date computation.
5. Update the documentation
| File | Change |
|---|---|
docs/src/positioning.md | Table row and a section with a @docs block |
docs/src/index.md | Table row |
README.md | Table row |
docs/src/refs.bib | Literature references |
docs/src/guides/benchmarking.md | Entry in algorithms and a colour |
benchmark/benchmarks.jl | Entry in POSITION_ALGORITHMS |
CHANGELOG.md | Entry under ## unreleased |
6. Run the checks
prek run -a # or pre-commit run -a
julia --project -e 'using Pkg; Pkg.test()'The hooks also run with pre-commit run -a.