-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added styles sub and tests * working through more testing in adjustments * minor cleanup
- Loading branch information
1 parent
bfd222e
commit 2f5bc68
Showing
7 changed files
with
158 additions
and
101 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from enum import Enum | ||
|
||
|
||
class EventStyle(Enum): | ||
""" | ||
Styles for plotting events in a timeseries, enums defined by | ||
color, line style and line width | ||
""" | ||
START = 'g', '--', 1 | ||
STOP = 'r', '--', 1 | ||
SURFACE = 'lightsteelblue', '--', 1 | ||
ERROR = 'orangered', 'dotted', 1 | ||
UNKNOWN = 'k', '--', 1 | ||
|
||
@classmethod | ||
def from_name(cls, name): | ||
result = cls.UNKNOWN | ||
for e in cls: | ||
if e.name == name.upper(): | ||
result = e | ||
break | ||
return result | ||
|
||
@property | ||
def color(self): | ||
return self.value[0] | ||
|
||
@property | ||
def linestyle(self): | ||
return self.value[1] | ||
|
||
@property | ||
def linewidth(self): | ||
return self.value[2] | ||
|
||
@property | ||
def label(self): | ||
return self.name.title() | ||
|
||
class SensorStyle(Enum): | ||
""" | ||
Enum to handle plotting titles and preferred colors | ||
""" | ||
# Df column name, plot title, color | ||
RAW_FORCE = 'Sensor1', 'Raw Force', 'black' | ||
RAW_AMBIENT_NIR = 'Sensor2', 'Ambient', 'darkorange' | ||
RAW_ACTIVE_NIR = 'Sensor3', 'Raw Active', 'crimson' | ||
ACTIVE_NIR = 'nir', 'NIR', 'crimson' | ||
ACC_X_AXIS = 'X-Axis', 'X-Axis', 'darkslategrey' | ||
ACC_Y_AXIS = 'Y-Axis', 'Y-Axis', 'darkgreen' | ||
ACC_Z_AXIS = 'Z-Axis', 'Z-Axis', 'darkorange' | ||
ACCELERATION = 'acceleration', 'Acc. Magn.', 'darkgreen' | ||
FUSED = 'fused', 'Fused', 'magenta' | ||
CONSTRAINED_BAROMETER = 'barometer', 'Constr. Baro.', 'navy' | ||
RAW_BARO = 'filtereddepth', 'Raw Baro.', 'Brown' | ||
UNKNOWN = 'UNKNOWN', 'UNKNOWN', None | ||
|
||
@property | ||
def column(self): | ||
return self.value[0] | ||
|
||
@property | ||
def label(self): | ||
return self.value[1].title() | ||
|
||
@property | ||
def color(self): | ||
return self.value[2] | ||
|
||
@classmethod | ||
def from_column(cls, column): | ||
result = cls.UNKNOWN | ||
for e in cls: | ||
if e.column.upper() == column.upper(): | ||
result = e | ||
break | ||
return result |
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,43 @@ | ||
""" | ||
Place to store common styling of plots as well as streamlining common tasks | ||
like labeling and coloring of events and sensors. | ||
""" | ||
|
||
from study_lyte.styles import EventStyle, SensorStyle | ||
import pytest | ||
|
||
class TestEventStyle: | ||
@pytest.mark.parametrize("name, expected", [ | ||
('error', EventStyle.ERROR), | ||
('blarg', EventStyle.UNKNOWN) | ||
]) | ||
def test_from_name(self, name, expected): | ||
style = EventStyle.from_name(name) | ||
assert style == expected | ||
|
||
@pytest.mark.parametrize("property, expected",[ | ||
('color', 'g'), | ||
('linestyle', '--'), | ||
('linewidth', 1), | ||
('label', 'Start'), | ||
]) | ||
def test_property(self, property, expected): | ||
assert getattr(EventStyle.START, property) == expected | ||
|
||
|
||
class TestSensorStyle: | ||
@pytest.mark.parametrize("name, expected", [ | ||
('Sensor1', SensorStyle.RAW_FORCE), | ||
]) | ||
def test_from_column(self, name, expected): | ||
style = SensorStyle.from_column(name) | ||
assert style == expected | ||
|
||
@pytest.mark.parametrize("property, expected",[ | ||
('column', 'fused'), | ||
('label', 'Fused'), | ||
('color', 'magenta'), | ||
]) | ||
def test_property(self, property, expected): | ||
assert getattr(SensorStyle.FUSED, property) == expected |