本文整理匯總了Python中astropy.convolution.Gaussian2DKernel方法的典型用法代碼示例。如果您正苦於以下問題:Python convolution.Gaussian2DKernel方法的具體用法?Python convolution.Gaussian2DKernel怎麽用?Python convolution.Gaussian2DKernel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類astropy.convolution
的用法示例。
在下文中一共展示了convolution.Gaussian2DKernel方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup_method
# 需要導入模塊: from astropy import convolution [as 別名]
# 或者: from astropy.convolution import Gaussian2DKernel [as 別名]
def setup_method(self, method):
np.random.seed(1000) # so we always get the same images.
self.min_, self.stretch_, self.Q = 0, 5, 20 # asinh
width, height = 85, 75
self.width = width
self.height = height
shape = (width, height)
image_r = np.zeros(shape)
image_g = np.zeros(shape)
image_b = np.zeros(shape)
# pixel locations, values and colors
points = [[15, 15], [50, 45], [30, 30], [45, 15]]
values = [1000, 5500, 600, 20000]
g_r = [1.0, -1.0, 1.0, 1.0]
r_i = [2.0, -0.5, 2.5, 1.0]
# Put pixels in the images.
for p, v, gr, ri in zip(points, values, g_r, r_i):
image_r[p[0], p[1]] = v*pow(10, 0.4*ri)
image_g[p[0], p[1]] = v*pow(10, 0.4*gr)
image_b[p[0], p[1]] = v
# convolve the image with a reasonable PSF, and add Gaussian background noise
def convolve_with_noise(image, psf):
convolvedImage = convolve(image, psf, boundary='extend', normalize_kernel=True)
randomImage = np.random.normal(0, 2, image.shape)
return randomImage + convolvedImage
psf = Gaussian2DKernel(2.5)
self.image_r = convolve_with_noise(image_r, psf)
self.image_g = convolve_with_noise(image_g, psf)
self.image_b = convolve_with_noise(image_b, psf)
示例2: test_filter_2D
# 需要導入模塊: from astropy import convolution [as 別名]
# 或者: from astropy.convolution import Gaussian2DKernel [as 別名]
def test_filter_2D(radius):
data = np.random.rand(4, 3, 6)
ds = xr.DataArray(data, dims=["x", "something", "y"])
ds_filt = filter_2D(ds, radius, dim=["x", "y"])
for xi, xx in enumerate(ds.something.data):
sample = ds_filt.sel({"something": xx})
kernel = Gaussian2DKernel(radius)
expected = convolve_fft(data[:, xi, :], kernel, boundary="wrap")
# result[np.isnan(raw_data)] = np.nan
np.testing.assert_allclose(sample, expected)
# TODO test case with nans (astropy interpolates nicely.
# I want to make the nan substitution optiona)
示例3: filter_2D
# 需要導入模塊: from astropy import convolution [as 別名]
# 或者: from astropy.convolution import Gaussian2DKernel [as 別名]
def filter_2D(data, std, dim, dtype=None):
if astropy is None:
raise RuntimeError(
"Module `astropy` not found. Please install optional dependency with `conda install -c conda-forge astropy"
)
if dtype is None:
dtype = detect_dtype(data)
kernel = Gaussian2DKernel(std)
def smooth_raw(data):
raw_data = getattr(data, "values", data)
result = convolve_fft(raw_data, kernel, boundary="wrap")
result[np.isnan(raw_data)] = np.nan
return result
def smoother(data):
dims = dim
# this is different from the 1d case
return xr.apply_ufunc(
smooth_raw,
data,
vectorize=True,
dask="parallelized",
input_core_dims=[dims],
output_core_dims=[dims],
output_dtypes=[dtype],
)
return smoother(data)
# TODO spatial filter
示例4: frame_filter_lowpass
# 需要導入模塊: from astropy import convolution [as 別名]
# 或者: from astropy.convolution import Gaussian2DKernel [as 別名]
def frame_filter_lowpass(array, mode='gauss', median_size=5, fwhm_size=5,
gauss_mode='conv'):
"""
Low-pass filtering of input frame depending on parameter ``mode``.
Parameters
----------
array : numpy ndarray
Input array, 2d frame.
mode : {'median', 'gauss'}, str optional
Type of low-pass filtering.
median_size : int, optional
Size of the median box for filtering the low-pass median filter.
fwhm_size : float, optional
Size of the Gaussian kernel for the low-pass Gaussian filter.
gauss_mode : {'conv', 'convfft'}, str optional
'conv' uses the multidimensional gaussian filter from scipy.ndimage and
'convfft' uses the fft convolution with a 2d Gaussian kernel.
Returns
-------
filtered : numpy ndarray
Low-pass filtered image.
"""
if array.ndim != 2:
raise TypeError('Input array is not a frame or 2d array.')
if not isinstance(median_size, int):
raise ValueError('`Median_size` must be integer')
if mode == 'median':
# creating the low_pass filtered (median) image
filtered = median_filter(array, median_size, mode='nearest')
elif mode == 'gauss':
# 2d Gaussian filter
sigma = fwhm_size * gaussian_fwhm_to_sigma
if gauss_mode == 'conv':
filtered = gaussian_filter(array, sigma=sigma, order=0,
mode='nearest')
elif gauss_mode == 'convfft':
# FFT Convolution with a 2d gaussian kernel created with Astropy.
filtered = convolve_fft(array, Gaussian2DKernel(stddev=sigma))
else:
raise TypeError('2d Gaussian filter mode not recognized')
else:
raise TypeError('Low-pass filter mode not recognized')
return filtered