Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing the FisherSky class to have angle unit suffix rad deg #4992

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 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 @@ -67,31 +68,27 @@ class FisherSky:

Parameters
----------
mean_ra: float
RA of the center of the distribution.
mean_dec: float
Declination of the center of the distribution.
sigma: float
mean_ra: float or str
RA of the center of the distribution. Use the rad or deg suffix to
specify units, otherwise radians are assumed.
mean_dec: float or str
Declination of the center of the distribution. Use the rad or deg
suffix to specify units, otherwise radians are assumed.
sigma: float or str
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".
about 20 deg for the approximation to be valid. Use the rad or deg
suffix to specify units, otherwise radians are assumed.

"""

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")
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'])
Thomas-JACQUOT marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -131,15 +128,13 @@ def from_config(cls, cp, section, variable_args):
"Not all parameters used by this distribution "
"included in tag portion of section name"
)
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)
mean_ra = cp.get_opt_tag(section, 'mean_ra', tag)
mean_dec = cp.get_opt_tag(section, 'mean_dec', tag)
sigma = cp.get_opt_tag(section, 'sigma', tag)
return cls(
mean_ra=mean_ra,
mean_dec=mean_dec,
sigma=sigma,
angle_unit=angle_unit,
)

def rvs(self, size):
Expand Down
Loading