spa 1.1.0

Solar Positioning Algorithm - Calculate the position of the sun at arbitrary coordinates. #

About #

This is a Dart implementation of the Solar Position Algorithm (SPA) by Ibrahim Reda and Afshin Andreas which is used by the U.S. government for radiology and energy purposes. See the paper here:

Given an observers coordinates and DateTime it can calculate the position of the sun and other information such as when the sun rises and sets.

Installation #

Add the package to your pubspec.yaml:

  spa: ^1.0.0

Example #

For a better example, see

main() {
  var output = spaCalculate(SPAParams(
    time: DateTime(2019, 7, 2, 22),
    longitude: -83.045753,
    latitude: 42.331429,
    elevation: 191,

  print("zenith: ${output.zenith}");
  print("azimuth_astro: ${output.azimuthAstro}");
  print("azimuth: ${output.azimuth}");
  print("incidence: ${output.incidence}");
  print("suntransit: ${output.sunTransit}");
  print("sunrise: ${output.sunrise}");
  print("sunset: ${output.sunset}");
zenith: 97.83236091904035
azimuth_astro: 131.18876481734603
azimuth: 311.18876481734605
incidence: 97.83236091904035
suntransit: 13.604235957046416
sunrise: 5.994654066296624
sunset: 21.21272791301299

Zenith will be less than 90 degrees when it's daytime.

Documentation #

Documentation can be found at

Accuracy #

Guaranteed accuracy of +/- 0.0003 degrees.

This library is tested against the C implementation by NREL using 1,000,000 random inputs, see test/spa_test.dart for more information.

Performance #

Benchmarks are done using benchmark/spa_benchmark.dart.

On my desktop with a Ryzen 5 1600 @ 3.2Ghz I get:

         [vm] Result: 16529 spa/s |  60 μs/spa
        [DDC] Result:  8077 spa/s | 123 μs/spa
[dart2js -O4] Result: 25316 spa/s |  39 μs/spa

On an LG K10 with a Snapdragon 410 @ 1.2Ghz I get:

Result: 1149 spa/s | 869 μs/spa

1.1.0 #

  • Performance improvements
  • Adjusted dependency constraints

1.0.0 #

  • First release!
  • Implemented entire SPA algorithm.
  • Added randomly generated test dataset to verify consistency with reference C implementation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  spa: ^1.1.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:spa/spa.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Sep 19, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:spa/spa.dart.

Health suggestions

Format lib/spa.dart.

Run dartfmt to format lib/spa.dart.

Format lib/src/spa.dart.

Run dartfmt to format lib/src/spa.dart.

Maintenance suggestions

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and spa.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
meta ^1.1.0 1.1.7
tuple ^1.0.2 1.0.2
Transitive dependencies
matcher 0.12.5
path 1.6.4
quiver 2.0.5
stack_trace 1.9.3
Dev dependencies
pedantic ^1.0.0
test ^1.0.0