summaryrefslogtreecommitdiff
path: root/invars.py
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2018-03-22 10:29:53 +0100
committerAnton Khirnov <anton@khirnov.net>2018-03-22 10:29:53 +0100
commitf55cb13c91ea247c595eb9e654a6997713787a0e (patch)
treeaeaf36f40d75dd9707876432e705d0ebf3ab086b /invars.py
parentacacea1a22a709d4551b8c7dfe069c23ef8e9335 (diff)
Add a function for calculating proper distance.
Diffstat (limited to 'invars.py')
-rw-r--r--invars.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/invars.py b/invars.py
new file mode 100644
index 0000000..7937108
--- /dev/null
+++ b/invars.py
@@ -0,0 +1,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 xrange(coord.shape[0] - 1):
+ r_proper[i + 1] = r_proper[i] + integrate.quad(sqgXX, coord[i], coord[i + 1])[0]
+ return r_proper