本文整理汇总了Python中astropy.stats.sigma_clip方法的典型用法代码示例。如果您正苦于以下问题:Python stats.sigma_clip方法的具体用法?Python stats.sigma_clip怎么用?Python stats.sigma_clip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.stats
的用法示例。
在下文中一共展示了stats.sigma_clip方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_lightcurve_y_limits
# 需要导入模块: from astropy import stats [as 别名]
# 或者: from astropy.stats import sigma_clip [as 别名]
def get_lightcurve_y_limits(lc_source):
"""Compute sensible defaults for the Y axis limits of the lightcurve plot.
Parameters
----------
lc_source : bokeh.plotting.ColumnDataSource
The lightcurve being shown.
Returns
-------
ymin, ymax : float, float
Flux min and max limits.
"""
with warnings.catch_warnings(): # Ignore warnings due to NaNs
warnings.simplefilter("ignore", AstropyUserWarning)
flux = sigma_clip(lc_source.data['flux'], sigma=5, masked=False)
low, high = np.nanpercentile(flux, (1, 99))
margin = 0.10 * (high - low)
return low - margin, high + margin
示例2: _cbrange_sigma_clip
# 需要导入模块: from astropy import stats [as 别名]
# 或者: from astropy.stats import sigma_clip [as 别名]
def _cbrange_sigma_clip(image, sigma):
"""Sigma clip colorbar range.
Parameters:
image (masked array):
Image.
sigma (float):
Sigma to clip.
Returns:
list: Colorbar range.
"""
try:
imclip = sigma_clip(image.data[~image.mask], sigma=sigma)
except TypeError:
imclip = sigma_clip(image.data[~image.mask], sig=sigma)
try:
cbrange = [imclip.min(), imclip.max()]
except ValueError:
cbrange = [image.min(), image.max()]
return cbrange
示例3: test_with_fitters_and_sigma_clip
# 需要导入模块: from astropy import stats [as 别名]
# 或者: from astropy.stats import sigma_clip [as 别名]
def test_with_fitters_and_sigma_clip(self):
import scipy.stats as stats
np.random.seed(0)
c = stats.bernoulli.rvs(0.25, size=self.x.shape)
self.y += (np.random.normal(0., 0.2, self.x.shape) +
c*np.random.normal(3.0, 5.0, self.x.shape))
g_init = models.Gaussian1D(amplitude=1., mean=0, stddev=1.)
# test with Levenberg-Marquardt Least Squares fitter
fit = FittingWithOutlierRemoval(LevMarLSQFitter(), sigma_clip,
niter=3, sigma=3.0)
fitted_model, _ = fit(g_init, self.x, self.y)
assert_allclose(fitted_model.parameters, self.model_params, rtol=1e-1)
# test with Sequential Least Squares Programming fitter
fit = FittingWithOutlierRemoval(SLSQPLSQFitter(), sigma_clip,
niter=3, sigma=3.0)
fitted_model, _ = fit(g_init, self.x, self.y)
assert_allclose(fitted_model.parameters, self.model_params, rtol=1e-1)
# test with Simplex LSQ fitter
fit = FittingWithOutlierRemoval(SimplexLSQFitter(), sigma_clip,
niter=3, sigma=3.0)
fitted_model, _ = fit(g_init, self.x, self.y)
assert_allclose(fitted_model.parameters, self.model_params, atol=1e-1)
示例4: test_1d_set_fitting_with_outlier_removal
# 需要导入模块: from astropy import stats [as 别名]
# 或者: from astropy.stats import sigma_clip [as 别名]
def test_1d_set_fitting_with_outlier_removal():
"""Test model set fitting with outlier removal (issue #6819)"""
poly_set = models.Polynomial1D(2, n_models=2)
fitter = FittingWithOutlierRemoval(LinearLSQFitter(),
sigma_clip, sigma=2.5, niter=3,
cenfunc=np.ma.mean, stdfunc=np.ma.std)
x = np.arange(10)
y = np.array([2.5*x - 4, 2*x*x + x + 10])
y[1, 5] = -1000 # outlier
poly_set, filt_y = fitter(poly_set, x, y)
assert_allclose(poly_set.c0, [-4., 10.], atol=1e-14)
assert_allclose(poly_set.c1, [2.5, 1.], atol=1e-14)
assert_allclose(poly_set.c2, [0., 2.], atol=1e-14)
示例5: test_2d_set_axis_2_fitting_with_outlier_removal
# 需要导入模块: from astropy import stats [as 别名]
# 或者: from astropy.stats import sigma_clip [as 别名]
def test_2d_set_axis_2_fitting_with_outlier_removal():
"""Test fitting 2D model set (axis 2) with outlier removal (issue #6819)"""
poly_set = models.Polynomial2D(1, n_models=2, model_set_axis=2)
fitter = FittingWithOutlierRemoval(LinearLSQFitter(),
sigma_clip, sigma=2.5, niter=3,
cenfunc=np.ma.mean, stdfunc=np.ma.std)
y, x = np.mgrid[0:5, 0:5]
z = np.rollaxis(np.array([x+y, 1-0.1*x+0.2*y]), 0, 3)
z[3, 3:5, 0] = 100. # outliers
poly_set, filt_z = fitter(poly_set, x, y, z)
assert_allclose(poly_set.c0_0, [[[0., 1.]]], atol=1e-14)
assert_allclose(poly_set.c1_0, [[[1., -0.1]]], atol=1e-14)
assert_allclose(poly_set.c0_1, [[[1., 0.2]]], atol=1e-14)
示例6: bkg_subtraction
# 需要导入模块: from astropy import stats [as 别名]
# 或者: from astropy.stats import sigma_clip [as 别名]
def bkg_subtraction(self, scope="tpf", sigma=2.5):
"""Subtracts background flux from target pixel file.
Parameters
----------
scope : string, "tpf" or "postcard"
If `tpf`, will use data from the target pixel file only to estimate and remove the background.
If `postcard`, will use data from the entire postcard region to estimate and remove the background.
sigma : float
The standard deviation cut used to determine which pixels are representative of the background in each cadence.
"""
time = self.time
if self.source_info.tc == True:
flux = self.bkg_tpf
else:
flux = self.tpf
tpf_flux_bkg = []
sigma_clip = SigmaClip(sigma=sigma)
bkg = MMMBackground(sigma_clip=sigma_clip)
for i in range(len(time)):
bkg_value = bkg.calc_background(flux[i])
tpf_flux_bkg.append(bkg_value)
if self.source_info.tc == True:
self.tpf_flux_bkg = np.array(tpf_flux_bkg)
else:
return np.array(tpf_flux_bkg)
示例7: test_1d_without_weights_with_sigma_clip
# 需要导入模块: from astropy import stats [as 别名]
# 或者: from astropy.stats import sigma_clip [as 别名]
def test_1d_without_weights_with_sigma_clip(self):
model = models.Polynomial1D(0)
fitter = FittingWithOutlierRemoval(LinearLSQFitter(), sigma_clip,
niter=3, sigma=3.)
fit, mask = fitter(model, self.x1d, self.z1d)
assert((~mask).sum() == self.z1d.size - 2)
assert(mask[0] and mask[1])
assert_allclose(fit.parameters[0], 0.0, atol=10**(-2)) # with removed outliers mean is 0.0
示例8: test_1d_set_with_common_weights_with_sigma_clip
# 需要导入模块: from astropy import stats [as 别名]
# 或者: from astropy.stats import sigma_clip [as 别名]
def test_1d_set_with_common_weights_with_sigma_clip(self):
"""added for #6819 (1D model set with weights in common)"""
model = models.Polynomial1D(0, n_models=2)
fitter = FittingWithOutlierRemoval(LinearLSQFitter(), sigma_clip,
niter=3, sigma=3.)
z1d = np.array([self.z1d, self.z1d])
fit, filtered = fitter(model, self.x1d, z1d, weights=self.weights1d)
assert_allclose(fit.parameters, [0.8, 0.8], atol=1e-14)
示例9: test_2d_without_weights_with_sigma_clip
# 需要导入模块: from astropy import stats [as 别名]
# 或者: from astropy.stats import sigma_clip [as 别名]
def test_2d_without_weights_with_sigma_clip(self):
model = models.Polynomial2D(0)
fitter = FittingWithOutlierRemoval(LinearLSQFitter(), sigma_clip,
niter=3, sigma=3.)
fit, mask = fitter(model, self.x, self.y, self.z)
assert((~mask).sum() == self.z.size - 2)
assert(mask[0, 0] and mask[0, 1])
assert_allclose(fit.parameters[0], 0.0, atol=10**(-2))
示例10: test_2d_with_weights_with_sigma_clip
# 需要导入模块: from astropy import stats [as 别名]
# 或者: from astropy.stats import sigma_clip [as 别名]
def test_2d_with_weights_with_sigma_clip(self):
"""smoke test for #7020 - fails without fitting.py patch because weights does not propagate"""
model = models.Polynomial2D(0)
fitter = FittingWithOutlierRemoval(LevMarLSQFitter(), sigma_clip,
niter=3, sigma=3.)
with pytest.warns(AstropyUserWarning,
match=r'Model is linear in parameters'):
fit, filtered = fitter(model, self.x, self.y, self.z,
weights=self.weights)
assert(fit.parameters[0] > 10**(-2)) # weights pulled it > 0
assert(fit.parameters[0] < 1.0) # outliers didn't pull it out of [-1:1] because they had been removed
示例11: _set_cbrange
# 需要导入模块: from astropy import stats [as 别名]
# 或者: from astropy.stats import sigma_clip [as 别名]
def _set_cbrange(image, cb_kws):
"""Set colorbar range.
Parameters:
image (masked array):
Image.
cb_kws (dict):
Colorbar kwargs.
Returns:
dict: Colorbar kwargs.
"""
if cb_kws.get('sigma_clip'):
cbr = _cbrange_sigma_clip(image, cb_kws['sigma_clip'])
elif cb_kws.get('percentile_clip'):
try:
cbr = _cbrange_percentile_clip(image, *cb_kws['percentile_clip'])
except IndexError:
cbr = [0.1, 1]
else:
cbr = [image.min(), image.max()]
if cb_kws.get('cbrange') is not None:
cbr = _cbrange_user_defined(cbr, cb_kws['cbrange'])
if cb_kws.get('symmetric', False):
cb_max = np.max(np.abs(cbr))
cbr = [-cb_max, cb_max]
cbr, cb_kws['ticks'] = _set_cbticks(cbr, cb_kws)
if cb_kws.get('log_cb', False):
try:
im_min = np.min(image[image > 0.])
except ValueError:
im_min = 0.1
if im_min is np.ma.masked:
im_min = 0.1
cbr[0] = np.max((cbr[0], im_min))
cb_kws['cbrange'] = cbr
return cb_kws