[ANN] SolarPosition.jl

I am excited to announce the release of my first public Julia package, SolarPosition.jl.

TLDR

SolarPosition.jl is a common interface to a variety of solar positioning algorithms which have been rewritten from scratch in Julia.

Installation

SolarPosition.jl is part of the general registry, so you can simply install from the REPL:

] add SolarPosition

Example usage

julia> using SolarPosition, Dates, TimeZones, DataFrames

julia> timezone = tz"Asia/Kolkata"
Asia/Kolkata (UTC+05:30)

julia> obs = Observer(28.6, 77.2, 0.0)
Observer(latitude=28.6°, longitude=77.2°, altitude=0.0m)

julia> times = collect(ZonedDateTime(DateTime(2019), timezone):Hour(1):ZonedDateTime(DateTime(2020), timezone))

julia> positions = solar_position(obs, times)

julia> df = DataFrame(positions)
8761×3 DataFrame
  Row │ azimuth   elevation  zenith  
      │ Float64   Float64    Float64 
──────┼──────────────────────────────
    1 │ 314.042    -82.2189  172.219
    2 │  57.3871   -80.2452  170.245
    3 │  81.0308   -67.8108  157.811
    4 │  90.0973   -54.6909  144.691
    5 │  96.4595   -41.5545  131.555
    6 │ 102.165    -28.5678  118.568
  ⋮   │    ⋮          ⋮         ⋮
 8757 │ 258.871    -31.0619  121.062
 8758 │ 264.625    -44.0833  134.083
 8759 │ 271.261    -57.2304  147.23
 8760 │ 281.445    -70.3099  160.31
 8761 │ 314.092    -82.2513  172.251
                    8750 rows omitted

Features

  • Supports PSA, NOAA, Walraven, USNO and the gold standard SPA algorithm.
  • Support for more algorithms can be added as PRs by following the supplied guide.
  • All algorithms are implemented in Julia, so no interfaces to C or python are required.
  • All algorithms are validated using reference implementations.
  • Tables.jl interface so you can easily work with solar positions in dataframes or any other container that supports the tables interface.
  • Efficient caching of time-independent quantities through the Observer struct.
  • Refraction models are abstracted from the base algorithms so you can mix and match refraction and positioning models as you see fit. By default, each algorithm will use the refraction model defined by its accompanying paper reference.

Extensions

  • Full multithreading support for all algorithms via OhMyThreads.jl extension.
  • Can be intergrated into symbolic workflows through a ModelingToolkit.jl extension that supplies a SolarPositionBlock component.
  • Makie.jl extension for making some basic plots.

Why SolarPosition.jl?

The primary application I had in mind when writing this package is solar photovoltaics engineering, but it can be used in any application where you need to know something about the position of the sun.

A second reason is that almost every programming language has a similar package offering solar positioning algorithms, and Julia didn’t have one yet (that I could find, I did find a few scripts scattered here and there). Python has solposx and pvlib, R has solarPos, Rust has spa-rs and so on. Now Julia has one too!

Feedback

As this is my first ‘serious’ Julia package, I am looking for feedback. Anything is welcome. You can either put a comment in this thread, or just make a PR or an issue on the GH repository.

31 Likes

What do you think of SunCalc.jl?

Did not show up in my initial google search. (it looks unmaintained)

Appreciate the effort put into the documentation: very thorough and with literature references.

2 Likes

Thanks to Documenter.jl for making the process so smooth :slight_smile:

3 Likes

It has had it for almost ten years now: Reference · AstroLib. Example of drawing the analemma with it: Drawing the analemma with Julia

1 Like

Also, you may want to provide an actual link to your package when you announce it, especially if it’s not registered so one doesn’t even know where to find it. Edit: I presume it’s GitHub - JuliaAstro/SolarPosition.jl: Solar positioning algorithms for Julia.

1 Like

Link should work when the registry PR is merged, I thought that would be right after I posted this but seems I timed it slightly wrong. Any hour now…

I know about that one. Also: Canonize all the things · Issue #59 · JuliaAstro/JuliaAstro.github.io · GitHub (I am not claiming I’m the first in any way :slight_smile: )

Howdy folks

First off, this is an awesome package, Stefan! I’ll definitely be stealing some of your project management workflows as I learn more, and as we continue to spiff up our JuliaAstro ecosystem.

Thanks for bringing up the analemma thread. There’s actually a quick comparison plot between AstroLib.jl (which we are working on transitioning to a maintenance-only mode) and SolarPosition.jl a few messages down. This was just me starting to fiddle around with things, certainly not a comprehensive breakdown.

In general, there’s been some discussion behind the scenes with Stefan and others about coordinating these astrometry related efforts; I think there is lots to learn from each other. This is actually going to be one of our agenda items during our inaugural JuliaAstro steering council meeting next week.

So, stay tuned y’all! We’ve got some good things cooking =]

4 Likes

The registry PR was just merged :slight_smile:

so you can now do:

] add SolarPosition
1 Like