Skip to main content

Got a spectra? Use this to find what is the observed colour.

Project description

coloured_spectra

Got a spectra? Use this to find the observed colour!

Works great when applied to a single spectra. Using this for hyperspectral though... this Python implementation is too slow to be practical. (Can be magnitudes faster if coded in Julia)

Documentation site: https://yiweimao.github.io/coloured_spectra/

Install

pip install coloured_spectra

Examples

Find the observed colour of a blackbody at 6500 K.

from coloured_spectra import *
import numpy as np
import pickle
import matplotlib.pyplot as plt
import cv2
bb = Blackbody(5778)
bb.plot()

png

def show_blackbody_colour(T_K):
    bb = Blackbody(T_K,np.linspace(380,750))

    sRGB = spectra2sRGB(bb.λ_nm,bb.B_λT)

    # Due to normalisation choices, the brightness can change depending on the spectra
    # show the colour at max brightness
    HSV = cv2.cvtColor(np.reshape(sRGB,(1,1,3)), cv2.COLOR_RGB2HSV_FULL)
    HSV[0,0,2] = 255
    RGB = cv2.cvtColor(HSV, cv2.COLOR_HSV2RGB_FULL)

    plot_colour(RGB)

This approximates the colour of the Sun with a blackbody temperature of 5778 K.

show_blackbody_colour(5778)

png

show_blackbody_colour(11000) # what about the star Rigel?

png

If you have a hyperspectral line, you can colour it in by the observed colour. For this, the invisible UV and NIR is painted white on top of a black background. This look up table spectrum is:

plot_hsv_LUT_spectrum()

png

# load a hyperspectral line (imaged HgAr lamp)
with open('../wave_cal.pkl','rb') as handle:
    img = np.float32(np.rot90(pickle.load(handle),1))

    # get rid of sensor abnormalities
    img[669,467] = img[670,467]
    img[587,1174] = img[588,1174]

    img /= np.max(img)

plt.imshow(img,cmap='gray',extent=[400,850,0,np.shape(img)[0]])
plt.xlabel("wavelengths (nm)")
plt.ylabel("cross-track")
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x1199e7af0>

png

You can see the emission lines have been coloured.

colour_hyperspectral_line(np.linspace(400,850,2064),img)
100%|██████████| 772/772 [00:40<00:00, 19.28it/s]

png

You can also return a column of observed colour given a hyperspectral line

hyperspec_line2colour(np.linspace(400,850,2064),img)
100%|██████████| 772/772 [02:01<00:00,  6.34it/s]

png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coloured_spectra-0.0.3.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

coloured_spectra-0.0.3-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file coloured_spectra-0.0.3.tar.gz.

File metadata

  • Download URL: coloured_spectra-0.0.3.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for coloured_spectra-0.0.3.tar.gz
Algorithm Hash digest
SHA256 edc1dd0317ea8e43ee2e50487513af47c8a68c94f16dcc3e55e41adcbebd015d
MD5 4d7160ff3dd858e01b0ed8f048a2293c
BLAKE2b-256 9f6781699b13608bd8b22cd1e43a4921e5a825eb6008197865a45b8044424fee

See more details on using hashes here.

File details

Details for the file coloured_spectra-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: coloured_spectra-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for coloured_spectra-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 03dc84ef09f0a80860efae4e6075f52a6613f77d889c73626f873afd179a45f8
MD5 33fb0138d30392cf51f4564a496a1f77
BLAKE2b-256 a95ff664d7972ab6aaa9bd0d9826e6cbe2b02cdb0517d4805d8600bd33f1d646

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page