-
Notifications
You must be signed in to change notification settings - Fork 51
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
Icrp107 database #608
base: master
Are you sure you want to change the base?
Icrp107 database #608
Conversation
@tbaudier This PR in principle does not change the behaviour of the tests, but the results may change a little bit as a more refined database is used. Regarding the json, I tried to push it minimized (11MB), but the formatting bot expanded it (41MB). |
@tbaudier the precommit bot is doing fancy things. I think I have succeeded this time. |
very good idea, thanks @BishopWolf ! @alexis-pereda can you have a look please to check this is ok for you ? |
@dsarrut Everything is working now. I will make a final push with the database schema. |
@alexis-pereda The change in the database makes some test yield a slightly different results, however those should be very close to before. The difference in time it's because the database is bigger, so once it's loaded it should work the same for larger simulations. If some of these presets are not respected, then there is a bug somewhere. A solution could be to separate the icrp107.json into components. An icrp107 folder containing 1252 JSON, one for each radionuclide. This way we don't need to read the entire database. Let me know your thoughts. We can off course optimize it. |
@dsarrut @alexis-pereda I just discovered that icrp107 DO have beta+ spectras. It is just located in the same b-spectra field. therefore you don't even need a separate database for this. Take as example the F18. |
Here it is the database separated into components, in binary format to prevent the issues with git transfer you can read it like isotopePath = Path("./icrp107") / "Lu-177.json"
with open(isotopePath, "rb") as i:
isot = json.loads(json.load(i))
print(isot["name"], isot["emissions"]) |
The comparison of icrp107 vs X. Mougeot for F-18 beta+ spectra: icrp107 mean energy 249.776 keV yield 0.9673 spectra icrp107 (better sampling at lower energies, worse sampling at higher energies) I think, being Mougeot work more recent it shall be the default and we can rely on icrp107 for the missing isotopes. isotopePath = Path("./icrp107") / "F-18.json"
with open(isotopePath, "rb") as i:
isot = json.loads(json.load(i))
print(isot["emissions"]["beta+"])
for line in isot["emissions"]["b-spectra"]:
print(f"| {line[0]*1000:.2f} | {line[1]/1000:.3e} |") |
I looked at it. It is great to have everything and I think this will allow more flexibility the way its done. However, it breaks the Also, after discussing it with other people, we think we should rename the function |
I have made some tests, separating by isotope seems to make everything faster. If you agree, I will push this change, and then we can work from there. Basically, we need a function to calculate the energy bins from the energy slots, or maybe drop the last weight (it's always zero) and consider the energies as bins |
@alexis-pereda So if I understand correctly, I must remove the last zero weight if the spectrum type is "b-spectra". Please confirm, this is a very trivial modification. |
@alexis-pereda Would somethign like this works ? Is it enough? Do you need spectrum_energies in histogram spectrum ? def set_source_icrp107_energy_spectrum(source, rad):
if (
source.particle == "beta-"
or source.particle == "e-"
or source.particle == "beta+"
or source.particle == "e+"
):
rad_spectrum = get_icrp107_spectrum(rad, "b-spectra")
source.energy.type = "spectrum_histogram"
source.energy.spectrum_weights = rad_spectrum.weights[:-1]
source.energy.spectrum_energy_bin_edges= rad_spectrum.energies
else:
rad_spectrum = get_icrp107_spectrum(rad, source.particle)
source.energy.type = "spectrum_discrete"
source.energy.spectrum_weights = rad_spectrum.weights
source.energy.spectrum_energies = rad_spectrum.energies |
If your |
About the trivial "remove the last 0-weight", I tested it with the |
I obtained 4x speed increase in the tests using individual json files compared to a monolithic database. So I have pushed that. It is also easier to debug and maintain. |
The test shall replace this function to use the proper initialization def add_source_energy_spectrum_histogram(sim, phsp, interpolation: str = None):
source = sim.add_source("GenericSource", "beam")
source.attached_to = phsp.name
source.particle = "e-"
source.n = 5e5 / sim.number_of_threads
source.position.type = "point"
source.direction.type = "iso"
spectrum = set_source_icrp107_energy_spectrum(source, "Lu177") # After defining the particle
source.energy.spectrum_histogram_interpolation = interpolation
return source |
I already fixed this and used |
The old test is wrong, it uses gammas with the energy spectra of electrons. Everything else works fine. I will push the latests changes we have discussed. |
Okay, I'll look again with your fix. (and just to extend a bit on why I am surprised at the tests not passing: |
I see the test 010 passing in all systems now. It remains the test 073 and this is the only thing different:
In this case it is indeed a database change issue, not much can be done. The difference is not that mch as expected. I can't explain the slow down as the comparison in both databases yields basically the same data radar "Lu177": {
"energies": [
0.0716418,
0.1129498,
0.1367245,
0.2083662,
0.2496742,
0.3213159
],
"weights": [
0.001726,
0.0620,
0.000470,
0.1038,
0.002012,
0.00216
]
} icrp107
|
Test 046 fails on these:
It really needs a tolerance, the difference is just the data provenance. |
test 046 is no longer failing |
@alexis-pereda I have pushed this change too. |
9f2ac43
to
9a3c5c8
Compare
@alexis-pereda test 73 discovery Lu177 will always fail since the icrp107 library has 4.74% extra gamma yield for Lu177. This IS a database issue, not a test issue. Therefore, either you rerun the test with the new database or we switch back to radar database. I mean set explicitly set_source_energy_spectrum(source, "Lu177", "radar") |
@dsarrut @alexis-pereda the tests |
@alexis-pereda we need a new rebase |
… the test 010 spectrum histogram
c1c4aae
to
19e4824
Compare
I have created an issue in radioactivedacay package to investigate the failing test053 |
@alexis-pereda @dsarrut the package radioactivedecay has been updated with a fix. We must use version 0.6.1 |
It remains this error in MacOS with python 3.12, I have created this issue
Apparently, the setuptools package is not properly installed in this case. Read this thread
|
This PR addresses the issue #590
Basically replace radar database by the ICRP107 database