Skip to content

Commit

Permalink
I changed it back to how it was before the code that was
Browse files Browse the repository at this point in the history
causing errors was commented out.
  • Loading branch information
abruns123 committed Nov 8, 2024
1 parent 8b5535f commit d4b1bdf
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions test_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
test_preparation.py
unit test for the functions fft_powerspectrum, fft_mag, inv_fft, calc_freq
"""
from datetime import datetime, timedelta
import numpy as np
import pandas as pd
from preparation import window,unwindow

#from datetime import datetime, timedelta
#from preparation import fft_powerspectrum, fft_mag, get_timeseries

from preparation import fft_powerspectrum, fft_mag, inv_fft, calc_freq
import pytest

from preparation import fft_powerspectrum, fft_mag, get_timeseries
from preparation import window,unwindow
#from thid import plot_rets

"""
t = np.linspace(0, 2, 2000, endpoint=False)
f1, f2 = 50, 120
Expand All @@ -21,7 +22,7 @@
print(inv_fft(data))
print(data)
plot_rets(freq,fft(data))
"""

t = np.linspace(0, 2, 2000, endpoint=False)
f1, f2 = 50, 120
Expand All @@ -35,55 +36,56 @@ def test_fft(data):
magnitudes = fft(data)
from preparation import fft_powerspectrum, fft_mag, inv_fft, calc_freq
import pytest
@pytest.fixture
def data():
trange = pd.date_range(datetime.now(), datetime.now() + timedelta(days=9), freq='d')
return pd.Series([1, 2, 3, 2, 1, 2, 3, 2, 1, 2], index=trange)
def test_fft_powerspectrum(data):
test the powerspectrums length and type of export
"""test the powerspectrums length and type of export"""
powrspec = fft_powerspectrum(data)
assert len(powrspec) == len(data)/2
assert isinstance(powrspec, np.ndarray)
def test_fft_mag(data):
test the fft_mag length and type of expor
"""test the fft_mag length and type of export"""
magnitudes = fft_mag(data)
assert len(magnitudes) == len(data)
assert isinstance(magnitudes, np.ndarray)
def test_inv_fft(data):
tests inv_fft length export aswell as testing to see if
the fit matches the data
"""tests inv_fft length export aswell as testing to see if
the fit matches the data"""
invdata = inv_fft(fft_mag(data))
assert len(invdata) == len(data)
assert np.allclose(invdata, data.values, atol=1e-4)
def test_get_timeseries_date_column_length():
'''
This function tests that the length of co2_series (output of get_timeseries)
has the same length of the original file.
'''
co2_series = get_timeseries('/mauna-loa-data/flask_monthly.json')

#Check that the length of the Series matches the original data length
original_data = pd.read_json('/mauna-loa-data/flask_monthly.json')
original_length = len(original_data) # Count of rows in the JSON data
assert len(co2_series) == original_length, (
"Length of the datetime index should match the length of the original Month column."
)

matr = fft_powerspectrum(data)

print(matr)

#freq = calc_freq(data)
# plot_rets(freq,fft(data))

#print(np.isclose(0, 0.0001, atol=0.001))
trange = pd.date_range(datetime.now(), datetime.now()+timedelta(days=9),freq='d')
data1 = pd.Series([1,2,3,4,5,6,7,8,9,10],index=trange)
print(len(data1))
print(data1.index[0].timestamp())
print(data1.iloc[2] * 1)

def test_calc_freq(data):

calcs the length of the export of calc_freq

freq = calc_freq(data, 'seconds')
assert len(freq) == len(data)
"""


def test_window():
Expand All @@ -98,7 +100,6 @@ def test_window():
end=75
func=[np.sin(i) for i in x]
data=pd.Series(func,index=x)

#the test data is windowed and the
#endpoints are checked.
windows=window(data, start,end)
Expand All @@ -111,7 +112,6 @@ def test_window():
ydata=windows["Welch Window"].values
assert ydata[0]==0
assert ydata[len(ydata)-1]==0

def test_unwindow():
"""
test_unwindow ensures that the unwindow function
Expand Down Expand Up @@ -145,4 +145,8 @@ def test_unwindow():
assert round(i,3)==round(new.values[count],3)
count+=1

def test_calc_freq(data):
"""calcs the length of the export of calc_freq"""
freq = calc_freq(data, 'seconds')
assert len(freq) == len(data)

0 comments on commit d4b1bdf

Please sign in to comment.