From aaf15ee62452a524b23f102c2a776a38c76e8678 Mon Sep 17 00:00:00 2001 From: Ali Camarata Date: Fri, 1 Dec 2023 16:41:57 +0700 Subject: [PATCH] moon visibility for start and end --- CHANGELOG.md | 3 +++ getMoonVisibility.js | 33 +++++++++++++++++++++++++-------- package.json | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29bb190..86547b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/getMoonVisibility.js b/getMoonVisibility.js index 2e67f27..e595f24 100644 --- a/getMoonVisibility.js +++ b/getMoonVisibility.js @@ -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)); */ diff --git a/package.json b/package.json index 6fa6d78..aac0627 100644 --- a/package.json +++ b/package.json @@ -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": {