Skip to content

Event finding from scalar expressions#519

Merged
ChristopherRabotin merged 13 commits into
masterfrom
feat/event-finding
Oct 10, 2025
Merged

Event finding from scalar expressions#519
ChristopherRabotin merged 13 commits into
masterfrom
feat/event-finding

Conversation

@ChristopherRabotin

Copy link
Copy Markdown
Member

Summary

Add the ability to find events of any kind as long as they can be represented by the scalar expressions.

TODO: description + bug fixes in the tests. Currently submitting for Gemini code review.

Architectural Changes

No change

New Features

No change

Improvements

No change

Bug Fixes

No change

Testing and validation

Detail the changes in tests, including new tests and validations

Documentation

This PR does not primarily deal with documentation changes.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ChristopherRabotin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the analysis capabilities by introducing a robust event-finding system based on scalar expressions. It allows for the definition and detection of various trajectory events, such as crossings or specific conditions, and provides tools to report these events and their characteristics. Additionally, it refactors internal frame information retrieval, expands the range of available scalar expressions, and introduces S-expression serialization for analysis configurations, making them more flexible and interoperable.

Highlights

  • Event Finding Framework: Introduced a comprehensive framework for event finding based on scalar expressions, including new Event, EventDetails, and EventArc structs. This allows for defining, detecting, and characterizing various events within a trajectory, such as rising/falling edges and event arcs.
  • Scalar Expression Enhancements: Expanded the ScalarExpr enum with new variants for celestial body properties (e.g., mean equatorial radius, gravitational parameter, flattening) and fundamental mathematical operations (add, multiply, negate, invert, square root, power). This significantly increases the flexibility and expressiveness of scalar computations.
  • Serialization with S-expressions: Integrated serde-lexpr to enable serialization and deserialization of ScalarExpr and ReportScalars using S-expressions (LISP-like syntax). This provides a human-readable and machine-parseable format for defining complex analysis configurations.
  • Almanac API Refactoring: Deprecated the Almanac::frame_from_uid method in favor of a new Almanac::frame_info method across the codebase. This change improves consistency and clarity in retrieving frame information.
  • New Analysis Capabilities: Added several new methods to Almanac for reporting scalar values over time (report_scalars), finding single events (report_event_once), finding all events within a trajectory (report_events), determining event minimums and maximums (report_event_minmax), and identifying event arcs (report_event_arcs).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a significant and powerful feature for event finding based on scalar expressions. The overall structure is well-designed, with clear separation of concerns into new modules for events, reports, and vector expressions. The refactoring of VectorExpr into its own file and the renaming of frame_from_uid to frame_info improve code organization and clarity.

I've identified a few areas for improvement, mainly concerning code duplication, potential panics from using unwrap(), and some minor code clarity issues. Addressing these will enhance the robustness and maintainability of this new functionality.

Comment thread anise/src/analysis/expr.rs Outdated
Comment thread anise/src/analysis/report.rs Outdated
Comment thread anise/src/analysis/event.rs
Comment thread anise/src/analysis/expr.rs
Comment thread anise/src/analysis/mod.rs Outdated
Comment thread anise/src/analysis/mod.rs Outdated
…was returning the wrong state

Currently debugging event arcs for eclipse finding.
@ChristopherRabotin

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a significant new feature: the ability to find events using scalar expressions. This is a major enhancement to the analysis capabilities of the library. The changes include a new event finding module with search algorithms, serialization for analysis-related structs, and a large expansion of the ScalarExpr enum. My review focuses on the new logic. I've found a few critical issues, including a bug in a mathematical expression evaluation that could lead to a panic, and potential panics in the new event search algorithms due to incorrect error handling and indexing. I've also included some suggestions for refactoring to improve code maintainability.

Comment thread anise/src/analysis/expr.rs Outdated
Comment thread anise/src/analysis/search.rs Outdated
Comment thread anise/src/analysis/search.rs
Comment thread anise/src/analysis/expr.rs Outdated
Comment thread anise/src/analysis/expr.rs
Comment thread anise/src/analysis/event.rs
@ChristopherRabotin

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a significant and powerful new feature: the ability to find events using scalar expressions. This is a great addition to the analysis capabilities of the library. The introduction of S-expression serialization for reports and expressions is also a very useful feature for interoperability. The refactoring of the analysis module into smaller, more focused modules (event, report, search, vector_expr) greatly improves the structure and maintainability of the code. The consistent renaming of frame_from_uid to frame_info across the codebase is also a welcome improvement for API clarity.

My review includes a few suggestions to fix correctness issues, particularly around angle and time calculations, and some recommendations to improve maintainability by reducing code duplication and making error handling more robust. Overall, this is an excellent contribution.

Comment thread anise/src/almanac/eclipse.rs Outdated
Comment thread anise/src/analysis/expr.rs Outdated
Comment thread anise/src/analysis/expr.rs Outdated
Comment thread anise/src/analysis/expr.rs
Comment thread anise/src/analysis/expr.rs Outdated
Comment thread anise/src/analysis/search.rs Outdated
Comment thread anise/src/analysis/report.rs Outdated
Comment thread anise/src/analysis/report.rs Outdated
Comment thread anise/src/math/angles.rs Outdated
Comment thread anise/src/math/angles.rs Outdated
@ChristopherRabotin ChristopherRabotin linked an issue Oct 9, 2025 that may be closed by this pull request
Arcs are not very fast because they're so precise (uses the report_events_slow).
Default precision for eclipse is 100 ms.
@ChristopherRabotin

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a powerful event-finding mechanism based on scalar expressions, which is a significant enhancement to the analysis capabilities of the library. The refactoring of frame_from_uid to frame_info improves API clarity, and the move of VectorExpr to its own module is a good structural improvement. The implementation of the Brent solver for event finding is also a solid choice for performance.

I've identified a few critical issues, mainly related to the incorrect use of trigonometric functions and potential panics from unwrap() calls. Addressing these will greatly improve the correctness and robustness of the new features. I've also found some high-severity issues regarding error handling and a logic bug in time calculation. Please review the detailed comments.

Comment thread anise/src/analysis/expr.rs Outdated
Comment thread anise/src/almanac/eclipse.rs Outdated
Comment thread anise/src/analysis/report.rs Outdated
Comment thread anise/src/analysis/search.rs Outdated
Comment thread anise/src/analysis/search.rs
Comment thread anise/src/analysis/expr.rs Outdated
@ChristopherRabotin

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a powerful and flexible event-finding system based on scalar expressions, which is a significant enhancement to the analysis capabilities of the library. The overall architecture is well-thought-out, with clear separation of concerns into new modules like event, search, and report. The use of S-expressions for serialization is a great choice for this domain.

I've identified a few areas for improvement, including a critical bug in a mathematical expression and opportunities to enhance code clarity and robustness. Addressing these points will help solidify this excellent new feature.

Comment thread anise/src/analysis/expr.rs Outdated
Comment thread anise/src/analysis/search.rs Outdated
Comment thread anise/src/almanac/eclipse.rs Outdated
Comment thread anise/src/analysis/expr.rs
Comment thread anise/src/analysis/mod.rs Outdated
Comment thread anise/src/analysis/search.rs
BUG: LST from ANISE and manual with ScalrExpr no longer match
It could be an error with the to_radians of the scalar expression (likely)
@ChristopherRabotin

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a significant and powerful feature for event finding based on scalar expressions. The overall architecture is well-thought-out, with clear separation of concerns into modules for expressions, events, searching, and reporting. The ability to serialize and deserialize reports and expressions using S-expressions is a great addition for interoperability and persistence.

I've identified a few areas for improvement, including a critical bug in an angle calculation, a potential issue with a division-by-zero check, and opportunities to reduce code duplication and improve clarity in some of the new mathematical functions. Addressing these points will enhance the correctness and maintainability of this new functionality.

Comment thread anise/src/analysis/expr.rs Outdated
Comment thread anise/src/analysis/expr.rs
Comment thread anise/src/analysis/expr.rs
Comment thread anise/src/math/angles.rs Outdated
Comment thread anise/src/math/angles.rs Outdated
@ChristopherRabotin

Copy link
Copy Markdown
Member Author

Added S-Expr for Events. Examples:

APO S-EXPR:

((scalar Element . TrueAnomaly) (desired_value . 180.0) (epoch_precision . "100 ms") (value_precision . 0.01) (ab_corr))

Eclipse S-EXPR:

 ((scalar SolarEclipsePercentage (eclipsing_frame (ephemeris_id . 301) (orientation_id . 1) (mu_km3_s2) (shape))) (desired_value . 99.9) (epoch_precision . "100 ms") (value_precision . 1.0) (ab_corr))

@ChristopherRabotin

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a powerful event-finding capability based on scalar expressions. The implementation is extensive, adding new modules for events, searching, and reporting, and significantly expanding the ScalarExpr enum. The code is well-structured, but there are a few areas for improvement. My review focuses on improving maintainability by reducing code duplication, enhancing the robustness of angle-based event detection, addressing a potential performance issue in arc finding, and improving the clarity of a mathematical formula. Overall, this is a great addition to the library.

Comment thread anise/src/analysis/event.rs
Comment thread anise/src/almanac/eclipse.rs
Comment thread anise/src/analysis/expr.rs
Comment thread anise/src/analysis/search.rs
@ChristopherRabotin ChristopherRabotin merged commit 771f95a into master Oct 10, 2025
17 checks passed
@ChristopherRabotin ChristopherRabotin deleted the feat/event-finding branch October 10, 2025 05:17
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.

Trajectory structure and event finding

1 participant