Use this helpful Bash script when stargazing | Opensource.com

Use this helpful Bash script when stargazing

Keep your eyes on the stars by putting your Linux machine in night vision mode with xcalib.

Computer laptop in space
Image by : 

Opensource.com

x

Subscribe now

Get the highlights in your inbox every week.

We often talk about Linux being used on servers and by developers, but it is used in many other fields too, including astronomy. There are a lot of astronomy tools available for Linux, such as sky maps, star charts, and interfaces to telescope drive systems for controlling your telescope. But one challenge for astronomers is using a computer while keeping their eyes working in the dark.

When working out in the field at night, astronomers need to preserve their night vision. It can take up to 30 minutes for the human eye to fully dilate and adjust to low light levels, and doing things like checking a phone or laptop at the regular color and brightness levels can cause the eyes to lose their adjustment. This reduces the ability to see in the dark. An example anyone can understand: if you're reading something on your phone in bed at night and get up to go to the bathroom, you know how difficult it can be to see any obstacles that might be in your way.

A solution

I'd like to present a nifty little script to help the astronomer in your family keep "their eyes" in the dark. It relies on a utility called xcalib, a "tiny monitor calibration loader for X.org." It can be installed easily using your Linux package manager.

On Fedora, for example:

$ sudo dnf info xcalib
$ sudo dnf install xcalib

Or Ubuntu:

$ sudo apt-get install xcalib

The xcalib application works only with X11, so it is not functional on Wayland systems. But Wayland has this functionality built-in, so you can get the same results through GNOME Settings. If you're using X11, xcalib is an easy way to change the color temperature of your display.

The script

I discovered Redscreen, a night vision filter script written by Jeff Jahr in 2014. The original script is written for the C shell, but Bash is the common default these days. In fact, the C shell is not installed by default on my current Fedora Linux workstation. So, I decided to write an updated version of the Redscreen script aimed at the newest Bash syntax, but I made one major change: utilizing a case statement.

#!/usr/bin/bash
# redscreen.sh Fri Feb 28 11:36 EST 2020 Alan Formy-Duval
# Turn screen red - Useful to Astronomers
# Inspired by redscreen.csh created by Jeff Jahr 2014
# (http://www.jeffrika.com/~malakai/redscreen/index.html)

# This program is free software: you can redistribute it
# and/or modify it under the terms of the GNU General
# Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any
# later version.

# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for
# more details.

# You should have received a copy of the GNU General Public
# License along with this program.  
# If not, see <http://www.gnu.org/licenses/>.

case $1 in
            on)
            # adjust color, gamma, brightness, contrast
            xcalib -green .1 0 1 -blue .1 0 1 -red 0.5 1 40 -alter
            exit 1
        ;;
        off)
                xcalib -clear
            exit 1
            ;;
        inv)
            # Invert screen
                xcalib -i -a
                    exit 1
        ;;
        dim)
            # Make the screen darker
                xcalib -clear
            xcalib -co 30 -alter
            exit 1      
        ;;
        *)
                echo "$0 [on | dim | inv | off]"
                    exit 1
        ;;
esac
A star chart displayed in red screen mode
Skychart for Linux Version 4.2.1 on Fedora workstation

A lot of astronomy programs include a "night-mode" function, but not all do. Also, this script provides a way to affect the entire screen, not just a specific application. This allows you to use your Linux system out in the field at night for other things than just stargazing—such as checking email or reading Opensource.com—without ruining your night vision.

Whether you are an astronomer or just an amateur stargazer, you can spend all night admiring the heavens using Linux and open source!

Person looking up at the stars

Explore the universe with NumPy, SciPy, Scikit-Image, and Astropy.

About the author

Alan
Alan Formy-Duval - Alan has 20 years of IT experience, mostly in the Government and Financial sectors. He started as a Value Added Reseller before moving into Systems Engineering. Alan's background is in high-availability clustered apps. He wrote the 'Users and Groups' and 'Apache and the Web Stack' chapters in the Oracle Press/McGraw Hill 'Oracle Solaris 11 System Administration' book. He earned his Master of Science in Information Systems from George Mason University. Alan is a long-time proponent of Open...