Skip to content

Commit 5c3fb15

Browse files
authored
Misc comments and checks (#671)
* Add a clarifying comment to obs_table.py * Add some comments * Update physical_model.py * Add some validity checks * Update graph_state.py
1 parent 5a4bfbf commit 5c3fb15

File tree

7 files changed

+23
-4
lines changed

7 files changed

+23
-4
lines changed

src/lightcurvelynx/effects/extinction.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,7 @@ def apply(
177177
if wavelengths is None:
178178
raise ValueError("wavelengths must be provided")
179179

180-
return flux_density * self.extinction_model.extinguish(wavelengths * u.angstrom, Ebv=ebv)
180+
# The extinction factor computed by dust_extinction is a multiplicative
181+
# factor to reduce the flux (<= 1 for all wavelengths).
182+
ext_factor = self.extinction_model.extinguish(wavelengths * u.angstrom, Ebv=ebv)
183+
return flux_density * ext_factor

src/lightcurvelynx/graph_state.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ def to_networkx(self):
869869
"""
870870
try:
871871
import networkx as nx
872-
except ImportError as err:
872+
except ImportError as err: # pragma: no cover
873873
raise ImportError(
874874
"NetworkX is required to convert the dependency graph to a NetworkX graph. "
875875
"Please install it with 'pip install networkx'."
@@ -919,7 +919,7 @@ def draw(self, param_name=None):
919919
try:
920920
import matplotlib.pyplot as plt
921921
import networkx as nx
922-
except ImportError as err:
922+
except ImportError as err: # pragma: no cover
923923
raise ImportError(
924924
"NetworkX and Matplotlib are required to draw the graph. "
925925
"Please install them with 'pip install networkx matplotlib'."

src/lightcurvelynx/models/physical_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def __init__(
9494
allow_gradient=False,
9595
)
9696
elif redshift is not None and kwargs.get("cosmology") is not None:
97-
self._redshift_func = RedshiftDistFunc(redshift=self.redshift, **kwargs)
97+
cosmology = kwargs.pop("cosmology")
98+
self._redshift_func = RedshiftDistFunc(redshift=self.redshift, cosmology=cosmology)
9899
self.add_parameter(
99100
"distance",
100101
self._redshift_func,

src/lightcurvelynx/models/redback_models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def __init__(
107107
) from err
108108

109109
self.source_name = source
110+
if source not in redback.model_library.all_models_dict: # pragma: no cover
111+
raise ValueError(f"Redback model '{source}' not found in redback model library.")
110112
self.source = redback.model_library.all_models_dict[source]
111113
else:
112114
self.source_name = source.__name__

src/lightcurvelynx/obstable/obs_table.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,9 @@ def range_search(self, query_ra, query_dec, *, radius=None, t_min=None, t_max=No
705705
# Confirm the query RA and Dec have the same length.
706706
if len(query_ra) != len(query_dec):
707707
raise ValueError("Query RA and Dec must have the same length.")
708+
709+
# Check that there are no None values in the query. We use == to do
710+
# an element-wise comparison.
708711
if np.any(query_ra == None) or np.any(query_dec == None): # noqa: E711
709712
raise ValueError("Query RA and dec cannot contain None.")
710713

tests/lightcurvelynx/astro_utils/test_sed_basis_models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ def test_sed_basis_model() -> None:
4747
)
4848
assert np.allclose(flux_density, expected)
4949

50+
# The computation fails if any filter is unknown.
51+
with pytest.raises(ValueError):
52+
_ = sed_basis.compute_sed_from_bandfluxes(["r", "g", "x", "r"], bandfluxes=[2.0, 1.0, 1.5, 2.5])
53+
54+
# The computation fails if bandfluxes length doesn't match filters length.
55+
with pytest.raises(ValueError):
56+
_ = sed_basis.compute_sed_from_bandfluxes(["r", "g", "g", "r"], bandfluxes=[2.0, 1.0, 1.5])
57+
5058
# SED creation fails if the lengths do not match.
5159
with pytest.raises(ValueError):
5260
_ = SEDBasisModel(np.array([300, 400, 500, 600, 700]), filter_data)

tests/lightcurvelynx/effects/test_extinction.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ def test_constant_dust_extinction():
114114
states = model.sample_parameters(num_samples=3)
115115
fluxes = model.evaluate_sed(times, wavelengths, states)
116116

117+
# We check that all fluxes are reduced, and that higher ebv leads to
118+
# lower fluxes.
117119
assert fluxes.shape == (3, 5, 3)
118120
assert np.all(fluxes < 100.0)
119121
assert np.all(fluxes[0, :, :] > fluxes[1, :, :])

0 commit comments

Comments
 (0)