Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.0 #38

Open
wants to merge 253 commits into
base: main
Choose a base branch
from
Open

V2.0 #38

Changes from 1 commit
Commits
Show all changes
253 commits
Select commit Hold shift + click to select a range
1a16aa3
add github action for unit test
KedoKudo Dec 4, 2024
987c743
add skeleton for the sammy backend support
KedoKudo Dec 17, 2024
f097c11
add configuration management for SAMMY execution backends
KedoKudo Dec 20, 2024
b986aaa
add directory preparation and execution logic for LocalSammyRunner
KedoKudo Dec 20, 2024
3717a34
refactor main execution logic in LocalSammyRunner for improved readab…
KedoKudo Dec 20, 2024
b8dfbe3
refactor Docker configuration validation and output collection logic …
KedoKudo Dec 20, 2024
b955a65
add NOVA backend implementation for SAMMY execution with configuratio…
KedoKudo Dec 23, 2024
867c661
add testing input data
KedoKudo Dec 23, 2024
3445307
add pyyaml dependency and configuration for SAMMY runner
KedoKudo Dec 23, 2024
0caa788
add back images
KedoKudo Dec 23, 2024
5b8d5b8
refactor SAMMY backend: update output collection logic and remove asy…
KedoKudo Dec 23, 2024
3a84dad
update poetry lock file
KedoKudo Dec 23, 2024
7e4c5d4
fix issues on runner
KedoKudo Dec 23, 2024
37e50c7
add unit test for interface
KedoKudo Dec 23, 2024
36b77d0
add unit tests for LocalSammyRunner and update coverage configuration
KedoKudo Dec 26, 2024
6efd3b2
fix errors introduced by pre-commit
KedoKudo Dec 26, 2024
d0fb413
fix issues related to mocked sammy binary
KedoKudo Dec 26, 2024
44c0173
add unit test for docker runner
KedoKudo Dec 26, 2024
93f72c1
add unit test for nova runner
KedoKudo Dec 26, 2024
1ad4f9a
add unit test for factory
KedoKudo Dec 27, 2024
3a97728
fix missing mocks for sammy binary
KedoKudo Dec 27, 2024
01492ea
add physical constants and validation tests
KedoKudo Dec 30, 2024
d15009e
add core physical quantity models with validation
KedoKudo Dec 30, 2024
14d2516
update deps lock
KedoKudo Dec 30, 2024
4fbc9b7
add models unit test
KedoKudo Dec 31, 2024
2106807
add neutron transmission calculations with error handling and logging
KedoKudo Dec 31, 2024
fdfdf2f
migrate sammy par file handler
KedoKudo Dec 31, 2024
cfb252a
switch back to original parFile parser
KedoKudo Jan 1, 2025
1dd4264
add legacy folder for og implementation
KedoKudo Jan 1, 2025
3aa1f55
add resonance card
KedoKudo Jan 7, 2025
58514cb
fix import error that leads to incorrect cov report
KedoKudo Jan 7, 2025
572110d
add extern R card parser
KedoKudo Jan 9, 2025
b862f63
add document to docs for original design
KedoKudo Jan 10, 2025
5975f47
fix name typo
KedoKudo Jan 14, 2025
8d73e39
add refactor design document
KedoKudo Jan 14, 2025
cb0cc0f
switch to pep621 format
KedoKudo Jan 16, 2025
3d5c043
add boardening card parser
KedoKudo Jan 16, 2025
8911e3f
add boradening paramter card
KedoKudo Jan 17, 2025
9d23c64
add unused card
KedoKudo Jan 17, 2025
b177aa0
add normalization card
KedoKudo Jan 17, 2025
41b09e6
add radius parser
KedoKudo Jan 22, 2025
be6e341
add unit test for radii
KedoKudo Jan 22, 2025
0ea0069
finished up development for radii card
KedoKudo Jan 22, 2025
081c50d
Merge pull request #23 from lanl/refactor_2nd_attempt
KedoKudo Jan 22, 2025
cfec5a1
add parser for data reduction
KedoKudo Jan 23, 2025
7ba58c3
add unit test for data reduction
KedoKudo Jan 23, 2025
5cbc690
Merge pull request #24 from lanl/sammy_param_datareduction
KedoKudo Jan 23, 2025
b25018c
add draft orres card
KedoKudo Jan 24, 2025
09f6882
update orres and imp partial unit test
KedoKudo Jan 26, 2025
18bbdfd
add unit test for LITHI
KedoKudo Jan 26, 2025
675390e
add unit test for NE110
KedoKudo Jan 27, 2025
251463d
add unit test for ChannelParameters
KedoKudo Jan 27, 2025
4f3743d
add final integrate test for orres card
KedoKudo Jan 27, 2025
229c2cd
expore orrse card at top level
KedoKudo Jan 27, 2025
57f9883
Merge pull request #25 from lanl/sammy_orres
KedoKudo Jan 27, 2025
70a10ff
add isotope and unit test
KedoKudo Jan 28, 2025
42e3706
Merge pull request #26 from lanl/sammy_iso_abund_mass
KedoKudo Jan 29, 2025
e493ea6
add delta and eta
KedoKudo Jan 30, 2025
5de5a55
add finit and gamma card
KedoKudo Jan 30, 2025
306ede1
add Tzero
KedoKudo Jan 30, 2025
a7609dd
add siabn
KedoKudo Jan 30, 2025
ea906b0
add SELFI
KedoKudo Jan 30, 2025
264ad35
add EFFIC
KedoKudo Jan 30, 2025
0e16330
add DELTE
KedoKudo Jan 30, 2025
2ed8a1f
add DrcapParameters
KedoKudo Jan 30, 2025
6dec7b9
add NONUN
KedoKudo Jan 30, 2025
c0333cb
remove special character
KedoKudo Jan 30, 2025
4deb0cd
Merge pull request #27 from lanl/sammy_param_misc
KedoKudo Jan 30, 2025
2c4c38e
add paramagnetic card
KedoKudo Jan 30, 2025
35e6a3f
Merge pull request #28 from lanl/sammy_param_paramag
KedoKudo Jan 30, 2025
6970fc2
enable checks from v2.0
KedoKudo Jan 31, 2025
b5d3fc2
add place holder modules for card not used now
KedoKudo Jan 31, 2025
8fe392e
enable pre-commit
KedoKudo Jan 31, 2025
2bda518
adjust exclude pattern
KedoKudo Jan 31, 2025
ab30e90
Merge pull request #32 from lanl/repo_config_adjust_3rd_attemp
KedoKudo Jan 31, 2025
b2a524b
safe guard not implemented cards
KedoKudo Feb 3, 2025
f09d580
safe guard resolution card with not implemented errors
KedoKudo Feb 3, 2025
b5632ee
safe guard det efficiency card with not implemented error
KedoKudo Feb 3, 2025
f811997
start with Burst param
KedoKudo Feb 7, 2025
9290971
add CHANN param
KedoKudo Feb 7, 2025
ee71936
deal with edge cases
KedoKudo Feb 7, 2025
2ab0757
update top level import
KedoKudo Feb 7, 2025
7f360fa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 7, 2025
05ba314
Merge pull request #34 from lanl/sammy_param_user
KedoKudo Feb 7, 2025
c8d2177
add placeholder for the last card
KedoKudo Feb 7, 2025
81d09d7
Merge pull request #35 from lanl/sammy_param_last_placeholder
KedoKudo Feb 7, 2025
2da5efa
add to_string method for top level
KedoKudo Feb 10, 2025
3d218d5
add from string and aux func to top param class
KedoKudo Feb 12, 2025
cb7f20a
fix unit basic unit tests
KedoKudo Feb 12, 2025
31a2fdb
fix broadening card str format issue
KedoKudo Feb 12, 2025
df3fcfb
fixing logic errors in parsing cards
KedoKudo Feb 13, 2025
a4ce75b
radius card has serious issue, need special attention, disable for now
KedoKudo Feb 13, 2025
a266b93
Fix radius card bug
KedoKudo Feb 17, 2025
8626668
remove debug print and add usage example notebook
KedoKudo Feb 17, 2025
47b7258
Merge pull request #37 from lanl/sammy_parfile
along4 Feb 18, 2025
f2e4015
adding ex012 example in notebook format.
alexmlongLANL Feb 18, 2025
907d17d
fixed bug with reading in isotope header for card 10 in the parfile
alexmlongLANL Feb 18, 2025
a01df6b
added some print statements for errors from_string that prints the ac…
alexmlongLANL Feb 18, 2025
8fe77d5
cut out print statements I added into wrong error message.
alexmlongLANL Feb 19, 2025
3f3fd8c
added repo map (not complete)
alexmlongLANL Feb 19, 2025
be1d4f8
adding notebooks.
alexmlongLANL Feb 19, 2025
b060098
deleted notebook
alexmlongLANL Feb 19, 2025
2fb392d
made fudge card optional
alexmlongLANL Feb 19, 2025
7cca3dd
updated repo.map
alexmlongLANL Feb 19, 2025
21fc928
got rid off le=1.0 for abundances in Isotope class.
alexmlongLANL Feb 19, 2025
124fb1d
modified isotope.py to not use extended format and git rid of validat…
alexmlongLANL Feb 19, 2025
472889e
added a fudge factor line
alexmlongLANL Feb 19, 2025
1b9d628
modified print_parameters function.
alexmlongLANL Feb 19, 2025
f0c01b1
modified notebook ex012a.ipynb
alexmlongLANL Feb 20, 2025
c67acab
modified notebook
alexmlongLANL Feb 21, 2025
e4fa46c
adding logger for debugging issues
alexmlongLANL Feb 21, 2025
359ab09
adding os and logger imports to parfile.py
alexmlongLANL Feb 21, 2025
d80ef6b
moved _log_and_raise_error() to logger.py
alexmlongLANL Feb 21, 2025
260c4e3
implemented logging in parfile.py for most functions.
alexmlongLANL Feb 21, 2025
dc780be
adding more logging functionality.
alexmlongLANL Feb 21, 2025
b0be537
added class and function finder.
alexmlongLANL Feb 21, 2025
d8f0420
reorged radius.py
alexmlongLANL Feb 21, 2025
32cd3c4
got rid of logger functionality to find class and function being called
alexmlongLANL Feb 21, 2025
3d8d65a
got rid of get_current_class_and_function()
alexmlongLANL Feb 22, 2025
51d2df7
using where_am_i strings for debugging
alexmlongLANL Feb 22, 2025
f505fd6
idk!
alexmlongLANL Feb 22, 2025
eba8fd9
debugging default card reading
alexmlongLANL Feb 22, 2025
e4e7ea4
fixed bug to allow RadiusCard to handle multiple RadiusParameters ent…
alexmlongLANL Feb 22, 2025
7860595
deleted example.
alexmlongLANL Feb 22, 2025
d528bc1
added attribustes in doc string of ResonanceEntry
alexmlongLANL Feb 22, 2025
d128137
finally fixed bugs in radius with printing to file!
alexmlongLANL Feb 22, 2025
e71c678
expanded print function for parameters
alexmlongLANL Feb 22, 2025
f305335
added notes on parameter libraries.
alexmlongLANL Feb 22, 2025
842af1f
updated debug to info for logging
alexmlongLANL Feb 22, 2025
b7b6bf4
added loggign
alexmlongLANL Feb 22, 2025
4294188
got rid of RadiusParametersContainer class.
alexmlongLANL Feb 22, 2025
40068a6
adding more detials to parfile_notes.md
alexmlongLANL Feb 22, 2025
c25dc03
updated notebook for example 12.
alexmlongLANL Feb 22, 2025
75f9c51
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 22, 2025
c4d7cb5
got rid of testing abundance validation, since this is no longer true…
alexmlongLANL Feb 22, 2025
b0d97d8
Fixed bug in IsotopeCard.is_header_line(). Can now identify both "ISO…
alexmlongLANL Feb 22, 2025
2599a4f
Merge branch '39-v20-examples' of github.com:lanl/PLEIADES into 39-v2…
alexmlongLANL Feb 22, 2025
1528139
adjusted functions test_radius.py for new list object for RadiusCard.
alexmlongLANL Feb 22, 2025
9cd9253
adjusted test_full_roundtrip to handle list of radiusParameters
alexmlongLANL Feb 22, 2025
fa9bd68
fixed bug in reading in parFile strings.
alexmlongLANL Feb 22, 2025
aeecdb8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 22, 2025
3b589a6
using unused variables in RadiusCardKeyword class to make overlord "p…
alexmlongLANL Feb 22, 2025
b48eed1
more making overlord happy
alexmlongLANL Feb 22, 2025
607a4b4
Merge pull request #40 from lanl/39-v20-examples
along4 Feb 22, 2025
aa3116b
moved helper.py to core/
alexmlongLANL Feb 28, 2025
201250e
adding nuclear params as base class
alexmlongLANL Feb 28, 2025
95afa4b
added additional validator for spin groups in RadiusParameters
alexmlongLANL Feb 28, 2025
41de42a
moved helper to core, so I needed to change import paths.
alexmlongLANL Feb 28, 2025
9814a24
I think I broke isotope.py... for now.
alexmlongLANL Feb 28, 2025
c977425
Starting to add to physics params
alexmlongLANL Feb 28, 2025
24a345e
moved helper.py to utils/
alexmlongLANL Feb 28, 2025
eb57418
added EnergyParameters, NormalizationParameters, and UserResolutionPa…
alexmlongLANL Mar 1, 2025
1effc31
updated helper import since moving.
alexmlongLANL Mar 1, 2025
6116502
moved fit_params.py to src/pleiades/sammy
alexmlongLANL Mar 1, 2025
f7c4ab4
added isotope name to IsotopeParameters and created nuclearParameters…
alexmlongLANL Mar 1, 2025
a034f08
created PhysicsParameters
alexmlongLANL Mar 1, 2025
698c67f
made class of AlphanumericOptions. To be used for determining steps i…
alexmlongLANL Mar 1, 2025
4cece50
moved notes to alphanumerics folder.
alexmlongLANL Mar 2, 2025
cab10f7
created class to determine how to treat spin group information and ot…
alexmlongLANL Mar 2, 2025
83c1560
Adding more detials to notes.
alexmlongLANL Mar 2, 2025
c69a501
created class pcm_out.py to define the method of output for the param…
alexmlongLANL Mar 2, 2025
cd91734
create class pcm_in.py to define the prior parameter covariance
alexmlongLANL Mar 2, 2025
16167a7
Added class to define which approximation to the R-matrix is to be us…
alexmlongLANL Mar 2, 2025
327a845
fixed bug in rm.py to allow for setting non-default options to true a…
alexmlongLANL Mar 2, 2025
13e8f3d
deleting more options from AlphanumericOptions class as I migrate them.
alexmlongLANL Mar 2, 2025
980bea6
Added broad.py to determine if broadening is wanted in the sammy fit.
alexmlongLANL Mar 2, 2025
c1b8012
added data class to define the format for the experimental
alexmlongLANL Mar 2, 2025
dff86e5
updated notes on alphanumeric commands
alexmlongLANL Mar 2, 2025
09e9ffc
updated fit_params.py with alphanumerics import
alexmlongLANL Mar 2, 2025
c8db8f5
updating alphanumeric notes
alexmlongLANL Mar 2, 2025
366a803
added multiple scattering class to define how the multiple scattering…
alexmlongLANL Mar 2, 2025
bb6daaa
updating notes on alphanumeric commands
along4 Mar 2, 2025
3573b16
finally got logic to enforce exclusivity. Starting with data.
along4 Mar 2, 2025
8027564
updated broad.py with new exclusivity logic.
along4 Mar 2, 2025
a9f5457
updated alphanumeric notes
along4 Mar 2, 2025
178cb64
updated dcm.py and unit tests with new mutually exclusive logic.
along4 Mar 2, 2025
8531e91
updated msc and unit test.
along4 Mar 2, 2025
4e3075f
updated params and unit tests with new logic for mutually exclusive g…
along4 Mar 2, 2025
17291d6
small edits for readability
along4 Mar 2, 2025
5b9791b
updated pcm_in class
along4 Mar 2, 2025
9af1e93
updated pcm_out and its unit tests.
along4 Mar 2, 2025
7151118
updated rm
along4 Mar 2, 2025
507aa3d
making coding style in classes and tests more consistent.
along4 Mar 2, 2025
57d6aba
fixing casing issue with tests.
along4 Mar 2, 2025
a6eb2c4
cleaning up code
along4 Mar 2, 2025
a3e1305
code clean up!
along4 Mar 2, 2025
71ab47b
final code clean up
along4 Mar 2, 2025
d4a3950
adding lpt option class
alexmlongLANL Mar 3, 2025
5ccf561
created unit tests for lpt option class.
along4 Mar 3, 2025
c99ee17
created bayes option class and unit tests.
along4 Mar 3, 2025
e3e2007
updated alphanumeric notes
along4 Mar 3, 2025
87b57c7
deleteted, since it was refactored.
alexmlongLANL Mar 8, 2025
759cd1f
adding general fit option class.
alexmlongLANL Mar 8, 2025
f83656f
added some comments
alexmlongLANL Mar 8, 2025
b808325
trying to figure out how to implement general fit options into the fi…
alexmlongLANL Mar 8, 2025
c083c79
making fit options tests
alexmlongLANL Mar 8, 2025
89d3ac9
updating fit_options and unit tests
along4 Mar 9, 2025
ac297e3
took out dataTypeOptions
along4 Mar 9, 2025
1684706
adding comments and example usage.
along4 Mar 9, 2025
4d4f2b9
adding data option file
along4 Mar 9, 2025
8a21e70
updated data options.
along4 Mar 9, 2025
634a124
me make code pretty
along4 Mar 9, 2025
0541155
moved dataType option to option.py in data dir
along4 Mar 9, 2025
f562185
adding pint capabilities to data/options.py
along4 Mar 9, 2025
81357ad
reorging fit_params.py
along4 Mar 9, 2025
d780ccc
adding a unit class in pleiades utils.
along4 Mar 9, 2025
ce1c8d6
got rid of converting unit functions.
along4 Mar 9, 2025
2050df8
add unit tests for dataParameters in test_options.py
along4 Mar 9, 2025
e06b0b0
refactor unit options and add unit tests for energy and cross-section…
along4 Mar 9, 2025
2169757
add fit options model and enumerations for SAMMY configuration
along4 Mar 9, 2025
8ec9f9f
add FitConfig and FitOptions models for SAMMY configuration
along4 Mar 9, 2025
f760a45
remove obsolete FitOptions and physics parameters tests
along4 Mar 9, 2025
6116d8a
renamed nuclear and experimental libraries
along4 Mar 9, 2025
ff02eb6
update import paths for nuclear and experimental parameters in fittin…
along4 Mar 9, 2025
49fb8c2
update import statement for IsotopeParameters to reflect new module s…
along4 Mar 9, 2025
3510488
add unit tests for FitOptions and FitConfig classes
along4 Mar 9, 2025
2971510
renamed data to nuclear
along4 Mar 9, 2025
375cc58
more renaming of data to nuclear
along4 Mar 9, 2025
9564783
renaming to parameters in nuclear dir
along4 Mar 9, 2025
b08df4a
renaming to manager in nuclear dir
along4 Mar 9, 2025
2698e14
refactor import path for nuclearParameters in config.py
along4 Mar 9, 2025
3742136
refactor import path for IsotopeParameters in isotope.py
along4 Mar 9, 2025
177c954
refactor import paths for NuclearDataManager and nuclearParameters
along4 Mar 9, 2025
512d303
moved models to nuclear directory
along4 Mar 9, 2025
4734443
refactor import path for Isotope in transmission.py
along4 Mar 9, 2025
d155b3c
refactor import paths for NuclearDataManager in manager.py
along4 Mar 9, 2025
c179c2a
moved unit tests for NuclearDataManager and nuclear data models
along4 Mar 9, 2025
d4af8f0
refactor import path for Mass and UnitType in test_constants.py
along4 Mar 9, 2025
52499c0
refactor import path for models in test_transmissions.py
along4 Mar 9, 2025
72d9265
add example usage for RadiusParameters, ResonanceEntry, IsotopeParame…
along4 Mar 9, 2025
e5d043e
add example usage for FitConfig in config.py
along4 Mar 9, 2025
2606e59
refactor get_isotope_info to accept string input and enhance isotope …
along4 Mar 9, 2025
cc51305
refactor IsotopeParameters to use NuclearDataManager and make fields …
along4 Mar 9, 2025
3ed187d
add unit tests for RadiusParameters, ResonanceEntry, IsotopeParameter…
along4 Mar 9, 2025
8b5c262
refactor NuclearDataManager to improve isotope data handling and add …
alexmlongLANL Mar 9, 2025
e942b97
refactor IsotopeInfo to rename atomic_mass to mass_data for clarity
alexmlongLANL Mar 9, 2025
2c6e5f6
adding resonance table
along4 Mar 9, 2025
4d31161
refactor NuclearDataManager to streamline abundance and spin setting,…
alexmlongLANL Mar 9, 2025
7f7f0bf
refactor IsotopeInfo to make atomic_number and mass_data optional for…
alexmlongLANL Mar 9, 2025
2050253
refactor IsotopeInfo to add material_number field for enhanced isotop…
alexmlongLANL Mar 9, 2025
4ea8d31
refactor NuclearDataManager to update isotope parameter type and set …
alexmlongLANL Mar 9, 2025
c1253bc
refactor IsotopeInfo to remove unused classes and methods for cleaner…
alexmlongLANL Mar 9, 2025
42e27a1
refactor NuclearDataManager to remove unused CrossSectionPoint and Is…
along4 Mar 10, 2025
a5b4868
refactor IsotopeParameters to replace isotope_name with IsotopeInfo f…
along4 Mar 10, 2025
4fcef0a
moved experimental.py to experimental/parameters.py
alexmlongLANL Mar 19, 2025
3f061dc
added fp05 user resolution function.
alexmlongLANL Mar 19, 2025
0a79f1f
refactor import paths for PhysicsParameters to align with new directo…
alexmlongLANL Mar 19, 2025
2e04313
add working directory structure documentation
alexmlongLANL Mar 19, 2025
bd05eaf
Merge pull request #44 from lanl/43-refactoring-to-core-and-fileio
along4 Mar 20, 2025
b266592
update working directory structure documentation with examples and ne…
alexmlongLANL Mar 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add boradening paramter card
KedoKudo committed Jan 17, 2025
commit 8911e3fc34e02cb3b68fbfb1668da090af216df4
2 changes: 2 additions & 0 deletions src/pleiades/sammy/parameters/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from pleiades.sammy.parameters.broadening import BroadeningParameterCard # noqa: F401
from pleiades.sammy.parameters.external_r import ExternalREntry # noqa: F401
from pleiades.sammy.parameters.resonance import ResonanceEntry # noqa: F401
14 changes: 7 additions & 7 deletions src/pleiades/sammy/parameters/broadening.py
Original file line number Diff line number Diff line change
@@ -194,20 +194,20 @@ def to_lines(self) -> List[str]:

# Format main parameter line
main_parts = [
format_float(self.crfn, width=10),
format_float(self.temp, width=10),
format_float(self.thick, width=10),
format_float(self.deltal, width=10),
format_float(self.deltag, width=10),
format_float(self.deltae, width=10),
format_float(self.crfn, width=9),
format_float(self.temp, width=9),
format_float(self.thick, width=9),
format_float(self.deltal, width=9),
format_float(self.deltag, width=9),
format_float(self.deltae, width=9),
format_vary(self.flag_crfn),
format_vary(self.flag_temp),
format_vary(self.flag_thick),
format_vary(self.flag_deltal),
format_vary(self.flag_deltag),
format_vary(self.flag_deltae),
]
lines.append("".join(main_parts))
lines.append(" ".join(main_parts))

# Add uncertainties line if any uncertainties are present
if any(getattr(self, f"d_{param}") is not None for param in ["crfn", "temp", "thick", "deltal", "deltag", "deltae"]):
17 changes: 15 additions & 2 deletions src/pleiades/sammy/parameters/helper.py
Original file line number Diff line number Diff line change
@@ -36,8 +36,21 @@ def format_float(value: Optional[float], width: int = 11) -> str:
"""Helper to format float values in fixed width with proper spacing"""
if value is None:
return " " * width
# Format with proper scientific notation and alignment
return f"{value:<{width}.4E}"

# Subtract 5 characters for "E+xx" (scientific notation exponent)
# The rest is for the significant digits (1 before the dot and decimals)
max_decimals = max(0, width - 6) # At least room for "0.E+00"

# Create a format string with dynamic precision
format_str = f"{{:.{max_decimals}E}}"
formatted = format_str.format(value)

# Ensure the string fits the width
if len(formatted) > width:
raise ValueError(f"Cannot format value {value} to fit in {width} characters.")

# Align to the left if required
return f"{formatted:<{width}}"


def format_vary(value: VaryFlag) -> str:
37 changes: 37 additions & 0 deletions src/pleiades/sammy/parfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
"""Top level parameter file handler for SAMMY."""

from typing import Optional

from pydantic import BaseModel, Field

from pleiades.sammy.parameters import (
BroadeningParameterCard,
ExternalREntry,
ResonanceEntry,
)


class SammyParameterFile(BaseModel):
"""Top level parameter file for SAMMY."""

resonance: ResonanceEntry = Field(description="Resonance parameters")
fudge: float = Field(0.1, description="Fudge factor", ge=0.0, le=1.0)
# Add additional optional cards
external_r: Optional[ExternalREntry] = Field(None, description="External R matrix")
broadening: Optional[BroadeningParameterCard] = Field(None, description="Broadening parameters")

@classmethod
def from_file(cls, file_path):
"""Load a SAMMY parameter file from disk."""
with open(file_path, "r") as f:
lines = f.readlines()

# Parse resonance card
resonance = ResonanceEntry.from_str(lines[0])

return cls(resonance=resonance)


if __name__ == "__main__":
print("TODO: usage example for SAMMY parameter file handling")
163 changes: 163 additions & 0 deletions tests/unit/pleiades/sammy/parameters/test_broadening.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/usr/bin/env python
"""Unit tests for card 04::broadening parameters."""

import pytest

from pleiades.sammy.parameters.broadening import BroadeningParameterCard, BroadeningParameters
from pleiades.sammy.parameters.helper import VaryFlag

# Test data with proper 10-char width formatting
MAIN_ONLY_LINE = "1.234E+00 2.980E+02 1.500E-01 2.500E-02 1.000E+00 5.000E-01 1 0 1 0 1 0"

WITH_UNC_LINES = [
"1.234E+00 2.980E+02 1.500E-01 2.500E-02 1.000E+00 5.000E-01 1 0 1 0 1 0",
"1.000E-02 1.000E+00 1.000E-03 1.000E-03 1.000E-02 1.000E-02",
]

FULL_LINES = [
"1.234E+00 2.980E+02 1.500E-01 2.500E-02 1.000E+00 5.000E-01 1 0 1 0 1 0",
"1.000E-02 1.000E+00 1.000E-03 1.000E-03 1.000E-02 1.000E-02",
"1.000E-01 2.000E-02 1 1",
"5.000E-03 1.000E-03",
]

COMPLETE_CARD = [
"BROADening parameters may be varied",
"1.234E+00 2.980E+02 1.500E-01 2.500E-02 1.000E+00 5.000E-01 1 0 1 0 1 0",
"1.000E-02 1.000E+00 1.000E-03 1.000E-03 1.000E-02 1.000E-02",
"1.000E-01 2.000E-02 1 1",
"5.000E-03 1.000E-03",
"",
]


def test_main_parameters_parsing():
"""Test parsing of main parameters only."""
params = BroadeningParameters.from_lines([MAIN_ONLY_LINE])

# Check values
assert params.crfn == pytest.approx(1.234)
assert params.temp == pytest.approx(298.0)
assert params.thick == pytest.approx(0.15)
assert params.deltal == pytest.approx(0.025)
assert params.deltag == pytest.approx(1.0)
assert params.deltae == pytest.approx(0.5)

# Check flags
assert params.flag_crfn == VaryFlag.YES
assert params.flag_temp == VaryFlag.NO
assert params.flag_thick == VaryFlag.YES
assert params.flag_deltal == VaryFlag.NO
assert params.flag_deltag == VaryFlag.YES
assert params.flag_deltae == VaryFlag.NO

# Check optional fields are None
assert params.deltc1 is None
assert params.deltc2 is None
assert params.d_crfn is None
assert params.d_temp is None


def test_parameters_with_uncertainties():
"""Test parsing of parameters with uncertainties."""
params = BroadeningParameters.from_lines(WITH_UNC_LINES)

# Check main values
assert params.crfn == pytest.approx(1.234)
assert params.temp == pytest.approx(298.0)

# Check uncertainties
assert params.d_crfn == pytest.approx(0.01)
assert params.d_temp == pytest.approx(1.0)
assert params.d_thick == pytest.approx(0.001)
assert params.d_deltal == pytest.approx(0.001)
assert params.d_deltag == pytest.approx(0.01)
assert params.d_deltae == pytest.approx(0.01)


def test_full_parameters():
"""Test parsing of full parameter set including Gaussian parameters."""
params = BroadeningParameters.from_lines(FULL_LINES)

# Check Gaussian parameters
assert params.deltc1 == pytest.approx(0.1)
assert params.deltc2 == pytest.approx(0.02)
assert params.d_deltc1 == pytest.approx(0.005)
assert params.d_deltc2 == pytest.approx(0.001)
assert params.flag_deltc1 == VaryFlag.YES
assert params.flag_deltc2 == VaryFlag.YES


def test_format_compliance():
"""Test that output lines comply with fixed-width format."""
params = BroadeningParameters.from_lines(FULL_LINES)
output_lines = params.to_lines()

print(output_lines)

# Check first line field widths
first_line = output_lines[0]
assert len(first_line[:10].rstrip()) == 9 # 9 chars + 1 space
assert len(first_line[10:20].rstrip()) == 9
assert len(first_line[20:30].rstrip()) == 9
assert len(first_line[30:40].rstrip()) == 9
assert len(first_line[40:50].rstrip()) == 9
assert len(first_line[50:60].rstrip()) == 9


def test_complete_card():
"""Test parsing and formatting of complete card including header."""
card = BroadeningParameterCard.from_lines(COMPLETE_CARD)
output_lines = card.to_lines()

# Check header
assert output_lines[0].startswith("BROAD")

# Check number of lines
assert len(output_lines) == 6 # Header + 4 data lines + blank

# Check last line is blank
assert output_lines[-1].strip() == ""


def test_invalid_header():
"""Test error handling for invalid header."""
bad_lines = ["WRONG header", MAIN_ONLY_LINE]
with pytest.raises(ValueError, match="Invalid header"):
BroadeningParameterCard.from_lines(bad_lines)


def test_missing_gaussian_parameter():
"""Test error handling for incomplete Gaussian parameters."""
bad_lines = [
MAIN_ONLY_LINE,
"1.000E-02 1.000E+00 1.000E-03 1.000E-03 1.000E-02 1.000E-02",
"1.000E-01 1", # Missing DELTC2
]
with pytest.raises(ValueError, match="Both DELTC1 and DELTC2 must be present"):
BroadeningParameters.from_lines(bad_lines)


def test_empty_input():
"""Test error handling for empty input."""
with pytest.raises(ValueError, match="No valid parameter line provided"):
BroadeningParameters.from_lines([])


def test_roundtrip():
"""Test that parsing and then formatting produces identical output."""
card = BroadeningParameterCard.from_lines(COMPLETE_CARD)
output_lines = card.to_lines()

# Parse the output again
reparsed_card = BroadeningParameterCard.from_lines(output_lines)

# Compare all attributes
assert card.parameters.crfn == reparsed_card.parameters.crfn
assert card.parameters.temp == reparsed_card.parameters.temp
assert card.parameters.deltc1 == reparsed_card.parameters.deltc1
assert card.parameters.flag_crfn == reparsed_card.parameters.flag_crfn


if __name__ == "__main__":
pytest.main(["-v", __file__])