本文整理汇总了Python中astropy.coordinates.Angle.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Angle.insert方法的具体用法?Python Angle.insert怎么用?Python Angle.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.coordinates.Angle
的用法示例。
在下文中一共展示了Angle.insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from astropy.coordinates import Angle [as 别名]
# 或者: from astropy.coordinates.Angle import insert [as 别名]
class TablePSF:
r"""Radially-symmetric table PSF.
Parameters
----------
rad : `~astropy.units.Quantity` with angle units
Offset wrt source position
psf_value : `~astropy.units.Quantity` with sr^-1 units
PSF value array
interp_kwargs : dict
Keyword arguments passed to `ScaledRegularGridInterpolator`
"""
def __init__(self, rad, psf_value, interp_kwargs=None):
self.rad = Angle(rad).to("rad")
self.psf_value = u.Quantity(psf_value).to("sr^-1")
self._interp_kwargs = interp_kwargs or {}
@lazyproperty
def _interpolate(self):
points = (self.rad,)
return ScaledRegularGridInterpolator(
points=points, values=self.psf_value, **self._interp_kwargs
)
@lazyproperty
def _interpolate_containment(self):
if self.rad[0] > 0:
rad = self.rad.insert(0, 0)
else:
rad = self.rad
rad_drad = 2 * np.pi * rad * self.evaluate(rad)
values = cumtrapz(rad_drad.to_value("rad-1"), rad.to_value("rad"), initial=0)
return ScaledRegularGridInterpolator(points=(rad,), values=values, fill_value=1)
@classmethod
def from_shape(cls, shape, width, rad):
"""Make TablePSF objects with commonly used shapes.
This function is mostly useful for examples and testing.
Parameters
----------
shape : {'disk', 'gauss'}
PSF shape.
width : `~astropy.units.Quantity` with angle units
PSF width angle (radius for disk, sigma for Gauss).
rad : `~astropy.units.Quantity` with angle units
Offset angle
Returns
-------
psf : `TablePSF`
Table PSF
Examples
--------
>>> import numpy as np
>>> from astropy.coordinates import Angle
>>> from gammapy.irf import TablePSF
>>> TablePSF.from_shape(shape='gauss', width='0.2 deg',
... rad=Angle(np.linspace(0, 0.7, 100), 'deg'))
"""
width = Angle(width)
rad = Angle(rad)
if shape == "disk":
amplitude = 1 / (np.pi * width.radian ** 2)
psf_value = np.where(rad < width, amplitude, 0)
elif shape == "gauss":
gauss2d_pdf = Gauss2DPDF(sigma=width.radian)
psf_value = gauss2d_pdf(rad.radian)
else:
raise ValueError("Invalid shape: {}".format(shape))
psf_value = u.Quantity(psf_value, "sr^-1")
return cls(rad, psf_value)
def info(self):
"""Print basic info."""
ss = array_stats_str(self.rad.deg, "offset")
ss += "integral = {}\n".format(self.integral())
for containment in [68, 80, 95]:
radius = self.containment_radius(0.01 * containment)
ss += "containment radius {} deg for {}%\n".format(radius.deg, containment)
return ss
def evaluate(self, rad):
r"""Evaluate PSF.
The following PSF quantities are available:
* 'dp_domega': PDF per 2-dim solid angle :math:`\Omega` in sr^-1
#.........这里部分代码省略.........