<jupyter_start><jupyter_text>Power spectrum<jupyter_code>#Power spectrum of entire time series
Tres=ds_usv.TEMP_SBE37_MEAN.resample(time='60MIN').mean(skipna=True)      # Hourly time step.      
Tresft=np.fft.fft(Tres)
n=len(Tresft)
freq=np.fft.fftfreq(n,1)                                                  # Frequency in units of 1/(1h).
k=int(n/2)
p=np.zeros(k)
p[0]=(abs(Tresft[0])**2)/(n**2)
i=1
for i in range(1,k):
    p[i]=(abs(Tresft[i])**2+abs(Tresft[n-i])**2)/(n**2) #spectrum by periodogram # why divide by n??? 
                                                        # It it a normalization...
        
        
plt.plot(freq[0:k],p[0:k]/(freq[1]), alpha=0.6) # Why divide by freq[1]? This is just another normalization.
plt.yscale('log')
 
p2=np.zeros(k)
for i in range(1,k):
    p2[i]=(abs(Tresft[i])**2)/(n) #spectrum by periodogram
plt.plot(freq[0:k],p2[0:k]/(freq[1]), alpha=0.6)

plt.vlines([1/24.,1/12.],0,10**5,color='grey',linestyles='dotted')  
plt.text(0.043, 14, '24H          12H')
plt.xscale('log')
# Define the window to be used as a filter.
a = np.zeros_like(freq)
cutoff_frequency = 1/24.
a[np.abs(freq) >= cutoff_frequency] = 1
plt.plot(np.abs(Tresft))
plt.ylim(0, 20)
plt.show()

# Filter the frequencies on the daily scale to remove slower variability.
Tresft_filt=a*Tresft
plt.plot(np.abs(Tresft_filt))
plt.ylim(0, 20)
plt.show()

# Invert the filtered FT and plot it.
Tresft_inv=np.fft.ifft(Tresft_filt)

time = pd.date_range('2020-01-17', freq='H', periods=46 * 24)
ds_temp = xr.Dataset({'Temp_filt': ('time', np.real(Tresft_inv)), 'time': time})
ds_temp.Temp_filt.groupby('time.hour').mean().plot()
plt.ylabel('Temperature anomaly diurnal cycle [°C]')
plt.show()

ds_temp.Temp_filt.plot()
plt.show()
# Now get the low-pass signal.
# Filter the frequencies on the daily scale to remove slower variability.
Tresft_filt=(1-a)*Tresft
plt.plot(np.abs(Tresft_filt))
plt.show()

# Invert the filtered FT and plot it.
Tresft_inv=np.fft.ifft(Tresft_filt)
time = pd.date_range('2020-01-17', freq='H', periods=46 * 24)
ds_temp_lp = xr.Dataset({'Temp_filt': ('time', np.real(Tresft_inv)), 'time': time})
ds_temp_lp.Temp_filt.plot()
plt.show()
# Check if the sum of the two filtered signals matches the full field.

sum_filtered = ds_temp.Temp_filt + ds_temp_lp.Temp_filt
sum_filtered.plot()

Tres.plot()
plt.show()

difference = sum_filtered-Tres
difference.plot()
plt.show()
ds_usv.TEMP_SBE37_MEAN.plot()
ds_usv.TEMP_CTD_RBR_MEAN.plot()
ds_logger.sea_water_temperature_00_mean.plot()
ds_logger.sea_water_temperature_01_mean.plot()
ds_logger.sea_water_temperature_02_mean.plot()
ds_logger.sea_water_temperature_03_mean.plot()
dif = ds_logger.sea_water_temperature_00_mean-ds_logger.sea_water_temperature_03_mean
#dif = ds_usv.TEMP_SBE37_MEAN-ds_usv.TEMP_CTD_RBR_MEAN
dif.plot()
plt.hist(ds_usv.wspd,bins=np.arange(0,15,.1))
plt.scatter(ds_usv.wspd,dif,c=ds_usv.tlmt.dt.hour)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16421987026288837, 'fraction_numerical': 0.03687265278251963, 'mean_word_length': 4.602294455066922, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '181196', 'license': 'Apache-2.0', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1223, 'n_words': 208, 'path': 'atomic/Basic_plotting.ipynb', 'repo_name': 'agonmer/Saildrone', 'size': '2929'}