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 uc 08 derive simulation production configuration parameters #1098

Conversation

tobiaskleiner
Copy link
Collaborator

@tobiaskleiner tobiaskleiner commented Aug 1, 2024

This PR adds the functionality defined in UC8 with the following four applications:

  • simtools-production-calculate-resource-estimates
    -- calculates compute and storage resources --

  • simtools-production-generate-grid
    -- generates a grid of simulation points --

  • simtools-production-generate-simulation-config
    -- generates simulation parameters for a specific grid point --

  • simtools-production-scale-events
    -- metric evaluation and statistical error calculations --

Modules are stored in production_configuration:

  • calculate_statistical_errors_grid_point.py
  • derive_computing_resources.py
  • generate_production_grid.py
  • generate_simulation_config.py
  • interpolation_handler.py

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

1 similar comment

This comment has been minimized.

@GernotMaier
Copy link
Contributor

Would like start the discussions how to best organize the code. At this point most of it is in the applications, but we want to move it into modules.

Suggest to start a module to put those classes in. What would be a good name?

  • simtools.production_tools (don't like tools, seems to cover everything)
  • simtools.production_configuration
  • simtools.simulation_production
  • ...something shorter...?

This module would include all classes currently defined in

  • simtools/applications/derive_resources.py (which will be renamed to simtools/applications/derive_computing_resources.py
  • simtools/applications/generate_grid.py (which will be renamed to simtools/applications/generate_production_grid.py)
  • simtools/applications/generate_simulation_config.py
  • `simtools/utils/calculate_statistical_errors_grid_point.py (maybe we can find a shorter name)

@orelgueta , @tobiaskleiner : please comment.

@orelgueta
Copy link
Contributor

Not much for me to comment. This is the first time I see that those modules are in applications and I definitely agree they should go into simtools instead. In terms of which name to put them under, I would vote for simtools.production_configuration.
However, I would also check if we can integrate these classes with the current modules we have (at least partly).

@tobiaskleiner
Copy link
Collaborator Author

I agree with the simtools.production_configuration suggestion and to move some parts into visualization or in other parts.

This comment has been minimized.

2 similar comments

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

6 similar comments

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@tobiaskleiner tobiaskleiner marked this pull request as ready for review September 19, 2024 15:53

This comment has been minimized.

2 similar comments

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.


# Determine the effective area threshold (50% of max effective area)
max_efficiency = np.max(efficiencies)
threshold_efficiency = 0.1 * max_efficiency
Copy link
Contributor

Choose a reason for hiding this comment

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

The docstring says "exceeds 50%". Do you use actually 10%?

This comment has been minimized.

1 similar comment

This comment has been minimized.

@tobiaskleiner
Copy link
Collaborator Author

@GernotMaier thanks for the review. I went through the comments and adressed most of them. Few more points need discussion/implementation see #1233, #1227, #1219. Will let you know when I have fixed the unit tests for another review.

This comment has been minimized.

1 similar comment

This comment has been minimized.

@tobiaskleiner
Copy link
Collaborator Author

@GernotMaier thanks again for the review of the first part of the PR. Went through your comments and fixed the unit/integration tests. I factored out the event scaling logic and added a file for helper functions in the production configuration folder. In there we could also move the dl2 reading part in a later stage.
Let me know if the changes make sense and if so you could start reviewing the other parts of the PR.

This comment has been minimized.

1 similar comment

This comment has been minimized.

Copy link
Contributor

@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.

A couple of more comments on the production_generate_simulation_config.

I will talk to you directly about a couple of points.

The data level for the simulation (e.g., 'A', 'B', 'C').
science_case (str, required)
The science case for the simulation.
file_path (str, required)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest to change the file_path doc string to

Path to file with MC events at CTAO DL2 data level. Used for statistical uncertainty evaluation.

elevation (float, required)
Elevation angle in degrees.
nsb (float, required)
Night sky background value.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the units for the NSB is "Hz" (but please check)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not 1/(srnscm**2) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

please find it out. I know that in some places we use Hz (which requires the knowledge of the pixel fov)

config.parser.add_argument(
"--data_level", type=str, required=True, help="Data level (e.g., 'A', 'B', 'C')."
)
config.parser.add_argument(
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, added this to the list of discussions.

"--science_case", type=str, required=True, help="Science case for the simulation."
)
config.parser.add_argument(
"--file_path", type=str, required=True, help="Path to the dl2_mc_events_file FITS file."
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment above.

Path to MC event file in DL2 format

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adding some comments here, but the changes are done in the separate part1 PR.
Changed the comment to your suggestion.

"--metrics_file",
required=True,
type=str,
help="Path to YAML file containing metrics and required precision as values (required).",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can remove the (required) from the comment (it is the only parameter with this added, although others are required).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

max_error : float
Maximum relative error.
"""
if "relative_errors" in self.metric_results["error_eff_area"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Trying to understand a case where relative_errors is not in metric_results by error_eff_area is filled. If I understand it correctly, both variables are always filled in calculate_metrics?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No currently this depends on the production_simulation_config_metrics file and what metrics are given there (i.e. which metric computation is required).

)
valid = (simulated_event_counts > 0 * u.ct) & (triggered_event_counts > 0 * u.ct)

uncertainties = np.zeros_like(triggered_event_counts) * u.ct**-0.5
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain the '-0.5'?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good point, this was wrongly implemented and the errors should be dimensionless. Previously when keeping the units the rel error turns out with this dimension.


return efficiencies, relative_errors

def calculate_energy_threshold(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest to replace the hardwired 10% by a variable (which default is 10%)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added

bin_edges = np.concatenate([bin_edges_low, [bin_edges_high[-1]]])
return np.unique(bin_edges)

def compute_histogram(self, event_energies_reco, bin_edges):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest 'compute_triggered_event_histogram' to make the purpose of this function clearer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Parameters
----------
event_energies_reco : array
Array of energies of the observed events.
Copy link
Contributor

Choose a reason for hiding this comment

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

Array of reconstructed energy per event

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

This comment has been minimized.

…UC-08-derive-simulation-production-configuration-parameters

This comment has been minimized.

…masim/simtools into add-UC-08-derive-simulation-production-configuration-parameters

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

…UC-08-derive-simulation-production-configuration-parameters

This comment has been minimized.

…UC-08-derive-simulation-production-configuration-parameters
Copy link

Passed

Analysis Details

0 Issues

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

Coverage and Duplications

  • Coverage 82.20% Coverage (92.80% Estimated after merge)
  • Duplications 0.00% Duplicated Code (0.00% Estimated after merge)

Project ID: gammasim_simtools_AY_ssha9WiFxsX-2oy_w

View in SonarQube

@GernotMaier
Copy link
Contributor

@tobiaskleiner - I am not sure on the status of this pull request and branch. Is this still relevant given all the other updates you have done? Please have a look and remove it if necessary.

@tobiaskleiner tobiaskleiner self-assigned this Feb 20, 2025
@tobiaskleiner
Copy link
Collaborator Author

@GernotMaier the only part that is not yet included in the code or in the other PR is generate_production_grid. But maybe its best if we close this one and I open another PR with just this part included?

@GernotMaier
Copy link
Contributor

Agree. Please close the PR and put a comment on where the updated work is taking place.

@tobiaskleiner
Copy link
Collaborator Author

Closing this PR as its parts are now either implemented (threshold/limits calculation for production, event scaling for production) or moved into other PRs:#1254 #1388.

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.

3 participants