-
Notifications
You must be signed in to change notification settings - Fork 274
More ImPACT code cleanup #2705
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
base: main
Are you sure you want to change the base?
More ImPACT code cleanup #2705
Conversation
src/ctapipe/reco/impact.py
Outdated
filename, role="ImPACT Time Template file for " + tel_type[t] | ||
for template_path, tel_ids in template_sort_dict.items(): | ||
net_interpolator = TemplateNetworkInterpolator( | ||
template_path, bounds=((-5, 1), (-1.5, 1.5)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really wise to hardcode the bounds of the templates this deep into a function? I think you should at least extract these definitions to some global constants at the top of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes putting them as a global constant is better than this
for id in tel_ids: | ||
if interp_tel_string != str(self.subarray.tel[id]): | ||
raise ValueError( | ||
"You are using templates that are not intended for this telescope type" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems a bit late to check if the template is compatible with the subarray only towards the end of the setup, aren't you able to do this first thing in the function and then setup the needed dictionaries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it doesn't really work the other way around because checking the compatibility of the templates with the telesopes requires initializing the TemplateNetworkInterpolator which is computationally expensive. Therefore, I don't want to check individually for every telescope at the beginning, but first figure out how many unique sets of templates there actually are and only then initialize the TemplateNetworkInterpolators for these few unique templates and check consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? Your dummy template function implies the template is a pickle with the tel type as a dict key, why do you need to setup the interpolator just to check a value in a pickle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, of course I could technically manually explicitly unpickle every file at the beginning and then check for the key in it. But I find my solution better than that because 1) It is faster. I don't need to unpickle and load the (sizeable) templates into memory more often than strictly necessary and 2) it is independent of the way the templates are saved. If that is changed in the future (or FreePACT models are used or whatever) this still works if the structure of the interpolator stays the same. Also, I don't think I really gain anything by checking first and then setting things up. This should fail on effectively the first event of a file, so the time wasted by waiting for the error message is really small compared to the total time it takes to process all events.
Analysis Details7 IssuesCoverage and DuplicationsProject ID: cta-observatory_ctapipe_AY52EYhuvuGcMFidNyUs |
Hi everyone,
I finally got around to clean up the ImPACT code a bit more.
This PR has 3 major changes:
I look forward to your comments and to discussion on the implementation of these things.