From aeecdb8d029c622bad1c70bfd4a75354a5259753 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 22 Feb 2025 21:37:49 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pleiades/sammy/parfile.py | 80 +++++++++---------- .../pleiades/sammy/parameters/test_radius.py | 9 ++- 2 files changed, 47 insertions(+), 42 deletions(-) diff --git a/src/pleiades/sammy/parfile.py b/src/pleiades/sammy/parfile.py index 7977f09..ae3e424 100644 --- a/src/pleiades/sammy/parfile.py +++ b/src/pleiades/sammy/parfile.py @@ -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. @@ -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 @@ -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: @@ -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 @@ -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 = [] @@ -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]}") diff --git a/tests/unit/pleiades/sammy/parameters/test_radius.py b/tests/unit/pleiades/sammy/parameters/test_radius.py index 2ef0efe..975785d 100644 --- a/tests/unit/pleiades/sammy/parameters/test_radius.py +++ b/tests/unit/pleiades/sammy/parameters/test_radius.py @@ -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) @@ -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).""" @@ -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.""" @@ -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.""" @@ -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.""" @@ -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.""" @@ -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.""" @@ -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.""" @@ -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)