From 31abd32807d5b55d9908f6415c434dbecdcfae6a Mon Sep 17 00:00:00 2001 From: jacquot Date: Mon, 16 Dec 2024 15:28:59 +0100 Subject: [PATCH] Removing angle_unit parameter of the FisherSky class and using the angle_as_radians function for __init__ of the class --- pycbc/distributions/sky_location.py | 33 ++++------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/pycbc/distributions/sky_location.py b/pycbc/distributions/sky_location.py index dc770e7f350..cfb789cb74c 100644 --- a/pycbc/distributions/sky_location.py +++ b/pycbc/distributions/sky_location.py @@ -26,6 +26,7 @@ from pycbc.distributions import angular from pycbc import VARARGS_DELIM from pycbc.io import FieldArray +from pycbc.types import angle_as_radians logger = logging.getLogger('pycbc.distributions.sky_location') @@ -75,39 +76,15 @@ class FisherSky: Spread of the distribution. For the precise interpretation, see Eq 8 of `Briggs et al 1999 ApJS 122 503`_. This should be smaller than about 20 deg for the approximation to be valid. - angle_unit: str - Unit for the angle parameters: either "deg" or "rad". """ name = 'fisher_sky' _params = ['ra', 'dec'] def __init__(self, **params): - if params['angle_unit'] not in ['deg', 'rad']: - raise ValueError("Only deg or rad is allowed as angle unit") - try: - rematch_ra = re.match('([0-9.e+-]+) *(deg|rad)', params['mean_ra']) - rematch_dec = re.match('([0-9.e+-]+) *(deg|rad)', params['mean_dec']) - rematch_sigma = re.match('([0-9.e+-]+) *(deg|rad)', params['sigma']) - if params['angle_unit'] != rematch_ra.group(2) \ - or params['angle_unit'] != rematch_dec.group(2) \ - or params['angle_unit'] != rematch_sigma.group(2): - raise ValueError( - f"Angle_unit ({params['angle_unit']}) and ra - ({rematch_ra.group(2)}) dec ({rematch_dec.group(2)}) units - must be the same" - ) - mean_ra = float(rematch_ra.group(1)) - mean_dec = float(rematch_dec.group(1)) - sigma = float(rematch_sigma.group(1)) - except: - mean_ra = params['mean_ra'] - mean_dec = params['mean_dec'] - sigma = params['sigma'] - if params['angle_unit'] == 'deg': - mean_ra = numpy.deg2rad(mean_ra) - mean_dec = numpy.deg2rad(mean_dec) - sigma = numpy.deg2rad(sigma) + mean_ra = angle_as_radians(params['mean_ra']) + mean_dec = angle_as_radians(params['mean_dec']) + sigma = angle_as_radians(params['sigma']) if mean_ra < 0 or mean_ra > 2 * numpy.pi: raise ValueError( f'The mean RA must be between 0 and 2π, {mean_ra} rad given' @@ -150,12 +127,10 @@ def from_config(cls, cp, section, variable_args): mean_ra = float(cp.get_opt_tag(section, 'mean_ra', tag)) mean_dec = float(cp.get_opt_tag(section, 'mean_dec', tag)) sigma = float(cp.get_opt_tag(section, 'sigma', tag)) - angle_unit = cp.get_opt_tag(section, 'angle_unit', tag) return cls( mean_ra=mean_ra, mean_dec=mean_dec, sigma=sigma, - angle_unit=angle_unit, ) def rvs(self, size):