本文整理匯總了Python中astropy.convolution.convolve方法的典型用法代碼示例。如果您正苦於以下問題:Python convolution.convolve方法的具體用法?Python convolution.convolve怎麽用?Python convolution.convolve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類astropy.convolution
的用法示例。
在下文中一共展示了convolution.convolve方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup_method
# 需要導入模塊: from astropy import convolution [as 別名]
# 或者: from astropy.convolution import convolve [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: smooth
# 需要導入模塊: from astropy import convolution [as 別名]
# 或者: from astropy.convolution import convolve [as 別名]
def smooth(y, box_pts, window='flat'):
# https://scipy-cookbook.readthedocs.io/items/SignalSmooth.html
if window is 'flat':
box = np.ones(box_pts)
elif window is 'blackman':
box = np.blackman(box_pts)
else:
raise ValueError('unknown window')
box /= np.sum(box)
y_smooth = astroconv.convolve(y, box, boundary='extend') # also: None, fill, wrap, extend
return y_smooth
示例3: smooth_magseries_gaussfilt
# 需要導入模塊: from astropy import convolution [as 別名]
# 或者: from astropy.convolution import convolve [as 別名]
def smooth_magseries_gaussfilt(mags, windowsize, windowfwhm=7):
'''This smooths the magseries with a Gaussian kernel.
Parameters
----------
mags : np.array
The input mags/flux time-series to smooth.
windowsize : int
This is a odd integer containing the smoothing window size.
windowfwhm : int
This is an odd integer containing the FWHM of the applied Gaussian
window function.
Returns
-------
np.array
The smoothed mag/flux time-series array.
'''
convkernel = Gaussian1DKernel(windowfwhm, x_size=windowsize)
smoothed = convolve(mags, convkernel, boundary='extend')
return smoothed
示例4: _smooth_acf
# 需要導入模塊: from astropy import convolution [as 別名]
# 或者: from astropy.convolution import convolve [as 別名]
def _smooth_acf(acf, windowfwhm=7, windowsize=21):
'''This returns a smoothed version of the ACF.
Convolves the ACF with a Gaussian of given `windowsize` and `windowfwhm`.
Parameters
----------
acf : np.array
The auto-correlation function array to smooth.
windowfwhm : int
The smoothing window Gaussian kernel's FWHM .
windowsize : int
The number of input points to apply the smoothing over.
Returns
-------
np.array
Smoothed version of the input ACF array.
'''
convkernel = Gaussian1DKernel(windowfwhm, x_size=windowsize)
smoothed = convolve(acf, convkernel, boundary='extend')
return smoothed
示例5: smooth
# 需要導入模塊: from astropy import convolution [as 別名]
# 或者: from astropy.convolution import convolve [as 別名]
def smooth(y, box_pts):
try:
from astropy.convolution import convolve
except ImportError:
raise ImportError("The astropy module is required to use this function")
box = np.ones(box_pts) / box_pts
# also: None, fill, wrap, extend
y_smooth = convolve(y, box, boundary="extend")
return y_smooth
示例6: image_std
# 需要導入模塊: from astropy import convolution [as 別名]
# 或者: from astropy.convolution import convolve [as 別名]
def image_std(image, radius):
"""
Calculates the standard deviation of an image, using a moving window of
specified radius. Uses astropy's convolution library'
Arguments:
-----------
image: np.array
2D array containing the pixel intensities of a single-band image
radius: int
radius defining the moving window used to calculate the standard deviation.
For example, radius = 1 will produce a 3x3 moving window.
Returns:
-----------
win_std: np.array
2D array containing the standard deviation of the image
"""
# convert to float
image = image.astype(float)
# first pad the image
image_padded = np.pad(image, radius, 'reflect')
# window size
win_rows, win_cols = radius*2 + 1, radius*2 + 1
# calculate std with uniform filters
win_mean = convolve(image_padded, np.ones((win_rows,win_cols)), boundary='extend',
normalize_kernel=True, nan_treatment='interpolate', preserve_nan=True)
win_sqr_mean = convolve(image_padded**2, np.ones((win_rows,win_cols)), boundary='extend',
normalize_kernel=True, nan_treatment='interpolate', preserve_nan=True)
win_var = win_sqr_mean - win_mean**2
win_std = np.sqrt(win_var)
# remove padding
win_std = win_std[radius:-radius, radius:-radius]
return win_std