-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from lanl/sammy_param_last_placeholder
add placeholder for the last card
- Loading branch information
Showing
2 changed files
with
147 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python | ||
"""Parser for SAMMY's Last Card parameters. | ||
Format specification from Table VI B.2: | ||
There are three alternative Last Card formats: | ||
1. Last A: COVAR matrix in binary form | ||
2. Last B: EXPLI (explicit uncertainties and correlations) | ||
3. Last C: RELAT (relative uncertainties) | ||
4. Last D: PRIOR (prior uncertainties in key word format) | ||
Multiple Last Card formats can be used together except for Last A. | ||
""" | ||
|
||
from typing import List | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class LastParameters(BaseModel): | ||
"""Placeholder for Last Card parameters. | ||
This class needs to be implemented to handle the various Last Card formats: | ||
- Last A: Binary covariance matrix | ||
- Last B: Explicit uncertainties and correlations | ||
- Last C: Relative uncertainties | ||
- Last D: Prior uncertainties in keyword format | ||
Note: | ||
Last A cannot be combined with other formats. | ||
Last B, C, and D can be used together. | ||
""" | ||
|
||
@classmethod | ||
def from_lines(cls, lines: List[str]) -> "LastParameters": | ||
"""Parse Last Card parameters from input lines. | ||
Args: | ||
lines: List of input lines | ||
Raises: | ||
NotImplementedError: This feature needs to be implemented | ||
""" | ||
raise NotImplementedError("Last Card parsing not yet implemented") | ||
|
||
def to_lines(self) -> List[str]: | ||
"""Convert parameters to fixed-width format lines. | ||
Raises: | ||
NotImplementedError: This feature needs to be implemented | ||
""" | ||
raise NotImplementedError("Last Card formatting not yet implemented") | ||
|
||
|
||
if __name__ == "__main__": | ||
print("This card is not used in PLEIADES at the moment.") |
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,91 @@ | ||
#!/usr/bin/env python | ||
"""Unit tests for Last Card parameter parsing.""" | ||
|
||
import pytest | ||
|
||
from pleiades.sammy.parameters.last import LastParameters | ||
|
||
|
||
class TestLastParameters: | ||
"""Test suite for Last Card parameter parsing. | ||
These tests serve as a placeholder and specification for the | ||
needed implementation of Last Card parsing. | ||
""" | ||
|
||
@pytest.fixture | ||
def valid_last_a_lines(self): | ||
"""Sample valid Last A (COVAR) format lines.""" | ||
return [ | ||
"COVARiance matrix is in binary form in another file", | ||
] | ||
|
||
@pytest.fixture | ||
def valid_last_b_lines(self): | ||
"""Sample valid Last B (EXPLI) format lines.""" | ||
return [ | ||
"EXPLIcit uncertainties and correlations follow", | ||
# TODO: Add example format lines when implementing | ||
] | ||
|
||
@pytest.fixture | ||
def valid_last_c_lines(self): | ||
"""Sample valid Last C (RELAT) format lines.""" | ||
return [ | ||
"RELATive uncertainties follow", | ||
# TODO: Add example format lines when implementing | ||
] | ||
|
||
@pytest.fixture | ||
def valid_last_d_lines(self): | ||
"""Sample valid Last D (PRIOR) format lines.""" | ||
return [ | ||
"PRIOR uncertainties follow in key word format", | ||
# TODO: Add example format lines when implementing | ||
] | ||
|
||
def test_unimplemented_parsing(self, valid_last_a_lines): | ||
"""Verify NotImplementedError is raised for parsing.""" | ||
with pytest.raises(NotImplementedError, match="not yet implemented"): | ||
LastParameters.from_lines(valid_last_a_lines) | ||
|
||
def test_unimplemented_formatting(self): | ||
"""Verify NotImplementedError is raised for formatting.""" | ||
params = LastParameters() | ||
with pytest.raises(NotImplementedError, match="not yet implemented"): | ||
params.to_lines() | ||
|
||
@pytest.mark.skip(reason="Awaiting implementation") | ||
def test_last_a_parsing(self, valid_last_a_lines): | ||
"""Test parsing of Last A (COVAR) format.""" | ||
_ = LastParameters.from_lines(valid_last_a_lines) | ||
# TODO: Add assertions when implementing | ||
|
||
@pytest.mark.skip(reason="Awaiting implementation") | ||
def test_last_b_parsing(self, valid_last_b_lines): | ||
"""Test parsing of Last B (EXPLI) format.""" | ||
_ = LastParameters.from_lines(valid_last_b_lines) | ||
# TODO: Add assertions when implementing | ||
|
||
@pytest.mark.skip(reason="Awaiting implementation") | ||
def test_last_c_parsing(self, valid_last_c_lines): | ||
"""Test parsing of Last C (RELAT) format.""" | ||
_ = LastParameters.from_lines(valid_last_c_lines) | ||
# TODO: Add assertions when implementing | ||
|
||
@pytest.mark.skip(reason="Awaiting implementation") | ||
def test_last_d_parsing(self, valid_last_d_lines): | ||
"""Test parsing of Last D (PRIOR) format.""" | ||
_ = LastParameters.from_lines(valid_last_d_lines) | ||
# TODO: Add assertions when implementing | ||
|
||
@pytest.mark.skip(reason="Awaiting implementation") | ||
def test_last_a_exclusive(self, valid_last_a_lines, valid_last_b_lines): | ||
"""Test that Last A cannot be combined with other formats.""" | ||
combined_lines = valid_last_a_lines + valid_last_b_lines | ||
with pytest.raises(ValueError, match="Last A cannot be combined"): | ||
LastParameters.from_lines(combined_lines) | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main(["-v", __file__]) |