Weather station scripts - Environment Canada

They're free, but use at your own risk

The scripts in PHP and Perl referenced here are used in the operation of this weather station, and may be freely copied and used to support your station. Please note that you use these scripts at your own risk. No warranty is expressed or implied. I accept no liability for any damages that may ensue from their use.
You will need to configure them for your own particular station website.
RSS feed for Scripts Updates A RSS Feed is available to help keep you informed on updates to the scripts.

If you find one or more of the scripts useful to you, please consider making a small donation to help offset the routine expenses of operation of this website.
Thanks for your kind support!

A Version History is available -- check back from time to time to see if there are updates to scripts you have downloaded earlier. Announcements of version updates and new scripts are made on WXForum.net and Weather-Watch forums and saratogaWXPHP Twitter account as they become available.

Latest postings about Saratoga-weather.org Weather PHP scripts on Twitter

follow Saratoga-Weather.org PHP script updates on Twitter

This page was updated Wednesday, 02-Sep-2009 9:17 AM

PHP Scripts (run on webserver)

These scripts have run on PHP 4.1.2, and PHP 4.4.1. I don't have access to PHP 3.x, so it is not known if they will work on versions below PHP 4.1.2. If you try them and they work (or not) on earlier versions of PHP, please send me a message at webmaster[at]saratoga-weather.org and let me know the results.

Environment Canada radar script (for www.weatheroffice.ec.gc.ca)

This script will read the HTML from the Environment Canada radar page (cached) and download/cache the radar images as .png files on your website. Since the EC uses radar graphic names with embedded timestamps, this script offers one of the few ways that weather enthusiasts can include EC radar images in their own websites.

The ec-radar.php script uses a subdirectory (/radar/) to store the contents of the EC radar HTML pages and the current radar graphics. For proper operation of the script, you need to ensure that the /radar directory is writable by PHP scripts. A simple test script is included to check this (ec-radar-cachetest.php).

The script will load the HTML page from the EC website (cached) and parse the contents for the radar graphic images available, then download (cache) the images in /radar/radar-AAA-N.png files (AAA=siteid, N=0 (most recent) to 6 (oldest). Then the script will generate HTML and JavaScript to display the graphics from the cache and the associated date stamps for the radar images. The script generates uniquely named JavaScript functions/variables to allow you to embed more than one Radar set on a page (as shown below). For the National (site=NAT) and the regional sites (PAC, WRN, ONT, QUE, and ERN), the radar includes a clickable image map that if clicked, will launch the $linkToPage page (default is $PHP_SELF) to display the new radar site. A smaller (1/4 size) image is also available that will display the words 'N/O - Non Operational' (english) or 'N/O - Non opérationnel' (french) with the time of the last available radar image. The following parameters are available on the ec-radar.php script:

site=AAA
If present, the script will load radar images from the 'AAA' radar site. The EC radar sites usually begin with X or W and are 3 alphabetic characters long. There are also several meta-site names available:
site=NAT - National radar
site=PAC - Pacific region
site=WRN - Prairies region
site=ONT - Ontario region
site=QUE - Quebec region
site=ERN - Atlantic region
inc=Y
If present, the script will not output surrounding HTML for the page returned. You should specify this if you invoke the script from within your webpage i.e.
<?php include("http://your.website/ec-radar.php?inc=Y"); ?>
lang=en
(Default) Text is in English..
lang=fr
Text is in French .
play=yes
(default)--Start the JavaScript animation when page is loaded.
play=no
Don't start the animation when the page is loaded. Viewer must press play-stop button to start animation.
imgonly=Y
Return a 1/4 size static image of the latest radar selected.
This is for use in an <img> statement on your page like this:
<img src="http://your.website.com/ec-radar.php?imgonly=Y"
width="290" height="240" alt="radar" title="radar" />
See example 1 below for usage.
Note: individual site radar images are width="290" height="240"
regional site radar images are width="290" height="150"
National radar image is width="290" height="150"
linkto=
This optional parameter is to connect clicks on the map to a different page on your site. The default is to return to the script itself ($PHP_SELF). See example 2 below for possible usage.
You can set this in the $linkToPage variable in the program instead (to hide the navigation if you like).

For webmaster help with debugging the setup/configuration of the script, the following parameters may also be used:

cache=no
Forces refresh of EC radar page and radar images .

Settings inside the script

If you create a writable /radar subdirectory in the document root of your webserver, then the only settings you should change are $siteID and $defaultLang.

// Settings:
// --------- start of settings ----------
// you need to set the $ECURL to the radar image for your site
//
//  Go to http://www.weatheroffice.ec.gc.ca/ and select your language (sorry, I don't 
//  speak French, so these instructions are all in English)
//
//  Go to http://weatheroffice.ec.gc.ca/radar/index_e.html
//  Click on the radar circle around your city/area.
//  You should see a radar page with an url like
//     http://weatheroffice.ec.gc.ca/radar/index_e.html?id=xxx
//  copy the three letter radar id=XXX into $siteID = 'XXX'; below
//
$siteID = 'XSM';      // set to default Site for radar (same as id=xxx on EC website)
//
$defaultLang = 'en';  // set to 'fr' for french default language
//                    // set to 'en' for english default language
//
$cacheName = 'ec-radar.txt';     // note: will be changed to -en.txt or 
//                                  -fr.txt depending on language choice and stored in $radarDir
$radarDir = '/radar/';           // directory for storing radar-XXX-0.png to radar-XXX-6.png images
//                                  note: relative to document root.
//
$refetchSeconds = 300;  // look for new radar from EC 
//                         every 5 minutes (300 seconds)
$noRadarMinutes = 25;   // minutes to wait before declaring the radar site as 'N/O -not operational'
//
$aniSec = 1; // number of seconds between animations
//
$linkToPage = '';         // detail url to link to when map link is clicked 
//                        default '' will link to this program (ec-radar.php) 
// ---------- end of settings -----------

Example 1 - Current default radar small image

<img src="http://saratoga-weather.org/ec-radar.php?imgonly=Y" width="290" height="240"
alt="Latest XSM radar from Environment Canada"
title="Latest XSM radar from Environment Canada" />

Results in:

Latest XSM radar from Environment Canada

Example 2 - Canada National Radar in French

<?php
$site = 'NAT';
$lang = 'fr';
if (isset($_REQUEST['site'])) { $site = $_REQUEST['site']; }
if (isset($_REQUEST['lang'])) { $lang = $_REQUEST['lang']; }
include("http://your.website.com/ec-radar.php?inc=Y&site=$site&lang=$lang&linkto=$PHP_SELF");
?>

Results in a clickable National radar map with animation (in French) that returns to this page:

Aldergrove - Radar image for station WUJ located near Vancouver, British Columbia. Bethune - Radar image for station XBE located near Regina, Saskatchewan. Britt - Radar image for station WBI located near Sudbury, Ontario Carvel - Radar image for station WHK located near Edmonton, Alberta Chipman - Radar image for station XNC located near Frederiction, New Brunswick. Dryden - Radar image for station XDR located near Dryden, Ontario Exeter - Radar image for station WSO located near London, Ontario. Foxwarren - Radar image for station XFW located near Brandon, Manitoba. Franktown - Radar image for station XFT located near Ottawa, Ontario. Halifax - Radar image for station XGO located near Halifax, Nova Scotia. Holyrood - Radar image for station WTP located near St. John's, Newfoundland and Labrador. Jimmy Lake - Radar image for station WHN located near Cold Lake, Alberta. King City - Radar image for station WKR located near Toronto, Ontario. Lac Castor - Radar image for station WMB located near Saguenay, Quebec. Landrienne - Radar image for station XLA located near Rouyn-Noranda, Quebec. Marble Mountain - Radar image for station XME located near Corner Brook, Newfoundland and Labrador. Marion Bridge - Radar image for station XMB located near Sydney, Nova Scotia. McGill - Radar image for station WMN located near Montréal, Quebec. Montreal River - Radar image for station WGJ located near Sault Ste. Marie, Ontario Northeast Ontario - Radar image for station XTI located near Timmins, Ontario Prince George - Radar image for station XPG located near Prince George, British Columbia. Radisson - Radar image for station XRA located near Saskatoon, Saskatchewan. Schuler - Radar image for station XBU located near Medicine Hat, Alberta. Silver Star Mountain - Radar image for station XSS located near Vernon, British Columbia Spirit River - Radar image for station WWW located near Grande Prairie, Alberta. Strathmore - Radar image for station XSM located near Calgary, Alberta. Superior West - Radar image for station XNI located near Thunder Bay, Ontario Val d'Irène - Radar image for station XAM located near Mont-Joli, Quebec Victoria - Radar image for station XSI located near Victoria, British Columbia. Villeroy - Radar image for station WVY located near Trois-Rivières, Quebec Woodlands - Radar image for station XWL located near Winnipeg, Manitoba. Radar image for stations located in Pacific region Radar image for stations located in Prairies region Radar image for stations located in Ontario region Radar image for stations located in Quebec region Radar image for stations located in Atlantic region

Canadian Weather Radar - 2010-07-30 21:00 UTC, 8/8
Radar Imagery - Environment Canada

Canadian Weather Radar - Environment Canada

Environment Canada Radar PHP script [V1.07] : demo [ see version history ]

Installation Instructions

  1. Download ec-radar-cachetest.php script from here and upload to your website (in your document root directory) . If you choose another subdirectory, to run the script, then change the $radarDir = '/radar/'; to be the full path from the document root (with leading slash).
    For example, if you put it in /EC/ from document root, then set $radarDir = '/EC/radar/'; and put the script in the /EC directory.
  2. Create a new ./radar directory on the webserver one directory below where you placed the script.
  3. Upload ec-radar-cachetest.php script to the chosen directory from step 1 and run the program from your browser.
    If the ec-radar-cachetest.php reports success in writing the file and that GD is installed, then proceed to step 4.
    If you have error messages appearing, then you'll have to fix the problem on your webserver (by changing the permissions on the ./radar directory to 777 on Linux/Unix systems, or allowing 'all' to read/write/create on IIS system). The ec-radar.php program requires the use of cache files, so you'll have to get a clean run on ec-radar-chachetest.php to have ec-radar.php run successfully.
  4. Download ec-radar.php from here, and make sure the $radarDir = '/radar/'; is set the same as in your ec-radar-cachetest.php file, and change other settings ($siteID) as you like.
  5. Upload ec-radar.php to the same directory that successfully ran ec-radar-cachetest.php.
  6. View ec-radar.php with your browser. You should see the animation of your local ($siteID) radar.
  7. Install links in your other webpages for the radar images you desire.

Note: this script is included with the WD/AJAX/PHP Canada template sets (English and bilingual English/French).

Websites using the ec-radar.php script

10 ec-radar.php sites listed.
If you would like your site listed please contact me with your location and weather website URL.