timotejroiko / sweph

The definitive Swiss Ephemeris bindings for Node.js
Other
93 stars 15 forks source link

Planet position different result from Astro.com birth chart #19

Closed mephitrpg closed 5 months ago

mephitrpg commented 5 months ago

I tried to get a planet position but the result is different from Astro.com birth chart, why? Thanks.

NOTE: the commented line is bugged: flag is 2 instead of 0.

const sweph = require('sweph');
const luxon = require('luxon');

const { constants, utc_to_jd, houses, house_pos, calc, calc_ut, split_deg } = sweph;
const { DateTime } = luxon;

sweph.set_ephe_path('ephe');

const planet_name = 'Neptune'
const planet_id = constants.SE_NEPTUNE;

const params = {
    year: 1978,
    month: 4,
    day: 11,
    hours: 11,
    minutes: 59,
    zone:  'Europe/Rome',
    // Camposampiero, ITALY, 45n34 11e56
    lat:  45.566667,
    lon: 11.933333
}

const localDate = DateTime.local(params.year, params.month, params.day, params.hours, params.minutes, { zone: params.zone });
const utcDate = localDate.toUTC();

const JD = utc_to_jd(utcDate.year, utcDate.month, utcDate.day, utcDate.hour, utcDate.minute, utcDate.second, constants.SE_GREG_CAL);
if (JD.flag !== constants.OK) { throw new Error(JD.error); }
const [ JDET, JDUT ] = JD.data;

const HOUSES = houses(JDUT, Number(params.lat), Number(params.lon), 'P');
if (HOUSES.flag !== constants.OK) { throw new Error(HOUSES.flag); }
const armc = HOUSES.data.points[2];

const ECLIPTIC = calc_ut(JDUT, constants.SE_ECL_NUT, 0);
const eps = ECLIPTIC.data[0];

const calcs = calc_ut(JDUT, planet_id, constants.SEFLG_TROPICAL);
// if (calcs.flag !== constants.OK) { throw new Error(JSON.stringify(calcs)); }
const xpin = calcs.data.slice(0, 2);

const NEPTUNE_POS = house_pos(armc, params.lat, eps, 'P', xpin);
const houseNum = parseInt(NEPTUNE_POS.data);
const housePosPercent = NEPTUNE_POS.data - houseNum;
const cusps = HOUSES.data.houses;
const currCusp = cusps[houseNum - 1];
let nextCusp = (cusps[houseNum] !== undefined ? cusps[houseNum] : cusps[0]);
if (nextCusp < currCusp) nextCusp += 360;
const houseWidth = (nextCusp - currCusp);
const deg = currCusp + houseWidth * housePosPercent;

let retrograde;
switch (planet_id) {
    case constants.SE_SUN:
    case constants.SE_MOON:
        retrograde = "Not applicable";
        break;
    case constants.SE_TRUE_NODE:
        retrograde = "Always";
        break;
    default:
        retrograde = (planet_id > 12) ? "Not a planet" : (calcs[3] < 0);
        break;
}

const SPLITTED_POS = split_deg(deg, constants.SE_SPLIT_DEG_ROUND_SEC + constants.SE_SPLIT_DEG_ZODIACAL);
console.log(``);
console.log(`Planet: ${planet_name}`);
console.log(``);
console.log(`SCRIPT RESULT`);
console.log(`sweph.house_pos = ${NEPTUNE_POS.data}`); // 5.618979596337847
console.log(`sweph.split_deg = ${JSON.stringify(SPLITTED_POS)}`); // {"degree":18,"minute":42,"second":36,"fraction":0,"sign":8}
console.log(`Retrograde = ${retrograde}`); // false
console.log(``);
console.log(`ASTRO.COM BIRTCHART RESULT`);
console.log(`deg = {"degree":18,"minute":11,"second":38,"fraction":0,"sign":8}`);
console.log(`Retrograde = true`);
console.log(``);
timotejroiko commented 5 months ago

Hi, could you please double check your Astro.com input?

The position 16 degrees 6 minutes does not seem correct for Neptune for that date.

mephitrpg commented 5 months ago

you're right, I updated the script with the correct Astro.com result, however the results remain different.

timotejroiko commented 5 months ago

hmmm, i'm not understanding the round trip you're doing with the house position, is there any reason for that?

I tested it here like this and i got the correct result:

...
const JD = utc_to_jd(utcDate.year, utcDate.month, utcDate.day, utcDate.hour, utcDate.minute, utcDate.second, constants.SE_GREG_CAL);
const [ JDET, JDUT ] = JD.data; // [ 2443609.9582081484, 2443609.95764303 ]

const calcs = calc_ut(JDUT, planet_id, constants.SEFLG_SWIEPH); // there is no SEFLG_TROPICAL, tropical is default
const deg = calcs.data[0]; // 258.19397969291236
const SPLITTED_POS = split_deg(deg, constants.SE_SPLIT_DEG_ROUND_SEC + constants.SE_SPLIT_DEG_ZODIACAL);

console.log(SPLITTED_POS) // { degree: 18, minute: 11, second: 38, fraction: 0, sign: 8 }
mephitrpg commented 5 months ago

You're right, I was unnecessarily complicating the issue! Thanks! But why the retrograde result is still false instead of true? PS: the calcs.flag is still 2

const sweph = require('sweph');
const luxon = require('luxon');

const { constants, utc_to_jd, houses, house_pos, calc, calc_ut, split_deg } = sweph;
const { DateTime } = luxon;

sweph.set_ephe_path('ephe');

const planet_name = 'Neptune'
const planet_id = constants.SE_NEPTUNE;

const params = {
    year: 1978,
    month: 4,
    day: 11,
    hours: 11,
    minutes: 59,
    zone:  'Europe/Rome',
    // Camposampiero, ITALY, 45n34 11e56
    lat:  45.566667,
    lon: 11.933333
}

const localDate = DateTime.local(params.year, params.month, params.day, params.hours, params.minutes, { zone: params.zone });
const utcDate = localDate.toUTC();

const JD = utc_to_jd(utcDate.year, utcDate.month, utcDate.day, utcDate.hour, utcDate.minute, utcDate.second, constants.SE_GREG_CAL);
if (JD.flag !== constants.OK) { throw new Error(JD.error); }
const [ JDET, JDUT ] = JD.data;

const HOUSES = houses(JDUT, Number(params.lat), Number(params.lon), 'P');
if (HOUSES.flag !== constants.OK) { throw new Error(HOUSES.flag); }
const armc = HOUSES.data.points[2];

const ECLIPTIC = calc_ut(JDUT, constants.SE_ECL_NUT, 0);
const eps = ECLIPTIC.data[0];

const calcs = calc_ut(JDUT, planet_id, constants.SEFLG_SWIEPH);
// if (calcs.flag !== constants.OK) { throw new Error(JSON.stringify(calcs)); }
const deg = calcs.data[0]; // 258.19397969291236
const xpin = calcs.data.slice(0, 2);

let retrograde;
switch (planet_id) {
    case constants.SE_SUN:
    case constants.SE_MOON:
        retrograde = "Not applicable";
        break;
    case constants.SE_TRUE_NODE:
        retrograde = "Always";
        break;
    default:
        retrograde = (planet_id > 12) ? "Not a planet" : (calcs[3] < 0);
        break;
}

const HOUSE_POS = house_pos(armc, params.lat, eps, 'P', xpin);

const SPLITTED_POS = split_deg(deg, constants.SE_SPLIT_DEG_ROUND_SEC + constants.SE_SPLIT_DEG_ZODIACAL);

console.log(``);
console.log(`Planet: ${planet_name}`);
console.log(``);
console.log(`SCRIPT RESULT`);
console.log(`sweph.calc pos = ${deg}`);
console.log(`sweph.split_deg = ${JSON.stringify(SPLITTED_POS)}`);
console.log(`Retrograde = ${retrograde}`);
console.log(`sweph.house_pos num = ${Math.floor(HOUSE_POS.data)}`);
console.log(``);
console.log(`ASTRO.COM BIRTCHART RESULT`);
console.log(`deg = {"degree":18,"minute":11,"second":38,"fraction":0,"sign":8}`);
console.log(`Retrograde = true`);
console.log(``);
timotejroiko commented 5 months ago

you need the SPEED flag to return speeds:

const calcs = calc_ut(JDUT, planet_id, constants.SEFLG_SWIEPH + constants.SEFLG_SPEED);
mephitrpg commented 5 months ago

works like a charm! thank you

Hrsikesa108 commented 5 months ago

Hi timotejroiko sir, can you give some guidelines how to run this program locally in node and get planetary details in json ? i found my intrest in learning astrology and was searching in github repos your repo i found and felt lucky.

Thanks sir

timotejroiko commented 5 months ago

hi @Hrsikesa108 , there should an example on how to get the positions of planets and houses in the beginning of index.d.ts, which you can also access by hovering the main sweph export when you import the library.

if you need further assistance, kindly open a new issue, i'm gonna go ahead and close this one.