def test_closed_form():
    "gravmag.normal_gravity.gamma_closed_form compatible with somigliana"
    lat = numpy.linspace(-90, 90, 200)
    som = gamma_somigliana(lat, ellipsoid=WGS84)
    closed = gamma_closed_form(lat, 0, ellipsoid=WGS84)
    for i in xrange(len(lat)):
        assert_almost_equal(closed[i], som[i], decimal=3,
                            err_msg='lat = {}'.format(lat[i]))

    gradient = (gamma_closed_form(lat, 1, ellipsoid=WGS84)
                - gamma_closed_form(lat, 0, ellipsoid=WGS84))
    mean = numpy.mean(gradient)
    assert_almost_equal(mean, -0.3086, decimal=4, err_msg='mean vs free-air')

    gamma_a = gamma_closed_form(0, 0, ellipsoid=WGS84)
    assert_almost_equal(gamma_a, utils.si2mgal(WGS84.gamma_a), decimal=5,
                        err_msg='equator vs gamma_a')

    gamma_b = gamma_closed_form(90, 0, ellipsoid=WGS84)
    assert_almost_equal(gamma_b, utils.si2mgal(WGS84.gamma_b), decimal=5,
                        err_msg='north pole vs gamma_b')

    gamma_b = gamma_closed_form(-90, 0, ellipsoid=WGS84)
    assert_almost_equal(gamma_b, utils.si2mgal(WGS84.gamma_b), decimal=5,
                        err_msg='south pole vs gamma_b')
def test_closed_form():
    "gravmag.normal_gravity.gamma_closed_form compatible with somigliana"
    lat = numpy.linspace(-90, 90, 200)
    som = gamma_somigliana(lat, ellipsoid=WGS84)
    closed = gamma_closed_form(lat, 0, ellipsoid=WGS84)
    for i in xrange(len(lat)):
        assert_almost_equal(closed[i],
                            som[i],
                            decimal=3,
                            err_msg='lat = {}'.format(lat[i]))

    gradient = (gamma_closed_form(lat, 1, ellipsoid=WGS84) -
                gamma_closed_form(lat, 0, ellipsoid=WGS84))
    mean = numpy.mean(gradient)
    assert_almost_equal(mean, -0.3086, decimal=4, err_msg='mean vs free-air')

    gamma_a = gamma_closed_form(0, 0, ellipsoid=WGS84)
    assert_almost_equal(gamma_a,
                        utils.si2mgal(WGS84.gamma_a),
                        decimal=5,
                        err_msg='equator vs gamma_a')

    gamma_b = gamma_closed_form(90, 0, ellipsoid=WGS84)
    assert_almost_equal(gamma_b,
                        utils.si2mgal(WGS84.gamma_b),
                        decimal=5,
                        err_msg='north pole vs gamma_b')

    gamma_b = gamma_closed_form(-90, 0, ellipsoid=WGS84)
    assert_almost_equal(gamma_b,
                        utils.si2mgal(WGS84.gamma_b),
                        decimal=5,
                        err_msg='south pole vs gamma_b')
def test_somigliana():
    "gravmag.normal_gravity.gamma_somigliana computes consistent results"
    res = gamma_somigliana(0, ellipsoid=WGS84)
    assert res == utils.si2mgal(WGS84.gamma_a), \
        "somigliana at equator != from gamma_a: {:.20f}".format(res)
    res = gamma_somigliana(90, ellipsoid=WGS84)
    assert res == utils.si2mgal(WGS84.gamma_b), \
        "somigliana at north pole != from gamma_b: {:.20f}".format(res)
    res = gamma_somigliana(-90, ellipsoid=WGS84)
    assert res == utils.si2mgal(WGS84.gamma_b), \
        "somigliana at south pole != from gamma_b: {:.20f}".format(res)
def test_somigliana():
    "gravmag.normal_gravity.gamma_somigliana computes consistent results"
    res = gamma_somigliana(0, ellipsoid=WGS84)
    assert res == utils.si2mgal(WGS84.gamma_a), \
        "somigliana at equator != from gamma_a: {:.20f}".format(res)
    res = gamma_somigliana(90, ellipsoid=WGS84)
    assert res == utils.si2mgal(WGS84.gamma_b), \
        "somigliana at north pole != from gamma_b: {:.20f}".format(res)
    res = gamma_somigliana(-90, ellipsoid=WGS84)
    assert res == utils.si2mgal(WGS84.gamma_b), \
        "somigliana at south pole != from gamma_b: {:.20f}".format(res)
示例#5
0
    def jacobian(self, p):
        """
        Calculate the Jacobian matrix.

        Will ignore the value of *p*.

        The Jacobian will have 2*Pi*G*rho in the diagonal
        if using Newton's method or Levemberg-Marquardt
        and 1/(2*2*Pi*G*rho) if using Steepest Descent.
        """
        method = getattr(self, 'fit_method', None)
        step = utils.si2mgal(2*np.pi*constants.G*self.mesh.props['density'])
        if method is not None and method == 'steepest':
            step = 1/(2*step)
        # Use a sparse matrix for the Jacobian in Compressed Sparse Row (CSR)
        # format. See
        # http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.html
        jac = scipy.sparse.diags([np.abs(step)], [0]).tocsr()
        return jac