bands

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bands carries light as amounts in logarithmic wavelength bins. A renderer can add, filter, or shift the spectrum before reducing it to colour. Infrared and radio power count as light here too.

This is a coarse spectral representation, not a colour model. Colour conversion belongs to libtheme and its CIE 1931 observer integration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Band

type Band int

Band identifies a half-open wavelength bin. Bin i spans [2^(i/PerOctave), 2^((i+1)/PerOctave)) nanometres. Band zero begins at 1 nm; wavelengths double every PerOctave bins. At the chosen spacing, visible light occupies roughly bands 205–230.

func Of

func Of(nm float64) Band

Of returns the band containing a wavelength in nanometres.

func PerOctave

func PerOctave() Band

PerOctave returns the chosen number of logarithmic bands per doubling of wavelength. Research data records the choice and its author.

Uniform spacing in log wavelength makes a redshift a translation through the bands rather than a resampling on a linear grid.

func (Band) Edges

func (band Band) Edges() (lo, hi float64)

Edges returns the lower-inclusive and upper-exclusive wavelengths of a band, in nanometres.

type Light

type Light struct {
	// contains filtered or unexported fields
}

Light stores power over consecutive wavelength bands, beginning at first. Units follow the input spectrum integrated over nanometres. The zero value contains no light.

func Add

func Add(one, other Light) Light

Add sums two spectra band by band without modifying either input.

func Lines

func Lines(spectrum map[float64]float64) Light

Lines groups power at arbitrary wavelengths in nanometres into bands. Unlike Split, it retains sub-nanometre line positions, including gamma rays.

func Lit

func Lit(light Light, share *Share) Light

Lit returns band power multiplied by the corresponding transmission or reflectance fraction. A nil share, like the zero Share, passes no light. The input spectrum is not modified.

func Split

func Split(spectrum map[int]float64) Light

Split groups a spectrum sampled at integer nanometres into bands, adding each sample to its containing band. Wavelengths outside human vision are retained.

func (Light) Power

func (light Light) Power(band Band) float64

Power returns the stored power in a band, or zero outside the span.

func (Light) Scale

func (light Light) Scale(times float64) Light

Scale returns a copy with every band’s power multiplied by times.

func (Light) Shift

func (light Light) Shift(steps int) Light

Shift translates power by whole bands; positive steps move toward longer, redder wavelengths. A redshift factor 1+z corresponds to PerOctave*log2(1+z) steps, exact when integral. Band powers do not change; distance dimming belongs to the caller.

func (Light) Span

func (light Light) Span() (first, last Band)

Span returns the first and last stored bands, both inclusive. For empty light, first is greater than last.

type Share

type Share struct {
	// contains filtered or unexported fields
}

Share represents transmission or reflectance fractions, not emitted light. Lit applies it to a spectrum. A finite curve passes nothing outside its stored bands; Even applies a fraction everywhere. The zero value transmits nothing.

func Even

func Even(part float64) (*Share, error)

Even constructs a wavelength-independent fraction, like a grey filter or neutral surface. Invalid fractions return an error.

func Shares

func Shares(spectrum map[int]float64) (*Share, error)

Shares constructs transmission or reflectance from samples at integer nanometres. Empty samples, nonpositive wavelengths, or fractions outside [0, 1] return an error and no share.

Samples within a band are averaged, not summed. Unsampled bands inside the run interpolate between neighbouring measurements at the band centre. Outside the sampled run, no light passes.

func (Share) Part

func (share Share) Part(band Band) float64

Part returns the fraction transmitted in a band.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL