-
Notifications
You must be signed in to change notification settings - Fork 10
Adding the KMOD summary outputs #560
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: master
Are you sure you want to change the base?
Conversation
…to kmod_tabsum_import
|
The output .txt table for the Logbook looks like this without Tabulate package |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
fsoubelet
left a comment
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.
Thanks for the PR Mattia, this is going to be useful to have.
I left comments here and there about inconsistencies / code clarity etc. See below.
One thing I'm wondering is: could this be a stand-alone script? And then it could be run on previous folders with kmod measurements from before we had it (and the relevant part just imported and called into kmob_importer.py)?
tests/unit/test_kmod_importer.py
Outdated
| lumi_filename = _get_lumi_filename(betas, ip_a=ips[0], ip_b=ips[1]) | ||
| assert (average_dir / lumi_filename).exists() | ||
|
|
||
|
|
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.
Could we add a little check that the written files are as expected?
JoschD
left a comment
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.
A few comments, but my main point is also, that this should be a standalone script, in case someone only wants the table without importing it anywhere.
When refactoring, also separate the output from the reading/transforming. There should be one function that creates the tables and simply returns them. Then another funtion/outer function that writes them out.
In my opinion the script/main function of the script should also have the following parameters:
- outputdir -> optional, write the files ou (always return the tables)
- average -> true/false, calls the functions to average the data (could also be
boolean | path-to-the-file | averaged-dataframes) - logbook -> optional, specify a logbook (LHC_OMC, LHC_OP, true->LHC_OMC) uses the logbook uploader to create a new logbook entry.
And then you can import the function here and re-use it to create the table automatically on import.
When putting it into another script: consider which parts might benefit from being in their own little function as well, to make the code more readable/self-explainatory.
Co-authored-by: Felix Soubelet <19598248+fsoubelet@users.noreply.github.com>
|
Hey, I’ve implemented most of the suggested changes in this second draft. I moved the script into a standalone module, which is now called by the main kmod_importer. Labels, comments, and variable names have been updated for clarity. The saving of files is now optional: if an output directory is provided, the results are saved; otherwise, the script simply returns the .txt tables for the logbook and the .tfs DataFrames containing all K-mod results. Additionally, if averaged results are provided, the script also includes the average values. I’m still working on implementing the optional creation of the logbook entry, and the writing of some further tests. I look forward to any further feedback or suggestions, thank you! |
|
I was also thinking that the other scripts within kmod_importer operate per beam, whereas this script currently processes both beams at the same time. Should I modify it to generate the tables for each beam individually, consistent with the other scripts? |
JoschD
left a comment
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.
The table creation function is quite hard to read and follow, because there are a lot of branches within that function. You need to split it into it's functional parts and then have a main function, that calls all of that:
- one function to read the data and put it into a df
- one function that takes a df and creates a txt
- one small function for the writing
- probably no function for the logbook, as you can just call the main from the logbook
- depending on the user input you then call the writing and/or the logbook function
- always return the df and txt content
- Unify the output filenames. Why to completely different filenames for files that basically contain the same information? "logbook" is also not needed in the file name, it doesn't matter what the tables are used for.
Co-authored-by: Felix Soubelet <19598248+fsoubelet@users.noreply.github.com>
Co-authored-by: Felix Soubelet <19598248+fsoubelet@users.noreply.github.com>
Co-authored-by: Felix Soubelet <19598248+fsoubelet@users.noreply.github.com>
Co-authored-by: Felix Soubelet <19598248+fsoubelet@users.noreply.github.com>
Co-authored-by: Felix Soubelet <19598248+fsoubelet@users.noreply.github.com>
Co-authored-by: Felix Soubelet <19598248+fsoubelet@users.noreply.github.com>
Co-authored-by: Felix Soubelet <19598248+fsoubelet@users.noreply.github.com>
|
I have further applied your suggestions to the code, now the script is more modular, and divided as:
The saving and the logbook creation are now independent (just no file is attached, the content of the .txt file is passed to create_logbook_entry as "text".) I also change the input parameters, now the code write the files, if required, to the average_dir of the averaged results, not the main output_dir. Also the beam is now an input parameter, first because it seems to me more coherent with the other parts of the kmod_importer, second because I was thinking that, hypothetically, if we are in the CCC, and we import the kmod results for both B1 and B2, it will create each time the tables for both beams, so we would need to coordinate. In this way, each logbook entry/saving is related to the particular beam you're working on. Small updates for the test_kmod_importer. |
|
I have added the optional luminosity imbalance information in the .txt tables generated. |
fsoubelet
left a comment
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.
There were plenty of inconsistencies from the transition to helper functions, see comments below. For most simple ones I've made a suggestion.
Importantly, there is not argument parsing for the main function that would run in script mode. So this would instantly crash in script mode. You need to add a get_params like usually done. The file docstring seems to already be there but I didn't check it yet.
Note: I find it a bit strange in the logic flow that the kmod results have to be parsed from file but the averaged results would already be parsed and provided.
Also, it would be nice to run ruff format on this file.
|
I think one of the main issues, why this looks/is so complicated it, that the main function from the kmod table creator is used in the kmod importer, which makes the input parameters very wonky. IMO the structure becomes much cleaner, if the main function in the table creator does (in separate consecutive functions):
In the kmod importer you only need to call then |
Co-authored-by: Felix Soubelet <19598248+fsoubelet@users.noreply.github.com>
Co-authored-by: Felix Soubelet <19598248+fsoubelet@users.noreply.github.com>
Co-authored-by: Felix Soubelet <19598248+fsoubelet@users.noreply.github.com>
I'll make shortly a new commit to include those changes. |
|
I have updated the code to match the new structure suggested by @JoschD. Now kmod_summary contains just the single functions as:
now both follow the same logic, the values are taken from the same output directory which is the average_output_dir in the kmod_importer. No need to pass directly the dataframes to the function as before.
---> I wonder if it's better to pass the output dir once, and then give the option to include averaged and/or lumi imbalance as a boolean. For the moment you basically pass the same argument twice to the corresponding quantity you want to include.
|
Adding a script to generate .tfs and .txt tables with the summary of the KMOD measurement imported with kmod_importer. It will generate one .tfs and one .txt table for each beam.
The .txt table has been made to be easily copy/pasted in the logbook keeping a readable format.