Source code for pleiades.sammy.io.card_formats.inp05_broadening

#!/usr/bin/env python
"""
Card Set 5 (Broadening/Resolution Parameters) for SAMMY INP files.

This module provides the Card05 class for parsing and generating the broadening
constants line in SAMMY input files. This card appears after the alphanumeric
command block and defines temperature, flight path, and resolution parameters.

Format specification (Card Set 5 - Broadening/Resolution):
    The line contains five floating-point values with variable spacing:
    - TEMP: Temperature (K)
    - FPL: Flight path length (m)
    - DELTAL: Spread in flight-path length (m)
    - DELTAG: Gaussian resolution width (μs)
    - DELTAE: e-folding width of exponential resolution (μs)

Example:
          300.  200.0000  0.182233       0.0  0.002518
"""

from typing import List

from pydantic import BaseModel, Field

from pleiades.utils.logger import loguru_logger

logger = loguru_logger.bind(name=__name__)


[docs] class PhysicalConstants(BaseModel): """Pydantic model for broadening constants in Card Set 5. Attributes: temperature: Temperature in Kelvin flight_path_length: Flight path length in meters delta_l: Spread in flight-path length in meters delta_g: Gaussian resolution width in microseconds delta_e: e-folding width of exponential resolution in microseconds """ temperature: float = Field(..., description="Temperature (K)", gt=0) flight_path_length: float = Field(..., description="Flight path length (m)", gt=0) delta_l: float = Field(default=0.0, description="Spread in flight-path length (m)", ge=0) delta_g: float = Field(default=0.0, description="Gaussian resolution width (μs)", ge=0) delta_e: float = Field(default=0.0, description="e-folding width of exponential resolution (μs)", ge=0)
[docs] class Card05(BaseModel): """ Class representing Card Set 5 (broadening constants) in SAMMY INP files. This card defines temperature, flight path, and resolution parameters for the analysis. """
[docs] @classmethod def from_lines(cls, lines: List[str]) -> PhysicalConstants: """Parse broadening constants from Card Set 5 line. Args: lines: List of input lines (expects single line for Card 5) Returns: PhysicalConstants: Parsed broadening constants Raises: ValueError: If format is invalid or required values missing """ if not lines or not lines[0].strip(): message = "No valid Card 5 line provided" logger.error(message) raise ValueError(message) line = lines[0].strip() fields = line.split() if len(fields) < 1: message = f"Card 5 line must have at least 1 field (TEMP), got {len(fields)}" logger.error(message) raise ValueError(message) try: temperature = float(fields[0]) flight_path_length = float(fields[1]) if len(fields) > 1 else 25.0 delta_l = float(fields[2]) if len(fields) > 2 else 0.0 delta_g = float(fields[3]) if len(fields) > 3 else 0.0 delta_e = float(fields[4]) if len(fields) > 4 else 0.0 except (ValueError, IndexError) as e: message = f"Failed to parse Card 5 line: {e}" logger.error(message) raise ValueError(message) return PhysicalConstants( temperature=temperature, flight_path_length=flight_path_length, delta_l=delta_l, delta_g=delta_g, delta_e=delta_e, )
[docs] @classmethod def to_lines(cls, constants: PhysicalConstants) -> List[str]: """Convert broadening constants to Card Set 5 formatted line. Args: constants: PhysicalConstants object containing parameter data Returns: List containing single formatted line for Card Set 5 """ if not isinstance(constants, PhysicalConstants): message = "constants must be an instance of PhysicalConstants" logger.error(message) raise ValueError(message) line = ( f" {constants.temperature:5.1f} " f"{constants.flight_path_length:8.4f} " f"{constants.delta_l:8.6f} " f"{constants.delta_g:3.1f} " f"{constants.delta_e:8.6f}" ) return [line]