diff --git a/pycbc/conversions.py b/pycbc/conversions.py index 832ce926667..83799976fa2 100644 --- a/pycbc/conversions.py +++ b/pycbc/conversions.py @@ -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 @@ -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. @@ -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. @@ -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] # # ============================================================================= diff --git a/pycbc/distributions/angular.py b/pycbc/distributions/angular.py index b321368dec4..ae85be60143 100644 --- a/pycbc/distributions/angular.py +++ b/pycbc/distributions/angular.py @@ -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)