### F DREAM/STARE data reduction workflow

The DREAM/STARE observing modes ([4]) were originally designed for mapping compact sources, i.e. those which are smaller than the field of view of SCUBA-2 (approximately 8 arcmin). Note that these modes have not been commissioned at the time of writing and it is thought that STARE mode will not work.

The workflow for processing DREAM and STARE data may proceed in one of two ways: a simplified workflow using images calculated by the data acquisition (DA) at the time of the observation, or the full workflow starting from the raw data. The full procedure is described below, and steps which are unnecessary in the simplified workflow are noted.

The workflow proceeds as follows:

(1)
Apply flatfield solution (full only);
(2)
Remove atmospheric emission;
(3)
Correct for atmospheric extinction;
(4)
Calculate images from time-series (full only);
(5)
Combine images to create output mosaic.
##### F.0.1 DA images

The images calculated by the DA are stored as NDF extensions in the raw data files under .MORE.SCU2RED.In where n is an integer (non-zero-padded). Each image is an average of the data in typically 1 second. Note the final image is created from whatever samples remain if the duration of the file is not an integer number of seconds. Each image has its own FITS header associated with it which contains values which vary between images.

##### F.0.2 Applying the flatfield correction

This section describes how to apply the flatfield solution to raw data. This step is not necessary for the simplified workflow.

A FLATFIELD observation records variation in the sensitivity of each bolometer. Ideally, every bolometer gives the same reading when exposed to a calibrated radiation source. In practice, each one responds in a slightly different way.

The flatfield response for each sub-array is derived at the telescope from a dedicated FLATFIELD observation. This solution is written to all subsequent data files until a new solution is derived (see Section 3.2.1 above).

Bolometer output is modified by the gain of the individual bolometer and its offset from a one-to-one relationship with the input radiation. Thus the output power from bolometer $i$ is related to the input (optical) power by:

 ${P}_{\mathrm{\text{out}},i}={G}_{i}{P}_{\mathrm{\text{in}},i}+{O}_{i}.$ (1)

where $G$ is the gain and $O$ is the offset.

The Smurf routine that applies the flatfield correction is called flatfield. Since the flatfield information is already included in each subscan, multiple files can be flatfielded with a single call to the flatfield routine; there is no need to process files from different sub-arrays separately. Dark frames should be included in the list of input files in order to correct for bolometer zero-point drifts. Note that only flatfielded data (non-dark) files are written out, and that the naming scheme will change. The list of output files given is truncated at the appropriate number. The list of files actually written to disk is obtained via the OUTFILES parameter if specified.

##### F.0.3 Removing the atmosphere

This section describes how to subtract the signal from the atmosphere (or sky) from your observations. This step is required for both the full and simplified workflows.

The sky is highly emissive (bright) at submillimetre wavelengths[1], and the radiation received from an astronomical source is only a very small fraction of the radiation received from the atmosphere. Typically the atmospheric signal is a factor of $1{0}^{5}$ times greater than that from the source (see Figure 5 for a pictorial representation). In addition, the atmospheric emission varies significantly over the timescales of a typical observation, further swamping any contribution from the source. Fortunately, the emission from the sky is correlated over the SCUBA-2 field of view, which enables simple sky removal techniques to be used effectively[111].

In a single sample the signal collected from an astronomical source is negligible in comparison with the contribution from the atmosphere. Many samples are required to collect a statistically significant signal from the source.

The Smurf routine that removes the sky is called remsky and has several options for fitting and removing the atmospheric contribution to the signal. All take advantage of the fact that the sky signal is correlated between adjacent bolometers.

The atmospheric signal can be fit in the following ways:

• Calculate the mean value of the signal;
• Fit a gradient in elevation only;
• Fit a plane of arbitrary orientation.

Furthermore, remsky can make use of the data from all available sub-arrays simultaneously to make a better estimate of the atmospheric emission (see the GROUP parameter).

For simple cases, subtracting a mean value may be sufficient, though it is not recommended for bright sources, as the mean will be biassed too high by the presence of the source. A more sophisticated solution may be obtained by fitting a plane to the data. The plane may have arbitrary orientation (in azimuth and elevation) or may be fixed so that the slope is in elevation only.

##### F.0.4 Correcting for atmospheric extinction

This section describes how to correct your data for atmospheric extinction, the loss of radiation from the source as it travels through the atmosphere. This step is required for both the full and simplified workflows.

The observed signal from an astronomical source decreases as the atmosphere along the line of sight increases. At lower elevations, there is more atmosphere along the line of sight between the source and the telescope.

The radiation received by SCUBA-2 is the sum of the radiation from the astronomical source (represented by ${I}_{\mathrm{\text{src}}}$ in Equation 2 below) and the radiation from the atmosphere (${I}_{\mathrm{\text{atm}}}$). However, ${I}_{\mathrm{\text{src}}}$ is diminished by the optical depth of the atmosphere ($\tau$) as follows:

 ${I}_{\mathrm{\text{obs}}}={I}_{\mathrm{\text{atm}}}+{I}_{\mathrm{\text{src}}}exp\left(-\tau \right).$ (2)

The optical depth is usually quoted as the value at the zenith (${\tau }_{\mathrm{\text{zenith}}}$), but you need the value of tau at the same elevation as your observations (${\tau }_{\mathrm{\text{obs}}}$). For a plane-parallel atmosphere, ${\tau }_{\mathrm{\text{obs}}}=A×{\tau }_{\mathrm{\text{zenith}}}$, where airmass ($A$) is a measure of the total atmosphere along the line of sight.

Airmass is defined as $1/cos\theta$, where $\theta$ is the zenith angle. The zenith angle is the vertical angle measured from the zenith ($\theta ={0}^{\circ }$) towards the horizon ($\theta =9{0}^{\circ }$) and is thus equal to $90-\varphi$, where $\varphi$ is the elevation. You can now calculate ${\tau }_{\mathrm{\text{obs}}}$ from ${\tau }_{\mathrm{\text{zenith}}}$ and $\varphi$ as follows:

 ${\tau }_{\mathrm{\text{obs}}}={\tau }_{\mathrm{\text{zenith}}}/cos\left(9{0}^{\circ }-\varphi \right).$ (3)

Using Equation 3, rewrite Equation 2 as:

 ${I}_{\mathrm{\text{obs}}}={I}_{\mathrm{\text{atm}}}+{I}_{\mathrm{\text{src}}}exp\left(\frac{-{\tau }_{\mathrm{\text{zenith}}}}{cos\left(9{0}^{\circ }-\varphi \right)}\right).$ (4)

The elevation angle of each bolometer can be calculated, and given ${\tau }_{\mathrm{\text{zenith}}}$ remsky calculates the ${\tau }_{\mathrm{\text{obs}}}$ at the elevation angle of each bolometer.

The zenith optical depth can be obtained via three methods:

(1)
Skydips: The zenith optical depth is derived from a SKYDIP observation, in which the signal at each wavelength is recorded over a range of airmasses. Smurf does not yet have the capability to process SCUBA-2 skydips.
(2)
CSO tipping radiometer: The Caltech Submillimeter Observatory (CSO) radiometer measures ${\tau }_{\mathrm{\text{zenith}}}$ from skydip observations at 225 GHz. The CSO radiometer records a new ${\tau }_{\mathrm{\text{zenith}}}$ every 10 minutes and values are stored in the FITS headers corresponding to the start and end timestamps of the file (TAU225ST and TAU225EN). Smurf converts CSO ${\tau }_{\mathrm{\text{zenith}}}$ to ${\tau }_{\mathrm{\text{zenith}}}$ at 450 or 850 $\mu$m, relying on an empirical relationship between ${\tau }_{\mathrm{\text{zenith}}}$ at 225 GHz and ${\tau }_{\mathrm{\text{zenith}}}$ at 450 or 850 $\mu$m.
(3)
JCMT Water Vapour Monitor: The JCMT Water Vapour Monitor (WVM) provides opacity estimates every 1.2 seconds by measuring the spectral shape of the 183 GHz water line along the telescope line-of-sight, and then converting this to an effective ${\tau }_{\mathrm{\text{zenith}}}$ at 225 GHz. Since the measurement is aligned with the submillimetre beam this method circumvents the need to apply the plane parallel approximation (which breaks down at the horizon). The raw WVM data are stored in the JCMT state structure, though the values at times corresponding to the start and end of the file are stored in the FITS headers (WVMTAUST and WVMTAUEN).

Optical depth measurements derived from the WVM are most useful in variable atmospheric conditions where the CSO radiometer may not be giving sufficiently-frequent readings.

The Smurf routine that corrects for atmospheric extinction is called extinction. The extinction routine can use ${\tau }_{\mathrm{\text{zenith}}}$ determined by all of the above methods, and obtains values automatically from the FITS headers for the WVM and CSO cases or uses the raw WVM data if desired.

The user can choose how accurate a correction they wish to apply using the METHOD parameter. By default, extinction will assess the magnitude of the correction and if it does not change significantly across the field of view, then a single value is used (corresponding to the elevation of the tracking position). If there is a significant variation, then extinction will apply a correction to each bolometer using the elevation of that bolometer. It is possible to enforce either of these options by setting METHOD to QUICK or FULL respectively.

Note that sky subtraction must take place before the extinction correction is applied. extinction checks the history to see if remsky has been run and exits with an error if not. However, if an alternative method of sky subtraction has been used (such as using Kappa csub to subtract a mean or median value) then the HASSKYREM may be set to TRUE to override the history check by extinction.

##### F.0.5 Calculating images from time-series data

This step is not required for the simplified workflow.

Smurf provides separate routines for calculating images from STARE and DREAM data. STARE images are calculated with starecalc; DREAM images are calculated with dreamsolve.

In starecalc the user may specify how many samples to average to create images (the default is to calculate averages once a second).

dreamsolve requires the DREAM weights file specified in the FITS header keyword DRMWGHTS to reside in the current directory. Data from each sub-array require a corresponding weights file. See section F.0.7 below for details on calculating alternative weights files.

##### F.0.6 Combining the images

Smurf does not have any image mosaicking tasks itself. This step is handled by routines in Kappa and Ccdpack. Suitable tasks are wcsmosaic in Kappa and a combination of Kappa wcsalign (to align all the images to a common coordinate frame) followed by Ccdpack makemos.

See the SCUBA-2 cookbook (SC/21) for more detailed information about mosaicking SCUBA-2 images.

##### F.0.7 Using alternative DREAM solutions

This step is not usually necessary for either workflow but is included for completeness.

The DREAM observing mode moves the secondary mirror in a pattern which causes adjacent bolometers to observe the same region of the sky multiple times [47]. The data are then described by a series of simultaneous equations which are solved via a matrix inversion (using singular value decomposition). Since the pattern traced out by the secondary mirror is known, the inverse of the matrix can be pre-calculated (a time-consuming task) for a given output grid and applied to data at the time of observation (quick).

It is strongly recommended that users become familiar with the details of DREAM [7] before using weights other than the default for science data processing.

The user may wish to experiment with different regridding schemes or there may be other reasons, not known at the time of observation, which require the inverse matrix to be re-calculated. The task for doing this is called dreamweights, and this allows the user to specify different output grid parameters. The calculation of the inverse is moderately time-consuming (compared with calculating the images) and takes of order 5–10 minutes on current hardware. The output file from dreamweights is the weights file required by dreamsolve. Kappa fitsedit may be used to specify weights files which differ in name from the default. Note that this process must be repeated for each sub-array for which data exist and that data which are to be combined should all use the same grid.

#### F.1 Moving sources

Mosaicking of DREAM and STARE images of moving sources will require the WCS attributes AlignOffset and SkyRefIs to be changed to 1 and ‘origin’ respectively. Use the Kappa task wcsattrib to modify these attributes.