def test_fit_single_dataset(IR_dataset_2D, script):
    dataset = IR_dataset_2D[54, 3700.0:3400.0]

    f1 = Fit(dataset, script, silent=True)
    f1.run(maxiter=10, every=1)
    #    assert_approx_equal(dataset.model_A, -116.40475, significant=4)
    #    assert_approx_equal(f1.fp['width_line_2'], 195.7273, significant=4)
    dataset.plot(plot_model=True)

    dataset2 = dataset.copy() * 2.34
    f2 = Fit(dataset2, script, silent=True)
    f2.run(maxiter=10, every=1)

    dataset2.plot(plot_model=True)

    assert_approx_equal(dataset2.model_A, 1389.6235438214812, significant=4)
    assert_approx_equal(f2.fp["width_line_2"], 184.6313, significant=4)

    f2 = Fit(dataset2, script, silent=False)
    f2.run(maxiter=100, every=1)

    dataset2.plot(plot_model=True)
    show()
def test_fit_multiple_dataset(IR_dataset_2D, script):
    dataset = IR_dataset_2D[54, 3700.0:3400.0]
    datasets = [dataset.copy(), dataset.copy() * 2.23456]
    f = Fit(datasets, script, silent=True)
    f.run(maxiter=10, every=1)
    assert_approx_equal(datasets[0].model_A, 593.8562153083558, significant=4)
    assert_approx_equal(datasets[1].model_A,
                        593.8562153083558 * 2.23456,
                        significant=4)
    assert_approx_equal(f.fp["width_line_2"], 184.6313, significant=4)
Exemple #3
0
def test_fit_multiple_dataset(IR_dataset_2D, script):
    dataset = IR_dataset_2D[54, 3700.:3400.]
    datasets = [dataset.copy(), dataset.copy() * 2.23456]
    f = Fit(datasets, script, silent=True)
    f.run(maxiter=10, every=1)
    assert_approx_equal(datasets[0].model_A, 116.3807504474709, significant=4)
    assert_approx_equal(datasets[1].model_A,
                        116.3807504474709 * 2.23456,
                        significant=4)
    assert_approx_equal(f.fp['width_line_2'], 195.7273, significant=4)
Exemple #4
0
def test_ndcomplex_slicing_byindex_quaternion(ndarrayquaternion):
    ndc = ndarrayquaternion.copy()
    ndc1 = ndc[1, 1].real
    assert_approx_equal(ndc1.values.magnitude, 4.646475973719301, 3)
def test_linearcoord():
    coord1 = Coord([1, 2.5, 4, 5])

    coord2 = Coord(np.array([1, 2.5, 4, 5]))
    assert coord2 == coord1

    coord3 = Coord(range(10))

    coord4 = Coord(np.arange(10))
    assert coord4 == coord3

    coord5 = coord4.copy()
    coord5 += 1
    assert np.all(coord5.data == coord4.data + 1)

    assert coord5 is not None
    coord5.linear = True

    coord6 = Coord(linear=True, offset=2.0, increment=2.0, size=10)
    assert np.all(coord6.data == (coord4.data + 1.0) * 2.0)

    LinearCoord(offset=2.0, increment=2.0, size=10)

    coord0 = LinearCoord.linspace(
        200.0,
        300.0,
        3,
        labels=["cold", "normal", "hot"],
        units="K",
        title="temperature",
    )
    coord1 = LinearCoord.linspace(0.0,
                                  60.0,
                                  100,
                                  labels=None,
                                  units="minutes",
                                  title="time-on-stream")
    coord2 = LinearCoord.linspace(4000.0,
                                  1000.0,
                                  100,
                                  labels=None,
                                  units="cm^-1",
                                  title="wavenumber")

    assert coord0.size == 3
    assert coord1.size == 100
    assert coord2.size == 100

    coordc = coord0.copy()
    assert coord0 == coordc

    coordc = coord1.copy()
    assert coord1 == coordc

    assert_approx_equal(coord1.spacing.m, 0.606060606)

    assert coord1.author is None
    assert not coord1.history

    assert not coord1.descendant
    assert coord2.descendant

    assert coord1.is_1d

    assert coord0.transpose() == coord0
def test_models():

    model = scp.asymmetricvoigtmodel()
    assert model.args == ["ampl", "pos", "width", "ratio", "asym"]

    x = np.arange(1000)
    ampl = 1000.0
    width = 100
    ratio = 0
    asym = 1.5
    pos = 500

    max = 6.366197723675813

    array = model.f(x, ampl, pos, width, ratio, asym)
    assert array.shape == (1000, )
    assert_approx_equal(array[pos], max, significant=4)

    array = model.f(x, 2.0 * ampl, pos, width, ratio, asym)  # ampl=2.
    assert_approx_equal(array[pos], max * 2.0, significant=4)

    # x array with units
    x1 = x * ur("cm")
    array = model.f(x1, ampl, pos, width, ratio, asym)
    assert_approx_equal(array[pos], max, significant=4)
    assert not hasattr(array, "units")

    # amplitude with units
    ampl = 1000.0 * ur("g")
    array = model.f(x1, ampl, pos, width, ratio, asym)
    assert hasattr(array, "units")
    assert array.units == ur("g")
    assert_approx_equal(array[pos].m, max, significant=4)

    # use keyword instead of positional parameters
    array = model.f(x1, ampl, pos, asym=asym, width=width, ratio=ratio)
    assert_approx_equal(array[pos].m, max, significant=4)

    # rescale some parameters
    array = model.f(x1,
                    width=1000.0 * ur("mm"),
                    ratio=ratio,
                    asym=asym,
                    ampl=ampl,
                    pos=pos)
    assert_approx_equal(array[pos].m, max, significant=4)

    # x is a Coord object
    x2 = scp.LinearCoord.arange(1000)
    width = 100.0
    array = model.f(x2, ampl, pos, width, ratio, asym)
    assert isinstance(array, scp.NDDataset)
    assert_approx_equal(array[pos].value.m, max, significant=4)
    assert array.units == ampl.units

    # x is a Coord object with units
    x3 = scp.LinearCoord.linspace(0.0,
                                  0.999,
                                  1000,
                                  units="m",
                                  title="distance")
    width = 100.0 * ur("mm")
    pos = 0.5
    array = model.f(x3, ampl, pos, width, ratio, asym)
    assert hasattr(array, "units")
    assert_approx_equal(array[500].m, max, significant=4)

    # do the same for various models
    kwargs = dict(
        ampl=1.0 * ur["g"],
        width=100.0 * ur("mm"),
        ratio=0.5,
        asym=2,
        pos=0.5,
        c_2=1.0,
    )

    for modelname, expected in [
        ("gaussianmodel", 0.9394292818892936),
        ("lorentzianmodel", 0.6366197723675814),
        ("voigtmodel", 0.8982186579508358),
        ("asymmetricvoigtmodel", 0.8982186579508358),
        ("polynomialbaseline", 0.0),
        ("sigmoidmodel", 50),
    ]:
        model = getattr(scp, modelname)()
        if modelname == "sigmoid":
            kwargs["width"] = 0.01
        array = model.f(x3, **kwargs)
        actual = array[pos].value
        if modelname != "sigmoid":
            actual = actual * 100
        assert_approx_equal(actual.m, expected, 4)