Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On how the library is to be used #73

Open
gkostov opened this issue Feb 14, 2021 · 2 comments
Open

On how the library is to be used #73

gkostov opened this issue Feb 14, 2021 · 2 comments

Comments

@gkostov
Copy link
Contributor

gkostov commented Feb 14, 2021

Hey guys,

All examples refer to functions from the Swiss Ephemeris library API (like swe_calc_ut()) but in the main file of this library /lib/swisseph.js there is that calc() function for which I can't find any documentation. Is that function meant to be used at all? It seems to produce results that are very close to the examples like /examples/planets.js but are not exactly equal.
I'm still trying to figure out how to properly use the library so any help would be appreciated.

Thanks

@krisztianb
Copy link
Contributor

krisztianb commented Sep 2, 2021

Hi. I've just discovered this library myself and was asking myself the same question.

But first I ran into several problems installing it:

  • First I had to install Python as it is required by node-gyp (a dependency of this library) which is used to build the C++ part of this library.
  • I also had to install some Visual Studio Addons (VC++ build tools, Windows 10 SDK etc.)

Then installing the package finally worked. But to get back to your question:

When you install the library it executes a C++ build which generates this file: myProject\node_modules\swisseph\build\Releases\wisseph.node. That is the file which is imported in the index.js file you are talking about. It is actually a C++ binary which Node.js can load. You can find more about this here.

The index.js file imports the Swiss Ephemeris library into an object and adds some constants to it. Then that object is exported. That object is what we import in our project by doing require("swisseph"). By importing the object you can access all the Swiss Ephemeris functions.

But not just some constants are added. Also this strange calc function is added. I don't know why it is there.

Executing the code from the README:

var swisseph = require("swisseph");
var date = { year: 2015, month: 1, day: 1, hour: 0 };
var julday = swisseph.swe_julday(date.year, date.month, date.day, date.hour, swisseph.SE_GREG_CAL);
console.log(julday);

Gives me: 2457023.5

@krisztianb
Copy link
Contributor

I think I now understand what the "calc" function does. It looks like it takes a data object (called options) and extends it with missing/converted data. So to answer your question: You don't have to use it. To me it looks like a test function, because it calls "swe_close" at the end which releases all resources (open files and allocated memory) used by the Swiss Ephemeris DLL.

Example (TypeScript code):

import swisseph from "swisseph";

var ret = swisseph.calc(
    {
        date: {
            gregorian: { terrestrial: { year: 2021, month: 9, day: 17, hour: 21 } },
        },
        body: {
            id: 1,
            position: {
                longitude: 47,
                latitude: 16,
            },
        },
        observer: {
            geographic: {
                longitude: 47,
                latitude: 16,
                height: 2,
            },
        },
    },
    (result) => {
        console.log(result);
    }
);

console.log(ret);

Output:

{
  date: {
    gregorian: {
      terrestrial: { terrestrial: { year: 2021, month: 9, day: 17, hour: 21 } },
      universal: { terrestrial: { year: 2021, month: 9, day: 17, hour: 20 } },
      delta: 69.81315104729428
    },
    julian: {
      terrestrial: 2459475.375,
      delta: 0.000808022581565906,
      universal: 2459475.3741919775
    }
  },
  body: {
    id: 1,
    position: {
      longitude: { decimalDegree: 47 };
      latitude: { decimalDegree: 16 };
      distance: 0.0025105828529191744,
      longitudeSpeed: 9.71724408884711,
      latitudeSpeed: 2.283500123212434,
      distanceSpeed: 0.00016263597412378983,
      rflag: 33028
    },
    name: 'Moon'
  },
  observer: {
    geographic: { longitude: 47, latitude: 16, height: 2 },
    ephemeris: 'moshier'
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants