-
Notifications
You must be signed in to change notification settings - Fork 1
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
Improve and simplify reading and writing of tools on the example of print_array_elements #683
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #683 +/- ##
==========================================
- Coverage 81.93% 81.84% -0.09%
==========================================
Files 40 41 +1
Lines 6128 6203 +75
==========================================
+ Hits 5021 5077 +56
- Misses 1107 1126 +19 ☔ View full report in Codecov by Sentry. |
Improved metadata filling and validation of output
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.
Hi @GernotMaier. Sorry for the delay, this was a relatively long one and it took me some time to understand the code. I provide here a couple of comments and I hope it helps improving the code.
Thank you!
layout.export_telescope_list(crs_name="corsika") | ||
_table = layout.export_telescope_list_table(crs_name="corsika") | ||
_export_file = tmp_test_directory / "test_layout.ecsv" | ||
_table.write(_export_file, format="ascii.ecsv", overwrite=True) |
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.
in order to test whether it was written, I suggest opening the file and checking whether the table is the same as before.
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.
I think this is an integration test we need to do (and I have it on my list to implement).
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.
Still on this PR or in another one?
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 - we need to work on integration tests in our maintenance period (remember that we don't have good tests).
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 considering the comments. I think we are good to go now if the tests pass.
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 minor comments. Did not go through everything very carefully since @VictorBarbosaMartins is actually doing the review.
|
||
if self.data_model_name: | ||
self._logger.debug(f"Schema file from data model name: {self.data_model_name}") | ||
return simtools.constants.SCHEMA_URL + self.data_model_name + ".schema.yml" |
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.
This can be shortened by changing the import to from simtools import constants
or importing as a short name. Also, please use f-string instead of combining strings like that.
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.
I consciously want to "simtools.constants", as modules called constants are quite common. Writing it like this improves readability (as one does not have to scroll up to see which import it is).
What is an advantage of f-strings to "+"?
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, no problem to keep simtools.constants
then, makes sense.
f-strings are significantly faster than adding strings and also for the purpose of consistency since I switched everything to f-string a while back.
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, changed.
BTW, notice that there are some new lines uncovered by tests (codacy complains). |
@VictorBarbosaMartins , @orelgueta - thanks for looking into the code. Will merge after the tests. |
Addresses partly #643 and is a step towards a more unified approach of input / output of tools. This PR deals mostly with unified output.
Functionality is added and tested mostly with the print_array_elements.py application, but partly also to derive_mirror_rnda.py (and minor changes to other applications to allow integration tests to run).
Goal is to first get input/output/metadata/validation working for one simple applications and then propagate this functionality to all other applications.
Conceptually new: introduced simtools/constant.py to put "hardwired" values like the paths to the schema files. Not sure if this is a best solution, the internet says it is acceptable.
Changes:
dump
function. The following lines are need to write a consistently data and metadata:input
andinput_meta
as command line parameters for input data/metadata at least for the three applications mention above (this needs another thought, but I think we are a bit inconsistent with our command line between the application)use_plain_output_path
byuse_simtools_output_path
, reversing the logic from before. Default is write into output path (if not set, the path./simtools-output/
is used) without the additional directories for tools, date, etc. (this will have to be propagated into other applications)collect_data_from_yaml_or_dict
downloads a file to temp disk and returns a dict if the file name is a urlModelDataWriter.dump
withvalidate_schema_file
set used this schema file to validate the output, transform it if necessary to the units listed in the schemafile.