moon visibility for start and end

This commit is contained in:
Ali Camarata 2023-12-01 16:41:57 +07:00
parent 2d266214fa
commit aaf15ee624
3 changed files with 29 additions and 9 deletions

View file

@ -23,3 +23,6 @@ All notable changes to this project will be documented in this file.
- Renamed to "pray-calc" and removed old package
- Improved Synodic accuracy slightly and lastKnownMoon
## [1.4.1] = 2013-12-01
- Modified getMoonVisibility to use adjusted moon phase for end of cycle

View file

@ -12,7 +12,7 @@
* @returns {Object} An object containing moon details: phase, position, illumination, and visibility.
*/
function getMoonVisibility(phase, position, illumination, elevation = 50, temp = 15, pressure = 1013.25, humidity = 50, clouds = 0) {
function getMoonVisibility(phase, position = 0, illumination = 0, elevation = 50, temp = 15, pressure = 1013.25, humidity = 50, clouds = 0) {
/** Placeholder Simplified Algorithm...
* This is a very simplified algorithm that is not intended to be precise or accurate.
@ -20,20 +20,37 @@ function getMoonVisibility(phase, position, illumination, elevation = 50, temp =
* Using a window of earliest general visibility until near definite visibility is reached.
*/
// Convert Phase from 0-1 to be 0 (full moon) to 0.5 (new moon) scale
const aphase = (phase - 0.5) < 0 ? -(phase - 0.5) : (phase - 0.5);
// Get synodic month and phase hour for adjustic moon phase
const sMonth = 29.530588861;
const phaseHour = 1 / 24 / sMonth; // ~ 0.001410966333
const startVis = phaseHour * 15; // ~ 0.02116449584
const endofVis = phaseHour * 30; // ~ 0.04232899168
const visWindow = endofVis - startVis;
const phaseHour = 1 / 24 / sMonth; // ~ 0.001410966333
const ahour = phaseHour / 2; // ~ 0.0007054831663
// Get estimated visibility window of a new moon (and ending)
const v1 = ahour * 15; // ~ 0.01058224749
const v2 = ahour * 30; // ~ 0.02116449499
const w1 = 0.5 - v1; // ~ 0.48941775251
const w2 = 0.5 - v2; // ~ 0.47883550501
const win = w1 - w2; // ~ 0.01058224749
let visibility = 0;
if (phase > endofVis) {
if (aphase < w2) {
visibility = 1;
} else if (phase > startVis) {
visibility = (phase - startVis) / visWindow;
} else if (aphase < w1) {
visibility = (w1 - aphase) / win;
}
return visibility;
}
module.exports = { getMoonVisibility };
/* console.log(getMoonVisibility(0.010));
console.log(getMoonVisibility(0.012));
console.log(getMoonVisibility(0.014));
console.log(getMoonVisibility(0.016));
console.log(getMoonVisibility(0.018));
console.log(getMoonVisibility(0.020));
console.log(getMoonVisibility(0.022)); */

View file

@ -1,6 +1,6 @@
{
"name": "pray-calc",
"version": "1.4.0",
"version": "1.4.1",
"description": "Prayer times calculator using nrel-spa and custom formula for Fajr and Isha angles (as well as traditional static angle methods in the All function)",
"main": "index.js",
"scripts": {