Skip to content

Add kilonova event source type - #445

Open
Zhengjingyi0823 wants to merge 23 commits into
LSST-strong-lensing:mainfrom
Zhengjingyi0823:add-kilonova-event
Open

Add kilonova event source type#445
Zhengjingyi0823 wants to merge 23 commits into
LSST-strong-lensing:mainfrom
Zhengjingyi0823:add-kilonova-event

Conversation

@Zhengjingyi0823

Copy link
Copy Markdown
Collaborator

This PR adds a Redback-based Kilonova light-curve wrapper and integrates it as a new KilonovaEvent source type. It also registers the new "kilonova" keyword in source.py and adds tests for the kilonova model and event-level behavior.

@Zhengjingyi0823

Copy link
Copy Markdown
Collaborator Author

The remaining CI failures seem unrelated to the kilonova changes. The failing tests are in the lens/profile and plotting parts.

I also added redback to requirements.txt because the CI environment did not have it installed, and the new kilonova model depends on it. One concern is that kilonova is an optional source type, so I wonder whether redback should be handled as an optional dependency instead of being required for all SLSim users. Please let me know which approach you prefer.

@Zhengjingyi0823
Zhengjingyi0823 requested a review from sibirrer July 9, 2026 20:14
@sibirrer

sibirrer commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Yes, I think I can fix the CI with my big change all at once

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

Thank you very much!
I could resolve the merge conflict with the new refactoring. I have some minor request before the merge

Comment thread requirements.txt Outdated
pyyaml
matplotlib
redback>=1.17.0
colossus

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.

Suggested change
colossus

Comment thread requirements.txt Outdated
speclite
pyyaml
matplotlib
redback>=1.17.0

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.

this is a very specific package only for kilonovae. Might be better to have it only in the test_requirements.txt

:param model_name: The kilonova light curve model to be used. If not provided,
the default model is the MOSFiT-based kilonova model.
:type model_name: str
:param ejecta_mass: Ejecta masses for the kilonova components.

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.

can you provide the units?

:type model_name: str
:param ejecta_mass: Ejecta masses for the kilonova components.
:type ejecta_mass: array-like or None
:param ejecta_velocity: Ejecta velocities for the kilonova components.

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.

units?

:type ejecta_velocity: array-like or None
:param opacity: Opacities for the kilonova components.
:type opacity: array-like or None
:param temperature_floor: Temperature floors for the kilonova components.

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.

units (K?)

for name, values in parameter_groups.items():
if values is None:
raise ValueError(f"{name} must be provided.")
if len(values) != 3:

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.

why is this test here? Why are there three values? Can you explain what you test here in the code?

self._model_name = model_name
self._mag_zpsys = mag_zpsys
self._modeldir = modeldir
self._kwargs_kilonova = kwargs_kilonova or {}

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 this proper python or what does the 'or' do here?

times = self._lightcurve_time

# Use the sncosmo band-name mapping since Redback expects registered filter names.
provided_band = get_sncosmo_filtername(element)

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 need SNCosmo band names? don't understand how this is required

raise ValueError(f"{name} must have three components.")

self._model_parameters = {
"mej_1": ejecta_mass[0],

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.

perhaps have all these parameters as inputs to this class instead of re-naming them

@sibirrer

sibirrer commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Thank you @Zhengjingyi0823 ! The CI fails because some tests were not updated

@Zhengjingyi0823
Zhengjingyi0823 force-pushed the add-kilonova-event branch 2 times, most recently from 205f7f6 to 15e8d07 Compare August 6, 2026 18:03
@sibirrer

sibirrer commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

From a quick search, perhaps add in the test files where the plots are generated these lines of code:
import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = False

@Zhengjingyi0823

Copy link
Copy Markdown
Collaborator Author

I added the suggested Matplotlib setting to the plot test file. However, GitHub Actions seems to be experiencing an outage. I tried pushing several times today, but the checks were either stuck in the queue or cancelled. Should I try rerunning them tomorrow?

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

Yeah, the GitHub action is either down or we are out of credits. Perhaps we wait and try tomorrow again to merge it

Comment thread requirements.txt Outdated
speclite
pyyaml
matplotlib
matplotlib==3.11.1

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 you still need that with the additional fix of not using latex?
I also added trough a separate PR #466 the pit.rcparams parts. Surprised it did not result in a merge conflict or pre-commit cit.

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.87179% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.57%. Comparing base (629c2a4) to head (c288567).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
slsim/Sources/SourceTypes/point_source.py 50.00% 2 Missing ⚠️
slsim/Sources/Events/BNSMerger/kilonova.py 94.73% 1 Missing ⚠️
slsim/Sources/SourceTypes/kilonova_event.py 98.03% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #445      +/-   ##
==========================================
- Coverage   98.62%   98.57%   -0.06%     
==========================================
  Files         112      114       +2     
  Lines        8733     8822      +89     
==========================================
+ Hits         8613     8696      +83     
- Misses        120      126       +6     
Files with missing lines Coverage Δ
slsim/Sources/source.py 100.00% <100.00%> (ø)
slsim/Sources/Events/BNSMerger/kilonova.py 94.73% <94.73%> (ø)
slsim/Sources/SourceTypes/kilonova_event.py 98.03% <98.03%> (ø)
slsim/Sources/SourceTypes/point_source.py 90.90% <50.00%> (-5.76%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sibirrer

sibirrer commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Ok, looks good now. Just one test that through Source() you can enable the BNS class needs to be tested (two missing lines in the tests) - thank you!

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.

2 participants