IRAF4Students

From AOB Wiki
Jump to navigation Jump to search

Author: Milan Bogosavljevic

pokreni ds9 &
pokreni xgterm komanda ispod
pokreni irafcl
posle toga step 2


# AOB I Katedra za astronomiju
# SVAP Maj, 2015

# Priprema za obradu podataka i fotometriju u IRAF-u
# Folder "raw" - sadrzi sirova posmatranja: kalibracione snimke i 
# snimke polja u kome se nalazi objekat Qatar-2b
# http://www.openexoplanetcatalogue.com/planet/Qatar-2%20b/
# http://var2.astro.cz/ETD/predict_detail.php?STARNAME=Qatar-2&PLANET=b&PER=&M=


###############################
## Step 1:
## These are general guidelines for a fresh start in using IRAF
###############################

# 1) In Unix command prompt
# Set up IRAF, this sets some preferences and paths to where you are
# the file login.cl with general preferences will be created in
# current directory to take advantage of those preferences, 
# you need to start IRAF from current directory
# choose xgterm when asked

mkiraf

# 2) edit the login.cl which was just created:
# uncomment the line for stdimage setting and
# increase the image buffer size to hold images up to 4096x4096 pixels
# the line should be like this (wihtout the # comment symbol):
# set     stdimage        = imt4096

# 3) launch xgterm with some neat options like a scrollbar

xgterm -sb -sl 1000 &

# 4) Start the IRAF command prompt (from the directory where login.cl was created)
cl

# start ds9

!ds9 &


###############################
# Step 2: raw data processing in IRAF
# redux of 2012_05_09 data
# Qatar 2-b transit; Bogosavljevic/Sekulic; Vidojevica 60cm
###############################

# While in IRAF command prompt:
# 5) make a folder called reduced and copy over raw files into that directory
# it is very advisable to always make this copy so that you can
# redo the process at any time by copying over the raw files 

 !mkdir reduced
 !cp ./raw/*fit reduced/
 cd reduced

# 6) Proceeding with bias, dark, flat corrections of raw data
# make bias list of all Bias files 
#(tip: fast and easy way to work in IRAF is to use lists)

!ls Calib-1*Bias* > bias.list

# 7) examine statistics of bias frames for uniformity
imstat.nclip = 3
imstat @bias.list 

# 8) take a look at one bias frame, examine it

displ Calib-100_Bias.fit 1

# 9) load ccdred package

noao
imred 
ccdred

# 10) combine bias (also called "zero") frames

zerocombine @bias.list output="Zero" combine="median" reject="minmax" ccdtype=""

# NOTE:
# same can be done by editing the parameters of the procedure "zerocombine"
#  with "epar zerocombine" and just changing the above listed parameters 
# (leave other as default), save and exit with ":q",
# or run it with ":go". If exit then run it "zerocombine",
# pressing enter for questions. This applies to all below procedures in IRAF
 
# 11) examine the final combined frame called Zero

displ Zero 2
imstat Zero

# note the decrease in STDDEV
# note that the average bias level is 1376

# 11) make dark list of all Dark files, check their statistics, see how they look like

!ls Calib-1*D60* > dark60.list
imstat @dark60.list 
displ  Calib-104_D60.fit 1

# note that after 60seconds of integration, the average level in the CCD is about 1389
# the temperature of the camera was -25 Celsius
# which means that the dark current electrons added 1389 - 1376 = 13 ADU
# the units recorded by the CCD camera are ADU. The actual eletroncs are 
# obtained when this number is divided by GAIN = 1.2 e-/ADU for this camera.
# so, we got about 13 / 1.2 = 10.8 e- of dark current in this case.

# 12) processing darks (subtracting bias) and combinining them
# set some general parameters for ccdred and ccdproc for ASV CCD camera

 ccdred.verbose=yes
 ccdproc.fixpix = no
 ccdproc.oversca = no
 ccdproc.trim = no
 ccdproc.ccdtype=""

 ccdproc @dark60.list zero="Zero" zerocor+ darkcor- flatcor- 

 darkcombine @dark60.list output="Dark60" ccdtype="" process- combine="median" # reject="minmax"
 
 # Proces- switch means : do not process with ccdproc, as we have already did this 
 # by hand, in the previous step

# does the end result make sense?
 displ Dark60 1
 imstat Dark60

# 13) make a list of twilight flatfield files in the V filter 
# check their statistics, see how they look like
!ls TwiFlat-*V.fit > twiflat_V.list
imstat @twiflat_V.list 

# For flats, it is very important to check them all visually
displ TwiFlat-010_V.fit 1
displ TwiFlat-011_V.fit 2
displ TwiFlat-012_V.fit 3
displ TwiFlat-013_V.fit 4
displ TwiFlat-014_V.fit 5

# what do you see if you flip trough these images (hit TAB key in DS9)?
# why is the light dropping of towards the edges?
# are there stars caught in the twilight flat?
# - we must get rid of those!

# 14) process flats (subtract bias, dark) and combine them

 ccdproc @twiflat_V.list zero="Zero" dark="Dark60" zerocor+ darkcor+ flatcor- 

# note that the dark frame used was Dark60,
#  and IRAF noted it was scaled to exposure of flats

# 15) combine the processed flats
 flatcombine @twiflat_V.list output="MasterFlatV" ccdtype="" process- scale="median"

# 16) examine the result

 displ MasterFlatV 1
 
# NOTE: stars have been averaged out! This is why we must dither (move the telescope)
# slightly when taking twilight flat frames!

# 17) Finally, processing science frames  
# subtracting bias, dark and then flatfielding all of them
!ls Qatar2b-*fit > qatar.list

ccdproc @qatar.list zero="Zero" dark="Dark60" flat="MasterFlatV" zerocor+ darkcor+ flatcor+

# with the above 3 steps you finished the data reduction in IRAF (bias, flat field, dark correction)
# next you move to the magnitude measurements

# 18) Check the header of any of the finally processed data frames:

 imhead Qatar2b-239_V.fit l+

# This is how a finished processing job should look like at the end:
#ZEROCOR = 'May 19 14:13 Zero level correction image is Zero'
#DARKCOR = 'May 19 14:13 Dark count correction image is Dark60 with scale=1.'
#FLATCOR = 'May 19 14:13 Flat field image is MasterFlatV with scale=30623.51'
#CCDSEC  = '[1:2048,1:2048]'
#CCDMEAN =             536.6693
#CCDMEANT=           1116511997
#CCDPROC = 'May 19 14:13 CCD processing done'


 # 19) Go to DS9 and remove all current frames by going in the menu:
 # Frame -> Delete All Frames
 # now compare a raw and processed science frame

 displ ../raw/Qatar2b-239_V.fit 1 zscale+
 displ Qatar2b-239_V.fit 2 zscale+

 # you can also press scale and select zscale in the DS9 window
 # compare the two images
 # what have we gained?
 # was the flatfielding in the reduction able to completely remove the effect of vigneting?

#####################################################################################


##############################
# Step 3: APERTURE PHOTOMETRY
##############################

# make a reference.dat file - what are the x,y coordinates of the objects you want to measure?
# lets take three objects - a check star, a comaprison star and the target

# Compare this
# http://var2.astro.cz/ETD/predict_detail.php?STARNAME=Qatar-2&PLANET=b&PER=&M=
# with the first frame

displ Qatar2b-101_V.fit 1

# note that the image looks flipped in the X axis (why could that be?)
# Do Zoom -> Invert X in DS9 to make life easier

# The star with the Qatar-2b planet is the one in the middle, close to 
# (x,y) = (1060,920)
# click on the star in DS9. A green circle should appear.
# Make sure the circle is selected (active) and go to the menu and click
# Region -> Centroid 
# then double click the circle to see its properties
# you will see the center as (1062, 919)

# Do the same for objects at (740,711) which we will take as comparison star
# and (1374, 1716)
# DONT FORGET THE DISPLAYED IMAGE IS FLIPPED IN X (coordinates are larger to the left)

# as in the exercise with the fake data
# make a reference.dat file containing these x and y of three objects
# (no commas between x and y)
# copy it so that it is also a .coo file for the first frame 

!cp reference.dat Qatar2b-101_V.coo

# check it once more
displ Qatar2b-101_V 1
tvmark 1 reference.dat mark="circle" radii=20

# calculate offsets using python code
!cp ../offsets_qphot.py .
!cp ../reference.dat .
!python offsets_qphot.py

# when promtped answer:
# Enter file with the list of images to be processed: qatar.list
# Enter file with object x,y coordinates in the reference frame: reference.dat
# The code will display a plot of all the X and Y offsets. 

# Can you understand why are the X shifts continually drifting?
# Its the telescope tracking innacuracy!
# Why is there a sudden jump at frame 90 in Y shifts?
# Somebody adjusted the field by moving the telescope at that time!
# Close this plot to continue.

# make the list of all the  .coo file

!ls Qatar*coo > coolist

# load the IRAF apphot package
noao 
digiphot
apphot

# set parameters of qphot which are instrument dependent

# FITS keywords for filter, time and exposure
# and some instrument and data specific parameters: CCD camera gain 
# and magnitude scale flux zeropoint (if known, or taken arbitrary setpoint)
# for the case of Qatar*.fit files in this exercise:

qphot.obstime="date"
qphot.exposur="exptime"
qphot.zmag = 20.
qphot.epadu= 1.2

# set sizes of annuli for measuring stars
# centering box size (qphot star will recenter the target positions)
# measuring aperture for star, and for sky inner radius and sky outer radius

qphot.cbox = 5.
qphot.annulus=20.
qphot.dannulus=20.
qphot.aperture=10.

qphot @qatar.list coords=@coolist interac-
# just hit enter when prompted, the defaults have been set in the earlier step

# QPHOT creates output files of the type QatarXXX.fit.mag.1 
# It contains various measurements of relevance to the aperture photometry
# there is one file for every image, with three different sources measured
# To convert this output into something more basic, you can use
# IRAF txdump command - it will print out just the columns you request
# but it will do so for all three sources

txdump Qatar*.mag.1 image,otime,xcenter,ycenter,mag,merr yes > all_measurements.dat

# extract the three sources separately for convenience of analysis
# the sed commands below extract the first line and then every third, 
# or the second and every third and so on.
!sed -n 'p;n;n;' all_measurements.dat >! target.dat
!sed -n 'n;p;n;' all_measurements.dat >! comparison.dat
!sed -n 'n;n;p;' all_measurements.dat >! check.dat

# use your favorite plotting software to plot the difference between target and comparison
# overplot the total error (propagate magnitude errors in quadrature!)
# Here is what I got as a result qatar2b-exercise.jpeg

# Lets check the magnitude of our check star, and the  difference between comparison and check.
# if everything is in order and our comparison and check stars are not variable, 
# the difference should be constant.

# Examine check.dat. Wait. what? Magnitudes are jumping up and down, and going to INDEF.
# Is there a problem? Seems like qphot could not measure anything in frame Qatar2b-122_V.fit
# And there is a jump in five magnitudes between 109 and 110. Smells like a crude error.
# Lets see what is going on.

# delete all frames in DS9 and then
displ Qatar2b-101_V.fit 1
displ Qatar2b-110_V.fit 2
# blink them. Look at the positon of the chosen check star. 
# Still dont see anything strange?
# how about now?
displ Qatar2b-120_V.fit 3
displ Qatar2b-130_V.fit 4
displ Qatar2b-140_V.fit 5
displ Qatar2b-150_V.fit 6

# use TAB in DS9 to flip trough the 6 frames.
# IT'S MOVING! Congratulations. You just discovered an asteroid (or a new Solar System planet?)
# by accident. It happens. Always - always be on the lookout and check-check-doublecheck your data.

# Do you know how to use the information from the header of the CCD image and go to
# Minor Planet Center Checker and find out if this is a known asteroid?