Skip to content

Export trigger threshold as parameter - #2457

Open
EshitaJoshi wants to merge 14 commits into
mainfrom
export-threshold
Open

Export trigger threshold as parameter#2457
EshitaJoshi wants to merge 14 commits into
mainfrom
export-threshold

Conversation

@EshitaJoshi

@EshitaJoshi EshitaJoshi commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Exporting trigger (asum or dsum) threshold as model parameter and updated plots to include fits and show trigger threshold:

bias_curves

@EshitaJoshi
EshitaJoshi marked this pull request as ready for review August 25, 2026 09:42

@GernotMaier GernotMaier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As discussed, remove the 1.35 (it is in quite many places) and add it as a command line parameter.

Questions (plus some minor stuff as comments):

  • what happens if no intersection point is found. Does this give an error or just writes something (what)?
  • are --ymin and --ymax ignored whenever data exists?


_logger.info("Plotting bias curves...")
plot_tables.plot_bias_curves(nsb_stats, proton_stats, args, plot_output_path)
# Log the data points for debugging

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is that comment correct? It is a _logger.info statement, not a a debug statement.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Edited the comment, thanks

for thresh in thresholds:
nsb_rate = nsb_stats[thresh]["rate_hz"] if thresh in nsb_stats else None
proton_rate = proton_stats[thresh]["rate_hz"] if thresh in proton_stats else None
scaled_proton = 1.35 * proton_rate if proton_rate is not None else None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here is the magic number! As discussed, move it to a command line parameter.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed

"""
Calculate trigger threshold from bias curve intersection.

Trigger threshold is calculated as the intersection between NSB curve and 1.35*proton curve.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no magic numbers in comments.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed

if not telescope_name:
_logger.warning("No telescope name provided. Using 'unknown' as telescope name.")
telescope_name = "unknown"
parameter_version = args.get("parameter_version")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this is not set on the CL ('None'), does it still try to write a model data file?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Made parameter version a required argument

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds trigger-threshold derivation and model-parameter export to the bias-curve workflow.

Changes:

  • Calculates and exports analog/digital trigger thresholds.
  • Enhances plots with fitted/scaled proton curves and threshold markers.
  • Expands unit coverage and explicit HDF5 reading.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/simtools/applications/derive_bias_curves.py Adds parameter-version CLI support.
src/simtools/simtel/bias_curve_generator.py Calculates and exports trigger thresholds.
src/simtools/simtel/nsb_trigger_calculator.py Explicitly reads HDF5 format.
src/simtools/visualization/plot_tables.py Adds scaled curves, threshold markers, and dynamic limits.
tests/unit_tests/simtel/test_bias_curve_generator.py Tests threshold calculation and export behavior.
tests/unit_tests/visualization/test_plot_tables.py Tests enhanced bias-curve plotting.
docs/changes/2457.maintenance.md Records the change.
Suppressed comments (1)

tests/unit_tests/simtel/test_bias_curve_generator.py:665

  • This file-writing test should use the repository's shared tmp_test_directory fixture rather than tmp_path (tests/unit_tests/conftest.py:240).
def test_group_hdf5_files_skips_missing_metadata(tmp_path):
    """Test that _group_hdf5_files_by_threshold_and_run skips files with missing metadata."""
    # Create a file without proper metadata
    (tmp_path / "proton_run000001.reduced_event_data.hdf5").touch()

    result = bias_curve_generator._group_hdf5_files_by_threshold_and_run(tmp_path)
    assert result == {}  # File skipped due to missing threshold/run

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/simtools/applications/derive_bias_curves.py Outdated
Comment thread src/simtools/simtel/bias_curve_generator.py
Comment thread src/simtools/visualization/plot_tables.py Outdated
Comment thread src/simtools/visualization/plot_tables.py
Comment thread src/simtools/simtel/bias_curve_generator.py Outdated
Comment thread src/simtools/simtel/bias_curve_generator.py
Comment thread docs/changes/2457.maintenance.md
Comment thread tests/unit_tests/simtel/test_bias_curve_generator.py Outdated
@EshitaJoshi

Copy link
Copy Markdown
Collaborator Author

Thanks for the review @GernotMaier! Made the changes requested by you and Copilot, please let me know if it's all ok now!

what happens if no intersection point is found. Does this give an error or just writes something (what)?

It raises a ValueError and no output is written.

are --ymin and --ymax ignored whenever data exists?

Yes, removed ymin and ymax for this reason.

@ctao-sonarqube

Copy link
Copy Markdown

@GernotMaier GernotMaier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good, thanks! I approve, but please fix the comments below (especially about the duplication of the documentation).

# Scale proton rates by 1.35 to account for ions we didn't simulate
scaled_proton_rates = 1.35 * proton_rates
# Scale proton rates to account for ions we didn't simulate
scaling_factor = args.get("scaling_factor", 1.35)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we duplicate here the default value? That might lead later to errors.

The input files can be generated using simtools-generate-bias-curve-submissions.
The input files can be generated using ``simtools-generate-bias-curve-submissions``.

**Command line arguments**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the description of the command line arguments is duplicated now: it is written here in plain text and added with the sphinx macro

## Command line arguments

```{eval-rst}
.. simtools-cli-help::
   :application: derive_bias_curves
   :no-heading:

Please check the html doc page and remove the 'hand written description'.


.. code-block:: console

simtools-derive-bias-curves \\

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

simtools-derive-bias-curves or simtools-generate-bias-curve-submissions?

Also please if possible simple list the integration tests here as example (with the corresponding sphinx macros, see the other application markdown documents).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants