[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.

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), tz):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.

18 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.

1 Like

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

1 Like

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

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.