AST 443: Notes on Computing

Now that you should all have accounts at the Math sinc site, and have logged in succesfully, here are some notes that may help you.

UNIX commands

Navigation
When you log in, you are in your home directory /home/username where username is the name you used to log in with. You may have subdirectories in your home directory. Create them with mkdir. Use subdirectories to organize your files. Use the cd command to change directories. Don't know where you are? Type pwd.

UNIX is case-sensitive. ls and LS are two different commands.

There are many variants of UNIX. I use the C-shell. Type tcsh to use this shell. If you want to use the bash shell, or any other shell, you are on your own!

You can run any UNIX command in the background by adding an ampersand (&) to then end of the command line. For example, to run netscape in the background, so you can use the terminal window for other things, type netscape &.

UNIX Mail
UNIX mail is neither intuitive or user friendly. In order to send mail, you would type: mail addressee, where addressee is the e-mail address of the intended recipient. You then type your mesage. End the message with a line that contains a single period. You will get a CC: prompt; you may enter other addresses here.

To send a subject line, add -s "subject line" to the mail command.

To send a file, append <filename to the mail command.

For example, to send your mock HST proposal, a file named hst_proposal.tex, to me, you would type the following:
mail -s"my HST proposal" fwalter@astro.sunysb.edu <hst_proposal.tex

Logging Out
When you are done, you must log out. Generally this is done by moving the mouse to a blank part of the window, and right-clicking. Look for a "logout" option. You will need to confirm the logout.

Running IDL

IDL should be in your path. If the command which idl returns the string /usr/local/bin/rsi, or something similar, you are in business. Otherwise, you will have to find the location of the IDL executable and add it to your path.

Start by typing idl. Need help? Type a question mark (followed by a return). This brings up the help manual (a pdf file). Read this at your leisure.

A better manual is Fanning's "IDL Programming Techniques". You may read this as a pdf file on the Blackboard page for this course (go to Course Documents)

There are a number of good web sites devoted to IDL programming. Among these are:

But before you go to any of the above-mentioned sites, read the following primer first.

Using IDL

A primer on IDL

IDL is a powerful language, with many intrinsic capabilities. It can be run interactively, line by line, from the terminal, or you can create programs (called procedures) which you can then run. The syntax is very similar to FORTRAN, so a user familiar with FORTRAN should have little difficulty coming up to speed in IDL (however, it takes years to become expert). Unlike Fortran or C, IDL code need not be compiled and linked. You can stop a procedure anywhere in the code, and examine intermediate results, change values, or do whatever you might think of doing. The best advice is, as often, to read the online manuals before you begin.

To run IDL, type idl.

Note that, unlike UNIX, IDL is not case-sensitive. However, file names are, because IDL must interesct with the operating system to find files. The IDL commands that follow are capitalized to distinguish them from the text; they need not be.

On some systems (including the Math sync site), the default "backing-store" is turned off. This means that the contents of a graphics window can be lost when the window is pushed into the background. To overcome this nuisance, type the command device, retain=2 upon starting IDL. If you will need to do this often, you might consider puting it in an IDL startup file.

IDL recognizes a lot of variable types, including

Once you start IDL, you should check your default directory. One way to find where you are is to type
CD,CUR=CUR & PRINT,CUR. If you are not where you want to be, you can use the CD command. CD is like the UNIX cd command, but it needs a string argument, as in CD,'new_dir'.

In addition to the intrinsic capabilities there exists a large and growing library of user-supplied routines. The most useful for our purposes is the Astronomy Users Library. These routines are in /home/fwalter/pro, and should be in your IDL_PATH. A brief description of the contents is in /home/fwalter/contents.txt.

For the most part, you will only need primitive IDL commands for displaying and measuring your data. The data files are generally in FITS format, which you can easily read in IDL by following these instructions. The data will then consist of a header H (a string array) and a data array D, which may be multi-dimensional.

Pointers on Using IDL

Pointers on IDL graphics

Acquaint yourself with the PLOT and TV commands. Use PLOT for line plots; use TV to display images.

The simplest graphics/display software in idl is written for single-plane, 256 color graphics. I don't know whether of not the Suns can deal with 24-bit color (true colors). If your plots come up black, or you can't get color tables to work, try DEVICE,DECOMPOSED=0. Feel free to experiment with colors.

Unpacking Dimensions

It is easy to extract M-dimensional data from N-dimensional data. For example, given a 2-dimensional array of spectra D (as you get from the IUE high dispersion data), you can extract the nth row with the command S=D(n,*), or the nth column with the command S=D(*,n)

Reading FITS Files

Read FITS files with READFITS. READFITS, a function, returns a parameter (the data array). To read a file, type
data = readfits("my_fits_file.fits",header)
Data is an array containg the data; header is a string array containing the FITS header. The fits file name is a string, and must be enclosed in quotes (unless it is a string variable). Use SXPAR to extract values from the fits header.

READFITS can read gzipped file (those with .fits.gz extensions): there is no need to uncompress the file first with gunzip.

More information about FITS files and reading FITS extensions is here.

Plotting and Measuring Data

For one-dimensional data (e.g., spectra), use the PLOT command. Set the plot scale and range with SET_XY.

Two-dimensional data can be displayed using the TV. Note that the window displays byte values, and PLOT does not do any byte-scaling. Use TVSCL,data or TV,BYTSCL(data) to scale your data appropriately. Note that, if you have a few pixels that are very much brighter than the others, you may not see much. This is because the full range is compressed into about 256 intensity levels. Use the < operator to truncate the image (e.g., TVSCL,data<500 will plot all pixels with values >500 as 500. Used in this manner, the operator does not overwrite the data.).

Using the Cursor to Measure Positions

The basic way to measure a value on the screen is with the CURSOR command. Type CURSOR,X,Y. Click the left mouse button at the point of interest, and then PRINT,X,Y to get the values back. On a 2-dimensional image, X and Y will be the pixel number, and the value at that point is IMAGE(X,Y).

In order to use the CURSOR command for images, you need to set up the plot limits properly (there may be more elegant methods, but this works!).

s=size(image)                  ;this returns a vector containing the size
                               ;of the image. s(0) is the number of dimensions,
                               ;which should be 2 for an image array
sx=s(1)                        ;size of X dimension
sy=s(2)                        ;size of Y dimension
window,xsize=sx,ysize=sy       ;create window the size of the image
!p.position=[0,0,1,1]          ;plot boundaries are window boundaries - there
                               ; are no margins
set_xy,0,sx-1,0,sy-1           ;set plot limits
!x.style=1 & !y.style=1        ; force exact plot boundaries
plot,indgen(10)                ;this dummy plot will define the plot limits
tvscl,image                    ; display image
x=sx/2 & y=sy/2                ; initialize to center of plot
cursor,x,y                     ; use cursor command to get position

Problems

On occasion, a procedure will encounter an error and stop. You will know this has happened when you see an error message followed by a traceback like
% Attempt to subscript K with  is out of range.
% Execution halted at:  DBHELP            192
  /data/gremlin/fwalter/astrolib/pro/database/dbhelp.pro
%                       $MAIN$
When this happens, you can either try to fix the problem, or bail out. The latter is generally recommended unless you know what you are doing. To bail out, type RETALL. This will close the procedure and return to the main level.

Other programs under UNIX

Accessing Data

Your SMARTS data are on the mathlab computer, in /mt/cootie/home/fwalter/data and its subdirectories. You can read these files directly, as in

data=readfits('mt/cootie/home/fwalter/data/XXX.fits',header)
. Note that you need to type the full path (including any other subdirectories) every time.
Use cp to copy the data to your own directory, or scp to copy to another computer.

Back to top