View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

Dealing with ESO HIERARCH keywords (KEYRENAME and RMHIERARCH scripts)

Frank Valdes wrote on May 08, 2000

Q:  I would like to know, how i can translate the header keywords of
my fits files into the right one, so that the iraf tasks understand
them.

I created a translation file and ran setinstrument, but things 
are not working ...

Maybe there is a mistake in the translation file?
it looks like that:

-------------------
subset		'HIERARCH ESO INS OPTI-2 NAME'
imagetyp        'HIERARCH ESO INS OPTI-2 NAME'

DK		dark
bias		zero
SCI		object
-------------------

I will attach one of the image headers.

********************************************************************

SIMPLE  =                    T / Standard FITS format                           
BITPIX  =                   16 / 16-bit numbers, in 2's complement              
NAXIS   =                    2 / Simple 2-D array                               
NAXIS1  =                 2102 / Dimension along the x-axis                     
NAXIS2  =                 2052 / Dimension along the y-axis                     
BSCALE  =                   1. / REAL=TAPE*BSCALE + BZERO                       
BZERO   =               32768. / Offset applied to true pixel values            
CRPIX1  =                   1. / x ref. pixel of instrument optical axis        
CRPIX2  =                   1. / y ref. pixel of instrument optical axis        
CRVAL1  =                   1. / Physical coordinate of CRPIX1                  
CRVAL2  =                   1. / Physical coordinate of CRPIX2                  
CDELT1  =                   1. / Increment unit along x-axis                    
CDELT2  =                   1. / Increment unit along y-axis                    
TM_START=             84819.00 / '23:33:39.00' measurement start time (UT)      
TM_END  =             85100.00 / '23:38:20.00' measurement end time (UT)        
TELESCOP= 'Danish 1.54m'       / Telescope identification                       
INSTRUME= 'DFOSC'              / Instrument used                                
OBSERVER= ' '                  / Name of the observer                           
ORIGIN  = 'ESO-LA SILLA'       / Tape writing institution                       
FILENAME= 'dfsc0050.mt'        / Name of this file                              
DATE    = '2000-04-21'         / Date file is written (UT)                      
DATE-OBS= '2000-04-21'         / Date of observation (UT)                       
MJD-OBS =        51655.9817014 / Start of observation = 2000/04/21 23:33:39.00  
EXPTIME = 200.000              / Integration time (secs)                        
OBJECT  = 'Hen3-600'           / Original target designation                    
AMPLM   =  'A       '          / A / B or AB                                    
CCDTEMP =               -100.0 /                                                
MPP     =                    1 /                                                
ST      =             31918.70 / ' 8:51:58.70' sidereal time at start           
RA      =             11.17481 / '11:10:29.32' right ascension at start         
DEC     =            -37.53439 / '-37:32:03.80' declination at start            
HA      =               2.30847 / Hour Angle at start                           
ZDIST   =              29.90000 / Zenith distance at start                      
CAMERA  = '2375'               / DFOSC Camera focus                             
ROTATOR = '-90.0'              / DFOSC Rotator angle                            
HIERARCH ESO GEN EXPO TYPE  = 'SCI'           / Type of exposure                
HIERARCH ESO TEL ID         = 'Danish 1.54m'  / Telescope identification        
HIERARCH ESO INS OPTI-1 NO  =               8 / Wheel#1 position                
HIERARCH ESO INS OPTI-1 ID  = ' '             / Optical element identification  
HIERARCH ESO INS OPTI-1 TYPE= 'SLIT    '      / What is this element            
HIERARCH ESO INS OPTI-1 NAME= 'FREE'          / Filter name                     
HIERARCH ESO INS OPTI-2 NO  =               1 / Wheel#2 position                
HIERARCH ESO INS OPTI-2 ID  = 'ESO#632*'      / Optical element identification  
HIERARCH ESO INS OPTI-2 TYPE= 'FILTER  '      / What is this element            
HIERARCH ESO INS OPTI-2 NAME= 'ESO U'         / Filter name                     
HIERARCH ESO INS OPTI-3 NO  =               8 / Wheel#3 position                
HIERARCH ESO INS OPTI-3 ID  = ' '             / Optical element identification  
HIERARCH ESO INS OPTI-3 TYPE= 'GRISM   '      / What is this element            
HIERARCH ESO INS OPTI-3 NAME= 'FREE'          / Filter name                     
HIERARCH ESO INS OPTI-4 NO  =               0 / Wheel 4 position                
HIERARCH ESO INS OPTI-4 ID  = ' '             / Optical element identification  
HIERARCH ESO INS OPTI-4 TYPE= 'FILTER B'      / What is this element            
HIERARCH ESO INS OPTI-4 NAME= 'Free'          / Filter name                     
HIERARCH ESO INS OPTI-5 NO  =               0 / Wheel 5 position                
HIERARCH ESO INS OPTI-5 ID  = ' '             / Optical element identification  
HIERARCH ESO INS OPTI-5 TYPE= 'FILTER A'      / What is this element            
HIERARCH ESO INS OPTI-5 NAME= 'Free'          / Filter name                     
HIERARCH ESO DET NAME       = 'LORAL 2k x 2k' / Detector name                   
HIERARCH ESO DET ID         = '2K3EB C1W7'    / Detector identification         
HIERARCH ESO DET BITS       =              16 / ADU bits per pixel              
HIERARCH ESO DET FRAM NAXIS1=            2102 / Number of pixels along horizonta
HIERARCH ESO DET FRAM NAXIS2=            2052 / Number of pixels along vertical 
HIERARCH ESO DET FRAM CRPIX1=              1. / Reference pixel                 
HIERARCH ESO DET FRAM CRPIX2=              1. / Reference pixel                 
HIERARCH ESO DET FRAM CDELT1=              1. / Binning factor along horizontal 
HIERARCH ESO DET FRAM CDELT2=              1. / Binning factor along vertical ax
HIERARCH ESO DET FRAM CRVAL1=              1. / Position of window along horizon
HIERARCH ESO DET FRAM CRVAL2=              1. / Position of window along vertica
HIERARCH ESO DET MODE       = 'HIA'           / Readout mode                    
HIERARCH ESO DET UDIT       =          200.00 / User defined exposure time (sec)
                                                                                                                                                              

A: The HIERARCH keywords are a non-standard FITS format which cannot be
used directly by IRAF.  IRAF considers any keyword to be 8 characters
at most followed by the equal sign.  So you need to translate those
keywords in some way.  You could ask the data providers (ESO or
whomever) if they can provide the images with standard 8 character FITS
keywords.  Alternatively you will need to edit the headers to
create 8 character names.

This can be done with the HFIX task calling some filter routine to
modify the header.  Below I include a filter script which you should
cut out into your home$ directory and define.  The filter script uses
a translation file. I made a minimal one for you that translates the
image type and the filter names:

HIERARCH ESO GEN EXPO TYPE  = IMAGETYP
HIERARCH ESO INS OPTI-1 NAME= FILTER1
HIERARCH ESO INS OPTI-2 NAME= FILTER2
HIERARCH ESO INS OPTI-3 NAME= FILTER3
HIERARCH ESO INS OPTI-4 NAME= FILTER4
HIERARCH ESO INS OPTI-5 NAME= FILTER5

This is not the translation file for CCDPROC.  For that you would then
have something like what you tried:

subset	FILTER2

SCI		object


For ESO WFI data, the 8K mosaic, there is a different task that is used
to remove the HIERARCH keywords.  This is part of the ESOWFI external
package.  As part of that package there is a hidden task (which users
can call use directly) comparable to KEYRENAME.  It is called
RMHIERARCH.  The difference is that that script uses an algorithm for
making the translations.  It removes a specified number of leading
characters in the HIERARCH keyword and maps the remainder to 8
characters.  The source for that task can also be found in
adass.iraf.sources.  The source for KEYRENAME may also be found in that
newsgroup.

==== keyrename.cl =====
# KEYRENAME - Rename FITS keywords.
# 
# A keyword translation file of the form
# 
#    xxxxxxxxx=yyyyyyy
# 
# is used to translate FITS keywords in the input text file to create an
# output text file.  All lines with no translation are left unchanged.  The
# file to be translated is often generated by the HFIX task from an image
# header.  Note that if the input and output filenames are the same then the
# modified version will replace the input version when the task completes.
# 
# The string
# to the left of the equal sign is matched exactly against the string to
# the left of the equal sign in the input file being edited.  Note that blanks
# are significant.  A common example is translating the ESO HIERARCH
# keywords using a translation file such as
# 
#   HIERARCH ESO GEN EXPO TYPE  = IMAGETYP
#   HIERARCH ESO INS OPTI-1 NAME= FILTER1
#    
# If a match is found the string to the right of the equal sign is
# substituted.  The substitution will be just the first word and it will be
# padded to the 8 character FITS keyword length.  In the above example
# the input and output lines will look like
# 
#   in:  HIERARCH ESO GEN EXPO TYPE  = 'SCI'           / Type of exposure
#   in:  HIERARCH ESO INS OPTI-1 NAME= 'ESO U'         / Filter name
# 
#   out: IMAGETYP= 'SCI'           / Type of exposure
#   out: FILTER1 = 'ESO U'         / Filter name
# 
# This task is commonly used with the task HFIX in a command such as:
# 
#     cl> hfix eso.fits command="keyrename $fname $fname trans.dat"
# 
# To define this task, copy it to your home directory.  Then in your login.cl
# or loginuser.cl files or interactive enter:
# 
#     task keyrename = home$keyrename.cl
# 


procedure keyrename (input, output, translation)

file	input		{prompt="Input filename"}
file	output		{prompt="Output filename"}
file	translation	{prompt="Translation filename"}

struct	*fd1, *fd2

begin
	file	in, out, trans, tmp
	string	key1, value
	struct	line, key
	int	idx

	# Read query parameters.
	in = input
	out = output
	trans = translation

	# Set temporary file if the input and output filenames are the same.
	if (in == out)
	    tmp = mktemp ("tmp$iraf")
	else
	    tmp = out

	# Scan each line in the input and translate.
	fd1 = in
	while (fscan (fd1, line) != EOF) {

	    # Find the equal sign and pass lines without one.
	    idx = stridx ("=", line)
	    if (idx == 0) {
		printf ("%s\n", line, >> tmp)
		next
	    }

	    # Extract the keyword part and the value part.
	    key = substr (line, 1, idx-1)
	    value = substr (line, idx, 80)

	    # Search for match in the translation file.
	    fd2 = trans
	    while (fscan (fd2, line) != EOF) {
		idx = stridx ("=", line)
		if (idx == 0)
		    next

		key1 = substr (line, 1, idx-1)
		if (key1 == key) {
		    key1 = substr (line, idx+1, 80)

		    # Strip whitespace and format to 8 characters.
		    printf ("%s\n", key1) | scan (key1)
		    printf ("%-8.8s\n", key1) | scan (key)

		    break
		}
	    }
	    fd2 = ""

	    # Output line with translation if one was found.
	    printf ("%s%s\n", key, value, >> tmp)
	}
	fd1 = ""

	# Replace input with output if the names are the same.
	if (in == out) {
	    delete (in, verify-)
	    rename (tmp, out, field="all")
	}
end
====

Last post on May 08, 2000