<jupyter_start><jupyter_text>1. Actividad solar: frecuencia manchas solaresThis notebook is part of the work done under the project Astronomía Accesible (http://astroaccesible.iaa.es/)This notebook uses data from the SILSO data/image $-$ Royal Observatory of Belgium, Brussels (http://sidc.be/silso/home), to study the solar activity's frequency. It is known to be approximately 11 years. We will calculate this explicitly. All plots will be sonified.<jupyter_code>from astronify.series import SoniSeries
import numpy
import matplotlib.pyplot as plt
from scipy.fftpack import fft, fftfreq
from scipy.signal import find_peaks

from astropy.table import Table

import os
from urllib.request import urlopen

from matplotlib import rcParams

rcParams['axes.linewidth']=1.5
rcParams['xtick.major.width']=1.5
rcParams['xtick.minor.width']=1.5
rcParams['ytick.major.width']=1.5
rcParams['ytick.minor.width']=1.5
# Only to be run once:
os.chdir('../')
folder = os.getcwd()
# Data source (credit): SILSO data/image, Royal Observatory of Belgium, Brussels
# dowloaded from http://sidc.oma.be/silso/DATA/SN_y_tot_V2.0.txt
file = urlopen('http://sidc.oma.be/silso/DATA/SN_y_tot_V2.0.txt')
data = numpy.genfromtxt(file, skip_footer = 1) # the last row on this file is a prediction, so we will ignore it 

time = data[:,0]     # time column [years]
sunspots = data[:,1] # Yearly mean total sunspot number
rcParams['font.size']=20

fig = plt.figure(figsize = (15,5))
ax = fig.subplots()

ax.plot(time, sunspots, color = 'k', linewidth = 2)

ax.set_xlabel('Año')
ax.set_ylabel('No. manchas solares')

fig.savefig(folder + '/plots/machassolares_año.png', dpi=500, bbox_inches='tight')

plt.show()
# Standard procedure to sonify sunspots' time series:

data_table = Table({"time": time,"flux": sunspots})
data_soni = SoniSeries(data_table)

#  Default note spacing (median time between notes in seconds) is 0.01,
#  slow it down to hear all the data points
data_soni.note_spacing = 0.1

data_soni.sonify()
data_soni.write(folder + '/sonifications/sunspots1.wav')
# Compute periodicity of the data:

# Fourier transform the sunspots data:
fourier_coeffs = numpy.abs(fft(sunspots))
# Dominant term (excluding the zeroth -- only a phase (no physical significance))
index_max_amplitude = numpy.argmax(fourier_coeffs[1:])+1 # +1 to get correct indexing because of [1:]

# Time frequency it corresponds to:
N = sunspots.size
dt = time[1] - time[0]  # time step [years]
fourier_freqs = fftfreq(N, d = dt)    # frequency [1/year] for each amplitude in fourier_coeffs

T = 1/fourier_freqs[index_max_amplitude]  # [year]
print('Period = {:.1f} years'.format(T))
# Only interested in the first half of the computed array (symmetric)
fourier_freqs  = fourier_freqs[0:N//2]
fourier_coeffs = fourier_coeffs[0:N//2]
rcParams['font.size']=20

fig = plt.figure(figsize = (10,5))
ax = fig.subplots()

# Frequency dominance within the signal recorded
ax.plot(fourier_freqs,fourier_coeffs, linewidth = 2.5, color='k')

# Check 11.1 years is the most dominant period:
ax.axvline(1/T, color = 'dimgrey', linestyle = 'dashed', linewidth = 3, label = '{:.1f} años'.format(T))

ax.legend()

ax.set_xlabel('Frecuencia [1/año]')
ax.set_ylabel(r'$\propto$Amplitud')

ax.set_xlim(-0.01,0.3) # Not really interesting stuff afterwards

fig.savefig(folder + '/plots/frequencia_manchas_solares.png', dpi=500, bbox_inches='tight')

plt.show()
# Sonify sunspots' frequency series:

data_table = Table({"time": fourier_freqs,"flux": fourier_coeffs})
data_soni = SoniSeries(data_table)

#  Default note spacing (median time between notes in seconds) is 0.01,
#  slow it down to hear all the data points
data_soni.note_spacing = 0.1

data_soni.sonify()
data_soni.write(folder + '/sonifications/sunspots_fourier1.wav')<jupyter_output>Pyo message: Offline Server rendering file /media/irene/6000-8897/AstroAccesible/sonifications/sunspots_fourier1.wav dur=16.400000
Pyo message: Offline Server rendering finished.
{'fraction_non_alphanumeric': 0.1236409608091024, 'fraction_numerical': 0.023514538558786345, 'mean_word_length': 5.319488817891374, 'pattern_counts': {'":': 4, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '524111', 'license': 'MIT', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1400, 'n_words': 380, 'path': 'Sun/1.Sunspots_year_frequency.ipynb', 'repo_name': 'iabrilcabezas/AstroAccesible', 'size': '3955'}