<commit_before>from __future__ import division
import numpy as np
from numpy.testing import assert_allclose, assert_array_almost_equal
from fatiando.gravmag.eqlayer import (EQLGravity, EQLTotalField,
                                      PELGravity, PELTotalField, PELSmoothness)
from fatiando.inversion import Damping
from fatiando.gravmag import sphere, prism
from fatiando.mesher import PointGrid, Prism
from fatiando import utils, gridder


def test_pel_polereduce():
    "PELTotalField can reduce data to the pole"
    # Use remanent magnetization
    sinc, sdec = -70, 30
    model = [Prism(-100, 100, -500, 500, 0, 100,
                   {'magnetization': utils.ang2vec(5, sinc, sdec)})]
    inc, dec = -60, -15
    shape = (40, 40)
    area = [-2000, 2000, -2000, 2000]
    x, y, z = gridder.regular(area, shape, z=-100)
    data = prism.tf(x, y, z, model, inc, dec)
    true = prism.tf(x, y, z, model, -90, 0, pmag=utils.ang2vec(5, -90, 0))

    layer = PointGrid(area, 100, shape)
    windows = (20, 20)
    degree = 3
    pel = PELTotalField(x, y, z, data, inc, dec, layer, windows, degree,
                        sinc, sdec)
    eql = pel + 1e-25*PELSmoothness(layer, windows, degree)
    eql.fit()

    assert_array_almost_equal(eql[0].predicted(), data, decimal=1)

    layer.addprop('magnetization',
                  utils.ang2vec(eql.estimate_, inc=-90, dec=0))
    calc = sphere.tf(x, y, z, layer, inc=-90, dec=0)

    assert_allclose(calc, true, atol=10, rtol=0.05)


def test_pelgrav_prism_interp():
    "PELGravity can interpolate data from a prism"
    model = [Prism(-300, 300, -500, 500, 100, 600, {'density': 400})]
    shape = (40, 40)<commit_msg>Less radical test for eqlayer pole reduction (#358)<commit_after>from __future__ import division
import numpy as np
from numpy.testing import assert_allclose, assert_array_almost_equal
from fatiando.gravmag.eqlayer import (EQLGravity, EQLTotalField,
                                      PELGravity, PELTotalField, PELSmoothness)
from fatiando.inversion import Damping
from fatiando.gravmag import sphere, prism
from fatiando.mesher import PointGrid, Prism
from fatiando import utils, gridder


def test_pel_polereduce():
    "PELTotalField can reduce data to the pole"
    # Use remanent magnetization
    sinc, sdec = -80, 5
    model = [Prism(-100, 100, -500, 500, 0, 100,
                   {'magnetization': utils.ang2vec(5, sinc, sdec)})]
    inc, dec = -83, 5
    shape = (40, 40)
    area = [-2000, 2000, -2000, 2000]
    x, y, z = gridder.regular(area, shape, z=-100)
    data = prism.tf(x, y, z, model, inc, dec)
    true = prism.tf(x, y, z, model, -90, 0, pmag=utils.ang2vec(5, -90, 0))

    layer = PointGrid(area, 100, shape)
    windows = (20, 20)
    degree = 3
    pel = PELTotalField(x, y, z, data, inc, dec, layer, windows, degree,
                        sinc, sdec)
    eql = pel + 1e-25*PELSmoothness(layer, windows, degree)
    eql.fit()

    assert_array_almost_equal(eql[0].predicted(), data, decimal=1)

    layer.addprop('magnetization',
                  utils.ang2vec(eql.estimate_, inc=-90, dec=0))
    calc = sphere.tf(x, y, z, layer, inc=-90, dec=0)

    assert_allclose(calc, true, atol=10, rtol=0.05)


def test_pelgrav_prism_interp():
    "PELGravity can interpolate data from a prism"
    model = [Prism(-300, 300, -500, 500, 100, 600, {'density': 400})]
    shape = (40, 40)
{'fraction_non_alphanumeric': 0.1258493353028065, 'fraction_numerical': 0.06351550960118169, 'mean_word_length': 3.0261593341260404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3938136', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1184, 'n_words': 342}