The latest page is at itmetr.net.
last modified:
05:02 PM MDT, Sun 15 Jun 2008
Here you will learn some of the basics of:
There is a lot of information here, probably too much for those truly unfamiliar with programming. Raster graphics describe an image as an array of colored pixels. A 512x512 raster image displays with a size of about 7 inches by 7 inches on a typical monitor. When printed on a 600 dpi (dots per inch) printer at 7 inches by 7 inches, it will look "jagged", or blocky, just like the image in a monitor. Vector graphics describe an image independent of the resolution of the final rendering device. The following sentence is a vector graphic: "Draw a circle 2 inches in diameter, filled with red, on a white background". When this is plotted on a 600 dpi printer it will look much smoother than the same graphic rendered on a monitor. Vector graphics are obviously good for plots that can be described by objects (lines, circles, letters, etc.). Raster graphics are the only reasonable choice for photos and satellite images. Vector graphics can be converted to a raster graphic with a specified resolution, as is almost always the case before printing, except for "pen plotters". Raster graphics cannot be converted back to vector graphics. Certain compressed image formats, PNG for example, identifies pixels of the same color and describe a region to fill with the same color, rather than specifying a color for each pixel. But the PNG compression still specifies the raster image exactly. Circles are still jagged no matter what the resolution of the printer. Making raster graphicsHere we will make portable pixel map files as our prime example of raster graphics. Using a text editor (gedit), put the following lines into a file a.ppm: P3 3 2 255 255 0 0 0 255 0 0 0 255 255 255 0 200 200 0 150 150 0 Now let's look at your image, with one or more of your available options. Your image is really tiny, three pixels by two pixels, and one pixel normally displays at about 1/72 of an inch on a monitor. So, we need to drastically enlarge the display of the image. Here are a few options on Gentry:
Making PPM files with PythonNeedless to say, you won't be completing your dissertation any time soon if you are going to manually type in RGB triplets for your graphics. Here we will use the Python programming language to write the RGB triplets to a file.
wget http://gentry.metr.ou.edu/rgraphics/makeppm.pyTry this: python makeppm.pyAlternatively, make makeppm.py executable with chmod u+x makeppm.py. Then run the program by typing the program name, e. g.: makeppm.py If that does not work, perhaps your current directory is not "in your path" (more on that later). Try: ./makeppm.py If the last line in makeppm.py did not show you your colors.ppm, try it from the Linux command line: display colors.ppmYou should see something like: ![]() Use head colors.ppm or tail colors.ppm to see some of the text that makeppm.py made. Have a look inside makeppm.py using gedit and try to understand the syntax. Feel free to play with it; blend red and blue, for example. One thing you should realize about the python language is that the indentations define the scope of loops and nests, and the indentations must be consistent. I use one tab character, others prefer four spaces.
Compressing raster graphicsUse ls -l colors.ppm to see the size. When written in ascii, the file is quite large. You may want to try editting makeppm.py to use the "P6" binary format (see the comments in the code). Now look at the file size. Then convert colors.ppm colors.png convert colors.ppm colors.jpg Use display colors.png of display colors.jpg to view what you made. Either one should look almost exactly like colors.ppm. Use ls -l colors.* to see the size of the files: -rw-r--r-- 1 yourname tux 2705 Dec 31 15:14 colors.jpg -rw-r--r-- 1 yourname tux 907 Dec 31 15:14 colors.png -rw-r--r-- 1 yourname tux 599055 Dec 31 11:34 colors.ppm .png is the winner, which surprises me, because usually for smoothly varying colors the .jpg will be smaller. Not only that, but .jpg is a lossy compression, as this exercise demonstrates: convert colors.ppm c.ppm convert c.ppm colors.jpg convert colors.jpg d.ppm diff c.ppm d.ppm Try the above exercise with .png, instead of .jpg, and you will see the .png is a reversible compression. But if you download a typical .jpg: liberty.jpg, then: convert liberty.jpg liberty.png you will find the .png is larger. convert is indeed a very useful command-line utility. Here is a short tutorial for convert. Here is the official online documentation for convert, listing all of the command line options. Task for Fall 2006
Download plotrean.py. Or from the Gentry command line:
wget http://gentry.metr.ou.edu/rgraphics/plotrean.pychmod it to be executable. Then also on Gentry: wgrib /REANALYSIS/1999/data/fixed/land.sfc -d 1 -text -o land.dat wgrib /REANALYSIS/1999/data/at00z12z/pres.sfc -d 1 -text -o pres1.dat plotrean.py land.dat plotrean.py pres1.datYou should see images like:
and .Note the surface pressure field is dominated by the effect of topography. Your task is to plot pressure only over the water. Read the notes at the end of plotrean.py for details. I suggest you: cp plotrean.py plotmask.pyor something like that, and hack away on plotmask.py to complete the task. Post your image, in PNG format, and your source code in your password protected site. Give the image an informative caption. Notify the instructor when it is ready for assessment.
Previous tasks now offered as examples
|