-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added NonSequentialTimeSeries Model #76
Merged
+792
−58
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0b156df
Added NonSequentialTimeSeries Model
abodh 23cab74
Merged with the main branch
abodh 8e84b20
Merge 'main' with Chronify changes into ap/issue71
abodh 2c4e33d
Updated based on pull request comments
abodh 6056c2d
minor update on the duplicate lines of code
abodh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
"""Test related to arrow storage module.""" | ||
|
||
from datetime import datetime, timedelta | ||
|
||
import pytest | ||
import numpy as np | ||
|
||
from infrasys.normalization import NormalizationMax | ||
from infrasys.quantities import ActivePower | ||
from infrasys.time_series_models import NonSequentialTimeSeries | ||
|
||
|
||
@pytest.fixture(name="timestamps") | ||
def sample_timestamps(): | ||
"Sample timestamps sequence" | ||
base_datetime = datetime(year=2020, month=1, day=1) | ||
return [base_datetime + timedelta(hours=4 * i) for i in range(4)] | ||
|
||
|
||
@pytest.fixture(name="quantity_data") | ||
def sample_quantity_data(): | ||
"Sample infrasys quantity data" | ||
return ActivePower(range(4), "kilowatts") | ||
|
||
|
||
@pytest.fixture(name="data") | ||
def sample_data(): | ||
"Sample data sequence" | ||
return range(4) | ||
|
||
|
||
@pytest.fixture(name="variable_name") | ||
def sample_variable_name(): | ||
"Sample variable name" | ||
return "active_power" | ||
|
||
|
||
def test_nonsequential_time_series_attributes(data, timestamps, variable_name): | ||
"Test NOnSequentialTimeseries with Infrasys Quantities as data" | ||
length = 4 | ||
ts = NonSequentialTimeSeries.from_array( | ||
data=data, | ||
variable_name=variable_name, | ||
timestamps=timestamps, | ||
) | ||
assert isinstance(ts, NonSequentialTimeSeries) | ||
assert ts.length == length | ||
assert isinstance(ts.data, np.ndarray) | ||
assert isinstance(ts.timestamps, np.ndarray) | ||
|
||
|
||
def test_invalid_sequence_length(data, timestamps, variable_name): | ||
"""Check that time series has at least 2 elements.""" | ||
with pytest.raises(ValueError, match="length must be at least 2"): | ||
NonSequentialTimeSeries.from_array( | ||
data=[data[0]], variable_name=variable_name, timestamps=[timestamps[0]] | ||
) | ||
|
||
|
||
def test_duplicate_timestamps(data, variable_name): | ||
"""Check that time series has unique timestamps""" | ||
timestamps = [ | ||
datetime(2020, 5, 17), | ||
datetime(2020, 5, 17), | ||
datetime(2020, 5, 18), | ||
datetime(2020, 5, 20), | ||
] | ||
with pytest.raises(ValueError, match="Timestamps must be unique"): | ||
NonSequentialTimeSeries.from_array( | ||
data=data, variable_name=variable_name, timestamps=timestamps | ||
) | ||
|
||
|
||
def test_chronological_timestamps(data, variable_name): | ||
"""Check that time series has unique timestamps""" | ||
timestamps = [ | ||
datetime(2020, 6, 17), | ||
datetime(2020, 5, 17), | ||
datetime(2020, 5, 18), | ||
datetime(2020, 5, 20), | ||
] | ||
with pytest.raises(ValueError, match="chronological order"): | ||
NonSequentialTimeSeries.from_array( | ||
data=data, variable_name=variable_name, timestamps=timestamps | ||
) | ||
|
||
|
||
def test_nonsequential_time_series_attributes_with_quantity( | ||
quantity_data, timestamps, variable_name | ||
): | ||
"Test NonSequentialTimeseries with Infrasys Quantities as data" | ||
length = 4 | ||
|
||
ts = NonSequentialTimeSeries.from_array( | ||
data=quantity_data, | ||
variable_name=variable_name, | ||
timestamps=timestamps, | ||
) | ||
assert isinstance(ts, NonSequentialTimeSeries) | ||
assert ts.length == length | ||
assert isinstance(ts.data, ActivePower) | ||
assert isinstance(ts.timestamps, np.ndarray) | ||
|
||
|
||
def test_normalization(data, timestamps, variable_name): | ||
"Test normalization approach on sample data for NonSequentialTimeSeries" | ||
length = 4 | ||
max_val = data[-1] | ||
ts = NonSequentialTimeSeries.from_array( | ||
data=data, | ||
timestamps=timestamps, | ||
variable_name=variable_name, | ||
normalization=NormalizationMax(), | ||
) | ||
assert isinstance(ts, NonSequentialTimeSeries) | ||
assert ts.length == length | ||
for i, val in enumerate(ts.data): | ||
assert val == data[i] / max_val | ||
|
||
|
||
def test_normalization_quantity(quantity_data, timestamps, variable_name): | ||
"Test normalization approach on sample quantity data for NonSequentialTimeSeries" | ||
length = 4 | ||
max_val = quantity_data.magnitude[-1] | ||
ts = NonSequentialTimeSeries.from_array( | ||
data=quantity_data, | ||
timestamps=timestamps, | ||
variable_name=variable_name, | ||
normalization=NormalizationMax(), | ||
) | ||
assert isinstance(ts, NonSequentialTimeSeries) | ||
assert ts.length == length | ||
for i, val in enumerate(ts.data): | ||
assert val == quantity_data.magnitude[i] / max_val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pesap Do you know why we need this?