Skip to content

Commit

Permalink
Provide a mechanism for collecting needed citations
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykubica committed Jun 28, 2024
1 parent 5b0a26f commit 0b9a0e6
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/tdastro/base_models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from tdastro.common_citations import numpy_citation


class PhysicalModel:
"""A physical model of a source of flux.
Expand Down Expand Up @@ -110,6 +113,39 @@ def evaluate(self, times, wavelengths, **kwargs):
flux_density = effect.apply(flux_density, wavelengths, self, **kwargs)
return flux_density

def _get_citation(self):
"""Get the citation for this specific model.
Returns
-------
citations : `set`
A set of strings containing citations needed for this model.
"""
return set()

def get_citations(self):
"""Get the citations for this model, its host, and its effects.
Returns
-------
citations : `set`
A set of citation strings.
"""
# Numpy is a base citation for all models.
citations = set([numpy_citation])

# Add model specific citations.
citations = citations.union(self._get_citation())

# Add any host specific citations.
if self.host is not None:
citations = citations.union(self.host.get_citations())

# Add citations for each effect.
for effect in self.effects:
citations = citations.union(effect.get_citations())
return citations


class EffectModel:
"""A physical or systematic effect to apply to an observation."""
Expand Down Expand Up @@ -149,3 +185,13 @@ def apply(self, flux_density, wavelengths=None, physical_model=None, **kwargs):
A length T x N matrix of flux densities after the effect is applied.
"""
raise NotImplementedError()

def get_citations(self):
"""Get the citation for this specific effect.
Returns
-------
citations : `set`
A set of strings with at most one element.
"""
return set()
84 changes: 84 additions & 0 deletions src/tdastro/common_citations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
numpy_citation = """@Article{ harris2020array,
title = {Array programming with {NumPy}},
author = {Charles R. Harris and K. Jarrod Millman and St{\'{e}}fan J.
van der Walt and Ralf Gommers and Pauli Virtanen and David
Cournapeau and Eric Wieser and Julian Taylor and Sebastian
Berg and Nathaniel J. Smith and Robert Kern and Matti Picus
and Stephan Hoyer and Marten H. van Kerkwijk and Matthew
Brett and Allan Haldane and Jaime Fern{\'{a}}ndez del
R{\'{i}}o and Mark Wiebe and Pearu Peterson and Pierre
G{\'{e}}rard-Marchant and Kevin Sheppard and Tyler Reddy and
Warren Weckesser and Hameer Abbasi and Christoph Gohlke and
Travis E. Oliphant},
year = {2020},
month = sep,
journal = {Nature},
volume = {585},
number = {7825},
pages = {357--362},
doi = {10.1038/s41586-020-2649-2},
publisher = {Springer Science and Business Media {LLC}},
url = {https://doi.org/10.1038/s41586-020-2649-2}
}
"""

scipy_citation = """@ARTICLE{2020SciPy-NMeth,
author = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
Haberland, Matt and Reddy, Tyler and Cournapeau, David and
Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
Kern, Robert and Larson, Eric and Carey, C J and
Polat, {\\.I}lhan and Feng, Yu and Moore, Eric W. and
{VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
Harris, Charles R. and Archibald, Anne M. and
Ribeiro, Ant{\\^o}nio H. and Pedregosa, Fabian and
{van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
title = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
Computing in Python}},
journal = {Nature Methods},
year = {2020},
volume = {17},
pages = {261--272},
adsurl = {https://rdcu.be/b08Wh},
doi = {10.1038/s41592-019-0686-2},
}
"""

sncosmo_citation = """@software{barbary_2024_10684802,
author = {Barbary, Kyle and
Bailey, Stephen and
Barentsen, Geert and
Barclay, Tom and
Biswas, Rahul and
Boone, Kyle and
Craig, Matt and
Feindt, Ulrich and
Friesen, Brian and
Goldstein, Danny and
Jha, Saurabh W. and
Jones, David O. and
Mondon, Florian and
Papadogiannakis, Seméli and
Perrefort, Daniel and
Pierel, Justin and
Rodney, Steve and
Rose, Benjamin and
Saunders, Clare and
Sipőcz, Brigitta and
Sofiatti, Caroline and
Thomas, Rollin C. and
van Santen, Jakob and
Vincenzi, Maria and
Wang, David and
Wood-Vasey, Michael},
title = {SNCosmo},
month = feb,
year = 2024,
publisher = {Zenodo},
version = {v2.10.4},
doi = {10.5281/zenodo.10684802},
url = {https://doi.org/10.5281/zenodo.10684802}
}"""
11 changes: 11 additions & 0 deletions src/tdastro/sources/spline_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from scipy.interpolate import RectBivariateSpline

from tdastro.base_models import PhysicalModel
from tdastro.common_citations import scipy_citation, sncosmo_citation


class SplineModel(PhysicalModel):
Expand Down Expand Up @@ -88,3 +89,13 @@ def _evaluate(self, times, wavelengths, **kwargs):
A length T x N matrix of SED values.
"""
return self.amplitude * self._spline(times, wavelengths, grid=True)

def _get_citation(self):
"""Get the citation for this specific model.
Returns
-------
citations : `set`
A set of strings containing citations needed for this model.
"""
return set([scipy_citation, sncosmo_citation])
15 changes: 15 additions & 0 deletions tests/tdastro/sources/test_spline_source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from tdastro.common_citations import numpy_citation, scipy_citation, sncosmo_citation
from tdastro.sources.spline_model import SplineModel


Expand Down Expand Up @@ -40,3 +41,17 @@ def test_spline_model_interesting() -> None:
[[1.0, 3.0, 5.0, 1.0], [3.0, 5.25, 7.5, 3.0], [5.0, 7.5, 10.0, 5.0], [1.0, 3.0, 5.0, 3.0]]
)
np.testing.assert_array_almost_equal(values, expected)


def test_static_source_citations() -> None:
"""Test that we get the citation string for a SplineModel."""
times = np.linspace(1.0, 5.0, 20)
wavelengths = np.linspace(100.0, 500.0, 25)
fluxes = np.full((len(times), len(wavelengths)), 1.0)
model = SplineModel(times, wavelengths, fluxes)

citations = model.get_citations()
assert len(citations) == 3
assert numpy_citation in citations
assert scipy_citation in citations
assert sncosmo_citation in citations
9 changes: 9 additions & 0 deletions tests/tdastro/sources/test_static_source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from tdastro.common_citations import numpy_citation
from tdastro.sources.static_source import StaticSource


Expand Down Expand Up @@ -27,3 +28,11 @@ def test_static_source_host() -> None:
assert model.ra == 1.0
assert model.dec == 2.0
assert model.distance == 3.0


def test_static_source_citations() -> None:
"""Test that we get the citation string for numpy."""
model = StaticSource(brightness=10.0)
citations = model.get_citations()
assert len(citations) == 1
assert numpy_citation in citations

0 comments on commit 0b9a0e6

Please sign in to comment.