Skip to content
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

feat(posfilter): Adds config model for Position Filtering #134

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/gnatss/configs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)

from .io import OutputPath
from .posfilter import PositionFilter
from .solver import Solver

CONFIG_FILE = "config.yaml"
Expand Down Expand Up @@ -118,12 +119,16 @@ class Configuration(BaseConfiguration):
site_id: str = Field(..., description="The site identification for processing")
# TODO: Separate settings out to core plugin
solver: Optional[Solver] = Field(None, description="Solver configurations")
output: OutputPath
posfilter: Optional[PositionFilter] = Field(
None, description="Position filter configurations"
)
output: Optional[OutputPath] = Field(None, description="Output path configurations")

def __init__(self, **data):
super().__init__(**data)

# Set the transponders pxp id based on the site id
transponders = self.solver.transponders
for idx in range(len(transponders)):
transponders[idx].pxp_id = "-".join([self.site_id, str(idx + 1)])
if self.solver is not None:
# Set the transponders pxp id based on the site id
transponders = self.solver.transponders
for idx in range(len(transponders)):
transponders[idx].pxp_id = "-".join([self.site_id, str(idx + 1)])
lsetiawan marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 25 additions & 0 deletions src/gnatss/configs/posfilter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""posfilter.py

The posfilter module containing base models for
position filtering configuration
"""

from pydantic import BaseModel, Field

from .io import InputData


class PositionFilterInputs(BaseModel):
roll_pitch_heading: InputData = Field(
..., description="Roll Pitch Heading (RPH) data path specification."
)


class PositionFilter(BaseModel):
"""
Position filter base model for position filtering routine
"""

input_files: PositionFilterInputs = Field(
..., description="Input files for position filtering routine."
)
44 changes: 44 additions & 0 deletions tests/configs/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from pathlib import Path

import pytest

from gnatss.configs.main import Configuration


def test_env_configuration_main(blank_env: None) -> None:
"""Testing a simple configuration class
with environment variables.

See root/conftest.py for fixture definition.
"""
with pytest.warns(
UserWarning,
match=(
"Configuration file `config.yaml` not found. "
"Will attempt to retrieve configuration from environment variables."
),
):
config = Configuration()

assert config.site_id == "test_site"


def test_env_main_posfilter(blank_csv_test_file: Path, blank_env: None) -> None:
"""Testing setting RPS input file path
with environment variables

See root/conftest.py for fixture definition.
"""
test_path = str(blank_csv_test_file)

with pytest.warns(
UserWarning,
match=(
"Configuration file `config.yaml` not found. "
"Will attempt to retrieve configuration from environment variables."
),
):
config = Configuration()

assert config.posfilter is not None
assert config.posfilter.input_files.roll_pitch_heading.path == test_path
24 changes: 24 additions & 0 deletions tests/configs/test_posfilter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from pathlib import Path

import pytest

from gnatss.configs.io import InputData
from gnatss.configs.posfilter import PositionFilter, PositionFilterInputs


def test_position_filter_input(blank_csv_test_file: Path) -> None:
"""Testing the PositionFilterInputs class.

See root/conftest.py for fixture definition.
"""
test_path = str(blank_csv_test_file)

# Test initialization of PositionFilter
inputs = PositionFilterInputs(roll_pitch_heading=InputData(path=test_path))
pos_filter = PositionFilter(input_files=inputs)
assert pos_filter.input_files.roll_pitch_heading.path == test_path

# Test invalid initialization of PositionFilter
with pytest.raises(Exception) as e:
pos_filter = PositionFilter()
assert "1 validation error for PositionFilter\ninput_files\n" in str(e)
25 changes: 25 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
from pathlib import Path

import pytest


@pytest.fixture
def blank_csv_test_file() -> Path:
# Create test file
test_file = Path(__file__).parent / "test_data.csv"
test_file.touch()
# This will yield and return until the end of the test
yield test_file
# Delete test file
test_file.unlink()


@pytest.fixture
def blank_env(blank_csv_test_file: Path) -> None:
# Set environment variables
os.environ.setdefault("GNATSS_SITE_ID", "test_site")
os.environ.setdefault(
"GNATSS_POSFILTER__INPUT_FILES__ROLL_PITCH_HEADING__PATH",
str(blank_csv_test_file),
)