Skip to content

arturania/sweph.dart

 
 

Repository files navigation

Sweph

Cross-platform bindings of Swiss Ephemeris APIs for Flutter. Everything you need to create Astrology and Astronomy applications with Dart and Flutter.

  • 100% API coverage
  • Dart friendly parameters and return values
  • Supported on all platforms. Uses ffi for non-Web platforms and wasm for Web
  • Version matched with source

References:

Usage example

import 'package:sweph/sweph.dart';

Future<void> main() async {
  // Sweph comes bundled with some ephe file. Refer to Sweph.bundledEpheAssets
  // These or any other bundled ephe files can be initialized during Sweph.init
  // These are coped to <ApplicationSupportDirectory>/ephe_files folder for non-Web platforms
  // For Web, this is the only way to provide ephe files, and they are loaded into memory
  await Sweph.init(epheAssets: [
    "packages/sweph/assets/ephe/sefstars.txt",
  ]);

  // alternately if a folder already contains ephe files, Sweph can be used in sync mode like this:
  // await Sweph.swe_set_ephe_path(<path-to-existing-folder>)
  // This is not available for Web

  print('sweph.swe_version = ${Sweph.swe_version()}');
  print('Moon longitude on 2022-06-29 02:52:00 UTC = ${Sweph.swe_calc_ut(Sweph.swe_julday(2022, 6, 29, (2 + 52 / 60), CalendarType.SE_GREG_CAL), HeavenlyBody.SE_MOON, SwephFlag.SEFLG_SWIEPH).longitude}');

  // Most methods use positional parameters, not named. So if some positional parameters take default values, please refer to original documentation
  // If only some specific flags are allowed for a method, it is restricted via the enumerated flags
  // For example, to set the sidereal mode to Lahiri with projection onto solar system plane and custom t0 in UT
  Sweph.swe_set_sid_mode(SiderealMode.SE_SIDM_LAHIRI, SiderealModeFlag.SE_SIDBIT_SSY_PLANE, 123.45 /* t0 */);
  // or, to set the sidereal mode to Lahiri with no flags and custom ayan_t0 in UT
  Sweph.swe_set_sid_mode(SiderealMode.SE_SIDM_LAHIRI, SiderealModeFlag.SE_SIDBIT_NONE, 0.0 /* t0 */, 987.65 /* ayan_t0 */);
}

Licensing

This library follows the licensing requirements for the Swiss Ephemeris by Astrodienst AG.

- AGPL

Starting from version 2.10.02 and later, this library is licensed under AGPL-3.0. To install and use the latest version of this library under AGPL, use flutter pub add sweph.

- LGPL

If you own a professional license for the Swiss Ephemeris, you may use any version of this library under LGPL-3.0.

Versioning

This library is version locked to the Swiss Ephemeris in addition to its own revisions. For example, version 2.10.02+1 corresponds to the Swiss Ephemeris version 2.10.02 and this library's revision 1.

Updates to this library will be released under new revisions, while updates to Swiss Ephemeris will be released under matching semver versions.

Ephemeris files

The following ephemeris files are bundled with this plugin:

  • seas_18.se1 - main ephemeris for asteroids (1800-2400 CE)
  • semo_18.se1 - main ephemeris for moon (1800-2400 CE)
  • sepl_18.se1 - main ephemeris for planets (1800-2400 CE)
  • seasnam.txt - list of asteroids
  • sefstars.txt - fixed stars data file
  • seleapsec.txt - dates of leap seconds to be taken into account
  • seorbel.txt - orbital elements of ficticious planets :)

These could also be download from https://www.astro.com/ftp/swisseph/ephe/. More information can be found in the Swiss Ephemeris files documentation.

Using bundled Ephemeris files

Sweph.init accepts a list of ephemeris files as assets. These could be any of the bundled ones or other app assets. It does not accept local file path!

non-Web

These are cached in <ApplicationSupportDirectory>/ephe_files folder. First load will be slow. Async methods swe_set_ephe_path & swe_set_jpl_file could be called to set new ephe files. If file already present, it is not overwritten, unless forceOverwrite is true.

Web

Sweph.init is the only way to provide ephe files, and they are loaded into memory. This is a limitation of the Web plugin. Calls to swe_set_ephe_path has no effect on Web. Only the loaded assets are used. If custom JPL files are needed, the need to be loaded as with the name "jpl_file.eph" during init and swe_set_jpl_file could be called.

Contributing

If you find any innacuracy or bug in this library, or if you find an update that is not yet included in this library, feel free to open an issue or a pull request.

Known Issues and Caveats

  • The included ephe files are available async only
  • Due to how the underlying C library operates, you may find that the error field returned by some functions will contain random data even if there is no actual error. This can happen when existing memory buffers are recycled therefore the user must always check the returned flag values as per the Swiss Ephemeris documentation.

Author

Copyright © 2022, VM75

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 48.4%
  • C 46.1%
  • Dart 4.3%
  • C++ 0.5%
  • CMake 0.5%
  • Makefile 0.1%
  • Other 0.1%