### 17 Longer recipes

This section brings together a number of the individual ingredients seen earlier into lengthier scripts. So far there is only one.

#### 17.1 Recipe for masking and background-fitting

The following script fits a surface to the background in a series of NDFs. First two bright galaxies are to be excluded from the fitting process by being masked using an ARD region (see SUN/95, “Doing it the ARD way”). It is known that the brighter galaxy is the brightest object in the field and the relative displacement of the two galaxies is constant.

# Loop through the remaining arguments, assuming that these are NDFs.
foreach file ($ndfs[1-]) # Obtain the NDF’s name. set file1=$file:r

# Obtain the centre of the galaxy, assuming it is the pixel with the
# largest value.
stats $file1 > /dev/null # Store the maximum (centre) co-ordinates values in shell variables. set centre = ‘parget maxcoord stats‘ # Create a two-line ARD file. The first is for the bright galaxy, and # the other is the second brightest galaxy. We assume a constant offset. # Use CALC to evaluate the expressions, as the centres are strings and # might be floating point. echo ’ELLIPSE( ’$centre[1]’, ’$centre[2]’, 82, 44, 152 )’ >$file1".ard"

set aa = ‘calc exp=\"$centre[1] + 68\"‘ set bb = ‘calc exp=\"$centre[2] - 59\"‘

echo ’ELLIPSE( ’$aa’, ’$bb’, 30, 25, 105 )’ >> $file1".ard" # Mask the NDF. ardmask$file1 $file1".ard"$file1"_masked" cosys=w
\rm $file1.ard # Do the surface fit. echo " " echo$file:r
surfit in=$file1"_masked" out=$file1"_bg" estimator=median \
fittype=polynomial nxpar=4 nypar=4 ix=16 iy=16 \
fitclip=$2,2.5,3$ evaluate=interpolate

# Perform the sky subtraction.
sub $file1$file1"_bg" $file1"_ss" # Remove work files. \rm$file1"_bg.sdf" $file1"_masked.sdf" end exit parget obtains the $x$-$y$ co-ordinates of the maximum value in each NDF, and these are stored in variable centre. Since there are two values, centre is an array. The value of the first element $centre[1] is the $x$ co-ordinate from stats, and the second $centre[2] is the $y$ co-ordinate. These values are placed in an ARD expression and output to $file".ard". calc applies the offset between the galaxies. The second ARD expression is appended to the same text file. ardmask then masks the galaxies, surfit performs the background fit, and subtracts it from the original NDF. The intermediate files are removed. The exit command meaning exit the script is implied at the end of the file, so it can usually be omitted. You might want to call it to leave the script, when some error is encountered.

If you want to make the shape and orientation arguments of the script, see the example of UNIX-style options in Section 14.