spectrumgen

package module
v0.0.0-...-1869eb6 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 7 Imported by: 0

README

Spectrum generator (light)

This package is for creating fake test light spectrums for projects like PySpectrometer2 or for acting as unit test utility for golang based light spectrometer

Usage

cmd/genspectrum is example program for generating spectrums.

build with

go build

that folder contains .peaksim files like

  • movingPeaks.peaksim
  • onenarrow.peaksim, example of one narrow peak
  • onewide.peaksim
./genspectrum -fr 1 -i fluoro.peaksim -o test.mp4 -pic test -rgb

produces fake one frame animation and test_0.png picture

Faking webcam

Install v4l-utils, ffmpeg etc...

check video devices present at the moment. As reference

ls /dev/video*

Load loopback video device

sudo modprobe v4l2loopback

then check is there new video device available

ls /dev/video*

in this example it is /dev/video2

Playing single picture

ffmpeg -loop 1 -re -i test_0.png -f v4l2 -vcodec rawvideo -pix_fmt yuv420p /dev/video2

command line options

Usage of ./genspectrum:
  -a float
    	shortest wavelength in nm (default 380)
  -b float
    	longest wavelength in nm (default 750)
  -c string
    	csv file output, one row per frame
  -d float
    	duration of render in seconds (default 10)
  -fps float
    	frames per second (default 15)
  -fr int
    	override duration by giving number of frames required, 0=infinite loop (default -1)
  -i string
    	peaksim file for input
  -na float
    	noise amplitude
  -o string
    	output animation
  -pic string
    	filename prefix for image output (png)
  -rgb
    	set RGB mode and simulate colors instead of BGR2GRAY
  -testtriangle
    	enable test triangle mode instead of peaks
  -xreso int
    	x resolution in pixels (default 800)
  -yreso int
    	y resolution in pixels (default 600)

peaksim file format

Simulator generates animated peak patters based on .peaksim file. Peaksimfile is tab/space separated file with following columns

  • 1st to N, list of positions (nm) durin animation separated by tab or space
  • Separator token telling TYPE of peak
    • GAUSS, GAUSSIAN or G for gaussian peak
    • LORENTZ L or PEAKMODEL_LORENTZ
    • HYPSEC, for hypsec
  • List of parameters depending on TYPE of peak
    • Now all have only 1 parameter: "Full width half maximum", ("puoliarvonleveys" in finnish)
  • List of intensities during animation

The symbol # acts as line comment starter

allpeakstyles

Issues and future features

This software is updated while experimenting with spectroscopy

Intensity & wavelength vs RGB values

Mapping intensity vs RGB color is not straightforward One way to map RGB value to intensity is to use equation where values are weighted

I=0.299*R + 0.587*G + 0.114*B

But function WavelengthToRGB( (copied from pyspectrometer) does not produce spectrums where intensity matches to intensity calculated by "R,G,B weighted average"

Better equation that produces "weighted average" results and looks good is now TBD.

Use -rgb command line option to choose mode where spectrum looks like light spectrum, instead of green-yellow thing.

Documentation

Overview

frequency data

Peak model file Text formatted file, describes how peakmodels are created

Index

Constants

View Source
const (
	REDWEIGHT   float64 = 0.299
	GREENWEIGHT float64 = 0.587
	BLUEWEIGHT  float64 = 0.114
)
View Source
const (
	PEAKMODEL_GAUSS   = 0
	PEAKMODEL_LORENTZ = 1
	PEAKMODEL_HYPSEC  = 2
)
View Source
const COMMENTSYMBOL = "#"
View Source
const NUMBEROFDECIMALS = 6

Variables

This section is empty.

Functions

func ColorToIntensity

func ColorToIntensity(c color.RGBA) float64

func WavelengthToRGB

func WavelengthToRGB(nm float64, intensity float64) color.RGBA

Intensity is 0 to 1.0

Types

type FrequencyData

type FrequencyData struct {
	NmStart   float64
	NmStop    float64
	Intensity []float64
}

func (*FrequencyData) AddPeak

func (p *FrequencyData) AddPeak(peak PeakModel) error

func (*FrequencyData) CreateImage

func (p *FrequencyData) CreateImage(xreso int, yreso int, rgbmode bool) *image.RGBA

func (*FrequencyData) ToCsv

func (p *FrequencyData) ToCsv() string

type FrequencyDataArr

type FrequencyDataArr []FrequencyData

func CalcFrequencyDataArr

func CalcFrequencyDataArr(model PeakModelFile, steps int, startNm float64, endNm float64, points int) (FrequencyDataArr, error)

func CalcTestTriangle

func CalcTestTriangle(steps int, startNm float64, endNm float64, points int) (FrequencyDataArr, error)

func (*FrequencyDataArr) ToGrid

func (p *FrequencyDataArr) ToGrid() (string, error)

Grid, for plotting. (assume same dimension and nm axis)

type PeakModel

type PeakModel struct {
	Type     PeakModelType
	Peak     float64
	Position float64
	Fwhm     float64 //Full width half maximum, puoliarvonleveys in finnish
}

func (*PeakModel) Eval

func (p *PeakModel) Eval(from float64, to float64, n int) ([]float64, []float64, error)

TODO optimize calculation. Pre-calc shapes and scale?

func (PeakModel) String

func (a PeakModel) String() string

type PeakModelArr

type PeakModelArr []PeakModel

func (PeakModelArr) String

func (a PeakModelArr) String() string

type PeakModelFile

type PeakModelFile []PeakModelFileRow

func LoadPeakModelFile

func LoadPeakModelFile(filename string) (PeakModelFile, error)

Helper function

func ParsePeakModelFile

func ParsePeakModelFile(content []byte) (PeakModelFile, error)

func (*PeakModelFile) GetPeakModels

func (p *PeakModelFile) GetPeakModels(progressRatio float64) []PeakModel

func (PeakModelFile) ToOutputFormat

func (a PeakModelFile) ToOutputFormat() (string, error)

type PeakModelFileRow

type PeakModelFileRow struct {
	Positions   []float64
	Type        PeakModelType
	Parameters  []float64 //Usually 1, depends on type. can be more at future
	Intencities []float64
}

func ParsePeakModelRow

func ParsePeakModelRow(row string) (PeakModelFileRow, error)

func (*PeakModelFileRow) GetPeakModel

func (p *PeakModelFileRow) GetPeakModel(progressRatio float64) PeakModel

func (*PeakModelFileRow) ToOutputFormat

func (p *PeakModelFileRow) ToOutputFormat() (string, error)

type PeakModelType

type PeakModelType int

func (PeakModelType) String

func (a PeakModelType) String() string

Jump to

Keyboard shortcuts

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