irprocexpr (Mar05) | irred | irprocexpr (Mar05) |
The irproc task uses of expressions which treat keywords and pixel values as operands. The expressions are used to select and group images, provide sort keys, evaluate exposure times, apply a non-linearity corrections and idenitfy bad pixels. The expressions provide a great deal of flexiblity and accomodate data from different instruments within and between observatories.
The expression syntax follows common algebraic and programming rules. For instance it is the same as available in the CL. The main things to understand are what constitutes a operand, what type of final value is required, and what functions are provided.
Expressions consist of operands, numeric and string constants, operators, and functions. Parentheses are also used to control the evaluation order as in standard algebraic expression. String constants are quoted strings and numeric constants are pure unquoted numbers. Numbers may be given in sexagesimal notation and are automatically converted to decimal numbers. The operators are arithmetic, logical, and string.
One feature of the irproc parameter values where the expressions are specified is that the expression may be read from a file using the @file syntax. This is useful if expressions are long. In the file newlines may be used make the expression more readable.
Except for the bad pixel and linearity correction expressions the only operands are keyword names. This means a operand is anything that is allowed for a keyword name and which is not quoted in the expression. There is one exception for keywords that include the characters that correspond to the operators in expressions. In this case the keyword is quoted as a string and then referenced as a keyword using a leading @ character; e.g. @"date-obs".
In the bad pixel and linearity expressions the values of pixels in the image being processed. The linearity expression also allows using the values of pixels representing coefficients in a linearity coefficient image as operands. The pixels in the image being processed are referenced by the operand $I. The pixels in the coefficient image are reference by $C1, $C2, etc. The number refers to the element of the third dimension of the coefficient image.
There are some special operands that relate to standard elements of an image and may not be the same as the FITS keywords. These are
title - title of the exposure naxis - number of axes naxis1 - number of pixel along the first axis naxis2 - number of pixel along the second axis
The following operators are recognized in expressions. With the exception of the operators "?", "?=", and "@", the operator set is equivalent to that available in the CL.
+ - * / arithmetic operators ** exponentiation // string concatenation ! - boolean not, unary negation < <= > >= order comparision (works for strings) == != && || equals, not equals, and, or ?= string equals pattern ? : conditional expression (ternary operator) @ reference a operand
The operators "==", "&&", and "||" may be abbreviated as "=", "&", and "|" if desired. The ?= operator performs pattern matching upon strings. The pattern syntax is that described for the task match. The @ operator is required to reference keywords with one of the operator characters. This is most likely to be used as:
@"date-obs"
A point to be aware of is that in the ?: conditional expression both possible result values are evaluated though the result of the expression is only one of them.
A number of standard intrinsic functions are recognized within expressions. Many of these may not be useful in the context of the irproc expressions but are part of the language. The set of functions currently supported is shown below.
abs atan2 deg log min real sqrt acos bool double log10 mod short str asin cos exp long nint sin tan atan cosh int max rad sinh tanh
The trigonometric functions operate in units of radians. The min and max functions may have any number of arguments up to a maximum of sixteen or so (configurable). The arguments need not all be of the same datatype.
A function call may take either of the following forms:
<identifier> '(' arglist ')' <string_expr> '(' arglist ')'
The first form is the conventional form found in all programming languages. The second permits the generation of function names by string valued expressions and might be useful on rare occasions.
There are a number of additional functions in addition to the above intrinsic functions. One may be particularly useful for irproc to map arbitrary strings in keywords to the same value for grouping or to translate long strings to shorter strings. This is the "strmap" function.
The other special functions provide astronomical features. These are:
sexstr - convert a number to a sexagesimal string epoch - compute an epoch julday - compute a Julian day mst - compute a mean siderial time precess - precess a coordinate pair ra_precess - precess ra dec_precess - precess dec arcsep - arc second separation of two coordinates airmass - compute airmass eairmass - compute effective airmass
effective = beginning + 4 * middle + ending
1. The intype and skytype parameters are used to select images from a list. The expression is a boolean that is applied to an image to determine whether it is to be used or not. For input images the most common type of selection is to select only one observational type. This is the same as the dtype and ftype parameter and examples are found later. But supposed one wants to process only those images which have NGC123 in the title:
title?="NGC123"
To make the match case insensitive use the {} pattern matching characters.
Now suppose one wants to process only the observations made in the Ks filter where the filter string in the header is that shown in the example:
filter="Ks kp1234 K short filter"
One can combine the booleans to:
title?="NGC123"&filter="Ks kp1234 K short filter"
2. Selection and identifications of observational types is a common requirement. Various observatories do this in diffent ways. One common way is with a string keyword such as OBSTYPE. The following matches when the image contains the keyword OBSTYPE with a value that contains the word "flat" while ignoring the case.
obstype?="{flat}"
But suppose the type is encoded as observation code and codes 3 and 4 indicated flat fields.
expcode=3|expcode=4
Finally suppose the types are only identified by the user putting the word flat in the title. The same expression as for OBSTYPE could be used with the keyword TITLE substituted.
3. The imageid and filter parameters are used to group images. Typically these would have the same value for all data that fall into the group. For instance if the keyword is AMPNUM to group images by amplifier it might be as follows.
ampnum
The filters are sometimes identified by filter wheel numbers but sometimes they are identified by strings. Now suppose it is possible that for some reason the same filter may have different names; say because it is manually entered by the observer. Then one could use the STRMAP function to map the strings to the same short value.
strmap(filter,"H filter","H", "Filter H","H", "Filter 2","H", "J filter","J", "j","J", "K short", "Ks" "Kshort", "Ks)
For a long expression like this it might be put in an @file. In this expression the values, assuming there are no others, would be "H", "J", and "Ks" and the images would be grouped by these values even though there are several variants.
4. A bad pixel expression is used to identify bad pixels based on the pixel values. The most common type of expression is a threshold for saturation. Note that the bad pixel expression must evaluate to an integer code where zero is a good pixel and any other positive integer is a bad pixel. A threshold saturation expression using a keyword "saturate" would be
$I >= saturate ? 4 : 0
A more complex expression might convert a saturation value given in electrons to data numbers based on the gain as in
$I*gain >= saturate ? 4 : 0