None of Gnuastro’s programs keep a default value internally within their code. However, when you ran CosmicCalculator only with the -z2 option (not specifying the cosmological parameters) in Cosmological coverage, it completed its processing and printed results. Where did the necessary cosmological parameters (like the matter density, etc) that are necessary for its calculations come from? Fast reply: the values come from a configuration file (see Configuration file precedence).
CosmicCalculator is a small program with a limited set of parameters/options. Therefore, let’s use it to discuss configuration files in Gnuastro (for more, you can always see Configuration files). Configuration files are an important part of all Gnuastro’s programs, especially the ones with a large number of options, so its important to understand this part well .
Once you get comfortable with configuration files here, you can make good use of them in all Gnuastro programs (for example, NoiseChisel). For example, to do optimal detection on various datasets, you can have configuration files for different noise properties. The configuration of each program (besides its version) is vital for the reproducibility of your results, so it is important to manage them properly.
As we saw above, the full list of the options in all Gnuastro programs can be seen with the --help option. Try calling it with CosmicCalculator as shown below. Note how options are grouped by context to make it easier to find your desired option. However, in each group, options are ordered alphabetically.
$ astcosmiccal --help
The options that need a value have an = sign after their long version and
STR for floating point numbers, integer numbers, and strings (filenames for example) respectively.
All options have a long format and some have a short format (a single character), for more see Options.
When you are using a program, it is often necessary to check the value the option has just before the program starts its processing.
In other words, after it has parsed the command-line options and all configuration files.
You can see the values of all options that need one with the --printparams or
--printparams is common to all programs (see Common options).
In the command below, try replacing
-P with --printparams to see how both do the same operation.
$ astcosmiccal -P
Let’s say you want a different Hubble constant. Try running the following command (just adding --H0=70 after the command above) to see how the Hubble constant in the output of the command above has changed.
$ astcosmiccal -P --H0=70
Afterwards, delete the -P and add a -z2 to see the calculations with the new cosmology (or configuration).
$ astcosmiccal --H0=70 -z2
From the output of the
--help option, note how the option for Hubble constant has both short (
-H) and long (
One final note is that the equal (=) sign is not mandatory.
In the short format, the value can stick to the actual option (the short option name is just one character after-all, thus easily identifiable) and in the long format, a white-space character is also enough.
$ astcosmiccal -H70 -z2 $ astcosmiccal --H0 70 -z2 --arcsectandist
When an option doesn’t need a value, and has a short format (like --arcsectandist), you can easily append it before other short options. So the last command above can also be written as:
$ astcosmiccal --H0 70 -sz2
Let’s assume that in one project, you want to only use rounded cosmological parameters (H0 of 70km/s/Mpc and matter density of 0.3). You should therefore run CosmicCalculator like this:
$ astcosmiccal --H0=70 --olambda=0.7 --omatter=0.3 -z2
But having to type these extra options every time you run CosmicCalculator will be prone to errors (typos in particular), frustrating and slow. Therefore in Gnuastro, you can put all the options and their values in a “Configuration file” and tell the programs to read the option values from there.
Let’s create a configuration file... With your favorite text editor, make a file named my-cosmology.conf (or my-cosmology.txt, the suffix doesn’t matter, but a more descriptive suffix like .conf is recommended). Then put the following lines inside of it. One space between the option value and name is enough, the values are just under each other to help in readability. Also note that you can only use long option names in configuration files.
H0 70 olambda 0.7 omatter 0.3
You can now tell CosmicCalculator to read this file for option values immediately using the --config option as shown below. Do you see how the output of the following command corresponds to the option values in my-cosmology.conf, and is therefore identical to the previous command?
$ astcosmiccal --config=my-cosmology.conf -z2
But still, having to type --config=my-cosmology.conf every time is annoying, isn’t it? If you need this cosmology every time you are working in a specific directory, you can use Gnuastro’s default configuration file names and avoid having to type it manually.
The default configuration files (that are checked if they exist) must be placed in the hidden .gnuastro sub-directory (in the same directory you are running the program). Their file name (within .gnuastro) must also be the same as the program’s executable name. So in the case of CosmicCalculator, the default configuration file in a given directory is .gnuastro/astcosmiccal.conf.
Let’s do this. We’ll first make a directory for our custom cosmology, then build a .gnuastro within it. Finally, we’ll copy the custom configuration file there:
$ mkdir my-cosmology $ mkdir my-cosmology/.gnuastro $ mv my-cosmology.conf my-cosmology/.gnuastro/astcosmiccal.conf
Once you run CosmicCalculator within my-cosmology (as shown below), you will see how your custom cosmology has been implemented without having to type anything extra on the command-line.
$ cd my-cosmology $ astcosmiccal -P $ cd ..
To further simplify the process, you can use the --setdirconf option. If you are already in your desired working directory, calling this option with the others will automatically write the final values (along with descriptions) in .gnuastro/astcosmiccal.conf. For example try the commands below:
$ mkdir my-cosmology2 $ cd my-cosmology2 $ astcosmiccal -P $ astcosmiccal --H0 70 --olambda=0.7 --omatter=0.3 --setdirconf $ astcosmiccal -P $ cd ..
Gnuastro’s programs also have default configuration files for a specific user (when run in any directory). This allows you to set a special behavior every time a program is run by a specific user. Only the directory and filename differ from the above, the rest of the process is similar to before. Finally, there are also system-wide configuration files that can be used to define the option values for all users on a system. See Configuration file precedence for a more detailed discussion.
We’ll stop the discussion on configuration files here, but you can always read about them in Configuration files. Before continuing the tutorial, let’s delete the two extra directories that we don’t need any more:
$ rm -rf my-cosmology*