atlas_py¶
Pure-Python ATLAS12 atmosphere engine. atlas_py iterates a 1-D stellar
atmosphere in hydrostatic, radiative, and convective equilibrium using the same
physics as the original Fortran ATLAS12 code.
The top-level entry point is run_atlas() in the driver. Most users invoke it
indirectly through pykurucz.run_atlas_py().
See also:
Configuration¶
Configuration models for atlas_py.
Classes¶
AtlasInput
dataclass
¶
AtlasInput(atmosphere_path: Path, control_deck_path: Optional[Path] = None, molecules_path: Optional[Path] = None, line_selection_path: Optional[Path] = None, nlteline_path: Optional[Path] = None, fort11_path: Optional[Path] = None, fort111_path: Optional[Path] = None, fort21_path: Optional[Path] = None, fort31_path: Optional[Path] = None, fort41_path: Optional[Path] = None, fort51_path: Optional[Path] = None, fort61_path: Optional[Path] = None)
Input sources for an ATLAS12-like run.
AtlasOutput
dataclass
¶
AtlasOutput(output_atm_path: Path, diagnostics_path: Optional[Path] = None, debug_state_path: Optional[Path] = None)
Output targets for an ATLAS12-like run.
AtlasConfig
dataclass
¶
AtlasConfig(inputs: AtlasInput, outputs: AtlasOutput, iterations: int = 1, enable_molecules: bool = False, enable_convection: bool = True, enable_scattering: bool = True, print_level: int = 1, punch_level: int = 1, log_level: str = 'INFO', convergence_epsilon: Optional[float] = None, convergence_min_iterations: int = 5, convergence_consecutive: int = 1, convergence_dlntmax: float = 0.0005, n_workers: Optional[int] = None, cache_dir: Optional[Path] = None, linop1_serial: Optional[bool] = None, convec_fd_parallel: Optional[bool] = None, pops_parallel: Optional[bool] = None)
Global runtime configuration for atlas_py.
Engine Driver¶
I/O — Atmosphere¶
ATLAS12 .atm read/write utilities.
Units (Fortran atlas12.for): - RHOX: g cm^-2 - T: K - P: dyn cm^-2 - XNE: cm^-3 - ABROSS: cm^2 g^-1 - ACCRAD: cm s^-2 - VTURB: cm s^-1
Classes¶
AtlasAtmosphere
dataclass
¶
AtlasAtmosphere(rhox: ndarray, temperature: ndarray, gas_pressure: ndarray, electron_density: ndarray, abross: ndarray, accrad: ndarray, vturb: ndarray, extra1: ndarray, extra2: ndarray, metadata: Dict[str, str] = dict(), abundances: Dict[int, float] = dict())
Structured ATLAS12 atmosphere model.
Functions:¶
write_atm
¶
write_atm(model: AtlasAtmosphere, path: Path) -> None
Write an ATLAS-compatible .atm file.
I/O — READIN Deck¶
Parser for ATLAS12 control-deck style commands (READIN semantics).
Classes¶
AtlasDeck
dataclass
¶
AtlasDeck(molecules_on: bool = True, read_molecules: bool = True, read_punch: bool = True, opacity_lines: bool = True, opacity_xlines: bool = True, convection_over: float = 1.25, iterations: int = 1, print_level: int = 1, punch_level: int = 1, scale_model_fields: List[float] | None = None, vturb_cms: float = 200000.0)
Normalized control deck fields used by atlas_py.
Functions:¶
parse_readin_deck
¶
parse_readin_deck(path: Path) -> AtlasDeck
Parse a simple ATLAS12 stdin deck used by atlas12.exe.
This parser supports the subset needed for single-iteration validation: MOLECULES, READ MOLECULES, READ PUNCH, OPACITY ON LINES/XLINES, CONVECTION OVER, ITERATIONS, PRINT, PUNCH, SCALE MODEL, VTURB.
Physics — Hydrostatic Equilibrium¶
Hydrostatic-equilibrium updates matching atlas12.for iteration section.
Classes¶
Functions:¶
integrate_hydrostatic_pressure
¶
integrate_hydrostatic_pressure(atm: AtlasAtmosphere, gravity_cgs: float, prad: ndarray, pturb: ndarray, pcon: float) -> np.ndarray
Compute gas pressure from hydrostatic balance.
Fortran reference (atlas12.for, lines 226-229):
P(J)=GRAV*RHOX(J)-PRAD(J)-PTURB(J)-PCON
Units: - gravity_cgs: cm s^-2 - RHOX: g cm^-2 - PRAD/PTURB/PCON/P: dyn cm^-2
update_total_pressure
¶
update_total_pressure(rhox: ndarray, gravity_cgs: float, pzero: float) -> np.ndarray
Fortran reference (atlas12.for, line 245): PTOTAL=GRAV*RHOX+PZERO.
Physics — Population Orchestration (POPSALL)¶
Physics — Molecular Equilibrium (NMOLEC)¶
Molecular equilibrium (NMOLEC/MOLEC) port from atlas12.for.
Fortran reference:
- atlas12.for lines 4038-4556 (MOLEC, NMOLEC)
- atlas12.for lines 23130-23231 (PARTFNH2, EQUILH2)
Classes¶
Functions:¶
set_nmolec_context
¶
set_nmolec_context(*, temperature_k: ndarray, tk_erg: ndarray, tlog: ndarray, gas_pressure: ndarray, state: AtlasRuntimeState, nummol: int, code_mol: ndarray, equil: ndarray, locj: ndarray, kcomps: ndarray, idequa: ndarray, nequa: int) -> None
Bind current atmospheric state + READMOL data for NMOLEC/MOLEC calls.
get_nmolec_snapshot
¶
get_nmolec_snapshot() -> dict[str, np.ndarray] | None
Return current molecular-state arrays for debug dumping.
nmolec
¶
nmolec(*_args, **_kwargs)
Compute molecular equilibrium and update state arrays (ATLAS12 path).
molec
¶
molec(*_args, **_kwargs)
Return requested molecule/ion populations from current molecular state.
set_nmolec_ifedns
¶
set_nmolec_ifedns(val: int) -> None
Set the nmolec ifedns flag (0=main iteration, 1=CONVEC FD warm-start).
save_nmolec_xnsave
¶
save_nmolec_xnsave() -> 'np.ndarray | None'
Return a copy of the current xnsave array for later restoration.
restore_nmolec_xnsave
¶
restore_nmolec_xnsave(saved: 'np.ndarray | None') -> None
Restore xnsave from a previously saved copy.
compute_nmolec_edens
¶
compute_nmolec_edens(*, temperature_k: 'np.ndarray', tk_erg: 'np.ndarray', gas_pressure: 'np.ndarray', state: 'AtlasRuntimeState') -> 'np.ndarray'
Compute EDENS = (thermal + molecular) / rho matching Fortran label 160 in NMOLEC.
Fortran reference: atlas12.for lines 4449-4554 (label 160 in SUBROUTINE NMOLEC). Called by _convec_fd_samples in place of compute_atomic_energy_density so that the CONVEC FD derivatives include molecular dissociation energy contributions (especially H2 at T<5000K).
Returns energy density in erg g^-1 per depth layer.
Physics — Continuum Opacity (KAPP)¶
Continuum opacity assembly for atlas_py (Phase 2 baseline).
Classes¶
KappAtmosphereAdapter
dataclass
¶
KappAtmosphereAdapter(temperature: ndarray, mass_density: ndarray, electron_density: ndarray, gas_pressure: ndarray, xnfph: ndarray, xnf_h: ndarray, xnf_h_ionized: ndarray, xnf_he1: ndarray, xnf_he2: ndarray, xabund: ndarray, bhyd: ndarray, turbulent_velocity: ndarray, xnf_all: ndarray, xnfp_all: ndarray, xnfpch: ndarray, xnfpoh: ndarray)
Adapter mirroring the ATLAS12 COMMON blocks used by KAPP and its sub-routines.
Every field corresponds to a Fortran array that is always allocated and
populated before KAPP is called. No field may be None unless noted;
Fortran COMMON blocks have no concept of absent arrays.
Units (matching Fortran): - temperature: K — COMMON /TEMP/ T(kw) - mass_density: g cm^-3 — COMMON /STATE/ RHO(kw) - electron_density: cm^-3 — COMMON /STATE/ XNE(kw) - gas_pressure: dyn cm^-2 — COMMON /STATE/ P(kw) - xnfph: cm^-3 / partition — POPS(1.01D0,11,XNFPH) - bhyd: dimensionless — COMMON /DEPART/ BHYD(kw,6), DATA 1.0 - turbulent_velocity: cm s^-1 — COMMON /TURBPR/ VTURB(kw)
Functions:¶
compute_kapp
¶
compute_kapp(adapter: KappAtmosphereAdapter, freq_hz: ndarray, atlas_tables: dict[str, ndarray], ifop: list[int], tcst=None) -> tuple[np.ndarray, np.ndarray, np.ndarray]
Compute continuum opacity arrays (ACONT, SIGMAC, SCONT).
ifop must be passed from the parsed .atm file or control deck —
mirrors Fortran KAPP which reads IFOP directly from READIN output.
Physics — Temperature Correction (TCORR)¶
TCORR port from ATLAS12 (mode 1/2/3).
Fortran reference:
- atlas12.for lines 605-701 (SUBROUTINE TCORR)
- atlas12.for lines 16024-16069 (FUNCTION EXPI)
Classes¶
TcorrState
dataclass
¶
TcorrState(rjmins: ndarray, rdabh: ndarray, rdiagj: ndarray, flxrad: ndarray, oldt1: ndarray, ross_tabt: ndarray, ross_tabp: ndarray, ross_logk: ndarray, nross: int, zerot: float, zerop: float, slopet: float, slopep: float)
Frequency-integrated accumulators used by TCORR.
TcorrMode3Result
dataclass
¶
TcorrMode3Result(temperature: ndarray, flxerr: ndarray, flxdrv: ndarray, dtflux: ndarray, dtlamb: ndarray, dtsurf: ndarray, t1: ndarray, hratio: ndarray, cnvflx: ndarray, rhox: ndarray, drhox: ndarray)
Mode-3 outputs for diagnostics and driver updates.
Returns corrected T (T+T1) and RHOX (RHOX+DRHOX) on the original TAUROS grid. The driver (atlas_py/engine/driver.py) is responsible for the full Fortran TCORR (atlas12.for lines 951-991) state remap: after applying these corrections, it MAP1-remaps ALL state arrays (RHOX, T, P, XNE, ABROSS, PRAD, ACCRAD, VTURB, PTURB) from TAUROS to TAUSTD and sets TAUROS=TAUSTD.
Functions:¶
rosstab_ingest
¶
rosstab_ingest(st: TcorrState, t: ndarray, p: ndarray, abross: ndarray) -> None
Mimic ROSSTAB(0,0,0) table accumulation from ATLAS12.
rosstab_eval
¶
rosstab_eval(st: TcorrState, temp: float, pressure: float) -> float
Evaluate ROSSTAB(T,P,V) interpolation from cached table.
Fortran reference: atlas12.for lines 1423-1549 (FUNCTION ROSSTAB). When the table is empty (NROSS=0), Fortran's DO 21 loop doesn't execute, all INDEX remain 0, and label 30 runs with ROSS(MAX(1,0))=ROSS(1). Because NROSS has a DATA statement, gfortran places all locals in static storage (implicit SAVE), so ROSS(1) is zero-initialized → R=0 → ROSSTAB = 10.*0 = 1.0.
tcorr_step
¶
tcorr_step(st: TcorrState, *, mode: int, rcowt: float, rhox: ndarray, abtot: ndarray, hnu: ndarray, jmins: ndarray, taunu: ndarray, bnu: ndarray, freq_hz: float, hkt: ndarray, temperature_k: ndarray, stim: ndarray, alpha: ndarray, flux: float, teff: float, numnu: int, tauros: ndarray | None = None, abross: ndarray | None = None, iter_index: int = 1, ifconv: int = 0, flxcnv: ndarray | None = None, flxcnv0: ndarray | None = None, dltdlp: ndarray | None = None, grdadb: ndarray | None = None, hscale: ndarray | None = None, ptotal: ndarray | None = None, rho: ndarray | None = None, dlrdlt: ndarray | None = None, heatcp: ndarray | None = None, mixlth: float = 1.0, j1smooth: int = 0, j2smooth: int = 0, wtjm1: float = 0.3, wtj: float = 0.4, wtjp1: float = 0.3, prad: ndarray | None = None, pturb: ndarray | None = None, gravity_cgs: float = 10000.0, steplg: float = 0.125, tau1lg: float = -6.875) -> TcorrMode3Result | None
Apply TCORR mode updates.
- Mode 1: zero frequency integrals
- Mode 2: accumulate frequency integrals
- Mode 3: apply temperature correction (ATLAS12 lines ~703-947)
Physics — Convection (CONVEC)¶
ATLAS12 HIGH/CONVEC step.
Fortran references:
- atlas12.for lines 5093-5107 (SUBROUTINE HIGH)
- atlas12.for lines 4849-5092 (SUBROUTINE CONVEC)
Notes: - When EDENS/RHO finite-difference samples are provided, this follows the Fortran CONVEC derivative path directly. - A fallback ideal-gas derivative path is retained for safety when those samples are unavailable.
Classes¶
ConvecResult
dataclass
¶
ConvecResult(height: ndarray, dltdlp: ndarray, heatcp: ndarray, dlrdlt: ndarray, velsnd: ndarray, grdadb: ndarray, hscale: ndarray, flxcnv: ndarray, vconv: ndarray, flxcnv0: ndarray, flxcnv1: ndarray)
Outputs corresponding to ATLAS12 /CONV/ and /HEIGHT/ blocks.
Functions:¶
high_from_rhox
¶
high_from_rhox(*, rhox: ndarray, rho: ndarray) -> np.ndarray
Port of HIGH: integrate geometric height from RHOX and RHO.
convec
¶
convec(*, tcst: TcorrState, rhox: ndarray, tauros: ndarray, temperature_k: ndarray, gas_pressure: ndarray, mass_density: ndarray, abross: ndarray, vturb: ndarray, pradk: ndarray, ptotal: ndarray, gravity_cgs: float, flux: float, mixlth: float = 1.0, overwt: float = 1.0, ifconv: int = 1, nconv: int = 36, edens1: ndarray | None = None, edens2: ndarray | None = None, edens3: ndarray | None = None, edens4: ndarray | None = None, rho1: ndarray | None = None, rho2: ndarray | None = None, rho3: ndarray | None = None, rho4: ndarray | None = None, convec_log_path: str | None = None) -> ConvecResult
Compute convection arrays for one iteration (ATLAS12 CONVEC structure).