Introduction to Numerical Astrophysics Visualization using sm and Other Tools - Prof. Dere, Study notes of Astronomy

An introduction to visualization tools and techniques for numerical astrophysics applications, focusing on the 2-d graphing package sm. It covers interactive use, macros, and scripting, as well as other visualization packages like gnuplot, pgplot, idl, and excel. The document also discusses animation creation using imagemagick and pov-ray, and presentation tools like latex and powerpoint.

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-x3i-1
koofers-user-x3i-1 🇺🇸

9 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Introduction to Visualization
(and presentation tools)
There are a variety of visualization packages suitable for numerical astrophysics applications, ranging from
simple 2-D plotters to professional products that supp ort animation and multi-dimensional exploration. This
tutorial will concentrate on sm, one of the 2-D varieties, and will touch on a few others. There will also
be some brief discussion regarding animations and ray tracing. Above all note that visualization is about
graphically conveying numerical information to viewers. As a result, there is a certain artistic element
involved that can be hard to master.
A brief word about presentation tools, such as L
A
T
E
Xand PowerPoint, is given at the end.
Visualization
sm
sm is a proprietary product for which the astronomy department has a license. If it’s not already in your
search path, add /local/bin/ to get it.1The advantage of sm is that it has a C-like programming interface;
although it’s easy to plot simple data, it is also possible to make very complex scripts to exploit the full
potential of the graphing package. The entire manual is available online.2
There are 3 ways sm is typically used: 1) interactively; 2) semi-interactively with user-defined macros;
3) semi- or non-interactively with user-built scripts. Method 1 is the fastest for simple data that you don’t
plan to look at again. Method 3 is preferred for complex graphing applications. Method 2 will be discussed
only in passing.
Interactive sm
To use sm interactively, simply type sm. You will be asked to enter a command. Try the following (hit
RETURN after each line):
dev x11
box
relocate 0 0
draw 1 1
If all went well an X window popped up after the device (shorthand dev) command, axes with values
ranging from 0 to 1 appeared, and a diagonal line from the lower left corner to the upper right was drawn.3
Now in another window create a file called sq.dat that looks like this:
1 1
2 4
3 9
4 16
5 25
6 36
7 51
8 64
9 81
10 100
sm interprets whitespace as column delimiters, much like awk. In sm type:
1sm is also available under astromake.
2http://www.astro.princeton.edu/rhl/sm/sm.html
3With some window managers, you may get the error message, “Unknown default colour #000000, using white,” and the
plot may be hard to see. In that case, replace the first line of the example with dev x11 -bg black to force a black background.
1
pf3
pf4
pf5

Partial preview of the text

Download Introduction to Numerical Astrophysics Visualization using sm and Other Tools - Prof. Dere and more Study notes Astronomy in PDF only on Docsity!

Introduction to Visualization

(and presentation tools)

There are a variety of visualization packages suitable for numerical astrophysics applications, ranging from simple 2-D plotters to professional products that support animation and multi-dimensional exploration. This tutorial will concentrate on sm, one of the 2-D varieties, and will touch on a few others. There will also be some brief discussion regarding animations and ray tracing. Above all note that visualization is about graphically conveying numerical information to viewers. As a result, there is a certain artistic element involved that can be hard to master. A brief word about presentation tools, such as LATEXand PowerPoint, is given at the end.

Visualization

sm

sm is a proprietary product for which the astronomy department has a license. If it’s not already in your search path, add /local/bin/ to get it.^1 The advantage of sm is that it has a C-like programming interface; although it’s easy to plot simple data, it is also possible to make very complex scripts to exploit the full potential of the graphing package. The entire manual is available online.^2 There are 3 ways sm is typically used: 1) interactively; 2) semi-interactively with user-defined macros;

  1. semi- or non-interactively with user-built scripts. Method 1 is the fastest for simple data that you don’t plan to look at again. Method 3 is preferred for complex graphing applications. Method 2 will be discussed only in passing.

Interactive sm

To use sm interactively, simply type sm. You will be asked to enter a command. Try the following (hit RETURN after each line):

dev x box relocate 0 0 draw 1 1

If all went well an X window popped up after the device (shorthand dev) command, axes with values ranging from 0 to 1 appeared, and a diagonal line from the lower left corner to the upper right was drawn.^3 Now in another window create a file called sq.dat that looks like this:

1 1 2 4 3 9 4 16 5 25 6 36 7 51 8 64 9 81 10 100

sm interprets whitespace as column delimiters, much like awk. In sm type: (^1) sm is also available under astromake. (^2) http://www.astro.princeton.edu/∼rhl/sm/sm.html (^3) With some window managers, you may get the error message, “Unknown default colour #000000, using white,” and the plot may be hard to see. In that case, replace the first line of the example with dev x11 -bg black to force a black background.

data sq.dat read {n 1 s 2} erase limits n s box points n s

You should see half a parabola worth of “x”s. The read command loaded two vectors—in this example we called them n and s—with the corresponding columns of the data file. The limits command set the plot limits automatically based on the values in n and s. The box command drew the axes (use xlabel and ylabel to make axis labels) and points drew the points. If you don’t like the point size, try expand 2 to make everything double size (you’ll need to redraw the points). You can also experiment with the ptype command (try ptype 3 0 for example). Hint: If your terminal settings are set correctly, you can use the up and down arrow keys to cycle through the command history. Now try the following:

set n2 = n*n connect n n

The set command allows you to make a new vector or modify an existing one. The connect command connects points. You should notice the point for n = 7 lies off the curve (yes, that was deliberate). You may also notice the curve is a bit jagged (particularly if you replot the curve without doing points first). Let’s use 100 points instead:

erase box set i = 1, set n2 = i*i connect i n points n s

(If you’re using expand 2 you’ll notice the axis labels and ticks got bigger.) Note how we were able to create the vector i. Now try this:

ctype red histogram n s

Assuming you’re in front of a colour screen you should now have steps drawn in red going up the curve. If you prefer your histograms to have bars that go all the way down, use barhist 100 n s instead (the optional numeric value specifies the percentage width of the bars). To go back to drawing in the default colour, type ctype default (this is preferable to ctype white because the latter won’t work very well on white paper, whereas the former automatically knows to switch to a black foreground). For more help on a particular function, simply type help function. You may also find the apropos command useful. And there’s always the manual. Some of the most popular commands, in addition to what we’ve seen so far, are: define, do, draw, errorbar, if, ltype, lweight, macro, putlabel, relocate, sort, ticksize, window, and while. Also try help arithmetic to see what math operators and functions are supported, and list device to see what devices are available (e.g. to output everything to an encapsulated postscript file, use dev postencap myfile.eps instead of dev x11).

Scripting sm

The commands in the example above could all be placed in a file, say sq.sm, and read in like this: sm inp new sq.sm. This is useful if you plan to look at data of this nature over and over. It’s particularly useful if you first want to look at the output on the screen and then later print to a file. Note however there were a few erases above, and these cause the plots to flash by. Here’s a way to handle such cases:

drawing package (like POV-Ray, described below) and/or a plotting package (for example, in sm you could output to device blackgif to create a GIF image of a plot). The frames should be numbered consecutively and left-padded with zeroes, e.g. frame001.gif, frame002.gif, etc. for easy manipulation. If you need to keep the frames as well as the movie, the best strategy is to use compressed formats for the frames, otherwise any recognizable format will do.

ImageMagick

Once you have the frames, probably the easiest way to make and view the movie is to use the ImageMagick software suite, which comes standard these days with many Linux implementations, but is also available for free download:

http://www.imagemagick.org/

(Unix, MacOS X, and Windows binaries are available). For example, to make an animated GIF from our sample frames above:

convert frame*.gif movie.gif

It may take a while, so be patient. The convert command is very powerful: not only can it make movies, as in this example, but it can translate between different image formats, including Postscript and PDF. To make an MPEG movie, replace movie.gif in the above example with movie.mpg (ImageMagick uses extensions as cues to file formats). To view the movie, use the animate command, e.g., animate movie.gif (in fact, you can skip the movie-making step altogether and just animate frame*.gif, but often having a single movie file is desirable, such as for a webpage). Finally, if you just want to view a single frame, or do simple interactive manipulations to it, use the display command. For complex image content manipulation, see the brief discussion on GIMP, below.

Other encoders

There are many other free encoders out there. Examples include gifsicle, mpeg encode, ppm2fli, etc.— surf the web to find them. ImageMagick has the advantage of supporting a variety of formats while also being easy to use, but may not offer the same fine-tuning as these more specialized packages. There are, of course, a variety of packages available for purchase that can make very fancy animations with titles, fades, etc., but most are designed for Windows/Mac environments.

Ray Tracers

To make really high quality animations (or stills) that consist of more than dots or line drawings, you need a ray tracer. A ray tracer allows you to construct a world seen from a specific viewpoint, using complicated geometrical shapes and carefully arranged light sources. A very easy-to-use public domain package is the Persistence of Vision Ray Tracer, POV-Ray:

http://www.povray.org/

(be sure to check out the Hall of Fame pictures!) POV-Ray accepts text-format descriptions of worlds that can be transformed quickly into high-quality images.

Presentation Tools

Although not visualization methods per se, presentation tools allow you to convey scientific concepts more easily by incorporating graphics and equations into text.

LATEX

LATEX (or, more specifically, LATEX 2ε) is a powerful text formatting language. Much like code, a LATEX document contains text commands that are compiled into the finished product (typically a postscript file). The language is best illustrated by example:

% this is a comment \documentclass[12pt]{article} \begin{document}

\section{Introduction}

Latex (or \LaTeX) is a powerful text formatting language. You can write in \textit{italics} or \textbf{bold face}. You can \underline{underline} and $\overline{\mbox{overline}}$. Best of all, you can do equations: \begin{equation} E = mc^ \end{equation} or arrays of equations: \begin{eqnarray} \dot{x} & = & z \ \dot{z} & = & x + z \end{eqnarray} Even integrals! \begin{equation} M = \int_x \int_y \int_z \rho(x,y,z), dz,dy,dx \end{equation}

\subsection{Here’s a subsection}

Here’s a table:

\begin{table}[h] \begin{tabular}{l|c|r} Left & Center & Right \ \hline 1 & 2 & 3 \ 4 & 5 & 6 \end{tabular} \end{table}

Here’s how you start a new paragraph (just leave a blank line). Notice how the line is indented.

\subsubsection*{Here’s a subsubsection without a number}

Here’s how you might include a figure:

\begin{figure} \resizebox{\textwidth}{!}{\includegraphics{myfigure.eps}} \caption{Caption goes here.} \end{figure}

(you’ll need a \usepackage{graphics} command in the preamble).