Skip to content
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

Add application to import model parameters from simtel configuration file #824

Merged

Conversation

GernotMaier
Copy link
Contributor

@GernotMaier GernotMaier commented Mar 5, 2024

This PR

  • adds application to extract model parameter values from sim_telarray , validate them using schemas, and write them as json files which can then be submitted to the mongo database
  • improves file and data validation routines (not clear if/why the existing code worked...).

The full model parameters used by sim_telarray can be exported using e.g.

./sim_telarray/bin/sim_telarray -c sim_telarray/cfg/CTA/CTA-PROD6-LaPalma.cfg -C limits=no-internal -C initlist=no-internal -C list=no-internal -C typelist=no-internal -C maximum_telescopes=30 -DNSB_AUTOSCALE -DNECTARCAM -DHYPER_LAYOUT -DNUM_TELESCOPES=30 /dev/null 2>|/dev/null | grep '(@cfg)'  >| all_telescope_config_la_palma.cfg

./sim_telarray/bin/sim_telarray -c sim_telarray/cfg/CTA/CTA-PROD6-Paranal.cfg -C limits=no-internal -C initlist=no-internal -C list=no-internal -C typelist=no-internal -C maximum_telescopes=87 -DNSB_AUTOSCALE -DNECTARCAM -DHYPER_LAYOUT -DNUM_TELESCOPES=87 /dev/null 2>|/dev/null | grep '(@cfg)'  >| all_telescope_config_paranal.cfg

There is an example for testing in tests/resources/simtel_config_test_la_palma.cfg and two integration tests are available. The two applications convert_all_model_parameter_from_simtel.py and convert_model_parameter_from_simtel.py are quite rich in printout - this is needed during the development phase to make sure that there is no incompatibility between schemas and sim_telarray.

For the data validation:

  • data files with single values entries (e.g. in json or yml format) where not validated correctly. We have checked the structure of the dicts (i.e., to all field exists), but not the actual values (e.g., range, units). Also no unit conversion to the 'preferred' units was implemented.

Fixed this in the process of this pull request and improved the tests significantly.

  • the application validate_file_using_schema was very confusing and did not always work as expected. Cleaned this up to have now clearly separated on how the validation works depending on the data type (metadata, schema, data). Adjusted and renamed the integration tests accordingly.

There is no need to review any schema files added or modified by this PR. This has been or will be review as part of the model parameter repository.

@GernotMaier GernotMaier self-assigned this Mar 5, 2024
Base automatically changed from unit-vs-units to new-simulation-model March 6, 2024 14:05
@GernotMaier GernotMaier changed the base branch from new-simulation-model to dev-simulation-model-elements-naming March 7, 2024 09:13
@GernotMaier GernotMaier marked this pull request as ready for review March 19, 2024 15:07
Copy link
Collaborator

@tobiaskleiner tobiaskleiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I am only having some minor comments.

or len(simtel_config_reader.parameter_dict) == 0
):
_parameters_not_in_simtel.append(_parameter)
logger.error("Parameter not found in sim_telarray configuration file.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe add a reminder to raise an error here in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am actually more included to 'downgrade this to a logger.info statement - it is not really an error, as the sim_telarray configuration includes also parameters we will never ever use (as they are either for outdated instruments, or for very special use cases). So this is expected, and I change it to an info.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey this is good then.

f"Data column '{column_name}' not found in reference column definition"
)
raise exc
except TypeError:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure how we can get this exception. Should we not also raise something here?

simtools/schemas/data.metaschema.yml Show resolved Hide resolved
Returns
-------
object, int
Values extracted from column. Of object is a list of array, return length of array.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If

simtools/simtel/simtel_config_reader.py Show resolved Hide resolved
simtools/simtel/simtel_config_reader.py Show resolved Hide resolved
Copy link
Contributor Author

@GernotMaier GernotMaier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tobiaskleiner for the review!

I tried to address your points, see below (and new commits). Let me know if this looks reasonable.

or len(simtel_config_reader.parameter_dict) == 0
):
_parameters_not_in_simtel.append(_parameter)
logger.error("Parameter not found in sim_telarray configuration 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.

I am actually more included to 'downgrade this to a logger.info statement - it is not really an error, as the sim_telarray configuration includes also parameters we will never ever use (as they are either for outdated instruments, or for very special use cases). So this is expected, and I change it to an info.

simtools/applications/validate_file_using_schema.py Outdated Show resolved Hide resolved
simtools/schemas/data.metaschema.yml Show resolved Hide resolved
@tobiaskleiner
Copy link
Collaborator

Thanks @GernotMaier for adressing the comments. It's ready for merging now.

@GernotMaier GernotMaier merged commit 1a35021 into dev-simulation-model-elements-naming Mar 20, 2024
13 checks passed
@GernotMaier GernotMaier deleted the sim_telarray-model-import branch March 20, 2024 16:49
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.

None yet

2 participants