Ejemplo n.º 1
0
import toy
from matplotlib import pyplot as plt

fig = plt.figure('savenoise2')
fig.clf()

axs = fig.subplots(2, 1)
axs[0].set_title('LNGS 1 GSa/s')
axs[1].set_title('LNGS 125 MSa/s')

sources = list(sorted(glob.glob('darksidehd/LF_TILE15_77K_*VoV_1.wav')))

for source in sources:
    suffix = '.wav'
    dest = 'noises/' + os.path.split(source)[1][:-len(suffix)] + '-noise.npz'
    print(f'saving {source} to {dest}...')
    lngs1GSas = toy.DataCycleNoise(timebase=1)
    lngs1GSas.load_LNGS_wav(source, 1100)
    lngs1GSas.save(dest)

    lngs1GSas = toy.DataCycleNoise(timebase=1)
    lngs1GSas.load(dest)
    axs[0].plot(lngs1GSas.generate(1, 1000)[0])

    lngs125MSas = toy.DataCycleNoise(timebase=8)
    lngs125MSas.load(dest)
    axs[1].plot(lngs125MSas.generate(1, 1000)[0])

fig.tight_layout()
fig.show()
Ejemplo n.º 2
0
of the script set the various parameters.
"""

import numpy as np

import toy
import template as _template

tau = np.array([4, 8, 16, 24, 32, 40, 48, 64, 96, 128, 192, 256, 384])
snr = np.linspace(1.8, 6, 15)

wlen = np.array(64 * np.array([1.5, 2, 2.5, 3, 4, 5, 6, 7]), int) - 32
wlmargin = np.full_like(wlen, 64 - 32)
wlmargin[0] = 16

noise_proto0 = toy.DataCycleNoise()
noise_proto0.load('noises/merged_000886-adc_W201_Ch00.npz')
noise_LNGS = toy.DataCycleNoise(allow_break=True)
noise_LNGS.load('noises/nuvhd_lf_3x_tile57_77K_64V_6VoV_1-noise.npz')
noise_white = toy.WhiteNoise()
noise_obj = [noise_proto0, noise_LNGS, noise_white]
noise_name = ['proto0', 'LNGS', 'white']

template = _template.Template.load(
    'templates/nuvhd_lf_3x_tile57_77K_64V_6VoV_1-template.npz')

toys = []
for name, noise in zip(noise_name, noise_obj):
    t = toy.Toy(template, tau, snr, noise, upsampling=False)
    # upsampling=True reduces speed dramatically
    print(f'running with {name} noise...')
Ejemplo n.º 3
0
    for i in range(len(timebase)):
        filename = f'toy1gvs125m/toy1gvs125m-{prefix}-{timebase[i]}-{noise_labels[inoise]}.npz'
        print(f'load {filename}...')
        t = toy.Toy.load(filename)
        toys[inoise].append(t)

noise = [None] * 2
noise_ratio = [None] * 2

noise[0] = [toy.WhiteNoise(timebase=t) for t in timebase]
noise_ratio[0] = [np.sqrt(timebase[0] / tb) for tb in timebase]

noise_file = f'noises/{prefix}-noise.npz'
noise[1] = []
for i in range(len(timebase)):
    n = toy.DataCycleNoise(allow_break=True, timebase=timebase[i])
    n.load(noise_file)
    noise[1].append(n)
noise_ratio[1] = [
    np.std(toy.downsample(noise[1][0].noise_array, tb // timebase[0]))
    for i, tb in enumerate(timebase)
]

for inoise in range(len(noise_labels)):
    print(
        f'noise_ratio ({noise_labels[inoise]}) =',
        ', '.join(f'{noise_ratio[inoise][i]:.3f} ({tb})'
                  for i, tb in enumerate(timebase)))

tau = toys[0][0].tau * toys[0][0].timebase
Ejemplo n.º 4
0
if not all(
        os.path.exists(simfile(n, tb)) for n in timebase
        for tb in timebase[n]):

    template = _template.Template.load(f'templates/{prefix}-template.npz')

    for n, timebases in timebase.items():

        timebases = np.sort(timebases)
        noises = {}
        noise_ratio = {}
        for itb, tb in enumerate(timebases):

            if n == 'proto0':
                noise = toy.DataCycleNoise(maxcycles=2,
                                           chunk_skip=1000,
                                           timebase=tb)
                noise.load(noisefile)
            elif n == 'lngs':
                noise = toy.DataCycleNoise(maxcycles=2, timebase=tb)
                noise.load(f'noises/{prefix}-noise.npz')
            elif n == 'white':
                noise = toy.WhiteNoise(timebase=tb)
            noises[tb] = noise

            if itb == 0:
                basenoise = noise
                basetb = tb
            noise_ratio[tb] = np.std(toy.downsample(
                basenoise.generate(20, 5000), tb // basetb),
                                     axis=None)
Ejemplo n.º 5
0
import numpy as np
from matplotlib import pyplot as plt

import figlatex
import toy
import num2si
import template as _template

templfile = 'templates/nuvhd_lf_3x_tile57_77K_64V_6VoV_1-template.npz'
noisefile = 'noises/merged_000886-adc_W201_Ch00.npz'
tau = 256
snr = 5

###########################

noise = toy.DataCycleNoise(maxcycles=1, chunk_skip=1000)
noise.load(noisefile)
template = _template.Template.load(templfile)
sim = toy.Toy(template, [tau], [snr], noise)
sim.run(1000, pbar=10, seed=202102172153)

fig, axs = plt.subplots(2, 2, num='figlochist', clear=True, figsize=[7, 4.3])

sim.plot_loc(0, 0, axs=axs, center=True)

fig.tight_layout()
fig.show()

figlatex.save(fig)
Ejemplo n.º 6
0
import figlatex
import toy
import num2si
import template as _template

prefix = 'nuvhd_lf_3x_tile57_77K_64V_6VoV_1'
snr = 5
mftau = 256
locfilter = 2
loctau = 16
wlen = 64
wlmargin = 16

###########################

noise = toy.DataCycleNoise(allow_break=True)
noise.load(f'noises/{prefix}-noise.npz')
template = _template.Template.load(f'templates/{prefix}-template.npz')
sim = toy.Toy(template, [loctau, mftau], [snr], noise)
sim.run(100, seed=202102190959)
wcenter = sim.window_center([locfilter], [0], [0])
sim.run_window([wlen], [wlmargin], wcenter)

fig, axs = plt.subplots(1,
                        2,
                        num='figwindowevent',
                        clear=True,
                        sharex=True,
                        sharey=True,
                        figsize=[8.94, 4.41])
Ejemplo n.º 7
0
"""
Run a simulation at 1 GSa/s with white and LNGS noise, saving the result to
file.
"""

import numpy as np

import toy
import template as _template

tau = np.array([4, 8, 16, 24, 32, 40, 48, 64, 96, 128, 192, 256, 384]) * 8
snr = np.linspace(1.8, 6, 15)

noise_LNGS = toy.DataCycleNoise(allow_break=True, timebase=1)
noise_LNGS.load('noises/nuvhd_lf_3x_tile57_77K_64V_6VoV_1-noise.npz')
noise_white = toy.WhiteNoise(timebase=1)
noise_obj = [noise_LNGS, noise_white]
noise_name = ['LNGS', 'white']

template = _template.Template.load(
    'templates/nuvhd_lf_3x_tile57_77K_64V_6VoV_1-template.npz')

toys = []
for name, noise in zip(noise_name, noise_obj):
    t = toy.Toy(template, tau, snr, noise, timebase=1)
    print(f'running with {name} noise...')
    t.run(1000, pbar=10, seed=202012081136)
    toys.append(t)

for inoise in range(len(toys)):
    filename = f'toy1gsa-{noise_name[inoise]}.npz'
Ejemplo n.º 8
0
def isomething(a, x, strict=True):
    i = min(np.searchsorted(a, x), len(a) - 1)
    assert not strict or a[i] == x
    return i


itau = lambda t: isomething(tau, t)
isnr = lambda s: isomething(snr, s, False)

names = ['proto0', 'lngs']
nicenames = dict(proto0='Proto0', lngs='LNGS')
simfile = lambda n: f'figthesis/figwindowtempres-{n}.npz'

if not all(os.path.exists(simfile(n)) for n in names):

    noise_proto0 = toy.DataCycleNoise(maxcycles=2, chunk_skip=1000)
    noise_proto0.load(noisefile)
    noise_lngs = toy.DataCycleNoise(maxcycles=2)
    noise_lngs.load(f'noises/{prefix}-noise.npz')
    noise = dict(proto0=noise_proto0, lngs=noise_lngs)

    template = _template.Template.load(f'templates/{prefix}-template.npz')

    for n in names:
        if os.path.exists(simfile(n)):
            continue
        sim = toy.Toy(template, tau, snr, noise[n])
        sim.run(1000, pbar=10, seed=202102191139)

        res = sim.templocres()  # shape == (nfilter, ntau, nsnr)
        i = isnr(2.4)
Ejemplo n.º 9
0
template = _template.Template.load(templfile)

savedir = 'toy1gvs125m'
os.makedirs(savedir, exist_ok=True)

for whitenoise in [True, False]:

    if whitenoise:
        noise = [toy.WhiteNoise(timebase=t) for t in timebase]
        noise_name = 'white'
    else:
        noise_file = f'noises/{prefix}-noise.npz'
        print(f'read {noise_file}...')
        noise = []
        for i in range(len(timebase)):
            n = toy.DataCycleNoise(maxcycles=2, timebase=timebase[i])
            n.load(noise_file)
            noise.append(n)
        noise_name = 'lngs'

    for i in range(len(timebase)):
        tb = timebase[i]
        noise_ratio = np.std(toy.downsample(noise[0].generate(100, 100), tb),
                             axis=None)
        snr = snr_1GSa / noise_ratio
        t = toy.Toy(template, tau // tb, snr, noise[i], timebase=tb)
        print(
            f'running with timebase={tb} (SNR *= {1/noise_ratio:.2g}), {noise_name} noise...'
        )
        t.run(1000, pbar=10, seed=202012111417)
        filename = f'{savedir}/toy1gvs125m-{prefix}-{timebase[i]}-{noise_name}.npz'
Ejemplo n.º 10
0
}

###########################

fig, axs = plt.subplots(1,
                        2,
                        num='fignoise',
                        clear=True,
                        figsize=[9, 3.3],
                        sharex=True,
                        sharey=True)

for ax, (label, noisefile, N, timebase) in zip(axs, config):

    basetb = np.gcd.reduce(timebase)
    noise = toy.DataCycleNoise(timebase=basetb)
    noise.load(noisefile)

    ax.set_xlabel(f'Time [ns]')

    n = noise.generate(1, 3 * N)[0]
    for tb in timebase:
        nr = toy.downsample(n, tb // basetb)
        x = (tb - 1) / 2 + tb * np.arange(len(nr)) - N
        kwargs = dict(
            label=num2si.num2si(1e9 / tb, format='%.3g') + 'Sa/s',
            marker='.',
        )
        kwargs.update(plotkw[tb])
        ax.plot(x, nr, **kwargs)