summaryrefslogtreecommitdiff
path: root/invars.py
blob: db9b6749d6adb376e2726c7fcba0e4f941558956 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import numpy             as np
import scipy.interpolate as interp
import scipy.integrate   as integrate

def calc_dist_proper(coord, gXX):
    """
    Calculate proper distance along given spatial axis.

    :param array_like coord: 1D array of spatial coordinates.
    :param array_like gXX: Values of the XX component of the spatial metric at
                           provided coordinates.
    :return: array of proper distances from coord[0].
    """
    r_proper = np.empty_like(coord)
    sqgXX    = interp.interp1d(coord, np.sqrt(gXX))
    r_proper[0] = 0.0
    for i in range(coord.shape[0] - 1):
        r_proper[i + 1] = r_proper[i] + integrate.quad(sqgXX, coord[i], coord[i + 1])[0]
    return r_proper