Skip to content

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

gschwefer
Copy link
Contributor

Hi everyone,

I finally got around to clean up the ImPACT code a bit more.

This PR has 3 major changes:

  • The paths to the input templates are now TelescopeParameters. I also changed the required structure of the templates, they now need to contain a new key tel_type which contains the telescope description as a string to check if they are valid for the telescope they are being used for. This will require a little fix to all currently existing templates, but it is an easy and quick one.
  • The pedestal and spe width parameters are now also TelescopeParameters. For the pedestal_width, I also included the option to read them from the monitoring. In case no values are specified, they fall back to a hardcoded value in a global dict.
  • Finally, for the tests, I removed the need for the dummy_reconstructor option/variable

I look forward to your comments and to discussion on the implementation of these things.

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))
Copy link
Contributor

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.

Copy link
Contributor Author

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"
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link

Failed

  • 30.32% Duplicated Lines (%) on New Code (is greater than 3.00%)
  • 76.20% Coverage on New Code (is less than 80.00%)

Analysis Details

7 Issues

  • Bug 0 Bugs
  • Vulnerability 0 Vulnerabilities
  • Code Smell 7 Code Smells

Coverage and Duplications

  • Coverage 76.20% Coverage (94.10% Estimated after merge)
  • Duplications 30.32% Duplicated Code (0.90% Estimated after merge)

Project ID: cta-observatory_ctapipe_AY52EYhuvuGcMFidNyUs

View in SonarQube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants