## GNU Astronomy Utilities

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

#### 6.2.3.1 Basic mathematical operators

These are some of the most common operations you will be doing on your data and include, so no further explanation is necessary. If you are new to Gnuastro, just read the description of each carefully.

+

Addition, so “4 5 +” is equivalent to $$4+5$$. for example, in the command below, the value 20000 is added to each pixel’s value in image.fits:

$astarithmetic 20000 image.fits +  You can also use this operator to sum the values of one pixel in two images (which have to be the same size). for example, in the commands below (which are identical, see paragraph after the commands), each pixel of sum.fits is the sum of the same pixel’s values in a.fits and b.fits. $ astarithmetic a.fits b.fits + -h1 -h1 --output=sum.fits
$astarithmetic a.fits b.fits + -g1 --output=sum.fits  The HDU/extension has to be specified for each image with -h. However, if the HDUs are the same in all inputs, you can use -g to only specify the HDU once If you need to add more than one dataset, one way is to use this operator multiple times, for example, see the two commands below that are identical in the Reverse Polish Notation (Reverse polish notation): $ astarithmetic a.fits b.fits + c.fits + -osum.fits
$astarithmetic a.fits b.fits c.fits + + -osum.fits  However, this can get annoying/buggy if you have more than three or four images, in that case, a better way to sum data is to use the sum operator (which also ignores blank pixels), that is discussed below. - Subtraction, so “4 5 -” is equivalent to $$4-5$$. Usage of this operator is similar to + operator, for example: $ astarithmetic 20000 image.fits -
$astarithmetic a.fits b.fits - -g1 --output=sub.fits  x Multiplication, so “4 5 x” is equivalent to $$4\times5$$. for example, in the command below, the value of each output pixel is 5 times its value in image.fits: $ astarithmetic image.fits 5 x


And you can multiply the value of each pixel in two images, like this:

$astarithmetic a.fits a.fits x -g1 –output=multip.fits  / Division, so “4 5 /” is equivalent to $$4/5$$. Like the multiplication, for example $ astarithmetic image.fits 5 -h1 /
$astarithmetic a.fits b.fits / -g1 –output=div.fits  % Modulo (remainder), so “3 2 %” will return $$1$$. Note that the modulo operator only works on integer types (see Numeric data types). This operator is therefore not defined for most processed astronomical astronomical images that have floating-point value. However it is useful in labeled images, for example, Segment output). In such cases, each pixel is the integer label of the object it is associated with hence with the example command below, we can change the labels to only be between 1 and 4 and decrease all objects on the image to 4/5th (all objects with a label that is a multiple of 5 will be set to 0). $ astarithmetic label.fits 5 1 %

abs

Absolute value of first operand, so “4 abs” is equivalent to $$|4|$$. for example, the output of the command bellow will not have any negative pixels (all negative pixels will be multiplied by $$-1$$ to become positive)

$astarithmetic image.fits abs  pow First operand to the power of the second, so “4.3 5 pow” is equivalent to $$4.3^{5}$$. for example, with the command below all pixels will be squared $ astarithmetic image.fits 2 pow

sqrt

The square root of the first operand, so “5 sqrt” is equivalent to $$\sqrt{5}$$. Since the square root is only defined for positive values, any negative-valued pixel will become NaN (blank). The output will have a floating point type, but its precision is determined from the input: if the input is a 64-bit floating point, the output will also be 64-bit. Otherwise, the output will be 32-bit floating point (see Numeric data types for the respective precision). Therefore if you require 64-bit precision in estimating the square root, convert the input to 64-bit floating point first, for example, with 5 float64 sqrt. for example, each pixel of the output of the command below will be the square root of that pixel in the input.

$astarithmetic image.fits sqrt  If you just want to scale an image with negative values using this operator (for better visual inspection, and the actual values do not matter for you), you can subtract the image from its minimum value, then take its square root: $ astarithmetic image.fits image.fits minvalue - sqrt -g1


Alternatively, to avoid reading the image into memory two times, you can use the set- operator to read it into the variable i and use i two times to speed up the operation (described below):

$astarithmetic image.fits set-i i i minvalue - sqrt  log Natural logarithm of first operand, so “4 log” is equivalent to $$ln(4)$$. Negative pixels will become NaN, and the output type is determined from the input, see the explanation under sqrt for more on these features. for example, the command below will take the natural logarithm of every pixel in the input. $ astarithmetic image.fits log --output=log.fits

log10

Base-10 logarithm of first popped operand, so “4 log” is equivalent to $$log_{10}(4)$$. Negative pixels will become NaN, and the output type is determined from the input, see the explanation under sqrt for more on these features. for example, the command below will take the base-10 logarithm of every pixel in the input.

\$ astarithmetic image.fits log10


Next: Trigonometric and hyperbolic operators, Previous: Arithmetic operators, Up: Arithmetic operators   [Contents][Index]