<- Back to Main
Assignment 05 - DUE Friday, March 28th
Reading Assignment:
Data Structures and Fits Tutorial
Read the "Creating IDL structures" and "Reading and writing FITS files" sections.
Introduction
This assignment is based on what Roger was talking about in class during his guest lecture. We will be writing two procedures. One which reads a .FITS file and extracts the image and header information and saves the extracted data to a .SAV file. The second program will read an ASCII (or .Dat file, which is a simple text file.) and resave it as a FITS file.
Make sure you link both of your programs and your .SAV and .FITS file you created on your index page.
The Assignment:
For the following problems, download these files so we have something to play with:
1) FITS files to play with
betelgeuse.fits - A stellar spectrum
eta_hydrae.fits - Another stellar spectrum
hinode.fts.gz - An image of the solar corona with a nice active region. (don't worry about the fact that the extension is different, it will still work to use the following process.)
2) ASCII files to play with
catalog.dat - An ascii data file containing redshift information on 5000 or so galaxies. (From IRAS redshift survey.)
This ascii file has 7 columns. (this is important to know, when you use READCOL.)
gal_cat.dat - An ascii data file containing various parameters for a large number of galaxies. For example it contains both the half-light radius and magnitude of the objects. Open the file in a text editer to see which columns contain which parameters. Try plotting different parameters against eachother.
1) FITS2SAV.PRO
The functions and procedures you will be using are:
readfits() -to look up how to use this, use IDL> doc,'procedurename'
save -IDL> ?save
sxpar() -IDL> doc,'procedurename'
The syntax to call your program should be something like:
IDL> fits2sav, filename, savefilename
a) Your procedure should load the specified FITS file (we're using the provided FITS files for this problem) and save both the header, and image (or data) into separate variables. For this part use READFITS.
b) Using SXPAR(), it should extract the tag, 'exptime' (the exposure time of the image) from the header if you are playing with hinode.fts.gz or extract the 'bunit' (the units of the data) tag if you're using either of the other two files. (Alternatively you can extract which ever tags you want (maybe extract all the tags into an array or structure of values!)). Just print the header and find an interesting looking tag to extract.)
c) Finally, using the SAVE procedure, re-save the extracted header value and the image (or data array) that was in the fits file into a file called 'spectra_sav.sav' or 'sun_sav.sav' or something like that.
In IDL try typing:
IDL> restore,'sun_sav.sav',/verbose
to make sure your program actually saved the variables (the extracted header info and the image).
d) To turn in: Make sure you link both your FITS2SAV program and SAVE.SAV file on your index.html page.
2) ASCII2FITS.PRO
The procedures and functions you will be using are:
readcol() -IDL> doc,'procedurename'
replicate() -IDL> doc,'procedurename'
mwrfits() -IDL> doc,'procedurename'
The syntax to call your program should be something like:
IDL> acii2fits, filename, fitsfilename
a) Your procedure should load an ASCII file (we're using the ASCII files for this problem) into IDL, loading several of the columns into separate variables (remember that when using READCOL, if you want to load the last column of data into a variable, you have to load all of the preceding columns into variables as well).
b) Then make a structure with a number of fields equal to the number of columns you have.
Load at least 2 of the data column variables into the new structure.
*(For CATALOG.DAT, I recomend using the 4th and 5th columns of data because when you plot them against eachother in logx, logy scale, and use an xrange of [1,1000], it makes an interesting pattern. remember to use psym=3 or 7 when you plot!)
*(For GAL_CAT.DAT, open the file in a text editer to check which columns contain which galaxy parameters.)
To make a structure:
IDL> structure={tag1:data1,tag2:data2,tag3:data3}
to extract one of the columns of data, type:
IDL> column=structure.tag1
or a range of data:
IDL> datachunk=structure[x1:x2].tag1
c) Now that you have some data columns loaded into your stucture, your program should make it into a FITS file, using MWRFITS.
IDL> mwrfits,structure,fname
To test to make sure your fits writing program worked, use the function,
READFITS() and try to extract the data structure that you saved.
d) To turn in: Make sure you link both your ASCII2FITS program and FILE.FITS file on your index.html page.
HINTS:
Read the reading assignment! Also, refer to the notes you took in class!
Hunt around on the web for tutorials on using FITS and ASCII!
Use the IDL> DOC,'procname' procedure to look up how to use a procedure. For native IDL procedures (such as save and restore) use ?save and ?restore.
Update: Paul Higgins - January 24, 2007 - UG Astro, Department of Astronomy, University of California at Berkeley