Skip to content

Commit

Permalink
Removing angle_unit parameter of the FisherSky class and using the
Browse files Browse the repository at this point in the history
angle_as_radians function for __init__ of the class
  • Loading branch information
jacquot committed Dec 16, 2024
1 parent cc60179 commit 31abd32
Showing 1 changed file with 4 additions and 29 deletions.
33 changes: 4 additions & 29 deletions pycbc/distributions/sky_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 31abd32

Please sign in to comment.