Next: Conditional operators, Previous: Interpolation operators, Up: Arithmetic operators [Contents][Index]

Through these operators you can change the dimensions of the output through certain statistics on the dimensions that should be removed.
For example, let’s assume you have a 3D data cube that has 300 by 300 pixels in the RA and Dec dimensions (first two dimensions), and 3600 slices along the wavelength (third dimension), so the whole cube is \(300\times300\times3600\) voxels (volume elements).
To create a narrow-band image that only contains 100 slices around a certain wavelength, you can crop that section (using Crop), giving you a \(300\times300\times100\) cube.
You can now use the `collapse-sum`

operator below to “collapse” all the 100 slices into one 2D image that has \(300\times300\) pixels.
Every pixel in this 2D image will have the flux of the sum of the 100 slices.

`collapse-sum`

Collapse the given dataset (second popped operand), by summing all elements along the first popped operand (a dimension in FITS standard: counting from one, from fastest dimension). The returned dataset has one dimension less compared to the input.

The output will have a double-precision floating point type irrespective of the input dataset’s type. Doing the operation in double-precision (64-bit) floating point will help the collapse (summation) be affected less by floating point errors. But afterwards, single-precision floating points are usually enough in real (noisy) datasets. So depending on the type of the input and its nature, it is recommended to use one of the type conversion operators on the returned dataset.

If any WCS is present, the returned dataset will also lack the respective dimension in its WCS matrix. Therefore, when the WCS is important for later processing, be sure that the input is aligned with the respective axes: all non-diagonal elements in the WCS matrix are zero.

One common application of this operator is the creation of pseudo broad-band or narrow-band 2D images from 3D data cubes. For example integral field unit (IFU) data products that have two spatial dimensions (first two FITS dimensions) and one spectral dimension (third FITS dimension). The command below will collapse the whole third dimension into a 2D array the size of the first two dimensions, and then convert the output to single-precision floating point (as discussed above).

$ astarithmetic cube.fits 3 collapse-sum float32

`collapse-mean`

Similar to

`collapse-sum`, but the returned dataset will be the mean value along the collapsed dimension, not the sum.`collapse-number`

Similar to

`collapse-sum`, but the returned dataset will be the number of non-blank values along the collapsed dimension. The output will have a 32-bit signed integer type. If the input dataset doesn’t have blank values, all the elements in the returned dataset will have a single value (the length of the collapsed dimension). Therefore this is mostly relevant when there are blank values in the dataset.`collapse-min`

Similar to

`collapse-sum`, but the returned dataset will have the same numeric type as the input and will contain the minimum value for each pixel along the collapsed dimension.`collapse-max`

Similar to

`collapse-sum`, but the returned dataset will have the same numeric type as the input and will contain the maximum value for each pixel along the collapsed dimension.`add-dimension`

Build a higher-dimensional dataset from all the input datasets stacked after one another (along the slowest dimension). The first popped operand has to be a single number. It is used by the operator to know how many operands it should pop from the stack (and the size of the output in the new dimension). The rest of the operands must have the same size and numerical data type. This operator currently only works for 2D input operands, please contact us if you want inputs to have different dimensions.

The output’s WCS (which should have a different dimensionality compared to the inputs) can be read from another file with the

`--wcsfile`option. If no file is specified for the WCS, the first dataset’s WCS will be used, you can later add/change the necessary WCS keywords with the FITS keyword modification features of the Fits program (see Fits).If your datasets don’t have the same type, you can use the type transformation operators of Arithmetic that are discussed below. Just beware of overflow if you are transforming to a smaller type, see Numeric data types.

For example if you want to put the three

`img1.fits`,`img2.fits`and`img3.fits`images (each a 2D dataset) into one 3D datacube, you can use this command:$ astarithmetic img1.fits img2.fits img3.fits 3 add-dimension

JavaScript license information

GNU Astronomy Utilities 0.16 manual, October 2021.