Welcome to iraf.net Friday, February 23 2018 @ 06:36 AM GMT


  • Monday, May 08 2006 @ 08:41 PM GMT
  • Contributed by:
  • Views: 4,219
Code Snippets For quite a while now users have been running into problems associated with the ESO convention of using HIERARCH keywords in their headers. This became a common enough issue that we developed a script to help deal with it. That script never made it into the core system, but the explanatory text and script itself is posted here.

I am trying to use hselect task for selecting images by header field. Apparently this task does not recognize long header fields like those frequently used by ESO telescopes. For example the field "HIERACH ESO INS GRAT1 NAME" and similars are not recognized.

You may be aware that the ESO HIERARCH convention doesn't conform to the FITS standard. In general FITS keywords have to be shorter than eight characters and can't contain blanks. ESO gets away with this (partially) since FITS software has to be able to handle HISTORY and COMMENT keywords (as well as so-called "blank" keywords) that don't actually have any value (that is, no equals sign with a value on the other side). HIERARCH keywords basically have the same syntax as these FITS comment keywords - the equals sign is really just part of a comment string along with the rest of the hierarchical fields starting with "ESO".

Most FITS readers place the fewest possible constraints on the headers. Certain keywords must be present and obey certain rules - other keywords are typically just copied over. Note that most astronomical packages also borrow the FITS keyword rules for their internal image formats (like IRAF .imh images). You don't specify what image format you are dealing with, but it seems likely that your data started as ESO FITS.

However, while the headers are readable and the HIERARCH keywords don't cause any overt errors, there is no plumbing in IRAF to support this ESO convention directly. As you found, hselect doesn't know what to do with these keywords.

I have appended a CL script that provides a partial solution to this problem. The "esoselect" script will accept a list of images and a single keyword and value to match. The names of images that have the specified value for the specified keyword will be printed out.

Copy the remainder of this message below "cut here" into a file "esoselect.cl" in a convenient directory. Declare the iraf task with:

        task esoselect = /esoselect.cl
where is replaced by the full pathname you picked. At this point you should be able to "lpar esoselect" and otherwise treat it like any other IRAF task, including using esoselect in a script. The task statement can be placed in your login.cl file or loginuser.cl file (followed by a keep at the end) so you won't need to type this in the future.

To execute the task use a command like:

        cl> esoselect *.imh "hierarch eso ins grat1 name" "name for grating 1"

Note that strings containing whitespace should be quoted as usual. The keyword name will be converted to upper case as necessary, but the value string is case sensitive.

You can redirect the standard output into a file or pipe it to another task for further processing.

procedure esoselect (images, keyword, value)

string  images          {prompt="input image list"}
string  keyword         {prompt="keyword to examine"}
string  value           {prompt="value to match"}

string  *list           # used internally, but must be list-directed parameter

        string  limages, lvalue, img, tmp, test
        struct lkeyword, keyval
        int     len, idx

        tmp = mktemp ("tmp$junk")

        # referencing query parameters will cause prompt,
        # so read into local variables for later use
        # (note that keyword names should always be upper case in headers)
        limages = images
        print (keyword) | ucase | scan (lkeyword)
        lvalue = value

        # expand the image template into an explicit list
        sections (limages, opt="fullname", > tmp)

        # step through the image list
        list = tmp
        while (fscan (list, img) != EOF) {
            keyval = ""

            # match the keyword names at the beginning of lines only
            imhead (img, long+, user+) | match ("^" // lkeyword, stop-, meta+) |
                scan (keyval)

            # trim off the keyword name and equals sign
            len = strlen (keyval)
            idx = stridx ("=", keyval)
            print (substr (keyval, idx+1, len) | scan (keyval)

            # trim off leading whitespace (and quote if keyword is a string)
            test = substr (keyval, 1, 1)
            while (test == " " || test == "'") {
                len = strlen (keyval)
                keyval = substr (keyval, 2, len)
                test = substr (keyval, 1, 1)

            # trim off any "/" delimited comment
            idx = stridx ("/", keyval)
            if (idx > 1)
                keyval = substr (keyval, 1, idx-1)

            # trim off trailing whitespace (and quote or slash)
            len = strlen (keyval)
            test = substr (keyval, len, len)
            while (test == " " || test == "'" || test == "/") {
                keyval = substr (keyval, 1, len-1)
                len = strlen (keyval)
                test = substr (keyval, len, len)

            if (keyval == value)
                printf ("%sn", img)

        delete (tmp, ver-, >& "dev$null")

ESOSELECT -- HSELECT for ESO HIERARCH Keywords | 0 comments | Create New Account

The following comments are owned by whomever posted them. This site is not responsible for what they say.

Privacy Policy
Terms of Use

User Functions