Skip to content

Fix lightcurve generation: FITS error handling and relativistic NaNs#130

Open
Dnsflr wants to merge 2 commits into
danieljprice:mainfrom
Dnsflr:fix-lightcurve-fits-bug-and-velocity-columns-loading
Open

Fix lightcurve generation: FITS error handling and relativistic NaNs#130
Dnsflr wants to merge 2 commits into
danieljprice:mainfrom
Dnsflr:fix-lightcurve-fits-bug-and-velocity-columns-loading

Conversation

@Dnsflr

@Dnsflr Dnsflr commented Jul 6, 2026

Copy link
Copy Markdown

Fix lightcurve generation: FITS error handling and relativistic NaNs

This PR addresses two bugs encountered when generating lightcurves across multiple dump files using splash calc lightcurve:

1. Empty lightcurve.out on FITS export failure

  • Bug: When the CFITSIO library fails to write the FITS image or cube in get_lightcurve (e.g. throwing ERROR: mom0 FITS image not written; skipping cube), the subroutine returns with ierr /= 0. This causes the condition if (ierr == 0) in src/analysis.f90 to evaluate to false, skipping the writing of data to lightcurve.out entirely.
  • Fix: Reset the ierr variable back to 0 inside the error catching blocks for both write_fits_image and write_fits_cube in src/lightcurve.f90. This allows the FITS export to gracefully fail while the subroutine still returns a successful code, ensuring the main data is still properly written to lightcurve.out.

2. NaN output in relativistic calculations during multi-file processing

  • Bug: When running with relativistic corrections enabled, SPLASH outputs NaN values for L_bol and T_eff on subsequent files. Because sequential file analysis uses a partial read mechanism, the velocity vector components (vx, vy, vz) were omitted from the required array in the case('lightcurve') initialization block. The first dump file bypasses this issue (as it reads all columns to establish the header), but subsequent files skip loading velocity data. This leads to uninitialized memory being passed to the get_lightcurve subroutine, resulting in NaNs when calculating the Lorentz factor (doppler_factor_max).
  • Fix: Explicitly required the velocity columns in the case('lightcurve') block inside src/analysis.f90:
    if (ivx > 0) required(ivx:ivx+ndimV-1) = .true.
    
    

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling when creating lightcurve FITS outputs, so one failed output file no longer stops the remaining export steps.
    • Prevented attempts to read velocity data when it isn’t available, reducing errors in lightcurve analysis runs.

…sure velocity columns are loaded for relativistic corrections
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Dnsflr, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 91b9dfe0-963a-4d64-9236-cdc65a988abe

📥 Commits

Reviewing files that changed from the base of the PR and between ca43117 and 86b16c1.

📒 Files selected for processing (1)
  • src/analysis.f90
📝 Walkthrough

Walkthrough

This PR modifies two Fortran source files: analysis.f90 makes velocity column requirements conditional on ivx > 0 in lightcurve analysis mode, and lightcurve.f90 changes FITS write error handling to avoid early exit on mom0 write failure, allowing continuation to cube writing with adjusted error reporting.

Changes

Lightcurve FITS and column fixes

Layer / File(s) Summary
Conditional velocity column requirement
src/analysis.f90
required(ivx:ivx+ndimV-1) is now only set when ivx > 0 for lightcurve analysis mode.
Non-fatal FITS write error handling
src/lightcurve.f90
Mom0 FITS write failure no longer causes early return; ierr is reset to 0 and execution continues to cube writing, whose failure is now logged inside an if (ierr /= 0) block before resetting ierr.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main fixes: FITS error handling and relativistic NaN issues in lightcurve generation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

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 updates src/analysis.f90 to set the required flags for velocity columns when ivx > 0, and modifies src/lightcurve.f90 to reset the error variable ierr to 0 after handling FITS write failures. The feedback suggests adding an upper-bound check on the required array slice in src/analysis.f90 to prevent potential out-of-bounds array access.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/analysis.f90 Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/analysis.f90 (1)

206-206: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Same unguarded required(ivx:...) pattern exists in energy, rhomach, and kh cases.

These cases set required(ivx:ivx+ndimV-1) = .true. without the ivx > 0 guard added for lightcurve. If ivx == 0 for these analysis types, the same unintended spill into required(1)/required(2) described above would occur.

♻️ Apply same guard to other cases
-    required(ivx:ivx+ndimV-1) = .true.
+    if (ivx > 0) required(ivx:ivx+ndimV-1) = .true.

(apply to lines 206, 321, 336)

Also applies to: 321-321, 336-336

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/analysis.f90` at line 206, The same unguarded required(ivx:ivx+ndimV-1)
assignment used in the energy, rhomach, and kh branches of analysis.f90 must
also be protected with the ivx > 0 check added for lightcurve. Update the
matching cases in the analysis logic so they only mark required(ivx:...) when
ivx is valid, using the same guard pattern around the existing required slice
assignment in each branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/analysis.f90`:
- Line 206: The same unguarded required(ivx:ivx+ndimV-1) assignment used in the
energy, rhomach, and kh branches of analysis.f90 must also be protected with the
ivx > 0 check added for lightcurve. Update the matching cases in the analysis
logic so they only mark required(ivx:...) when ivx is valid, using the same
guard pattern around the existing required slice assignment in each branch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7cf88432-62cd-4fd4-b8a5-f03cd292432e

📥 Commits

Reviewing files that changed from the base of the PR and between 4efd030 and ca43117.

📒 Files selected for processing (2)
  • src/analysis.f90
  • src/lightcurve.f90

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.

1 participant