GNU Astronomy Utilities

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

When you simulate data (for example see Sufi simulates a detection), everything is ideal and there is no noise! The final step of the process is to add simulated noise to the data. The operators in this section are designed for that purpose.


Add a fixed noise (Gaussian standard deviation) to each element of the input dataset. This operator takes two arguments: the top/first popped operand is the noise standard deviation, the next popped operand is the dataset that the noise should be added to.

When --quiet isn’t given, a statement will be printed on each invocation of this operator (if there are multiple calls to the mknoise-*, the statement will be printed multiple times). It will show the random number generator function and seed that was used in that invocation, see Generating random numbers. Reproducibility of the outputs can be ensured with the --envseed option, see below for more.

For example with the first command below, image.fits will be degraded by a noise of standard deviation 3 units.

$ astarithmetic image.fits 3 mknoise-sigma

Alternatively, you can use this operator within column arithmetic in the Table program, to generate a random number like below (centered on 0, with \(\sigma=3\)) like the first command below. With the second command, you can put it into a shell variable for later usage.

$ echo 0 | asttable -c'arith $1 3 mknoise-sigma'
$ value=$(echo 0 | asttable -c'arith $1 3 mknoise-sigma')
$ echo $value

You can also use this operator in combination with AWK to easily generate an arbitrarily large table with random columns. In the example below, we’ll create a two column table with 20 rows. The first column will be centered on 5 and \(\sigma_1=2\), the second will be centered on 10 and \(\sigma_2=3\):

$ echo 5 10 \
       | awk '{for(i=0;i<20;++i) print $1, $2}' \
       | asttable -c'arith $1 2 mknoise-sigma' \
                  -c'arith $2 3 mknoise-sigma'

By adding an extra --output=random.fits, the table will be saved into a file called random.fits, and you can change the i<20 to i<5000 to have 5000 rows instead. Of course, if your input table has different values in the desired column the noisy distribution will be centered on each input element, but all will have the same scatter/sigma.

You can use the --envseed option to fix the random number generator seed (and thus get a reproducible result). For more on --envseed, see Generating random numbers. When using column arithmetic in Table, it may happen that multiple columns need random numbers (with any of the mknoise-* operators) in one call of asttable. In such cases, the value given to GSL_RNG_SEED is incremented by one on every call to the mknoise-* operators. Without this increment, when the column values are the same (happens a lot, for no-noised datasets), the returned values for all columns will be identical. But this feature has a side-effect: that if the order of calling the mknoise-* operators changes, the seeds used for each operator will change125.


Add Poisson noise to each element of the input dataset (see Photon counting noise). This operator takes two arguments: the top/first popped operand is the background value (in units of electron counts), the next popped operand is the dataset that the noise should be added to.

Except for the noise-model, this operator is very similar to mknoise-sigma and the examples there apply here too. The main difference with mknoise-sigma is that in a Poisson distribution the scatter/sigma will depend on each element’s value.

For example, let’s assume you have made a mock image called mock.fits with MakeProfiles and its assumed zeropoint is 22.5 (for more on the zero point, see Brightness, Flux, Magnitude and Surface brightness). Let’s assume the background level for the Poisson noise has a value of 19 magnitudes. You can first use the mag-to-counts operator to convert this background magnitude into counts, then feed the background value in counts to mknoise-poisson operator:

$ astarithmetic mock.fits 19 22.5 mag-to-counts \

Try changing the background value from 19 to 10 to see the effect! Recall that the tutorial Sufi simulates a detection shows how you can use MakeProfiles to build mock images.


Add uniform noise to each element of the input dataset. This operator takes two arguments: the top/first popped operand is the width of the interval, the second popped operand is the dataset that the noise should be added to (each element will be the center of the interval). The returned random values may happen to be the minimum interval value, but will never be the maximum. Except for the noise-model, this operator behaves very similar to mknoise-sigma, see the explanation there for more.

For example with the command below, a random value will be selected between 10 to 14 (centered on 12, which is the only input data element, with a total width of 4).

echo 12 | asttable -c'arith $1 4 mknoise-uniform'

Similar to the example in mknoise-sigma, you can pipe the output of echo to awk before passing it to asttable to generate a full column of uniformly selected values within the same interval.



We have defined Task 15971 in Gnuastro’s project management system to address this. If you need this feature please send us an email at (to motivate us in its implementation).

Next: Elliptical shape operators, Previous: Numerical type conversion operators, Up: Arithmetic operators   [Contents][Index]