示例#1
0
"""Here we mostly test if it works at all."""
from skultrafast.dataset import TimeResSpec, PolTRSpec
from skultrafast.data_io import load_example
import numpy as np
from numpy.testing import assert_almost_equal

wl, t, data = load_example()


def test_integrate():
    ds = TimeResSpec(wl, t, data)
    ds.wn_i(15000, 20000)


def test_methods():
    ds = TimeResSpec(wl, t, data)
    bds = ds.bin_freqs(300)
    ds2 = TimeResSpec(1e7 / wl, t, data, freq_unit='cm', disp_freq_unit='cm')
    bds2 = ds2.bin_freqs(50)
    assert (np.all(np.isfinite(bds2.data)))

    assert (len(bds.wavelengths) == 300)
    nds = ds.cut_freq(400, 600)
    assert (np.all(nds.wavelengths > 600))
    nds = ds.cut_time(-100, 1)
    assert (np.all(nds.t > .99))
    nds = ds.bin_times(5)
    assert (nds.t.size == np.ceil(ds.t.size / 5))
    ds.mask_freqs([(400, 600)])
    assert (np.all(ds.data.mask[:, ds.wl_idx(550)]))
    ds2 = ds.scale_and_shift(2, t_shift=1, wl_shift=10)
示例#2
0
def test_load_exmaple():
    wl, t, d = data_io.load_example()
    assert ((t.shape[0], wl.shape[0]) == d.shape)
示例#3
0
"""Here we mostly test if it works at all."""
from skultrafast.dataset import TimeResSpec, PolTRSpec
from skultrafast.data_io import  load_example
import numpy as np
from numpy.testing import assert_almost_equal

wl, t, data = load_example()

def test_methods():
    ds = TimeResSpec(wl, t, data)
    bds = ds.bin_freqs(300)
    assert(len(bds.wavelengths) == 300)
    nds = ds.cut_freqs([(400, 600)])
    assert(np.all(nds.wavelengths > 600))
    nds = ds.cut_times([(-100, 1)])
    assert(np.all(nds.t > .99))
    nds = ds.bin_times(5)
    assert(nds.t.size == np.ceil(ds.t.size/5))
    ds.mask_freqs([(400, 600)])
    assert(np.all(ds.data.mask[:, ds.wl_idx(550)]))

def test_est_disp():
    ds = TimeResSpec(wl, t, data)
    ds.auto_plot =  False
    for s in ['abs', 'diff', 'gauss_diff', 'max']:
        ds.estimate_dispersion(heuristic=s)

def test_fitter():
    ds = TimeResSpec(wl, t, data)
    x0 = [0.1, 0.1, 1, 1000]
    out = ds.fit_exp(x0)
j
# %%
# The transformation matrix is then given by

A = vecs @ np.diag(np.linalg.inv(vecs) @ j)
A_inv = np.linalg.inv(A)

# %%
# Now `DAS @ A_inv` should give the SAS, while `A_inv @ basis_vecs` should
# return the time-depedence of the concentrations. Let's test that on some data.
# Load test data and correct the dispersion.

from skultrafast import dataset, data_io, plot_helpers
plot_helpers.enable_style()

wl, t, d = data_io.load_example()
ds = dataset.TimeResSpec(wl, t, d)
dsb = ds.bin_freqs(50)  # Bin dataset to save computation while building docs
res = dsb.estimate_dispersion(heuristic_args=(1.5, ), deg=3, shift_result=.15)

# %%
# Fit the DAS first.

ids = res.correct_ds
fr = ids.fit_exp([0.0, 0.08, 1, 500000],
                 model_coh=True,
                 fix_sigma=False,
                 fix_t0=False)
ids.plot.das()

# %%
示例#5
0
# %%
# Some matplotlib setting for nicer pictures.
plt.rcParams['figure.dpi'] = 150
plt.rcParams['figure.figsize'] = (4, 3)
plt.rcParams['figure.autolayout'] = True
plt.rcParams['font.size'] = 9

# %% [markdown]
# Creating a TimeResSpec
# ----------------------
# In this tuturial we use the example data which is provided by *skultrafast*.
# The `load_example` function gives us three arrays. One containing the wavelengths,
# another one containing the delay times and one two dimensional array containing
# the data in mOD.

wavelengths, t_ps, data_mOD = data_io.load_example()

# %%
# Lets look at the constructor of the `TimeResSpec` (Time resolved Spectra) class,
# which is the main object when working with single data:
print(TimeResSpec.__init__.__doc__)


# %%
# As we see, we can supply all the required parameters.
# Since the `freq_unit` defaults to 'nm' we don't need to supply this argument.

ds = TimeResSpec(wavelengths, t_ps, data_mOD)


# %%