Skip to content

Commit

Permalink
remove some unneaded numpy vectorizes and speed up det_tc (gwastro#3356)
Browse files Browse the repository at this point in the history
* We should be consistent about units

* Do not use numpy vectorize

* remove more numpy vect

* no commit

* cc
  • Loading branch information
ahnitz authored and lenona committed Sep 14, 2020
1 parent a3c603f commit 24ec28d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
29 changes: 10 additions & 19 deletions pycbc/conversions.py
Expand Up @@ -662,7 +662,8 @@ def distance_from_chirp_distance_mchirp(chirp_distance, mchirp, ref_mass=1.4):
return chirp_distance * (2.**(-1./5) * ref_mass / mchirp)**(-5./6)


def _det_tc(detector_name, ra, dec, tc, ref_frame='geocentric'):
_detector_cache = {}
def det_tc(detector_name, ra, dec, tc, ref_frame='geocentric'):
"""Returns the coalescence time of a signal in the given detector.
Parameters
Expand All @@ -686,26 +687,24 @@ def _det_tc(detector_name, ra, dec, tc, ref_frame='geocentric'):
"""
if ref_frame == detector_name:
return tc
detector = Detector(detector_name)
if detector_name not in _detector_cache:
_detector_cache[detector_name] = Detector(detector_name)
detector = _detector_cache[detector_name]
if ref_frame == 'geocentric':
return tc + detector.time_delay_from_earth_center(ra, dec, tc)
else:
other = Detector(ref_frame)
return tc + detector.time_delay_from_detector(other, ra, dec, tc)

det_tc = numpy.vectorize(_det_tc)

def _optimal_orientation_from_detector(detector_name, tc):
def optimal_orientation_from_detector(detector_name, tc):
""" Low-level function to be called from _optimal_dec_from_detector
and _optimal_ra_from_detector"""

d = Detector(detector_name)
ra, dec = d.optimal_orientation(tc)

return ra, dec


def _optimal_dec_from_detector(detector_name, tc):
def optimal_dec_from_detector(detector_name, tc):
"""For a given detector and GPS time, return the optimal orientation
(directly overhead of the detector) in declination.
Expand All @@ -722,13 +721,9 @@ def _optimal_dec_from_detector(detector_name, tc):
float :
The declination of the signal, in radians.
"""
return _optimal_orientation_from_detector(detector_name, tc)[1]


optimal_dec_from_detector = numpy.vectorize(_optimal_dec_from_detector)
return optimal_orientation_from_detector(detector_name, tc)[1]


def _optimal_ra_from_detector(detector_name, tc):
def optimal_ra_from_detector(detector_name, tc):
"""For a given detector and GPS time, return the optimal orientation
(directly overhead of the detector) in right ascension.
Expand All @@ -745,11 +740,7 @@ def _optimal_ra_from_detector(detector_name, tc):
float :
The declination of the signal, in radians.
"""
return _optimal_orientation_from_detector(detector_name, tc)[0]


optimal_ra_from_detector = numpy.vectorize(_optimal_ra_from_detector)

return optimal_orientation_from_detector(detector_name, tc)[0]

#
# =============================================================================
Expand Down
1 change: 1 addition & 0 deletions pycbc/distributions/angular.py
Expand Up @@ -89,6 +89,7 @@ def __init__(self, cyclic_domain=False, **params):
"got [{a},{b})".format(x=self._domain.min,
y=self._domain.max, a=bnds.min,
b=bnds.max))

# update
params[p] = bnds
super(UniformAngle, self).__init__(**params)
Expand Down

0 comments on commit 24ec28d

Please sign in to comment.