It is currently September 21st, 2020, 12:19 pm

Moon and Sun data

General topics related to Rainmeter.
User avatar
jsmorley
Developer
Posts: 21374
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Moon and Sun data

Post by jsmorley »

While I don't think I'm going to parse through this much data for the .inc files I provide to parse weather.com JSON API data, someone else might be interested in this information for a skin they would like to write:

https://api.weather.com/v2/astro?apiKey=6532d6454b8aa370768e63d6ba5a832e&geocode=37.26%2C-122.03&days=3&date=20200803&format=json

Format the &days parameter for the number of days worth you want, and the &date parameter as YYYYMMDD for the current date.

There is certainly a boatload of data...


1.jpg


Aside from the Moon stuff, that I honestly don't care about, it might be fun to use the difference between "dawn" and "sunrise" in some way. Have a skin that slowly brightens up starting at dawn and being fully bright at sunrise.
You do not have the required permissions to view the files attached to this post.
User avatar
SilverAzide
Posts: 954
Joined: March 23rd, 2015, 5:26 pm

Re: Moon and Sun data

Post by SilverAzide »

jsmorley wrote: August 3rd, 2020, 2:55 pmAside from the Moon stuff, that I honestly don't care about, it might be fun to use the difference between "dawn" and "sunrise" in some way. Have a skin that slowly brightens up starting at dawn and being fully bright at sunrise.
Whoa! Nice find! I think someone in another thread recently was trying to create a clock skin that did just that. It's certainly a lot simpler to use this API than trying to implement some gnarly Lua functions to calculate all this stuff.
Gadgets Wiki GitHub More Gadgets...
User avatar
jsmorley
Developer
Posts: 21374
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Moon and Sun data

Post by jsmorley »

SilverAzide wrote: August 3rd, 2020, 3:46 pm Whoa! Nice find! I think someone in another thread recently was trying to create a clock skin that did just that. It's certainly a lot simpler to use this API than trying to implement some gnarly Lua functions to calculate all this stuff.
Yeah, might be fun. You can know the time of dawn (or dusk) and the time of sunrise (or sunset), and then calculate the difference in seconds to create a percentage-based effect of some kind.
User avatar
Yincognito
Posts: 2565
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Moon and Sun data

Post by Yincognito »

jsmorley wrote: August 3rd, 2020, 3:49 pm Yeah, might be fun. You can know the time of dawn (or dusk) and the time of sunrise (or sunset), and then calculate the difference in seconds to create a percentage-based effect of some kind.
Indeed - nice stuff. That's precisely what I attempted to do in my first (but unreleased) skin suite, Yinmeter. :D Given up on trying that (I wanted to replicate the exact luminosity and appearance of the sky for the current location and basically draw a 3 layer, i.e. sky, celestial body and weather image in my weather skin) when the poles and those skewed values near the Polar Circles complicated the math to an unreasonable level. Good to know though. ;-)
User avatar
balala
Rainmeter Sage
Posts: 11372
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Moon and Sun data

Post by balala »

Most (or all) of those information can be calculated locally, without getting them online. If anyone is interested, let me know.
User avatar
raiguard
Posts: 667
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: Moon and Sun data

Post by raiguard »

In case anyone is interested, I managed to cobble together a small file to get the moon's current exact illumination value. This is a range from 0 to 100.

This depends on WeatherComJSONVariables.inc and any variant of WeatherComJSONMeasures.inc

Code: Select all

; This is NOT part of the WeatherCom includes, this is a custom file. This depends on WeatherComJSONVariables.inc and any variant of WeatherComJSONMeasures to be loaded first

[Variables]
AstroApiKey=6532d6454b8aa370768e63d6ba5a832e

[@AstroTimestamp]
Measure=Time
Group=Times
Disabled=1
TimeStamp=[@CurrentObservationTimeStamp]
TimeStampFormat=%Y-%m-%dT%H:%M:%S
Format=%Y%m%d
DynamicVariables=1

[@AstroSuperParent]
Measure=WebParser
URL=https://api.weather.com/v2/astro?apiKey=#AstroApiKey#&geocode=#Latitude#%2C#Longitude#&days=1&date=[&@AstroTimestamp]&format=json
UpdateRate=#UpdateRate#
Flags=Resync | NoCookies
UserAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
DecodeCharacterReference=1
LogSubstringErrors=0
RegExp=(?siU)^(.*)$
StringIndex=1
DynamicVariables=1
FinishAction=[!EnableMeasureGroup Astro][!Update]
Group=Times
Disabled=1

[@AstroMoonRiseSetParent]
Measure=WebParser
URL=[@AstroSuperParent]
RegExp=(?siU)"percentIlluminated":(.*),
StringIndex=1
Group=Astro
Disabled=1

[@AstroMoonPercentIlluminated]
Measure=WebParser
URL=[@AstroMoonRiseSetParent]
StringIndex=1
Group=Astro
Disabled=1
2020-08-12 15_27_43-Rainmeter Forums - Post a reply.png
You do not have the required permissions to view the files attached to this post.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
Yincognito
Posts: 2565
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Moon and Sun data

Post by Yincognito »

Just for reference, the locally calculated / aproximated values...

Moon Illumination Side Formula: ([MoonAgeInDays]<=15?Sgn([Latitude]):-Sgn([Latitude])) (-1=Left, 1=Right, 0=Bottom)
Moon Illumination % Approximation: Ceil(50+(Sin((([MoonAgeInDays]/29)*2*PI)-(PI/2))*50)) (Error margin: ±3%)

MoonAgeInDays = "moonPhaseDay" in the API JSON.
User avatar
balala
Rainmeter Sage
Posts: 11372
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Moon and Sun data

Post by balala »

raiguard wrote: August 12th, 2020, 9:28 pm In case anyone is interested, I managed to cobble together a small file to get the moon's current exact illumination value. This is a range from 0 to 100.
In my SunMoon skin of my Mirage suite, this calculation is done locally, without downloading the information from internet.
User avatar
raiguard
Posts: 667
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: Moon and Sun data

Post by raiguard »

balala wrote: August 13th, 2020, 3:44 pm In my SunMoon skin of my Mirage suite, this calculation is done locally, without downloading the information from internet.
IIRC you're using the SunCalc script that you got from me, which has proven to be wildly inaccurate in several locations. I would recommend against using it.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
balala
Rainmeter Sage
Posts: 11372
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Moon and Sun data

Post by balala »

raiguard wrote: August 13th, 2020, 4:45 pm IIRC you're using the SunCalc script that you got from me, which has proven to be wildly inaccurate in several locations. I would recommend against using it.
SunCalc does just a part of the calculations. Two other .lua script files are present as well: Sun.lua (for calculations related to Sun) and Moon.lua (supposing it's obvious: for calculations related to the Moon). SunCalc calculates the Moon phase, while all other calculations are made by Moon.lua.
Althought I widly tested the script in the past, everything seemed very fine: had no inadvertances. There might be something I didn't take into account, however as far as I can tell, it works very well.
I downloaded your .lua script file long time ago and couldn't say anymore who the author is. Now I see your signature into the file, but since I didn't look for it, I simply missed the author. Even if you're not entirely satisfied with it, I consider it being an excelent piece of software, so congratulations for it. It does perfectly works for me. Don't recommend against it.
Many thanks for this script. :great: