trident.spectrum_generator.SpectrumGenerator.add_gaussian_noise

SpectrumGenerator.add_gaussian_noise(snr, seed=None)[source]

Postprocess a spectrum to add gaussian random noise of a given SNR.

Parameters

Snr

float

The desired signal-to-noise ratio for determining the amount of gaussian noise

Seed

optional, int

Seed for the random number generator. This should be used to ensure than the same noise is added each time the spectrum is regenerated, if desired. Default: None

Example

Make a one zone ray and generate a COS spectrum for it. Add noise to the spectrum as though it were observed with a signal to noise ratio of 30.

>>> import trident
>>> ray = trident.make_onezone_ray(redshift=0.5)
>>> sg = trident.SpectrumGenerator('COS')
>>> sg.make_spectrum(ray)
>>> sg.add_gaussian_noise(30)
>>> sg.plot_spectrum('spec_noise_corrected.png')

Plot a DLA with SNR of 10.

>>> import trident
>>> ray = trident.make_onezone_ray(column_densities={'H_p0_number_density':1e21})
>>> sg = trident.SpectrumGenerator(lambda_min=1200, lambda_max=1300, dlambda=0.1)
>>> sg.make_spectrum(ray, lines=['Ly a'])
>>> sg.add_gaussian_noise(10)
>>> sg.plot_spectrum('spec_noise.png')