<jupyter_start><jupyter_text>Mains frequency measurement for one day<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter
data = np.genfromtxt('frequency_data.txt')
frequency_data = data[:, 0]
hour = data[:, 1]
%pylab inline
pylab.rcParams['figure.figsize'] = (15, 10)
fig, ax = plt.subplots()


plt.title("Frequency characteristic 16/06/2017 in Rostock",fontsize=22)
plt.xlabel("Time of day",fontsize=22)
plt.ylabel("f / Hz",fontsize=22)

x_ticks_labels = ["00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00",
                  "07:00", "08:00", "09:00", "10:00", "11:00", "12:00",
                  "13:00", "14:00", "15:00", "16:00", "17:00", "18:00",
                  "19:00", "20:00", "21:00", "22:00", "23:00", "00:00"]

ax.set_xticklabels(x_ticks_labels)
start, end = ax.get_xlim()
ax.xaxis.set_ticks([0, 240, 479, 718, 958, 1197, 1436, 1675, 1914, 2153, 2393,
                    2632, 2871, 3110, 3349, 3588, 3828, 4067, 4306, 4545,
                    4784, 5023, 5263, 5502, 5741])

ax.yaxis.set_major_formatter(FormatStrFormatter('%.3f'))
fig.autofmt_xdate()
plt.grid()
plt.plot(frequency_data)

plt.show()<jupyter_output>Populating the interactive namespace from numpy and matplotlib<jupyter_text>Averaging mains frequency per hour<jupyter_code>hour01 = np.mean(frequency_data[:240])
hour02 = np.mean(frequency_data[240:479])
hour03 = np.mean(frequency_data[479:718])
hour04 = np.mean(frequency_data[718:958])
hour05 = np.mean(frequency_data[958:1197])
hour06 = np.mean(frequency_data[1197:1436])
hour07 = np.mean(frequency_data[1436:1675])
hour08 = np.mean(frequency_data[1675:1914])
hour09 = np.mean(frequency_data[1914:2153])
hour10 = np.mean(frequency_data[2153:2393])
hour11 = np.mean(frequency_data[2393:2632])
hour12 = np.mean(frequency_data[2632:2871])
hour13 = np.mean(frequency_data[2871:3110])
hour14 = np.mean(frequency_data[3110:3349])
hour15 = np.mean(frequency_data[3349:3588])
hour16 = np.mean(frequency_data[3588:3828])
hour17 = np.mean(frequency_data[3828:4067])
hour18 = np.mean(frequency_data[4067:4306])
hour19 = np.mean(frequency_data[4306:4545])
hour20 = np.mean(frequency_data[4545:4784])
hour21 = np.mean(frequency_data[4784:5023])
hour22 = np.mean(frequency_data[5023:5263])
hour23 = np.mean(frequency_data[5263:5502])
hour00 = np.mean(frequency_data[5502:5741])
hour_array = np.array([hour01, hour02, hour03, hour04, hour05, hour06, hour07, hour08, hour09, hour10,
                      hour11, hour12, hour13, hour14, hour15, hour16, hour17, hour18, hour19, hour20,
                      hour21, hour22, hour23, hour00])
fig, ax2 = plt.subplots()


plt.title("Frequency characteristic 16/06/2017 in Rostock",fontsize=22)
plt.xlabel("Time of day",fontsize=22)
plt.ylabel("f / Hz",fontsize=22)

x_ticks_labels = ["01:00", "02:00", "03:00", "04:00", "05:00", "06:00",
                  "07:00", "08:00", "09:00", "10:00", "11:00", "12:00",
                  "13:00", "14:00", "15:00", "16:00", "17:00", "18:00",
                  "19:00", "20:00", "21:00", "22:00", "23:00", "00:00"]

ax2.set_xticklabels(x_ticks_labels)
start, end = ax.get_xlim()
ax2.xaxis.set_ticks([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
                     21, 22, 23, 24])

x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]

ax2.yaxis.set_major_formatter(FormatStrFormatter('%.3f'))
fig.autofmt_xdate()
plt.grid()
plt.ylim([49.97,50.04])
plt.plot(hour_array, linewidth=2, label='temporal average of mains frequency')
ax2.axhline(y=50.00, color="k",linewidth=1)
axhspan(49.99, 50.01 , facecolor='g', alpha=0.5, label='dead band')
axhspan(50.01, 50.04 , facecolor='r', alpha=0.5, label='adjustment')
axhspan(49.99, 49.97 , facecolor='r', alpha=0.5)
ax2.legend(loc='lower right')
plt.show()

hour_array
bins = np.array([ 49.934     ,  49.93697959,  49.93995918,  49.94293878,
        49.94591837,  49.94889796,  49.95187755,  49.95485714,
        49.95783673,  49.96081633,  49.96379592,  49.96677551,
        49.9697551 ,  49.97273469,  49.97571429,  49.97869388,
        49.98167347,  49.98465306,  49.98763265,  49.99061224,
        49.99359184,  49.99657143,  49.99955102,  50.00253061,
        50.0055102 ,  50.0084898 ,  50.01146939,  50.01444898,
        50.01742857,  50.02040816,  50.02338776,  50.02636735,
        50.02934694,  50.03232653,  50.03530612,  50.03828571,
        50.04126531,  50.0442449 ,  50.04722449,  50.05020408,
        50.05318367,  50.05616327,  50.05914286,  50.06212245,
        50.06510204,  50.06808163,  50.07106122,  50.07404082,
        50.07702041,  50.08      ])
my = np.mean(frequency_data)
sig = np.std(frequency_data)
plt.hist(frequency_data, bins=bins)
plt.title(" Histogram $\mu$ =  %.3f, $\sigma$ = %.3f" % (my, sig),fontsize=22)
plt.xlabel("f / Hz",fontsize=22)
plt.ylabel("Absolute Frequency",fontsize=22)
plt.grid()
plt.show()
weights = np.ones_like(frequency_data)/float(len(frequency_data))
counts, bin_edges = np.histogram(frequency_data, bins=bins, weights=weights)
cdf = np.cumsum(counts)
plt.title("Cumulative Density Function" ,fontsize=22)
plt.xlabel("f / Hz",fontsize=22)
plt.ylabel("CDF",fontsize=22)
plt.grid()
plt.plot(bin_edges[1:], cdf, linewidth=1.6)

plt.show()
from scipy import stats
stats.anderson(frequency_data)
stats.kstest(frequency_data, 'norm')
x = np.random.normal(0,1,1000)

test_stat = stats.kstest(x, 'norm')
stats.anderson(x)
poisson = np.random.poisson(5, 10000)
stats.kstest(poisson, 'norm')<jupyter_output><empty_output><jupyter_text>"If the K-S statistic is small or the p-value is high, then we cannot reject the hypothesis that the distributions of the two samples are the same."  Normalizing Data<jupyter_code>frequency_data_normalized = (frequency_data - np.mean(frequency_data)) / np.std(frequency_data)
from scipy.stats import norm
counts, bin_edges = np.histogram(frequency_data_normalized, weights=weights, bins = 139)
cdf = np.cumsum(counts)
plt.title("Visual comparison between CDF of data and standard normal" ,fontsize=22)
plt.xlabel("f / Hz",fontsize=22)
plt.ylabel("CDF",fontsize=22)
plt.grid()
plt.plot(bin_edges[1:], cdf, linewidth=3, color='b', label='Data CDF')
standard = norm.cdf(bin_edges)
plt.plot(bin_edges, standard, linewidth=3, color='r', label='Standard Normal CDF')
plt.ylim([0,1])
plt.legend(loc='lower right')

plt.show()<jupyter_output><empty_output><jupyter_text>Kolmogorov-Smirnov-Test<jupyter_code>stats.kstest(frequency_data_normalized, 'norm')
stats.kstest(frequency_data_normalized, 'norm')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16959684752955442, 'fraction_numerical': 0.1905122764474083, 'mean_word_length': 4.814096916299559, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '127259', 'license': 'MIT', 'n_tokens_mistral': 3472, 'n_tokens_neox': 2681, 'n_words': 501, 'path': 'jupyter_notebooks/mains_frequency_measurement_one_day.ipynb', 'repo_name': 'franzpl/StableGrid', 'size': '6598'}