我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用scipy.signal.lombscargle()。
def lomb(data: List[DataPoint], low_frequency: float, high_frequency: float): """ Lomb–Scargle periodogram implementation :param data: List[DataPoint] :param high_frequency: float :param low_frequency: float :return lomb-scargle pgram and frequency values """ time_stamps = np.array([dp.start_time.timestamp() for dp in data]) samples = np.array([dp.sample for dp in data]) frequency_range = np.linspace(low_frequency, high_frequency, len(data)) result = signal.lombscargle(time_stamps, samples, frequency_range) return result, frequency_range
def get_frequency_grid(times, samplesperpeak=5, nyquistfactor=5, minfreq=None, maxfreq=None, returnf0dfnf=False): '''This calculates a frequency grid for the period finding functions in this module. Based on the autofrequency function in astropy.stats.lombscargle. http://docs.astropy.org/en/stable/_modules/astropy/stats/lombscargle/core.html#LombScargle.autofrequency ''' baseline = times.max() - times.min() nsamples = times.size df = 1. / baseline / samplesperpeak if minfreq is not None: f0 = minfreq else: f0 = 0.5 * df if maxfreq is not None: Nf = int(npceil((maxfreq - f0) / df)) else: Nf = int(0.5 * samplesperpeak * nyquistfactor * nsamples) if returnf0dfnf: return f0, df, Nf, f0 + df * nparange(Nf) else: return f0 + df * nparange(Nf) ############################################### ## DWORETSKY STRING LENGTH (Dworetsky+ 1983) ## ## (don't use this -- it's very slow) ## ###############################################
def parallel_scipylsp_worker(task): ''' This is a worker to wrap the scipy lombscargle function. ''' try: return lombscargle(*task) except Exception as e: return npnan
def lombscargle_scipy(t, y, frequency, normalization='normalized', center_data=True): """Lomb-Scargle Periodogram This is a wrapper of ``scipy.signal.lombscargle`` for computation of the Lomb-Scargle periodogram. This is a relatively fast version of the naive O[N^2] algorithm, but cannot handle heteroskedastic errors. Parameters ---------- t, y: array_like times, values, and errors of the data points. These should be broadcastable to the same shape. frequency : array_like frequencies (not angular frequencies) at which to calculate periodogram normalization : string (optional, default='normalized') Normalization to use for the periodogram TODO: figure out what options to use center_data : bool (optional, default=True) if True, pre-center the data by subtracting the weighted mean of the input data. Returns ------- power : array_like Lomb-Scargle power associated with each frequency. Units of the result depend on the normalization. References ---------- .. [1] M. Zechmeister and M. Kurster, A&A 496, 577-584 (2009) .. [2] W. Press et al, Numerical Recipies in C (2002) .. [3] Scargle, J.D. 1982, ApJ 263:835-853 """ if not HAS_SCIPY: raise ValueError("scipy must be installed to use lombscargle_scipy") t, y = np.broadcast_arrays(t, y) frequency = np.asarray(frequency) assert t.ndim == 1 assert frequency.ndim == 1 if center_data: y = y - y.mean() # Note: scipy input accepts angular frequencies p = signal.lombscargle(t, y, 2 * np.pi * frequency) if normalization == 'unnormalized': pass elif normalization == 'normalized': p *= 2 / (t.size * np.mean(y ** 2)) else: raise ValueError("normalization='{0}' " "not recognized".format(normalization)) return p
def periodogram(x, rv, f, max_period): ''' Computes a Lomb-Scargle Periodogram of the input RV data. This was adapted from Jake Vanderplas' article "Fast Lomb-Scargle Periodograms in Python." Parameters ---------- x : list The times at which the data points were gathered. rv : list The values of the measurand at the corresponding time, x. f : float The number of samples to take over the interval. max_period : float The maximum of the interval of periods to check. Returns ------- periods : array_like[len(f)] Equally spaced array of possible period values. powers : array_like[len(f)] The calculated Power values over the range of periods, these form the normalized Lomb-Scargle Periodogram. delta_x : float The smallest separation between two values in x. ''' from scipy.signal import lombscargle # Sort the time data chronologically. x = np.sort(np.array(x)) rv = np.array(rv) # Start delta_x very large delta_x = np.inf # Iteratively lower delta_x for i in range(0, len(x)-2): if x[i+1]-x[i] < delta_x and x[i+1]-x[i] != 0: delta_x = x[i+1]-x[i] # Compute the periodogram periods = np.linspace(delta_x, max_period, num = f) ang_freqs = 2 * pi / periods powers = lombscargle(x, rv - rv.mean(), ang_freqs) powers *= 2 / (len(x) * rv.std() ** 2) return periods, powers, delta_x
def dataWindow(x, f, max_period): ''' Computes a data window of the dataset. That is, a periodogram with the all of the RV values and variances set to 1. Parameters ---------- x : list The times at which the data points were gathered. f : float The number of samples to take over the interval. max_period : float The maximum of the interval of periods to check. Returns ------- periods : array_like[len(f)] Equally spaced array of possible period values. powers : array_like[len(f)] The calculated Power values over the range of periods, these form the normalized Lomb-Scargle Periodogram. ''' from scipy.signal import lombscargle # Sort the time data chronologically. x = np.sort(np.array(x)) delta_x = np.inf # Iteratively lower the measure delta_x for i in range(0, len(x)-2): if x[i+1]-x[i] < delta_x and x[i+1]-x[i] != 0: delta_x = x[i+1]-x[i] periods = np.linspace(delta_x, max_period, num = f) ang_freqs = 2 * pi / periods powers = lombscargle(x, np.ones(len(x)), ang_freqs) powers *= 2 / len(x) return periods, powers