Giter Site home page Giter Site logo

ephemeris's Introduction

Note: Need any help to support this project. Contributors are welcome!

Pure javascript implementation of ephemeris calculations for sun, planets, comets, asteroids and stars.

This implementation based on Steve Moshier (http://www.moshier.net).

Licensed under GPL version 2 (http://www.gnu.org/licenses/gpl-2.0.html).

Please contribute in this project.

Example

<script type='text/javascript' src='ephemeris-0.1.0.js' charset='utf-8'></script>
<script type='text/javascript'>

var date = {year: 1986, month: 1, day: 1, hours: 1, minutes: 52, seconds: 0};

$const.tlong = -71.10; // longitude
$const.glat = 42.37; // latitude

$processor.init ();

// sun, mercury, venus, moon, mars, jupiter, saturn, uranus, neptune, pluto, chiron, sirius
var body = $moshier.body.sun;

$processor.calc (date, body);

document.write(`<p style="white-space: pre-wrap">${JSON.stringify(body.position, '', 2)}</p>`);
</script>

ephemeris's People

Contributors

bittnkr avatar blucobalto avatar kibo avatar mivion avatar xerik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ephemeris's Issues

Understanding PhaseQuarter of Moon calculation

Hi, I pulled a sample of the moon phase calculations for the month of January, 2000 at midnight UTC each day.

Everything seems to be OK with the illuminatedFraction property (reference: https://www.calendar-12.com/moon_calendar/2000/january) , except for the phaseQuarter property which doesn't make sense to me. It seems to not correspond with the actual quarters of illumination I'd expect.

Here's what I expect:

0 = full moon = illuminatedFraction: 1.0
1 = last quarter = illuminatedFraction: 0.5
2 = new moon = illuminatedFraction: 0.0
3 = first quarter = illuminatedFraction: 0.5

Here's what we get:

// Day: 1 || illuminatedFraction: 0.2718262029195282 || phaseQuarter: 1 
//        || phaseDaysBefore:1 undefined || phaseDaysAfter: 2.308172935055592
// Day: 2 || illuminatedFraction: 0.1913535738047783 || phaseQuarter: 1 
//        || phaseDaysBefore: undefined || phaseDaysAfter: 3.2571149412964684
// Day: 3 || illuminatedFraction: 0.12275534591473419 || phaseQuarter: 2 
//        || phaseDaysBefore: 3.4652655135006944 || phaseDaysAfter: undefined
// Day: 4 || illuminatedFraction: 0.06789228968867916 || phaseQuarter: 2 
//        || phaseDaysBefore: 2.5492861313626625 || phaseDaysAfter: undefined
// Day: 5 || illuminatedFraction: 0.028402658847401396 || phaseQuarter: 2 
//        || phaseDaysBefore: 1.6280241934067152 || phaseDaysAfter: undefined
// Day: 6 || illuminatedFraction: 0.005654730897217575 || phaseQuarter: 2 
//        || phaseDaysBefore: 0.7040191067596543 || phaseDaysAfter: undefined
// Day: 7 || illuminatedFraction: 0.0006617445257049992 || phaseQuarter: 2 
//        || phaseDaysBefore: undefined || phaseDaysAfter: 0.22075147788362653
// Day: 8 || illuminatedFraction: 0.01398865166284069 || phaseQuarter: 2 
//        || phaseDaysBefore: undefined || phaseDaysAfter: 1.1448340436311208
// Day: 9 || illuminatedFraction: 0.04567593153994548 || phaseQuarter: 2 
//        || phaseDaysBefore: undefined || phaseDaysAfter: 2.0671500977301687
// Day: 10 illuminatedFraction: 0.09519380617986456 || phaseQuarter: 2 
//         || phaseDaysBefore: undefined || phaseDaysAfter: 2.986823486633503
// Day: 11 || illuminatedFraction: 0.16142284737506968 || phaseQuarter: 3 
//         || phaseDaysBefore: 3.5398367149824304 || phaseDaysAfter: undefined
// Day: 12 || illuminatedFraction: 0.2426405680532956 || phaseQuarter: 3 
//         || phaseDaysBefore: 2.5533075133229017 || phaseDaysAfter: undefined
// Day: 13 || illuminatedFraction: 0.3364851635748891 || phaseQuarter: 3 
//         || phaseDaysBefore: 1.5617258301440125 || phaseDaysAfter: undefined
// Day: 14 || illuminatedFraction: 0.43987279594989304 || phaseQuarter: 3 
//         || phaseDaysBefore: 0.5660695275207581 || phaseDaysAfter: undefined
// Day: 15 || illuminatedFraction: 0.5488689342271671 || phaseQuarter: 3 
//         || phaseDaysBefore: undefined || phaseDaysAfter: 0.4328134799840978
// Day: 16 || illuminatedFraction: 0.6585597621788225 || phaseQuarter: 3 
//         || phaseDaysBefore: undefined || phaseDaysAfter: 1.4347825833178847
// Day: 17 || illuminatedFraction: 0.763029581554865 || phaseQuarter: 3 
//         || phaseDaysBefore: undefined || phaseDaysAfter: 2.4411278010307518
// Day: 18 || illuminatedFraction: 0.8555981913616235 || phaseQuarter: 0 
//         || phaseDaysBefore: 3.3968086998851095 || phaseDaysAfter: undefined
// Day: 19 || illuminatedFraction: 0.9294546722062444 || phaseQuarter: 0 
//         || phaseDaysBefore: 2.324450568092969 || phaseDaysAfter: undefined
// Day: 20 || illuminatedFraction: 0.9786814411700813 || phaseQuarter: 0 
//         || phaseDaysBefore: 1.2622056903618648 || phaseDaysAfter: undefined
// Day: 21 || illuminatedFraction: 0.9994095420276781 || phaseQuarter: 0 
//         || phaseDaysBefore: 0.2067958496511151 || phaseDaysAfter: undefined
// Day: 22 || illuminatedFraction: 0.9906443297921943 || phaseQuarter: 0 
//         || phaseDaysBefore: undefined || phaseDaysAfter: 0.8464007357321963
// Day: 23 || illuminatedFraction: 0.9543665946579276 || phaseQuarter: 0 
//         || phaseDaysBefore: undefined || phaseDaysAfter: 1.9014688914148588
// Day: 24 || illuminatedFraction: 0.8948694419357917 || phaseQuarter: 0 
//         || phaseDaysBefore: undefined || phaseDaysAfter: 2.9602910307223924
// Day: 25 || illuminatedFraction: 0.8176725929146917 || phaseQuarter: 1 
//         || phaseDaysBefore: 3.139210557769397 || phaseDaysAfter: undefined
// Day: 26 || illuminatedFraction: 0.728477536842415 || phaseQuarter: 1 
//         || phaseDaysBefore: 2.196368545523418 || phaseDaysAfter: undefined
// Day: 27 || illuminatedFraction: 0.6324682679459483 || phaseQuarter: 1 
//         || phaseDaysBefore: 1.2544965074283883 || phaseDaysAfter: undefined
// Day: 28 || illuminatedFraction: 0.5340178279576334 || phaseQuarter: 1 
//         || phaseDaysBefore: 0.31305101838232047 || phaseDaysAfter: undefined
// Day: 29 || illuminatedFraction: 0.4367005906508668 || phaseQuarter: 1 
//         || phaseDaysBefore: undefined || phaseDaysAfter: 0.626845766795706
// Day: 30 || illuminatedFraction: 0.3434676777124016 || phaseQuarter: 1 
//         || phaseDaysBefore: undefined || phaseDaysAfter: 1.5632065731833897
// Day: 31 || illuminatedFraction: 0.2568689766546564 || phaseQuarter: 1 
//         || phaseDaysBefore: undefined || phaseDaysAfter: 2.493893981318598

As you can see, the phaseQuarter changes well before it hits the illuminatedFraction thresholds I'm expecting.

Am I misunderstanding the calculations? Is this intended or a bug?

Converting to php

Thanks for this great code. You likely saved me a bundle on Swiss Ephemeris. Hope it's still active.

To suit my needs tho, I'm working on porting it over to php. Here's my question.

PHP isn't known for it's floating point precision. I can pretty accurately get it to 10 decimal places, mostly accurate to 14. Will this be sufficient to get reasonably accurate results. I'm not expecting JPL Horizon accuracy.

Thanks.

possible typo's in code.

@mivion

Hi,

I found the following lines:

astronomy/moshier/deflection.js:1:$ns.deflectioon = {}; astronomy/moshier/deflection.js:3:$ns.deflectioon.calc = function (p, q, e, result) { astronomy/moshier/planet.js:102: body.position.deflection = $moshier.deflectioon.calc ( p, q, e ); // relativity astronomy/moshier/star.js:108: body.position.deflectioon = $moshier.deflectioon.calc ( p, p, e ); // relativity

I guess deflectioon should read deflection.
Worse might be line 108 in star.js: ( p, p, e ); if that should read ( p, q, e ); instead, as in line 102 of planet.js

Hope this helps improving the code.

Query on how to compute planetary angles

Hi, Is there any utility function available in this package that can help me compute the Heliocentric and Geocentric angles of a given planet on a given date.

Actually I have a time series stock price data and would like to overlay the planetary angles on every date as part of the Astro Trading package

In case, it is not possible, any direction or guidance to a npm package that addresses my requirement would be most appreciated.

Below is a picture of a software that computes the angles of the bodies based on date. I am assuming your package is my answer to create the below view. Now, I simply need a utility function that I can apply on every date of a timeseries dataset and compute the angles as given in the picture below

image

Stars data

Good evening,

I noticed the implementation of Sirius, and the results seem fair. Still, I haven't found the correct form for defining a star. Here's the code you have for Sirius:

	epoch: 2000,
	hmsRa: {hours: 6, minutes: 45, seconds: 8.871},
	hmsDec: {hours: -16, minutes: 42, seconds: 57.99},
	raMotion: -3.847,
	decMotion: -120.53,
	velocity: -7.6,
	parallax: 0.3751,
	magnitude: -1.46,
	ra: 0.0,
	dec: 0.0,
	equinox: {julian: 0.0}

The RA and Dec seem close from the Simbad database for the stars. But can you please tell me how did you reduced the proper motion? Simbad gives the values -546.01 -1223.07, and for the radial velocity -5.50.

Can you please advise?

Kind regards

CPtolemy

Here goes nothing... unconventional contact method, yes, but I REALLY want to discuss HD with you.

I read your medium articles "knocking on heavens door" yesterday and I've been thrust into a phase of doubt and investigation. Somehow I was able to find your github and it appears posting an issue might be the only way I can actually leave you a message. I really hope this works. lol.

I would love to discuss what you've found in the last 6 years. If you feel called you can email me at [email protected]

retrograde planets?

Hi

I was wondering: if we know the geocentric coordinates of the sun and one planet (longitude and distance) in one instant only, can we calculate/know mathematically if the planet is in retrograde motion or not? Or must we have 2 observations?

Clear skies

How to find ascendant?

Which data point is connected to the ascendant degree? I'm having trouble running my own calculations

e.load() has to run 3 times for proper calculations to be made.

I wanted to be able to calculate all of the planetary bodies on the first page load, and I had to clean up quite a bit of stuff in order to do that. The error that I see is "TypeError: date is undefined" on line 14 of epsilon.js. I see this on the initial page load and execution of the e.load(). I see it again when I click on the equal sign in order to populate the Body drop-down.

You can see how I cleaned up the load.js file here https://github.com/kentbye/ephemeris/blob/master/calculatedTime.js

I'm also mostly interested in the longitude, and was able to simplify things a bit more.

Thanks for the awesome start on this, and it so far has been pretty accurate!

Also, quick question. Do you know if the north node of the moon is being calculated anywhere?

twilight

Hi!
I find your library superb!
But I can't find 2 things:

  • How to calculate moon phase?
  • How to calculate the times for astronomical, nautical and civil dusk and dawn?
    Thanks

Compute separation angle of two objects (Sun, Moon) from location on Earth at time?

Hi,
I am looking at eclipse prediction and I'd like to compute the separation angle of two objections (Sun and Moon) from a location on Earth at a particular time. For example, in 2017 there will be a solar eclipse across North America, I would like to find the start and end time of the eclipse in, say, Corvallis OR, given that I know the eclipse will happen on Aug 21.

In Python using pyephem, I do this by computing the separation angle of the Sun and the Moon from a position on Earth for all the seconds in the day (example here: https://www.chromosphere.co.uk/2015/03/18/eclipse-calculations-using-python/)

     timetuple = (2017, 8, 21, 9+7, 00, 00)
     location = ephem.Observer()
     location.lon = '-123:15:43.4'
     location.lat = '44:33:52.4'
     location.date=timetuple

     location.date= (ephem.date(ephem.date(timetuple)+x*ephem.second))
     sun.compute(location)
     moon.compute(location)
     r_sun=sun.size/2
     r_moon=moon.size/2
     dt = location.date.datetime()
     dt2 = utc_to_local(dt)
     print dt2.strftime('%Y-%m-%d %H:%M:%S.%f %Z%z'), ephem.separation((sun.az, sun.alt), (moon.az, moon.alt))
     s=math.degrees(ephem.separation((sun.az, sun.alt), (moon.az, moon.alt)))*60*60

Note that the 'compute' routine is similar to calc but seems to allow you specify it to be relative to a body position (I wasn't sure how to achieve that with this library), and then call separation(), which is pretty simple to implement, here:
https://github.com/brandon-rhodes/pyephem/blob/026225ff566a858d6ef625c2bb2cb092ad20daa5/extensions/_libastro.c#L2598

Question

Quick question, does this library produce the same result as your swiss ephemeris implementation (https://github.com/mivion/swisseph) using the Moshiers flag ?

By way of explanation, I am currently using the following library:
https://github.com/0xStarcat/CircularNatalHoroscopeJS

Which uses another library:
https://github.com/xErik/ephemeris-moshier/

Which is supposedly JS module converted from THIS library.

Anyway, I am NOT getting consistency (very different results) with some of the records on Astro.com (for example, Napoleon or Neil Armstrong), however, when I use your https://github.com/mivion/swisseph library, the results are bang on, pretty much exactly within the expected accuracy as is 'written on the tin'.

So I have been trying to trace back where these errors are coming from, and whether I should migrate my code to your swisseph library, which will take quite a bit of effort to refactor my existing codebase in my current project.

Many Thanks

Best Practice for Importing/Exporting classes in Angular project

I've managed to open the files and experiment with making one page scripts on my own, but I'm having trouble coming up with a solution to organizing the ephemeris files in a way in which I can easily import and export classes for use in an Angular 2 dynamic webapp. I could use some help being pointed in the right direction if anyone has knowledge of working with this data in an Angular based webapp.

local Apparent Sidereal Time Incorrect

In Meuss (2nd ed) Chapter 15, there is an example of rise/transit/set for Venus in Boston, MA. The test case below, with Meuss inputs is used to generate the local apparent sidereal time:

``
$processor.init();

$const.tlong = +71.0833;

$const.tlat = +42.3333;

$const.glat = +42.3333;

$const.height = 43.0;

$const.date = { day:20, month:3, year:1988, hours:0, minutes:0, seconds:0 };

$processor.calc($const.date,$moshier.body.venus);

last = $util.hms($moshier.body.venus.position.altaz.dLocalApparentSiderialTime);
``
From the above, last = 16h35m18s whereas Meuss calculates THETA0 = 11h50m58.1s (Meuss and the Astronomical Almanac 1988 agree.)

In addition, the following values in transit.js are not computed correctly:

``

$moshier.body.venus.position.altaz.transit.approxRiseUT = 26h56m22s (Moshier: 12h25m)

$moshier.body.venus.position.altaz.transit.approxLocalMeridian = 34h10m48s (Moshier: 19h41m)

$moshier.body.venus.position.altaz.transit.approxSetUT = 41h:26m13s (Moshier: 02h55m)

``

Geocentric distance equal to -1?...

Hi,

I've just tested your code and noticed that apart from the moon the planet geocentric distances are always equal to -1.

Can you please tell me where the bug might be?

Kind regards,

CPtolemy

Code for calculating "exact" sunrise/sunset

Hello

this little snippet of code was implemented from, if i remember, wikipedia.
It assumes longitude/latitude is stored in lon/lat variables.
The results are not "exact" to the minute, but approximately so. Better than the moshier calculations tho.


datesr = {
	year: 2000,
	month: 1,
	day: 1),
	hours: 12,
	minutes: 0,
	seconds: 0.0
};

nj = datesr.julian - 2451545.0;
Jst = nj - (lon/360.0);
Mas = (357.5291 + (0.98560028*Jst)) % 360.0;
Cen = 1.9148*Math.sin(Mas*$const.DTR) + 0.02*Math.sin(2*Mas*$const.DTR) + 0.0003*Math.sin(3*Mas*$const.DTR);
lamda = (Mas + Cen + 180 + 102.9372) % 360.0;
Jtra = 2451545.0 + Jst + 0.0053*Math.sin(Mas*$const.DTR) - 0.0069*Math.sin(2*lamda*$const.DTR);
sindelta = Math.sin(lamda*$const.DTR) * Math.sin(23.44*$const.DTR);
deltainv = Math.asin(sindelta);
elevel = -1.15*Math.sqrt(60)/60;
cosw = ((Math.sin((elevel-0.83)*$const.DTR) - Math.sin(lat*$const.DTR)*sindelta)/(Math.cos(lat*$const.DTR)*Math.cos(deltainv)));
wo = Math.acos(cosw)*$const.RTD;
Jsunrise = Jtra - wo/360;
Jsunset = Jtra + wo/360;
sunr = { year:0, month:0, day:0, hours:0, minutes:0, seconds:0 };
suns = { year:0, month:0, day:0, hours:0, minutes:0, seconds:0 };
$copy(sunr , d);
$copy(suns , d);
sunr.universalDate = $moshier.julian.toGregorian ({ julian: Jsunrise + ((tz*3600.0)/86400.0) });
suns.universalDate = $moshier.julian.toGregorian ({ julian: Jsunset  + ((tz*3600.0)/86400.0)});
sunriset = (sunr.universalDate.hours % 12) + ":" + ("00"+sunr.universalDate.minutes).substr(-2) + " AM";
sunsett =  (suns.universalDate.hours % 12) + ":" + ("00"+suns.universalDate.minutes).substr(-2) + " PM";

Maybe a little bug in siderial.js

Hi,
first of all thanks for your valuable work.

Maybe, I think I found a little bug.

In file siderial.js

Original lines:
jd = date.universal; // UT
jd0 = Math.floor(jd);
secs = date.universal - jd0; // UT

I modified the code in:
jd = date.julian; // UT
jd0 = Math.floor(jd);
secs = date.julian - jd0; // UT

With this change, I get the expected result.

Thanks again,
blu

Wrong values in years B.C.

Hi,
using dates before the year zero the values are wrong.

From ephemeris index.html
Gregorian: 29.9.-2015 14:15:40
Julian: 985754.094212963
Sun - Apparent Longitude (dd): 186.12039963898445

From Moshier aa.exe
Gregorian: 29.9.-2015 14:15:40
Julian: 985716.09
Sun - Apparent Longitude (dd): 169.0666

I think it is wrong to calculate the Julian date.

Thanks a lot,
blu

Calculating Eclipses

I believe the ephemeris produces enough information to do the calculation. What I have figured out so far is the following:
For the Lunar eclipses, it comes down to finding how close the full moon is to either of the nodes.

Ephemeris.moon.orbit .meanAscendingNode.apparentLongitude
Ephemeris.moon.orbit .meanDescendingNode.apparentLongitude

and comparing it to

Ephemeris.moon.position.apparentGeocentric.longitude

Would this be correct, and if so, is there a function / method (orbs?) to do this? Within how many degrees between the moon and it's nodes does a lunar eclipse occur?

With regards to a solar eclipses

when the new moon is close to one of the nodes and only when the Sun is within about 15 to 18 degrees of a node, (10 to 12 degrees for central eclipses).

Total - Moon is near its closest distance to Earth (i.e., near its perigee)

Annular - Moon is near its farthest distance from Earth (i.e., near its apogee)

Suggestions or references would be greatly welcome.

Longitude speed

Cool script! Seeking a way to use it instead of swisseph for some simple calculations. Any ideas on how to add longitude speed and topocentric longitude(ecliptic) positions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.