@@ -33,6 +33,7 @@ def test_get_channel(filename, expected_channel):
3333 assert ch == expected_channel
3434
3535
36+
3637def create_empty_csv_files (directory , base_name , count , channel ):
3738 """
3839 Creates empty CSV files in a specified directory with a specific pattern.
@@ -1724,3 +1725,102 @@ def test_get_peaks(detector_type, nuclide, signal_to_background_ratio):
17241725 for test_energy , expected_energy in zip (test_peaks , nuclide .energy ):
17251726 print (f"Detected peak at { test_energy :.2f} keV, expected at { expected_energy } keV" )
17261727 assert np .isclose (test_energy , expected_energy , rtol = 0.05 )
1728+
1729+
1730+ @pytest .mark .parametrize (
1731+ "peak_kwargs, expected" ,
1732+ [
1733+ (None , {}),
1734+ ({na22 .name : {"start_index" : 123 , "height" : 4.5 },
1735+ co60 .name : {"start_index" : 456 , "height" : 7.8 }},
1736+ {"start_index" : 123 , "height" : 4.5 }),
1737+ ({co60 .name : {"distance" : 99 }}, {}),
1738+ ],
1739+ )
1740+ def test_get_nuclide_peak_kwargs (peak_kwargs , expected ):
1741+ measurement = compass .CheckSourceMeasurement ("test" )
1742+ measurement .check_source = CheckSource (
1743+ nuclide = na22 ,
1744+ activity_date = datetime .datetime (2024 , 1 , 1 ),
1745+ activity = 1.0 ,
1746+ )
1747+
1748+ result = compass ._get_nuclide_peak_kwargs (measurement , peak_kwargs )
1749+
1750+ assert result == expected
1751+
1752+
1753+ @pytest .mark .parametrize (
1754+ "detector_type, nuclide" ,
1755+ [
1756+ ("NaI" , na22 ),
1757+ ("NaI" , co60 ),
1758+ ("NaI" , ba133 ),
1759+ ("NaI" , mn54 ),
1760+ ("HPGe" , na22 ),
1761+ ("HPGe" , co60 ),
1762+ ("HPGe" , ba133 ),
1763+ ("HPGe" , mn54 ),
1764+ ],
1765+ )
1766+ def test_get_peak_fitting_parameters_with_kwargs (detector_type , nuclide ):
1767+ """Test that kwargs properly override default parameters in get_peak_fitting_parameters."""
1768+
1769+ # Create a test histogram (random values)
1770+ hist = np .random .rand (1000 ) * 100
1771+ hist [500 :600 ] = np .random .rand (100 ) * 1000 # Add a peak
1772+
1773+ # Create a CheckSourceMeasurement
1774+ check_source = CheckSource (
1775+ nuclide = nuclide ,
1776+ activity_date = datetime .datetime (2024 , 1 , 1 ),
1777+ activity = 1.0
1778+ )
1779+
1780+ measurement = compass .CheckSourceMeasurement (name = "test_measurement" )
1781+ measurement .check_source = check_source
1782+ measurement .detector_type = detector_type
1783+
1784+ # Test 1: Get default parameters (no kwargs)
1785+ default_params = measurement .get_peak_fitting_parameters (hist )
1786+
1787+ # Check that all expected keys are present
1788+ assert "start_index" in default_params
1789+ assert "prominence" in default_params
1790+ assert "height" in default_params
1791+ assert "width" in default_params
1792+ assert "distance" in default_params
1793+
1794+ # Test 2: Override with custom kwargs
1795+ custom_kwargs = {
1796+ "start_index" : 200 ,
1797+ "prominence" : 50.0 ,
1798+ "height" : 75.0 ,
1799+ "width" : [5 , 100 ],
1800+ "distance" : 50 ,
1801+ }
1802+
1803+ custom_params = measurement .get_peak_fitting_parameters (hist , ** custom_kwargs )
1804+
1805+ # Verify all kwargs were applied
1806+ assert custom_params ["start_index" ] == 200 , "start_index kwarg not applied"
1807+ assert custom_params ["prominence" ] == 50.0 , "prominence kwarg not applied"
1808+ assert custom_params ["height" ] == 75.0 , "height kwarg not applied"
1809+ assert custom_params ["width" ] == [5 , 100 ], "width kwarg not applied"
1810+ assert custom_params ["distance" ] == 50 , "distance kwarg not applied"
1811+
1812+ # Test 3: Partial kwargs override (some default, some custom)
1813+ partial_kwargs = {
1814+ "start_index" : 300 ,
1815+ "height" : 100.0 ,
1816+ }
1817+
1818+ partial_params = measurement .get_peak_fitting_parameters (hist , ** partial_kwargs )
1819+
1820+ # Verify partial overrides work
1821+ assert partial_params ["start_index" ] == 300 , "partial start_index kwarg not applied"
1822+ assert partial_params ["height" ] == 100.0 , "partial height kwarg not applied"
1823+ # Other parameters should remain as defaults
1824+ assert partial_params ["prominence" ] == default_params ["prominence" ], "Other params should not change"
1825+ assert partial_params ["width" ] == default_params ["width" ], "Other params should not change"
1826+ assert partial_params ["distance" ] == default_params ["distance" ], "Other params should not change"
0 commit comments