View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

efficient way of finding imstat of an echelle spectra

rohit wrote on Apr 09, 2010

I would like to obtain the mean flux for each of the orders in my echelle spectra. Using just the command:

imstat filename

gives me the mean of the entire spectra. However I would like to find for each order. For this I wrote the following script:

ls > 20070430-GJ1156free.dat
scopy 20070430-GJ1156free.fits ord01.fits aperture=1
scopy 20070430-GJ1156free.fits ord02.fits aperture=2
scopy 20070430-GJ1156free.fits ord03.fits aperture=3
scopy 20070430-GJ1156free.fits ord04.fits aperture=4
scopy 20070430-GJ1156free.fits ord05.fits aperture=5
scopy 20070430-GJ1156free.fits ord06.fits aperture=6
scopy 20070430-GJ1156free.fits ord07.fits aperture=7
scopy 20070430-GJ1156free.fits ord08.fits aperture=8
scopy 20070430-GJ1156free.fits ord09.fits aperture=9
scopy 20070430-GJ1156free.fits ord010.fits aperture=10
print "Done with breaking the files..................."
imstat ord01.fits
imstat ord02.fits
imstat ord03.fits
imstat ord04.fits
imstat ord05.fits
imstat ord06.fits
imstat ord07.fits
imstat ord08.fits
imstat ord09.fits
imstat ord010.fits
print "Done with imstat.................................."
del ord*

Basically I create a dummy .dat file, break the spectra into orders and imstat each order. I copy the values from the screen and paste them in the dummy dat file, I created. It works but is there a more efficient way of copying the imstat values of each order in a file directly?

Thanks!

Rohit

Francisco Valdes wrote on Apr 09, 2010


for (i=1; i<=10; i+=1) {
    printf ("%s[*,%d]\n", "20070430-GJ1156free", i) | scan (s1)
    imstat (s1)
}


The use of parenthesis and quotes is important in "programming" mode to distinguish variables (like i and s1) from fixed strings like the image name. Clearly there are many variations you can use including:


imstat (s1, > "output.dat")


To capture the output. Also if your image is 3D (because of extra bands) then you would use "%s[*,%d,1]".

Yours,
Frank Valdes

rohit wrote on Apr 09, 2010

Thanks Frank. Just one wrinkle in the code. When I set the output, IRAF is unable to write to it recursively because the file seems to exist. So the code you suggested:

for (i=1; i<=10; i+=1) {
    printf ("%s[*,%d]\n", "20070430-GJ1156free", i) | scan (s1)
    imstat (s1, > "output.dat")
} 

give me the following error:


echelle> cl < scopy2.cl 
ERROR: cannot open `output.dat' for writing
     called as: `cl ()'
echelle> 


Opening the output.dat file, I see that IRAF has written the first line. So it looks like IRAF creates the file, writes the first line and tries to create the same file again for the second line. It does not overwrite and therefore stops. But I thought the whole thing was in the loop. So why it does not work?

Francisco Valdes wrote on Apr 09, 2010

Sorry, instead of '>' use '>>' to append on each iterations. Frank

Last post on Apr 09, 2010