-
Notifications
You must be signed in to change notification settings - Fork 13
Added a method to get detector effeciencies without creating an event #149
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
Added a method to get detector effeciencies without creating an event #149
Conversation
would be nice to have a similar change in the corresponding python helper here: |
Polymorphism is not a thing in python, so it would need some gymnastic which I am not sure how best to take on or defines two functions with different name. Which you believe is best? |
Looks useful to me to have this extra morphology of get_detector_efficiencies in the standard. Implementation looks good to me too. Thanks @MaxTousss |
Agreed this creates headaches. I guess we could do a type-check, but it's going to slow everything down. Having different names might be best. @naegelejd @casperdcl any suggestions? |
Completely missed the re-definition of the function (thought the the aim was to only keep the new version). On top, having a few vectorized helpers would be nice to speed up calculations. |
I just modified the python code to have two function to get eff: one that take detector ids and a new one that take event in input. The python analysis/generator helpers were modified following this change. Note: I did not touch the matlab case. While I can guess how to do it, I can't test it. Funny discovery: the generator helpers create eff. that are larger than 1.0! XD |
Hehe. I think in real scanners efficiencies can have arb. magnitudes because: (i) vendor include / can correct for global scales at multiple places in the recon pipeline, (ii) it depends on which units we use for the image that is being reconstructed (counts per voxel, activity per ml, ...), (iii) LORs that contain edge crystals (in the presence of big gaps between modules) behave very differently compared to LORs connecting center crystals. so depending on your assumed global scales, some effs. can be > 1, some <1. Long story short, the effs. are correction factors that depend on many things which easily introduce global scaling factors. |
I just pushed a Pythonic overload (which also reverts the breaking change caused by renaming); feel free to revert if you prefer.
quack yes it is 🦆🐍 |
ffdfafa
to
6b208c2
Compare
Thanks @casperdcl I guess this makes Python happy, but it will also slow every call down due to the type-check. What about something like this def get_detection_efficiencies_for_bins(...):
bla
def get_detection_efficiencies_for_event(...):
return get_detection_efficiencies_for_detection_bins(something)
# current code with the @typing.overload
# but let get_detection_efficiencies() call one of the above
sure, feel free... we could have "stupid" implementations now (as I did for |
Do you mean the single |
I have no idea. If you say it isn't, I'll believe you. |
|
Wait, since when does python as polymorphism in that form? At the same time as typing hint was introduced?! Woahhh XD |
While 20 ns seems like nothing, it is called O(N^2) where N is the number of detectors. So, it will take a couple of seconds for a whole scanner, but I guess it is marginal compared to everything else in |
It's all smoke and mirrors in my opinion. |
ok. Let's keep @casperdcl 's version then. Can we still think about the vectorised version in this PR? Main reason I ask is to think about the signature:
or something like that? or return a choices, choices... |
Of course, need to fix the run-time error first
|
TBH: I wouldn't worry too much about the runtime right now. I see the current python helpers as proof of concept. To get sth really efficient and "fast" on real world data sets, we need vectorized helper functions and a more efficient implementation of the yardl generated reading functions anyway. @KrisThielemans: since we will most of the time process many events contained in an eventblock, why not having future helpers that that multiple events as input and output numpy / cupy / xp arrays? @MaxTousss: |
@gschramm My bad, when I said "in that form", I meant the For the signature thing, hmmm, my first though is that it should follow the format that |
I completely agree In an ideal scenario (but I don't think that this is currently supported by the way that yardl encodes the data), |
…ious method to det eff for an event to take detectors bins as input; Adapted analysis and generator to use the correct method following these changes
for more information, see https://pre-commit.ci
6b208c2
to
8aca933
Compare
fixed types methinks |
Of course. Ideally we make our helpers to future-proof the user for any changes, but that'll only work as far as it goes.
Not very easy if "events" are structures in numpy, but certainly should aim for that!
good point, as we have PETSIRD/python/petsird/helpers/__init__.py Lines 33 to 36 in ed570d1
I think it is best to stick to the current 2 argument signature. I therefore suggest to merge as-is. ok? |
(with my limited C/Cpp knowledge), I thought if the event structure is fixed (let's say two ints and a float), we can define a custom np dtype a read like:
or sth similar using ctypes if we have a pointer to the start of the eventblock. Then we should be able to access the float, and two int arrays like:
Obviously that only works if the data is not compressed. |
@gschramm when using ctypes, everything can be done. But it's not so easy for yardl to generate all this of course. If it can be done, in my opinion, it is quite unsatisfactory, as it doesn't give you access to any methods defined on the type, but that seems just to be a python/numpy limitation. This would probably be discussed with @naegelejd in the relevant yardl issue.
The data is compressed, so the yardl API will first have to decompress it, or it needs to do it on the fly, via some kind of plug-in. In the mean time, I'll merge this PR! |
Summary
Added a method in the CPP helpers to get efficiency from two detection bins, without creating an event. It is only quality of life, since it make no sense to create an event when we simply want to get all the efficiency coefficients.
Testing performed
Compilation, eye and logic.
Related issues
Checklist before requesting a review
Contribution Notes
This is only basic polymorphism, no need to bother everyone.
Please tick the following: