Askaniy / TrueColorTools

GUI application for calculating human-visible colors of celestial bodies from their photometric data
MIT License
19 stars 5 forks source link
astro astronomical-algorithms astronomy blackbody blackbody-radiation color colors data-visualization gamma-correction image-processing photometry planet planetary-science planets python redshift space spectra spectral-analysis spectrum

Header logo

Astronomy-focused set of Python tools with a GUI that uses spectrum construction and eye absorption to compute realistic colors.

Input data is accepted in the form of filters measurements (such as color indices) or continuous spectra, in irradiance units or in magnitudes. Stores a comprehensive catalog of photometry in a proprietary format. Can process spectral cubes, multiband spacecraft images and correct images in enhanced colors.

To calibrate the color of maps based on TCT data, I recommend using Cylindrical Texture Calibrator.

Please note that this is a hobby project and no guarantees are provided for the results. Help is welcome!

TCT screenshot

Installation

TrueColorTools has been tested on Windows 10/11, macOS and Linux (this can be used to run on Windows 7). Python version 3.11 or higher is required. Depending on the system, you may need to replace the python command with python3.

  1. Clone the repository or download the archive using the GitHub web interface;
  2. Open the console in the project root folder;
  3. Create a virtual environment with python -m venv .venv;
  4. Install the dependencies with .venv/bin/pip install -r requirements.txt;
  5. Execute .venv/bin/python -u runTCT.py.

Executable file

SevenSpheres compiles stable versions of TCT for Windows 8/10/11. Thus, Python is not required in this installation way.

  1. Go to the latest release page;
  2. Download and unpack the first archive;
  3. Launch the runTCT.exe.

How it works?

The key processing method is to convert a photometric data into a continuous spectrum and convolve it with color matching functions of an eye. Summary of the standard steps:

  1. Data reading and conversion into the form of "wavelength: spectral energy density". Built-in filter information is used to work with color indices and spacecraft images.
  2. The resulting values are interpolated (and extrapolated if necessary). The program uses its own functions, which are faster and more reliable than SciPy's. The plan is to replace the interpolation with an algorithm that takes into account the profile of the filters.
  3. By default, the spectrum is convolved with RGB sensitivity curves. When sRGB mode is enabled, the spectrum is first convolved into XYZ space and then RGB is calculated with assuming of the illuminant E (the equal energy white point is much better than standard D65 for our purposes).

How to use?

GUI is the only way to interact with TrueColorTools. If you run it from the command line, you can set the startup language (run with --help for details). No Internet connection is required, the databases are stored in the appropriate repository folders, and you can replenish them.

Program interface is functionally divided into tabs: Database viewer, Image processing and Blackbody & Redshifts. Color output formatting, often common to tabs, is located in the sidebar settings.

The Database viewer tab provides access to the spectra database and allows you to calculate a color with the selected settings by simply clicking on an object. It is possible to plot one or more spectra from the database in a pop-up window. You can process the colors of an entire category at once and get the output in text form or as a graphical table (examples).

The Image processing tab accepts regular images, a series of black and white images, or a spectral cube as input. Using the wavelength information, the image is restored in true color. The internal operations are similar to reconstructing the spectrum for each pixel.

The Blackbody & Redshifts tab calculates the influence of physical phenomena on color. Based on the blackbody spectrum, the program displays the color and brightness changes due to Doppler and gravitational redshifts. You can lock the exposure on the logarithmic scale of apparent magnitude, setting the overexposure limit for a tuned blackbody object if it was in the sky replacing the Sun (at the same angular size).

Features

Databases

Spectra database structure

Data listed in JSON5 files can be of two types: reference and photometric. There are no restrictions on their order and relative position at all (data block and its reference block can be in different files), but it is usually convenient to list the sources at the beginning of the file, then the spectra.

The object name may contain indicators for the GUI and the color table, the template is (index) name: note (info) | reference. The contents of the brackets are placed in the upper left corner; colon followed by a note; what appears after a vertical bar is reference(s) and is placed in the upper right corner. The naming conventions in the GUI may vary and try to follow naming standards in astronomy.

The brightness scale is not strictly tied to physical quantities. Using the albedo key, you can indicate that the appropriate spectrum is scaled and the brightness in the range 0 to 1 should be treated as reflectance. The scaling task can be left to the program by specifying a wavelength or filter for which the albedo is known. Optional internal standard is irradiance spectral density measured in W / (m² nm).

For the visible range, there are two main types of albedo: geometric and spherical. Geometric albedo is coefficient of reflected light at the zero phase angle (for simplicity, normal albedo is now not distinguished from geometric albedo). It is usually brighter than the spherical albedo, the ratio of all incident light to all reflected light. If one is not specified in the database or can't be calculated from the phase function, TCT uses a theoretical model to convert one to the other for the appropriate brightness display mode. If no albedo is specified, the object will not be displayed in albedo modes (exception for the star tag). The albedo parameter indicates both albedos at once, but it is not recommended.

Phase functions are now used to calculate the phase integral, which is used to convert between spherical and geometric albedo. The name and function parameters are stored in the database as ['name', {param1: value1, ...}], each value can be numeric or a list of [value, sd]. The following phase functions are supported:

It is assumed that all data is given in ascending wavelength order, and it is necessary to specify "white spectrum" for calibration if the photometric system does not determine it by equal-energy irradiance density by wavelengths (this link may help). Typically you need to specify calibration_system: 'AB' when working with Sloan filters and calibration_system: 'Vega' for all other cases.

Supported input keys of a database unit:

Standard deviations are syntactically supported (but not always processed). Any brightness value in any of the data types can be replaced by a corresponding list of [value, sd] (or [value, +sd, -sd] for asymmetric standard deviation).

You can store the file with the spectrum outside of JSON5, and include a link in it. Text (*.txt, *.dat) and FITS (*.fits, *.fit) formats are supported for external files. A text file must contain at least wavelengths in the first column, irradiance in the second column, and optionally standard deviations in the third column and a mask in the fourth column ("good" rows in SMASS data marked with "1"). Data is assumed to be in the second HDU in FITS files. If you have problems reading FITS, contact me, I'll improve the parsing of the provided example.

As in JSON5, the default wavelengths for external files are in nanometers and the spectrum is in energy density. For FITS files, TCT attempt to determine the wavelength unit from internal data. You can also force the data type by using letters in the file extension (.txt for example):

Spectra database extension

The data in the /spectra folder can be modified by the user (except for the "vital" spectra of the Sun and Vega). The display order in the Database viewer is determined by the file names and the order within the file. If the spectrum header is repeated in the database, the last spectrum will replace the previous one. The tag list is created and completed while reading files. /spectra_extras is recommended as the storage location for user files and add-ons; they will be shown last in the GUI. There is a pinned issue for sharing "official" and user add-ons. Pull requests are welcome too.

Filters database extension

TCT uses filter sensitivity profiles for accurate spectrum restoration. They are provided by the SVO Filter Profile Service and stored here. To replenish the database, select a filter on the site, select the "ascii" data file and place it in the folder. You need also specify the wavelength unit (usually ångströms, so you get the .datA extension). If you see "Detector Type: Photon counter" in the filter description there (instead of "Energy counter", which we need) you need to add P to the extension. Also note that V band filter in the /filters folder is "vital".

Short help on the UBVRI photometric system implementations:

Acknowledgements

This research has made use of:

My thanks to arbodox for the creation of the project logo.