It is currently July 18th, 2024, 11:02 pm

Weather Radar (Gif?)

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7742
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Weather Radar (Gif?)

Post by Yincognito »

frshmrrw wrote: September 19th, 2023, 3:04 am I apologize if double posting is frowned upon around here. I think my questions have merit for other noobs. If it should be a new post I'll do so.

This is an example of a URL I'm trying to decode so I can request it again with variables.

Code: Select all

https://weather.gc.ca/api/map/radar.3978/wmts/RADAR_1KM_RRAI_14_2023-09-19T02-12-00Z_512/wxo_3978_grid_512/11/103/74.png
Variation in this URL seems to be:

-The Date 2023-09-19
-The T00-00-00Z bit changes but I can't figure its use edit: I think it's actually just the Time in UTC
-The Zoom Level 11
-The Tile Number on the master map, so to speak 103
-The 74.png seems to change for a reason I can't determine.


If anyone has any thoughts I would welcome them. Even if it's simply direction to some documentation I need to re-read.
Maybe the API documentation for the radar there has some answers? Anyway, this is not certain, but 74 might be the frame number in the animation?
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
frshmrrw
Posts: 19
Joined: May 7th, 2022, 10:28 pm

Re: Weather Radar (Gif?)

Post by frshmrrw »

Maybe the API documentation for the radar there has some answers? Anyway, this is not certain, but 74 might be the frame number in the animation?
I may need to come back to that URL data because those ones are transparent Radar-Only. For the purposes of learning I'm using the data from here: https://dd.weather.gc.ca/radar/PRECIPET/GIF/CASET/

I managed to get the RegEx correct in RainRegExp, but the variables I'm having to use, I think, are confusing it.

Code: Select all

[Rainmeter]
Update=10000
AccurateText=1
DynamicWindowSize=1

[Variables]
Station=CASET

;;Radar Station Master List - https://collaboration.cmc.ec.gc.ca/cmc/cmos/public_doc/msc-data/obs_radar/radars_list.pdf

;;	==	Time Measures	==

[MeasureYear]
Measure=Time
Format=%Y
Timezone=0
DynamicVariable=1

[MeasureMonth]
Measure=Time
Format=%m 
Timezone=0
DynamicVariable=1

[MeasureDay]
Measure=Time
Format=%d
Timezone=-1
DynamicVariable=1

[MeasureHour]
Measure=Time
Format=%H 
Timezone=-1
DynamicVariable=1

[MeasureMinute]
Measure=Time
Format=%M   
Timezone=-1
DynamicVariable=1

;;	==	Radar Frames ==

[MeasureRadar1]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/
RegEx=(?siU)<ahref"[#MeasureYear][#MeasureMonth][#MeasureDay] [#MeasureHour][#MeasureMinute]_[#Station]_PRECIPET_RAIN_A11Y.gif">(.*)</a>[#MeasureYear]-[#MeasureMonth]-[#MeasureDay] [#MeasureHour]:[#MeasureMinute]
DynamicVariables=1

[MeasureFrame1]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[#MeasureRadar1]
Download=1
DownloadFile=Frame1.png
DynamicVariables=1

;;	==	Meters	==	

[MeterFrame1]
Meter=Image
ImagePath=DownloadFile
ImageName=Frame1.png
DynamicVariables=1
It's grabbing the time ok, am I using those variable callbacks correctly? I want to get a string value back to append to the original URL, which is an image file to download. But alas, I'm stuck..


Edit: I realize now that I need the Minute not to be measured in real time, but instead any multiple of 6. I don't know how to express that. I somehow need to tell that minute section to be '0 OR 6 OR 12' etc. Is that possible?
I generally don't know what I'm doing but I'm here to learn
User avatar
Yincognito
Rainmeter Sage
Posts: 7742
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Weather Radar (Gif?)

Post by Yincognito »

frshmrrw wrote: September 19th, 2023, 4:07 pm I may need to come back to that URL data because those ones are transparent Radar-Only. For the purposes of learning I'm using the data from here: https://dd.weather.gc.ca/radar/PRECIPET/GIF/CASET/

I managed to get the RegEx correct in RainRegExp, but the variables I'm having to use, I think, are confusing it.

Code: Select all

[Rainmeter]
Update=10000
AccurateText=1
DynamicWindowSize=1

[Variables]
Station=CASET

;;Radar Station Master List - https://collaboration.cmc.ec.gc.ca/cmc/cmos/public_doc/msc-data/obs_radar/radars_list.pdf

;;	==	Time Measures	==

[MeasureYear]
Measure=Time
Format=%Y
Timezone=0
DynamicVariable=1

[MeasureMonth]
Measure=Time
Format=%m 
Timezone=0
DynamicVariable=1

[MeasureDay]
Measure=Time
Format=%d
Timezone=-1
DynamicVariable=1

[MeasureHour]
Measure=Time
Format=%H 
Timezone=-1
DynamicVariable=1

[MeasureMinute]
Measure=Time
Format=%M   
Timezone=-1
DynamicVariable=1

;;	==	Radar Frames ==

[MeasureRadar1]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/
RegEx=(?siU)<ahref"[#MeasureYear][#MeasureMonth][#MeasureDay] [#MeasureHour][#MeasureMinute]_[#Station]_PRECIPET_RAIN_A11Y.gif">(.*)</a>[#MeasureYear]-[#MeasureMonth]-[#MeasureDay] [#MeasureHour]:[#MeasureMinute]
DynamicVariables=1

[MeasureFrame1]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[#MeasureRadar1]
Download=1
DownloadFile=Frame1.png
DynamicVariables=1

;;	==	Meters	==	

[MeterFrame1]
Meter=Image
ImagePath=DownloadFile
ImageName=Frame1.png
DynamicVariables=1
It's grabbing the time ok, am I using those variable callbacks correctly? I want to get a string value back to append to the original URL, which is an image file to download. But alas, I'm stuck..


Edit: I realize now that I need the Minute not to be measured in real time, but instead any multiple of 6. I don't know how to express that. I somehow need to tell that minute section to be '0 OR 6 OR 12' etc. Is that possible?
No, the syntax is not entirely correct. In Rainmeter, you reference variables using a syntax like #Station# and measures using a syntax like [MeasureYear] and so on. What you did above is to use the nested variable syntax like [#Something] for variables and measures alike, which is not correct for measures.

Regarding the minute issue, that is not possible directly, but it can be done. However, there are multiple issues with your code that need to be addressed. You'd better figure out exactly what images you need to download before proceeding with the code...
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
frshmrrw
Posts: 19
Joined: May 7th, 2022, 10:28 pm

Re: Weather Radar (Gif?)

Post by frshmrrw »

Yincognito wrote: September 19th, 2023, 5:30 pm No, the syntax is not entirely correct. In Rainmeter, you reference variables using a syntax like #Station# and measures using a syntax like [MeasureYear] and so on. What you did above is to use the nested variable syntax like [#Something] for variables and measures alike, which is not correct for measures.
Ah okay, I was definitely confused about that. I see that issue now. Thanks!
Yincognito wrote: September 19th, 2023, 5:30 pmRegarding the minute issue, that is not possible directly, but it can be done. However, there are multiple issues with your code that need to be addressed. You'd better figure out exactly what images you need to download before proceeding with the code...
It almost does what I want for this moment of learning. I have read and re-read the regex documentation and I just can't get it to do what I want. It's likely an obvious dumb mistake but I'm not adept enough at this stuff. The meter shouldn't work right now, neither should the MeasureRadar1. For right now, I'm just trying to get it to output the URL correctly but I'm omitting it somehow.

Less mistakes, still wrong:

Code: Select all

[Rainmeter]
Update=10000
AccurateText=1
DynamicWindowSize=1

[Variables]
Station=CASET

;;Radar Station Master List - https://collaboration.cmc.ec.gc.ca/cmc/cmos/public_doc/msc-data/obs_radar/radars_list.pdf

;;	==	Time Measures	==

[MeasureYear]
Measure=Time
Format=%Y
Timezone=0
DynamicVariables=1

[MeasureMonth]
Measure=Time
Format=%m 
Timezone=0
DynamicVariables=1

[MeasureDay]
Measure=Time
Format=%d
Timezone=-1
DynamicVariables=1

[MeasureHour]
Measure=Time
Format=%H 
Timezone=-1
DynamicVariables=1

[MeasureMinute]
Measure=Time
Format=%M   
Timezone=-1
DynamicVariables=1

;;	==	Radar Frames ==

[MeasureRadar1]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/
RegEx=(?siU)<ahref"[&MeasureYear][&MeasureMonth][&MeasureDay] [&MeasureHour]00_[#Station]_PRECIPET_RAIN_A11Y.gif">(.*)</a>[&MeasureYear]-[&MeasureMonth]-[&MeasureDay] [&MeasureHour]:00
DynamicVariables=1

[MeasureFrame1]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[&MeasureRadar1]_[#Station]_PRECIPET_RAIN_AllY.gif
Download=1
DownloadFile=Frame1.png
DynamicVariables=1

;;	==	Meters	==	

[MeterFrame1]
Meter=Image
ImagePath=DownloadFile
ImageName=Frame1.png
DynamicVariables=1
It's producing:
https://dd.weather.gc.ca/radar/PRECIPET/GIF/CASET/_CASET_PRECIPET_RAIN_AllY.gif

instead of
https://dd.weather.gc.ca/radar/PRECIPET/GIF/CASET/202309191400_CASET_PRECIPET_RAIN_A11Y.gif
I generally don't know what I'm doing but I'm here to learn
User avatar
SilverAzide
Rainmeter Sage
Posts: 2687
Joined: March 23rd, 2015, 5:26 pm

Re: Weather Radar (Gif?)

Post by SilverAzide »

frshmrrw wrote: September 19th, 2023, 7:21 pm
Sorry to interject here, but why are you trying to grab a specific image for a specific time? The timestamp embedded in the image may or may not exist, as an image doesn't exist for every minute of the day. Looks like that site only updates at roughly 6 minute intervals, so your code has a very low chance of working, even if you do get the code right.

It seems to me you'd just want to grab the latest file in that folder, for the type of precip and image you are looking for. :confused:
Gadgets Wiki GitHub More Gadgets...
frshmrrw
Posts: 19
Joined: May 7th, 2022, 10:28 pm

Re: Weather Radar (Gif?)

Post by frshmrrw »

SilverAzide wrote: September 19th, 2023, 10:55 pm Sorry to interject here, but why are you trying to grab a specific image for a specific time? The timestamp embedded in the image may or may not exist, as an image doesn't exist for every minute of the day. Looks like that site only updates at roughly 6 minute intervals, so your code has a very low chance of working, even if you do get the code right.

It seems to me you'd just want to grab the latest file in that folder, for the type of precip and image you are looking for. :confused:
Interjections help me learn! Don't apologize.

I could grab the most recent image, that's true. I have a working bit that simply does that but it uses the unique bit at the end off the body and I'm trying to build something that can be expanded as I learn more hence going after the date strings. I hadn't really arrived at solving the timing yet because once I did that I wanted it to animate it. I'm mostly trying to learn new things. This is the first Rainmeter skin I've ever written beyond copying the tutorials or editing existing skins afterall. :) My problem now is Regular Expressions, so I'm off topic at this point.

Thanks for reading and thanks for your patience.
I generally don't know what I'm doing but I'm here to learn
frshmrrw
Posts: 19
Joined: May 7th, 2022, 10:28 pm

Re: Weather Radar (Gif?)

Post by frshmrrw »

SilverAzide wrote: September 19th, 2023, 10:55 pm grab the latest file in that folder
Is there a simple way to achieve that? I apologize if it's a stupid question..


I'm trying the following but for some reason the UTC time on the image isn't matching the hour so I've got something wrong.

Code: Select all

[Rainmeter]
Update=10000
AccurateText=1
DynamicWindowSize=1

[Variables]
Station=CASET

[MeasureTime]
Measure=Time
Format=%Y%m%d%H
Timezone=0

[MeasureRadar]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[MeasureTime]00_[#Station]_PRECIPET_RAIN.gif
Download=1
DownloadFile=Frame1.png
DynamicVariables=1

[MeterFrame1]
Meter=Image
ImagePath=DownloadFile
ImageName=Frame1.png
I'm actively avoiding regular expressions because they make my brain hot, but I know in theory I can parse the last "PRECIPET_RAIN.gif" in the list. Or maybe there's a way to ask for the last, second last, third last, etc. There's probably a few ways to do it, but I'm hoping to learn something useful through the process here.

Thanks for reading
I generally don't know what I'm doing but I'm here to learn
User avatar
SilverAzide
Rainmeter Sage
Posts: 2687
Joined: March 23rd, 2015, 5:26 pm

Re: Weather Radar (Gif?)

Post by SilverAzide »

frshmrrw wrote: September 20th, 2023, 5:34 pmIs there a simple way to achieve that?
No, because...
frshmrrw wrote: September 20th, 2023, 5:34 pmI'm actively avoiding regular expressions because they make my brain hot...
...you are gonna have to use regular expressions.

I am *not* a regexp guru; that would be Mr. Yincognito or a couple of the other uber-gurus on the forums. But something like this might work.

Code: Select all

[MeasureLastFileName]
Measure=WebParser
UpdateRate=360
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/
RegExp=(?si).*(?<!PRECIPET_RAIN)(\d{12}_\w+_PRECIPET_RAIN\.gif)
FinishAction=[!EnableMeasure MeasureLastFileImage]

[MeasureLastFileImage]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[&MeasureLastFile]
Download=1
DownloadFile=Frame1.png
DynamicVariables=1
Disabled=1
FinishAction=[!DisableMeasure MeasureLastFileImage]
The first measure grabs the directory contents of the entire folder and uses a "negative lookbehind" regexp to match the last instance of the filename that matches <blah>_PRECIPET_RAIN.gif. The second measure downloads the file once you have the name.

Consider this pseudo-code, 'cuz I didn't try it.

No idea what you'd do if you wanted, say, the last X images so you could play them in a sequence.
Gadgets Wiki GitHub More Gadgets...
frshmrrw
Posts: 19
Joined: May 7th, 2022, 10:28 pm

Re: Weather Radar (Gif?)

Post by frshmrrw »

SilverAzide wrote: September 20th, 2023, 10:06 pm snipped
No idea what you'd do if you wanted, say, the last X images so you could play them in a sequence.
Dang! Cause that's exactly where I am at. I've got this, which downloads the last hour's set of imagery.

Code: Select all

[Rainmeter]
Update=10000
AccurateText=1
DynamicWindowSize=1

[Variables]
Station=CASET
Scale=0.535
;;Radar Station Master List - https://collaboration.cmc.ec.gc.ca/cmc/cmos/public_doc/msc-data/obs_radar/radars_list.pdf

;;	Get Time

[MeasureYear]
Measure=Time
Format=%Y

[MeasureMonth]
Measure=Time
Format=%m

[MeasureDay]
Measure=Time
Format=%d

[MeasureHour]
Measure=Time
Format=%H
Timezone=-2

;;	Get Radar Imagery

[MeasureRadar1]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[&MeasureYear][&MeasureMonth][&MeasureDay][&MeasureHour]54_[#Station]_PRECIPET_RAIN.gif
Download=1
DownloadFile=Radar10.png
DynamicVariables=1

[MeasureRadar2]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[&MeasureYear][&MeasureMonth][&MeasureDay][&MeasureHour]48_[#Station]_PRECIPET_RAIN.gif
Download=1
DownloadFile=Radar9.png
DynamicVariables=1

[MeasureRadar3]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[&MeasureYear][&MeasureMonth][&MeasureDay][&MeasureHour]42_[#Station]_PRECIPET_RAIN.gif
Download=1
DownloadFile=Radar8.png
DynamicVariables=1

[MeasureRadar4]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[&MeasureYear][&MeasureMonth][&MeasureDay][&MeasureHour]36_[#Station]_PRECIPET_RAIN.gif
Download=1
DownloadFile=Radar7.png
[MeasureRadar5]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[&MeasureYear][&MeasureMonth][&MeasureDay][&MeasureHour]30_[#Station]_PRECIPET_RAIN.gif
Download=1
DownloadFile=Radar6.png
DynamicVariables=1

[MeasureRadar6]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[&MeasureYear][&MeasureMonth][&MeasureDay][&MeasureHour]24_[#Station]_PRECIPET_RAIN.gif
Download=1
DownloadFile=Radar5.png
DynamicVariables=1

[MeasureRadar7]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[&MeasureYear][&MeasureMonth][&MeasureDay][&MeasureHour]18_[#Station]_PRECIPET_RAIN.gif
Download=1
DownloadFile=Radar4.png
DynamicVariables=1

[MeasureRadar8]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[&MeasureYear][&MeasureMonth][&MeasureDay][&MeasureHour]12_[#Station]_PRECIPET_RAIN.gif
Download=1
DownloadFile=Radar3.png
DynamicVariables=1

[MeasureRadar9]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[&MeasureYear][&MeasureMonth][&MeasureDay][&MeasureHour]06_[#Station]_PRECIPET_RAIN.gif
Download=1
DownloadFile=Radar2.png
DynamicVariables=1

[MeasureRadar10]
Measure=WebParser
URL=https://dd.weather.gc.ca/radar/PRECIPET/GIF/[#Station]/[&MeasureYear][&MeasureMonth][&MeasureDay][&MeasureHour]00_[#Station]_PRECIPET_RAIN.gif
Download=1
DownloadFile=Radar1.png
DynamicVariables=1

;;	Radar Animation

[ImageNumberCalc]
Measure=Calc
Formula=Counter % 10

[ImageMeter]
Meter=Image
ImagePath=DownloadFile
ImageName=Radar[ImageNumberCalc].png
AntiAlias=1
DynamicVariables=1
You're very patient with my silly questions, I appreciate it, Silver. I'm still googling because I know 'How do I animate these frames' is a common question I'm sure has been solved.

Any suggestions to this bit of code is welcome! I'm not at all confident in it except that it was able to download the frames.
I generally don't know what I'm doing but I'm here to learn
User avatar
SilverAzide
Rainmeter Sage
Posts: 2687
Joined: March 23rd, 2015, 5:26 pm

Re: Weather Radar (Gif?)

Post by SilverAzide »

frshmrrw wrote: September 21st, 2023, 1:09 am
Your technique will certainly work, assuming that their clock and your clock are roughly in sync (you can easily miss a frame or two if not). Also, i don't think your time measures are returning UTC time, so your maps might be off by a few hours since the files are timestamped in UTC.

You could use a hybrid approach. Grab that last filename, then parse out the timestamp string, convert it to a real "number of seconds" value, and "walk it backwards" at 6 minutes intervals to derive the previous filenames, however many frames you want. Once you have that last file's timestamp, it's easy math to figure out the rest.
Gadgets Wiki GitHub More Gadgets...