我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用scipy.ndimage.gaussian_filter1d()。
def mk_data(n_samples=200, random_state=0, separability=1, noise_corr=2, dim=100): rng = np.random.RandomState(random_state) y = rng.random_integers(0, 1, size=n_samples) noise = rng.normal(size=(n_samples, dim)) if not noise_corr is None and noise_corr > 0: noise = ndimage.gaussian_filter1d(noise, noise_corr, axis=0) noise = noise / noise.std(axis=0) # We need to decrease univariate separability as dimension increases centers = 4. / dim * np.ones((2, dim)) centers[0] *= -1 X = separability * centers[y] + noise return X, y ############################################################################### # Code to run the cross-validations
def mk_data(n_samples=200, random_state=0, separability=1, noise_corr=2, dim=100): rng = np.random.RandomState(random_state) y = rng.random_integers(0, 1, size=n_samples) noise = rng.normal(size=(n_samples, dim)) if not noise_corr is None and noise_corr > 0: noise = ndimage.gaussian_filter1d(noise, noise_corr, axis=0) noise = noise / noise.std(axis=0) # We need to decrease univariate separability as dimension increases centers = 4. / dim * np.ones((2, dim)) centers[0] *= -1 X = separability * centers[y] + noise return X, y ############################################################################### # The perfect predictor
def gaussian_smooth(self, fwhm, **kwargs): profile_sigma = fwhm / (2 * (2*np.log(2))**0.5) # The requested FWHM is in Angstroms, but the dispersion between each # pixel is likely less than an Angstrom, so we must calculate the true # smoothing value true_profile_sigma = profile_sigma / np.median(np.diff(self.dispersion)) smoothed_flux = ndimage.gaussian_filter1d(self.flux, true_profile_sigma, **kwargs) # TODO modify ivar based on smoothing? return self.__class__(self.dispersion, smoothed_flux, self.ivar.copy(), metadata=self.metadata.copy())
def _erfimage_imshow(ax, ch_idx, tmin, tmax, vmin, vmax, ylim=None, data=None, epochs=None, sigma=None, order=None, scalings=None, vline=None, x_label=None, y_label=None, colorbar=False, cmap='RdBu_r'): """Aux function to plot erfimage on sensor topography""" from scipy import ndimage import matplotlib.pyplot as plt this_data = data[:, ch_idx, :].copy() if callable(order): order = order(epochs.times, this_data) if order is not None: this_data = this_data[order] if sigma > 0.: this_data = ndimage.gaussian_filter1d(this_data, sigma=sigma, axis=0) ax.imshow(this_data, extent=[tmin, tmax, 0, len(data)], aspect='auto', origin='lower', vmin=vmin, vmax=vmax, picker=True, cmap=cmap, interpolation='nearest') ax = plt.gca() if x_label is not None: ax.set_xlabel(x_label) if y_label is not None: ax.set_ylabel(y_label) if colorbar: plt.colorbar()
def _erfimage_imshow_unified(bn, ch_idx, tmin, tmax, vmin, vmax, ylim=None, data=None, epochs=None, sigma=None, order=None, scalings=None, vline=None, x_label=None, y_label=None, colorbar=False, cmap='RdBu_r'): """Aux function to plot erfimage topography using a single axis""" from scipy import ndimage _compute_scalings(bn, (tmin, tmax), (0, len(epochs.events))) ax = bn.ax data_lines = bn.data_lines extent = (bn.x_t + bn.x_s * tmin, bn.x_t + bn.x_s * tmax, bn.y_t, bn.y_t + bn.y_s * len(epochs.events)) this_data = data[:, ch_idx, :].copy() if callable(order): order = order(epochs.times, this_data) if order is not None: this_data = this_data[order] if sigma > 0.: this_data = ndimage.gaussian_filter1d(this_data, sigma=sigma, axis=0) data_lines.append(ax.imshow(this_data, extent=extent, aspect='auto', origin='lower', vmin=vmin, vmax=vmax, picker=True, cmap=cmap, interpolation='nearest'))
def __call__(self, data): if data.domain != self.domain: data = data.from_table(self.domain, data) xs, xsind, mon, X = _transform_to_sorted_features(data) X, nans = _nan_extend_edges_and_interpolate(xs[xsind], X) X = gaussian_filter1d(X, sigma=self.sd, mode="nearest") if nans is not None: X[nans] = np.nan return _transform_back_to_features(xsind, mon, X)