more helpful error message for dose_coefficients (#3534)

This commit is contained in:
Jonathan Shimwell 2025-08-14 20:26:27 +02:00 committed by GitHub
parent f8fa751da0
commit 14d51e0eba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View file

@ -82,7 +82,12 @@ def dose_coefficients(particle, geometry='AP', data_source='icrp116'):
cv.check_value('data_source', data_source, {'icrp74', 'icrp116'})
if (data_source, particle) not in _FILES:
raise ValueError(f"{particle} has no dose data in data source {data_source}.")
available_particles = sorted({p for (ds, p) in _FILES if ds == data_source})
msg = (
f"'{particle}' has no dose data in data source {data_source}. "
f"Available particles for {data_source} are: {available_particles}"
)
raise ValueError(msg)
elif (data_source, particle) not in _DOSE_TABLES:
_load_dose_icrp(data_source, particle)

View file

@ -41,3 +41,23 @@ def test_dose_coefficients():
dose_coefficients('neutron', 'ZZ')
with raises(ValueError):
dose_coefficients('neutron', data_source='icrp7000')
with raises(ValueError) as excinfo:
dose_coefficients("photons", data_source="icrp116")
expected_particles = [
"electron",
"helium",
"mu+",
"mu-",
"neutron",
"photon",
"photon kerma",
"pi+",
"pi-",
"positron",
"proton",
]
expected_msg = (
"'photons' has no dose data in data source icrp116. "
f"Available particles for icrp116 are: {expected_particles}"
)
assert str(excinfo.value) == expected_msg