Adding a New Solar Position Algorithm

Use an existing algorithm in src/Positioning/ as a starting point:

  • iqbal.jl for an algorithm without default refraction
  • noaa.jl for 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 a SolPos{T}.

All returned angles must be in degrees:

AngleConvention
Azimuth0° is north, positive clockwise, in the range [0°, 360°)
ElevationAngle above the horizon, in the range [-90°, 90°]
Zenith90° - elevation

Compute the result at the observer's precision T:

  • Take the time from julian_day_j2000(T, dt), julian_century(T, dt) or fractional_hour(T, dt). Never call datetime2julian directly.
  • Wrap the argument of asin and acos in unit_clamp to prevent numerical issues. See iqbal.jl for 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

  1. In test/positioning/expected-values.jl, add the algorithm to the using SolarPosition line and to test_algorithms().
  2. Create test/positioning/test-<name>.jl and compare against reference values. Files named test-*.jl are discovered automatically.
Reference timestamps

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

FileChange
docs/src/positioning.mdTable row and a section with a @docs block
docs/src/index.mdTable row
README.mdTable row
docs/src/refs.bibLiterature references
docs/src/guides/benchmarking.mdEntry in algorithms and a colour
benchmark/benchmarks.jlEntry in POSITION_ALGORITHMS
CHANGELOG.mdEntry 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.