Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @lispandfound, 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 focuses on a major performance overhaul for the plot-ts script, aiming to significantly reduce both memory consumption and execution time when generating ground motion animations. The changes involve optimizing data access patterns, improving parallel processing efficiency, and introducing a new downsampling capability to provide faster rendering options.
Highlights
- Performance Optimization: The core optimization involves a significant shift in how ground motion data is handled. Instead of pre-calculating and loading the entire
ground_motion_magnitudearray into memory, individual frames are now loaded on demand within therender_single_framefunction using the newtslice_gethelper. This drastically reduces memory usage and improves overall processing speed, especially for large datasets, contributing to the reported 50x speedup. - Parallelization Efficiency: By passing the
xyts_file_pathto therender_single_framefunction (which is executed in parallel), rather than a large NumPy array, the amount of data copied between processes is significantly reduced. This change directly addresses the goal of properly parallelizing the main loop without excessive data copying, enhancing the efficiency of multi-threaded rendering. - Downsampling Feature: A new
downsampleoption has been introduced, allowing users to specify a downsampling factor for the waveform mesh. This enables rendering frames at a lower resolution, which can further accelerate the animation generation process, particularly when high fidelity is not required or for quick previews. - Flexible Frame Control: The
animate_low_frequency_mpl_nztmfunction now accepts aframe_startparameter, enabling users to begin rendering an animation from a specific frame index. This provides greater control and flexibility for generating partial animations or resuming interrupted processes.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 is currently in preview and 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 to provide feedback.
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
-
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. ↩
There was a problem hiding this comment.
Pull Request Overview
This PR accelerates plot-ts by parallelizing frame rendering, optimizing memmap access, and adding a downsampling option to reduce memory and compute overhead.
- Added
tslice_getto read and downsample individual time slices without precomputing full magnitude arrays. - Refactored
render_single_frameto accept an XYTS file path anddownsampleparameter and updated the animation entrypoint. - Changed frame‐range handling to support a configurable
frame_start.
Comments suppressed due to low confidence (2)
visualisation/plot_ts.py:314
- Consider adding unit tests for
tslice_getto cover both downsample > 1 and default cases to ensure correct slicing and norm computation.
def tslice_get(xyts_file: XYTSFile, index: int, downsample: int = 1) -> np.ndarray:
visualisation/plot_ts.py:589
- The
functools.partialcall omits required parameterssimple_map,scale,map_quality, andtitle, which will cause aTypeErrorwhen invokingrender_single_frame. Include these arguments or provide defaults.
render_frame = functools.partial(
There was a problem hiding this comment.
Code Review
This pull request improves the performance and memory usage of plot-ts by optimizing data loading and enabling parallel frame rendering. The introduction of a downsampling option is a great feature. The review focuses on refining these improvements, including optimizing downsampling, exposing the downsample parameter to the command line, and addressing a minor logic issue in the frame rendering loop.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
Jenkins builds are failing because of some stuff that changed in the realisation format recently. Will fix that in a separate PR. |
This PR improves the speed of
plot-tsto reduce the memory usage and time this script takes to run. Average frame generation speeds have reduced from ~5 seconds per frame to 10 frames per second on Hypocentre, a 50x speedup.The main achievements to do this are: