<commit_before># transform. Status 5/8
import pytest
import numpy as np
from os.path import join, dirname
from numpy.testing import assert_allclose

from empymod import transform, filters

# No input checks are carried out in transform, by design. Input checks are
# carried out in model/utils, not in the core functions kernel/transform.
# Rubbish in, rubbish out. So we also do not check these functions for wrong
# inputs.

# Load required data
# Data generated with create_transform.py [27/01/2017]
DATA = np.load(join(dirname(__file__), 'data_transform.npz'))

# 1. fht

# 2. hqwe


class TestFFT:                                   # 3. fft / 4. fqwe / 5. fftlog
    # Check FFT-method with the analytical functions for a halfspace.
    @pytest.mark.parametrize("ftype", ['fft', 'fqwe', 'fftlog'])
    def test_fft(self, ftype):
        t = DATA['t'][()]
        for i in [0, 1]:
            fl = DATA[ftype+str(i)][()]
            res = DATA['tEM'+str(i)][()]
            if i == 1:
                finp = fl['fEM']/(2j*np.pi*fl['f'])
            else:
                finp = fl['fEM']
            tEM, _ = getattr(transform, ftype)(finp, t, fl['f'], fl['ftarg'])
            assert_allclose(tEM*2/np.pi, res, rtol=1e-3)


# 6. qwe


def test_get_spline_values():                            # 7. get_spline_values
    # Check one example
    out, new_inp = transform.get_spline_values(filters.key_81_CosSin_2009(),
                                               np.arange(1, 6), None)
    # Expected values
    oout = np.array([[6.70925256e-05, 8.19469958e-05, 1.00090287e-04,
                      1.22250552e-04, 1.49317162e-04, 1.82376393e-04,
                      2.22755030e-04, 2.72073608e-04, 3.32311455e-04,
                      4.05886127e-04, 4.95750435e-04, 6.05510949e-04,
                      7.39572743e-04, 9.03316189e-04, 1.10331288e-03,
                      1.34758940e-03, 1.64594941e-03, 2.01036715e-03,
                      2.45546798e-03, 2.99911536e-03, 3.66312778e-03,
                      4.47415437e-03, 5.46474449e-03, 6.67465399e-03,
                      8.15244080e-03, 9.95741367e-03, 1.21620125e-02,
                      1.48547156e-02, 1.81435907e-02, 2.21606317e-02,
                      2.70670566e-02, 3.30597776e-02, 4.03793036e-02,
                      4.93193928e-02, 6.02388424e-02, 7.35758882e-02,
                      8.98657928e-02, 1.09762327e-01, 1.34064009e-01,
                      1.63746151e-01, 2.00000000e-01, 2.44280552e-01,
                      2.98364940e-01, 3.64423760e-01, 4.45108186e-01,
                      5.43656366e-01, 6.64023385e-01, 8.11039993e-01,
                      9.90606485e-01, 1.20992949e+00, 1.47781122e+00,
                      1.80500270e+00, 2.20463528e+00, 2.69274761e+00,
                      3.28892935e+00, 4.01710738e+00, 4.90650604e+00,
                      5.99282001e+00, 7.31964689e+00, 8.94023690e+00,
                      1.09196300e+01, 1.33372662e+01, 1.62901737e+01,
                      1.98968631e+01, 2.43020835e+01, 2.96826318e+01,
                      3.62544484e+01, 4.42812832e+01, 5.40852815e+01,
                      6.60599120e+01, 8.06857587e+01, 9.85498082e+01,
                      1.20369008e+02, 1.47019038e+02, 1.79569458e+02,
                      2.19326632e+02, 2.67886153e+02, 3.27196886e+02,
                      3.99639179e+02, 4.88120396e+02, 5.96191597e+02,
                      7.28190061e+02, 8.89413350e+02, 1.08633192e+03,
                      1.32684880e+03, 1.62061679e+03, 1.97942581e+03,
                      2.41767615e+03, 2.95295631e+03, 3.60674899e+03]])
    onew_inp = np.array([5., 4.09365377, 3.35160023, 2.74405818, 2.24664482,
                         1.83939721, 1.50597106, 1.23298482, 1.00948259,
                         0.82649444])
    # Comparison
    assert_allclose(out, oout)
    assert_allclose(new_inp, onew_inp)
<commit_msg>Tests status: 24/52<commit_after># transform. Status 6/8
import pytest
import numpy as np
from os.path import join, dirname
from numpy.testing import assert_allclose

from empymod import transform, filters, kernel, utils

# No input checks are carried out in transform, by design. Input checks are
# carried out in model/utils, not in the core functions kernel/transform.
# Rubbish in, rubbish out. So we also do not check these functions for wrong
# inputs.

# Load required data
# Data generated with create_transform.py [27/01/2017]
DATA = np.load(join(dirname(__file__), 'data_transform.npz'))


def test_fht():                                                        # 1. fht
    # Compare wavenumber-domain calculation / FHT with analytical
    # frequency-domain fullspace solution
    model = utils.check_model([], 10, 2, 2, 5, 1, 10, 0)
    depth, res, aniso, epermH, epermV, mpermH, mpermV, isfullspace = model
    frequency = utils.check_frequency(1, res, aniso, epermH, epermV, mpermH,
                                      mpermV, 0)
    freq, etaH, etaV, zetaH, zetaV = frequency
    src = [0, 0, 0]
    src, nsrc = utils.check_dipole(src, 'src', 0)
    ht, htarg = utils.check_hankel('fht', None, 0)
    ab, msrc, mrec = utils.check_ab(11, 0)
    options = utils.check_opt(None, None, 'fht', None, 0)
    use_spline, use_ne_eval, loop_freq, loop_off = options
    xdirect = False  # Important, as we want to compare wavenumber-frequency!
    rec = [np.arange(1, 11)*500, np.zeros(10), 300]
    rec, nrec = utils.check_dipole(rec, 'rec', 0)
    off, angle = utils.get_off_ang(src, rec, nsrc, nrec, 0)
    lsrc, zsrc = utils.get_layer_nr(src, depth)
    lrec, zrec = utils.get_layer_nr(rec, depth)

    # # # 0. No Spline # # #
    # Wavenumber solution plus transform
    wvnr0, _, _ = transform.fht(zsrc, zrec, lsrc, lrec, off, angle, depth, ab,
                                etaH, etaV, zetaH, zetaV, xdirect, htarg,
                                use_spline, False, msrc, mrec)
    wvnr0 = np.squeeze(wvnr0)
    # Analytical frequency-domain solution
    freq0 = kernel.fullspace(off, angle, zsrc, zrec, etaH, etaV, zetaH, zetaV,
                             ab, msrc, mrec)
    freq0 = np.squeeze(freq0)
    # Compare
    assert_allclose(wvnr0, freq0)

    # # # 1. Spline; One angle # # #
    options = utils.check_opt('spline', None, 'fht', None, 0)
    use_spline, use_ne_eval, loop_freq, loop_off = options
    # Wavenumber solution plus transform
    wvnr1, _, _ = transform.fht(zsrc, zrec, lsrc, lrec, off, angle, depth, ab,
                                etaH, etaV, zetaH, zetaV, xdirect, htarg,
                                use_spline, False, msrc, mrec)
    wvnr1 = np.squeeze(wvnr1)
    # Analytical frequency-domain solution
    freq1 = kernel.fullspace(off, angle, zsrc, zrec, etaH, etaV, zetaH, zetaV,
                             ab, msrc, mrec)
    freq1 = np.squeeze(freq1)
    # Compare
    assert_allclose(wvnr1, freq1, rtol=1e-4)

    # # # 2. Spline; Multi angle # # #
    rec = [np.arange(1, 11)*500, np.arange(-5, 5)*200, 300]
    rec, nrec = utils.check_dipole(rec, 'rec', 0)
    off, angle = utils.get_off_ang(src, rec, nsrc, nrec, 0)
    # Analytical frequency-domain solution
    wvnr2, _, _ = transform.fht(zsrc, zrec, lsrc, lrec, off, angle, depth, ab,
                                etaH, etaV, zetaH, zetaV, xdirect, htarg,
                                use_spline, False, msrc, mrec)
    wvnr2 = np.squeeze(wvnr2)
    # Analytical frequency-domain solution
    freq2 = kernel.fullspace(off, angle, zsrc, zrec, etaH, etaV, zetaH, zetaV,
                             ab, msrc, mrec)
    freq2 = np.squeeze(freq2)
    # Compare
    assert_allclose(wvnr2, freq2, rtol=1e-4)

    # # # 3. Spline; ndec # # #
    ht, htarg = utils.check_hankel('fht', ['key_201_2012', 20], 0)
    # Analytical frequency-domain solution
    wvnr3, _, _ = transform.fht(zsrc, zrec, lsrc, lrec, off, angle, depth, ab,
                                etaH, etaV, zetaH, zetaV, xdirect, htarg,
                                use_spline, False, msrc, mrec)
    wvnr3 = np.squeeze(wvnr3)
    # Analytical frequency-domain solution
    freq3 = kernel.fullspace(off, angle, zsrc, zrec, etaH, etaV, zetaH, zetaV,
                             ab, msrc, mrec)
    freq3 = np.squeeze(freq3)
    # Compare
    assert_allclose(wvnr3, freq3, rtol=1e-4)

    # # # 4. Spline; Only one offset # # #
    rec = [5000, 0, 300]
    rec, nrec = utils.check_dipole(rec, 'rec', 0)
    off, angle = utils.get_off_ang(src, rec, nsrc, nrec, 0)
    # Analytical frequency-domain solution
    wvnr4, _, _ = transform.fht(zsrc, zrec, lsrc, lrec, off, angle, depth, ab,
                                etaH, etaV, zetaH, zetaV, xdirect, htarg,
                                use_spline, False, msrc, mrec)
    wvnr4 = np.squeeze(wvnr4)
    # Analytical frequency-domain solution
    freq4 = kernel.fullspace(off, angle, zsrc, zrec, etaH, etaV, zetaH, zetaV,
                             ab, msrc, mrec)
    freq4 = np.squeeze(freq4)
    # Compare
    assert_allclose(wvnr4, freq4, rtol=1e-4)


# 2. hqwe


class TestFFT:                                   # 3. fft / 4. fqwe / 5. fftlog
    # Check FFT-method with the analytical functions for a halfspace.
    @pytest.mark.parametrize("ftype", ['fft', 'fqwe', 'fftlog'])
    def test_fft(self, ftype):
        t = DATA['t'][()]
        for i in [0, 1]:
            fl = DATA[ftype+str(i)][()]
            res = DATA['tEM'+str(i)][()]
            if i == 1:
                finp = fl['fEM']/(2j*np.pi*fl['f'])
            else:
                finp = fl['fEM']
            tEM, _ = getattr(transform, ftype)(finp, t, fl['f'], fl['ftarg'])
            assert_allclose(tEM*2/np.pi, res, rtol=1e-3)


# 6. qwe


def test_get_spline_values():                            # 7. get_spline_values
    # Check one example
    filt = filters.key_81_CosSin_2009()
    out, new_inp = transform.get_spline_values(filt, np.arange(1, 6), None)
    # Expected values
    oout = np.array([[6.70925256e-05, 8.19469958e-05, 1.00090287e-04,
                      1.22250552e-04, 1.49317162e-04, 1.82376393e-04,
                      2.22755030e-04, 2.72073608e-04, 3.32311455e-04,
                      4.05886127e-04, 4.95750435e-04, 6.05510949e-04,
                      7.39572743e-04, 9.03316189e-04, 1.10331288e-03,
                      1.34758940e-03, 1.64594941e-03, 2.01036715e-03,
                      2.45546798e-03, 2.99911536e-03, 3.66312778e-03,
                      4.47415437e-03, 5.46474449e-03, 6.67465399e-03,
                      8.15244080e-03, 9.95741367e-03, 1.21620125e-02,
                      1.48547156e-02, 1.81435907e-02, 2.21606317e-02,
                      2.70670566e-02, 3.30597776e-02, 4.03793036e-02,
                      4.93193928e-02, 6.02388424e-02, 7.35758882e-02,
                      8.98657928e-02, 1.09762327e-01, 1.34064009e-01,
                      1.63746151e-01, 2.00000000e-01, 2.44280552e-01,
                      2.98364940e-01, 3.64423760e-01, 4.45108186e-01,
                      5.43656366e-01, 6.64023385e-01, 8.11039993e-01,
                      9.90606485e-01, 1.20992949e+00, 1.47781122e+00,
                      1.80500270e+00, 2.20463528e+00, 2.69274761e+00,
                      3.28892935e+00, 4.01710738e+00, 4.90650604e+00,
                      5.99282001e+00, 7.31964689e+00, 8.94023690e+00,
                      1.09196300e+01, 1.33372662e+01, 1.62901737e+01,
                      1.98968631e+01, 2.43020835e+01, 2.96826318e+01,
                      3.62544484e+01, 4.42812832e+01, 5.40852815e+01,
                      6.60599120e+01, 8.06857587e+01, 9.85498082e+01,
                      1.20369008e+02, 1.47019038e+02, 1.79569458e+02,
                      2.19326632e+02, 2.67886153e+02, 3.27196886e+02,
                      3.99639179e+02, 4.88120396e+02, 5.96191597e+02,
                      7.28190061e+02, 8.89413350e+02, 1.08633192e+03,
                      1.32684880e+03, 1.62061679e+03, 1.97942581e+03,
                      2.41767615e+03, 2.95295631e+03, 3.60674899e+03]])
    onew_inp = np.array([5., 4.09365377, 3.35160023, 2.74405818, 2.24664482,
                         1.83939721, 1.50597106, 1.23298482, 1.00948259,
                         0.82649444])
    # Comparison
    assert_allclose(out, oout)
    assert_allclose(new_inp, onew_inp)

    # Ensure out has dimension len(filter.base)+3, if inp is smaller than that
    filt = filters.anderson_801_1982()
    out, _ = transform.get_spline_values(filt, np.array([1, 1.1]), None)
    assert_allclose(out.size, 804)

{'fraction_non_alphanumeric': 0.12492007672634271, 'fraction_numerical': 0.18773976982097187, 'mean_word_length': 1.8985406532314106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2815316', 'n_tokens_mistral': 6288, 'n_tokens_neox': 4824, 'n_words': 936}