Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 22, 2025
1 parent fa9bd68 commit aeecdb8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 42 deletions.
80 changes: 40 additions & 40 deletions src/pleiades/sammy/parfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,47 @@
UnusedCorrelatedCard,
UserResolutionParameters,
)
from pleiades.utils.logger import Logger, _log_and_raise_error
from pleiades.utils.logger import Logger

# Initialize logger with file logging
log_file_path = os.path.join(os.getcwd(), "pleiades-par.log")
logger = Logger(__name__, log_file=log_file_path)

# Header lines for card sets in the PARameter file
# NOTE: If a card is not implemented, the value is None
# NOTE: If a card is not implemented, the value is None
parFile_header_card_class = {
"EXTERnal R-function parameters follow": ExternalRFunction,
"R-EXTernal parameters follow": ExternalRFunction,
"BROADening parameters may be varied": BroadeningParameterCard,
"UNUSEd but correlated variables": UnusedCorrelatedCard,
"NORMAlization and background": NormalizationBackgroundCard,
"RADIUs parameters follow": RadiusCard,
"RADII are in KEY-WORD format": RadiusCard,
"CHANNel radius parameters follow": RadiusCard,
"DATA reduction parameters are next": DataReductionCard,
"ORRES": ORRESCard,
"ISOTOpic abundances and masses": IsotopeCard,
"NUCLIde abundances and masses": IsotopeCard,
"MISCEllaneous parameters follow": None, # Not implemented
"PARAMagnetic cross section parameters follow": ParamagneticParameters,
"BACKGround functions": None, # Not implemented
"RPI Resolution function": None, # Not implemented
"GEEL resolution function": None, # Not implemented
"GELINa resolution": None, # Not implemented
"NTOF resolution function": None, # Not implemented
"RPI Transmission resolution function": None, # Not implemented
"RPI Capture resolution function": None, # Not implemented
"GEEL DEFAUlts": None, # Not implemented
"GELINa DEFAUlts": None, # Not implemented
"NTOF DEFAUlts": None, # Not implemented
"DETECtor efficiencies": None, # Not implemented
"USER-Defined resolution function": UserResolutionParameters,
"COVARiance matrix is in binary form in another file": None, # Not implemented
"EXPLIcit uncertainties and correlations follow": None, # Not implemented
"RELATive uncertainties follow": None, # Not implemented
"PRIOR uncertainties follow in key-word format": None, # Not implemented
}
"EXTERnal R-function parameters follow": ExternalRFunction,
"R-EXTernal parameters follow": ExternalRFunction,
"BROADening parameters may be varied": BroadeningParameterCard,
"UNUSEd but correlated variables": UnusedCorrelatedCard,
"NORMAlization and background": NormalizationBackgroundCard,
"RADIUs parameters follow": RadiusCard,
"RADII are in KEY-WORD format": RadiusCard,
"CHANNel radius parameters follow": RadiusCard,
"DATA reduction parameters are next": DataReductionCard,
"ORRES": ORRESCard,
"ISOTOpic abundances and masses": IsotopeCard,
"NUCLIde abundances and masses": IsotopeCard,
"MISCEllaneous parameters follow": None, # Not implemented
"PARAMagnetic cross section parameters follow": ParamagneticParameters,
"BACKGround functions": None, # Not implemented
"RPI Resolution function": None, # Not implemented
"GEEL resolution function": None, # Not implemented
"GELINa resolution": None, # Not implemented
"NTOF resolution function": None, # Not implemented
"RPI Transmission resolution function": None, # Not implemented
"RPI Capture resolution function": None, # Not implemented
"GEEL DEFAUlts": None, # Not implemented
"GELINa DEFAUlts": None, # Not implemented
"NTOF DEFAUlts": None, # Not implemented
"DETECtor efficiencies": None, # Not implemented
"USER-Defined resolution function": UserResolutionParameters,
"COVARiance matrix is in binary form in another file": None, # Not implemented
"EXPLIcit uncertainties and correlations follow": None, # Not implemented
"RELATive uncertainties follow": None, # Not implemented
"PRIOR uncertainties follow in key-word format": None, # Not implemented
}


class CardOrder(Enum):
"""Defines the standard order of cards in SAMMY parameter files.
Expand Down Expand Up @@ -145,7 +146,7 @@ def to_string(self) -> str:
"""
where_am_i = "SammyParameterFile.to_string()"

#logger.info(f"{where_am_i}: Attempting to convert parameters to string format")
# logger.info(f"{where_am_i}: Attempting to convert parameters to string format")
lines = []

# Process each card type in standard order
Expand Down Expand Up @@ -224,7 +225,7 @@ def from_string(cls, content: str) -> "SammyParameterFile":
# Split content into lines
lines = content.splitlines()

logger.info(f"{where_am_i}: Attempting to parse parameter file content from string {lines}")
logger.info(f"{where_am_i}: Attempting to parse parameter file content from string {lines}")

# Early exit for empty content
if not lines:
Expand All @@ -238,11 +239,10 @@ def from_string(cls, content: str) -> "SammyParameterFile":

# read and append lines to resonance_or_fudge_factor_content until we find a header line
for line in lines:

# Check if line matches any keys in parFile_header_card_class
if line in parFile_header_card_class.keys():
card_type, card_class = cls._get_card_class_with_header(line)

# if so then you have pasted the resonances and fudge factor
if card_class:
break
Expand Down Expand Up @@ -290,9 +290,9 @@ def from_string(cls, content: str) -> "SammyParameterFile":
except Exception as e:
logger.error(f"Failed to parse resonance table: {str(e)}\nLines: {resonances_entries}")
raise ValueError(f"Failed to parse resonance table: {str(e)}\nLines: {resonances_entries}")

# remove the resonance_or_fudge_factor_content from the lines
lines = lines[len(resonance_or_fudge_factor_content):]
lines = lines[len(resonance_or_fudge_factor_content) :]

# Second, partition lines into group of lines based on blank lines
card_groups = []
Expand Down Expand Up @@ -329,7 +329,7 @@ def from_string(cls, content: str) -> "SammyParameterFile":
except Exception as e:
logger.error(f"Failed to parse {card_type.name} card: {str(e)}\nLines: {group}")
raise ValueError(f"Failed to parse {card_type.name} card: {str(e)}\nLines: {group}")

# If card type is not implemented, then throw an error stating card type is not implemented yet
else:
logger.error(f"{where_am_i}: Card type not implemented: {group[0]}")
Expand Down
9 changes: 7 additions & 2 deletions tests/unit/pleiades/sammy/parameters/test_radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def test_basic_fixed_width_format():
# Access the RadiusParameters object in the parameters list
params = card.parameters[0]


# Verify parsed values
assert params.effective_radius == pytest.approx(3.200)
assert params.true_radius == pytest.approx(3.200)
Expand Down Expand Up @@ -107,6 +106,7 @@ def test_basic_fixed_width_format():
assert content_line[26:28] == " 2" # Second spin group
assert content_line[28:30] == " 3" # Third spin group


@pytest.mark.skip(reason="Alternate fixed-width format is unsupported at the moment")
def test_alternate_fixed_width_format():
"""Test alternate fixed-width format parsing (for >=99 spin groups)."""
Expand Down Expand Up @@ -159,6 +159,7 @@ def test_alternate_fixed_width_format():
assert content_line[40:45] == " 102" # Second spin group (5 cols)
assert content_line[45:50] == " 103" # Third spin group (5 cols)


@pytest.mark.skip(reason="Alternate keyword format is unsupported at the moment")
def test_basic_radius_keyword_format():
"""Test basic keyword format parsing with single radius value."""
Expand Down Expand Up @@ -189,6 +190,7 @@ def test_basic_radius_keyword_format():
assert any(line.startswith("Radius= 3.2") for line in output_lines)
assert any(line.startswith("Group= 1") for line in output_lines)


@pytest.mark.skip(reason="Alternate keyword format is unsupported at the moment")
def test_separate_radii_keyword_format():
"""Test keyword format parsing with different effective/true radius values."""
Expand All @@ -213,6 +215,7 @@ def test_separate_radii_keyword_format():
print("\nGenerated output:")
print("\n".join(output_lines))


@pytest.mark.skip(reason="Alternate keyword format is unsupported at the moment")
def test_uncertainties_keyword_format():
"""Test keyword format parsing with uncertainty specifications."""
Expand All @@ -239,6 +242,7 @@ def test_uncertainties_keyword_format():
assert any(line.startswith("Relative= 0.05") for line in output_lines)
assert any(line.startswith("Absolute= 0.002") for line in output_lines)


@pytest.mark.skip(reason="Alternate keyword format is unsupported at the moment")
def test_particle_pair_keyword_format():
"""Test keyword format parsing with particle pair and orbital momentum."""
Expand All @@ -263,6 +267,7 @@ def test_particle_pair_keyword_format():
assert any(line.startswith("PP= n+16O") for line in output_lines)
assert any("L= all" in line for line in output_lines)


@pytest.mark.skip(reason="Alternate keyword format is unsupported at the moment")
def test_groups_channels_keyword_format():
"""Test keyword format parsing with group and channel specifications."""
Expand All @@ -287,6 +292,7 @@ def test_groups_channels_keyword_format():
print("\nGenerated output:")
print("\n".join(output_lines))


@pytest.mark.skip(reason="Alternate keyword format is unsupported at the moment")
def test_invalid_keyword_format():
"""Test error handling for invalid keyword format."""
Expand Down Expand Up @@ -381,7 +387,6 @@ def test_radius_with_extras():
# Verify that there is only one set of parameters in the card
assert len(card.parameters) == 1


# Verify core parameters
assert card.parameters[0].effective_radius == pytest.approx(3.200)
assert card.parameters[0].true_radius == pytest.approx(3.200)
Expand Down

0 comments on commit aeecdb8

Please sign in to comment.