It is currently January 29th, 2023, 8:12 pm

Sunrise-Moonset

Weather skins
User avatar
Mordasius
Posts: 1099
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Sunrise-Moonset

Post by Mordasius »

This is something I started a while ago using regular Calc measures. The Calc measures got messy when trying to accommodate higher latitudes with no sunrise or sunset during certain months. It's much easier using a Lua script but the site I'm scraping misses days at the end of some months like March 2013. I've added quick fixes for March and May 2013 but I'm going to have to find a more permanent solution. I was sent some javascript stuff to calculate moonrise and moonset but I've been too lazy to convert it to Lua. Does anyone out there happen to have Lua script to calculate moonrise and moonset?
sun-moon.png
Download from Deviant Art
You do not have the required permissions to view the files attached to this post.
Last edited by Mordasius on August 17th, 2022, 2:17 am, edited 2 times in total.
Stone
Posts: 25
Joined: March 12th, 2013, 8:51 am
Location: Copenhagen / Denmark

Re: Sunrise-Moonset

Post by Stone »

Hello Mordasius...

Here is a Lua-file that calculates Moonrise/set...
Moon.zip
I have converted it from C-source 'moon.c', which is also included in the attached zip-file.
'moon.c' is a conversion from Java (originally written by Stephen R. Schmitt)
- Perphaps it's that Javascript you already have...

The zip-file contains a directory (\moon) containing three files: 'moon.c', 'moon.lua' and
'moon.ini'.

You can set the variables _TimeZone, Latitude & Longitude in 'moon.ini' to see if the
whole thing works.

Yesterday I added a 'math.floor(...)' i had missed in the translation-process (it caused an
error of about 20 minutes on the rise/set-times), but now it should work (i tested it
for March month using the US-Naval data, and it looked fine).

- Hope you can use it, and hope to see more of your Steam Punk stuff in the future.

- Stone
You do not have the required permissions to view the files attached to this post.
- Stone
User avatar
Mordasius
Posts: 1099
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Sunrise-Moonset

Post by Mordasius »

Many, many thanks for this. Your Lua script gets the moonrise and moonset times in a fraction of the time taken to access and read values from http://www.moonsigncalendar.net and, more importantly, it will work for any day of the year.

Your translation from C- seems to originate from the same Javascript source as the one I have as the variable names and comments are pretty much the same. The version I have is 'Calculate Moonrise and Moonset' - version 2.2 © 2006-2012 Harry Whitfield (attached below in case anyone is interested).

Anyway, I can now combine your Lua script along with stuff I had to calculate sunrise, sunset and twilight hours in my Islamic Prayer Times skin to make the Sunrise-Moonset skin work without the need for scraping anything from the moonsigncalendar.net pages.

Thanks again.
You do not have the required permissions to view the files attached to this post.
User avatar
Mordasius
Posts: 1099
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Sunrise-Moonset

Post by Mordasius »

Given that there were already problems with some of the months with 31 days and that benjam has recently told us that the iohelix moon feed may be going down [link] I've put this skin into storage until I can get all the sun and moon data calculated rather than scraped from web sites.

Stone's Lua script calculates the moonrise and moonset times accurately but I was using http://iohelix.net to provide information on the percentage illumination and days to the next phase of the moon.

I'll bring the skin out of storage once I've had time to work on the Lua scripts.
User avatar
Mordasius
Posts: 1099
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Sunrise-Moonset

Post by Mordasius »

Improved version using a lua script to get the sunrise, sunset, moonrise, moonset and civil twilight times is now available. Get it from the link in the first post or here .

Thanks again to Stone for providing the lua script to calculate the times for moonrise and moonset.

UPDATE - I've also added a clock which you can toggle on/off by clicking on the panel which shows 'Twilight' in the screenshot.
User avatar
balala
Rainmeter Sage
Posts: 14928
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Sunrise-Moonset

Post by balala »

Hello,

Well, I realy modified the skin, but right now I just downloaded again the skin and here a systemdate-change updates the skin. It's strange, because I haven't modified the 'Update=60000', in fact I haven't modified anything. What operating system are you using (mine is Win 7 Ultimate SP1)?
I attach my skin and lua scripts. The Moon.lua is your script, I just added the else sections in if Moonrise > 0 and if Moonset > 0, in riseset function, because without this, if at a certain day the moon hasn't rise or set, the time remains the same as previous day's data and only the changed value is updated. The Sun.lua is my script, but I'm still working on it, this is just a preliminary version, which works well, but must be treated keeping this in mind.
Also, I didn't forget the 'DynamicVariables=1', so it's not the cause. In fact, this afternoon I found a way to resolve the problem: in the Update() section in Lua script, I added a
if Old ~= New then

Old = New
end
part (as it is described in http://docs.rainmeter.net/snippets/detect-value-change), which helped.
But I still can't understand, if you have used 'Update=60000' in your skin, why this skin updates every 60 seconds? (I hope didn't asked a big crap, I just started to learn Lua, and haven't great experience).

Stone wrote:Hello Mordasius...

Here is a Lua-file that calculates Moonrise/set...
Moon.zip
I have converted it from C-source 'moon.c', which is also included in the attached zip-file.
'moon.c' is a conversion from Java (originally written by Stephen R. Schmitt)
- Perphaps it's that Javascript you already have...

The zip-file contains a directory (\moon) containing three files: 'moon.c', 'moon.lua' and
'moon.ini'.

You can set the variables _TimeZone, Latitude & Longitude in 'moon.ini' to see if the
whole thing works.

Yesterday I added a 'math.floor(...)' i had missed in the translation-process (it caused an
error of about 20 minutes on the rise/set-times), but now it should work (i tested it
for March month using the US-Naval data, and it looked fine).

- Hope you can use it, and hope to see more of your Steam Punk stuff in the future.

- Stone
You do not have the required permissions to view the files attached to this post.
User avatar
Mordasius
Posts: 1099
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Sunrise-Moonset

Post by Mordasius »

You've certainly taken a different approach to calculating the times for sunrise and sunset. It must have taken hours to type in and then check all those lines of if day == 6 then MELS = 344.155 end and if LastTwoDigits == 17 then Correct = Correct-0.128 end.

However, there does seem to be a little something amiss somewhere as sun.lua produces times a few minutes different from those calculated on http://www.timeanddate.com/worldclock/sunrise.html or http://aa.usno.navy.mil/data/docs/RS_OneDay.php.
balala wrote:But I still can't understand, if you have used 'Update=60000' in your skin, why this skin updates every 60 seconds?
I don't know, but I suspect Stone may have just had 'Update=60000' in there for testing. In my version, I have UpdateDivider=-1 on the script measure so that the times are only calculated once when the skin loads.

Code: Select all

[mLuaSunMoonTimes]
Measure=SCRIPT
ScriptFile=SunMoonTimes.lua
UpdateDivider=-1
I then use the Detect Value Change snippet to update the measure when the day changes.

Code: Select all

-- check to see if the day has changed
	local TodayTimes = tonumber(SKIN:GetVariable('todaysday'))
		if OldTimes ~= TodayTimes then
			 SKIN:Bang("!UpdateMeasure mLuaSunMoonTimes") 
			OldTimes = TodayTimes
		end
Stone
Posts: 25
Joined: March 12th, 2013, 8:51 am
Location: Copenhagen / Denmark

Re: Sunrise-Moonset

Post by Stone »

- Sorry! I simply forgot the Update=60000 when extracting the Moon rise & set functions for Mordasius' Sunrise Moonset machinery; It is of course not neccessary to recalculate rise/set 60x24=1440 times each day. I have (in the attached Moon II.zip) used the above update-snippet, so recalculation of rise/set only happens when the skin loads, or if the day changes (or up to 2 minutes after since Update is now 120000). The Update=60000 was originally there because i found some code (in John Walkers Moontool) to calculate distance, illumination and some other stuff, and that needs to be updated pretty often. I have checked the calculated values against the Iohelix data in Mordasius' Sunrise-Moonset machine, and that seems to match fine. I have also corrected the error balala found (if the moon rises on day N, and doesn't on day N+1, then moonrise showed the risetime for day N on day N+1 - and the same with settime).
Note: The moonphase is implemented after the description in Wikipedia (<1% illumination is a New Moon, and so on). This means that the skin may show 'New Moon' on two days, or 'First Quarter' for only a few hours (49%<Illumination<51%).
Moon II (updated).zip
(- forgot to check if month or year had changed in 'Update()' in Luafile; that's why I updated Moon II.zip).

- thanks for your help with the Update and the error balala found. I 'borrowed' 'getTimeOffset()' and looked at UTC-stuff in Mordasius' skin - Thanks for that too.

Correction 2. April: 'Moon II.zip' and 'Moon II (updated).zip' doesn't detect DST. Please use this:
Moon II DST.zip

or 'Stones-Moon III.rar' from Mordasius (on the next page) instead.
You do not have the required permissions to view the files attached to this post.
Last edited by Stone on April 2nd, 2013, 4:37 pm, edited 2 times in total.
- Stone
User avatar
balala
Rainmeter Sage
Posts: 14928
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Sunrise-Moonset

Post by balala »

Mordasius wrote:You've certainly taken a different approach to calculating the times for sunrise and sunset. It must have taken hours to type in and then check all those lines of if day == 6 then MELS = 344.155 end and if LastTwoDigits == 17 then Correct = Correct-0.128 end.
I partialy had automated the script creation, with a little program I wrote, so it didn't took hours.
Mordasius wrote:However, there does seem to be a little something amiss somewhere as sun.lua produces times a few minutes different from those calculated on http://www.timeanddate.com/worldclock/sunrise.html or http://aa.usno.navy.mil/data/docs/RS_OneDay.php.
I know there is an amiss, but, as a wrote, I'm still working on skin's improvement.
Mordasius wrote:I then use the Detect Value Change snippet to update the measure when the day changes.

Code: Select all

-- check to see if the day has changed
	local TodayTimes = tonumber(SKIN:GetVariable('todaysday'))
		if OldTimes ~= TodayTimes then
			 SKIN:Bang("!UpdateMeasure mLuaSunMoonTimes") 
			OldTimes = TodayTimes
		end
This was my approach, too.

In creation of this lua script, I had used the following site: http://www.moonstick.com/sunriseset.htm. If somebody knows a better site, with a simpler algorithm, I'd be happy if should share it.
Stone
Posts: 25
Joined: March 12th, 2013, 8:51 am
Location: Copenhagen / Denmark

Re: Sunrise-Moonset

Post by Stone »

- I have found this:
Sun.zip
It was already in Lua, converted from C (C-source included in the zip).
Rise and set times works fine, but the twilight-times doesn't (the code Mordasius converted from Java
is much better at twilight).

Correction 2. April: - Seems like I made the same mistake as in 'Moon.zip' and 'Moon II.zip' (not detecting when DaylightSavingsTime begins). 'Sun II.zip' should work a little better. - Thanks Balala & Mordasius...
Sun II.zip
You do not have the required permissions to view the files attached to this post.
Last edited by Stone on April 2nd, 2013, 4:19 pm, edited 1 time in total.
- Stone