Login to AccuWeather.com Premium Login to AccuWeather.com Professional Login to AccuWeather.com RadarPlus AccuWeather.com

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Combining instantweathermaps.com CDN and US maps
knorthern_knight
post Oct 31 2012, 06:01 PM
Post #1




Rank: Tornado
**

Group: Member
Posts: 220
Joined: 3-December 10
From: Greater Toronto
Member No.: 24,490





Weather systems do not respect political boundaries, but the Canadian and US outputs from instantweathermaps.com come separately. This can be inconvenient for viewing systems that straddle the border. I've cobbled together scripts to rescale and combine the two outputs. An example follows...

Attached File  c000.gif ( 32.1K ) Number of downloads: 1


Attached File  u000.gif ( 26.53K ) Number of downloads: 0


Attached File  result.gif ( 191.72K ) Number of downloads: 2


The Canadian map has to be magnified 43% over its original size, to line up with the US map. The result is that the lines and numbers are bigger+thicker on the Canadian side.

The scripts use the "convert" tool in the Imagemagick suite. The Imagemagick homepage is at http://www.imagemagick.org/script/index.php and the executable program download page is http://www.imagemagick.org/script/binary-releases.php Linux users should be able to install it using the package-management tool that comes with their distro (apt/yum/rpm/emerge/etc).

Once you have the software installed, you will need to download a Canadian and a US map from Instantweathermaps.com (same parameter/run-date/valid-date) . In the following examples, I use the names
  • "c000.gif" for the Canadian map
  • "u000.gif" for the US map
  • "r000.gif" for the Canadian map
I've set up scripts to do the grunt work, in bash and in DOS bat files. The scripts take 3 parameters...
  • the filename of the Canadian map (example c000.gif)
  • the filename of the US map (example u000.gif)
  • the filename of the output (combined) map (example r000.gif)
==================================================
Edit / clarification; the order of the parameters in the script is crucial. The parameters are
  1. Canadian file name
  2. American file name
  3. Combined output file name
==================================================

For posix (bsd/linux/unix) environments, use the following bash script, named "combo". Given the above map names, it would be invoked as...
combo c000.gif u000.gif r000.gif

CODE
#!/bin/bash
convert -crop 800x60+0+60! ${1} label1.gif
convert -extent 1024x60-174+0 label1.gif label1a.gif
convert ${1} -resize '142.8x142.9%' int1.gif
convert -crop 1100x490+3+172! int1.gif int2.gif
convert -crop 800x290+0+223! ${2} int3.gif
convert -extent 1024x290-174+0 int3.gif int4.gif
convert -crop 800x20+0+570! ${1} label2.gif
convert -extent 1024x20-174+0 label2.gif label2a.gif
convert -crop 800x30+0+570! ${2} label3.gif
convert -extent 1024x30-174+0 label3.gif label3a.gif
convert -append label1a.gif int2.gif int4.gif label2a.gif label3a.gif ${3}
rm label*.gif int*.gif


I don't have a Windows machine, so I can't test the bat file. Let me know if it doesn't work, and I'll try to figure out why. A couple of notes for Windows users...
  • There is a Windows system program called "convert", which is used to convert FAT32 file systems to NTFS. Make sure that the "convert" program from the Imagemagick suite is before the "convert" program from the Windows system in your PATH variable.
  • Because percent signs are parameter specifiers in DOS bat files, a literal "%" inside a bat file must be written as "%%". That's why it's doubled up in the "convert -resize" command.
Create the text file "combo.bat", containg the following lines...

CODE
convert -crop 800x60+0+60! %1 label1.gif
convert -extent 1024x60-174+0 label1.gif label1a.gif
convert %1 -resize 142.8x142.9%% int1.gif
convert -crop 1100x490+3+172! int1.gif int2.gif
convert -crop 800x290+0+223! %2 int3.gif
convert -extent 1024x290-174+0 int3.gif int4.gif
convert -crop 800x20+0+570! %1 label2.gif
convert -extent 1024x20-174+0 label2.gif label2a.gif
convert -crop 800x30+0+570! %2 label3.gif
convert -extent 1024x30-174+0 label3.gif label3a.gif
convert -append label1a.gif int2.gif int4.gif label2a.gif label3a.gif %3
del label*.gif
del int*.gif


The command, assuming the files listed above, would be
combo c000.gif u000.gif r000.gif

EDIT: I did not go out and buy a Windows machine laugh.gif But I did install WINE for linux, and the Windows version of ImageMagick. This gives me a simulated Windows XP environment. I fired up a "Windows command prompt" and tested my BAT file. I discovered one problem, which I've corrected. The linux version requires single quotes around the scale factor to "escape" the percent sign, which has a special meaning to the bash shell. Percent signs also have a special meaning to the CMD.EXE shell. But the "escape" mechanism is to double up the percent sign. Adding single quotes causes an error. I removed the single quotes in the "convert -resize" line, and it now works properly under an emulated Windows XP command prompt.

This post has been edited by knorthern_knight: Nov 3 2012, 07:27 PM
Go to the top of the page
 
+Quote Post
Astronomer
post Oct 31 2012, 08:34 PM
Post #2




Rank: F5 Superstorm
***

Group: Member
Posts: 674
Joined: 8-March 08
From: Mount Brydges
Member No.: 14,308





Awesome! Thanks for taking the time to do this. I'll try and find the time to try this on the weekend. It's been added to my hobbies "to-do" list.
Go to the top of the page
 
+Quote Post
bigmt
post Nov 1 2012, 05:31 AM
Post #3




Rank: F5 Superstorm
***

Group: Member
Posts: 5,845
Joined: 29-September 10
From: Ottawa
Member No.: 23,784





This is a good idea. I'll definitely make use of it, assuming it's kink-free on Windows 7.
Go to the top of the page
 
+Quote Post
EOsnowmom
post Nov 1 2012, 07:43 AM
Post #4




Rank: F5 Superstorm
***

Group: Member
Posts: 508
Joined: 30-January 09
From: south of Ottawa, Ontario
Member No.: 17,244





Awesome tutorial! Is there a mod in this group who can made this a sticky at the top of the forum so it isn't lost in the threads?

I'd like to see another thread started (and stuck) just for our fav links to models, radar etc etc as this seems to be a reoccurring question for newbies (myself included!).
Go to the top of the page
 
+Quote Post
knorthern_knight
post Nov 7 2012, 06:04 PM
Post #5




Rank: Tornado
**

Group: Member
Posts: 220
Joined: 3-December 10
From: Greater Toronto
Member No.: 24,490





Scripts for combining output maps from Instantweathermaps.com

The Imagemagick suite is command line oriented. You have to run it from the command line, no ifs, ands, ors, buts. In linux it's an xterm or similar. In Windows it's from a CMD.EXE terminal. It's not really that difficult.

This is version 2 of my combo scripts. After a bit of testing I noticed that the initial version did not cover situations where a system swings wide of the US northeast coast, and hits Atlantic Canada from the south. This version allows ***BUT DOES NOT REQUIRE***, a 3rd map (North Atlantic) to be added to the mix. This additional map covers the area south of NS and NL.

Weather systems do not respect political boundaries, but the Canadian and US and North Atlantic outputs from instantweathermaps.com come separately. This can be inconvenient for viewing systems that straddle the border or come at Atlantic Canada from the south. I've cobbled together scripts to rescale and combine the outputs. The Canadian and Atlantic maps have to be magnified 43% over their original size, to line up with the US map. The result is that the lines and numbers are bigger+thicker than on the US map.

The scripts use the "convert" tool in the Imagemagick suite. The Imagemagick homepage is at http://www.imagemagick.org/script/index.php and the executable program download page for Windows users is at http://www.imagemagick.org/script/binary-releases.php Linux users should be able to install Imagemagick using the package-management tool that comes with their distro (apt/yum/rpm/emerge/etc).

Once you have the software installed, you will need to download a Canadian and a US and possibly an optional North Atlantic map from Instantweathermaps.com. In the following examples, I use the names

"c000.gif" for the Canadian map
"u000.gif" for the US map
"a000.gif" for the North Atlantic map (optional)
"r000.gif" for the output map


It goes without saying, but I will say it...

1) the maps *MUST* be for the same model/parameter/run-date/valid-date.

2) The examples assume that you are in the same directory as the files that you are combining. It's possible to use relative or absolute pathnames, and have each file in a different directory, but that just makes things more complex.

3) The last parameter is the filename that output gets written to. If you give the name of an existing file, it will be overwritten without asking. You have been warned.

4) The scripts also write to several scratch files. The filenames are in the format "label???.gif" and "int??.gif". These are intermediate files, and get overwritten each time you run the script.

I've set up scripts to do the grunt work, in bash and in DOS bat files. Rather than deal with 2 sets of scripts ( 1 with and 1 without North Atlantic), I've set up the scripts to respond differently, depending on the the number of parameters you pass. The scripts allow you to enter either 3 or 4 parameters. The order of the parameters passed to the script is crucial. If you submit 3 parameters, e.g...

combo c000.gif u000.gif r000.gif

The parameters are read as follows...
  1. the filename of the Canadian map (example c000.gif)
  2. the filename of the US map (example u000.gif)
  3. the filename of the output (combined) map (example r000.gif)
If you submit 4 parameters, e.g...

combo c000.gif u000.gif a000.gif r000.gif

The parameters are read as follows...
  1. the filename of the Canadian map (example c000.gif)
  2. the filename of the US map (example u000.gif)
  3. the filename of the North Atlantic map (example a000.gif)
  4. the filename of the output (combined) map (example r000.gif)
The 2 scripts are 1 for posix (linux/unix/*bsd) and 1 for Windows. Some forums are paranoid about allowing executable attachments like BAT files. So I'll post the contents as text. Cut and paste to a text file on your computer. Due to the length of the files (heavily commented), I'll do separate posts for the posix and Windows versions.
Go to the top of the page
 
+Quote Post
knorthern_knight
post Nov 7 2012, 06:17 PM
Post #6




Rank: Tornado
**

Group: Member
Posts: 220
Joined: 3-December 10
From: Greater Toronto
Member No.: 24,490





This code listing is for Windows. Posix users, please go to the next post.
A couple of notes for Windows users...

1) There is a Windows system program called "convert", which is used to
convert FAT32 file systems to NTFS. Make sure that the "convert" program
from the Imagemagick suite is before the "convert" program from the
Windows system in your PATH variable.

2) Because percent signs are parameter specifiers in DOS bat files, a
literal "%" inside a bat file must be written as "%%". That's why it's
doubled up in the "convert -resize" command.

Create the text file "combo.bat", containing the following lines and put it
in a directory in your PATH.

CODE
@echo off
REM
REM Note: The DOS "EXIT" command not only exits the batch file, it exits
REM the command prompt entirely.  In case of an error, it'll close down the
REM command prompt before you have a chance to look at the error message.
REM That is not what we want.  Hence all the jumps to ":ENDBATCH".
REM
REM Check that we have either 3 or 4 arguments.  If not, bail out.
IF NOT "%5"=="" (
   ECHO ERROR: Script encountered more than 4 arguments; only 3 or 4 allowed.
   GOTO ENDBATCH)
IF "%3"=="" (
   ECHO ERROR: Script encountered less than 3 arguments; only 3 or 4 allowed.
   GOTO ENDBATCH)
REM
REM Get top label from Canadian image
convert -crop 800x60+0+60! %1 labeltc1.gif
REM
REM Pad with additional space on left, to keep it centered over the larger
REM rescaled Canadian map
convert -extent 1024x60-174+0 labeltc1.gif labeltc2.gif
REM
REM Rescale the Canadian map to match the US map scale
convert %1 -resize 142.8x142.9%% intc1.gif
REM
REM Crop the bottom of the Canadian map, so it can be put adjacent to the US map
convert -crop 1100x490+3+172! intc1.gif intc2.gif
REM
REM Crop the top of the US map, so it can be put adjacent to the Canadian map
convert -crop 800x290+0+223! %2 intu1.gif
REM
REM Pad with additional space on left, to keep it centered under the larger
REM rescaled Canadian map
convert -extent 936x290-174+0 intu1.gif intu2.gif
REM
REM Get bottom label from Canadian image
convert -crop 800x20+0+570! %1 labelbc1.gif
REM
REM Pad with additional space on left, to keep it centered under the larger
REM rescaled Canadian map
convert -extent 1024x20-174+0 labelbc1.gif labelbc2.gif
REM
REM Get bottom label from US image
convert -crop 800x30+0+570! %2 labelbu1.gif
REM
REM Pad with additional space on left, to keep it centered under the larger
REM rescaled Canadian map
convert -extent 1024x30-174+0 labelbu1.gif labelbu2.gif
REM Code to execute if 4 parameters passed to script
IF NOT "%4"=="" (
REM
REM Rescale the Atlantic map to match the US map scale
   convert %3 -resize 142.5x143.3%% inta1.gif
REM
REM Crop to get the relevant portion of the Atlantic map, so it can be
REM joined to Canadian and US maps.
   convert -crop 150x272+454+219! inta1.gif inta2.gif
REM
REM Append to right-hand edge of US map
   convert +append intu2.gif inta2.gif intu3.gif
REM
REM Append top to bottom
REM - Top label from Canadian map
REM - Canadian map
REM - US map (with extra Atlantic map attached)
REM - Canadian bottom label
REM - US bottom label
   convert -append labeltc2.gif intc2.gif intu3.gif labelbc2.gif labelbu2.gif %4
) ELSE (
REM
REM If 3 parameters passed
REM Append top to bottom
REM - Top label from Canadian map
REM - Canadian map
REM - US map
REM - Canadian bottom label
REM - US bottom label
   convert -append labeltc2.gif intc2.gif intu2.gif labelbc2.gif labelbu2.gif %3
)
:ENDBATCH


Edit 2012/11/13 10:10: changed Atlantic map rescale line from

convert %3 -resize 143.4x143.3%% inta1.gif

to

convert %3 -resize 142.5x143.3%% inta1.gif

for a better seam with the Canada map. Still not perfect.

This post has been edited by knorthern_knight: Nov 13 2012, 10:10 AM
Go to the top of the page
 
+Quote Post
knorthern_knight
post Nov 7 2012, 06:24 PM
Post #7




Rank: Tornado
**

Group: Member
Posts: 220
Joined: 3-December 10
From: Greater Toronto
Member No.: 24,490





This code listing is for linux/unix/*bsd. Windows users, please go to the
previous post.

Create the text file "combo", containing the following lines and put it
in a directory in your PATH. The recommended location is ~/bin/ Remember to
chmod it executable.

CODE
#!/bin/bash
#
# Check that we have either 3 or 4 arguments.  If not, bail out.
if [ ${#} -gt 4 ]; then
   echo "ERROR: Script encountered ${#} arguments; only 3 or 4 allowed."
   exit
elif [ ${#} -lt 3 ]; then
   echo "ERROR: Script encountered ${#} arguments; only 3 or 4 allowed."
   exit
fi
#
# Get top label from Canadian image
convert -crop 800x60+0+60! ${1} labeltc1.gif
#
# Pad with additional space on left, to keep it centered over the larger
# rescaled Canadian map
convert -extent 1024x60-174+0 labeltc1.gif labeltc2.gif
#
# Rescale the Canadian map to match the US map scale
convert ${1} -resize '142.8x142.9%' intc1.gif
#
# Crop the bottom of the Canadian map, so it can be put adjacent to the US map
convert -crop 1100x490+3+172! intc1.gif intc2.gif
#
# Crop the top of the US map, so it can be put adjacent to the Canadian map
convert -crop 800x290+0+223! ${2} intu1.gif
#
# Pad with additional space on left, to keep it centered under the larger
# rescaled Canadian map
convert -extent 936x290-174+0 intu1.gif intu2.gif
#
# Get bottom label from Canadian image
convert -crop 800x20+0+570! ${1} labelbc1.gif
#
# Pad with additional space on left, to keep it centered under the larger
# rescaled Canadian map
convert -extent 1024x20-174+0 labelbc1.gif labelbc2.gif
#
# Get bottom label from US image
convert -crop 800x30+0+570! ${2} labelbu1.gif
#
# Pad with additional space on left, to keep it centered under the larger
# rescaled Canadian map
convert -extent 1024x30-174+0 labelbu1.gif labelbu2.gif
# Code to execute if 4 parameters passed to script
if [ ${#} -eq 4 ]; then
#
# Rescale the Atlantic map to match the US map scale
   convert ${3} -resize '142.5x143.3%' inta1.gif
#
# Crop to get the relevant portion of the Atlantic map, so it can be
# joined to Canadian and US maps.
   convert -crop 150x272+454+219! inta1.gif inta2.gif
#
# Append to right-hand edge of US map
   convert +append intu2.gif inta2.gif intu3.gif
#
# Append top to bottom
# - Top label from Canadian map
# - Canadian map
# - US map (with extra Atlantic map attached)
# - Canadian bottom label
# - US bottom label
   convert -append labeltc2.gif intc2.gif intu3.gif labelbc2.gif labelbu2.gif ${4}
elif [ ${#} -eq 3 ]; then
#
# If 3 parameters passed
# Append top to bottom
# - Top label from Canadian map
# - Canadian map
# - US map
# - Canadian bottom label
# - US bottom label
   convert -append labeltc2.gif intc2.gif intu2.gif labelbc2.gif labelbu2.gif ${3}
fi


Edit 2012/11/13 10:10: changed Atlantic map rescale line from

convert ${3} -resize '143.4x143.3%' inta1.gif

to

convert ${3} -resize '142.5x143.3%' inta1.gif

for a better seam with the Canada map. Still not perfect.

This post has been edited by knorthern_knight: Nov 13 2012, 10:14 AM
Go to the top of the page
 
+Quote Post
knorthern_knight
post Nov 8 2012, 11:32 AM
Post #8




Rank: Tornado
**

Group: Member
Posts: 220
Joined: 3-December 10
From: Greater Toronto
Member No.: 24,490





An example of the map without and with the additional North Atlantic map portion. Notice the area south of NS and NL.

Attached File  r1.gif ( 206.82K ) Number of downloads: 0

Attached File  r2.gif ( 219.14K ) Number of downloads: 0
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 24th May 2013 - 09:23 PM