本文整理汇总了Python中astropy.units.Quantity.max方法的典型用法代码示例。如果您正苦于以下问题:Python Quantity.max方法的具体用法?Python Quantity.max怎么用?Python Quantity.max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.units.Quantity
的用法示例。
在下文中一共展示了Quantity.max方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EnergyDependentTablePSF
# 需要导入模块: from astropy.units import Quantity [as 别名]
# 或者: from astropy.units.Quantity import max [as 别名]
#.........这里部分代码省略.........
if rad is None:
rad = self.rad
energy = Energy(energy).to('TeV')
rad = Angle(rad).to('deg')
energy_bin = self.energy.to('TeV')
rad_bin = self.rad.to('deg')
points = (energy_bin, rad_bin)
interpolator = RegularGridInterpolator(points, self.psf_value, **interp_kwargs)
energy_grid, rad_grid = np.meshgrid(energy.value, rad.value, indexing='ij')
shape = energy_grid.shape
pix_coords = np.column_stack([energy_grid.flat, rad_grid.flat])
data_interp = interpolator(pix_coords)
return Quantity(data_interp.reshape(shape), self.psf_value.unit)
def table_psf_at_energy(self, energy, interp_kwargs=None, **kwargs):
"""Evaluate the `EnergyOffsetArray` at one given energy.
Parameters
----------
energy : `~astropy.units.Quantity`
Energy
interp_kwargs : dict
Option for interpolation for `~scipy.interpolate.RegularGridInterpolator`
Returns
-------
table : `~astropy.table.Table`
Table with two columns: offset, value
"""
psf_value = self.evaluate(energy, None, interp_kwargs)[0, :]
table_psf = TablePSF(self.rad, psf_value, **kwargs)
return table_psf
def kernels(self, cube, rad_max, **kwargs):
"""
Make a set of 2D kernel images, representing the PSF at different energies.
The kernel image is evaluated on the spatial and energy grid defined by
the reference sky cube.
Parameters
----------
cube : `~gammapy.cube.SkyCube`
Reference sky cube.
rad_max `~astropy.coordinates.Angle`
PSF kernel size
kwargs : dict
Keyword arguments passed to `EnergyDependentTablePSF.table_psf_in_energy_band()`.
Returns
-------
kernels : list of `~numpy.ndarray`
List of 2D convolution kernels.
"""
energies = cube.energies(mode='edges')
kernels = []
for emin, emax in zip(energies[:-1], energies[1:]):
energy_band = Quantity([emin, emax])
try:
psf = self.table_psf_in_energy_band(energy_band, **kwargs)
kernel = psf.kernel(cube.sky_image_ref, rad_max=rad_max)
except ValueError:
kernel = np.nan * np.ones((1, 1)) # Dummy, means "no kernel available"
kernels.append(kernel)
return kernels
示例2: EnergyDependentTablePSF
# 需要导入模块: from astropy.units import Quantity [as 别名]
# 或者: from astropy.units.Quantity import max [as 别名]
#.........这里部分代码省略.........
table : `~astropy.table.Table`
Table with two columns: offset, value
"""
psf_value = self.evaluate(energy, None, interp_kwargs)[0, :]
table_psf = TablePSF(self.offset, psf_value, **kwargs)
return table_psf
def table_psf_in_energy_band(self, energy_band, spectral_index=2, spectrum=None, **kwargs):
"""Average PSF in a given energy band.
Expected counts in sub energy bands given the given exposure
and spectrum are used as weights.
Parameters
----------
energy_band : `~astropy.units.Quantity`
Energy band
spectral_index : float
Power law spectral index (used if spectrum=None).
spectrum : callable
Spectrum (callable with energy as parameter).
Returns
-------
psf : `TablePSF`
Table PSF
"""
if spectrum is None:
def spectrum(energy):
return (energy / energy_band[0]) ** (-spectral_index)
# TODO: warn if `energy_band` is outside available data.
energy_idx_min, energy_idx_max = self._energy_index(energy_band)
# TODO: extract this into a utility function `npred_weighted_mean()`
# Compute weights for energy bins
weights = np.zeros_like(self.energy.value, dtype=np.float64)
for idx in range(energy_idx_min, energy_idx_max - 1):
energy_min = self.energy[idx]
energy_max = self.energy[idx + 1]
exposure = self.exposure[idx]
flux = spectrum(energy_min)
weights[idx] = (exposure * flux * (energy_max - energy_min)).value
# Normalize weights to sum to 1
weights = weights / weights.sum()
# Compute weighted PSF value array
total_psf_value = np.zeros_like(self._get_1d_psf_values(0), dtype=np.float64)
for idx in range(energy_idx_min, energy_idx_max - 1):
psf_value = self._get_1d_psf_values(idx)
total_psf_value += weights[idx] * psf_value
# TODO: add version that returns `total_psf_value` without
# making a `TablePSF`.
return TablePSF(self.offset, total_psf_value, **kwargs)
def containment_radius(self, energies, fraction, interp_kwargs=None):
"""Containment radius.
Parameters
----------
energies : `~astropy.units.Quantity`