Giter VIP home page Giter VIP logo

lune's Introduction

Lune Build Status

Lune.js — calculate the phases of the moon.

Installation

npm install lune

Usage

To calculate current phase information:

var lune = require('lune')
var current_phase = lune.phase()
console.log(current_phase)

Output:

{ phase: 0.3435664924086369,
  illuminated: 0.7773055846628978,
  age: 10.1457207715498,
  distance: 386679.7626047325,
  angular_diameter: 0.5150467579643708,
  sun_distance: 148929846.0148686,
  sun_angular_diameter: 0.5354732715700135 }

To calculate phase information for a specific date:

var lune = require('lune')
var some_date = new Date('2014-02-17T00:00-0500')
var some_date_phase = lune.phase(some_date)
console.log(some_date_phase)

Output:

{ phase: 0.568204641580006,
  illuminated: 0.9547862069882863,
  age: 16.779417556565985,
  distance: 396084.54752883443,
  angular_diameter: 0.5028172882344054,
  sun_distance: 147822484.14817196,
  sun_angular_diameter: 0.5394845874736046 }

To search for recent phases around the current date:

var lune = require('lune')
var recent_phases = lune.phase_hunt()
console.log(recent_phases)

Output:

{ new_date: Tue Mar 08 2016 20:55:59 GMT-0500 (EST),
  q1_date: Tue Mar 15 2016 13:04:23 GMT-0400 (EDT),
  full_date: Wed Mar 23 2016 08:01:38 GMT-0400 (EDT),
  q3_date: Thu Mar 31 2016 11:18:41 GMT-0400 (EDT),
  nextnew_date: Thu Apr 07 2016 07:25:20 GMT-0400 (EDT) }

To search for recent phases around a specific date:

var lune = require('lune')
var some_date = new Date('2014-02-17T00:00-0500')
var some_date_phase = lune.phase_hunt(some_date)
console.log(some_date_phase)

Output:

{ new_date: Thu Jan 30 2014 16:40:35 GMT-0500 (EST),
  q1_date: Thu Feb 06 2014 14:22:33 GMT-0500 (EST),
  full_date: Fri Feb 14 2014 18:54:46 GMT-0500 (EST),
  q3_date: Sat Feb 22 2014 12:16:56 GMT-0500 (EST),
  nextnew_date: Sat Mar 01 2014 03:02:41 GMT-0500 (EST) }

To search for phases between two dates:

// print all full moons in the first quarter of 2014
var lune = require('lune')
var phase_list = lune.phase_range(
  new Date('2014-01-01T00:00:00.000Z'),
  new Date('2014-03-31T23:59:59.999Z'),
  lune.PHASE_FULL
)
console.log(phase_list)

Possible values for the third argument of the function are:

  • lune.PHASE_NEW (new moon)
  • lune.PHASE_FIRST (first quarter moon)
  • lune.PHASE_FULL (full moon)
  • lune.PHASE_LAST (third or last quarter moon)

Output:

[ Wed Jan 01 2014 06:15:02 GMT-0500 (EST),
  Thu Jan 30 2014 16:40:35 GMT-0500 (EST),
  Sat Mar 01 2014 03:02:41 GMT-0500 (EST),
  Sun Mar 30 2014 14:48:06 GMT-0400 (EDT) ]

Image

Moon image graciously provided by Mike DiLuigi.

Contributing

Please feel free to contribute to this project! :) Pull requests and feature requests welcome!

License

See LICENSE file in this repo

lune's People

Contributors

algesten avatar firelemons avatar jalbertogonzalez avatar ryanseys 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

lune's Issues

Optimization Questions

I recently purchased a copy of Astronomical Algorithms, 2nd ed. and was interested in implementing some of their approximation algorithms.

This is for two reasons: first, they're much faster, and second, they're much simpler. This can help with cases where high performance (e.g. getting a large number of lunar dates—which is my use-case 😉) is important, but mostly it's a benefit to maintainability.

I had two questions regarding this before I pass along a PR:

  1. What kind of accuracy guarantees does this library try to make? (If "none", then I should note my changes to phase() bring the amount of error in the moon phase from from 0.024% to 0.039%. The tests themselves check for an error of 0.1%, so we remain well below that threshold.)

  2. I'm seeing some issues in the tests, in particular these lines: https://github.com/ryanseys/lune/blame/9ffb65d76e9ed2c4334531601086edf516a8648e/test/index.js#L13-L14

    I can't tell whether the test is bad, or if my new calculations are, but I can't get the two to agree. I have checked and re-checked my code, though, and it seems to agree very well with all the other tests I can throw at it, so I suspect this test might be bad.

    Do you happen to remember where you got the data you're comparing against?

Calculate moon ecliptic longitude

Hello, you've got a great project here in that it tells me when the moon will enter a new phase; really awesome, exactly what I need. I'm also looking for the same type of functionality, but for the longitude of the ecliptic (which I would use for calculating the zodiac sign that the moon will be in at that point). Any thoughts on how this could be added? I would be happy to write the software to do this, but I have zero knowledge of the math which would be behind it. Thank you 🙏

angle or rotation ?

I'm guessing the illuminated value is the actual lit surface of the moon ( compared to the values at https://www.timeanddate.com/astronomy/moon ) , but what is the phase for ? Trying to figure out if this lib supports finding out rotation of the shadow that earth is casting on the moon given the current long and lat

New Feature: phase_range function

I want a function that, given a start date, and end date, and a desired phase (one of new, q1, full, q3), returns a list of all dates between the given two on which the desired phase occurs.

For example,

// print all full moons that occurred in the year 2000
console.log(lune.phase_range(
  new Date('2000-01-01T00:00:00.000Z'),
  new Date('2000-12-31T23:59:59.999Z'),
  'full'
))

Naturally, I've already written the code and tests for this (it uses all of the existing machinery in lune and is accurate to within 90s or so) and will issue a pull request once the other pull requests have been merged in.

Moon phase: What value range approximates "full moon"?

First, thank you for sharing this. AWESOME! I plan to share the little app I'm making that makes heavy use of this one as well.

My app will speak to the current phase of the moon approximately. It's approximate as I won't be able to know the user's timezone for now. With that in mind, what phase value range would approximate "full moon"?

If I have a phase value of 0.5 being a full moon and a lunar cycle of 29.5 days, I'm thinking:
0.5 +/- (1.0/29.5)
or:
0.4666 - 0.5334

Does that seem right? Am I in dangerous waters by not knowing the timezone of the app user?

Thanks for taking a look as I wrap my brain around this!

bug: phase_hunt seeks phases in the past, no guarantee that next new moon is in the future

While testing across multiple dates, I ran into this issue where the phases were in the previous month, including the next new moon. The bug is that the provided date is outside of the interval ranging from the previous new moon to the next new moon.

It can be replicated by trying the date July 6th, 2024, (2024-07-06):

const lune = require('lune');
const luxon = require('luxon');
const datetime = luxon.DateTime.fromISO("2024-07-06", { zone: "UTC" });
const jsdate = datetime.toJSDate();
lune.phase_hunt(jsdate);

The output is here, you can see the dates are in June 2024 rather than in July 2024:
Screenshot 2024-03-09 at 7 43 10 PM

And when I try the next day over, 2024-07-07, it shows the phases in July 2024:

Screenshot 2024-03-09 at 7 45 01 PM

To work around this issue, in my code I added a conditional to check if the next new moon is before the provided date and if it is, to run the phase hunt 1 day in the future:

// my codebase is using Luxon
if (phases.nextnew_date.getTime() < date.getTime()) {
  const futureDate = DateTime.fromJSDate(date).plus(Duration.fromObject({ days: 1 })).toJSDate();
  phases = lune.phase_hunt(futureDate);
}

// without Luxon
if (phases.nextnew_date.getTime() < date.getTime()) {
  const futureDate = new Date(date.getTime() + (1000 * 60 * 60 * 24));
  phases = lune.phase_hunt(futureDate);
}

How the calculation works?

Good Work! Congratulations! 😃

I need to make this same calculation in a Android App. You can explain me how this calculation works? I want to understand what is the theory from behind your code...

Julian dates don't care about timezone offsets?

https://github.com/ryanseys/lune/blob/master/lib/lune.js#L27

This strikes me as wrong. Date.prototype.valueOf is an alias to Date.prototype.getDate, which returns the number of milliseconds (ignoring leap seconds!) since 1 Jan 1970 UTC. This means that it's timezone offset is defined as zero: adding in my local timezone offset is mixing and matching values from two different timezones, which is asking for trouble: it will only work if your local timezone offset happens to be zero!

For comparison:

As such, I believe this is a bug. (Also, javascript.about.com isn't a very reputable source 👎 )

Wrong timezone?

So. I'm looking at the phase_hunt() output.

{ new_date: Thu Oct 23 2014 21:56:14 GMT+0530 (IST),
  q1_date: Fri Oct 31 2014 02:48:57 GMT+0530 (IST),
  full_date: Thu Nov 06 2014 22:22:57 GMT+0530 (IST),
  q3_date: Fri Nov 14 2014 15:17:56 GMT+0530 (IST),
  nextnew_date: Sat Nov 22 2014 12:32:04 GMT+0530 (IST) }

Today I'm on IST (India) time, and I think the output is incorrect. full_date shows Thu Nov 06 2014 22:22:57, which I believe is it correct time, but not in GMT+0530. I corroborate that with NASA's tables which say Nov 6 22:23, however those tables are in UTC. Likewise, NASA says Nov 22 12:32 for next new moon.

Moon Trajectory

Hi, awesome job here! Do you know how moon trajectory can be calculated? I've reading about biodinamic gardening and they say that the trajectory of the moon (ascending or descending) is quite important for gardening...

Replace 'var' with 'let' and 'const'.

Creating this issue per prior discussion with @ryanseys; Lune is currently built to work with Node 0.10, but this restricts us to using ugly old var. For reasons of maintenance sanity, let's bring Lune up to date to work with the current LTS and Stable versions of Node, and make use of let and const while we're at it.

While I'm at it, any problems with my bringing in JSHint as a dev dependency and enabling some basic style checks?

To draw moon shadow

Hi.
How can I calculate the shadow of the moon.
How do I apply the shadow over an image of the moon.
Based on which properties can I calculate this?

Thank you

I can't integrate your wonderful library into my react native

Hello
I can't integrate your wonderful library into my react native project
I'm getting an error

error

error: bundling failed: Error: Unable to resolve module lune from D:\projeckts\compass-react-native-non-expo-master\src\Compass.js: Module lune does not exist in the Haste module map

This might be related to facebook/react-native#4968
To resolve try the following:

  1. Clear watchman watches: watchman watch-del-all.
  2. Delete the node_modules folder: rm -rf node_modules && npm install.
  3. Reset Metro Bundler cache: rm -rf /tmp/metro-bundler-cache-* or npm start -- --reset-cache.
  4. Remove haste cache: rm -rf /tmp/haste-map-react-native-packager-*.
    at ModuleResolver.resolveDependency (D:\projeckts\compass-react-native-non-expo-master\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:183:15)
    at ResolutionRequest.resolveDependency (D:\projeckts\compass-react-native-non-expo-master\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (D:\projeckts\compass-react-native-non-expo-master\node_modules\metro\src\node-haste\DependencyGraph.js:283:16)
    at Object.resolve (D:\projeckts\compass-react-native-non-expo-master\node_modules\metro\src\lib\transformHelpers.js:264:42)
    at dependencies.map.result (D:\projeckts\compass-react-native-non-expo-master\node_modules\metro\src\DeltaBundler\traverseDependencies.js:399:31)
    at Array.map ()
    at resolveDependencies (D:\projeckts\compass-react-native-non-expo-master\node_modules\metro\src\DeltaBundler\traverseDependencies.js:396:18)
    at D:\projeckts\compass-react-native-non-expo-master\node_modules\metro\src\DeltaBundler\traverseDependencies.js:269:33
    at Generator.next ()
    at asyncGeneratorStep (D:\projeckts\compass-react-native-non-expo-master\node_modules\metro\src\DeltaBundler\traverseDependencies.js:87:24)
    DELTA [android, dev] ./index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.

package.json

{
"name": "CompassReactNative",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"luna": "^1.6.3",
"react": "16.8.6",
"react-native": "0.60.5",
"react-native-easy-grid": "^0.2.1",
"react-native-sensors": "^5.3.0",
"suncalc": "^1.8.0"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/runtime": "^7.5.5",
"babel-jest": "^24.8.0",
"jest": "^24.8.0",
"metro-react-native-babel-preset": "^0.55.0",
"react-test-renderer": "16.8.6"
},
"jest": {
"preset": "react-native"
}
}

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.