mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-05-20 17:41:13 +00:00
Add great circle distance
This commit is contained in:
parent
45f6584493
commit
fb2ac576ea
2 changed files with 22 additions and 1 deletions
|
@ -16,7 +16,8 @@ from csiborgtools import clustering, field, match, read, summary
|
||||||
|
|
||||||
from .utils import (center_of_mass, delta2ncells, number_counts, # noqa
|
from .utils import (center_of_mass, delta2ncells, number_counts, # noqa
|
||||||
periodic_distance, periodic_distance_two_points, # noqa
|
periodic_distance, periodic_distance_two_points, # noqa
|
||||||
binned_statistic, cosine_similarity, fprint) # noqa
|
binned_statistic, cosine_similarity, fprint, # noqa
|
||||||
|
great_circle_distance) # noqa
|
||||||
|
|
||||||
|
|
||||||
# Arguments to csiborgtools.read.Paths.
|
# Arguments to csiborgtools.read.Paths.
|
||||||
|
|
|
@ -148,6 +148,26 @@ def radec_to_cartesian(X):
|
||||||
]).T
|
]).T
|
||||||
|
|
||||||
|
|
||||||
|
@jit(nopython=True, fastmath=True, boundscheck=False)
|
||||||
|
def great_circle_distance(x1, x2):
|
||||||
|
"""
|
||||||
|
Great circle distance between two points on a sphere, defined by RA and
|
||||||
|
dec, both in degrees.
|
||||||
|
"""
|
||||||
|
ra1, dec1 = x1
|
||||||
|
ra2, dec2 = x2
|
||||||
|
|
||||||
|
ra1 *= numpy.pi / 180
|
||||||
|
dec1 *= numpy.pi / 180
|
||||||
|
ra2 *= numpy.pi / 180
|
||||||
|
dec2 *= numpy.pi / 180
|
||||||
|
|
||||||
|
return 180 / numpy.pi * numpy.arccos(
|
||||||
|
numpy.sin(dec1) * numpy.sin(dec2)
|
||||||
|
+ numpy.cos(dec1) * numpy.cos(dec2) * numpy.cos(ra1 - ra2)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def cosine_similarity(x, y):
|
def cosine_similarity(x, y):
|
||||||
r"""
|
r"""
|
||||||
Calculate the cosine similarity between two Cartesian vectors. Defined
|
Calculate the cosine similarity between two Cartesian vectors. Defined
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue