Пример #1
0
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...')
    t.run(1000, pbar=10, seed=202012071818)

    # Make window center argument for Toy.run_window.
    isnr = np.searchsorted(snr, 2.4)
    res = t.templocres()  # shape == (nfilter, ntau, nsnr)
    ifilterisnritau = np.array([
        (3, -1, -1),  # matched, high snr, high tau
        (3, isnr, 7),  # matched, tau=64
        (2, isnr, np.argmin(res[2, :, isnr])),  # exp, best tau
        (1, isnr, np.argmin(res[1, :, isnr])),  # movavg, best tau
    ])
    wcenter = t.window_center(*ifilterisnritau.T)
Пример #2
0
                basenoise = noise
                basetb = tb
            noise_ratio[tb] = np.std(toy.downsample(
                basenoise.generate(20, 5000), tb // basetb),
                                     axis=None)

        for tb in timebases:

            filename = simfile(n, tb)
            if os.path.exists(filename):
                continue

            nr = noise_ratio[tb] / noise_ratio[8]
            snr = snr_125MSa / nr
            sim = toy.Toy(template, [tau_125MSa * 8 // tb],
                          snr,
                          noises[tb],
                          timebase=tb)
            sim.noise_ratio = nr
            sim.run(1000, pbar=10, seed=202102191411)
            print(f'save {filename}')
            sim.save(filename)

sim = {}
for n, timebases in timebase.items():
    sim[n] = {}
    for tb in timebases:
        filename = simfile(n, tb)
        print(f'load {filename}')
        sim[n][tb] = toy.Toy.load(filename)

Пример #3
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)
Пример #4
0
import os
import logging
import fuse
import time

import toy

fuse.fuse_python_api = (0, 2)

# Logging
logger = logging.getLogger("toyfs")
handler = logging.FileHandler('toyfs.log')
logger.addHandler(handler)
logger.setLevel(logging.INFO)

fs = toy.Toy()


# ToyFS
class ToyFS(fuse.Fuse):
    def getattr(self, path):
        logger.info("[getattr] (path=%s)" % path)
        st = fs.getattr(path)
        return st

    def readdir(self, path, offset):
        logger.info("[readdir] (path=%s, offset=%s)" % (path, offset))
        directories = fs.readdir(path)
        for directory in directories:
            yield fuse.Direntry(directory)
Пример #5
0
"""
A simple example: 
    - Solve a snake cube of length 3
    - write all solutions to `example_solutions.py`
    - visualize the first solution 
"""

import toy
import visualize 

if __name__ == "__main__": 
    strip_lengths = [2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2]
    toy = toy.Toy(strip_lengths) 
    toy.run()
    if toy.solutions():
        print("I found " + str(len(toy.solutions())) + " solutions! =D")
        file_name = "example_solutions.py" 
        with open(file_name, 'w') as fh:
            fh.write("strip_lengths = " + str(strip_lengths) + "\n\n")
            str_sols = "".join(["    " + str(sol)+",\n" for sol in toy.solutions()]) 
            fh.write("solutions = {\n" + str_sols + "    }")
        print("solutions written to `" + file_name + "`")
        # Visualizing a solution
        print("... visualizing ...")
        visualize.visualize(toy.solutions()[0]) 

    else: 
        print("I found no solutions :'(")

Пример #6
0
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])

sim.plot_event(ievent=0, ifilter=locfilter, isnr=0, itau=0, ax=axs[0])
sim.plot_event_window(ievent=0, isnr=0, itau=1, iwlen=0, icenter=1, ax=axs[1])
Пример #7
0
"""

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'
    print(f'saving to {filename}...')
    toys[inoise].save(filename)
Пример #8
0
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)
        ifilterisnritau = np.array([
            (3, i, itau(64)),  # matched N=64
            (2, i, np.argmin(res[2, :, i])),  # exp, best tau
        ])
        wcenter = sim.window_center(*ifilterisnritau.T)

        sim.run_window(wlen, wlmargin, wcenter, pbar=10)

        print(f'save {simfile(n)}')
        sim.save(simfile(n))
Пример #9
0
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'
        print(f'saving to {filename}...')
        t.save(filename)
Пример #10
0
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_white = toy.WhiteNoise()
    noise = dict(proto0=noise_proto0, white=noise_white, 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], **options.get(n, {}))
        sim.run(1000, pbar=10, seed=202102181611)
        print(f'save {simfile(n)}')
        sim.save(simfile(n))

sim = {}
for n in names:
    print(f'load {simfile(n)}')
    sim[n] = toy.Toy.load(simfile(n))
    assert np.array_equal(sim[n].tau, tau)
    assert np.array_equal(sim[n].snr, snr)

fig, ax = plt.subplots(num='figrescomp', clear=True, figsize=[7, 10])


def isomething(a, x, strict=True):