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

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: https://www.nrel.gov/docs/fy08osti/34302.pdf

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`:

``````dependencies:
spa: ^1.1.0
``````

Example #

For a better example, see https://github.com/PixelToast/dart-spa/tree/master/example/cities

``````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 https://pub.dev/documentation/spa/latest/

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

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

``````
dependencies:
spa: ^1.1.1-hotfix1

``````

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';
``````
 Popularity: Describes how popular the package is relative to other packages. [more] 37 Health: Code health derived from static analysis. [more] 100 Maintenance: Reflects how tidy and up-to-date the package is. [more] 95 Overall: Weighted score of the above. [more] 67

We analyzed this package on Jan 28, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

• Dart: 2.7.1
• pana: 0.13.4

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

Package is pre-release. (-5 points)

Pre-release versions should be used with caution; their API can change in breaking ways.

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/README.md`.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
meta ^1.1.0 1.1.8
tuple ^1.0.2 1.0.3
Transitive dependencies
matcher 0.12.6
path 1.6.4
quiver 2.1.2+1
stack_trace 1.9.3
Dev dependencies
pedantic ^1.0.0
test ^1.0.0