pleiades.sammy.io.card_formats.par10_isotopes module
- pleiades.sammy.io.card_formats.par10_isotopes.logical_line_two(lst) bool[source]
Validates a list representing spin group numbers according to specific rules.
- The input list is expected to have the following structure:
The first element is a flag (vary flag) that must be either 0 or 1.
The remaining elements represent spin group numbers.
- Validation criteria:
The list must not be empty.
The first element (flag) must be 0 or 1.
- All spin group numbers (elements after the first) must be:
Positive integers (> 0)
Unique (no duplicates)
Strictly increasing (each subsequent number is greater than the previous)
- Parameters:
lst (list) – A list where the first element is a flag (0 or 1), followed by spin group numbers.
- Returns:
True if the list meets all validation criteria, False otherwise.
- Return type:
Examples
>>> logical_line_two([1, 2, 3, 5]) True >>> logical_line_two([0, 1, 1, 2]) False >>> logical_line_two([2, 1, 2, 3]) False
- pleiades.sammy.io.card_formats.par10_isotopes.get_line_two_format_and_parse(line)[source]
Parses a line to extract spin group numbers using either the standard or extended format.
This function attempts to parse a given line, extracting spin group numbers based on two possible formats: standard and extended. The function first strips trailing whitespace from the line, then divides the relevant portion of the line into fields according to the widths defined in the LINE_TWO_BACK_MATTER_STANDARD and LINE_TWO_BACK_MATTER_EXTENDED dictionaries. It attempts to convert each field to an integer, stopping at the first occurrence of “-1” or an invalid value.
The function then checks which format (standard or extended) yields a logically valid result using the logical_line_two function. If a valid format is found, it returns a tuple containing the first spin group number and a list of the remaining spin group numbers. If neither format is valid, it logs an error and raises a ValueError.
- Parameters:
line (str) – The input line from which to parse spin group numbers.
- Returns:
- A tuple (first_group, remaining_groups), where first_group is the first parsed spin group
number (int), and remaining_groups is a list of the remaining parsed spin group numbers (List[int]).
- Return type:
- Raises:
ValueError – If neither the standard nor extended format yields a valid set of spin group numbers.
- Logs:
Error messages if the input line cannot be parsed into a valid format.
- pleiades.sammy.io.card_formats.par10_isotopes.parse_line_three(line)[source]
Parse a line according to the Card-10 line-3 extended format and return a list of spin groups.
This function processes a fixed-width formatted line, extracting integer values representing spin groups. It iterates over the line in field-width increments, starting from a specified offset, and attempts to convert each field to an integer. If a field contains the continuation marker “-1”, parsing stops. If a field cannot be converted to an integer, -1 is appended as a placeholder.
- class pleiades.sammy.io.card_formats.par10_isotopes.Card10[source]
Bases:
BaseModelContainer for a complete isotope parameter card set (Card Set 10).
This class handles a complete Card Set 10, including: - Header line validation - Multiple isotope entries - Total abundance validation - Format selection (standard vs extended)
- classmethod is_header_line(line: str) bool[source]
Check if line is a valid header line.
- Parameters:
line – Input line to check
- Returns:
True if the first 5 characters of the line are ‘ISOTO’
- Return type:
- classmethod from_lines(lines: List[str], fit_config: FitConfig = None) None[source]
Parse a complete isotope parameter card set from lines.
- Parameters:
lines – List of input lines including header and blank terminator
FitConfig – FitConfig object to read isotopes into.
- Raises:
ValueError – If no valid header found or invalid format
- static to_lines(fit_config: FitConfig) List[str][source]
Convert a fit_config object to a Card 10 list of lines.
Figures out the number of spin groups and formats the lines accordingly.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].