Minor tweak to Figure 10.4

14 views
Skip to first unread message

Tom Johnson

unread,
Jul 23, 2018, 9:57:27 AM7/23/18
to astroML-general
The code for Figure 10.4 http://www.astroml.org/book_figures/chapter10/fig_FFT_sampling.html has this line

t_obs = 100 * np.random.random(40)
I suspect that this should read 
t_obs = 100 * np.random.random(Nobs)
instead so that changing the number of observations will actually update the results.

Tom Johnson

unread,
Jul 23, 2018, 10:09:29 AM7/23/18
to astroML-general
When running under Python 3.6 and NumPy 1.14.5 you need to update the line

Nfreq = Nbins / 2

to be 

Nfreq = int(Nbins / 2)

otherwise python will complain

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-d70eb03ef0a7> in <module>()
     47 f = df * np.arange(Nfreq)
     48 
---> 49 PSD_window = abs(np.fft.fft(window)[:Nfreq]) ** 2
     50 PSD_y = abs(np.fft.fft(y)[:Nfreq]) ** 2
     51 PSD_obs = abs(np.fft.fft(y * window)[:Nfreq]) ** 2

TypeError: slice indices must be integers or None or have an __index__ method
Reply all
Reply to author
Forward
0 new messages